mirror of
https://github.com/penpot/penpot.git
synced 2025-06-04 03:21:38 +02:00
✨ Allow modifying property name when a variation is selected (#6174)
* ✨ Change property name when a variation is selected * 📎 PR changes
This commit is contained in:
parent
4e1ae1bc1a
commit
648a8f9237
3 changed files with 36 additions and 15 deletions
|
@ -16,25 +16,28 @@
|
||||||
(def ^:private schema:input-with-values
|
(def ^:private schema:input-with-values
|
||||||
[:map
|
[:map
|
||||||
[:name :string]
|
[:name :string]
|
||||||
[:values :string]
|
[:values {:optional true} :string]
|
||||||
[:on-blur {:optional true} fn?]])
|
[:on-blur {:optional true} fn?]])
|
||||||
|
|
||||||
|
|
||||||
(mf/defc input-with-values*
|
(mf/defc input-with-values*
|
||||||
{::mf/props :obj
|
{::mf/props :obj
|
||||||
::mf/schema schema:input-with-values}
|
::mf/schema schema:input-with-values}
|
||||||
[{:keys [name values on-blur] :rest props}]
|
[{:keys [name values on-blur] :rest props}]
|
||||||
(let [editing* (mf/use-state false)
|
(let [editing* (mf/use-state false)
|
||||||
editing? (deref editing*)
|
editing? (deref editing*)
|
||||||
|
|
||||||
input-ref (mf/use-ref)
|
input-ref (mf/use-ref)
|
||||||
input (mf/ref-val input-ref)
|
input (mf/ref-val input-ref)
|
||||||
title (str name ": " values)
|
|
||||||
|
title (if values (str name ": " values) name)
|
||||||
|
|
||||||
on-edit
|
on-edit
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
(fn [event]
|
(fn [event]
|
||||||
(dom/stop-propagation event)
|
(dom/stop-propagation event)
|
||||||
(reset! editing* true)
|
(reset! editing* true)
|
||||||
(dom/focus! input)))
|
(dom/focus! input)))
|
||||||
|
|
||||||
on-stop-edit
|
on-stop-edit
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
(mf/deps on-blur)
|
(mf/deps on-blur)
|
||||||
|
@ -43,6 +46,7 @@
|
||||||
(reset! editing* false)
|
(reset! editing* false)
|
||||||
(when on-blur
|
(when on-blur
|
||||||
(on-blur event))))
|
(on-blur event))))
|
||||||
|
|
||||||
on-focus
|
on-focus
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
(fn [event]
|
(fn [event]
|
||||||
|
@ -70,6 +74,8 @@
|
||||||
[:div {:class (stl/css :input-with-values-edit-container)}
|
[:div {:class (stl/css :input-with-values-edit-container)}
|
||||||
[:> input* props]]
|
[:> input* props]]
|
||||||
[:div {:class (stl/css :input-with-values-container :input-with-values-grid)
|
[:div {:class (stl/css :input-with-values-container :input-with-values-grid)
|
||||||
:title title :on-click on-edit}
|
:title title
|
||||||
|
:on-click on-edit}
|
||||||
[:span {:class (stl/css :input-with-values-name)} name]
|
[:span {:class (stl/css :input-with-values-name)} name]
|
||||||
[:span {:class (stl/css :input-with-values-values)} values]])))
|
(when values
|
||||||
|
[:span {:class (stl/css :input-with-values-values)} values])])))
|
||||||
|
|
|
@ -281,25 +281,40 @@
|
||||||
(fn [pos value]
|
(fn [pos value]
|
||||||
(st/emit! (dwv/update-property-value id-component pos value))))
|
(st/emit! (dwv/update-property-value id-component pos value))))
|
||||||
|
|
||||||
|
update-property-name
|
||||||
|
(mf/use-fn
|
||||||
|
(mf/deps variant-id)
|
||||||
|
(fn [event]
|
||||||
|
(let [value (dom/get-target-val event)
|
||||||
|
pos (-> (dom/get-current-target event)
|
||||||
|
(dom/get-data "position")
|
||||||
|
int)]
|
||||||
|
(st/emit! (dwv/update-property-name variant-id pos value)))))
|
||||||
|
|
||||||
switch-component
|
switch-component
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
(mf/deps shape)
|
(mf/deps shape)
|
||||||
(fn [id]
|
(fn [id]
|
||||||
(st/emit! (dwl/component-swap shape (:component-file shape) id))))]
|
(st/emit! (dwl/component-swap shape (:component-file shape) id))))]
|
||||||
|
|
||||||
[:*
|
[:*
|
||||||
(for [[pos prop] (map vector (range) properties)]
|
(for [[pos prop] (map vector (range) properties)]
|
||||||
|
|
||||||
[:div {:key (str (:id shape) pos) :class (stl/css :variant-property-container)}
|
[:div {:key (str (:id shape) pos) :class (stl/css :variant-property-container)}
|
||||||
(if (ctk/main-instance? shape)
|
(if (ctk/main-instance? shape)
|
||||||
[:*
|
[:*
|
||||||
[:span {:class (stl/css :variant-property-name :variant-property-name-bg)} (:name prop)]
|
[:div {:class (stl/css :variant-property-name-wrapper)}
|
||||||
|
[:> input-with-values* {:name (:name prop)
|
||||||
|
:data-position pos
|
||||||
|
:on-blur update-property-name}]]
|
||||||
[:> combobox* {:id (str "variant-prop-" (:id shape) pos)
|
[:> combobox* {:id (str "variant-prop-" (:id shape) pos)
|
||||||
:default-selected (if (str/empty? (:value prop)) "--" (:value prop))
|
:default-selected (if (str/empty? (:value prop)) "--" (:value prop))
|
||||||
:options (clj->js (get-options (:name prop)))
|
:options (clj->js (get-options (:name prop)))
|
||||||
:on-change (partial change-property-value pos)}]]
|
:on-change (partial change-property-value pos)}]]
|
||||||
|
|
||||||
[:*
|
[:*
|
||||||
[:span {:class (stl/css :variant-property-name)} (:name prop)]
|
[:span {:class (stl/css :variant-property-name)}
|
||||||
|
(:name prop)]
|
||||||
[:& select {:default-value id-component
|
[:& select {:default-value id-component
|
||||||
:options (filter-matching id-component (keyword (:name prop)))
|
:options (filter-matching id-component (keyword (:name prop)))
|
||||||
:on-change switch-component}]])])]))
|
:on-change switch-component}]])])]))
|
||||||
|
|
|
@ -717,22 +717,22 @@
|
||||||
padding-right: var(--sp-xxs);
|
padding-right: var(--sp-xxs);
|
||||||
}
|
}
|
||||||
|
|
||||||
.variant-property-name-bg {
|
|
||||||
border-radius: $br-8;
|
|
||||||
background-color: var(--assets-item-background-color);
|
|
||||||
}
|
|
||||||
|
|
||||||
.variant-property-name {
|
.variant-property-name {
|
||||||
color: var(--color-foreground-primary);
|
color: var(--color-foreground-primary);
|
||||||
|
height: var(--sp-xxxl);
|
||||||
width: $s-104;
|
width: $s-104;
|
||||||
|
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
height: var(--sp-xxxl);
|
|
||||||
|
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.variant-property-name-wrapper {
|
||||||
|
display: flex;
|
||||||
|
flex: 0 0 auto;
|
||||||
|
width: $s-104;
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue