|
1 | 1 | (ns renderer.dialog.views
|
2 | 2 | (:require
|
3 | 3 | ["@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] |
6 | 9 | [re-frame.core :as rf]
|
7 | 10 | [renderer.components :as comp]
|
8 | 11 | [renderer.dialog.events :as-alias dialog.e]
|
9 | 12 | [renderer.dialog.subs :as-alias dialog.s]
|
10 | 13 | [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])) |
12 | 16 |
|
13 | 17 | (defn close-button
|
14 | 18 | []
|
|
67 | 71 | "Save"]]
|
68 | 72 | [close-button]]))
|
69 | 73 |
|
| 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 | + |
70 | 117 | (defn root
|
71 | 118 | []
|
72 | 119 | (let [dialogs @(rf/subscribe [::dialog.s/dialogs])]
|
|
0 commit comments