0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-04-13 15:31:26 -05:00

🐛 Fix copying layout values with only multiple decimals

This commit is contained in:
Eva 2022-05-05 14:42:22 +02:00 committed by Andrés Moya
parent 1102bc9cba
commit 37fdf51eaf
2 changed files with 14 additions and 12 deletions

View file

@ -8,9 +8,9 @@
(:require
[app.common.spec.radius :as ctr]
[app.main.ui.components.copy-button :refer [copy-button]]
[app.main.ui.formats :as fmt]
[app.util.code-gen :as cg]
[app.util.i18n :refer [tr]]
[app.util.strings :as ust]
[cuerdas.core :as str]
[rumext.alpha :as mf]))
@ -35,50 +35,51 @@
(mf/defc layout-block
[{:keys [shape]}]
(let [selrect (:selrect shape)
_ (prn shape)
{:keys [width height x y]} selrect]
[:*
[:div.attributes-unit-row
[:div.attributes-label (tr "handoff.attributes.layout.width")]
[:div.attributes-value (ust/format-precision width 2) "px"]
[:div.attributes-value (fmt/format-pixels width)]
[:& copy-button {:data (copy-data selrect :width)}]]
[:div.attributes-unit-row
[:div.attributes-label (tr "handoff.attributes.layout.height")]
[:div.attributes-value (ust/format-precision height 2) "px"]
[:div.attributes-value (fmt/format-pixels height)]
[:& copy-button {:data (copy-data selrect :height)}]]
(when (not= (:x shape) 0)
[:div.attributes-unit-row
[:div.attributes-label (tr "handoff.attributes.layout.left")]
[:div.attributes-value (ust/format-precision x 2) "px"]
[:div.attributes-value (fmt/format-pixels x)]
[:& copy-button {:data (copy-data selrect :x)}]])
(when (not= (:y shape) 0)
[:div.attributes-unit-row
[:div.attributes-label (tr "handoff.attributes.layout.top")]
[:div.attributes-value (ust/format-precision y 2) "px"]
[:div.attributes-value (fmt/format-pixels y)]
[:& copy-button {:data (copy-data selrect :y)}]])
(when (ctr/radius-1? shape)
[:div.attributes-unit-row
[:div.attributes-label (tr "handoff.attributes.layout.radius")]
[:div.attributes-value (ust/format-precision (:rx shape 0) 2) "px"]
[:div.attributes-value (fmt/format-pixels (:rx shape 0))]
[:& copy-button {:data (copy-data shape :rx)}]])
(when (ctr/radius-4? shape)
[:div.attributes-unit-row
[:div.attributes-label (tr "handoff.attributes.layout.radius")]
[:div.attributes-value
(ust/format-precision (:r1 shape) 2) ", "
(ust/format-precision (:r2 shape) 2) ", "
(ust/format-precision (:r3 shape) 2) ", "
(ust/format-precision (:r4 shape) 2) "px"]
(fmt/format-number (:r1 shape)) ", "
(fmt/format-number (:r2 shape)) ", "
(fmt/format-number (:r3 shape))", "
(fmt/format-pixels (:r4 shape))]
[:& copy-button {:data (copy-data shape :r1)}]])
(when (not= (:rotation shape 0) 0)
[:div.attributes-unit-row
[:div.attributes-label (tr "handoff.attributes.layout.rotation")]
[:div.attributes-value (ust/format-precision (:rotation shape) 2) "deg"]
[:div.attributes-value (fmt/format-number (:rotation shape)) "deg"]
[:& copy-button {:data (copy-data shape :rotation)}]])]))

View file

@ -8,6 +8,7 @@
(:require
[app.common.data :as d]
[app.common.text :as txt]
[app.main.ui.formats :as fmt]
[app.util.color :as uc]
[cuerdas.core :as str]))
@ -108,7 +109,7 @@
(every? #(or (nil? %) (= % 0)) value)
(or (nil? value) (= value 0))))
default-format (fn [value] (str value "px"))
default-format (fn [value] (str (fmt/format-pixels value)))
format-property (fn [prop]
(let [css-prop (or (prop to-prop) (name prop))
format-fn (or (prop format) default-format)