0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-10 00:40:30 -05:00

🐛 It is possible to create empty component annotation

This commit is contained in:
Pablo Alba 2023-06-22 12:03:51 +02:00 committed by Andrés Moya
parent 45e76bc38b
commit 776159c1e8
2 changed files with 27 additions and 20 deletions

View file

@ -2418,6 +2418,9 @@
.hidden {
display: none;
svg {
display: none;
}
}
.counter {

View file

@ -19,6 +19,7 @@
[app.main.ui.icons :as i]
[app.util.dom :as dom]
[app.util.i18n :as i18n :refer [tr]]
[cuerdas.core :as str]
[rumext.v2 :as mf]))
(def component-attrs [:component-id :component-file :shape-ref :main-instance? :annotation])
@ -30,6 +31,7 @@
component-id (:component-id values)
annotation (:annotation component)
editing? (mf/use-state false)
invalid-text? (mf/use-state (str/empty? annotation))
size (mf/use-state (count annotation))
textarea-ref (mf/use-ref)
@ -37,6 +39,7 @@
;; based on https://css-tricks.com/the-cleanest-trick-for-autogrowing-textareas/
autogrow #(let [textarea (mf/ref-val textarea-ref)
text (when textarea (.-value textarea))]
(reset! invalid-text? (str/empty? text))
(when textarea
(reset! size (count text))
(aset (.-dataset (.-parentNode textarea)) "replicatedValue" text)))
@ -55,10 +58,11 @@
(dom/stop-propagation event)
(let [textarea (mf/ref-val textarea-ref)
text (.-value textarea)]
(when-not (str/blank? text)
(reset! editing? false)
(st/emit!
(dw/set-annotations-id-for-create nil)
(dw/update-component-annotation component-id text))))
(dw/update-component-annotation component-id text)))))
workspace-annotations (mf/deref refs/workspace-annotations)
annotations-expanded? (:expanded? workspace-annotations)
creating? (= id (:id-for-create workspace-annotations))
@ -71,7 +75,6 @@
(let [textarea (mf/ref-val textarea-ref)]
(reset! editing? true)
(dom/focus! textarea))))
on-delete-annotation
(mf/use-callback
(mf/deps shape)
@ -112,7 +115,8 @@
(if (or @editing? creating?)
[:*
[:div.icon {:title (if creating? (tr "labels.create") (tr "labels.save"))
:on-click save} i/tick]
:on-click save
:class (dom/classnames :hidden @invalid-text?)} i/tick]
[:div.icon {:title (tr "labels.discard")
:on-click discard} i/cross]]
[:*