Compare commits

...

1 Commits

Author SHA1 Message Date
Eva Marco
91b1c210d1 wip 2025-12-11 09:47:11 +01:00
8 changed files with 119 additions and 28 deletions

View File

@@ -32,13 +32,19 @@
min-width: var(--sp-l);
}
// TODO: Review if we need other type of button, so we don't need important here
.invisible-button {
position: absolute;
right: 4px;
top: 4px;
opacity: var(--opacity-button);
background-color: var(--color-background-quaternary) !important;
&:hover {
background-color: var(--color-background-quaternary);
--opacity-button: 1;
}
&:focus {
background-color: var(--color-background-quaternary);
--opacity-button: 1;
}
}

View File

@@ -80,7 +80,7 @@
[:div {:class (stl/css :pill-dot)}])]]
(when-not ^boolean disabled
[:> icon-button* {:variant "action"
[:> icon-button* {:variant "ghost"
:class (stl/css :invisible-button)
:icon i/broken-link
:ref token-detach-btn-ref

View File

@@ -8,6 +8,7 @@
@use "ds/_sizes.scss" as *;
@use "ds/typography.scss" as t;
@use "ds/colors.scss" as *;
@use "ds/mixins.scss" as *;
.token-field {
--token-field-bg-color: var(--color-background-tertiary);
@@ -16,9 +17,8 @@
--token-field-outline-color: none;
--token-field-height: var(--sp-xxxl);
--token-field-margin: unset;
display: grid;
grid-template-columns: 1fr auto;
width: inherit;
column-gap: var(--sp-xs);
align-items: center;
position: relative;
@@ -27,6 +27,7 @@
border-radius: $br-8;
padding: var(--sp-xs);
outline: $b-1 solid var(--token-field-outline-color);
position: relative;
&:hover {
--token-field-bg-color: var(--color-background-quaternary);
@@ -39,7 +40,7 @@
}
.with-icon {
grid-template-columns: auto 1fr auto;
grid-template-columns: auto 1fr;
}
.token-field-disabled {
@@ -57,6 +58,8 @@
--pill-bg-color: var(--color-background-tertiary);
--pill-fg-color: var(--color-token-foreground);
@include t.use-typography("code-font");
@include textEllipsis;
display: block;
height: var(--sp-xxl);
width: fit-content;
background: var(--pill-bg-color);
@@ -65,6 +68,7 @@
color: var(--pill-fg-color);
border-radius: $br-6;
padding-inline: $sz-6;
max-width: 100%;
&:hover {
--pill-bg-color: var(--color-token-background);
--pill-fg-color: var(--color-foreground-primary);
@@ -115,6 +119,9 @@
}
.invisible-button {
position: absolute;
right: 0;
top: 0;
opacity: var(--opacity-button);
&:hover {

View File

@@ -159,4 +159,6 @@ $arrow-side: 12px;
block-size: fit-content;
inline-size: fit-content;
line-height: 0;
display: grid;
max-width: 100%;
}

View File

@@ -3,10 +3,15 @@
(:require
[app.common.data.macros :as dm]
[app.common.types.shape.radius :as ctsr]
[app.common.types.token :as tk]
[app.main.data.workspace.shapes :as dwsh]
[app.main.data.workspace.tokens.application :as dwta]
[app.main.features :as features]
[app.main.store :as st]
[app.main.ui.components.numeric-input :as deprecated-input]
[app.main.ui.context :as muc]
[app.main.ui.ds.buttons.icon-button :refer [icon-button*]]
[app.main.ui.ds.controls.numeric-input :refer [numeric-input*]]
[app.main.ui.ds.foundations.assets.icon :refer [icon*] :as i]
[app.main.ui.hooks :as hooks]
[app.util.i18n :as i18n :refer [tr]]
@@ -21,11 +26,15 @@
(defn- check-border-radius-menu-props
[old-props new-props]
(let [old-values (unchecked-get old-props "values")
new-values (unchecked-get new-props "values")]
new-values (unchecked-get new-props "values")
old-applied-tokens (unchecked-get old-props "applied-tokens")
new-applied-tokens (unchecked-get new-props "applied-tokens")]
(and (identical? (unchecked-get old-props "class")
(unchecked-get new-props "class"))
(identical? (unchecked-get old-props "ids")
(unchecked-get new-props "ids"))
(identical? old-applied-tokens
new-applied-tokens)
(identical? (get old-values :r1)
(get new-values :r1))
(identical? (get old-values :r2)
@@ -35,13 +44,64 @@
(identical? (get old-values :r4)
(get new-values :r4)))))
(mf/defc numeric-input-wrapper*
{::mf/private true}
[{:keys [values name applied-tokens align on-detach radius] :rest props}]
(let [tokens (mf/use-ctx muc/active-tokens-by-type)
tokens (mf/with-memo [tokens name]
(delay
(-> (deref tokens)
(select-keys (get tk/tokens-by-input name))
(not-empty))))
on-detach-attr
(mf/use-fn
(mf/deps on-detach name)
#(on-detach % name))
r1-value (get applied-tokens :r1)
r2-value (get applied-tokens :r2)
r3-value (get applied-tokens :r3)
r4-value (get applied-tokens :r4)
all-equal? (= r1-value r2-value r3-value r4-value)
applied-token (if (= :all radius)
(if all-equal?
r1-value
:mixed)
:mixed)
props (mf/spread-props props
{:placeholder (if (or (= :multiple (:applied-tokens values))
(= :multiple (get values name)))
(tr "settings.multiple") "--")
:class (stl/css :numeric-input-measures)
:applied-token applied-token
:tokens (if (delay? tokens) @tokens tokens)
:align align
:on-detach on-detach-attr
:value (get values name)})]
[:> numeric-input* props]))
(mf/defc border-radius-menu*
{::mf/wrap [#(mf/memo' % check-border-radius-menu-props)]}
[{:keys [class ids values]}]
(let [all-equal? (all-equal? values)
[{:keys [class ids values applied-tokens]}]
(let [token-numeric-inputs
(features/use-feature "tokens/numeric-input")
all-equal? (all-equal? values)
radius-expanded* (mf/use-state false)
radius-expanded (deref radius-expanded*)
;; DETACH
on-detach-token
(mf/use-fn
(mf/deps ids)
(fn [token attr]
(st/emit! (dwta/unapply-token {:token (first token)
:attributes #{attr}
:shape-ids ids}))))
change-radius
(mf/use-fn
(mf/deps ids)
@@ -94,23 +154,39 @@
[:div {:class (dm/str class " " (stl/css :radius))}
(if (not radius-expanded)
[:div {:class (stl/css :radius-1)
:title (tr "workspace.options.radius")}
[:> icon* {:icon-id i/corner-radius
:size "s"
:class (stl/css :icon)}]
[:> deprecated-input/numeric-input*
{:placeholder (cond
(not all-equal?)
"Mixed"
(= :multiple (:r1 values))
(tr "settings.multiple")
:else
"--")
:min 0
:nillable true
:on-change on-single-radius-change
:value (if all-equal? (:r1 values) nil)}]]
(if token-numeric-inputs
[:div {:class (stl/css :radius-1)
:title (tr "workspace.options.radius")}
[:> numeric-input-wrapper*
{:on-change on-single-radius-change
:on-detach on-detach-token
:icon i/corner-radius
:min 0
:name :border-radius
:nillable true
:property (tr "workspace.options.width")
:applied-tokens applied-tokens
:radius :all
:values (if all-equal? (:r1 values) nil)}]]
[:div {:class (stl/css :radius-1)
:title (tr "workspace.options.radius")}
[:> icon* {:icon-id i/corner-radius
:size "s"
:class (stl/css :icon)}]
[:* [:> deprecated-input/numeric-input*
{:placeholder (cond
(not all-equal?)
"Mixed"
(= :multiple (:r1 values))
(tr "settings.multiple")
:else
"--")
:min 0
:nillable true
:on-change on-single-radius-change
:value (if all-equal? (:r1 values) nil)}]]])
[:div {:class (stl/css :radius-4)}
[:div {:class (stl/css :small-input)}

View File

@@ -77,7 +77,7 @@
(nil? (get values name)))
(tr "settings.multiple")
"--")
:class (stl/css :numeric-input-measures)
:class (stl/css :numeric-input-layout)
:applied-token (get applied-tokens name)
:tokens tokens
:align align

View File

@@ -433,6 +433,6 @@
align-items: center;
}
.numeric-input-measures {
.numeric-input-layout {
--dropdown-width: var(--7-columns-dropdown-width);
}

View File

@@ -6,6 +6,7 @@
@use "refactor/common-refactor.scss" as deprecated;
@use "../../../sidebar/common/sidebar.scss" as sidebar;
@use "ds/_utils.scss" as *;
.element-set {
display: grid;
@@ -188,7 +189,6 @@
@extend .button-icon;
}
// TODO: Add a proper variable to this sizing
.numeric-input-measures {
--dropdown-width: var(--7-columns-dropdown-width);
}