0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-01 20:09:04 -05:00

Restore token saving

This commit is contained in:
Florian Schroedl 2024-06-25 11:15:43 +02:00
parent ca98747dea
commit 33131fa943
2 changed files with 24 additions and 21 deletions

View file

@ -8,6 +8,9 @@
(:require-macros [app.main.style :as stl]) (:require-macros [app.main.style :as stl])
(:require (:require
["lodash.debounce" :as debounce] ["lodash.debounce" :as debounce]
[app.main.data.modal :as modal]
[app.main.data.tokens :as dt]
[app.main.store :as st]
[app.main.ui.workspace.tokens.common :as tokens.common] [app.main.ui.workspace.tokens.common :as tokens.common]
[app.main.ui.workspace.tokens.style-dictionary :as sd] [app.main.ui.workspace.tokens.style-dictionary :as sd]
[app.util.dom :as dom] [app.util.dom :as dom]
@ -47,12 +50,11 @@
(seq (finalize-name (str name)))) (seq (finalize-name (str name))))
(defn finalize-value [value] (defn finalize-value [value]
(str/trim value)) (-> (str value)
(str/trim)))
(defn valid-value? [value] (defn valid-value? [value]
(-> (str value) (seq (finalize-value value)))
(finalize-value)
(seq)))
;; Component ------------------------------------------------------------------- ;; Component -------------------------------------------------------------------
@ -107,7 +109,7 @@
(mf/defc form (mf/defc form
{::mf/wrap-props false} {::mf/wrap-props false}
[{:keys [token] :as _args}] [{:keys [token token-type] :as _args}]
(let [tokens (sd/use-resolved-workspace-tokens) (let [tokens (sd/use-resolved-workspace-tokens)
existing-token-names (mf/use-memo existing-token-names (mf/use-memo
(mf/deps tokens) (mf/deps tokens)
@ -178,22 +180,22 @@
;; Form ;; Form
disabled? (or (not valid-name-field?) disabled? (or (not valid-name-field?)
(not valid-value-field?) (not valid-value-field?)
(not valid-description-field?))] (not valid-description-field?))
;; on-submit (fn [e] on-submit (mf/use-callback
;; (dom/prevent-default e) (fn [e]
;; (let [token-value (-> (fields->map state) (js/console.log "@value-ref" @value-ref (finalize-value @value-ref))
;; (first) (dom/prevent-default e)
;; (val)) (let [token (cond-> {:name (finalize-name @name-ref)
;; token (cond-> {:name (:name state) :type (or (:type token) token-type)
;; :type (or (:type token) token-type) :value (finalize-value @value-ref)}
;; :value token-value @description-ref (assoc :description @description-ref)
;; :description (:description state)} (:id token) (assoc :id (:id token)))]
;; (:id token) (assoc :id (:id token)))] (js/console.log "token" token)
;; (st/emit! (dt/add-token token)) (st/emit! (dt/add-token token))
;; (modal/hide!)))] (modal/hide!))))]
[:form [:form
{#_#_:on-submit on-submit} {:on-submit on-submit}
[:div {:class (stl/css :token-rows)} [:div {:class (stl/css :token-rows)}
[:div [:div
[:& tokens.common/labeled-input {:label "Name" [:& tokens.common/labeled-input {:label "Name"

View file

@ -39,12 +39,13 @@
(mf/defc modal (mf/defc modal
{::mf/wrap-props false} {::mf/wrap-props false}
[{:keys [x y position token] :as _args}] [{:keys [x y position token token-type] :as _args}]
(let [wrapper-style (use-viewport-position-style x y position)] (let [wrapper-style (use-viewport-position-style x y position)]
[:div [:div
{:class (stl/css :shadow) {:class (stl/css :shadow)
:style wrapper-style} :style wrapper-style}
[:& form {:token token}]])) [:& form {:token token
:token-type token-type}]]))
;; Modals ---------------------------------------------------------------------- ;; Modals ----------------------------------------------------------------------