Skip to content

Commit 4e13dd3

Browse files
committed
move cmdk to views
1 parent e5c0b64 commit 4e13dd3

File tree

3 files changed

+52
-58
lines changed

3 files changed

+52
-58
lines changed

src/renderer/dialog/cmdk.cljs

Lines changed: 0 additions & 52 deletions
This file was deleted.

src/renderer/dialog/events.cljs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
(ns renderer.dialog.events
22
(:require
33
[re-frame.core :as rf]
4-
[renderer.dialog.views :as v]
5-
[renderer.dialog.cmdk :as cmdk]))
4+
[renderer.dialog.views :as v]))
65

76
(defn create
87
[db dialog]
@@ -11,7 +10,7 @@
1110
(rf/reg-event-db
1211
::cmdk
1312
(fn [db [_]]
14-
(create db {:content [cmdk/root]
13+
(create db {:content [v/cmdk]
1514
:attrs {:class "dialog-content dialog-cmdk-content"}})))
1615

1716
(rf/reg-event-db

src/renderer/dialog/views.cljs

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
(ns renderer.dialog.views
22
(:require
33
["@radix-ui/react-dialog" :as Dialog]
4-
[config]
5-
[platform]
4+
["cmdk" :as Command]
5+
[clojure.string :as str]
6+
[config :as config]
7+
[i18n :refer [t]]
8+
[platform :as platform]
69
[re-frame.core :as rf]
710
[renderer.components :as comp]
811
[renderer.dialog.events :as-alias dialog.e]
912
[renderer.dialog.subs :as-alias dialog.s]
1013
[renderer.document.events :as-alias document.e]
11-
[renderer.document.subs :as-alias document.s]))
14+
[renderer.document.subs :as-alias document.s]
15+
[renderer.menubar.views :as menubar]))
1216

1317
(defn close-button
1418
[]
@@ -67,6 +71,49 @@
6771
"Save"]]
6872
[close-button]]))
6973

74+
(defn cmdk-item
75+
[{:keys [label action key icon type]}]
76+
(when-not (= type :separator)
77+
[:> Command/CommandItem
78+
{:key key
79+
:on-select (fn []
80+
(rf/dispatch [::dialog.e/close false])
81+
(rf/dispatch action))}
82+
[:div.w-7.h-7.mr-2.rounded.line-height-6.flex.justify-center.items-center
83+
{:class (when icon "overlay")}
84+
(when icon [comp/icon icon {:class "icon"}])]
85+
label
86+
[:div.right-slot
87+
[comp/shortcuts action]]]))
88+
89+
(defn cmdk-group-inner
90+
[items label]
91+
(for [i items]
92+
^{:key key}
93+
(if-not (:items i)
94+
[cmdk-item (update i :label #(str/join " - " (remove nil? [label %])))]
95+
(cmdk-group-inner (:items i) (:label i)))))
96+
97+
(defn cmdk-group
98+
[{:keys [label items]}]
99+
[:> Command/CommandGroup
100+
{:heading label}
101+
(cmdk-group-inner items nil)])
102+
103+
(defn cmdk
104+
[]
105+
[:> Command/Command
106+
{:label "Command Menu"
107+
:on-key-down #(when-not (= (.-key %) "Escape") (.stopPropagation %))}
108+
[:> Command/CommandInput
109+
{:placeholder (t [:cmdk/search-command "Search for a command"])}]
110+
[:> Command/CommandList
111+
[:> Command/CommandEmpty
112+
(t [:cmdk/no-results "No results found."])]
113+
(for [i (menubar/root-menu)]
114+
^{:key (:key i)}
115+
[cmdk-group i])]])
116+
70117
(defn root
71118
[]
72119
(let [dialogs @(rf/subscribe [::dialog.s/dialogs])]

0 commit comments

Comments
 (0)