mirror of
https://github.com/penpot/penpot.git
synced 2025-02-13 10:38:13 -05:00
🐛 Fix Apply library colors to gradient points
This commit is contained in:
parent
b2d8f807f9
commit
f6ff80a3d4
2 changed files with 42 additions and 6 deletions
|
@ -88,9 +88,44 @@
|
|||
|
||||
on-select-library-color
|
||||
(mf/use-fn
|
||||
(fn [color]
|
||||
(st/emit! (dc/update-colorpicker color))
|
||||
(on-change color)))
|
||||
(fn [state color]
|
||||
(let [type-origin (:type state)
|
||||
editig-stop-origin (:editing-stop state)
|
||||
is-gradient? (some? (:gradient color))
|
||||
change-to (fn [new-color]
|
||||
(st/emit! (dc/update-colorpicker new-color))
|
||||
(on-change new-color))
|
||||
clean-stop (fn [stops index color]
|
||||
(-> (nth stops index)
|
||||
(merge color)
|
||||
(assoc :offset index)
|
||||
(dissoc :r)
|
||||
(dissoc :g)
|
||||
(dissoc :b)
|
||||
(dissoc :alpha)
|
||||
(dissoc :s)
|
||||
(dissoc :h)
|
||||
(dissoc :v)
|
||||
(dissoc :hex)))
|
||||
set-new-gradient (fn [state color index]
|
||||
(let [old-stops (:stops state)
|
||||
old-gradient (:gradient state)
|
||||
new-gradient (-> old-gradient
|
||||
(cond-> (= index 0) (assoc :stops [(clean-stop old-stops 0 color) (nth old-stops 1)]))
|
||||
(cond-> (= index 1) (assoc :stops [(nth old-stops 0) (clean-stop old-stops 1 color)]))
|
||||
(dissoc :shape-id))]
|
||||
(change-to {:gradient new-gradient})))]
|
||||
;; If we have any kind of gradient and:
|
||||
;; Click on a solid color -> This color is applied to the selected offset
|
||||
;; Click on a color with transparency -> The same to solid color will happend
|
||||
;; Click on any kind of gradient -> The color changes completly to new gradient
|
||||
|
||||
;; If we have a non gradient color the new color is applied without any change
|
||||
(if (or (= :radial-gradient type-origin) (= :linear-gradient type-origin))
|
||||
(if is-gradient?
|
||||
(change-to color)
|
||||
(set-new-gradient state color editig-stop-origin))
|
||||
(change-to color)))))
|
||||
|
||||
on-add-library-color
|
||||
(mf/use-fn
|
||||
|
@ -230,7 +265,8 @@
|
|||
:on-change handle-change-color}]
|
||||
|
||||
[:& libraries
|
||||
{:current-color current-color
|
||||
{:state state
|
||||
:current-color current-color
|
||||
:disable-gradient disable-gradient
|
||||
:disable-opacity disable-opacity
|
||||
:on-select-color on-select-library-color
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
[rumext.v2 :as mf]))
|
||||
|
||||
(mf/defc libraries
|
||||
[{:keys [on-select-color on-add-library-color disable-gradient disable-opacity]}]
|
||||
[{:keys [state on-select-color on-add-library-color disable-gradient disable-opacity]}]
|
||||
(let [selected (h/use-shared-state mdc/colorpicker-selected-broadcast-key :recent)
|
||||
current-colors (mf/use-state [])
|
||||
|
||||
|
@ -88,4 +88,4 @@
|
|||
[:& color-bullet
|
||||
{:key (dm/str "color-" idx)
|
||||
:color color
|
||||
:on-click on-select-color}])]]))
|
||||
:on-click (partial on-select-color state)}])]]))
|
||||
|
|
Loading…
Add table
Reference in a new issue