🎉 Add test for token creation (#7915)

This commit is contained in:
Eva Marco
2025-12-10 09:56:21 +01:00
committed by GitHub
parent 8a8f360c7f
commit 179e6a195d
8 changed files with 1339 additions and 89 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -43,8 +43,8 @@
;; 2) Indexed Color Input ;; 2) Indexed Color Input
;; - Used when the tokens value stores an array of items (e.g. inside ;; - Used when the tokens value stores an array of items (e.g. inside
;; shadows, where each shadow layer has its own :color field). ;; shadows, where each shadow layer has its own :color field).
;; - The input writes to a nested subfield: ;; - The input writes to a nested value-subfield:
;; [:value <subfield> <index> :color] ;; [:value <value-subfield> <index> :color]
;; - Only that specific color entry is validated. ;; - Only that specific color entry is validated.
;; - Other properties (offsets, blur, inset, etc.) remain untouched. ;; - Other properties (offsets, blur, inset, etc.) remain untouched.
;; ;;
@@ -436,19 +436,21 @@
(some? error) (some? error)
(let [error' (:message error)] (let [error' (:message error)]
(swap! form assoc-in [:extra-errors :value value-subfield index input-name] {:message error'}) (do
(swap! form assoc-in [:data :value value-subfield index :color-result] "") (swap! form assoc-in [:extra-errors :value value-subfield index input-name] {:message error'})
(reset! hint* {:message error' :type "error"})) (swap! form assoc-in [:data :value value-subfield index :color-result] "")
(reset! hint* {:message error' :type "error"})))
:else :else
(let [message (tr "workspace.tokens.resolved-value" (dwtf/format-token-value value)) (let [message (tr "workspace.tokens.resolved-value" (dwtf/format-token-value value))
input-value (get-in @form [:data :value value-subfield index input-name] "")] input-value (get-in @form [:data :value value-subfield index input-name] "")]
(swap! form update :errors dissoc :value) (do
(swap! form update :extra-errors dissoc :value) (swap! form update :errors dissoc :value)
(swap! form assoc-in [:data :value value-subfield index :color-result] (dwtf/format-token-value value)) (swap! form update :extra-errors dissoc :value)
(if (= input-value (str value)) (swap! form assoc-in [:data :value value-subfield index :color-result] (dwtf/format-token-value value))
(reset! hint* {}) (if (= input-value (str value))
(reset! hint* {:message message :type "hint"})))))))] (reset! hint* {})
(reset! hint* {:message message :type "hint"}))))))))]
(fn [] (fn []
(rx/dispose! subs)))) (rx/dispose! subs))))

View File

@@ -41,7 +41,7 @@
;; 2) Composite Font Picker ;; 2) Composite Font Picker
;; - Used inside typography tokens, where `:value` is a map (e.g. contains ;; - Used inside typography tokens, where `:value` is a map (e.g. contains
;; :font-family, :font-weight, :letter-spacing, etc.). ;; :font-family, :font-weight, :letter-spacing, etc.).
;; - The input writes to the specific subfield `[:value :font-family]`. ;; - The input writes to the specific value-subfield `[:value :font-family]`.
;; - Only this field is validated and updated—other typography fields remain ;; - Only this field is validated and updated—other typography fields remain
;; untouched. ;; untouched.
;; ;;

View File

