mirror of
https://github.com/penpot/penpot.git
synced 2025-03-13 08:11:30 -05:00
Fix recent colors on shape color picker.
This commit is contained in:
parent
ce5811b86b
commit
390a73eeac
1 changed files with 18 additions and 26 deletions
|
@ -6,17 +6,15 @@
|
||||||
;; Copyright (c) 2015-2016 Juan de la Cruz <delacruzgarciajuan@gmail.com>
|
;; Copyright (c) 2015-2016 Juan de la Cruz <delacruzgarciajuan@gmail.com>
|
||||||
|
|
||||||
(ns uxbox.main.ui.workspace.recent-colors
|
(ns uxbox.main.ui.workspace.recent-colors
|
||||||
(:require [sablono.core :as html :refer-macros [html]]
|
(:require [lentes.core :as l]
|
||||||
[rum.core :as rum]
|
|
||||||
[lentes.core :as l]
|
|
||||||
[uxbox.util.i18n :refer (tr)]
|
|
||||||
[potok.core :as ptk]
|
[potok.core :as ptk]
|
||||||
[uxbox.store :as st]
|
[uxbox.store :as st]
|
||||||
[uxbox.main.data.workspace :as dw]
|
[uxbox.main.data.workspace :as dw]
|
||||||
|
[uxbox.main.ui.workspace.base :as wb]
|
||||||
[uxbox.main.ui.icons :as i]
|
[uxbox.main.ui.icons :as i]
|
||||||
[uxbox.util.mixins :as mx :include-macros true]
|
[uxbox.util.mixins :as mx :include-macros true]
|
||||||
[uxbox.util.dom :as dom]
|
[uxbox.util.dom :as dom]
|
||||||
[uxbox.main.ui.workspace.base :as wb]))
|
[uxbox.util.i18n :refer (tr)]))
|
||||||
|
|
||||||
;; --- Helpers
|
;; --- Helpers
|
||||||
|
|
||||||
|
@ -30,35 +28,29 @@
|
||||||
(defn- calculate-colors
|
(defn- calculate-colors
|
||||||
[shapes]
|
[shapes]
|
||||||
(as-> {} $
|
(as-> {} $
|
||||||
(reduce #(count-color %1 %2 :fill) $ shapes)
|
(reduce #(count-color %1 %2 :fill-color) $ shapes)
|
||||||
(reduce #(count-color %1 %2 :stroke) $ shapes)
|
(reduce #(count-color %1 %2 :stroke-color) $ shapes)
|
||||||
(remove nil? $)
|
(remove nil? $)
|
||||||
(sort-by second (into [] $))
|
(sort-by second (into [] $))
|
||||||
(take 5 (map first $))))
|
(take 5 (map first $))))
|
||||||
|
|
||||||
;; --- Component
|
;; --- Component
|
||||||
|
|
||||||
(defn- recent-colors-render
|
(mx/defc recent-colors
|
||||||
[own {:keys [page id] :as shape} callback]
|
{:mixins [mx/static mx/reactive]}
|
||||||
|
[{:keys [page id] :as shape} callback]
|
||||||
(let [shapes-by-id (mx/react wb/shapes-by-id-ref)
|
(let [shapes-by-id (mx/react wb/shapes-by-id-ref)
|
||||||
shapes (->> (vals shapes-by-id)
|
shapes (->> (vals shapes-by-id)
|
||||||
(filter #(= (:page %) page)))
|
(filter #(= (:page %) page)))
|
||||||
colors (calculate-colors shapes)]
|
colors (calculate-colors shapes)]
|
||||||
(html
|
[:div
|
||||||
[:div
|
[:span (tr "ds.recent-colors")]
|
||||||
[:span (tr "ds.recent-colors")]
|
[:div.row-flex
|
||||||
[:div.row-flex
|
(for [color colors]
|
||||||
(for [color colors]
|
[:span.color-th {:style {:background-color color}
|
||||||
[:span.color-th {:style {:background-color color}
|
:key color
|
||||||
:key color
|
:on-click (partial callback color)}])
|
||||||
:on-click (partial callback color)}])
|
(for [i (range (- 5 (count colors)))]
|
||||||
(for [i (range (- 5 (count colors)))]
|
[:span.color-th {:key (str "empty" i)}])
|
||||||
[:span.color-th {:key (str "empty" i)}])
|
[:span.color-th.palette-th i/picker]]]))
|
||||||
[:span.color-th.palette-th i/picker]]])))
|
|
||||||
|
|
||||||
(def recent-colors
|
|
||||||
(mx/component
|
|
||||||
{:render recent-colors-render
|
|
||||||
:name "recent-colors"
|
|
||||||
:mixins [mx/static mx/reactive]}))
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue