mirror of
https://github.com/penpot/penpot.git
synced 2025-05-10 22:26:38 +02:00
♻️ Refactor code style on actionable ds component
This commit is contained in:
parent
f98dbef228
commit
f9f5f0af7d
2 changed files with 26 additions and 23 deletions
|
@ -17,34 +17,37 @@
|
||||||
[:class {:optional true} :string]
|
[:class {:optional true} :string]
|
||||||
[:variant {:optional true}
|
[:variant {:optional true}
|
||||||
[:maybe [:enum "default" "error"]]]
|
[:maybe [:enum "default" "error"]]]
|
||||||
[:acceptLabel {:optional true} :string]
|
[:accept-label {:optional true} :string]
|
||||||
[:cancelLabel {:optional true} :string]
|
[:cancel-label {:optional true} :string]
|
||||||
[:onAccept {:optional true} [:fn fn?]]
|
[:on-accept {:optional true} [:fn fn?]]
|
||||||
[:onCancel {:optional true} [:fn fn?]]])
|
[:on-cancel {:optional true} [:fn fn?]]])
|
||||||
|
|
||||||
(mf/defc actionable*
|
(mf/defc actionable*
|
||||||
{::mf/props :obj
|
{::mf/schema schema:actionable}
|
||||||
::mf/schema schema:actionable}
|
[{:keys [class variant accept-label cancel-label children on-accept on-cancel] :rest props}]
|
||||||
[{:keys [class variant acceptLabel cancelLabel children onAccept onCancel] :rest props}]
|
|
||||||
|
|
||||||
(let [variant (or variant "default")
|
(let [variant (d/nilv variant "default")
|
||||||
class (d/append-class class (stl/css :notification))
|
class (d/append-class class (stl/css :notification))
|
||||||
props (mf/spread-props props {:class class :data-testid "actionable"})
|
props (mf/spread-props props
|
||||||
|
{:class class
|
||||||
|
:data-testid "actionable"})
|
||||||
|
|
||||||
handle-accept
|
on-accept
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
(fn [e]
|
(fn [e]
|
||||||
(when onAccept (onAccept e))))
|
(when (fn? on-accept)
|
||||||
|
(on-accept e))))
|
||||||
|
|
||||||
handle-cancel
|
on-cancel
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
(fn [e]
|
(fn [e]
|
||||||
(when onCancel (onCancel e))))]
|
(when on-cancel (on-cancel e))))]
|
||||||
|
|
||||||
[:> "aside" props
|
[:> :aside props
|
||||||
[:div {:class (stl/css :notification-message)}
|
[:div {:class (stl/css :notification-message)} children]
|
||||||
children]
|
|
||||||
[:> button* {:variant "secondary"
|
[:> button* {:variant "secondary"
|
||||||
:on-click handle-cancel} cancelLabel]
|
:on-click on-cancel}
|
||||||
|
cancel-label]
|
||||||
[:> button* {:variant (if (= variant "default") "primary" "destructive")
|
[:> button* {:variant (if (= variant "default") "primary" "destructive")
|
||||||
:on-click handle-accept} acceptLabel]]))
|
:on-click on-accept}
|
||||||
|
accept-label]]))
|
||||||
|
|
|
@ -21,10 +21,10 @@
|
||||||
[{:keys [content accept cancel links] :as props}]
|
[{:keys [content accept cancel links] :as props}]
|
||||||
|
|
||||||
[:> actionable* {:class (stl/css :new-inline)
|
[:> actionable* {:class (stl/css :new-inline)
|
||||||
:cancelLabel (:label cancel)
|
:cancel-label (:label cancel)
|
||||||
:onCancel (:callback cancel)
|
:on-cancel (:callback cancel)
|
||||||
:acceptLabel (:label accept)
|
:accept-label (:label accept)
|
||||||
:onAccept (:callback accept)}
|
:on-accept (:callback accept)}
|
||||||
content
|
content
|
||||||
|
|
||||||
(when (some? links)
|
(when (some? links)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue