diff --git a/frontend/uxbox/data/workspace.cljs b/frontend/uxbox/data/workspace.cljs index f3079526e..be6ae9b58 100644 --- a/frontend/uxbox/data/workspace.cljs +++ b/frontend/uxbox/data/workspace.cljs @@ -29,6 +29,10 @@ :height [v/integer] :lock [v/boolean]}) +(def ^:static +shape-update-fill-schema+ + {:fill [sc/color] + :opacity [v/number]}) + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Events ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -202,10 +206,13 @@ (update-in state [:shapes-by-id sid] shapes/-resize size))))) -(defn update-shape-color - [sid color] - (sc/valid? sc/color color) +(defn update-shape-fill + [sid {:keys [fill opacity] :as opts}] + (sc/validate! +shape-update-fill-schema+ opts) (reify rs/UpdateEvent (-apply-update [_ state] - (assoc-in state [:shapes-by-id sid :fill] color)))) + (update-in state [:shapes-by-id sid] + merge + (when fill {:fill fill}) + (when opacity {:opacity opacity}))))) diff --git a/frontend/uxbox/ui/shapes.cljs b/frontend/uxbox/ui/shapes.cljs index c0445d251..b8e17711a 100644 --- a/frontend/uxbox/ui/shapes.cljs +++ b/frontend/uxbox/ui/shapes.cljs @@ -33,7 +33,8 @@ "Extract predefinet attrs from shapes." [shape] (select-keys shape [:rotation :lock :width :height - :view-box :x :y :cx :cy :fill])) + :view-box :x :y :cx :cy :fill + :opacity])) (defmethod shapes/-render :builtin/icon [{:keys [data id] :as shape} attrs] diff --git a/frontend/uxbox/ui/workspace/options.cljs b/frontend/uxbox/ui/workspace/options.cljs index 1743d423a..60073e266 100644 --- a/frontend/uxbox/ui/workspace/options.cljs +++ b/frontend/uxbox/ui/workspace/options.cljs @@ -47,12 +47,14 @@ (letfn [(on-color-change [event] (let [value (dom/event->value event) sid (:id shape)] - (-> (dw/update-shape-color sid value) + (-> (dw/update-shape-fill sid {:fill value}) (rs/emit!)))) (on-opacity-change [event] (let [value (dom/event->value event) - value (parse-float value 1)] - (println "opacity:" value)))] + value (parse-float value 1) + sid (:id shape)] + (-> (dw/update-shape-fill sid {:opacity value}) + (rs/emit!))))] (html [:div.element-set {:key (str (:id menu))} [:div.element-set-title (:name menu)] @@ -83,7 +85,8 @@ {:type "range" :min "0" :max "1" - :step "0.02" + :value (:opacity shape "1") + :step "0.0001" :on-change on-opacity-change}]]]]))) (defmethod -render-menu :menu/measures