🐛 Fix problem with multiple values in inputs

This commit is contained in:
alonso.torres 2022-03-15 10:48:57 +01:00
parent 9b862b672f
commit ccca3a38f0
4 changed files with 35 additions and 15 deletions

View file

@ -30,7 +30,7 @@
on-change (obj/get props "onChange") on-change (obj/get props "onChange")
on-blur (obj/get props "onBlur") on-blur (obj/get props "onBlur")
title (obj/get props "title") title (obj/get props "title")
default-val (obj/get props "default" 0) default-val (obj/get props "default")
;; We need a ref pointing to the input dom element, but the user ;; We need a ref pointing to the input dom element, but the user
;; of this component may provide one (that is forwarded here). ;; of this component may provide one (that is forwarded here).

View file

@ -6,31 +6,38 @@
(ns app.main.ui.formats (ns app.main.ui.formats
(:require (:require
[app.common.data :as d]
[app.common.data.macros :as dm] [app.common.data.macros :as dm]
[app.common.math :as mth])) [app.common.math :as mth]))
(defn format-percent (defn format-percent
([value] ([value]
(format-percent value nil)) (format-percent value nil))
([value {:keys [precision] :or {precision 2}}] ([value {:keys [precision] :or {precision 2}}]
(when (d/num? value)
(let [percent-val (mth/precision (* value 100) precision)] (let [percent-val (mth/precision (* value 100) precision)]
(dm/str percent-val "%")))) (dm/str percent-val "%")))))
(defn format-number (defn format-number
([value] ([value]
(format-number value nil)) (format-number value nil))
([value {:keys [precision] :or {precision 2}}] ([value {:keys [precision] :or {precision 2}}]
(when (d/num? value)
(let [value (mth/precision value precision)] (let [value (mth/precision value precision)]
(dm/str value)))) (dm/str value)))))
(defn format-pixels (defn format-pixels
([value] ([value]
(format-pixels value nil)) (format-pixels value nil))
([value {:keys [precision] :or {precision 2}}] ([value {:keys [precision] :or {precision 2}}]
(when (d/num? value)
(let [value (mth/precision value precision)] (let [value (mth/precision value precision)]
(dm/str value "px")))) (dm/str value "px")))))
(defn format-int (defn format-int
[value] [value]
(when (d/num? value)
(let [value (mth/precision value 0)] (let [value (mth/precision value 0)]
(dm/str value))) (dm/str value))))

View file

@ -8,6 +8,7 @@
(:require (:require
[app.common.data :as d] [app.common.data :as d]
[app.common.geom.shapes :as gsh] [app.common.geom.shapes :as gsh]
[app.common.math :as mth]
[app.main.ui.context :as muc] [app.main.ui.context :as muc]
[app.main.ui.shapes.attrs :as attrs] [app.main.ui.shapes.attrs :as attrs]
[app.main.ui.shapes.custom-stroke :refer [shape-custom-strokes]] [app.main.ui.shapes.custom-stroke :refer [shape-custom-strokes]]
@ -24,6 +25,7 @@
(let [render-id (mf/use-ctx muc/render-ctx) (let [render-id (mf/use-ctx muc/render-ctx)
{:keys [x y width height position-data] :as shape} (obj/get props "shape") {:keys [x y width height position-data] :as shape} (obj/get props "shape")
transform (str (gsh/transform-matrix shape)) transform (str (gsh/transform-matrix shape))
;; These position attributes are not really necesary but they are convenient for for the export ;; These position attributes are not really necesary but they are convenient for for the export
@ -48,8 +50,8 @@
[:> :g group-props [:> :g group-props
(for [[index data] (d/enumerate position-data)] (for [[index data] (d/enumerate position-data)]
(let [props (-> #js {:x (:x data) (let [props (-> #js {:x (mth/round (:x data))
:y (:y data) :y (mth/round (:y data))
:dominantBaseline "ideographic" :dominantBaseline "ideographic"
:style (-> #js {:fontFamily (:font-family data) :style (-> #js {:fontFamily (:font-family data)
:fontSize (:font-size data) :fontSize (:font-size data)
@ -61,7 +63,18 @@
:whiteSpace "pre"} :whiteSpace "pre"}
(obj/set! "fill" (str "url(#fill-" index "-" render-id ")")))}) (obj/set! "fill" (str "url(#fill-" index "-" render-id ")")))})
shape (assoc shape :fills (:fills data))] shape (assoc shape :fills (:fills data))]
[:*
#_[:rect {:x (:x data)
:y (- (:y data) (:height data))
:width (:width data)
:height (:height data)
:style {:fill "none" :stroke-width 1 :stroke "red"}}]
[:line {:x1 (mth/round (:x data))
:y1 (mth/round (:y data))
:x2 (mth/round (+ (:x data) (:width data)))
:y2 (mth/round (:y data))
:style {:fill "none" :stroke-width 0.5 :stroke "blue"}}]
[:& shape-custom-strokes {:shape shape} [:& shape-custom-strokes {:shape shape}
[:> :text props (:text data)]]))]])) [:> :text props (:text data)]]]))]]))