mirror of
https://github.com/penpot/penpot.git
synced 2025-08-07 14:38:33 +02:00
✨ Add recent used fonts in font selection widget
This commit is contained in:
parent
37f4b83d96
commit
a2c3b0926b
5 changed files with 57 additions and 9 deletions
|
@ -11,8 +11,10 @@
|
|||
[app.common.exceptions :as ex]
|
||||
[app.common.pages :as cp]
|
||||
[app.common.text :as txt]
|
||||
[app.main.data.fonts :as fts]
|
||||
[app.main.data.shortcuts :as dsc]
|
||||
[app.main.fonts :as fonts]
|
||||
[app.main.refs :as refs]
|
||||
[app.main.store :as st]
|
||||
[app.main.ui.components.editable-select :refer [editable-select]]
|
||||
[app.main.ui.components.numeric-input :refer [numeric-input]]
|
||||
|
@ -93,13 +95,14 @@
|
|||
|
||||
(mf/defc font-selector
|
||||
[{:keys [on-select on-close current-font] :as props}]
|
||||
(let [selected (mf/use-state current-font)
|
||||
state (mf/use-state {:term "" :backends #{}})
|
||||
(let [selected (mf/use-state current-font)
|
||||
state (mf/use-state {:term "" :backends #{}})
|
||||
|
||||
flist (mf/use-ref)
|
||||
input (mf/use-ref)
|
||||
flist (mf/use-ref)
|
||||
input (mf/use-ref)
|
||||
|
||||
fonts (mf/use-memo (mf/deps @state) #(filter-fonts @state @fonts/fonts))
|
||||
fonts (mf/use-memo (mf/deps @state) #(filter-fonts @state @fonts/fonts))
|
||||
recent-fonts (mf/deref refs/workspace-recent-fonts)
|
||||
|
||||
select-next
|
||||
(mf/use-callback
|
||||
|
@ -142,6 +145,10 @@
|
|||
(on-select font)
|
||||
(on-close)))
|
||||
]
|
||||
|
||||
(mf/use-effect
|
||||
(fn []
|
||||
(st/emit! (fts/load-recent-fonts))))
|
||||
|
||||
(mf/use-effect
|
||||
(mf/deps fonts)
|
||||
|
@ -183,6 +190,13 @@
|
|||
:ref input
|
||||
:spell-check false
|
||||
:on-change on-filter-change}]
|
||||
(when recent-fonts
|
||||
(for [font recent-fonts]
|
||||
[:& font-item {:key (:id font)
|
||||
:font font
|
||||
:style {}
|
||||
:on-click on-select-and-close
|
||||
:current? (= (:id font) (:id @selected))}]))
|
||||
|
||||
#_[:div.options
|
||||
{:on-click #(swap! state assoc :show-options true)
|
||||
|
@ -242,12 +256,13 @@
|
|||
|
||||
fonts (mf/deref fonts/fontsdb)
|
||||
font (get fonts font-id)
|
||||
recent-fonts (mf/deref refs/workspace-recent-fonts)
|
||||
|
||||
open-selector? (mf/use-state false)
|
||||
|
||||
change-font
|
||||
(mf/use-callback
|
||||
(mf/deps on-change fonts)
|
||||
(mf/deps on-change fonts recent-fonts)
|
||||
(fn [new-font-id]
|
||||
(let [{:keys [family] :as font} (get fonts new-font-id)
|
||||
{:keys [id name weight style]} (fonts/get-default-variant font)]
|
||||
|
@ -255,7 +270,8 @@
|
|||
:font-family family
|
||||
:font-variant-id (or id name)
|
||||
:font-weight weight
|
||||
:font-style style}))))
|
||||
:font-style style})
|
||||
(st/emit! (fts/add-recent-font font)))))
|
||||
|
||||
on-font-size-change
|
||||
(mf/use-callback
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue