0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-03 04:49:03 -05:00

Make the copy and move tooltip generic for colors page.

This commit is contained in:
Andrey Antukh 2016-11-07 22:13:54 +01:00
parent 151da534c2
commit ec9495a2fc
No known key found for this signature in database
GPG key ID: 4DFEBCB8316A8B95
2 changed files with 34 additions and 37 deletions

View file

@ -179,41 +179,23 @@
{:on-click #(udl/open! :color-form {:coll coll-id})} {:on-click #(udl/open! :color-form {:coll coll-id})}
[:span "+ New color"]]) [:span "+ New color"]])
(mx/defc grid-options-copy (mx/defc grid-options-tooltip
{:mixins [mx/reactive mx/static]} {:mixins [mx/reactive mx/static]}
[current-coll] [& {:keys [selected on-select title]}]
{:pre [(uuid? current-coll)]} {:pre [(uuid? selected)
(fn? on-select)
(string? title)]}
(let [colls (mx/react collections-ref) (let [colls (mx/react collections-ref)
colls (->> (vals colls) colls (->> (vals colls)
(filter #(= :own (:type %))) (filter #(= :own (:type %)))
(remove #(= current-coll (:id %))) (remove #(= selected (:id %)))
(sort-by :name colls)) (sort-by :name colls))
on-select (fn [event id] on-select (fn [event id]
(dom/prevent-default event) (dom/prevent-default event)
(rs/emit! (dc/copy-selected id)))] (dom/stop-propagation event)
(on-select id))]
[:ul.move-list [:ul.move-list
[:li.title "Copy to library"] [:li.title title]
[:li [:a {:href "#" :on-click #(on-select % nil)} "Storage"]]
(for [coll colls
:let [id (:id coll)
name (:name coll)]]
[:li {:key (str id)}
[:a {:on-click #(on-select % id)} name]])]))
(mx/defc grid-options-move
{:mixins [mx/reactive mx/static]}
[current-coll]
{:pre [(uuid? current-coll)]}
(let [colls (mx/react collections-ref)
colls (->> (vals colls)
(filter #(= :own (:type %)))
(remove #(= current-coll (:id %)))
(sort-by :name colls))
on-select (fn [event id]
(dom/prevent-default event)
(rs/emit! (dc/move-selected current-coll id)))]
[:ul.move-list
[:li.title "Move to library"]
[:li [:a {:href "#" :on-click #(on-select % nil)} "Storage"]] [:li [:a {:href "#" :on-click #(on-select % nil)} "Storage"]]
(for [coll colls (for [coll colls
:let [id (:id coll) :let [id (:id coll)
@ -231,13 +213,22 @@
(on-delete [event] (on-delete [event]
(udl/open! :confirm {:on-accept delete})) (udl/open! :confirm {:on-accept delete}))
(on-toggle-copy [event] (on-toggle-copy [event]
(swap! local assoc (swap! local update :show-copy-tooltip not)
:show-copy-tooltip not (swap! local assoc :show-move-tooltip false))
:show-move-tooltip false))
(on-toggle-move [event] (on-toggle-move [event]
(swap! local update :show-move-tooltip not)
(swap! local assoc :show-copy-tooltip false))
(on-copy [selected]
(swap! local assoc (swap! local assoc
:show-move-tooltip not :show-move-tooltip false
:show-copy-tooltip false))] :show-copy-tooltip false)
(rs/emit! (dc/copy-selected selected)))
(on-move [selected]
(swap! local assoc
:show-move-tooltip false
:show-copy-tooltip false)
(rs/emit! (dc/move-selected id selected)))]
;; MULTISELECT OPTIONS BAR ;; MULTISELECT OPTIONS BAR
[:div.multiselect-bar [:div.multiselect-bar
(if editable? (if editable?
@ -245,12 +236,17 @@
[:span.move-item.tooltip.tooltip-top [:span.move-item.tooltip.tooltip-top
{:on-click on-toggle-copy} {:on-click on-toggle-copy}
(when (:show-copy-tooltip @local) (when (:show-copy-tooltip @local)
(grid-options-copy id)) (grid-options-tooltip :selected id
:title "Copy to library"
:on-select on-copy))
i/organize] i/organize]
[:span.move-item.tooltip.tooltip-top [:span.move-item.tooltip.tooltip-top
{:on-click on-toggle-move} {:on-click on-toggle-move}
(when (:show-move-tooltip @local) (when (:show-move-tooltip @local)
(grid-options-move id)) (grid-options-tooltip :selected id
:title "Move to library"
:on-select on-move))
i/organize] i/organize]
[:span.delete.tooltip.tooltip-top [:span.delete.tooltip.tooltip-top
{:alt "Delete" {:alt "Delete"
@ -260,7 +256,9 @@
[:span.move-item.tooltip.tooltip-top [:span.move-item.tooltip.tooltip-top
{:on-click on-toggle-copy} {:on-click on-toggle-copy}
(when (:show-copy-tooltip @local) (when (:show-copy-tooltip @local)
(grid-options-copy id)) (grid-options-tooltip :selected id
:title "Copy to library"
:on-select on-copy))
i/organize]])]))) i/organize]])])))
(mx/defc grid-item (mx/defc grid-item

View file

@ -89,9 +89,8 @@
(dom/prevent-default e) (dom/prevent-default e)
(dom/stop-propagation e) (dom/stop-propagation e)
(on-save e)))) (on-save e))))
(delete [] (delete []
(rs/emit! (di/delete-collection (:id coll)))) (rs/emit! (di/delete-collection id)))
(on-delete [] (on-delete []
(udl/open! :confirm {:on-accept delete}))] (udl/open! :confirm {:on-accept delete}))]
[:div.dashboard-title [:div.dashboard-title