@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,332 @@
|
|
|
1
|
+
// The bordered list used by top-level list pages (apps, teams, domains,
|
|
2
|
+
// admin lists): a muted heading row and one grid row per item, its key facts
|
|
3
|
+
// in columns. Secondary columns drop away on narrow screens.
|
|
4
|
+
//
|
|
5
|
+
// <DataList columns={[{ label: "Name", width: "2fr" }, …]}>
|
|
6
|
+
// {items.map((x) => <DataListRow key={x.id} to={`/x/${x.id}`} cells={[…]} />)}
|
|
7
|
+
// </DataList>
|
|
8
|
+
//
|
|
9
|
+
// A row with `to` is one link (keyboard, middle-click, new tab) and gets a
|
|
10
|
+
// chevron; it must not hold other controls. A row with controls passes
|
|
11
|
+
// `onClick` instead and keeps a real link in its first cell.
|
|
12
|
+
|
|
13
|
+
import {
|
|
14
|
+
makeStyles,
|
|
15
|
+
mergeClasses,
|
|
16
|
+
Skeleton,
|
|
17
|
+
SkeletonItem,
|
|
18
|
+
tokens,
|
|
19
|
+
} from "@fluentui/react-components";
|
|
20
|
+
import { ChevronRightRegular } from "@fluentui/react-icons";
|
|
21
|
+
import { createContext, useContext, type ReactNode } from "react";
|
|
22
|
+
import { UiLink } from "../provider/context.js";
|
|
23
|
+
|
|
24
|
+
const NARROW = "@media (max-width: 768px)";
|
|
25
|
+
|
|
26
|
+
export interface DataListColumn {
|
|
27
|
+
/** Heading text; empty for an unlabelled column (actions). */
|
|
28
|
+
label: ReactNode;
|
|
29
|
+
/** CSS grid track, e.g. "minmax(0, 2fr)" or "120px". */
|
|
30
|
+
width: string;
|
|
31
|
+
/** Hidden on narrow screens. */
|
|
32
|
+
secondary?: boolean;
|
|
33
|
+
/** Right-align the column (numbers, actions). */
|
|
34
|
+
end?: boolean;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const useStyles = makeStyles({
|
|
38
|
+
frame: {
|
|
39
|
+
borderRadius: tokens.borderRadiusXLarge,
|
|
40
|
+
border: `1px solid ${tokens.colorNeutralStroke1}`,
|
|
41
|
+
background: tokens.colorNeutralBackground1,
|
|
42
|
+
overflow: "hidden",
|
|
43
|
+
},
|
|
44
|
+
grid: {
|
|
45
|
+
display: "grid",
|
|
46
|
+
gridTemplateColumns: "var(--cols)",
|
|
47
|
+
gap: "16px",
|
|
48
|
+
alignItems: "center",
|
|
49
|
+
[NARROW]: { gridTemplateColumns: "var(--cols-narrow)" },
|
|
50
|
+
},
|
|
51
|
+
head: {
|
|
52
|
+
padding: "10px 16px",
|
|
53
|
+
fontSize: "12px",
|
|
54
|
+
color: tokens.colorNeutralForeground3,
|
|
55
|
+
minHeight: "40px",
|
|
56
|
+
boxSizing: "border-box",
|
|
57
|
+
},
|
|
58
|
+
row: {
|
|
59
|
+
minHeight: "56px",
|
|
60
|
+
padding: "10px 16px",
|
|
61
|
+
boxSizing: "border-box",
|
|
62
|
+
borderTop: `1px solid ${tokens.colorNeutralStroke2}`,
|
|
63
|
+
color: "inherit",
|
|
64
|
+
textDecorationLine: "none",
|
|
65
|
+
},
|
|
66
|
+
clickable: {
|
|
67
|
+
cursor: "pointer",
|
|
68
|
+
":hover": { background: tokens.colorNeutralBackground1Hover },
|
|
69
|
+
":focus-visible": {
|
|
70
|
+
outline: `2px solid ${tokens.colorStrokeFocus2}`,
|
|
71
|
+
outlineOffset: "-2px",
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
selected: { background: tokens.colorNeutralBackground1Selected },
|
|
75
|
+
cell: {
|
|
76
|
+
minWidth: 0,
|
|
77
|
+
fontSize: tokens.fontSizeBase300,
|
|
78
|
+
color: tokens.colorNeutralForeground2,
|
|
79
|
+
overflowWrap: "anywhere",
|
|
80
|
+
},
|
|
81
|
+
first: { color: tokens.colorNeutralForeground1 },
|
|
82
|
+
secondary: { [NARROW]: { display: "none" } },
|
|
83
|
+
// Flex alone: a text-align here would leak into controls in the cell
|
|
84
|
+
// (it shoved a Switch knob out of its track).
|
|
85
|
+
end: { display: "flex", justifyContent: "flex-end" },
|
|
86
|
+
chevron: { fontSize: "14px", color: tokens.colorNeutralForeground3 },
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
const ColumnsContext = createContext<DataListColumn[]>([]);
|
|
90
|
+
|
|
91
|
+
function tracks(columns: DataListColumn[], chevron: boolean, narrow: boolean) {
|
|
92
|
+
const list = columns.filter((c) => !narrow || !c.secondary).map((c) => c.width);
|
|
93
|
+
if (chevron) list.push("14px");
|
|
94
|
+
return list.join(" ");
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
interface DataListProps {
|
|
98
|
+
/** The columns, in order: `{ label, width, secondary?, end? }`. `width` is a
|
|
99
|
+
* CSS grid track, e.g. "minmax(0, 2fr)" or "120px". */
|
|
100
|
+
columns: DataListColumn[];
|
|
101
|
+
/** Rows link somewhere: keeps room for their chevron. */
|
|
102
|
+
linked?: boolean;
|
|
103
|
+
/** Replaces the column headings, e.g. a bulk-action bar. */
|
|
104
|
+
head?: ReactNode;
|
|
105
|
+
/** The rows, as `DataListRow`s. */
|
|
106
|
+
children: ReactNode;
|
|
107
|
+
/** Extra styles for the list's frame. */
|
|
108
|
+
className?: string;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** A list with columns, lighter than a table. */
|
|
112
|
+
export function DataList({ columns, linked, head, children, className }: DataListProps) {
|
|
113
|
+
const styles = useStyles();
|
|
114
|
+
const vars = {
|
|
115
|
+
"--cols": tracks(columns, !!linked, false),
|
|
116
|
+
"--cols-narrow": tracks(columns, !!linked, true),
|
|
117
|
+
} as React.CSSProperties;
|
|
118
|
+
return (
|
|
119
|
+
<ColumnsContext.Provider value={columns}>
|
|
120
|
+
<div className={mergeClasses(styles.frame, className)} style={vars}>
|
|
121
|
+
{head ?? (
|
|
122
|
+
<div className={mergeClasses(styles.grid, styles.head)} aria-hidden>
|
|
123
|
+
{columns.map((c, i) => (
|
|
124
|
+
<span
|
|
125
|
+
key={i}
|
|
126
|
+
className={mergeClasses(c.secondary && styles.secondary, c.end && styles.end)}
|
|
127
|
+
>
|
|
128
|
+
{c.label}
|
|
129
|
+
</span>
|
|
130
|
+
))}
|
|
131
|
+
{linked && <span />}
|
|
132
|
+
</div>
|
|
133
|
+
)}
|
|
134
|
+
{children}
|
|
135
|
+
</div>
|
|
136
|
+
</ColumnsContext.Provider>
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
interface DataListRowProps {
|
|
141
|
+
/** One node per column, in order. */
|
|
142
|
+
cells: ReactNode[];
|
|
143
|
+
/** The whole row links here and shows a chevron. A linked row mustn't hold
|
|
144
|
+
* other controls. */
|
|
145
|
+
to?: string;
|
|
146
|
+
/** Router state passed with `to`, e.g. where the page was opened from. */
|
|
147
|
+
state?: unknown;
|
|
148
|
+
/** Called on a click, in place of `to`, e.g. to select the row. A row with
|
|
149
|
+
* controls uses this and keeps a real link in a cell (`DataListLink`). */
|
|
150
|
+
onClick?: () => void;
|
|
151
|
+
/** Shows the row as selected. */
|
|
152
|
+
selected?: boolean;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** One item in a `DataList`: a cell per column. */
|
|
156
|
+
export function DataListRow({ cells, to, state, onClick, selected }: DataListRowProps) {
|
|
157
|
+
const styles = useStyles();
|
|
158
|
+
const columns = useContext(ColumnsContext);
|
|
159
|
+
const className = mergeClasses(
|
|
160
|
+
styles.grid,
|
|
161
|
+
styles.row,
|
|
162
|
+
(to || onClick) && styles.clickable,
|
|
163
|
+
selected && styles.selected,
|
|
164
|
+
);
|
|
165
|
+
const content = (
|
|
166
|
+
<>
|
|
167
|
+
{cells.map((cell, i) => (
|
|
168
|
+
<div
|
|
169
|
+
key={i}
|
|
170
|
+
className={mergeClasses(
|
|
171
|
+
styles.cell,
|
|
172
|
+
i === 0 && styles.first,
|
|
173
|
+
columns[i]?.secondary && styles.secondary,
|
|
174
|
+
columns[i]?.end && styles.end,
|
|
175
|
+
)}
|
|
176
|
+
>
|
|
177
|
+
{cell}
|
|
178
|
+
</div>
|
|
179
|
+
))}
|
|
180
|
+
{to && <ChevronRightRegular className={styles.chevron} />}
|
|
181
|
+
</>
|
|
182
|
+
);
|
|
183
|
+
if (to)
|
|
184
|
+
return (
|
|
185
|
+
<UiLink to={to} state={state} className={className}>
|
|
186
|
+
{content}
|
|
187
|
+
</UiLink>
|
|
188
|
+
);
|
|
189
|
+
return (
|
|
190
|
+
<div className={className} onClick={onClick}>
|
|
191
|
+
{content}
|
|
192
|
+
</div>
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const useNameStyles = makeStyles({
|
|
197
|
+
root: { display: "flex", alignItems: "center", gap: "12px", minWidth: 0 },
|
|
198
|
+
text: { display: "flex", flexDirection: "column", gap: "2px", minWidth: 0 },
|
|
199
|
+
line: {
|
|
200
|
+
display: "flex",
|
|
201
|
+
alignItems: "center",
|
|
202
|
+
gap: "6px",
|
|
203
|
+
minWidth: 0,
|
|
204
|
+
flexWrap: "wrap",
|
|
205
|
+
},
|
|
206
|
+
name: {
|
|
207
|
+
fontWeight: tokens.fontWeightSemibold,
|
|
208
|
+
color: tokens.colorNeutralForeground1,
|
|
209
|
+
overflowWrap: "anywhere",
|
|
210
|
+
},
|
|
211
|
+
sub: {
|
|
212
|
+
fontSize: tokens.fontSizeBase200,
|
|
213
|
+
color: tokens.colorNeutralForeground3,
|
|
214
|
+
overflow: "hidden",
|
|
215
|
+
textOverflow: "ellipsis",
|
|
216
|
+
whiteSpace: "nowrap",
|
|
217
|
+
},
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
/** First-column content: an icon or avatar, the name, badges, a subtitle. */
|
|
221
|
+
export function DataListName({
|
|
222
|
+
icon,
|
|
223
|
+
name,
|
|
224
|
+
badges,
|
|
225
|
+
sub,
|
|
226
|
+
}: {
|
|
227
|
+
/** An icon or avatar before the name. */
|
|
228
|
+
icon?: ReactNode;
|
|
229
|
+
/** The item's name. */
|
|
230
|
+
name: ReactNode;
|
|
231
|
+
/** Shown after the name, e.g. a `Badge`. */
|
|
232
|
+
badges?: ReactNode;
|
|
233
|
+
/** A muted line under the name, e.g. an ID. */
|
|
234
|
+
sub?: ReactNode;
|
|
235
|
+
}) {
|
|
236
|
+
const styles = useNameStyles();
|
|
237
|
+
return (
|
|
238
|
+
<div className={styles.root}>
|
|
239
|
+
{icon}
|
|
240
|
+
<div className={styles.text}>
|
|
241
|
+
<div className={styles.line}>
|
|
242
|
+
<span className={styles.name}>{name}</span>
|
|
243
|
+
{badges}
|
|
244
|
+
</div>
|
|
245
|
+
{sub && <span className={styles.sub}>{sub}</span>}
|
|
246
|
+
</div>
|
|
247
|
+
</div>
|
|
248
|
+
);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/** Placeholder rows in the list's own frame, so nothing moves when the
|
|
252
|
+
* items arrive. `icon` reserves the first column's avatar. */
|
|
253
|
+
export function DataListSkeleton({
|
|
254
|
+
columns,
|
|
255
|
+
linked,
|
|
256
|
+
rows = 4,
|
|
257
|
+
icon,
|
|
258
|
+
}: {
|
|
259
|
+
/** The columns of the list it stands in for, headings included. */
|
|
260
|
+
columns: DataListColumn[];
|
|
261
|
+
/** Keeps room for the chevron, as on a linked `DataList`. */
|
|
262
|
+
linked?: boolean;
|
|
263
|
+
/** How many rows to show. */
|
|
264
|
+
rows?: number;
|
|
265
|
+
/** Reserves the first column's avatar, in this shape. */
|
|
266
|
+
icon?: "square" | "circle";
|
|
267
|
+
}) {
|
|
268
|
+
const nameStyles = useNameStyles();
|
|
269
|
+
return (
|
|
270
|
+
<Skeleton aria-busy>
|
|
271
|
+
<DataList columns={columns} linked={linked}>
|
|
272
|
+
{Array.from({ length: rows }).map((_, i) => (
|
|
273
|
+
<DataListRow
|
|
274
|
+
key={i}
|
|
275
|
+
cells={columns.map((_, c) => {
|
|
276
|
+
const bar = (
|
|
277
|
+
<SkeletonItem
|
|
278
|
+
key={c}
|
|
279
|
+
size={12}
|
|
280
|
+
style={{ width: c === 0 ? `${40 + (i % 3) * 12}%` : "60%" }}
|
|
281
|
+
/>
|
|
282
|
+
);
|
|
283
|
+
return c === 0 && icon ? (
|
|
284
|
+
<div key={c} className={nameStyles.root}>
|
|
285
|
+
<SkeletonItem shape={icon} size={32} />
|
|
286
|
+
{bar}
|
|
287
|
+
</div>
|
|
288
|
+
) : (
|
|
289
|
+
bar
|
|
290
|
+
);
|
|
291
|
+
})}
|
|
292
|
+
/>
|
|
293
|
+
))}
|
|
294
|
+
</DataList>
|
|
295
|
+
</Skeleton>
|
|
296
|
+
);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
const useLinkStyles = makeStyles({
|
|
300
|
+
link: {
|
|
301
|
+
color: tokens.colorNeutralForeground1,
|
|
302
|
+
textDecorationLine: "none",
|
|
303
|
+
":hover": { textDecorationLine: "underline" },
|
|
304
|
+
":focus-visible": {
|
|
305
|
+
outline: `2px solid ${tokens.colorStrokeFocus2}`,
|
|
306
|
+
borderRadius: "2px",
|
|
307
|
+
},
|
|
308
|
+
},
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
/** The real link inside a row that passes `onClick` (because it holds other
|
|
312
|
+
* controls), so the row still works with the keyboard, middle-click and
|
|
313
|
+
* "open in new tab". */
|
|
314
|
+
export function DataListLink({
|
|
315
|
+
to,
|
|
316
|
+
state,
|
|
317
|
+
children,
|
|
318
|
+
}: {
|
|
319
|
+
/** Where the link goes. */
|
|
320
|
+
to: string;
|
|
321
|
+
/** Router state passed with `to`. */
|
|
322
|
+
state?: unknown;
|
|
323
|
+
/** The link's text. */
|
|
324
|
+
children: ReactNode;
|
|
325
|
+
}) {
|
|
326
|
+
const styles = useLinkStyles();
|
|
327
|
+
return (
|
|
328
|
+
<UiLink to={to} state={state} className={styles.link} onClick={(e) => e.stopPropagation()}>
|
|
329
|
+
{children}
|
|
330
|
+
</UiLink>
|
|
331
|
+
);
|
|
332
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// The top of a detail page (an app, a team, a user, a notice…): the way back
|
|
2
|
+
// to its list, then its name with badges, a line under it, and an action.
|
|
3
|
+
|
|
4
|
+
import { Button, Text, Title2, makeStyles, mergeClasses, tokens } from "@fluentui/react-components";
|
|
5
|
+
import { ArrowLeftRegular } from "@fluentui/react-icons";
|
|
6
|
+
import type { ReactNode } from "react";
|
|
7
|
+
import { useUiNavigate } from "../provider/context.js";
|
|
8
|
+
|
|
9
|
+
const useStyles = makeStyles({
|
|
10
|
+
back: {
|
|
11
|
+
alignSelf: "flex-start",
|
|
12
|
+
marginLeft: "-8px",
|
|
13
|
+
color: tokens.colorNeutralForeground3,
|
|
14
|
+
},
|
|
15
|
+
header: {
|
|
16
|
+
display: "flex",
|
|
17
|
+
alignItems: "center",
|
|
18
|
+
flexWrap: "wrap",
|
|
19
|
+
gap: "16px",
|
|
20
|
+
},
|
|
21
|
+
titles: {
|
|
22
|
+
display: "flex",
|
|
23
|
+
flexDirection: "column",
|
|
24
|
+
gap: "4px",
|
|
25
|
+
flex: "1 1 240px",
|
|
26
|
+
minWidth: 0,
|
|
27
|
+
},
|
|
28
|
+
titleLine: {
|
|
29
|
+
display: "flex",
|
|
30
|
+
alignItems: "center",
|
|
31
|
+
flexWrap: "wrap",
|
|
32
|
+
gap: "8px",
|
|
33
|
+
},
|
|
34
|
+
title: { margin: 0, letterSpacing: "-0.015em", overflowWrap: "anywhere" },
|
|
35
|
+
subtitle: {
|
|
36
|
+
color: tokens.colorNeutralForeground3,
|
|
37
|
+
overflowWrap: "anywhere",
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
/** "← Apps": back to the list the page was opened from. */
|
|
42
|
+
export function BackButton({
|
|
43
|
+
to,
|
|
44
|
+
children,
|
|
45
|
+
}: {
|
|
46
|
+
/** The list's path, opened through the app's router. */
|
|
47
|
+
to: string;
|
|
48
|
+
/** The list's name. */
|
|
49
|
+
children: ReactNode;
|
|
50
|
+
}) {
|
|
51
|
+
const styles = useStyles();
|
|
52
|
+
const navigate = useUiNavigate();
|
|
53
|
+
return (
|
|
54
|
+
<Button
|
|
55
|
+
appearance="subtle"
|
|
56
|
+
size="small"
|
|
57
|
+
icon={<ArrowLeftRegular />}
|
|
58
|
+
className={styles.back}
|
|
59
|
+
onClick={() => navigate(to)}
|
|
60
|
+
>
|
|
61
|
+
{children}
|
|
62
|
+
</Button>
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function DetailHeader({
|
|
67
|
+
icon,
|
|
68
|
+
title,
|
|
69
|
+
badges,
|
|
70
|
+
subtitle,
|
|
71
|
+
actions,
|
|
72
|
+
className,
|
|
73
|
+
}: {
|
|
74
|
+
/** An avatar or icon before the name. */
|
|
75
|
+
icon?: ReactNode;
|
|
76
|
+
/** The item's name, the page's `h1`. */
|
|
77
|
+
title: ReactNode;
|
|
78
|
+
/** Badges after the name, such as "Verified". */
|
|
79
|
+
badges?: ReactNode;
|
|
80
|
+
/** A line under the name. */
|
|
81
|
+
subtitle?: ReactNode;
|
|
82
|
+
/** Buttons at the end of the row, e.g. "Edit" or "Visit website". */
|
|
83
|
+
actions?: ReactNode;
|
|
84
|
+
className?: string;
|
|
85
|
+
}) {
|
|
86
|
+
const styles = useStyles();
|
|
87
|
+
return (
|
|
88
|
+
<div className={mergeClasses(styles.header, className)}>
|
|
89
|
+
{icon}
|
|
90
|
+
<div className={styles.titles}>
|
|
91
|
+
<div className={styles.titleLine}>
|
|
92
|
+
<Title2 as="h1" className={styles.title}>
|
|
93
|
+
{title}
|
|
94
|
+
</Title2>
|
|
95
|
+
{badges}
|
|
96
|
+
</div>
|
|
97
|
+
{subtitle && <Text className={styles.subtitle}>{subtitle}</Text>}
|
|
98
|
+
</div>
|
|
99
|
+
{actions}
|
|
100
|
+
</div>
|
|
101
|
+
);
|
|
102
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
// Input that accepts free-form duration text (e.g. "60", "60min", "1 hour",
|
|
2
|
+
// "30 days") and commits an integer in the field's storage unit on blur.
|
|
3
|
+
// Empty input commits `null`, meaning "use the site default".
|
|
4
|
+
//
|
|
5
|
+
// Why a custom component (and not Fluent's SpinButton): SpinButton's
|
|
6
|
+
// controlled state diverges from `value`/`displayValue` on invalid intermediate
|
|
7
|
+
// input — typing "60min" and then clicking elsewhere left the box blank.
|
|
8
|
+
// This component keeps a local string buffer that's only synced from `value`
|
|
9
|
+
// when `value` changes externally, so user typing is preserved across blur
|
|
10
|
+
// until we successfully parse it.
|
|
11
|
+
|
|
12
|
+
import { Input, Text, tokens } from "@fluentui/react-components";
|
|
13
|
+
import { useEffect, useRef, useState } from "react";
|
|
14
|
+
import { useUiStrings } from "../provider/context.js";
|
|
15
|
+
import { UI_STRINGS, parseDuration, type DurationUnit } from "@siiway/ui-core";
|
|
16
|
+
|
|
17
|
+
interface DurationInputProps {
|
|
18
|
+
/** The length of time as a whole number in `unit`. `null` is blank. */
|
|
19
|
+
value: number | null;
|
|
20
|
+
/** Called with the new value, or `null` for blank, when the text is read
|
|
21
|
+
* (on blur or Enter), not on every keystroke. Text it can't read shows an
|
|
22
|
+
* error and doesn't call it. */
|
|
23
|
+
onChange: (value: number | null) => void;
|
|
24
|
+
/** The unit of `value`, `minutes` or `days`. A bare number is read in this
|
|
25
|
+
* unit. */
|
|
26
|
+
unit: DurationUnit;
|
|
27
|
+
/** Shown while the field is blank. */
|
|
28
|
+
placeholder?: string;
|
|
29
|
+
/** Disables the field. */
|
|
30
|
+
disabled?: boolean;
|
|
31
|
+
/** Whether the field may be left blank, giving `null`. Default `true`:
|
|
32
|
+
* blank means "use the default". When `false`, a blank field shows
|
|
33
|
+
* "Required" and puts back the last value. */
|
|
34
|
+
allowBlank?: boolean;
|
|
35
|
+
/** The text input's `id`. */
|
|
36
|
+
id?: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function DurationInput({
|
|
40
|
+
value,
|
|
41
|
+
onChange,
|
|
42
|
+
unit,
|
|
43
|
+
placeholder,
|
|
44
|
+
disabled,
|
|
45
|
+
allowBlank = true,
|
|
46
|
+
id,
|
|
47
|
+
}: DurationInputProps) {
|
|
48
|
+
const strings = useUiStrings();
|
|
49
|
+
// Local buffer of the displayed text. Synced from `value` only when value
|
|
50
|
+
// changes externally — typing while the field is focused doesn't cause
|
|
51
|
+
// a parent state round-trip on every keystroke.
|
|
52
|
+
const { duration } = strings;
|
|
53
|
+
const format = (next: number | null) => (next === null ? "" : duration(next, unit));
|
|
54
|
+
const [text, setText] = useState<string>(() => format(value));
|
|
55
|
+
const [error, setError] = useState<string | null>(null);
|
|
56
|
+
// Track focus via ref so the sync effect doesn't re-run on focus changes —
|
|
57
|
+
// that would overwrite a parse-error buffer the user is mid-edit. The
|
|
58
|
+
// effect only fires when the parent's `value` (or unit, or the language)
|
|
59
|
+
// actually changes.
|
|
60
|
+
const focusedRef = useRef(false);
|
|
61
|
+
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
if (focusedRef.current) return;
|
|
64
|
+
setText(value === null ? "" : duration(value, unit));
|
|
65
|
+
}, [value, unit, duration]);
|
|
66
|
+
|
|
67
|
+
const commit = () => {
|
|
68
|
+
// The app's language, and English, which people type in any language.
|
|
69
|
+
const result = parseDuration(text, unit, [strings.durationUnits, UI_STRINGS.en.durationUnits]);
|
|
70
|
+
if (result.kind === "blank") {
|
|
71
|
+
if (allowBlank) {
|
|
72
|
+
setError(null);
|
|
73
|
+
onChange(null);
|
|
74
|
+
setText("");
|
|
75
|
+
} else {
|
|
76
|
+
setError(strings.required);
|
|
77
|
+
// Restore last known good value so the box doesn't go blank.
|
|
78
|
+
setText(format(value));
|
|
79
|
+
}
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if (result.kind === "error") {
|
|
83
|
+
setError(
|
|
84
|
+
result.reason === "non_positive"
|
|
85
|
+
? strings.durationNotPositive
|
|
86
|
+
: result.reason === "unknown_unit"
|
|
87
|
+
? strings.durationUnknownUnit
|
|
88
|
+
: strings.durationInvalid,
|
|
89
|
+
);
|
|
90
|
+
// Keep the user's text so they can correct it; revert the canonical
|
|
91
|
+
// value parent-side to whatever it was.
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
setError(null);
|
|
95
|
+
onChange(result.value);
|
|
96
|
+
// Re-format so "60min" becomes "60 min" — gives feedback that we parsed
|
|
97
|
+
// it the way they expected.
|
|
98
|
+
setText(format(result.value));
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
return (
|
|
102
|
+
<div style={{ display: "flex", flexDirection: "column", gap: 4 }}>
|
|
103
|
+
<Input
|
|
104
|
+
id={id}
|
|
105
|
+
value={text}
|
|
106
|
+
disabled={disabled}
|
|
107
|
+
placeholder={placeholder}
|
|
108
|
+
onChange={(_, d) => {
|
|
109
|
+
setText(d.value);
|
|
110
|
+
if (error) setError(null);
|
|
111
|
+
}}
|
|
112
|
+
onFocus={() => {
|
|
113
|
+
focusedRef.current = true;
|
|
114
|
+
}}
|
|
115
|
+
onBlur={() => {
|
|
116
|
+
focusedRef.current = false;
|
|
117
|
+
commit();
|
|
118
|
+
}}
|
|
119
|
+
onKeyDown={(e) => {
|
|
120
|
+
if (e.key === "Enter") {
|
|
121
|
+
e.preventDefault();
|
|
122
|
+
commit();
|
|
123
|
+
}
|
|
124
|
+
}}
|
|
125
|
+
/>
|
|
126
|
+
{error && (
|
|
127
|
+
<Text size={100} style={{ color: tokens.colorPaletteRedForeground1 }}>
|
|
128
|
+
{error}
|
|
129
|
+
</Text>
|
|
130
|
+
)}
|
|
131
|
+
</div>
|
|
132
|
+
);
|
|
133
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// Shared empty-state block for lists and tables: muted icon in a circle,
|
|
2
|
+
// title, optional description, optional call-to-action.
|
|
3
|
+
|
|
4
|
+
import { Text, makeStyles, tokens } from "@fluentui/react-components";
|
|
5
|
+
import type { ReactNode } from "react";
|
|
6
|
+
|
|
7
|
+
const useStyles = makeStyles({
|
|
8
|
+
root: {
|
|
9
|
+
display: "flex",
|
|
10
|
+
flexDirection: "column",
|
|
11
|
+
alignItems: "center",
|
|
12
|
+
textAlign: "center",
|
|
13
|
+
gap: "8px",
|
|
14
|
+
padding: "48px 16px",
|
|
15
|
+
},
|
|
16
|
+
iconCircle: {
|
|
17
|
+
display: "flex",
|
|
18
|
+
alignItems: "center",
|
|
19
|
+
justifyContent: "center",
|
|
20
|
+
width: "56px",
|
|
21
|
+
height: "56px",
|
|
22
|
+
borderRadius: tokens.borderRadiusXLarge,
|
|
23
|
+
// Bordered tile rather than a grey disc: empty states often sit straight
|
|
24
|
+
// on the canvas, where a Background3 fill all but disappears.
|
|
25
|
+
background: tokens.colorNeutralBackground1,
|
|
26
|
+
border: `1px solid ${tokens.colorNeutralStroke2}`,
|
|
27
|
+
color: tokens.colorNeutralForeground3,
|
|
28
|
+
fontSize: "28px",
|
|
29
|
+
marginBottom: "8px",
|
|
30
|
+
},
|
|
31
|
+
description: {
|
|
32
|
+
color: tokens.colorNeutralForeground3,
|
|
33
|
+
maxWidth: "380px",
|
|
34
|
+
},
|
|
35
|
+
action: {
|
|
36
|
+
marginTop: "8px",
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
interface EmptyStateProps {
|
|
41
|
+
/** An icon, shown in a tile above the title. */
|
|
42
|
+
icon?: ReactNode;
|
|
43
|
+
/** What's missing, such as "No apps yet". */
|
|
44
|
+
title: ReactNode;
|
|
45
|
+
/** A line under the title. */
|
|
46
|
+
description?: ReactNode;
|
|
47
|
+
/** Under the text, such as the list's main button. */
|
|
48
|
+
action?: ReactNode;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function EmptyState({ icon, title, description, action }: EmptyStateProps) {
|
|
52
|
+
const styles = useStyles();
|
|
53
|
+
return (
|
|
54
|
+
<div className={styles.root}>
|
|
55
|
+
{icon && <div className={styles.iconCircle}>{icon}</div>}
|
|
56
|
+
<Text size={400} weight="semibold">
|
|
57
|
+
{title}
|
|
58
|
+
</Text>
|
|
59
|
+
{description && (
|
|
60
|
+
<Text size={300} className={styles.description}>
|
|
61
|
+
{description}
|
|
62
|
+
</Text>
|
|
63
|
+
)}
|
|
64
|
+
{action && <div className={styles.action}>{action}</div>}
|
|
65
|
+
</div>
|
|
66
|
+
);
|
|
67
|
+
}
|