mirror of
https://github.com/penpot/penpot.git
synced 2026-11-16 15:11:17 +00:00
♻️ Refactor the share link dialog to the design system (#12965)
* ♻️ Split the share link dialog into smaller components Move the dialog state into a content component and extract the permissions section, the page selection, the select rows, the collapsible panel and the destroy confirmation. The confirmation now keeps the link to destroy instead of matching it by flags, so deleting a link no longer depends on the options snapshot. AI-assisted-by: deepseek-v4.1-flash (cherry picked from commit 3ce7f9d09765e4f6afc033db544aabca379c0ca4) * ♻️ Use the design system controls in the share link dialog Replace the deprecated select, the raw text input and the hand-written page checkboxes with the design system select, input field and checkbox components, and drop the deprecated icons and the unused uuid parsing. AI-assisted-by: deepseek-v4.1-flash (cherry picked from commit 3ce7f9d09765e4f6afc033db544aabca379c0ca4) * ✨ Add dialog semantics to the share link dialog Give the dialog and the destroy confirmation proper dialog and alertdialog roles and labels, cancel the confirmation with Escape, and connect the disclosure button with its panel through aria-controls. AI-assisted-by: deepseek-v4.1-flash (cherry picked from commit 3ce7f9d09765e4f6afc033db544aabca379c0ca4) * ✨ Toggle the share dialog from the viewer header Let the share button close the dialog when it is already open, report the dialog state with aria-expanded and aria-pressed, and mark the button with data-allow-click-modal so the closing click does not count as an outside click. Drop the click-outside guard on close; it is not needed once the button can reopen the dialog. AI-assisted-by: deepseek-v4.1-flash (cherry picked from commit 3ce7f9d09765e4f6afc033db544aabca379c0ca4) * 🐛 Move focus into the share dialog and restore it on close Move focus into the dialog when it opens and into the Cancel button when the delete confirmation opens, so Escape reaches the confirmation handler instead of closing the whole dialog. Restore focus to Destroy link when the confirmation closes and to the Share button when the dialog closes. AI-assisted-by: deepseek-v4.1-flash * ♻️ Apply review follow-ups to the share link dialog Use aria-haspopup instead of aria-pressed on the Share toggle, drop the raw z-index, and express the small spacing values with px2rem. Restore the collapsible pointer cursor and merge its two classes. Memoize the permission options, expose aria-controls only while the panel is open, and label the read-only URL field. AI-assisted-by: deepseek-v4.1-flash
This commit is contained in:
parent
192e76781a
commit
24a5fd2043
@ -35,6 +35,11 @@
|
||||
(dm/get-in state [:viewer-local :fullscreen?]))
|
||||
st/state))
|
||||
|
||||
(def ^:private share-modal-open-ref
|
||||
(l/derived (fn [state]
|
||||
(= :share-link (dm/get-in state [::modal/modal :type])))
|
||||
st/state))
|
||||
|
||||
(defn open-login-dialog
|
||||
[]
|
||||
(modal/show! :login-register {}))
|
||||
@ -131,6 +136,15 @@
|
||||
(mf/defc header-options
|
||||
[{:keys [section zoom page file index permissions interactions-mode share]}]
|
||||
(let [fullscreen? (mf/deref fullscreen-ref)
|
||||
share-open? (mf/deref share-modal-open-ref)
|
||||
|
||||
share-btn-ref (mf/use-ref nil)
|
||||
share-was-open* (mf/use-ref false)
|
||||
|
||||
set-share-btn-ref
|
||||
(mf/use-fn
|
||||
(fn [node]
|
||||
(mf/set-ref-val! share-btn-ref node)))
|
||||
|
||||
toggle-fullscreen
|
||||
(mf/use-fn
|
||||
@ -144,11 +158,19 @@
|
||||
|
||||
open-share-dialog
|
||||
(mf/use-fn
|
||||
(mf/deps page)
|
||||
(mf/deps page file)
|
||||
(fn []
|
||||
(modal/show! :share-link {:page page :file file})
|
||||
(modal/disallow-click-outside!)))
|
||||
|
||||
toggle-share-dialog
|
||||
(mf/use-fn
|
||||
(mf/deps open-share-dialog share-open?)
|
||||
(fn []
|
||||
(if share-open?
|
||||
(modal/hide!)
|
||||
(open-share-dialog))))
|
||||
|
||||
handle-increase
|
||||
(mf/use-fn
|
||||
#(st/emit! dv/increase-zoom))
|
||||
@ -168,6 +190,12 @@
|
||||
handle-zoom-fit
|
||||
(mf/use-fn
|
||||
#(st/emit! dv/zoom-to-fit))]
|
||||
(mf/with-effect [share-open?]
|
||||
(let [was-open? (mf/ref-val share-was-open*)]
|
||||
(when (and was-open? (not share-open?))
|
||||
(some-> (mf/ref-val share-btn-ref) dom/focus!))
|
||||
(mf/set-ref-val! share-was-open* share-open?)))
|
||||
|
||||
(mf/with-effect [permissions share]
|
||||
(when (and
|
||||
(:in-team permissions)
|
||||
@ -211,7 +239,11 @@
|
||||
(when (:in-team permissions)
|
||||
[:> button* {:variant "primary"
|
||||
:class (stl/css :share-btn)
|
||||
:on-click open-share-dialog}
|
||||
:on-ref set-share-btn-ref
|
||||
:aria-expanded share-open?
|
||||
:aria-haspopup "dialog"
|
||||
:data-allow-click-modal "share-link"
|
||||
:on-click toggle-share-dialog}
|
||||
(tr "labels.share")])
|
||||
|
||||
(when-not (:is-logged permissions)
|
||||
|
||||
@ -10,7 +10,6 @@
|
||||
[app.common.data :as d]
|
||||
[app.common.data.macros :as dm]
|
||||
[app.common.logging :as log]
|
||||
[app.common.uuid :as uuid]
|
||||
[app.main.data.common :as dc]
|
||||
[app.main.data.event :as ev]
|
||||
[app.main.data.modal :as modal]
|
||||
@ -18,113 +17,259 @@
|
||||
[app.main.refs :as refs]
|
||||
[app.main.router :as rt]
|
||||
[app.main.store :as st]
|
||||
[app.main.ui.components.select :refer [select]]
|
||||
[app.main.ui.ds.buttons.button :refer [button*]]
|
||||
[app.main.ui.ds.buttons.icon-button :refer [icon-button*]]
|
||||
[app.main.ui.ds.controls.checkbox :refer [checkbox*]]
|
||||
[app.main.ui.ds.controls.select :refer [select*]]
|
||||
[app.main.ui.ds.controls.utilities.input-field :refer [input-field*]]
|
||||
[app.main.ui.ds.foundations.assets.icon :refer [icon*] :as i]
|
||||
[app.main.ui.icons :as deprecated-icon]
|
||||
[app.util.clipboard :as clipboard]
|
||||
[app.util.dom :as dom]
|
||||
[app.util.i18n :as i18n :refer [tr]]
|
||||
[app.util.keyboard :as kbd]
|
||||
[rumext.v2 :as mf]))
|
||||
|
||||
(log/set-level! :warn)
|
||||
|
||||
(defn- prepare-params
|
||||
(defn- link-params
|
||||
[{:keys [pages who-comment who-inspect]}]
|
||||
{:pages pages
|
||||
:who-comment who-comment
|
||||
:who-inspect who-inspect})
|
||||
|
||||
(mf/defc share-link-dialog
|
||||
{::mf/register modal/components
|
||||
::mf/register-as :share-link
|
||||
::mf/wrap-props false}
|
||||
[{:keys [file page]}]
|
||||
(let [current-page page
|
||||
current-page-id (:id page)
|
||||
slinks (mf/deref refs/share-links)
|
||||
router (mf/deref refs/router)
|
||||
route (mf/deref refs/route)
|
||||
zoom-type (mf/deref refs/viewer-zoom-type)
|
||||
page-ids (dm/get-in file [:data :pages])
|
||||
(defn- link->url
|
||||
[router route page-ids zoom-type link]
|
||||
(let [page-id (d/seek #(contains? (:pages link) %) page-ids)
|
||||
params (-> (:query-params route)
|
||||
(assoc :share-id (:id link))
|
||||
(assoc :page-id page-id)
|
||||
(assoc :index "0"))
|
||||
params (if (nil? zoom-type)
|
||||
(dissoc params :zoom)
|
||||
(assoc params :zoom zoom-type))]
|
||||
(rt/resolve-uri router :viewer params)))
|
||||
|
||||
perms-visible* (mf/use-state false)
|
||||
perms-visible? (deref perms-visible*)
|
||||
(defn- copy-url-to-clipboard
|
||||
[url]
|
||||
(clipboard/to-clipboard url)
|
||||
(st/emit! (ntf/show {:level :info
|
||||
:type :toast
|
||||
:content (tr "common.share-link.link-copied-success")
|
||||
:timeout 1000})
|
||||
(ev/event {::ev/name "copy-share-link"
|
||||
::ev/origin "viewer"})))
|
||||
|
||||
confirm* (mf/use-state false)
|
||||
confirm? (deref confirm*)
|
||||
(defn- use-collapsible
|
||||
[]
|
||||
(let [expanded* (mf/use-state false)
|
||||
expanded (deref expanded*)
|
||||
content-id (mf/use-id)
|
||||
toggle (mf/use-fn
|
||||
#(swap! expanded* not))]
|
||||
{:expanded expanded
|
||||
:content-id content-id
|
||||
:toggle toggle}))
|
||||
|
||||
options* (mf/use-state
|
||||
{:pages-mode "current"
|
||||
:all-pages false
|
||||
:pages #{(:id page)}
|
||||
:who-comment "team"
|
||||
:who-inspect "team"})
|
||||
options (deref options*)
|
||||
(mf/defc collapsible-panel*
|
||||
{::mf/private true}
|
||||
[{:keys [class title children]}]
|
||||
(let [{:keys [expanded content-id toggle]} (use-collapsible)]
|
||||
[:div {:class class}
|
||||
[:button {:class (stl/css :collapsible-title)
|
||||
:type "button"
|
||||
:aria-expanded expanded
|
||||
:aria-controls (when expanded content-id)
|
||||
:on-click toggle}
|
||||
[:> icon* {:icon-id (if expanded i/arrow-down i/arrow-right)
|
||||
:class (stl/css :collapsible-title-icon)}]
|
||||
title]
|
||||
|
||||
current-link
|
||||
(mf/with-memo [slinks options page-ids]
|
||||
(let [{:keys [pages who-comment who-inspect] :as params} (prepare-params options)
|
||||
slink (d/seek #(and (= (:who-inspect %) who-inspect)
|
||||
(= (:who-comment %) who-comment)
|
||||
(= (:pages %) pages))
|
||||
slinks)]
|
||||
(when slink
|
||||
(let [page-id (d/seek #(contains? (:pages slink) %) page-ids)
|
||||
params (-> (:query-params route)
|
||||
(assoc :share-id (:id slink))
|
||||
(assoc :page-id page-id)
|
||||
(assoc :index "0"))
|
||||
params (if (nil? zoom-type)
|
||||
(dissoc params :zoom)
|
||||
(assoc params :zoom zoom-type))
|
||||
(when ^boolean expanded
|
||||
[:div {:id content-id}
|
||||
children])]))
|
||||
|
||||
href (rt/resolve-uri router :viewer params)]
|
||||
href))))
|
||||
(mf/defc permissions-select-row*
|
||||
{::mf/private true}
|
||||
[{:keys [label value options on-change]}]
|
||||
[:div {:class (stl/css :permissions-select-row)}
|
||||
[:div {:class (stl/css :permissions-label)} label]
|
||||
[:div {:class (stl/css :permissions-control)}
|
||||
[:> select* {:default-selected (dm/str value)
|
||||
:options options
|
||||
:has-portal true
|
||||
:aria-label label
|
||||
:on-change on-change}]]])
|
||||
|
||||
on-close
|
||||
(mf/defc permissions-page-selection*
|
||||
{::mf/private true}
|
||||
[{:keys [file page selected on-toggle-all on-checked-page]}]
|
||||
(let [pages (->> (get-in file [:data :pages])
|
||||
(map #(get-in file [:data :pages-index %])))
|
||||
page-id (:id page)
|
||||
all-selected? (= selected (into #{} (map :id) pages))]
|
||||
|
||||
[:div {:class (stl/css :permissions-pages-field)}
|
||||
[:div {:class (stl/css :permissions-label)}
|
||||
(tr "common.share-link.permissions-pages")]
|
||||
[:div {:class (stl/css :permissions-control)}
|
||||
(if (= 1 (count pages))
|
||||
[:div {:class (stl/css :permissions-page-row)}
|
||||
[:> checkbox* {:id (dm/str "page-" page-id)
|
||||
:class (stl/css :permissions-checkbox)
|
||||
:label (:name page)
|
||||
:checked true
|
||||
:disabled true}]
|
||||
[:span {:class (stl/css :permissions-current-tag)}
|
||||
(tr "common.share-link.current-tag")]]
|
||||
|
||||
[:*
|
||||
[:div {:class (stl/css :permissions-select-all-row)}
|
||||
[:> checkbox* {:id "view-all"
|
||||
:class (stl/css :permissions-checkbox)
|
||||
:label (tr "common.share-link.view-all")
|
||||
:checked all-selected?
|
||||
:on-change on-toggle-all}]
|
||||
[:span {:class (stl/css :permissions-page-count)}
|
||||
(tr "common.share-link.page-shared" (i18n/c (count selected)))]]
|
||||
|
||||
[:ul {:class (stl/css :permissions-pages-selection)}
|
||||
(for [{:keys [id name]} pages]
|
||||
(let [checked? (contains? selected id)
|
||||
only-selected? (and checked? (= 1 (count selected)))]
|
||||
[:li {:class (stl/css :permissions-page-row)
|
||||
:key (dm/str id)}
|
||||
[:> checkbox* {:id (dm/str "page-" id)
|
||||
:class (stl/css :permissions-checkbox)
|
||||
:label name
|
||||
:checked checked?
|
||||
:disabled only-selected?
|
||||
:on-change #(on-checked-page id %)}]
|
||||
(when (= page-id id)
|
||||
[:span {:class (stl/css :permissions-current-tag)}
|
||||
(tr "common.share-link.current-tag")])]))]])]]))
|
||||
|
||||
(mf/defc permissions-section*
|
||||
{::mf/private true}
|
||||
[{:keys [file page link-options on-toggle-all on-checked-page
|
||||
on-comment-change on-inspect-change]}]
|
||||
(let [locale (mf/deref i18n/locale)
|
||||
selected (:pages link-options)
|
||||
permissions (mf/with-memo [locale]
|
||||
[{:id "team" :label (tr "common.share-link.team-members")}
|
||||
{:id "all" :label (tr "common.share-link.all-users")}])]
|
||||
|
||||
[:> collapsible-panel* {:class (stl/css :permissions-section)
|
||||
:title (tr "common.share-link.manage-ops")}
|
||||
[:div {:class (stl/css :permissions-content)}
|
||||
[:> permissions-page-selection* {:file file
|
||||
:page page
|
||||
:selected selected
|
||||
:on-toggle-all on-toggle-all
|
||||
:on-checked-page on-checked-page}]
|
||||
|
||||
[:> permissions-select-row* {:label (tr "common.share-link.permissions-can-comment")
|
||||
:value (:who-comment link-options)
|
||||
:options permissions
|
||||
:on-change on-comment-change}]
|
||||
|
||||
[:> permissions-select-row* {:label (tr "common.share-link.permissions-can-inspect")
|
||||
:value (:who-inspect link-options)
|
||||
:options permissions
|
||||
:on-change on-inspect-change}]]]))
|
||||
|
||||
(mf/defc destroy-link-confirmation*
|
||||
{::mf/private true}
|
||||
[{:keys [on-cancel on-destroy]}]
|
||||
(let [cancel-ref (mf/use-ref nil)
|
||||
|
||||
on-cancel-ref
|
||||
(mf/use-fn
|
||||
(fn [node]
|
||||
(mf/set-ref-val! cancel-ref node)))
|
||||
|
||||
on-key-down
|
||||
(fn [event]
|
||||
(dom/prevent-default event)
|
||||
(st/emit! (modal/hide))
|
||||
(modal/disallow-click-outside!))
|
||||
(when (kbd/esc? event)
|
||||
(dom/stop-propagation event)
|
||||
(on-cancel event)))]
|
||||
|
||||
(mf/with-effect []
|
||||
(some-> (mf/ref-val cancel-ref) dom/focus!))
|
||||
|
||||
[:div {:class (stl/css :share-link-confirm)
|
||||
:role "alertdialog"
|
||||
:aria-modal true
|
||||
:aria-labelledby "share-link-title"
|
||||
:aria-describedby "share-link-confirm-description"
|
||||
:tab-index "-1"
|
||||
:on-key-down on-key-down}
|
||||
[:div {:id "share-link-confirm-description"
|
||||
:class (stl/css :share-link-confirm-description)}
|
||||
(tr "common.share-link.confirm-deletion-link-description")]
|
||||
[:div {:class (stl/css :share-link-confirm-actions)}
|
||||
[:> button* {:variant "secondary"
|
||||
:type "button"
|
||||
:on-ref on-cancel-ref
|
||||
:on-click on-cancel}
|
||||
(tr "labels.cancel")]
|
||||
[:> button* {:variant "destructive"
|
||||
:type "button"
|
||||
:on-click on-destroy}
|
||||
(tr "common.share-link.destroy-link")]]]))
|
||||
|
||||
(mf/defc share-link-content*
|
||||
{::mf/private true}
|
||||
[{:keys [file page on-request-destroy on-destroy-ref]}]
|
||||
(let [share-links (mf/deref refs/share-links)
|
||||
router (mf/deref refs/router)
|
||||
route (mf/deref refs/route)
|
||||
zoom-type (mf/deref refs/viewer-zoom-type)
|
||||
|
||||
page-ids (dm/get-in file [:data :pages])
|
||||
all-page-ids (into #{} page-ids)
|
||||
|
||||
link-options* (mf/use-state
|
||||
{:pages #{(:id page)}
|
||||
:who-comment "team"
|
||||
:who-inspect "team"})
|
||||
link-options (deref link-options*)
|
||||
|
||||
current-share-link
|
||||
(mf/with-memo [share-links link-options]
|
||||
(let [{:keys [pages who-comment who-inspect]} (link-params link-options)]
|
||||
(d/seek #(and (= (:who-inspect %) who-inspect)
|
||||
(= (:who-comment %) who-comment)
|
||||
(= (:pages %) pages))
|
||||
share-links)))
|
||||
|
||||
current-share-url
|
||||
(mf/with-memo [current-share-link page-ids route router zoom-type]
|
||||
(when (some? current-share-link)
|
||||
(link->url router route page-ids zoom-type current-share-link)))
|
||||
|
||||
on-toggle-all
|
||||
(fn [_event]
|
||||
(reset! confirm* false)
|
||||
(swap! options*
|
||||
(fn [state]
|
||||
(if (true? (:all-pages state))
|
||||
(-> state
|
||||
(assoc :all-pages false)
|
||||
(assoc :pages #{(:id page)}))
|
||||
(-> state
|
||||
(assoc :all-pages true)
|
||||
(assoc :pages (into #{} (get-in file [:data :pages]))))))))
|
||||
(swap! link-options*
|
||||
(fn [{:keys [pages] :as state}]
|
||||
(if (= pages all-page-ids)
|
||||
(assoc state :pages #{(:id page)})
|
||||
(assoc state :pages all-page-ids)))))
|
||||
|
||||
on-mark-checked-page
|
||||
(fn [event]
|
||||
(let [target (dom/get-target event)
|
||||
checked? (dom/checked? target)
|
||||
page-id (uuid/parse (dom/get-data target "page-id"))
|
||||
dif-pages? (not= page-id (first (:pages options)))
|
||||
no-one-page (< 1 (count (:pages options)))
|
||||
should-change? (or ^boolean no-one-page
|
||||
^boolean dif-pages?)]
|
||||
(when ^boolean should-change?
|
||||
(reset! confirm* false)
|
||||
(swap! options*
|
||||
(fn [{:keys [pages] :as state}]
|
||||
(let [pages (if checked?
|
||||
(conj pages page-id)
|
||||
(disj pages page-id))]
|
||||
(-> state
|
||||
(assoc :pages pages)
|
||||
(assoc :all-pages (= (count pages) (count page-ids))))))))))
|
||||
on-checked-page
|
||||
(fn [page-id event]
|
||||
(let [checked? (dom/checked? (dom/get-target event))]
|
||||
(swap! link-options*
|
||||
(fn [{:keys [pages] :as state}]
|
||||
(let [pages (if checked?
|
||||
(conj pages page-id)
|
||||
(disj pages page-id))]
|
||||
(if (seq pages)
|
||||
(assoc state :pages pages)
|
||||
state))))))
|
||||
|
||||
create-link
|
||||
on-create-link
|
||||
(fn [_]
|
||||
(let [params (prepare-params options)
|
||||
(let [params (link-params link-options)
|
||||
params (assoc params :file-id (:id file))]
|
||||
(st/emit! (dc/create-share-link params)
|
||||
(ev/event {::ev/name "create-share-link"
|
||||
@ -132,192 +277,142 @@
|
||||
:can-comment (:who-comment params)
|
||||
:can-inspect-code (:who-inspect params)}))))
|
||||
|
||||
copy-link
|
||||
(fn [_]
|
||||
(clipboard/to-clipboard current-link)
|
||||
(st/emit! (ntf/show {:level :info
|
||||
:type :toast
|
||||
:content (tr "common.share-link.link-copied-success")
|
||||
:timeout 1000})
|
||||
(ev/event {::ev/name "copy-share-link"
|
||||
::ev/origin "viewer"})))
|
||||
on-copy-current-share-url
|
||||
(mf/use-fn
|
||||
(mf/deps current-share-url)
|
||||
(fn [_]
|
||||
(copy-url-to-clipboard current-share-url)))
|
||||
|
||||
try-delete-link
|
||||
(fn [_]
|
||||
(reset! confirm* true))
|
||||
|
||||
delete-link
|
||||
(fn [_]
|
||||
(let [params (prepare-params options)
|
||||
slink (d/seek #(= (:flags %) (:flags params)) slinks)]
|
||||
(reset! confirm* false)
|
||||
(st/emit! (dc/delete-share-link slink))))
|
||||
|
||||
toggle-perms-visibility
|
||||
(fn [_]
|
||||
(swap! perms-visible* not))
|
||||
on-destroy-current-share-link
|
||||
(mf/use-fn
|
||||
(mf/deps current-share-link on-request-destroy)
|
||||
(fn [_]
|
||||
(on-request-destroy current-share-link)))
|
||||
|
||||
on-inspect-change
|
||||
(fn [value]
|
||||
(reset! confirm* false)
|
||||
(swap! options* assoc :who-inspect value))
|
||||
(swap! link-options* assoc :who-inspect value))
|
||||
|
||||
on-comment-change
|
||||
(fn [value]
|
||||
(reset! confirm* false)
|
||||
(swap! options* assoc :who-comment value))]
|
||||
(swap! link-options* assoc :who-comment value))]
|
||||
|
||||
[:div {:class (stl/css :share-modal)}
|
||||
[:div {:class (stl/css :share-link-dialog)}
|
||||
[:div {:class (stl/css :share-link-content)}
|
||||
[:div {:class (stl/css :share-link-form)}
|
||||
(when (some? current-share-url)
|
||||
[:div {:class (stl/css :share-link-url)}
|
||||
[:> input-field* {:id "share-link-url-input"
|
||||
:type "text"
|
||||
:class (stl/css :share-link-url-input)
|
||||
:value (or current-share-url "")
|
||||
:placeholder (tr "common.share-link.placeholder")
|
||||
:aria-label (tr "common.share-link.placeholder")
|
||||
:read-only true}]
|
||||
[:> icon-button* {:variant "secondary"
|
||||
:class (stl/css :share-link-url-button)
|
||||
:aria-label (tr "viewer.header.share.copy-link")
|
||||
:icon i/clipboard
|
||||
:on-click on-copy-current-share-url}]])
|
||||
|
||||
[:div {:class (stl/css :share-link-hint-row)}
|
||||
[:div {:class (stl/css :share-link-hint)} (tr "common.share-link.permissions-hint")]
|
||||
(if (some? current-share-link)
|
||||
[:> button* {:variant "destructive"
|
||||
:type "button"
|
||||
:on-ref on-destroy-ref
|
||||
:on-click on-destroy-current-share-link}
|
||||
(tr "common.share-link.destroy-link")]
|
||||
[:> button* {:variant "primary"
|
||||
:type "button"
|
||||
:on-click on-create-link}
|
||||
(tr "common.share-link.get-link")])]]
|
||||
|
||||
[:> permissions-section* {:file file
|
||||
:page page
|
||||
:link-options link-options
|
||||
:on-toggle-all on-toggle-all
|
||||
:on-checked-page on-checked-page
|
||||
:on-comment-change on-comment-change
|
||||
:on-inspect-change on-inspect-change}]]))
|
||||
|
||||
(mf/defc share-link-dialog
|
||||
{::mf/register modal/components
|
||||
::mf/register-as :share-link
|
||||
::mf/wrap-props false}
|
||||
[{:keys [file page]}]
|
||||
(let [link-to-destroy* (mf/use-state nil)
|
||||
link-to-destroy (deref link-to-destroy*)
|
||||
|
||||
dialog-ref (mf/use-ref nil)
|
||||
destroy-btn-ref (mf/use-ref nil)
|
||||
focus-target* (mf/use-ref nil)
|
||||
|
||||
on-close
|
||||
(mf/use-fn
|
||||
(fn [event]
|
||||
(dom/prevent-default event)
|
||||
(modal/hide!)))
|
||||
|
||||
on-request-destroy
|
||||
(mf/use-fn
|
||||
(fn [link]
|
||||
(reset! link-to-destroy* link)))
|
||||
|
||||
on-destroy-ref
|
||||
(mf/use-fn
|
||||
(fn [node]
|
||||
(mf/set-ref-val! destroy-btn-ref node)))
|
||||
|
||||
on-destroy-link
|
||||
(fn [_]
|
||||
(let [link link-to-destroy]
|
||||
(mf/set-ref-val! focus-target* :dialog)
|
||||
(reset! link-to-destroy* nil)
|
||||
(st/emit! (dc/delete-share-link link))))
|
||||
|
||||
on-cancel-destroy
|
||||
(fn [_]
|
||||
(mf/set-ref-val! focus-target* :destroy-button)
|
||||
(reset! link-to-destroy* nil))]
|
||||
|
||||
(mf/with-effect []
|
||||
(some-> (mf/ref-val dialog-ref) dom/focus!))
|
||||
|
||||
(mf/with-effect [link-to-destroy]
|
||||
(when (nil? link-to-destroy)
|
||||
(when-let [target (mf/ref-val focus-target*)]
|
||||
(mf/set-ref-val! focus-target* nil)
|
||||
(case target
|
||||
:destroy-button
|
||||
(some-> (mf/ref-val destroy-btn-ref) dom/focus!)
|
||||
|
||||
:dialog
|
||||
(some-> (mf/ref-val dialog-ref) dom/focus!)))))
|
||||
|
||||
[:div {:class (stl/css :share-link-modal)}
|
||||
[:div {:ref dialog-ref
|
||||
:class (stl/css :share-link-dialog)
|
||||
:role "dialog"
|
||||
:aria-modal true
|
||||
:aria-labelledby "share-link-title"
|
||||
:tab-index "-1"}
|
||||
[:div {:class (stl/css :share-link-header)}
|
||||
[:h2 {:class (stl/css :share-link-title)}
|
||||
[:h2 {:id "share-link-title"
|
||||
:class (stl/css :share-link-title)}
|
||||
(tr "common.share-link.title")]
|
||||
[:> icon-button* {:variant "ghost"
|
||||
:tooltip-class (stl/css :modal-close-button)
|
||||
:class (stl/css :share-link-close-button)
|
||||
:aria-label (tr "labels.close")
|
||||
:icon i/close
|
||||
:on-click on-close}]]
|
||||
[:div {:class (stl/css :modal-content)}
|
||||
[:div {:class (stl/css :share-link-section)}
|
||||
(when (and (not confirm?) (some? current-link))
|
||||
[:div {:class (stl/css :custon-input-wrapper)}
|
||||
[:input {:class (stl/css :input-text)
|
||||
:type "text"
|
||||
:value (or current-link "")
|
||||
:placeholder (tr "common.share-link.placeholder")
|
||||
:read-only true}]
|
||||
|
||||
[:> icon-button* {:variant "secondary"
|
||||
:aria-label (tr "viewer.header.share.copy-link")
|
||||
:icon i/clipboard
|
||||
:on-click copy-link}]])
|
||||
|
||||
[:div {:class (stl/css :hint-wrapper)}
|
||||
(when (not ^boolean confirm?)
|
||||
[:div {:class (stl/css :hint)} (tr "common.share-link.permissions-hint")])
|
||||
(cond
|
||||
(true? confirm?)
|
||||
[:div {:class (stl/css :confirm-dialog)}
|
||||
[:div {:class (stl/css :description)}
|
||||
(tr "common.share-link.confirm-deletion-link-description")]
|
||||
[:div {:class (stl/css :actions)}
|
||||
[:> button* {:variant "secondary"
|
||||
:type "button"
|
||||
:on-click #(reset! confirm* false)}
|
||||
(tr "labels.cancel")]
|
||||
[:> button* {:variant "destructive"
|
||||
:type "button"
|
||||
:on-click delete-link}
|
||||
(tr "common.share-link.destroy-link")]]]
|
||||
|
||||
(some? current-link)
|
||||
[:> button* {:variant "destructive"
|
||||
:type "button"
|
||||
:on-click try-delete-link}
|
||||
(tr "common.share-link.destroy-link")]
|
||||
|
||||
:else
|
||||
[:> button* {:variant "primary"
|
||||
:type "button"
|
||||
:on-click create-link}
|
||||
(tr "common.share-link.get-link")])]]
|
||||
|
||||
|
||||
(when (not ^boolean confirm?)
|
||||
[:div {:class (stl/css :permissions-section)}
|
||||
[:button {:class (stl/css :manage-permissions)
|
||||
:type "button"
|
||||
:aria-expanded perms-visible?
|
||||
:on-click toggle-perms-visibility}
|
||||
[:span {:class (stl/css-case :icon true
|
||||
:rotated perms-visible?)}
|
||||
[:> icon* {:icon-id i/arrow
|
||||
:class (stl/css :arrow-icon)}]]
|
||||
(tr "common.share-link.manage-ops")]
|
||||
|
||||
(when ^boolean perms-visible?
|
||||
[:*
|
||||
(let [all-selected? (:all-pages options)
|
||||
pages (->> (get-in file [:data :pages])
|
||||
(map #(get-in file [:data :pages-index %])))
|
||||
selected (:pages options)]
|
||||
[:div {:class (stl/css :view-mode)}
|
||||
[:div {:class (stl/css :subtitle)}
|
||||
(tr "common.share-link.permissions-pages")]
|
||||
[:div {:class (stl/css :items)}
|
||||
(if (= 1 (count pages))
|
||||
[:div {:class (stl/css :checkbox-wrapper)}
|
||||
|
||||
[:label {:for (str "page-" current-page-id)
|
||||
:class (stl/css-case :global/checked true)}
|
||||
|
||||
[:span {:class (stl/css :checked)}
|
||||
deprecated-icon/status-tick]
|
||||
|
||||
(:name current-page)]
|
||||
|
||||
[:input {:type "checkbox"
|
||||
:id (dm/str "page-" current-page-id)
|
||||
:data-page-id (dm/str current-page-id)
|
||||
:on-change on-mark-checked-page
|
||||
:checked true}]
|
||||
[:span (str " " (tr "common.share-link.current-tag"))]]
|
||||
|
||||
[:*
|
||||
[:div {:class (stl/css :select-all-row)}
|
||||
[:div {:class (stl/css :checkbox-wrapper)}
|
||||
[:label {:for "view-all"
|
||||
:class (stl/css :select-all-label)}
|
||||
[:span {:class (stl/css-case :global/checked all-selected?)}
|
||||
(when all-selected?
|
||||
deprecated-icon/status-tick)]
|
||||
(tr "common.share-link.view-all")
|
||||
[:input {:type "checkbox"
|
||||
:id "view-all"
|
||||
:checked all-selected?
|
||||
:name "pages-mode"
|
||||
:on-change on-toggle-all}]]]
|
||||
|
||||
[:span {:class (stl/css :count-pages)}
|
||||
(tr "common.share-link.page-shared" (i18n/c (count selected)))]]
|
||||
|
||||
[:ul {:class (stl/css :pages-selection)}
|
||||
(for [{:keys [id name]} pages]
|
||||
[:li {:class (stl/css :checkbox-wrapper :page-row)
|
||||
:key (dm/str id)}
|
||||
[:label {:for (dm/str "page-" id)}
|
||||
[:span {:class (stl/css-case :global/checked (contains? selected id))}
|
||||
(when (contains? selected id)
|
||||
deprecated-icon/status-tick)]
|
||||
name
|
||||
(when (= current-page-id id)
|
||||
[:div {:class (stl/css :current-tag)} (dm/str " " (tr "common.share-link.current-tag"))])
|
||||
[:input {:type "checkbox"
|
||||
:id (dm/str "page-" id)
|
||||
:data-page-id (dm/str id)
|
||||
:on-change on-mark-checked-page
|
||||
:checked (contains? selected id)}]]])]])]])
|
||||
|
||||
[:div {:class (stl/css :access-mode)}
|
||||
[:div {:class (stl/css :subtitle)}
|
||||
(tr "common.share-link.permissions-can-comment")]
|
||||
[:div {:class (stl/css :items)}
|
||||
[:& select
|
||||
{:class (stl/css :who-comment-select)
|
||||
:default-value (dm/str (:who-comment options))
|
||||
:options [{:value "team" :label (tr "common.share-link.team-members")}
|
||||
{:value "all" :label (tr "common.share-link.all-users")}]
|
||||
:on-change on-comment-change}]]]
|
||||
[:div {:class (stl/css :inspect-mode)}
|
||||
[:div {:class (stl/css :subtitle)}
|
||||
(tr "common.share-link.permissions-can-inspect")]
|
||||
[:div {:class (stl/css :items)}
|
||||
[:& select
|
||||
{:class (stl/css :who-inspect-select)
|
||||
:default-value (dm/str (:who-inspect options))
|
||||
:options [{:value "team" :label (tr "common.share-link.team-members")}
|
||||
{:value "all" :label (tr "common.share-link.all-users")}]
|
||||
:on-change on-inspect-change}]]]])])]]]))
|
||||
|
||||
|
||||
[:div {:class (stl/css :share-link-scroll)
|
||||
:hidden (some? link-to-destroy)}
|
||||
[:> share-link-content* {:file file
|
||||
:page page
|
||||
:on-request-destroy on-request-destroy
|
||||
:on-destroy-ref on-destroy-ref}]]
|
||||
|
||||
(when (some? link-to-destroy)
|
||||
[:> destroy-link-confirmation* {:on-cancel on-cancel-destroy
|
||||
:on-destroy on-destroy-link}])]]))
|
||||
|
||||
@ -9,13 +9,112 @@
|
||||
@use "ds/_utils.scss" as *;
|
||||
@use "ds/typography.scss" as *;
|
||||
|
||||
// refactor/ stays for the modal placeholder (%modal-container-base), the
|
||||
// link input (%input-element) and the page checkboxes (%input-checkbox,
|
||||
// %button-icon-small for their tick), which move with their own groups.
|
||||
// refactor/ stays for the modal placeholder (%modal-container-base), which
|
||||
// moves with its own group.
|
||||
@use "refactor/common-refactor.scss" as deprecated;
|
||||
|
||||
.share-modal {
|
||||
display: block;
|
||||
// --- Collapsible (shared)
|
||||
|
||||
.collapsible-title {
|
||||
@include use-typography("headline-small");
|
||||
|
||||
border: none;
|
||||
background: none;
|
||||
color: var(--color-foreground-secondary);
|
||||
block-size: $sz-32;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: flex-start;
|
||||
padding: 0;
|
||||
cursor: pointer;
|
||||
|
||||
&:focus-visible {
|
||||
outline: $b-1 solid var(--color-accent-primary);
|
||||
outline-offset: px2rem(2);
|
||||
}
|
||||
}
|
||||
|
||||
.collapsible-title-icon {
|
||||
margin-inline-end: px2rem(6);
|
||||
}
|
||||
|
||||
// --- Permissions section
|
||||
|
||||
.permissions-section {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--sp-s);
|
||||
}
|
||||
|
||||
.permissions-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--sp-s);
|
||||
}
|
||||
|
||||
.permissions-pages-field,
|
||||
.permissions-select-row {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(px2rem(136), max-content) 1fr;
|
||||
align-items: start;
|
||||
column-gap: var(--sp-s);
|
||||
inline-size: 100%;
|
||||
}
|
||||
|
||||
.permissions-pages-field {
|
||||
max-block-size: px2rem(216);
|
||||
overflow: hidden auto;
|
||||
scrollbar-gutter: stable;
|
||||
}
|
||||
|
||||
.permissions-label {
|
||||
color: var(--color-foreground-secondary);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: flex-start;
|
||||
block-size: $sz-32;
|
||||
}
|
||||
|
||||
.permissions-control {
|
||||
color: var(--color-foreground-primary);
|
||||
}
|
||||
|
||||
.permissions-page-row,
|
||||
.permissions-select-all-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--sp-xs);
|
||||
block-size: $sz-32;
|
||||
}
|
||||
|
||||
.permissions-page-row .permissions-checkbox,
|
||||
.permissions-select-all-row .permissions-checkbox {
|
||||
--input-checkbox-text-color: var(--color-foreground-primary);
|
||||
}
|
||||
|
||||
.permissions-current-tag {
|
||||
@include use-typography("body-small");
|
||||
|
||||
color: var(--color-foreground-secondary);
|
||||
}
|
||||
|
||||
.permissions-select-all-row {
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.permissions-page-count {
|
||||
@include use-typography("body-small");
|
||||
|
||||
color: var(--color-foreground-secondary);
|
||||
}
|
||||
|
||||
.permissions-pages-selection {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
// --- Share link dialog
|
||||
|
||||
.share-link-modal {
|
||||
position: absolute;
|
||||
inset-block-start: px2rem(52);
|
||||
inset-inline: calc(100vw - #{$sz-512}) var(--sp-m);
|
||||
@ -25,7 +124,18 @@
|
||||
.share-link-dialog {
|
||||
@extend %modal-container-base;
|
||||
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-block-size: unset;
|
||||
|
||||
&:focus {
|
||||
outline: none;
|
||||
}
|
||||
}
|
||||
|
||||
.share-link-scroll {
|
||||
min-block-size: 0;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.share-link-header {
|
||||
@ -38,14 +148,13 @@
|
||||
color: var(--color-foreground-primary);
|
||||
}
|
||||
|
||||
// Tooltip wrapper of the close button: it places it in the corner.
|
||||
.modal-close-button {
|
||||
.share-link-close-button {
|
||||
position: absolute;
|
||||
inset-block-start: var(--sp-s);
|
||||
inset-inline-end: var(--sp-xs);
|
||||
}
|
||||
|
||||
.modal-content {
|
||||
.share-link-content {
|
||||
@include use-typography("body-small");
|
||||
|
||||
display: flex;
|
||||
@ -53,171 +162,61 @@
|
||||
gap: var(--sp-xxl);
|
||||
}
|
||||
|
||||
.share-link-section {
|
||||
.share-link-form {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--sp-s);
|
||||
}
|
||||
|
||||
.hint-wrapper {
|
||||
.share-link-url {
|
||||
display: flex;
|
||||
padding: px2rem(1);
|
||||
}
|
||||
|
||||
.share-link-url-input {
|
||||
border-end-end-radius: 0;
|
||||
border-start-end-radius: 0;
|
||||
}
|
||||
|
||||
.share-link-url-button {
|
||||
border-start-start-radius: 0;
|
||||
border-end-start-radius: 0;
|
||||
}
|
||||
|
||||
.share-link-hint-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--sp-xs);
|
||||
}
|
||||
|
||||
.hint {
|
||||
.share-link-hint {
|
||||
flex-grow: 1;
|
||||
color: var(--color-foreground-secondary);
|
||||
}
|
||||
|
||||
.custon-input-wrapper {
|
||||
.share-link-confirm {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--sp-xs);
|
||||
border-radius: $br-8;
|
||||
block-size: $sz-32;
|
||||
inline-size: 100%;
|
||||
background-color: var(--color-background-tertiary);
|
||||
}
|
||||
|
||||
.input-text {
|
||||
@extend %input-element;
|
||||
@include use-typography("body-small");
|
||||
|
||||
color: var(--color-foreground-primary);
|
||||
padding-inline-start: var(--sp-s);
|
||||
margin: 0;
|
||||
flex-direction: column;
|
||||
flex-grow: 1;
|
||||
justify-content: center;
|
||||
min-block-size: 0;
|
||||
overflow-y: auto;
|
||||
|
||||
&:focus {
|
||||
outline: none;
|
||||
border: $b-1 solid var(--color-accent-primary);
|
||||
}
|
||||
}
|
||||
|
||||
.description {
|
||||
.share-link-confirm-description {
|
||||
@include use-typography("body-small");
|
||||
|
||||
color: var(--color-foreground-secondary);
|
||||
margin-block-end: var(--sp-xxl);
|
||||
}
|
||||
|
||||
.actions {
|
||||
.share-link-confirm-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--sp-xs);
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.permissions-section {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--sp-s);
|
||||
}
|
||||
|
||||
.manage-permissions {
|
||||
@include use-typography("headline-small");
|
||||
|
||||
border: none;
|
||||
background: none;
|
||||
cursor: pointer;
|
||||
color: var(--color-foreground-secondary);
|
||||
block-size: $sz-32;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.icon {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
margin-inline-end: px2rem(6);
|
||||
|
||||
.arrow-icon {
|
||||
flex-shrink: 0;
|
||||
color: var(--color-foreground-secondary);
|
||||
}
|
||||
|
||||
&.rotated {
|
||||
transform: rotate(90deg);
|
||||
}
|
||||
}
|
||||
|
||||
.view-mode,
|
||||
.access-mode,
|
||||
.inspect-mode {
|
||||
display: flex;
|
||||
inline-size: 100%;
|
||||
}
|
||||
|
||||
.view-mode {
|
||||
max-block-size: px2rem(216);
|
||||
overflow: hidden auto;
|
||||
scrollbar-gutter: stable;
|
||||
}
|
||||
|
||||
.subtitle {
|
||||
color: var(--color-foreground-secondary);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: flex-start;
|
||||
inline-size: px2rem(136);
|
||||
block-size: $sz-32;
|
||||
}
|
||||
|
||||
.items {
|
||||
flex-grow: 1;
|
||||
color: var(--color-foreground-primary);
|
||||
}
|
||||
|
||||
.select-all-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--sp-xs);
|
||||
justify-content: space-between;
|
||||
block-size: $sz-32;
|
||||
border-block-end: $b-1 solid var(--color-background-quaternary);
|
||||
}
|
||||
|
||||
.select-all-label {
|
||||
color: var(--color-foreground-primary);
|
||||
}
|
||||
|
||||
.pages-selection {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.page-row {
|
||||
border-block-end: $b-1 solid var(--color-background-quaternary);
|
||||
|
||||
&:last-child {
|
||||
border-block-end: none;
|
||||
}
|
||||
}
|
||||
|
||||
.count-pages,
|
||||
.current-tag {
|
||||
@include use-typography("body-small");
|
||||
|
||||
color: var(--color-foreground-secondary);
|
||||
}
|
||||
|
||||
.checkbox-wrapper {
|
||||
@extend %input-checkbox;
|
||||
|
||||
block-size: $sz-32;
|
||||
padding: 0;
|
||||
|
||||
span.checked {
|
||||
background-color: var(--color-accent-primary);
|
||||
border: $b-1 solid var(--color-accent-primary);
|
||||
|
||||
// The legacy tick icon has no class; it moves with the checkboxes.
|
||||
svg {
|
||||
@extend %button-icon-small;
|
||||
|
||||
stroke: var(--color-background-primary);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user