mirror of
https://github.com/penpot/penpot.git
synced 2026-09-07 04:29:31 +00:00
Add workspace specific colorpicker.
This commit is contained in:
parent
75995c8cf7
commit
5da652a794
65
src/uxbox/ui/workspace/colorpicker.cljs
Normal file
65
src/uxbox/ui/workspace/colorpicker.cljs
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
;;
|
||||||
|
;; Copyright (c) 2016 Andrey Antukh <niwi@niwi.nz>
|
||||||
|
;; Copyright (c) 2016 Juan de la Cruz <delacruzgarciajuan@gmail.com>
|
||||||
|
|
||||||
|
(ns uxbox.ui.workspace.colorpicker
|
||||||
|
(:require [sablono.core :as html :refer-macros [html]]
|
||||||
|
[rum.core :as rum]
|
||||||
|
[lentes.core :as l]
|
||||||
|
[uxbox.locales :refer (tr)]
|
||||||
|
[uxbox.router :as r]
|
||||||
|
[uxbox.rstore :as rs]
|
||||||
|
[uxbox.state :as st]
|
||||||
|
[uxbox.data.workspace :as udw]
|
||||||
|
[uxbox.data.shapes :as uds]
|
||||||
|
[uxbox.ui.workspace.base :as wb]
|
||||||
|
[uxbox.ui.icons :as i]
|
||||||
|
[uxbox.ui.mixins :as mx]
|
||||||
|
[uxbox.ui.lightbox :as lbx]
|
||||||
|
[uxbox.ui.colorpicker :as cp]
|
||||||
|
[uxbox.ui.workspace.recent-colors :refer (recent-colors)]
|
||||||
|
[uxbox.ui.workspace.base :as wb]
|
||||||
|
[uxbox.util.geom :as geom]
|
||||||
|
[uxbox.util.dom :as dom]
|
||||||
|
[uxbox.util.data :refer (parse-int parse-float read-string)]))
|
||||||
|
|
||||||
|
(defn- colorpicker-render
|
||||||
|
[own {:keys [x y shape] :as opts}]
|
||||||
|
(println opts)
|
||||||
|
(let [shape {}
|
||||||
|
on-change (constantly nil)
|
||||||
|
left (- x 260)
|
||||||
|
top (- y 150)]
|
||||||
|
(letfn [(on-color-change [event]
|
||||||
|
(let [value (dom/event->value event)]
|
||||||
|
(on-change {:color value})))]
|
||||||
|
(html
|
||||||
|
;; COLOR PICKER TOOLTIP
|
||||||
|
[:div.colorpicker-tooltip
|
||||||
|
{:style {:left (str left "px")
|
||||||
|
:top (str top "px")}}
|
||||||
|
|
||||||
|
(cp/colorpicker
|
||||||
|
:theme :small
|
||||||
|
:value (:stroke shape "#000000")
|
||||||
|
:on-change (constantly nil))
|
||||||
|
|
||||||
|
(recent-colors shape (constantly nil) #_#(change-stroke {:color %}))
|
||||||
|
|
||||||
|
#_[:span "Color options"]
|
||||||
|
#_[:div.row-flex
|
||||||
|
[:span.color-th.palette-th i/picker]
|
||||||
|
[:span.color-th.palette-th i/palette]]]))))
|
||||||
|
|
||||||
|
(def colorpicker
|
||||||
|
(mx/component
|
||||||
|
{:render colorpicker-render
|
||||||
|
:name "colorpicker"
|
||||||
|
:mixins []}))
|
||||||
|
|
||||||
|
(defmethod lbx/render-lightbox :workspace/colorpicker
|
||||||
|
[params]
|
||||||
|
(colorpicker params))
|
||||||
@ -16,6 +16,7 @@
|
|||||||
[uxbox.library :as library]
|
[uxbox.library :as library]
|
||||||
[uxbox.data.workspace :as udw]
|
[uxbox.data.workspace :as udw]
|
||||||
[uxbox.data.shapes :as uds]
|
[uxbox.data.shapes :as uds]
|
||||||
|
[uxbox.data.lightbox :as udl]
|
||||||
[uxbox.ui.icons :as i]
|
[uxbox.ui.icons :as i]
|
||||||
[uxbox.ui.mixins :as mx]
|
[uxbox.ui.mixins :as mx]
|
||||||
[uxbox.ui.workspace.colorpicker :refer (colorpicker)]
|
[uxbox.ui.workspace.colorpicker :refer (colorpicker)]
|
||||||
@ -44,7 +45,11 @@
|
|||||||
(on-stroke-style-change [event]
|
(on-stroke-style-change [event]
|
||||||
(let [value (dom/event->value event)
|
(let [value (dom/event->value event)
|
||||||
value (read-string value)]
|
value (read-string value)]
|
||||||
(change-stroke {:type value})))]
|
(change-stroke {:type value})))
|
||||||
|
(show-color-picker [event]
|
||||||
|
(let [x (.-screenX event)
|
||||||
|
y (.-screenY event)]
|
||||||
|
(udl/open! :workspace/colorpicker {:x x :y y :shape shape})))]
|
||||||
(let [local (:rum/local own)]
|
(let [local (:rum/local own)]
|
||||||
(html
|
(html
|
||||||
[:div.element-set {:key (str (:id menu))}
|
[:div.element-set {:key (str (:id menu))}
|
||||||
@ -70,13 +75,12 @@
|
|||||||
;; SLIDEBAR FOR ROTATION AND OPACITY
|
;; SLIDEBAR FOR ROTATION AND OPACITY
|
||||||
[:span "Color"]
|
[:span "Color"]
|
||||||
|
|
||||||
;; ;; HERE COLOR PICKER
|
|
||||||
|
|
||||||
[:div.row-flex.color-data
|
[:div.row-flex.color-data
|
||||||
[:span.color-th]
|
[:span.color-th
|
||||||
|
{:style {:background-color (:stroke shape)}
|
||||||
|
:on-click show-color-picker}]
|
||||||
[:div.color-info
|
[:div.color-info
|
||||||
[:span.type "#"]
|
[:span (:stroke shape)]]]
|
||||||
[:span.number "F1F1F1"]]]
|
|
||||||
|
|
||||||
;; SLIDEBAR FOR ROTATION AND OPACITY
|
;; SLIDEBAR FOR ROTATION AND OPACITY
|
||||||
[:span "Opacity"]
|
[:span "Opacity"]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user