@@ -48,7 +48,7 @@
;; 2) COMPOSITE INPUTS ;; 2) COMPOSITE INPUTS
;; ---------------------------------------------------------- ;; ----------------------------------------------------------
;; Used when the token contains a set of *named fields* inside :value. ;; Used when the token contains a set of *named fields* inside :value.
;; The UI must write into a specific subfield inside the :value map. ;; The UI must write into a specific value-subfield inside the :value map.
;; ;;
;; Example: typography tokens ;; Example: typography tokens
;; {:value {:font-family "Inter" ;; {:value {:font-family "Inter"
@@ -64,7 +64,7 @@
;; * Validation rules apply per-field. ;; * Validation rules apply per-field.
;; ;;
;; In practice: ;; In practice:
;; - The component knows which subfield to update. ;; - The component knows which value-subfield to update.
;; - The form accumulates multiple fields into a single map under :value. ;; - The form accumulates multiple fields into a single map under :value.
;; ;;
;; ;;

View File

@@ -13,10 +13,10 @@
;; --- Select Input (Indexed) -------------------------------------------------- ;; --- Select Input (Indexed) --------------------------------------------------
;; ;;
;; This input type is part of the indexed system, used for fields that exist ;; This input type is part of the indexed system, used for fields that exist
;; inside an array of maps stored in a subfield of :value. ;; inside an array of maps stored in a value-subfield of :value.
;; ;;
;; - Writes to a nested location: ;; - Writes to a nested location:
;; [:value <subfield> <index> <field>] ;; [:value <value-subfield> <index> <field>]
;; - Each item in the array has its own select input, independent of others. ;; - Each item in the array has its own select input, independent of others.
;; - Validation ensures the selected value is valid for that field. ;; - Validation ensures the selected value is valid for that field.
;; - Changing one item does not affect the other items in the array. ;; - Changing one item does not affect the other items in the array.

View File

@@ -230,16 +230,29 @@
{:level :warning :appearance :ghost} (tr "workspace.tokens.warning-name-change")]])] {:level :warning :appearance :ghost} (tr "workspace.tokens.warning-name-change")]])]
[:div {:class (stl/css :input-row)} [:div {:class (stl/css :input-row)}
[:> input-component (case type
{:placeholder (or input-value-placeholder (tr "workspace.tokens.token-value-enter")) :indexed
:label (tr "workspace.tokens.token-value") [:> input-component
:name :value {:token token
:form form :tokens tokens
:token token :tab active-tab
:tokens tokens :value-subfield value-subfield
:tab active-tab :handle-toggle on-toggle-tab}]
:subfield value-subfield
:toggle on-toggle-tab}]] :composite
[:> input-component
{:token token
:tokens tokens
:tab active-tab
:handle-toggle on-toggle-tab}]
[:> input-component
{:placeholder (or input-value-placeholder
(tr "workspace.tokens.token-value-enter"))
:label (tr "workspace.tokens.token-value")
:name :value
:token token
:tokens tokens}])]
[:div {:class (stl/css :input-row)} [:div {:class (stl/css :input-row)}
[:> fc/form-input* {:id "token-description" [:> fc/form-input* {:id "token-description"

View File

@@ -208,19 +208,20 @@
:tokens tokens}]]) :tokens tokens}]])
(mf/defc tabs-wrapper* (mf/defc tabs-wrapper*
[{:keys [token tokens form tab toggle subfield] :rest props}] [{:keys [token tokens tab handle-toggle value-subfield] :rest props}]
(let [on-add-shadow-block (let [form (mf/use-ctx forms/context)
on-add-shadow-block
(mf/use-fn (mf/use-fn
(mf/deps subfield) (mf/deps value-subfield)
(fn [] (fn []
(swap! form update-in [:data :value subfield] conj default-token-shadow))) (swap! form update-in [:data :value value-subfield] conj default-token-shadow)))
remove-shadow-block remove-shadow-block
(mf/use-fn (mf/use-fn
(mf/deps subfield) (mf/deps value-subfield)
(fn [index event] (fn [index event]
(dom/prevent-default event) (dom/prevent-default event)
(swap! form update-in [:data :value subfield] #(d/remove-at-index % index))))] (swap! form update-in [:data :value value-subfield] #(d/remove-at-index % index))))]
[:* [:*
[:div {:class (stl/css :title-bar)} [:div {:class (stl/css :title-bar)}
@@ -232,7 +233,7 @@
:icon i/add}] :icon i/add}]
[:& radio-buttons {:class (stl/css :listing-options) [:& radio-buttons {:class (stl/css :listing-options)
:selected (d/name tab) :selected (d/name tab)
:on-change toggle :on-change handle-toggle
:name "reference-composite-tab"} :name "reference-composite-tab"}
[:& radio-button {:icon i/layers [:& radio-button {:icon i/layers
:value "composite" :value "composite"
@@ -247,7 +248,7 @@
[:> composite-form* {:token token [:> composite-form* {:token token
:tokens tokens :tokens tokens
:remove-shadow-block remove-shadow-block :remove-shadow-block remove-shadow-block
:value-subfield subfield}] :value-subfield value-subfield}]
[:> reference-form* {:token token [:> reference-form* {:token token
:tokens tokens}])])) :tokens tokens}])]))

View File

@@ -181,13 +181,13 @@
:tokens tokens}]]) :tokens tokens}]])
(mf/defc tabs-wrapper* (mf/defc tabs-wrapper*
[{:keys [token tokens tab toggle] :rest props}] [{:keys [token tokens tab handle-toggle] :rest props}]
[:* [:*
[:div {:class (stl/css :title-bar)} [:div {:class (stl/css :title-bar)}
[:div {:class (stl/css :title)} (tr "labels.typography")] [:div {:class (stl/css :title)} (tr "labels.typography")]
[:& radio-buttons {:class (stl/css :listing-options) [:& radio-buttons {:class (stl/css :listing-options)
:selected (d/name tab) :selected (d/name tab)
:on-change toggle :on-change handle-toggle
:name "reference-composite-tab"} :name "reference-composite-tab"}
[:& radio-button {:icon i/layers [:& radio-button {:icon i/layers
:value "composite" :value "composite"