♻️ Refactor shape options sidebar.

This commit is contained in:
Andrey Antukh 2020-04-07 19:52:37 +02:00
parent 8b7d613b99
commit 54f6e7cc9e
11 changed files with 378 additions and 268 deletions

View file

@ -2,8 +2,10 @@
;; 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) 2015-2016 Juan de la Cruz <delacruzgarciajuan@gmail.com>
;; Copyright (c) 2015-2019 Andrey Antukh <niwi@niwi.nz>
;; This Source Code Form is "Incompatible With Secondary Licenses", as
;; defined by the Mozilla Public License, v. 2.0.
;;
;; Copyright (c) 2020 UXBOX Labs SL
(ns uxbox.main.ui.workspace.sidebar.options.circle
(:require
@ -17,12 +19,14 @@
[uxbox.main.ui.workspace.sidebar.options.stroke :refer [stroke-menu]]
[uxbox.util.dom :as dom]
[uxbox.util.geom.point :as gpt]
[uxbox.util.i18n :refer [tr]]
[uxbox.util.math :as math :refer (precision-or-0)]))
[uxbox.util.i18n :as i18n :refer [tr t]]
[uxbox.util.math :as math]))
(mf/defc measures-menu
[{:keys [shape] :as props}]
(let [on-size-change
(let [locale (i18n/use-locale)
on-size-change
(fn [event attr]
(let [value (-> (dom/get-target event)
(dom/get-value)
@ -40,7 +44,7 @@
(fn [event attr]
(let [value (-> (dom/get-target event)
(dom/get-value)
(d/parse-integer))]
(d/parse-integer 0))]
(st/emit! (udw/update-position (:id shape) {attr value}))))
on-pos-cx-change #(on-position-change % :x)
@ -57,71 +61,83 @@
(fn [event]
(let [value (-> (dom/get-target event)
(dom/get-value)
(d/parse-double 0))]
(d/parse-integer 0))]
(st/emit! (udw/update-shape (:id shape) {:rx value :ry value}))))]
[:div.element-set
[:div.element-set-title (tr "workspace.options.measures")]
[:div.element-set-content
;; SIZE
[:span (tr "workspace.options.size")]
[:div.row-flex
[:div.input-element.pixels
[:input.input-text {:type "number"
:min "0"
:on-change on-size-rx-change
:value (-> (:rx shape)
(math/precision 2)
(d/coalesce-str "0"))}]]
[:span.element-set-subtitle (t locale "workspace.options.size")]
[:div.lock-size {:class (when (:proportion-lock shape) "selected")
:on-click on-proportion-lock-change}
(if (:proportion-lock shape)
i/lock
i/unlock)]
[:div.input-element.pixels
[:input.input-text {:type "number"
:min "0"
:on-change on-size-rx-change
:value (str (-> (:rx shape)
(d/coalesce 0)
(math/round)))}]]
[:div.input-element.pixels
[:input.input-text {:type "number"
:min "0"
:on-change on-size-ry-change
:value (-> (:ry shape)
(math/precision 2)
(d/coalesce-str "0"))}]]]
:value (str (-> (:ry shape)
(d/coalesce 0)
(math/round)))}]]]
;; POSITION
[:span (tr "workspace.options.position")]
[:div.row-flex
[:span.element-set-subtitle (t locale "workspace.options.position")]
[:div.input-element.pixels
[:input.input-text {:type "number"
:on-change on-pos-cx-change
:value (-> (:cx shape)
(math/precision 2)
(d/coalesce-str "0"))}]]
:value (str (-> (:cx shape)
(d/coalesce 0)
(math/round)))}]]
[:div.input-element.pixels
[:input.input-text {:type "number"
:on-change on-pos-cy-change
:value (-> (:cy shape)
(math/precision 2)
(d/coalesce-str "0"))}]]]
;; ROTATION & RADIUS
[:span (tr "workspace.options.rotation-radius")]
[:div.row-flex
[:div.input-element.degrees
[:input.input-text {:placeholder ""
:type "number"
:min 0
:max 360
:on-change on-rotation-change
:value (-> (:rotation shape)
(math/precision 2)
(d/coalesce-str "0"))}]]
:value (str (-> (:cy shape)
(d/coalesce 0)
(math/round)))}]]]
[:div.row-flex
[:span.element-set-subtitle (t locale "workspace.options.rotation")]
[:div.input-element.degrees
[:input.input-text
{:type "number"
:min "0"
:max "360"
:on-change on-rotation-change
:value (str (-> (:rotation shape)
(d/coalesce 0)
(math/round)))}]]
[:input.slidebar
{:type "range"
:min "0"
:max "360"
:on-change on-rotation-change
:value (str (-> (:rotation shape)
(d/coalesce 0)
(math/round)))
:step "1"}]]
[:div.row-flex
[:span.element-set-subtitle (t locale "workspace.options.radius")]
[:div.input-element.pixels
[:input.input-text {:type "number"
:on-change on-radius-change
:value (-> (:rx shape)
(math/precision 2)
(d/coalesce-str "0"))}]]]]]))
[:input.input-text
{:type "number"
:on-change on-radius-change
:value (str (-> (:rx shape)
(d/coalesce 0)
(math/round)))}]]
[:div.input-element]]]]))
(mf/defc options
[{:keys [shape] :as props}]

View file

@ -2,8 +2,10 @@
;; 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) 2015-2017 Juan de la Cruz <delacruzgarciajuan@gmail.com>
;; Copyright (c) 2015-2019 Andrey Antukh <niwi@niwi.nz>
;; This Source Code Form is "Incompatible With Secondary Licenses", as
;; defined by the Mozilla Public License, v. 2.0.
;;
;; Copyright (c) 2020 UXBOX Labs SL
(ns uxbox.main.ui.workspace.sidebar.options.fill
(:require
@ -15,52 +17,66 @@
[uxbox.main.ui.modal :as modal]
[uxbox.main.ui.workspace.colorpicker :refer [colorpicker-modal]]
[uxbox.util.dom :as dom]
[uxbox.util.i18n :refer [tr]]))
[uxbox.util.math :as math]
[uxbox.util.i18n :as i18n :refer [tr t]]))
(mf/defc fill-menu
[{:keys [shape] :as props}]
(letfn [(update-shape! [attr value]
(st/emit! (udw/update-shape (:id shape) {attr value})))
(on-color-change [event]
(let [value (-> (dom/get-target event)
(dom/get-value))]
(update-shape! :fill-color value)))
(on-opacity-change [event]
(let [value (-> (dom/get-target event)
(dom/get-value)
(d/parse-double 1)
(/ 10000))]
(update-shape! :fill-opacity value)))
(show-color-picker [event]
(let [x (.-clientX event)
y (.-clientY event)
props {:x x :y y
:on-change #(update-shape! :fill-color %)
:default "#ffffff"
:value (:fill-color shape)
:transparent? true}]
(modal/show! colorpicker-modal props)))]
(let [locale (i18n/use-locale)
on-color-change
(fn [color]
(st/emit! (udw/update-shape (:id shape) {:fill-color color})))
on-opacity-change
(fn [event]
(let [value (-> (dom/get-target event)
(dom/get-value)
(d/parse-integer 1)
(/ 100))]
(st/emit! (udw/update-shape (:id shape) {:fill-opacity value}))))
show-color-picker
(fn [event]
(let [x (.-clientX event)
y (.-clientY event)
props {:x x :y y
:on-change on-color-change
:default "#ffffff"
:value (:fill-color shape)
:transparent? true}]
(modal/show! colorpicker-modal props)))]
[:div.element-set
[:div.element-set-title (tr "element.fill")]
[:div.element-set-title (t locale "workspace.options.fill")]
[:div.element-set-content
[:span (tr "workspace.options.color")]
[:div.row-flex.color-data
[:span.color-th
{:style {:background-color (:fill-color shape "#000000")}
{:style {:background-color (:fill-color shape)}
:on-click show-color-picker}]
[:div.color-info
[:input
{:on-change on-color-change
:value (:fill-color shape "")}]]]
;; SLIDEBAR FOR ROTATION AND OPACITY
[:span (tr "workspace.options.opacity")]
[:div.row-flex
[:input.slidebar
{:type "range"
:min "0"
:max "10000"
:value (str (* 10000 (:fill-opacity shape 1)))
:step "1"
:on-change on-opacity-change}]]]]))
[:div.color-info
[:input {:read-only true
:key (:fill-color shape)
:default-value (:fill-color shape)}]]
[:div.input-element.percentail
[:input.input-text {:type "number"
:value (str (-> (:fill-opacity shape)
(d/coalesce 1)
(* 100)
(math/round)))
:on-change on-opacity-change
:min "0"
:max "100"}]]
[:input.slidebar {:type "range"
:min "0"
:max "100"
:value (str (-> (:fill-opacity shape)
(d/coalesce 1)
(* 100)
(math/round)))
:step "1"
:on-change on-opacity-change}]]]]))

