@siiway/ui-react 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +20 -2
- package/dist/components/BrandMark.d.ts +11 -0
- package/dist/components/BrandMark.d.ts.map +1 -0
- package/dist/components/BrandMark.js +11 -0
- package/dist/components/BrandMark.js.map +1 -0
- package/dist/components/CheckboxField.d.ts +15 -0
- package/dist/components/CheckboxField.d.ts.map +1 -0
- package/dist/components/CheckboxField.js +23 -0
- package/dist/components/CheckboxField.js.map +1 -0
- package/dist/components/ColorPickerInput.d.ts +17 -0
- package/dist/components/ColorPickerInput.d.ts.map +1 -0
- package/dist/components/ColorPickerInput.js +97 -0
- package/dist/components/ColorPickerInput.js.map +1 -0
- package/dist/components/CommandPalette.d.ts +53 -0
- package/dist/components/CommandPalette.d.ts.map +1 -0
- package/dist/components/CommandPalette.js +239 -0
- package/dist/components/CommandPalette.js.map +1 -0
- package/dist/components/CopyButton.d.ts +8 -0
- package/dist/components/CopyButton.d.ts.map +1 -0
- package/dist/components/CopyButton.js +17 -0
- package/dist/components/CopyButton.js.map +1 -0
- package/dist/components/CopyIdTrigger.d.ts +31 -0
- package/dist/components/CopyIdTrigger.d.ts.map +1 -0
- package/dist/components/CopyIdTrigger.js +72 -0
- package/dist/components/CopyIdTrigger.js.map +1 -0
- package/dist/components/DataList.d.ts +78 -0
- package/dist/components/DataList.d.ts.map +1 -0
- package/dist/components/DataList.js +150 -0
- package/dist/components/DataList.js.map +1 -0
- package/dist/components/DetailHeader.d.ts +22 -0
- package/dist/components/DetailHeader.d.ts.map +1 -0
- package/dist/components/DetailHeader.js +48 -0
- package/dist/components/DetailHeader.js.map +1 -0
- package/dist/components/DurationInput.d.ts +25 -0
- package/dist/components/DurationInput.d.ts.map +1 -0
- package/dist/components/DurationInput.js +83 -0
- package/dist/components/DurationInput.js.map +1 -0
- package/dist/components/EmptyState.d.ts +14 -0
- package/dist/components/EmptyState.d.ts.map +1 -0
- package/dist/components/EmptyState.js +41 -0
- package/dist/components/EmptyState.js.map +1 -0
- package/dist/components/FormPage.d.ts +22 -0
- package/dist/components/FormPage.d.ts.map +1 -0
- package/dist/components/FormPage.js +65 -0
- package/dist/components/FormPage.js.map +1 -0
- package/dist/components/GetStartedPanel.d.ts +16 -0
- package/dist/components/GetStartedPanel.d.ts.map +1 -0
- package/dist/components/GetStartedPanel.js +96 -0
- package/dist/components/GetStartedPanel.js.map +1 -0
- package/dist/components/LabeledLine.d.ts +12 -0
- package/dist/components/LabeledLine.d.ts.map +1 -0
- package/dist/components/LabeledLine.js +6 -0
- package/dist/components/LabeledLine.js.map +1 -0
- package/dist/components/ListSearch.d.ts +15 -0
- package/dist/components/ListSearch.d.ts.map +1 -0
- package/dist/components/ListSearch.js +23 -0
- package/dist/components/ListSearch.js.map +1 -0
- package/dist/components/LoadingBar.d.ts +8 -0
- package/dist/components/LoadingBar.d.ts.map +1 -0
- package/dist/components/LoadingBar.js +55 -0
- package/dist/components/LoadingBar.js.map +1 -0
- package/dist/components/Outline.d.ts +23 -0
- package/dist/components/Outline.d.ts.map +1 -0
- package/dist/components/Outline.js +150 -0
- package/dist/components/Outline.js.map +1 -0
- package/dist/components/Overview.d.ts +103 -0
- package/dist/components/Overview.d.ts.map +1 -0
- package/dist/components/Overview.js +286 -0
- package/dist/components/Overview.js.map +1 -0
- package/dist/components/PageHeader.d.ts +19 -0
- package/dist/components/PageHeader.d.ts.map +1 -0
- package/dist/components/PageHeader.js +50 -0
- package/dist/components/PageHeader.js.map +1 -0
- package/dist/components/Pagination.d.ts +19 -0
- package/dist/components/Pagination.d.ts.map +1 -0
- package/dist/components/Pagination.js +47 -0
- package/dist/components/Pagination.js.map +1 -0
- package/dist/components/PasswordInput.d.ts +3 -0
- package/dist/components/PasswordInput.d.ts.map +1 -0
- package/dist/components/PasswordInput.js +16 -0
- package/dist/components/PasswordInput.js.map +1 -0
- package/dist/components/PrevNext.d.ts +16 -0
- package/dist/components/PrevNext.d.ts.map +1 -0
- package/dist/components/PrevNext.js +61 -0
- package/dist/components/PrevNext.js.map +1 -0
- package/dist/components/SearchButton.d.ts +16 -0
- package/dist/components/SearchButton.d.ts.map +1 -0
- package/dist/components/SearchButton.js +63 -0
- package/dist/components/SearchButton.js.map +1 -0
- package/dist/components/SearchField.d.ts +10 -0
- package/dist/components/SearchField.d.ts.map +1 -0
- package/dist/components/SearchField.js +67 -0
- package/dist/components/SearchField.js.map +1 -0
- package/dist/components/Segmented.d.ts +28 -0
- package/dist/components/Segmented.d.ts.map +1 -0
- package/dist/components/Segmented.js +74 -0
- package/dist/components/Segmented.js.map +1 -0
- package/dist/components/Select.d.ts +22 -0
- package/dist/components/Select.d.ts.map +1 -0
- package/dist/components/Select.js +50 -0
- package/dist/components/Select.js.map +1 -0
- package/dist/components/Settings.d.ts +103 -0
- package/dist/components/Settings.d.ts.map +1 -0
- package/dist/components/Settings.js +246 -0
- package/dist/components/Settings.js.map +1 -0
- package/dist/components/SideNav.d.ts +34 -0
- package/dist/components/SideNav.d.ts.map +1 -0
- package/dist/components/SideNav.js +99 -0
- package/dist/components/SideNav.js.map +1 -0
- package/dist/components/Skeletons.d.ts +37 -0
- package/dist/components/Skeletons.d.ts.map +1 -0
- package/dist/components/Skeletons.js +109 -0
- package/dist/components/Skeletons.js.map +1 -0
- package/dist/components/StatusPage.d.ts +37 -0
- package/dist/components/StatusPage.d.ts.map +1 -0
- package/dist/components/StatusPage.js +106 -0
- package/dist/components/StatusPage.js.map +1 -0
- package/dist/components/ThemeMenu.d.ts +11 -0
- package/dist/components/ThemeMenu.d.ts.map +1 -0
- package/dist/components/ThemeMenu.js +42 -0
- package/dist/components/ThemeMenu.js.map +1 -0
- package/dist/components/ThemeSwitch.d.ts +14 -0
- package/dist/components/ThemeSwitch.d.ts.map +1 -0
- package/dist/components/ThemeSwitch.js +17 -0
- package/dist/components/ThemeSwitch.js.map +1 -0
- package/dist/components/TopBar.d.ts +45 -0
- package/dist/components/TopBar.d.ts.map +1 -0
- package/dist/components/TopBar.js +145 -0
- package/dist/components/TopBar.js.map +1 -0
- package/dist/components/ViewBanner.d.ts +17 -0
- package/dist/components/ViewBanner.d.ts.map +1 -0
- package/dist/components/ViewBanner.js +14 -0
- package/dist/components/ViewBanner.js.map +1 -0
- package/dist/hooks/platform.d.ts +7 -0
- package/dist/hooks/platform.d.ts.map +1 -0
- package/dist/hooks/platform.js +19 -0
- package/dist/hooks/platform.js.map +1 -0
- package/dist/hooks/useConfirm.d.ts +23 -0
- package/dist/hooks/useConfirm.d.ts.map +1 -0
- package/dist/hooks/useConfirm.js +55 -0
- package/dist/hooks/useConfirm.js.map +1 -0
- package/dist/hooks/useCopy.d.ts +9 -0
- package/dist/hooks/useCopy.d.ts.map +1 -0
- package/dist/hooks/useCopy.js +14 -0
- package/dist/hooks/useCopy.js.map +1 -0
- package/dist/hooks/useDebouncedSearch.d.ts +8 -0
- package/dist/hooks/useDebouncedSearch.d.ts.map +1 -0
- package/dist/hooks/useDebouncedSearch.js +19 -0
- package/dist/hooks/useDebouncedSearch.js.map +1 -0
- package/dist/hooks/usePageClamp.d.ts +4 -0
- package/dist/hooks/usePageClamp.d.ts.map +1 -0
- package/dist/hooks/usePageClamp.js +17 -0
- package/dist/hooks/usePageClamp.js.map +1 -0
- package/dist/hooks/useSearchShortcut.d.ts +8 -0
- package/dist/hooks/useSearchShortcut.d.ts.map +1 -0
- package/dist/hooks/useSearchShortcut.js +38 -0
- package/dist/hooks/useSearchShortcut.js.map +1 -0
- package/dist/hooks/useThemeMode.d.ts +17 -0
- package/dist/hooks/useThemeMode.d.ts.map +1 -0
- package/dist/hooks/useThemeMode.js +62 -0
- package/dist/hooks/useThemeMode.js.map +1 -0
- package/dist/hooks/useToastMessage.d.ts +22 -0
- package/dist/hooks/useToastMessage.d.ts.map +1 -0
- package/dist/hooks/useToastMessage.js +26 -0
- package/dist/hooks/useToastMessage.js.map +1 -0
- package/dist/index.d.ts +45 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +55 -0
- package/dist/index.js.map +1 -0
- package/dist/provider/UiProvider.d.ts +37 -0
- package/dist/provider/UiProvider.d.ts.map +1 -0
- package/dist/provider/UiProvider.js +42 -0
- package/dist/provider/UiProvider.js.map +1 -0
- package/dist/provider/canvas.d.ts +2 -0
- package/dist/provider/canvas.d.ts.map +1 -0
- package/dist/provider/canvas.js +15 -0
- package/dist/provider/canvas.js.map +1 -0
- package/dist/provider/context.d.ts +45 -0
- package/dist/provider/context.d.ts.map +1 -0
- package/dist/provider/context.js +39 -0
- package/dist/provider/context.js.map +1 -0
- package/dist/theme/createTheme.d.ts +13 -0
- package/dist/theme/createTheme.d.ts.map +1 -0
- package/dist/theme/createTheme.js +18 -0
- package/dist/theme/createTheme.js.map +1 -0
- package/package.json +49 -4
- package/src/components/BrandMark.tsx +28 -0
- package/src/components/CheckboxField.tsx +50 -0
- package/src/components/ColorPickerInput.tsx +190 -0
- package/src/components/CommandPalette.tsx +437 -0
- package/src/components/CopyButton.tsx +48 -0
- package/src/components/CopyIdTrigger.tsx +127 -0
- package/src/components/DataList.tsx +332 -0
- package/src/components/DetailHeader.tsx +102 -0
- package/src/components/DurationInput.tsx +133 -0
- package/src/components/EmptyState.tsx +67 -0
- package/src/components/FormPage.tsx +109 -0
- package/src/components/GetStartedPanel.tsx +132 -0
- package/src/components/LabeledLine.tsx +28 -0
- package/src/components/ListSearch.tsx +64 -0
- package/src/components/LoadingBar.tsx +81 -0
- package/src/components/Outline.tsx +208 -0
- package/src/components/Overview.tsx +448 -0
- package/src/components/PageHeader.tsx +80 -0
- package/src/components/Pagination.tsx +105 -0
- package/src/components/PasswordInput.tsx +35 -0
- package/src/components/PrevNext.tsx +98 -0
- package/src/components/SearchButton.tsx +90 -0
- package/src/components/SearchField.tsx +97 -0
- package/src/components/Segmented.tsx +136 -0
- package/src/components/Select.tsx +110 -0
- package/src/components/Settings.tsx +432 -0
- package/src/components/SideNav.tsx +188 -0
- package/src/components/Skeletons.tsx +233 -0
- package/src/components/StatusPage.tsx +188 -0
- package/src/components/ThemeMenu.tsx +83 -0
- package/src/components/ThemeSwitch.tsx +39 -0
- package/src/components/TopBar.tsx +280 -0
- package/src/components/ViewBanner.tsx +51 -0
- package/src/hooks/platform.ts +22 -0
- package/src/hooks/useConfirm.tsx +97 -0
- package/src/hooks/useCopy.ts +20 -0
- package/src/hooks/useDebouncedSearch.ts +19 -0
- package/src/hooks/usePageClamp.ts +20 -0
- package/src/hooks/useSearchShortcut.ts +49 -0
- package/src/hooks/useThemeMode.ts +98 -0
- package/src/hooks/useToastMessage.ts +38 -0
- package/src/index.ts +140 -0
- package/src/provider/UiProvider.tsx +95 -0
- package/src/provider/canvas.ts +17 -0
- package/src/provider/context.tsx +85 -0
- package/src/theme/createTheme.ts +29 -0
|
@@ -0,0 +1,437 @@
|
|
|
1
|
+
// Ctrl K search, as Prism and Vellum both have it: a dialog pinned near the
|
|
2
|
+
// top of the screen (so the list grows downwards and the field stays put), a
|
|
3
|
+
// field, grouped results and the keys to use them. ↑ ↓ move, Enter opens,
|
|
4
|
+
// Esc closes. The app does the searching: it holds the query and gives the
|
|
5
|
+
// groups to show.
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
Button,
|
|
9
|
+
Dialog,
|
|
10
|
+
DialogSurface,
|
|
11
|
+
Spinner,
|
|
12
|
+
makeStyles,
|
|
13
|
+
mergeClasses,
|
|
14
|
+
tokens,
|
|
15
|
+
} from "@fluentui/react-components";
|
|
16
|
+
import { ArrowEnterLeftRegular, DismissRegular, SearchRegular } from "@fluentui/react-icons";
|
|
17
|
+
import {
|
|
18
|
+
useEffect,
|
|
19
|
+
useId,
|
|
20
|
+
useMemo,
|
|
21
|
+
useRef,
|
|
22
|
+
useState,
|
|
23
|
+
type MouseEvent,
|
|
24
|
+
type ReactNode,
|
|
25
|
+
} from "react";
|
|
26
|
+
import { useUiStrings } from "../provider/context.js";
|
|
27
|
+
|
|
28
|
+
// Highlighted terms (<mark>) and code in titles and excerpts.
|
|
29
|
+
const inline = {
|
|
30
|
+
"& mark": {
|
|
31
|
+
backgroundColor: tokens.colorPaletteYellowBackground2,
|
|
32
|
+
color: tokens.colorPaletteYellowForeground1,
|
|
33
|
+
paddingInline: "3px",
|
|
34
|
+
borderRadius: "2px",
|
|
35
|
+
fontWeight: tokens.fontWeightSemibold,
|
|
36
|
+
},
|
|
37
|
+
"& code": {
|
|
38
|
+
fontFamily: tokens.fontFamilyMonospace,
|
|
39
|
+
fontSize: "0.92em",
|
|
40
|
+
paddingInline: "4px",
|
|
41
|
+
paddingBlock: "1px",
|
|
42
|
+
borderRadius: tokens.borderRadiusSmall,
|
|
43
|
+
backgroundColor: tokens.colorNeutralBackground3,
|
|
44
|
+
},
|
|
45
|
+
} as const;
|
|
46
|
+
|
|
47
|
+
const useStyles = makeStyles({
|
|
48
|
+
surface: {
|
|
49
|
+
width: "min(640px, calc(100vw - 32px))",
|
|
50
|
+
maxWidth: "640px",
|
|
51
|
+
padding: 0,
|
|
52
|
+
alignSelf: "flex-start",
|
|
53
|
+
marginTop: "12vh",
|
|
54
|
+
overflow: "hidden",
|
|
55
|
+
borderRadius: tokens.borderRadiusXLarge,
|
|
56
|
+
"@media (max-width: 640px)": { marginTop: "16px" },
|
|
57
|
+
},
|
|
58
|
+
inputRow: {
|
|
59
|
+
display: "flex",
|
|
60
|
+
alignItems: "center",
|
|
61
|
+
gap: "10px",
|
|
62
|
+
padding: "0 10px 0 16px",
|
|
63
|
+
borderBottom: `1px solid ${tokens.colorNeutralStroke2}`,
|
|
64
|
+
"& > svg": { fontSize: "18px", color: tokens.colorNeutralForeground3, flexShrink: 0 },
|
|
65
|
+
},
|
|
66
|
+
input: {
|
|
67
|
+
flex: 1,
|
|
68
|
+
minWidth: 0,
|
|
69
|
+
height: "52px",
|
|
70
|
+
padding: 0,
|
|
71
|
+
border: "none",
|
|
72
|
+
outline: "none",
|
|
73
|
+
background: "transparent",
|
|
74
|
+
color: tokens.colorNeutralForeground1,
|
|
75
|
+
fontFamily: "inherit",
|
|
76
|
+
fontSize: tokens.fontSizeBase400,
|
|
77
|
+
"::placeholder": { color: tokens.colorNeutralForeground4 },
|
|
78
|
+
},
|
|
79
|
+
list: {
|
|
80
|
+
maxHeight: "min(60vh, 480px)",
|
|
81
|
+
overflowY: "auto",
|
|
82
|
+
padding: "6px",
|
|
83
|
+
},
|
|
84
|
+
group: { marginBottom: "4px" },
|
|
85
|
+
groupHead: {
|
|
86
|
+
display: "flex",
|
|
87
|
+
alignItems: "center",
|
|
88
|
+
justifyContent: "space-between",
|
|
89
|
+
gap: "8px",
|
|
90
|
+
minHeight: "28px",
|
|
91
|
+
padding: "6px 4px 2px 10px",
|
|
92
|
+
fontSize: tokens.fontSizeBase200,
|
|
93
|
+
color: tokens.colorNeutralForeground3,
|
|
94
|
+
},
|
|
95
|
+
item: {
|
|
96
|
+
display: "flex",
|
|
97
|
+
alignItems: "center",
|
|
98
|
+
gap: "12px",
|
|
99
|
+
padding: "8px 10px",
|
|
100
|
+
borderRadius: tokens.borderRadiusMedium,
|
|
101
|
+
cursor: "pointer",
|
|
102
|
+
color: tokens.colorNeutralForeground1,
|
|
103
|
+
},
|
|
104
|
+
active: { backgroundColor: tokens.colorNeutralBackground1Hover },
|
|
105
|
+
itemIcon: {
|
|
106
|
+
display: "inline-flex",
|
|
107
|
+
flexShrink: 0,
|
|
108
|
+
fontSize: "18px",
|
|
109
|
+
color: tokens.colorNeutralForeground3,
|
|
110
|
+
},
|
|
111
|
+
itemText: {
|
|
112
|
+
display: "flex",
|
|
113
|
+
flexDirection: "column",
|
|
114
|
+
gap: "2px",
|
|
115
|
+
flex: 1,
|
|
116
|
+
minWidth: 0,
|
|
117
|
+
},
|
|
118
|
+
title: {
|
|
119
|
+
fontSize: tokens.fontSizeBase300,
|
|
120
|
+
overflow: "hidden",
|
|
121
|
+
textOverflow: "ellipsis",
|
|
122
|
+
whiteSpace: "nowrap",
|
|
123
|
+
...inline,
|
|
124
|
+
},
|
|
125
|
+
subtitle: {
|
|
126
|
+
fontSize: tokens.fontSizeBase200,
|
|
127
|
+
color: tokens.colorNeutralForeground3,
|
|
128
|
+
overflow: "hidden",
|
|
129
|
+
textOverflow: "ellipsis",
|
|
130
|
+
whiteSpace: "nowrap",
|
|
131
|
+
},
|
|
132
|
+
excerpt: {
|
|
133
|
+
fontSize: tokens.fontSizeBase200,
|
|
134
|
+
lineHeight: 1.4,
|
|
135
|
+
color: tokens.colorNeutralForeground2,
|
|
136
|
+
overflow: "hidden",
|
|
137
|
+
display: "-webkit-box",
|
|
138
|
+
WebkitLineClamp: 2,
|
|
139
|
+
WebkitBoxOrient: "vertical",
|
|
140
|
+
...inline,
|
|
141
|
+
},
|
|
142
|
+
action: { display: "inline-flex", flexShrink: 0 },
|
|
143
|
+
enter: {
|
|
144
|
+
flexShrink: 0,
|
|
145
|
+
fontSize: "14px",
|
|
146
|
+
color: tokens.colorNeutralForeground3,
|
|
147
|
+
visibility: "hidden",
|
|
148
|
+
},
|
|
149
|
+
enterVisible: { visibility: "visible" },
|
|
150
|
+
empty: {
|
|
151
|
+
display: "flex",
|
|
152
|
+
flexDirection: "column",
|
|
153
|
+
alignItems: "center",
|
|
154
|
+
gap: "8px",
|
|
155
|
+
padding: "28px 16px",
|
|
156
|
+
textAlign: "center",
|
|
157
|
+
color: tokens.colorNeutralForeground3,
|
|
158
|
+
},
|
|
159
|
+
footer: {
|
|
160
|
+
display: "flex",
|
|
161
|
+
alignItems: "center",
|
|
162
|
+
justifyContent: "space-between",
|
|
163
|
+
gap: "16px",
|
|
164
|
+
padding: "8px 16px",
|
|
165
|
+
borderTop: `1px solid ${tokens.colorNeutralStroke2}`,
|
|
166
|
+
fontSize: tokens.fontSizeBase200,
|
|
167
|
+
color: tokens.colorNeutralForeground3,
|
|
168
|
+
"@media (max-width: 640px)": { display: "none" },
|
|
169
|
+
},
|
|
170
|
+
hints: { display: "flex", flexWrap: "wrap", alignItems: "center", gap: "12px" },
|
|
171
|
+
hint: { display: "inline-flex", alignItems: "center", gap: "4px" },
|
|
172
|
+
kbd: {
|
|
173
|
+
display: "inline-flex",
|
|
174
|
+
alignItems: "center",
|
|
175
|
+
justifyContent: "center",
|
|
176
|
+
minWidth: "18px",
|
|
177
|
+
height: "18px",
|
|
178
|
+
paddingInline: "5px",
|
|
179
|
+
boxSizing: "border-box",
|
|
180
|
+
border: `1px solid ${tokens.colorNeutralStroke2}`,
|
|
181
|
+
borderRadius: tokens.borderRadiusSmall,
|
|
182
|
+
fontFamily: "inherit",
|
|
183
|
+
fontSize: "11px",
|
|
184
|
+
lineHeight: 1,
|
|
185
|
+
},
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
export interface CommandItem {
|
|
189
|
+
/** Unique within the palette. */
|
|
190
|
+
id: string;
|
|
191
|
+
/** The row's text. Wrap matched words in `<mark>` to highlight them. */
|
|
192
|
+
title: ReactNode;
|
|
193
|
+
/** One line under the title: where the result is, what matched. */
|
|
194
|
+
subtitle?: ReactNode;
|
|
195
|
+
/** Up to two lines under that, such as a passage of the page. `<mark>` highlights here too. */
|
|
196
|
+
excerpt?: ReactNode;
|
|
197
|
+
/** Shown before the text. */
|
|
198
|
+
icon?: ReactNode;
|
|
199
|
+
/**
|
|
200
|
+
* A button at the row's end, such as "Remove" on a recent search. Clicking
|
|
201
|
+
* it doesn't open the row.
|
|
202
|
+
*/
|
|
203
|
+
action?: ReactNode;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export interface CommandGroup {
|
|
207
|
+
/** The group's heading. With none, the items follow the group before. */
|
|
208
|
+
label?: ReactNode;
|
|
209
|
+
/** A button beside the heading, such as "Clear" for recent searches. */
|
|
210
|
+
action?: ReactNode;
|
|
211
|
+
/** The group's rows. A group without any isn't shown. */
|
|
212
|
+
items: CommandItem[];
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export interface CommandPaletteProps {
|
|
216
|
+
/** Whether the palette is open. */
|
|
217
|
+
open: boolean;
|
|
218
|
+
/** Called with the new state, as when Esc or the close button closes it. */
|
|
219
|
+
onOpenChange: (open: boolean) => void;
|
|
220
|
+
/** The field's text. Clear it when you open the palette if each search should start anew. */
|
|
221
|
+
query: string;
|
|
222
|
+
/** Called with the field's text as the reader types. */
|
|
223
|
+
onQueryChange: (query: string) => void;
|
|
224
|
+
/**
|
|
225
|
+
* What to show for the query: `{ label?, action?, items }` each. `action`
|
|
226
|
+
* is a button beside the label, such as "Clear".
|
|
227
|
+
*/
|
|
228
|
+
groups: CommandGroup[];
|
|
229
|
+
/** Called on Enter, or a click on a row. Close the palette here when the row leads away. */
|
|
230
|
+
onSelect: (item: CommandItem) => void;
|
|
231
|
+
/** The field's placeholder and accessible name. */
|
|
232
|
+
placeholder: string;
|
|
233
|
+
/** Shows a spinner in the field while results are on their way. */
|
|
234
|
+
loading?: boolean;
|
|
235
|
+
/** Shown when no group has items: a start screen, or "No results". */
|
|
236
|
+
empty?: ReactNode;
|
|
237
|
+
/** The footer's right side, such as a count of results. */
|
|
238
|
+
status?: ReactNode;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
export function CommandPalette({
|
|
242
|
+
open,
|
|
243
|
+
onOpenChange,
|
|
244
|
+
query,
|
|
245
|
+
onQueryChange,
|
|
246
|
+
groups,
|
|
247
|
+
onSelect,
|
|
248
|
+
placeholder,
|
|
249
|
+
loading,
|
|
250
|
+
empty,
|
|
251
|
+
status,
|
|
252
|
+
}: CommandPaletteProps) {
|
|
253
|
+
const styles = useStyles();
|
|
254
|
+
const strings = useUiStrings();
|
|
255
|
+
const listId = useId();
|
|
256
|
+
const listRef = useRef<HTMLDivElement>(null);
|
|
257
|
+
const inputRef = useRef<HTMLInputElement>(null);
|
|
258
|
+
|
|
259
|
+
// The rows in the order they're drawn, for the arrow keys, and where each
|
|
260
|
+
// group's rows start among them.
|
|
261
|
+
const flat = useMemo(() => groups.flatMap((group) => group.items), [groups]);
|
|
262
|
+
const starts = useMemo(
|
|
263
|
+
() =>
|
|
264
|
+
groups.map((_, g) =>
|
|
265
|
+
groups.slice(0, g).reduce((sum, before) => sum + before.items.length, 0),
|
|
266
|
+
),
|
|
267
|
+
[groups],
|
|
268
|
+
);
|
|
269
|
+
// The active row, by id: when the results change under it, the first row
|
|
270
|
+
// takes over, so Enter always opens what's at the top of fresh results.
|
|
271
|
+
const [activeId, setActiveId] = useState<string | null>(null);
|
|
272
|
+
const activeIndex = Math.max(
|
|
273
|
+
0,
|
|
274
|
+
flat.findIndex((item) => item.id === activeId),
|
|
275
|
+
);
|
|
276
|
+
const active = flat[activeIndex];
|
|
277
|
+
|
|
278
|
+
useEffect(() => {
|
|
279
|
+
if (!active) return;
|
|
280
|
+
listRef.current
|
|
281
|
+
?.querySelector(`[data-index="${activeIndex}"]`)
|
|
282
|
+
?.scrollIntoView({ block: "nearest" });
|
|
283
|
+
}, [active, activeIndex]);
|
|
284
|
+
|
|
285
|
+
const optionId = (index: number) => `${listId}-${index}`;
|
|
286
|
+
|
|
287
|
+
// The field keeps focus, as a combobox's does: a press on a row or its
|
|
288
|
+
// button doesn't take it, and when a button removes itself (a recent
|
|
289
|
+
// search), focus goes back to the field rather than to nowhere.
|
|
290
|
+
const keepFocus = (e: MouseEvent) => e.preventDefault();
|
|
291
|
+
const afterAction = (e: MouseEvent) => {
|
|
292
|
+
e.stopPropagation();
|
|
293
|
+
requestAnimationFrame(() => {
|
|
294
|
+
const now = document.activeElement;
|
|
295
|
+
if (!now || now === document.body || !now.isConnected) inputRef.current?.focus();
|
|
296
|
+
});
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
return (
|
|
300
|
+
<Dialog open={open} onOpenChange={(_, data) => onOpenChange(data.open)}>
|
|
301
|
+
<DialogSurface className={styles.surface} aria-label={placeholder}>
|
|
302
|
+
<div className={styles.inputRow}>
|
|
303
|
+
<SearchRegular />
|
|
304
|
+
<input
|
|
305
|
+
ref={inputRef}
|
|
306
|
+
autoFocus
|
|
307
|
+
className={styles.input}
|
|
308
|
+
role="combobox"
|
|
309
|
+
aria-expanded
|
|
310
|
+
aria-autocomplete="list"
|
|
311
|
+
aria-controls={listId}
|
|
312
|
+
aria-activedescendant={active ? optionId(activeIndex) : undefined}
|
|
313
|
+
aria-label={placeholder}
|
|
314
|
+
placeholder={placeholder}
|
|
315
|
+
autoComplete="off"
|
|
316
|
+
spellCheck={false}
|
|
317
|
+
value={query}
|
|
318
|
+
onChange={(e) => {
|
|
319
|
+
onQueryChange(e.target.value);
|
|
320
|
+
setActiveId(null);
|
|
321
|
+
}}
|
|
322
|
+
onKeyDown={(e) => {
|
|
323
|
+
// An input method's Enter commits its text, not a result.
|
|
324
|
+
if (e.nativeEvent.isComposing) return;
|
|
325
|
+
if (e.key === "ArrowDown") {
|
|
326
|
+
e.preventDefault();
|
|
327
|
+
const next = flat[Math.min(flat.length - 1, activeIndex + 1)];
|
|
328
|
+
if (next) setActiveId(next.id);
|
|
329
|
+
} else if (e.key === "ArrowUp") {
|
|
330
|
+
e.preventDefault();
|
|
331
|
+
const prev = flat[Math.max(0, activeIndex - 1)];
|
|
332
|
+
if (prev) setActiveId(prev.id);
|
|
333
|
+
} else if (e.key === "Enter") {
|
|
334
|
+
e.preventDefault();
|
|
335
|
+
if (active) onSelect(active);
|
|
336
|
+
}
|
|
337
|
+
}}
|
|
338
|
+
/>
|
|
339
|
+
{loading && <Spinner size="extra-tiny" />}
|
|
340
|
+
<Button
|
|
341
|
+
appearance="subtle"
|
|
342
|
+
size="small"
|
|
343
|
+
icon={<DismissRegular />}
|
|
344
|
+
aria-label={strings.close}
|
|
345
|
+
onClick={() => onOpenChange(false)}
|
|
346
|
+
/>
|
|
347
|
+
</div>
|
|
348
|
+
|
|
349
|
+
<div
|
|
350
|
+
ref={listRef}
|
|
351
|
+
id={listId}
|
|
352
|
+
role="listbox"
|
|
353
|
+
aria-label={placeholder}
|
|
354
|
+
className={styles.list}
|
|
355
|
+
>
|
|
356
|
+
{flat.length === 0
|
|
357
|
+
? empty != null && <div className={styles.empty}>{empty}</div>
|
|
358
|
+
: groups.map((group, g) =>
|
|
359
|
+
group.items.length === 0 ? null : (
|
|
360
|
+
<div key={g} role="presentation" className={styles.group}>
|
|
361
|
+
{(group.label != null || group.action != null) && (
|
|
362
|
+
<div className={styles.groupHead} role="presentation">
|
|
363
|
+
<span>{group.label}</span>
|
|
364
|
+
{group.action != null && (
|
|
365
|
+
<span
|
|
366
|
+
className={styles.action}
|
|
367
|
+
onMouseDown={keepFocus}
|
|
368
|
+
onClick={afterAction}
|
|
369
|
+
>
|
|
370
|
+
{group.action}
|
|
371
|
+
</span>
|
|
372
|
+
)}
|
|
373
|
+
</div>
|
|
374
|
+
)}
|
|
375
|
+
{group.items.map((item, j) => {
|
|
376
|
+
const i = starts[g]! + j;
|
|
377
|
+
const isActive = i === activeIndex;
|
|
378
|
+
return (
|
|
379
|
+
<div
|
|
380
|
+
key={item.id}
|
|
381
|
+
id={optionId(i)}
|
|
382
|
+
data-index={i}
|
|
383
|
+
role="option"
|
|
384
|
+
aria-selected={isActive}
|
|
385
|
+
className={mergeClasses(styles.item, isActive && styles.active)}
|
|
386
|
+
// Movement, not hover: a pointer resting on the list
|
|
387
|
+
// mustn't take the row from fresh results.
|
|
388
|
+
onMouseMove={() => !isActive && setActiveId(item.id)}
|
|
389
|
+
onMouseDown={keepFocus}
|
|
390
|
+
onClick={() => onSelect(item)}
|
|
391
|
+
>
|
|
392
|
+
{item.icon && <span className={styles.itemIcon}>{item.icon}</span>}
|
|
393
|
+
<span className={styles.itemText}>
|
|
394
|
+
<span className={styles.title}>{item.title}</span>
|
|
395
|
+
{item.subtitle && (
|
|
396
|
+
<span className={styles.subtitle}>{item.subtitle}</span>
|
|
397
|
+
)}
|
|
398
|
+
{item.excerpt && <span className={styles.excerpt}>{item.excerpt}</span>}
|
|
399
|
+
</span>
|
|
400
|
+
{item.action && (
|
|
401
|
+
<span className={styles.action} onClick={afterAction}>
|
|
402
|
+
{item.action}
|
|
403
|
+
</span>
|
|
404
|
+
)}
|
|
405
|
+
<ArrowEnterLeftRegular
|
|
406
|
+
className={mergeClasses(styles.enter, isActive && styles.enterVisible)}
|
|
407
|
+
/>
|
|
408
|
+
</div>
|
|
409
|
+
);
|
|
410
|
+
})}
|
|
411
|
+
</div>
|
|
412
|
+
),
|
|
413
|
+
)}
|
|
414
|
+
</div>
|
|
415
|
+
|
|
416
|
+
<div className={styles.footer}>
|
|
417
|
+
<span className={styles.hints}>
|
|
418
|
+
<span className={styles.hint}>
|
|
419
|
+
<kbd className={styles.kbd}>↑</kbd>
|
|
420
|
+
<kbd className={styles.kbd}>↓</kbd>
|
|
421
|
+
{strings.commandMove}
|
|
422
|
+
</span>
|
|
423
|
+
<span className={styles.hint}>
|
|
424
|
+
<kbd className={styles.kbd}>Enter</kbd>
|
|
425
|
+
{strings.commandOpen}
|
|
426
|
+
</span>
|
|
427
|
+
<span className={styles.hint}>
|
|
428
|
+
<kbd className={styles.kbd}>Esc</kbd>
|
|
429
|
+
{strings.commandClose}
|
|
430
|
+
</span>
|
|
431
|
+
</span>
|
|
432
|
+
{status}
|
|
433
|
+
</div>
|
|
434
|
+
</DialogSurface>
|
|
435
|
+
</Dialog>
|
|
436
|
+
);
|
|
437
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// An icon button that copies a value and briefly shows how it went.
|
|
2
|
+
|
|
3
|
+
import { Button, Tooltip } from "@fluentui/react-components";
|
|
4
|
+
import { CheckmarkRegular, CopyRegular, DismissRegular } from "@fluentui/react-icons";
|
|
5
|
+
import { useUiStrings } from "../provider/context.js";
|
|
6
|
+
import { useCopy } from "../hooks/useCopy.js";
|
|
7
|
+
|
|
8
|
+
/** An icon button that copies `text`. */
|
|
9
|
+
export function CopyButton({
|
|
10
|
+
text,
|
|
11
|
+
label,
|
|
12
|
+
}: {
|
|
13
|
+
/** The value to copy. */
|
|
14
|
+
text: string;
|
|
15
|
+
/** The button's tooltip and accessible name. Defaults to the library's "Copy". */
|
|
16
|
+
label?: string;
|
|
17
|
+
}) {
|
|
18
|
+
const strings = useUiStrings();
|
|
19
|
+
const { state, copy } = useCopy();
|
|
20
|
+
return (
|
|
21
|
+
<Tooltip
|
|
22
|
+
content={
|
|
23
|
+
state === "copied"
|
|
24
|
+
? strings.copied
|
|
25
|
+
: state === "failed"
|
|
26
|
+
? strings.copyFailed
|
|
27
|
+
: (label ?? strings.copy)
|
|
28
|
+
}
|
|
29
|
+
relationship="label"
|
|
30
|
+
withArrow
|
|
31
|
+
>
|
|
32
|
+
<Button
|
|
33
|
+
size="small"
|
|
34
|
+
appearance="subtle"
|
|
35
|
+
icon={
|
|
36
|
+
state === "copied" ? (
|
|
37
|
+
<CheckmarkRegular />
|
|
38
|
+
) : state === "failed" ? (
|
|
39
|
+
<DismissRegular />
|
|
40
|
+
) : (
|
|
41
|
+
<CopyRegular />
|
|
42
|
+
)
|
|
43
|
+
}
|
|
44
|
+
onClick={() => void copy(text)}
|
|
45
|
+
/>
|
|
46
|
+
</Tooltip>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
// Click-to-copy wrapper for list avatars/icons.
|
|
2
|
+
//
|
|
3
|
+
// The My Apps / Teams / Team members / Authorized apps lists show an avatar
|
|
4
|
+
// per row; wrapping it in this trigger lets a click copy the row's id
|
|
5
|
+
// (client id for apps, user id for users, team id for teams) without
|
|
6
|
+
// navigating. The click is stopped so a surrounding card's navigate handler
|
|
7
|
+
// doesn't fire too.
|
|
8
|
+
|
|
9
|
+
import { Tooltip, makeStyles, mergeClasses, tokens } from "@fluentui/react-components";
|
|
10
|
+
import { type ReactNode, type KeyboardEvent, type MouseEvent } from "react";
|
|
11
|
+
import { useUiStrings } from "../provider/context.js";
|
|
12
|
+
import { CopyRegular } from "@fluentui/react-icons";
|
|
13
|
+
import { useCopy } from "../hooks/useCopy.js";
|
|
14
|
+
|
|
15
|
+
const useStyles = makeStyles({
|
|
16
|
+
text: {
|
|
17
|
+
justifyContent: "flex-start",
|
|
18
|
+
gap: "6px",
|
|
19
|
+
maxWidth: "100%",
|
|
20
|
+
fontFamily: tokens.fontFamilyMonospace,
|
|
21
|
+
fontSize: tokens.fontSizeBase200,
|
|
22
|
+
color: tokens.colorNeutralForeground2,
|
|
23
|
+
},
|
|
24
|
+
ellipsis: {
|
|
25
|
+
overflow: "hidden",
|
|
26
|
+
textOverflow: "ellipsis",
|
|
27
|
+
whiteSpace: "nowrap",
|
|
28
|
+
},
|
|
29
|
+
trigger: {
|
|
30
|
+
display: "flex",
|
|
31
|
+
alignItems: "center",
|
|
32
|
+
justifyContent: "center",
|
|
33
|
+
cursor: "pointer",
|
|
34
|
+
borderRadius: tokens.borderRadiusMedium,
|
|
35
|
+
transitionProperty: "opacity",
|
|
36
|
+
transitionDuration: "0.1s",
|
|
37
|
+
":hover": { opacity: 0.75 },
|
|
38
|
+
":focus-visible": {
|
|
39
|
+
outline: `2px solid ${tokens.colorCompoundBrandForeground1}`,
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
interface CopyIdTriggerProps {
|
|
45
|
+
/** The ID to copy. */
|
|
46
|
+
id: string;
|
|
47
|
+
/** The tooltip and accessible name: what a click copies, e.g. "Copy team ID". */
|
|
48
|
+
label: string;
|
|
49
|
+
/** Tooltip label to flash on success. Defaults to the library's "Copied!".
|
|
50
|
+
* Callers should pass a specific label (e.g. "Copied team ID") so the
|
|
51
|
+
* confirmation says *what* landed on the clipboard. */
|
|
52
|
+
copiedLabel?: string;
|
|
53
|
+
/** Extra styles for the trigger, e.g. left-aligned text in a table cell. */
|
|
54
|
+
className?: string;
|
|
55
|
+
/** What to click: a name in a header, a cell, an avatar. */
|
|
56
|
+
children: ReactNode;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Makes its children copy an ID on click, or on Enter or Space. The click
|
|
60
|
+
* doesn't reach a clickable row or card around it. */
|
|
61
|
+
export function CopyIdTrigger({ id, label, copiedLabel, className, children }: CopyIdTriggerProps) {
|
|
62
|
+
const styles = useStyles();
|
|
63
|
+
const strings = useUiStrings();
|
|
64
|
+
const { state, copy: copyText } = useCopy();
|
|
65
|
+
const copy = () => void copyText(id);
|
|
66
|
+
|
|
67
|
+
const onClick = (e: MouseEvent) => {
|
|
68
|
+
e.stopPropagation();
|
|
69
|
+
copy();
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const onKeyDown = (e: KeyboardEvent) => {
|
|
73
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
74
|
+
e.preventDefault();
|
|
75
|
+
e.stopPropagation();
|
|
76
|
+
copy();
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
return (
|
|
81
|
+
<Tooltip
|
|
82
|
+
content={
|
|
83
|
+
state === "copied"
|
|
84
|
+
? (copiedLabel ?? strings.copied)
|
|
85
|
+
: state === "failed"
|
|
86
|
+
? strings.copyFailed
|
|
87
|
+
: label
|
|
88
|
+
}
|
|
89
|
+
relationship="label"
|
|
90
|
+
>
|
|
91
|
+
<div
|
|
92
|
+
className={mergeClasses(styles.trigger, className)}
|
|
93
|
+
role="button"
|
|
94
|
+
tabIndex={0}
|
|
95
|
+
aria-label={label}
|
|
96
|
+
onClick={onClick}
|
|
97
|
+
onKeyDown={onKeyDown}
|
|
98
|
+
>
|
|
99
|
+
{children}
|
|
100
|
+
</div>
|
|
101
|
+
</Tooltip>
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** An id in monospace with a copy icon, copied on click — a list cell or a
|
|
106
|
+
* page footer. */
|
|
107
|
+
export function CopyIdText({
|
|
108
|
+
id,
|
|
109
|
+
label,
|
|
110
|
+
copiedLabel,
|
|
111
|
+
}: {
|
|
112
|
+
/** The ID to show and copy. */
|
|
113
|
+
id: string;
|
|
114
|
+
/** The tooltip and accessible name, e.g. "Copy user ID". */
|
|
115
|
+
label: string;
|
|
116
|
+
/** Tooltip label to flash on success, e.g. "Copied user ID". Defaults to
|
|
117
|
+
* the library's "Copied!". */
|
|
118
|
+
copiedLabel?: string;
|
|
119
|
+
}) {
|
|
120
|
+
const styles = useStyles();
|
|
121
|
+
return (
|
|
122
|
+
<CopyIdTrigger id={id} label={label} copiedLabel={copiedLabel} className={styles.text}>
|
|
123
|
+
<span className={styles.ellipsis}>{id}</span>
|
|
124
|
+
<CopyRegular />
|
|
125
|
+
</CopyIdTrigger>
|
|
126
|
+
);
|
|
127
|
+
}
|