Merge pull request #392 from penpot/text-options-ui

Text options ui & bug fixing
This commit is contained in:
Andrey Antukh 2020-11-23 15:17:14 +01:00 committed by GitHub
commit e1db6d3a37
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 123 additions and 117 deletions

View file

@ -373,9 +373,10 @@ ul.slider-dots {
font-size: $fs12; font-size: $fs12;
height: 20px; height: 20px;
position: absolute; position: absolute;
right: 3px; right: $small;
text-align: right;
top: 26%; top: 26%;
width: 20px; width: 18px;
} }
.after { .after {
@ -539,7 +540,7 @@ input.element-name {
@extend .input-text; @extend .input-text;
background-image: url("/images/icons/arrow-down-white.svg"); background-image: url("/images/icons/arrow-down-white.svg");
background-repeat: no-repeat; background-repeat: no-repeat;
background-position: 95% 48%; background-position: calc(100% - 4px) 48%;
background-size: 10px; background-size: 10px;
cursor: pointer; cursor: pointer;

View file

@ -226,17 +226,17 @@
.element-set-subtitle { .element-set-subtitle {
color: $color-gray-20; color: $color-gray-20;
font-size: $fs11; font-size: $fs11;
width: 12rem; width: 64px;
} }
.lock-size { .lock-size {
cursor: pointer; cursor: pointer;
width: 20%; margin: auto;
svg { svg {
fill: $color-gray-20; fill: $color-gray-20;
height: 15px; height: 14px;
width: 15px; width: 14px;
&:hover { &:hover {
fill: $color-primary; fill: $color-primary;
@ -518,16 +518,15 @@
} }
.align-icons { .align-icons {
border: 1px solid $color-gray-60;
border-radius: $br-small;
cursor: pointer; cursor: pointer;
display: flex; display: flex;
flex: 1; flex: 1;
justify-content: space-between; justify-content: flex-end;
margin-left: $small; margin: $small 0 $small $small;
padding: $small; padding: 0 $x-small;
&:first-child { &:first-child {
justify-content: space-between;
margin-left: 0; margin-left: 0;
} }
@ -542,8 +541,8 @@
svg { svg {
fill: $color-gray-30; fill: $color-gray-30;
height: 15px; height: 14px;
width: 15px; width: 14px;
} }
&:hover, &:hover,
@ -651,12 +650,12 @@
display: flex; display: flex;
height: 18px; height: 18px;
position: relative; position: relative;
width: 18px; width: 14px;
svg { svg {
fill: $color-gray-30; fill: $color-gray-30;
height: 16px; height: 14px;
width: 16px; width: 14px;
} }
} }
} }
@ -927,6 +926,10 @@
} }
} }
.spacing-options {
display: flex;
}
.asset-group { .asset-group {
.typography-entry { .typography-entry {
margin: 0.25rem 0; margin: 0.25rem 0;

View file

@ -114,13 +114,6 @@
(when (options :size) (when (options :size)
[:div.row-flex [:div.row-flex
[:span.element-set-subtitle (t locale "workspace.options.size")] [:span.element-set-subtitle (t locale "workspace.options.size")]
[:div.lock-size {:class (classnames
:selected (true? proportion-lock)
:disabled (= proportion-lock :multiple))
:on-click on-proportion-lock-change}
(if proportion-lock
i/lock
i/unlock)]
[:div.input-element.width [:div.input-element.width
[:input.input-text {:type "number" [:input.input-text {:type "number"
:min "0" :min "0"
@ -138,7 +131,15 @@
:placeholder "--" :placeholder "--"
:on-click select-all :on-click select-all
:on-change on-height-change :on-change on-height-change
:value (attr->string :height values)}]]]) :value (attr->string :height values)}]]
[:div.lock-size {:class (classnames
:selected (true? proportion-lock)
:disabled (= proportion-lock :multiple))
:on-click on-proportion-lock-change}
(if proportion-lock
i/lock
i/unlock)]])
;; POSITION ;; POSITION
(when (options :position) (when (options :position)

View file

@ -62,7 +62,7 @@
(on-change {:text-align new-align}))] (on-change {:text-align new-align}))]
;; --- Align ;; --- Align
[:div.row-flex.align-icons [:div.align-icons
[:span.tooltip.tooltip-bottom [:span.tooltip.tooltip-bottom
{:alt (t locale "workspace.options.text-options.align-left") {:alt (t locale "workspace.options.text-options.align-left")
:class (dom/classnames :current (= "left" text-align)) :class (dom/classnames :current (= "left" text-align))
@ -85,58 +85,55 @@
i/text-align-justify]])) i/text-align-justify]]))
(mf/defc additional-options (mf/defc vertical-align
[{:keys [shapes editor ids values locale on-change] :as props}] [{:keys [shapes editor ids values locale on-change] :as props}]
(let [{:keys [vertical-align]} values (let [{:keys [vertical-align]} values
to-single-value (fn [coll] (if (> (count coll) 1) nil (first coll)))
grow-type (->> shapes (map :grow-type) (remove nil?) (into #{}) to-single-value)
vertical-align (or vertical-align "top") vertical-align (or vertical-align "top")
handle-change-grow
(fn [event grow-type]
(st/emit! (dwc/update-shapes ids #(assoc % :grow-type grow-type))))
handle-change handle-change
(fn [event new-align] (fn [event new-align]
(on-change {:vertical-align new-align}))] (on-change {:vertical-align new-align}))]
[:div.row-flex [:div.align-icons
[:div.align-icons [:span.tooltip.tooltip-bottom
[:span.tooltip.tooltip-bottom {:alt (t locale "workspace.options.text-options.align-top")
{:alt (t locale "workspace.options.text-options.align-top") :class (dom/classnames :current (= "top" vertical-align))
:class (dom/classnames :current (= "top" vertical-align)) :on-click #(handle-change % "top")}
:on-click #(handle-change % "top")} i/align-top]
i/align-top] [:span.tooltip.tooltip-bottom
[:span.tooltip.tooltip-bottom {:alt (t locale "workspace.options.text-options.align-middle")
{:alt (t locale "workspace.options.text-options.align-middle") :class (dom/classnames :current (= "center" vertical-align))
:class (dom/classnames :current (= "center" vertical-align)) :on-click #(handle-change % "center")}
:on-click #(handle-change % "center")} i/align-middle]
i/align-middle] [:span.tooltip.tooltip-bottom
[:span.tooltip.tooltip-bottom {:alt (t locale "workspace.options.text-options.align-bottom")
{:alt (t locale "workspace.options.text-options.align-bottom") :class (dom/classnames :current (= "bottom" vertical-align))
:class (dom/classnames :current (= "bottom" vertical-align)) :on-click #(handle-change % "bottom")}
:on-click #(handle-change % "bottom")} i/align-bottom]]))
i/align-bottom]]
[:div.align-icons (mf/defc grow-options
[:span.tooltip.tooltip-bottom [{:keys [shapes editor ids values locale on-change] :as props}]
{:alt (t locale "workspace.options.text-options.grow-fixed") (let [to-single-value (fn [coll] (if (> (count coll) 1) nil (first coll)))
:class (dom/classnames :current (= :fixed grow-type)) grow-type (->> shapes (map :grow-type) (remove nil?) (into #{}) to-single-value)
:on-click #(handle-change-grow % :fixed)} handle-change-grow
i/auto-fix] (fn [event grow-type]
[:span.tooltip.tooltip-bottom (st/emit! (dwc/update-shapes ids #(assoc % :grow-type grow-type))))]
{:alt (t locale "workspace.options.text-options.grow-auto-width")
:class (dom/classnames :current (= :auto-width grow-type)) [:div.align-icons
:on-click #(handle-change-grow % :auto-width)} [:span.tooltip.tooltip-bottom
i/auto-width] {:alt (t locale "workspace.options.text-options.grow-fixed")
[:span.tooltip.tooltip-bottom :class (dom/classnames :current (= :fixed grow-type))
{:alt (t locale "workspace.options.text-options.grow-auto-height") :on-click #(handle-change-grow % :fixed)}
:class (dom/classnames :current (= :auto-height grow-type)) i/auto-fix]
:on-click #(handle-change-grow % :auto-height)} [:span.tooltip.tooltip-bottom
i/auto-height]]])) {:alt (t locale "workspace.options.text-options.grow-auto-width")
:class (dom/classnames :current (= :auto-width grow-type))
:on-click #(handle-change-grow % :auto-width)}
i/auto-width]
[:span.tooltip.tooltip-bottom
{:alt (t locale "workspace.options.text-options.grow-auto-height")
:class (dom/classnames :current (= :auto-height grow-type))
:on-click #(handle-change-grow % :auto-height)}
i/auto-height]]))
(mf/defc text-decoration-options (mf/defc text-decoration-options
[{:keys [editor ids values locale on-change] :as props}] [{:keys [editor ids values locale on-change] :as props}]
@ -147,26 +144,24 @@
handle-change handle-change
(fn [event type] (fn [event type]
(on-change {:text-decoration type}))] (on-change {:text-decoration type}))]
[:div.row-flex [:div.align-icons
[:span.element-set-subtitle (t locale "workspace.options.text-options.decoration")] [:span.tooltip.tooltip-bottom
[:div.align-icons {:alt (t locale "workspace.options.text-options.none")
[:span.tooltip.tooltip-bottom :class (dom/classnames :current (= "none" text-decoration))
{:alt (t locale "workspace.options.text-options.none") :on-click #(handle-change % "none")}
:class (dom/classnames :current (= "none" text-decoration)) i/minus]
:on-click #(handle-change % "none")}
i/minus]
[:span.tooltip.tooltip-bottom [:span.tooltip.tooltip-bottom
{:alt (t locale "workspace.options.text-options.underline") {:alt (t locale "workspace.options.text-options.underline")
:class (dom/classnames :current (= "underline" text-decoration)) :class (dom/classnames :current (= "underline" text-decoration))
:on-click #(handle-change % "underline")} :on-click #(handle-change % "underline")}
i/underline] i/underline]
[:span.tooltip.tooltip-bottom [:span.tooltip.tooltip-bottom
{:alt (t locale "workspace.options.text-options.strikethrough") {:alt (t locale "workspace.options.text-options.strikethrough")
:class (dom/classnames :current (= "line-through" text-decoration)) :class (dom/classnames :current (= "line-through" text-decoration))
:on-click #(handle-change % "line-through")} :on-click #(handle-change % "line-through")}
i/strikethrough]]])) i/strikethrough]]))
(defn generate-typography-name [{:keys [font-id font-variant-id] :as typography}] (defn generate-typography-name [{:keys [font-id font-variant-id] :as typography}]
(let [{:keys [name]} (fonts/get-font-data font-id)] (let [{:keys [name]} (fonts/get-font-data font-id)]
@ -273,9 +268,16 @@
[:> typography-options opts]) [:> typography-options opts])
[:div.element-set-content [:div.element-set-content
[:> text-align-options opts]
[:> additional-options opts] [:div.row-flex
[:> text-decoration-options opts]]])) [:> text-align-options opts]
[:> vertical-align opts]]
[:div.row-flex
[:> grow-options opts]
[:> text-decoration-options opts]]
]]))
(mf/defc options (mf/defc options
[{:keys [shape] :as props}] [{:keys [shape] :as props}]

View file

@ -135,7 +135,7 @@
(let [new-spacing (dom/get-target-val event)] (let [new-spacing (dom/get-target-val event)]
(on-change {attr new-spacing})))] (on-change {attr new-spacing})))]
[:div.row-flex [:div.spacing-options
[:div.input-icon [:div.input-icon
[:span.icon-before.tooltip.tooltip-bottom [:span.icon-before.tooltip.tooltip-bottom
{:alt (t locale "workspace.options.text-options.line-height")} {:alt (t locale "workspace.options.text-options.line-height")}
@ -171,29 +171,27 @@
handle-change handle-change
(fn [event type] (fn [event type]
(on-change {:text-transform type}))] (on-change {:text-transform type}))]
[:div.row-flex [:div.align-icons
[:span.element-set-subtitle (t locale "workspace.options.text-options.text-case")] [:span.tooltip.tooltip-bottom
[:div.align-icons {:alt (t locale "workspace.options.text-options.none")
[:span.tooltip.tooltip-bottom :class (dom/classnames :current (= "none" text-transform))
{:alt (t locale "workspace.options.text-options.none") :on-click #(handle-change % "none")}
:class (dom/classnames :current (= "none" text-transform)) i/minus]
:on-click #(handle-change % "none")} [:span.tooltip.tooltip-bottom
i/minus] {:alt (t locale "workspace.options.text-options.uppercase")
[:span.tooltip.tooltip-bottom :class (dom/classnames :current (= "uppercase" text-transform))
{:alt (t locale "workspace.options.text-options.uppercase") :on-click #(handle-change % "uppercase")}
:class (dom/classnames :current (= "uppercase" text-transform)) i/uppercase]
:on-click #(handle-change % "uppercase")} [:span.tooltip.tooltip-bottom
i/uppercase] {:alt (t locale "workspace.options.text-options.lowercase")
[:span.tooltip.tooltip-bottom :class (dom/classnames :current (= "lowercase" text-transform))
{:alt (t locale "workspace.options.text-options.lowercase") :on-click #(handle-change % "lowercase")}
:class (dom/classnames :current (= "lowercase" text-transform)) i/lowercase]
:on-click #(handle-change % "lowercase")} [:span.tooltip.tooltip-bottom
i/lowercase] {:alt (t locale "workspace.options.text-options.titlecase")
[:span.tooltip.tooltip-bottom :class (dom/classnames :current (= "capitalize" text-transform))
{:alt (t locale "workspace.options.text-options.titlecase") :on-click #(handle-change % "capitalize")}
:class (dom/classnames :current (= "capitalize" text-transform)) i/titlecase]]))
:on-click #(handle-change % "capitalize")}
i/titlecase]]]))
(mf/defc typography-options (mf/defc typography-options
[{:keys [ids editor values on-change]}] [{:keys [ids editor values on-change]}]
@ -206,8 +204,9 @@
[:div.element-set-content [:div.element-set-content
[:> font-options opts] [:> font-options opts]
[:> spacing-options opts] [:div.row-flex
[:> text-transform-options opts]])) [:> spacing-options opts]
[:> text-transform-options opts]]]))
(mf/defc typography-entry (mf/defc typography-entry