View file

@ -73,7 +73,6 @@
on-pos-y-change #(on-position-change % :y)]
[:div.element-set
[:div.element-set-title (tr "workspace.options.measures")]
[:div.element-set-content
@ -96,10 +95,15 @@
[:span.orientation-icon {on-click #(on-orientation-clicked :horiz)} i/size-horiz]
]
[:span (tr "workspace.options.size")]
;; WIDTH & HEIGHT
[:div.row-flex
[:span.element-set-subtitle (tr "workspace.options.size")]
[:div.lock-size {:class (when (:proportion-lock shape) "selected")
:on-click on-proportion-lock-change}
(if (:proportion-lock shape)
i/lock
i/unlock)]
[:div.input-element.pixels
[:input.input-text {:type "number"
:min "0"
@ -108,11 +112,6 @@
(math/precision 2)
(d/coalesce-str "0"))}]]
[:div.lock-size {:class (when (:proportion-lock shape) "selected")
:on-click on-proportion-lock-change}
(if (:proportion-lock shape)
i/lock
i/unlock)]
[:div.input-element.pixels
[:input.input-text {:type "number"
@ -123,8 +122,8 @@
(d/coalesce-str "0"))}]]]
;; POSITION
[:span (tr "workspace.options.position")]
[:div.row-flex
[:span.element-set-subtitle (tr "workspace.options.position")]
[:div.input-element.pixels
[:input.input-text {:placeholder "x"
:type "number"

View file

@ -20,12 +20,14 @@
[uxbox.main.ui.workspace.sidebar.options.stroke :refer [stroke-menu]]
[uxbox.util.dom :as dom]
[uxbox.util.geom.point :as gpt]
[uxbox.util.i18n :refer [tr]]
[uxbox.util.i18n :as i18n :refer [tr t]]
[uxbox.util.math :as math]))
(mf/defc measures-menu
[{:keys [shape] :as props}]
(let [on-size-change
(let [locale (i18n/use-locale)
on-size-change
(fn [event attr]
(let [value (-> (dom/get-target event)
(dom/get-value)
@ -40,7 +42,7 @@
(fn [event attr]
(let [value (-> (dom/get-target event)
(dom/get-value)
(d/parse-integer))]
(d/parse-integer 0))]
(st/emit! (udw/update-position (:id shape) {attr value}))))
on-rotation-change
@ -54,7 +56,7 @@
(fn [event]
(let [value (-> (dom/get-target event)
(dom/get-value)
(d/parse-double 0))]
(d/parse-integer 0))]
(st/emit! (udw/update-shape (:id shape) {:rx value :ry value}))))
on-width-change #(on-size-change % :width)
@ -63,72 +65,89 @@
on-pos-y-change #(on-position-change % :y)]
[:div.element-set
[:div.element-set-title (tr "workspace.options.measures")]
[:div.element-set-content
[:span (tr "workspace.options.size")]
;; WIDTH & HEIGHT
[:div.row-flex
[:div.input-element.pixels
[:input.input-text {:type "number"
:min "0"
:on-change on-width-change
:value (-> (:width shape)
(math/precision 2)
(d/coalesce-str "0"))}]]
[:span.element-set-subtitle (t locale "workspace.options.size")]
[:div.lock-size {:class (when (:proportion-lock shape) "selected")
:on-click on-proportion-lock-change}
(if (:proportion-lock shape)
i/lock
i/unlock)]
[:div.input-element.pixels
[:input.input-text {:type "number"
:min "0"
:no-validate true
:on-change on-width-change
:value (str (-> (:width shape)
(d/coalesce 0)
(math/round)))}]]
[:div.input-element.pixels
[:input.input-text {:type "number"
:min "0"
:no-validate true
:on-change on-height-change
:value (-> (:height shape)
(math/precision 2)
(d/coalesce-str "0"))}]]]
:value (str (-> (:height shape)
(d/coalesce 0)
(math/round)))}]]]
;; POSITION
[:span (tr "workspace.options.position")]
[:div.row-flex
[:span.element-set-subtitle (t locale "workspace.options.position")]
[:div.input-element.pixels
[:input.input-text {:placeholder "x"
:type "number"
:no-validate true
:on-change on-pos-x-change
:value (-> (:x shape)
(math/precision 2)
(d/coalesce-str "0"))}]]
:value (str (-> (:x shape)
(d/coalesce 0)
(math/round)))}]]
[:div.input-element.pixels
[:input.input-text {:placeholder "y"
:type "number"
:no-validate true
:on-change on-pos-y-change
:value (-> (:y shape)
(math/precision 2)
(d/coalesce-str "0"))}]]]
:value (str (-> (:y shape)
(d/coalesce 0)
(math/round)))}]]]
[:span (tr "workspace.options.rotation-radius")]
[:div.row-flex
[:span.element-set-subtitle (t locale "workspace.options.rotation")]
[:div.input-element.degrees
[:input.input-text {:placeholder ""
:type "number"
:min 0
:max 360
:on-change on-rotation-change
:value (-> (:rotation shape 0)
(math/precision 2)
(d/coalesce-str "0"))}]]
[:input.input-text
{:placeholder ""
:type "number"
:no-validate true
:min "0"
:max "360"
:on-change on-rotation-change
:value (str (-> (:rotation shape)
(d/coalesce 0)
(math/round)))}]]
[:input.slidebar
{:type "range"
:min "0"
:max "360"
:step "1"
:no-validate true
:on-change on-rotation-change
:value (str (-> (:rotation shape)
(d/coalesce 0)))}]]
[:div.row-flex
[:span.element-set-subtitle (t locale "workspace.options.radius")]
[:div.input-element.pixels
[:input.input-text
{:placeholder "rx"
:type "number"
:on-change on-radius-change
:value (-> (:rx shape)
(math/precision 2)
(d/coalesce-str "0"))}]]]]]))
:value (str (-> (:rx shape)
(d/coalesce 0)
(math/round)))}]]
[:div.input-element]]]]))
(mf/defc options

View file

@ -15,12 +15,15 @@
[uxbox.main.store :as st]
[uxbox.util.dom :as dom]
[uxbox.util.geom.point :as gpt]
[uxbox.util.i18n :refer [tr]]
[uxbox.util.i18n :as i18n :refer [t]]
[uxbox.util.math :as math]))
(mf/defc measures-menu
[{:keys [shape] :as props}]
(let [on-size-change
(let [locale (i18n/use-locale)
on-size-change
(fn [event attr]
(let [value (-> (dom/get-target event)
(dom/get-value)
@ -35,9 +38,8 @@
(fn [event attr]
(let [value (-> (dom/get-target event)
(dom/get-value)
(d/parse-integer))
point (gpt/point {attr value})]
(st/emit! (udw/update-position (:id shape) point))))
(d/parse-integer 0))]
(st/emit! (udw/update-position (:id shape) {attr value}))))
on-rotation-change
(fn [event]
@ -50,7 +52,7 @@
(fn [event]
(let [value (-> (dom/get-target event)
(dom/get-value)
(d/parse-double 0))]
(d/parse-integer 0))]
(st/emit! (udw/update-shape (:id shape) {:rx value :ry value}))))
on-width-change #(on-size-change % :width)
@ -59,72 +61,89 @@
on-pos-y-change #(on-position-change % :y)]
[:div.element-set
[:div.element-set-title (tr "workspace.options.measures")]
[:div.element-set-content
[:span (tr "workspace.options.size")]
;; WIDTH & HEIGHT
[:div.row-flex
[:div.input-element.pixels
[:input.input-text {:type "number"
:min "0"
:on-change on-width-change
:value (-> (:width shape)
(math/precision 2)
(d/coalesce-str "0"))}]]
[:span.element-set-subtitle (t locale "workspace.options.size")]
[:div.lock-size {:class (when (:proportion-lock shape) "selected")
:on-click on-proportion-lock-change}
(if (:proportion-lock shape)
i/lock
i/unlock)]
[:div.input-element.pixels
[:input.input-text {:type "number"
:min "0"
:no-validate true
:on-change on-width-change
:value (str (-> (:width shape)
(d/coalesce 0)
(math/round)))}]]
[:div.input-element.pixels
[:input.input-text {:type "number"
:min "0"
:no-validate true
:on-change on-height-change
:value (-> (:height shape)
(math/precision 2)
(d/coalesce-str "0"))}]]]
:value (str (-> (:height shape)
(d/coalesce 0)
(math/round)))}]]]
;; POSITION
[:span (tr "workspace.options.position")]
[:div.row-flex
[:span.element-set-subtitle (t locale "workspace.options.position")]
[:div.input-element.pixels
[:input.input-text {:placeholder "x"
:type "number"
:no-validate true
:on-change on-pos-x-change
:value (-> (:x shape)
(math/precision 2)
(d/coalesce-str "0"))}]]
:value (str (-> (:x shape)
(d/coalesce 0)
(math/round)))}]]
[:div.input-element.pixels
[:input.input-text {:placeholder "y"
:type "number"
:no-validate true
:on-change on-pos-y-change
:value (-> (:y shape)
(math/precision 2)
(d/coalesce-str "0"))}]]]
:value (str (-> (:y shape)
(d/coalesce 0)
(math/round)))}]]]
[:span (tr "workspace.options.rotation-radius")]
[:div.row-flex
[:span.element-set-subtitle (t locale "workspace.options.rotation")]
[:div.input-element.degrees
[:input.input-text {:placeholder ""
:type "number"
:min 0
:max 360
:on-change on-rotation-change
:value (-> (:rotation shape 0)
(math/precision 2)
(d/coalesce-str "0"))}]]
[:input.input-text
{:placeholder ""
:type "number"
:no-validate true
:min "0"
:max "360"
:on-change on-rotation-change
:value (str (-> (:rotation shape)
(d/coalesce 0)
(math/round)))}]]
[:input.slidebar
{:type "range"
:min "0"
:max "360"
:step "1"
:no-validate true
:on-change on-rotation-change
:value (str (-> (:rotation shape)
(d/coalesce 0)))}]]
[:div.row-flex
[:span.element-set-subtitle (t locale "workspace.options.radius")]
[:div.input-element.pixels
[:input.input-text
{:placeholder "rx"
:type "number"
:on-change on-radius-change
:value (-> (:rx shape)
(math/precision 2)
(d/coalesce-str "0"))}]]]]]))
:value (str (-> (:rx shape)
(d/coalesce 0)
(math/round)))}]]
[:div.input-element]]]]))
(mf/defc options

View file

@ -111,8 +111,8 @@
[:div.element-set
[:div.element-set-title (tr "workspace.options.grid-options")]
[:div.element-set-content
[:span (tr "workspace.options.size")]
[:div.row-flex
[:span.element-set-subtitle (tr "workspace.options.size")]
[:div.input-element.pixels
[:input.input-text {:type "number"
:value (:grid-x options)
@ -121,8 +121,8 @@
[:input.input-text {:type "number"
:value (:grid-y options)
:on-change on-y-change}]]]
[:span (tr "workspace.options.color")]
[:div.row-flex.color-data
[:span.element-set-subtitle (tr "workspace.options.color")]
[:span.color-th {:style {:background-color (:grid-color options)}
:on-click show-color-picker}]
[:div.color-info

View file

@ -5,8 +5,7 @@
;; This Source Code Form is "Incompatible With Secondary Licenses", as
;; defined by the Mozilla Public License, v. 2.0.
;;
;; Copyright (c) 2015-2020 Andrey Antukh <niwi@niwi.nz>
;; Copyright (c) 2015-2020 Juan de la Cruz <delacruzgarciajuan@gmail.com>
;; Copyright (c) 2020 UXBOX Labs SL
(ns uxbox.main.ui.workspace.sidebar.options.rect
(:require
@ -20,12 +19,14 @@
[uxbox.main.ui.workspace.sidebar.options.stroke :refer [stroke-menu]]
[uxbox.util.dom :as dom]
[uxbox.util.geom.point :as gpt]
[uxbox.util.i18n :refer [tr]]
[uxbox.util.i18n :as i18n :refer [tr t]]
[uxbox.util.math :as math]))
(mf/defc measures-menu
[{:keys [shape] :as props}]
(let [on-size-change
(let [locale (i18n/use-locale)
on-size-change
(fn [event attr]
(let [value (-> (dom/get-target event)
(dom/get-value)
@ -40,7 +41,7 @@
(fn [event attr]
(let [value (-> (dom/get-target event)
(dom/get-value)
(d/parse-integer))]
(d/parse-integer 0))]
(st/emit! (udw/update-position (:id shape) {attr value}))))
on-rotation-change
@ -54,7 +55,7 @@
(fn [event]
(let [value (-> (dom/get-target event)
(dom/get-value)
(d/parse-double 0))]
(d/parse-integer 0))]
(st/emit! (udw/update-shape (:id shape) {:rx value :ry value}))))
on-width-change #(on-size-change % :width)
@ -63,72 +64,89 @@
on-pos-y-change #(on-position-change % :y)]
[:div.element-set
[:div.element-set-title (tr "workspace.options.measures")]
[:div.element-set-content
[:span (tr "workspace.options.size")]
;; WIDTH & HEIGHT
[:div.row-flex
[:div.input-element.pixels
[:input.input-text {:type "number"
:min "0"
:on-change on-width-change
:value (-> (:width shape)
(math/precision 2)
(d/coalesce-str "0"))}]]
[:span.element-set-subtitle (t locale "workspace.options.size")]
[:div.lock-size {:class (when (:proportion-lock shape) "selected")
:on-click on-proportion-lock-change}
(if (:proportion-lock shape)
i/lock
i/unlock)]
[:div.input-element.pixels
[:input.input-text {:type "number"
:min "0"
:no-validate true
:on-change on-width-change
:value (str (-> (:width shape)
(d/coalesce 0)
(math/round)))}]]
[:div.input-element.pixels
[:input.input-text {:type "number"
:min "0"
:no-validate true
:on-change on-height-change
:value (-> (:height shape)
(math/precision 2)
(d/coalesce-str "0"))}]]]
:value (str (-> (:height shape)
(d/coalesce 0)
(math/round)))}]]]
;; POSITION
[:span (tr "workspace.options.position")]
[:div.row-flex
[:span.element-set-subtitle (t locale "workspace.options.position")]
[:div.input-element.pixels
[:input.input-text {:placeholder "x"
:type "number"
:no-validate true
:on-change on-pos-x-change
:value (-> (:x shape)
(math/precision 2)
(d/coalesce-str "0"))}]]
:value (str (-> (:x shape)
(d/coalesce 0)
(math/round)))}]]
[:div.input-element.pixels
[:input.input-text {:placeholder "y"
:type "number"
:no-validate true
:on-change on-pos-y-change
:value (-> (:y shape)
(math/precision 2)
(d/coalesce-str "0"))}]]]
:value (str (-> (:y shape)
(d/coalesce 0)
(math/round)))}]]]
[:span (tr "workspace.options.rotation-radius")]
[:div.row-flex
[:span.element-set-subtitle (t locale "workspace.options.rotation")]
[:div.input-element.degrees
[:input.input-text {:placeholder ""
:type "number"
:min 0
:max 360
:on-change on-rotation-change
:value (-> (:rotation shape 0)
(math/precision 2)
(d/coalesce-str "0"))}]]
[:input.input-text
{:placeholder ""
:type "number"
:no-validate true
:min "0"
:max "360"
:on-change on-rotation-change
:value (str (-> (:rotation shape)
(d/coalesce 0)
(math/round)))}]]
[:input.slidebar
{:type "range"
:min "0"
:max "360"
:step "1"
:no-validate true
:on-change on-rotation-change
:value (str (-> (:rotation shape)
(d/coalesce 0)))}]]
[:div.row-flex
[:span.element-set-subtitle (t locale "workspace.options.radius")]
[:div.input-element.pixels
[:input.input-text
{:placeholder "rx"
:type "number"
:on-change on-radius-change
:value (-> (:rx shape)
(math/precision 2)
(d/coalesce-str "0"))}]]]]]))
:value (str (-> (:rx shape)
(d/coalesce 0)
(math/round)))}]]
[:div.input-element]]]]))
(mf/defc options

View file

@ -2,8 +2,10 @@
;; 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) 2015-2017 Juan de la Cruz <delacruzgarciajuan@gmail.com>
;; Copyright (c) 2015-2019 Andrey Antukh <niwi@niwi.nz>
;; This Source Code Form is "Incompatible With Secondary Licenses", as
;; defined by the Mozilla Public License, v. 2.0.
;;
;; Copyright (c) 2020 UXBOX Labs SL
(ns uxbox.main.ui.workspace.sidebar.options.stroke
(:require
@ -14,14 +16,14 @@
[uxbox.main.store :as st]
[uxbox.main.ui.modal :as modal]
[uxbox.main.ui.workspace.colorpicker :refer [colorpicker-modal]]
[uxbox.util.data :refer [parse-int parse-float read-string]]
[uxbox.util.dom :as dom]
[uxbox.util.i18n :refer [tr]]
[uxbox.util.i18n :as i18n :refer [tr t]]
[uxbox.util.math :as math]))
(mf/defc stroke-menu
[{:keys [shape] :as props}]
(let [show-options (not= (:stroke-style shape) :none)
(let [locale (i18n/use-locale)
show-options (not= (:stroke-style shape) :none)
on-stroke-style-change
(fn [event]
@ -34,15 +36,15 @@
(fn [event]
(let [value (-> (dom/get-target event)
(dom/get-value)
(d/parse-double 1))]
(d/parse-integer 0))]
(st/emit! (udw/update-shape (:id shape) {:stroke-width value}))))
on-stroke-opacity-change
(fn [event]
(let [value (-> (dom/get-target event)
(dom/get-value)
(d/parse-double 1)
(/ 10000))]
(d/parse-integer 0)
(/ 100))]
(st/emit! (udw/update-shape (:id shape) {:stroke-opacity value}))))
show-color-picker
@ -56,50 +58,60 @@
:transparent? true}]
(modal/show! colorpicker-modal props)))]
;; COLLAPSED
;; [:div.element-set
;; [:div.element-set-title (tr "workspace.options.stroke")]
;; [:div.add-page i/close]]
;; EXPANDED
[:div.element-set
[:div.element-set-title (tr "workspace.options.stroke")]
[:div.element-set-title (t locale "workspace.options.stroke")]
[:div.element-set-content
;; Stroke Color
[:div.row-flex.color-data
[:span.color-th {:style {:background-color (:stroke-color shape)}
:on-click show-color-picker}]
[:div.color-info
[:input {:read-only true
:key (:stroke-color shape)
:default-value (:stroke-color shape)}]]
[:div.input-element.percentail
[:input.input-text {:placeholder ""
:value (str (-> (:stroke-opacity shape)
(d/coalesce 1)
(* 100)
(math/round)))
:type "number"
:on-change on-stroke-opacity-change
:min "0"
:max "100"}]]
[:input.slidebar {:type "range"
:min "0"
:max "100"
:value (str (-> (:stroke-opacity shape)
(d/coalesce 1)
(* 100)
(math/round)))
:step "1"
:on-change on-stroke-opacity-change}]]
;; Stroke Style & Width
[:span (tr "workspace.options.stroke.style")]
[:div.row-flex
[:select#style.input-select {:value (pr-str (:stroke-style shape))
:on-change on-stroke-style-change}
[:option {:value ":none"} (tr "workspace.options.stroke.none")]
[:option {:value ":solid"} (tr "workspace.options.stroke.solid")]
[:option {:value ":dotted"} (tr "workspace.options.stroke.dotted")]
[:option {:value ":dashed"} (tr "workspace.options.stroke.dashed")]
[:option {:value ":mixed"} (tr "workspace.options.stroke.mixed")]]
[:option {:value ":none"} (t locale "workspace.options.stroke.none")]
[:option {:value ":solid"} (t locale "workspace.options.stroke.solid")]
[:option {:value ":dotted"} (t locale "workspace.options.stroke.dotted")]
[:option {:value ":dashed"} (t locale "workspace.options.stroke.dashed")]
[:option {:value ":mixed"} (t locale "workspace.options.stroke.mixed")]]
[:div.input-element {:class (when show-options "pixels")}
(when show-options
[:input.input-text {:type "number"
:min "0"
:value (-> (:stroke-width shape)
(math/precision 2)
(d/coalesce-str "1"))
:on-change on-stroke-width-change}])]]
;; Stroke Color
(when show-options
[:*
[:span (tr "workspace.options.color")]
[:div.row-flex.color-data
[:span.color-th {:style {:background-color (:stroke-color shape)}
:on-click show-color-picker}]
[:div.color-info
[:input {:read-only true
:default-value (:stroke-color shape "")}]]]
[:span (tr "workspace.options.opacity")]
[:div.row-flex
[:input.slidebar {:type "range"
[:div.input-element.pixels
[:input.input-text {:type "number"
:min "0"
:max "10000"
:value (-> (:stroke-opacity shape 1)
(* 10000)
(d/coalesce-str "1"))
:step "1"
:on-change on-stroke-opacity-change}]]])]]))
:value (str (-> (:stroke-width shape)
(d/coalesce 1)
(math/round)))
:on-change on-stroke-width-change}]]]]]))