0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-13 16:21:57 -05:00

🐛 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-blur (obj/get props "onBlur")
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
;; of this component may provide one (that is forwarded here).

View file

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

View file

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

View file

@ -201,8 +201,8 @@
(fn []
(when (and (= radius-mode :radius-1)
(= @radius-multi? false))
;; when going back from radius-multi to normal radius-1,
;; restore focus to the newly created numeric-input
;; when going back from radius-multi to normal radius-1,
;; restore focus to the newly created numeric-input
(let [radius-input (mf/ref-val radius-input-ref)]
(dom/focus! radius-input)))))