🐛 Don't allow letter-spacing value with % (#7100)

This commit is contained in:
Florian Schrödl
2025-08-13 08:31:43 +02:00
committed by GitHub
parent 36bafc0d40
commit ccd6ae5ade
3 changed files with 18 additions and 1 deletions

View File

@@ -133,7 +133,6 @@
:else {:errors [(wte/error-with-value :error.style-dictionary/invalid-token-value value)]})))
(defn- parse-sd-token-stroke-width-value
"Parses `value` of a dimensions `sd-token` into a map like `{:value 1 :unit \"px\"}`.
If the `value` is not parseable and/or has missing references returns a map with `:errors`.
@@ -158,6 +157,15 @@
:else {:errors [(wte/error-with-value :error.style-dictionary/invalid-token-value value)]})))
(defn- parse-sd-token-letter-spacing-value
"Parses `value` of a text-case `sd-token` into a map like `{:value \"1\"}`.
If the `value` is not parseable and/or has missing references returns a map with `:errors`."
[value]
(let [parsed-value (parse-sd-token-general-value value)]
(if (= (:unit parsed-value) "%")
{:errors [(wte/error-with-value :error.style-dictionary/value-with-percent value)]}
parsed-value)))
(defn- parse-sd-token-text-case-value
"Parses `value` of a text-case `sd-token` into a map like `{:value \"uppercase\"}`.
If the `value` is not parseable and/or has missing references returns a map with `:errors`."
@@ -253,6 +261,7 @@
:opacity (parse-sd-token-opacity-value value has-references?)
:stroke-width (parse-sd-token-stroke-width-value value has-references?)
:text-case (parse-sd-token-text-case-value value)
:letter-spacing (parse-sd-token-letter-spacing-value value)
:text-decoration (parse-sd-token-text-decoration-value value)
:font-weight (parse-sd-token-font-weight-value value)
:number (parse-sd-token-number-value value)

View File

@@ -64,6 +64,10 @@
{:error/code :error.style-dictionary/value-with-units
:error/fn #(str (tr "workspace.tokens.value-with-units"))}
:error.style-dictionary/value-with-percent
{:error/code :error.style-dictionary/value-with-percent
:error/fn #(str (tr "workspace.tokens.value-with-percent"))}
:error.style-dictionary/invalid-token-value-opacity
{:error/code :error.style-dictionary/invalid-token-value-opacity
:error/fn #(str/join "\n" [(str (tr "workspace.tokens.invalid-value" %) ".") (tr "workspace.tokens.opacity-range")])}

View File

@@ -7626,6 +7626,10 @@ msgstr "Right click to see options"
msgid "workspace.tokens.value-with-units"
msgstr "Invalid value: Units are not allowed."
#: src/app/main/data/workspace/tokens/errors.cljs:61
msgid "workspace.tokens.value-with-percent"
msgstr "Invalid value: % is not allowed."
#: src/app/main/ui/workspace/tokens/form.cljs:555
msgid "workspace.tokens.warning-name-change"
msgstr "Renaming this token will break any reference to its old name."