mirror of
https://github.com/penpot/penpot.git
synced 2025-01-07 15:39:42 -05:00
Extract component
This commit is contained in:
parent
b61a59d375
commit
85a40d19ed
1 changed files with 27 additions and 20 deletions
|
@ -37,6 +37,27 @@
|
||||||
:else new-value)]
|
:else new-value)]
|
||||||
(set-value! new-value)))))
|
(set-value! new-value)))))
|
||||||
|
|
||||||
|
(mf/defc dropdown-select [{:keys [on-close element-id element-ref options on-select]}]
|
||||||
|
[:& dropdown {:show true
|
||||||
|
:on-close on-close}
|
||||||
|
[:div {:class (stl/css :custom-select-dropdown)
|
||||||
|
:ref element-ref}
|
||||||
|
[:ul {:class (stl/css :custom-select-dropdown-list)}
|
||||||
|
(for [[index item] (d/enumerate options)]
|
||||||
|
(cond
|
||||||
|
(= :separator item) [:li {:class (stl/css :separator)
|
||||||
|
:key (dm/str element-id "-" index)}]
|
||||||
|
:else (let [{:keys [value label]} item]
|
||||||
|
[:li
|
||||||
|
{:key (str element-id "-" index)
|
||||||
|
:class (stl/css-case :dropdown-element true
|
||||||
|
:is-selected false #_(= (dm/str value) current-value))
|
||||||
|
:data-label label
|
||||||
|
:on-click on-select}
|
||||||
|
[:span {:class (stl/css :label)} label]
|
||||||
|
[:span {:class (stl/css :value)} value]
|
||||||
|
[:span {:class (stl/css :check-icon)} i/tick]])))]]])
|
||||||
|
|
||||||
(mf/defc editable-select
|
(mf/defc editable-select
|
||||||
[{:keys [value type options class on-change placeholder on-blur input-class] :as params}]
|
[{:keys [value type options class on-change placeholder on-blur input-class] :as params}]
|
||||||
(let [state* (mf/use-state {:id (uuid/next)
|
(let [state* (mf/use-state {:id (uuid/next)
|
||||||
|
@ -187,23 +208,9 @@
|
||||||
:on-click toggle-dropdown}
|
:on-click toggle-dropdown}
|
||||||
i/arrow])
|
i/arrow])
|
||||||
|
|
||||||
[:& dropdown {:show (or is-open? false)
|
(when (and is-open? (seq options))
|
||||||
:on-close close-dropdown}
|
[:& dropdown-select {:on-close close-dropdown
|
||||||
[:div {:class (stl/css :custom-select-dropdown)
|
:element-id element-id
|
||||||
:ref select-wrapper-ref}
|
:element-ref select-wrapper-ref
|
||||||
[:ul {:class (stl/css :custom-select-dropdown-list)}
|
:options options
|
||||||
(for [[index item] (d/enumerate options)]
|
:on-select select-item}])]))
|
||||||
(cond
|
|
||||||
(= :separator item) [:li {:class (stl/css :separator)
|
|
||||||
:key (dm/str element-id "-" index)}]
|
|
||||||
:else (let [{:keys [value label]} item]
|
|
||||||
[:li
|
|
||||||
{:key (str element-id "-" index)
|
|
||||||
:class (stl/css-case :dropdown-element true
|
|
||||||
:is-selected (= (dm/str value) current-value))
|
|
||||||
:data-label label
|
|
||||||
:on-click select-item}
|
|
||||||
[:span {:class (stl/css :label)} label]
|
|
||||||
[:span {:class (stl/css :value)} value]
|
|
||||||
[:span {:class (stl/css :check-icon)}
|
|
||||||
i/tick]])))]]]]))
|
|
||||||
|
|
Loading…
Reference in a new issue