🐛 Fix numeric values for tokens (#10270)

This commit is contained in:
Alonso Torres 2026-06-18 11:05:14 +02:00 committed by GitHub
parent a7e57c78cf
commit b573a71017
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 25 additions and 3 deletions

View File

@ -222,7 +222,7 @@
(d/without-nils {:name name
:type type
:value value
:value (cond-> value (number? value) str)
:description description})))
;; Token set

View File

@ -25,6 +25,18 @@
(t/testing "doesnt accept invalid double"
(t/is (nil? (cfo/parse-token-value ".3")))))
(t/deftest convert-dtcg-token-test
(t/testing "keeps string scalar values untouched"
(t/is (= {:name "spacing.16" :type :spacing :value "16"}
(cfo/convert-dtcg-token {"name" "spacing.16" "type" "spacing" "value" "16"})))
(t/is (= {:name "spacing.16" :type :spacing :value "16px"}
(cfo/convert-dtcg-token {"name" "spacing.16" "type" "spacing" "value" "16px"}))))
(t/testing "coerces numeric scalar values to strings"
(t/is (= {:name "spacing.16" :type :spacing :value "16"}
(cfo/convert-dtcg-token {"name" "spacing.16" "type" "spacing" "value" 16})))
(t/is (= {:name "radius" :type :border-radius :value "4"}
(cfo/convert-dtcg-token {"name" "radius" "type" "borderRadius" "value" 4})))))
(t/deftest token-applied-test
(t/testing "matches passed token with `:token-attributes`"
(t/is (true? (cfo/token-applied? {:name "a"} {:applied-tokens {:x "a"}} #{:x}))))

View File

@ -5060,12 +5060,18 @@ export interface TokenTypography extends TokenBase {
/**
* Any possible type of value field in a token.
*
* Token values are always stored as strings, including for numeric token
* types such as `spacing`, `dimension` or `borderRadius` (e.g. `"16"` or
* `"16px"`). A plain `number` is also accepted on input and coerced to its
* string representation.
*/
export type TokenValueString =
| TokenShadowValueString
| TokenTypographyValueString
| string
| string[];
| string[]
| number;
/**
* The supported Design Tokens in Penpot.
@ -5193,7 +5199,11 @@ export interface TokenSet {
* @param type The type of the token.
* @param name The name of the token (required). It may contain
* a group path, separated by `.`.
* @param value The value of the token (required), in the string form.
* @param value The value of the token (required), always in its string
* form. This applies to numeric token types too (e.g. `spacing`,
* `dimension`, `borderRadius`): use `"16"` or `"16px"` rather than `16`.
* For convenience a plain number is also accepted and coerced to its
* string representation (`16` becomes `"16"`).
* @return Returns the created Token.
*/
addToken({