mirror of
https://github.com/penpot/penpot.git
synced 2025-06-12 01:11:38 +02:00
✨ Fix problems with extreme values
This commit is contained in:
parent
999af63118
commit
ed9400912c
59 changed files with 359 additions and 340 deletions
|
@ -6,23 +6,22 @@
|
|||
|
||||
(ns app.main.ui.components.numeric-input
|
||||
(:require
|
||||
[app.main.ui.formats :as fmt]
|
||||
[app.common.data :as d]
|
||||
[app.common.math :as math]
|
||||
[app.common.spec :as us]
|
||||
[app.util.dom :as dom]
|
||||
[app.util.globals :as globals]
|
||||
[app.util.keyboard :as kbd]
|
||||
[app.util.object :as obj]
|
||||
[app.util.simple-math :as sm]
|
||||
[app.util.strings :as ust]
|
||||
[goog.events :as events]
|
||||
[rumext.alpha :as mf])
|
||||
(:import goog.events.EventType))
|
||||
|
||||
(defn num? [val]
|
||||
(and (number? val)
|
||||
(not (math/nan? val))
|
||||
(math/finite? val)))
|
||||
(not (mth/nan? val))
|
||||
(mth/finite? val)))
|
||||
|
||||
(mf/defc numeric-input
|
||||
{::mf/wrap-props false
|
||||
|
@ -37,7 +36,6 @@
|
|||
on-blur (obj/get props "onBlur")
|
||||
title (obj/get props "title")
|
||||
default-val (obj/get props "default" 0)
|
||||
precision (obj/get props "precision")
|
||||
|
||||
;; We need a ref pointing to the input dom element, but the user
|
||||
;; of this component may provide one (that is forwarded here).
|
||||
|
@ -85,10 +83,6 @@
|
|||
(sm/expr-eval value))]
|
||||
(when (num? new-value)
|
||||
(-> new-value
|
||||
(cond-> (number? precision)
|
||||
(math/precision precision))
|
||||
(cond-> (nil? precision)
|
||||
(math/round))
|
||||
(cljs.core/max us/min-safe-int)
|
||||
(cljs.core/min us/max-safe-int)
|
||||
(cond->
|
||||
|
@ -103,9 +97,7 @@
|
|||
(mf/deps ref)
|
||||
(fn [new-value]
|
||||
(let [input-node (mf/ref-val ref)]
|
||||
(dom/set-value! input-node (if (some? precision)
|
||||
(ust/format-precision new-value precision)
|
||||
(str new-value))))))
|
||||
(dom/set-value! input-node (fmt/format-number new-value)))))
|
||||
|
||||
apply-value
|
||||
(mf/use-callback
|
||||
|
@ -193,17 +185,17 @@
|
|||
(obj/set! "className" "input-text")
|
||||
(obj/set! "type" "text")
|
||||
(obj/set! "ref" ref)
|
||||
(obj/set! "defaultValue" value-str)
|
||||
(obj/set! "defaultValue" (fmt/format-number value))
|
||||
(obj/set! "title" title)
|
||||
(obj/set! "onWheel" handle-mouse-wheel)
|
||||
(obj/set! "onKeyDown" handle-key-down)
|
||||
(obj/set! "onBlur" handle-blur))]
|
||||
|
||||
(mf/use-effect
|
||||
(mf/deps value-str)
|
||||
(mf/deps value)
|
||||
(fn []
|
||||
(when-let [input-node (mf/ref-val ref)]
|
||||
(dom/set-value! input-node value-str))))
|
||||
(dom/set-value! input-node (fmt/format-number value)))))
|
||||
|
||||
(mf/use-effect
|
||||
(mf/deps handle-blur)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue