@qodalis/console-kit 0.0.0-stage → 1.0.0-beta.33
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/README.md +251 -2
- package/dist/components/Badge.d.ts +14 -0
- package/dist/components/ButtonGroup.d.ts +35 -0
- package/dist/components/ChipList.d.ts +53 -0
- package/dist/components/ConfirmDialog.d.ts +28 -0
- package/dist/components/DataTable.d.ts +29 -0
- package/dist/components/DropdownMenu.d.ts +32 -0
- package/dist/components/ErrorBoundary.d.ts +29 -0
- package/dist/components/Modal.d.ts +30 -0
- package/dist/components/MonoPanel.d.ts +9 -0
- package/dist/components/PageHeader.d.ts +7 -0
- package/dist/components/Pagination.d.ts +11 -0
- package/dist/components/Select.d.ts +54 -0
- package/dist/components/Skeleton.d.ts +66 -0
- package/dist/components/Spinner.d.ts +9 -0
- package/dist/components/StatCard.d.ts +9 -0
- package/dist/components/States.d.ts +33 -0
- package/dist/components/Tooltip.d.ts +24 -0
- package/dist/components/actionIcons.d.ts +6 -0
- package/dist/components/charts/ColumnChart.d.ts +37 -0
- package/dist/components/charts/LineChart.d.ts +28 -0
- package/dist/components/charts/chartParts.d.ts +31 -0
- package/dist/components/charts/chartUtils.d.ts +14 -0
- package/dist/components/componentText.d.ts +3 -0
- package/dist/components/drawerGestures.d.ts +15 -0
- package/dist/components/errorText.d.ts +31 -0
- package/dist/components/overlay.d.ts +51 -0
- package/dist/components/paging.d.ts +16 -0
- package/dist/components/sortRows.d.ts +10 -0
- package/dist/components/useConfirm.d.ts +18 -0
- package/dist/extension/ExtensionLink.d.ts +10 -0
- package/dist/extension/defineExtension.d.ts +96 -0
- package/dist/extension/serverPlugin.d.ts +18 -0
- package/dist/extension/serverPluginApi.d.ts +42 -0
- package/dist/extension/types.d.ts +247 -0
- package/dist/extension/useQueryParams.d.ts +5 -0
- package/dist/format.d.ts +4 -0
- package/dist/hooks/liveReload.d.ts +28 -0
- package/dist/hooks/useAsync.d.ts +10 -0
- package/dist/hooks/usePaging.d.ts +10 -0
- package/dist/hooks/useStoredState.d.ts +9 -0
- package/dist/i18n/locales.d.ts +60 -0
- package/dist/i18n/messages.d.ts +3 -0
- package/dist/i18n/text.d.ts +21 -0
- package/dist/i18n/translations.d.ts +32 -0
- package/dist/index.d.ts +64 -0
- package/dist/index.js +2735 -0
- package/dist/index.js.map +1 -0
- package/dist/styles.css +1 -0
- package/dist/tailwind-preset.js +35 -0
- package/dist/tailwind-preset.js.map +1 -0
- package/dist/testing.d.ts +35 -0
- package/dist/testing.js +70 -0
- package/dist/testing.js.map +1 -0
- package/dist/theme/tagColors.d.ts +27 -0
- package/dist/theme/tailwind-preset.d.ts +46 -0
- package/dist/theme/tokens.d.ts +33 -0
- package/dist/tokens-3WNFc3gU.js +82 -0
- package/dist/tokens-3WNFc3gU.js.map +1 -0
- package/package.json +59 -4
package/README.md
CHANGED
|
@@ -1,3 +1,252 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @qodalis/console-kit
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Build pages that a plugin adds to the admin Console of the Qodalis CLI servers (Node, .NET, Python). The kit
|
|
4
|
+
holds the Console's own components, its theme (CSS variables and a Tailwind preset), the texts of its components
|
|
5
|
+
in eleven languages, and the extension API. A page built with it looks and behaves like the Console's own pages, in
|
|
6
|
+
the light and dark themes and in the reader's language.
|
|
7
|
+
|
|
8
|
+
The contract between server, Console and extension is in
|
|
9
|
+
[docs/extensions.md](https://github.com/qodalis-solutions/qodalis-console/blob/main/docs/extensions.md).
|
|
10
|
+
|
|
11
|
+
## How an extension works
|
|
12
|
+
|
|
13
|
+
1. The plugin registers the page on the server: `builder.addConsoleExtension({ id, title, entry, ... })` (Node),
|
|
14
|
+
`cli.AddConsoleExtension(...)` (.NET), `builder.add_console_extension(...)` (Python); servers before the rename
|
|
15
|
+
to Qodalis Console call it `addDashboardExtension`, `AddDashboardExtension`, `add_dashboard_extension`.
|
|
16
|
+
2. The plugin serves `entry` (an ES module) and its stylesheet, e.g. under `/qcli/<plugin>/admin/`.
|
|
17
|
+
3. The Console lists the page in its navigation (only for users holding its `permission`), and at `/x/<id>` it
|
|
18
|
+
loads the module and calls `mount(element, context)`.
|
|
19
|
+
|
|
20
|
+
## Install
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install @qodalis/console-kit react react-dom
|
|
24
|
+
npm install -D vite @vitejs/plugin-react tailwindcss@3 postcss autoprefixer
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## A page
|
|
28
|
+
|
|
29
|
+
```tsx
|
|
30
|
+
// src/index.tsx
|
|
31
|
+
import './styles.css';
|
|
32
|
+
import { PageHeader, defineExtension, defineMessages, useApi, useConsole, useTranslations } from '@qodalis/console-kit';
|
|
33
|
+
|
|
34
|
+
// The page's own texts: each plugin ships its messages, in as many of the Console's languages as it likes
|
|
35
|
+
const messages = {
|
|
36
|
+
billing: defineMessages({
|
|
37
|
+
en: { title: 'Billing', invoices_one: '{count} invoice', invoices_other: '{count} invoices' },
|
|
38
|
+
de: { title: 'Abrechnung', invoices_one: '{count} Rechnung', invoices_other: '{count} Rechnungen' },
|
|
39
|
+
ro: { title: 'Facturare', invoices_one: '{count} factură', invoices_few: '{count} facturi', invoices_other: '{count} de facturi' },
|
|
40
|
+
}),
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
function Billing() {
|
|
44
|
+
const { user } = useConsole();
|
|
45
|
+
const api = useApi(); // JSON over the Console's session: api.get('/api/v1/qcli/...')
|
|
46
|
+
const { t, formatDate } = useTranslations(messages); // the Console's language, plural rules, dates
|
|
47
|
+
// ...
|
|
48
|
+
return <PageHeader title={t('billing.title')} subtitle={t('billing.invoices', { count: 3 })} />;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export default defineExtension(Billing);
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
`defineExtension` mounts a React root with the Console's context and re-renders on theme, language, path and
|
|
55
|
+
settings changes. Without React, export `{ mount(element, context) { ...; return cleanup; } }` yourself.
|
|
56
|
+
|
|
57
|
+
The context (`useConsole()`):
|
|
58
|
+
|
|
59
|
+
| Member | |
|
|
60
|
+
|---|---|
|
|
61
|
+
| `fetch(path, init)` | `fetch` against the server with the Console's token and JSON headers; a 401 signs the user out, unless `quiet: true` |
|
|
62
|
+
| `user`, `permissions`, `hasPermission(p)` | the signed-in user; wildcard-aware permission check |
|
|
63
|
+
| `theme`, `onThemeChange` | `light` or `dark` |
|
|
64
|
+
| `language`, `onLanguageChange` | the Console's language (`en`, `de`, ...) |
|
|
65
|
+
| `path`, `navigate(path)`, `onPathChange` | the page's own routing below `/x/<id>` |
|
|
66
|
+
| `onServerEvent(pattern, listener)` | server events (`databases:migration-run`, `job:*`, `*`) on the Console's socket; `useServerEvents(patterns, reload)` reloads after them |
|
|
67
|
+
| `config`, `onConfigChange(listener)` | a marketplace plugin's settings (below); `undefined` for built-in extensions; `useExtensionConfig()` reads them and renders again on every change |
|
|
68
|
+
| `notify(message, kind)`, `confirm(options)` | the Console's notices and confirm dialog |
|
|
69
|
+
| `extension`, `apiBase`, `consoleVersion` (also `dashboardVersion`, deprecated), `apiVersion` | the registration, the server's URL, versions |
|
|
70
|
+
|
|
71
|
+
Hooks and helpers the Console's own pages use: `useAsync`, `usePaging`, `useStoredState`, `useQueryParams` (the
|
|
72
|
+
page's query string), `useLiveReload`, `ExtensionLink`/`useExtensionHref` (links below `/x/<id>`), `formatBytes`,
|
|
73
|
+
`shortDuration`, `tagStyle`, and the charts (`LineChart`, `ColumnChart`, `ChartCard`).
|
|
74
|
+
|
|
75
|
+
## Overview cards, attention and the command palette
|
|
76
|
+
|
|
77
|
+
Registered with `widgets: ["overview"]` and/or `["palette"]`, the module also fills the Overview and the command
|
|
78
|
+
palette. They are mounted with the page's context; `navigate` opens the page.
|
|
79
|
+
|
|
80
|
+
```tsx
|
|
81
|
+
export default defineExtension(Billing, {
|
|
82
|
+
overview: {
|
|
83
|
+
// stat: a figure in the top row; half or full: a panel below
|
|
84
|
+
cards: [{ id: 'open', size: 'stat', component: OpenInvoices }],
|
|
85
|
+
// Needs attention, asked again every minute
|
|
86
|
+
attention: async ctx => [{ id: 'late', level: 'warning', title: '3 invoices late', path: '/?status=late' }],
|
|
87
|
+
},
|
|
88
|
+
// Command palette entries, under the page's title
|
|
89
|
+
palette: async ctx => [{ id: 'inv-42', label: 'Invoice 42', path: '/42' }],
|
|
90
|
+
});
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
With `widgets: ["config"]`, `configEditors` gives the Config page an input for every entry with an `editor` hint
|
|
94
|
+
(`{ cron: CronEditor }`, a component taking `ConfigEditorProps`: `entry`, `value`, `onChange`, `disabled`, `error`).
|
|
95
|
+
`mountConfigEditor(Component)` makes the same mount function by hand.
|
|
96
|
+
|
|
97
|
+
With `search: "/?q="` in the registration, the palette offers "Search Billing for …" and opens `/x/<id>/?q=<text>`.
|
|
98
|
+
|
|
99
|
+
## Settings of a marketplace plugin
|
|
100
|
+
|
|
101
|
+
A Console plugin installed from the marketplace can declare settings with defaults in its package.json, with the
|
|
102
|
+
server config providers' entry model (`ConsolePluginConfigEntry`):
|
|
103
|
+
|
|
104
|
+
```json
|
|
105
|
+
{
|
|
106
|
+
"name": "@acme/console-kanban",
|
|
107
|
+
"keywords": ["qodalis-console-plugin"],
|
|
108
|
+
"qodalis": {
|
|
109
|
+
"kind": "console",
|
|
110
|
+
"extension": { "js": "dist/extension.js", "css": "dist/extension.css" },
|
|
111
|
+
"config": {
|
|
112
|
+
"entries": [
|
|
113
|
+
{ "key": "refreshSeconds", "label": "Refresh every", "description": "Seconds between reloads", "type": "number", "default": 30, "validation": { "min": 5, "max": 3600 } },
|
|
114
|
+
{ "key": "columns", "label": "Columns", "type": "string[]", "default": ["name", "status"] },
|
|
115
|
+
{ "key": "mode", "type": "enum", "default": "compact", "validation": { "options": ["compact", "full"] } }
|
|
116
|
+
]
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
- `kind: "console"`, the keyword `qodalis-console-plugin` and `qodalis.consoleApi` are the manifest's forms since the
|
|
123
|
+
rename to Qodalis Console; the old ones (`kind: "dashboard"`, `qodalis-dashboard-plugin`, `qodalis.dashboardApi`) are
|
|
124
|
+
accepted for good.
|
|
125
|
+
- Types: `string`, `number`, `boolean`, `string[]`, `enum`, `json`, `duration` (`30s`, `15m`; min/max in
|
|
126
|
+
milliseconds), `url`. No `secret`: the plugin runs in the browser and cannot keep one; the marketplace rejects a
|
|
127
|
+
version declaring one. Rules: `min`, `max` (value, length, items), `pattern`, `options`, `required`.
|
|
128
|
+
- Keys `^[a-zA-Z][a-zA-Z0-9_.-]{0,63}$`, at most 50 entries, each default valid under its own rules, at most 32 KB of
|
|
129
|
+
JSON; the marketplace rejects a version otherwise.
|
|
130
|
+
- The install dialog shows the settings with their defaults to change; afterwards they are the section `<id>` of the
|
|
131
|
+
`console-plugins` provider on the Config page (`/config?provider=console-plugins§ion=<id>`) and
|
|
132
|
+
`config set console-plugins.<id>.<key> <value>` in the CLI (`dashboard-plugins` on servers before the rename). An update keeps the values the new version still
|
|
133
|
+
accepts and resets the others to its defaults.
|
|
134
|
+
|
|
135
|
+
The plugin reads the stored values over the defaults, by key. The Console reads them before it mounts the page (and
|
|
136
|
+
its Overview cards), and again on each change, live:
|
|
137
|
+
|
|
138
|
+
```tsx
|
|
139
|
+
import { defineExtension, useExtensionConfig } from '@qodalis/console-kit';
|
|
140
|
+
|
|
141
|
+
interface KanbanSettings { refreshSeconds: number; columns: string[]; mode: 'compact' | 'full' }
|
|
142
|
+
|
|
143
|
+
function Kanban() {
|
|
144
|
+
const config = useExtensionConfig<KanbanSettings>(); // renders again when someone saves new values
|
|
145
|
+
const seconds = config?.refreshSeconds ?? 30; // keep the package.json defaults as fallbacks
|
|
146
|
+
// ...
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export default defineExtension(Kanban);
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
Without React: `context.config` on mount and `context.onConfigChange(values => ...)` (returns the unsubscribe; absent
|
|
153
|
+
on Consoles before settings, so call it as `context.onConfigChange?.(...)`).
|
|
154
|
+
|
|
155
|
+
- Built-in extensions (the server's own modules) get `config: undefined`.
|
|
156
|
+
- When the Console cannot read the settings, the plugin still mounts, with `config: {}`, and the user sees a notice:
|
|
157
|
+
fall back to your defaults for every key (`config.x ?? default`), as above.
|
|
158
|
+
|
|
159
|
+
## Tests
|
|
160
|
+
|
|
161
|
+
`@qodalis/console-kit/testing` mounts a page with a fake context whose `fetch` answers from a function
|
|
162
|
+
(needs `@testing-library/react`):
|
|
163
|
+
|
|
164
|
+
```tsx
|
|
165
|
+
import { fakeConsole, json, mountExtension } from '@qodalis/console-kit/testing';
|
|
166
|
+
import billing from '../src/index';
|
|
167
|
+
|
|
168
|
+
const fake = fakeConsole('billing', { server: path => json([]), permissions: ['billing:read'] });
|
|
169
|
+
const unmount = await mountExtension(billing, fake.context);
|
|
170
|
+
// fake.state.requests: what the page asked the server
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
`fakeConsole(id, { server, config: { refreshSeconds: 60 } })` makes it a marketplace plugin with these settings;
|
|
174
|
+
`fake.setConfig(values)` changes them as a save on the Config page would.
|
|
175
|
+
|
|
176
|
+
## Styles
|
|
177
|
+
|
|
178
|
+
```css
|
|
179
|
+
/* src/styles.css */
|
|
180
|
+
@tailwind components;
|
|
181
|
+
@tailwind utilities;
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
```js
|
|
185
|
+
// tailwind.config.js
|
|
186
|
+
import kit from '@qodalis/console-kit/tailwind-preset';
|
|
187
|
+
|
|
188
|
+
export default {
|
|
189
|
+
presets: [kit],
|
|
190
|
+
content: ['./src/**/*.{ts,tsx}', './node_modules/@qodalis/console-kit/dist/**/*.js'],
|
|
191
|
+
corePlugins: { preflight: false }, // the Console has its base styles
|
|
192
|
+
important: '.qcli-extension', // the page's classes apply only inside it (EXTENSION_SCOPE)
|
|
193
|
+
};
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
`important: '.qcli-extension'` is required: the Console loads every extension's stylesheet into its own page, and
|
|
197
|
+
unscoped utility classes (`.grid-cols-1`, ...) would override the Console's responsive layout on its other pages. The
|
|
198
|
+
Console puts `qcli-extension` on the element it mounts the page (and each Overview card) into, and `defineExtension`
|
|
199
|
+
renders the kit's modals, menus, selects and tooltips into a body-level element with the same class.
|
|
200
|
+
|
|
201
|
+
The preset maps every color to the Console's theme variables (`bg-surface`, `text-muted`, `border-border`,
|
|
202
|
+
`text-error`, ...), so the page follows the server's color scheme. `@qodalis/console-kit/styles.css`
|
|
203
|
+
holds the classes the kit's components use, for pages that do not run Tailwind.
|
|
204
|
+
|
|
205
|
+
## Build
|
|
206
|
+
|
|
207
|
+
```ts
|
|
208
|
+
// vite.config.ts
|
|
209
|
+
import { defineConfig } from 'vite';
|
|
210
|
+
import react from '@vitejs/plugin-react';
|
|
211
|
+
|
|
212
|
+
export default defineConfig({
|
|
213
|
+
plugins: [react()],
|
|
214
|
+
define: { 'process.env.NODE_ENV': JSON.stringify('production') },
|
|
215
|
+
build: {
|
|
216
|
+
lib: { entry: 'src/index.tsx', formats: ['es'], fileName: () => 'extension.js', cssFileName: 'extension' },
|
|
217
|
+
rollupOptions: { output: { inlineDynamicImports: true } },
|
|
218
|
+
},
|
|
219
|
+
});
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
The output (`dist/extension.js`, `dist/extension.css`) is what the plugin serves as `entry` and `styles`. React and
|
|
223
|
+
the kit are bundled in: the extension does not depend on the Console's versions of them. Keep it to these two files
|
|
224
|
+
(`inlineDynamicImports` bundles lazy imports in): the marketplace records and the servers install only `extension.js`
|
|
225
|
+
and `extension.css`, so a chunk next to them would be missing on a server that installed the plugin from the
|
|
226
|
+
marketplace.
|
|
227
|
+
|
|
228
|
+
A complete example is in [example/](example/) (`npm run build:example -w kit` in this repository).
|
|
229
|
+
|
|
230
|
+
## Moving from @qodalis/cli-server-dashboard-kit
|
|
231
|
+
|
|
232
|
+
The kit was `@qodalis/cli-server-dashboard-kit` before the admin UI was renamed Qodalis Console. The old package gets
|
|
233
|
+
the same releases for a while and is then deprecated; its exports keep working. To move:
|
|
234
|
+
|
|
235
|
+
1. Depend on `@qodalis/console-kit` instead (`npm uninstall @qodalis/cli-server-dashboard-kit && npm install -D @qodalis/console-kit`)
|
|
236
|
+
and change the imports (`@qodalis/console-kit`, `@qodalis/console-kit/testing`, `@qodalis/console-kit/styles.css`,
|
|
237
|
+
`@qodalis/console-kit/tailwind-preset`).
|
|
238
|
+
2. Rename what you use (the old names are deprecated aliases of the new ones):
|
|
239
|
+
|
|
240
|
+
| Before | Now |
|
|
241
|
+
|---|---|
|
|
242
|
+
| `useDashboard()` | `useConsole()` |
|
|
243
|
+
| `fakeDashboard()` (testing) | `fakeConsole()` |
|
|
244
|
+
| `DashboardExtension`, `DashboardExtensionContext`, `DashboardExtensionInfo`, `DashboardExtensionConfig` | `ConsoleExtension`, `ConsoleExtensionContext`, `ConsoleExtensionInfo`, `ConsoleExtensionConfig` |
|
|
245
|
+
| `DashboardMount`, `DashboardOverview`, `DashboardTheme` | `ConsoleMount`, `ConsoleOverview`, `ConsoleTheme` |
|
|
246
|
+
| `DashboardPluginConfig`, `DashboardPluginConfigEntry`, `DashboardPluginConfigType`, `DashboardPluginConfigValue` | `ConsolePluginConfig`, `ConsolePluginConfigEntry`, `ConsolePluginConfigType`, `ConsolePluginConfigValue` |
|
|
247
|
+
| `context.dashboardVersion` | `context.consoleVersion` (both are set) |
|
|
248
|
+
|
|
249
|
+
3. In a marketplace plugin's package.json, use `"kind": "console"`, the keyword `qodalis-console-plugin` and
|
|
250
|
+
`qodalis.consoleApi`; register pages with `addConsoleExtension` on servers that have it.
|
|
251
|
+
|
|
252
|
+
A bundle built with the old kit needs no change: the Console still passes `dashboardVersion`, and the old names stay exported.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
declare const variants: {
|
|
2
|
+
readonly success: "bg-success/15 text-success border-success/30";
|
|
3
|
+
readonly warning: "bg-warning/15 text-warning border-warning/30";
|
|
4
|
+
readonly error: "bg-error/15 text-error border-error/30";
|
|
5
|
+
readonly info: "bg-info/15 text-info border-info/30";
|
|
6
|
+
readonly neutral: "bg-subtle/15 text-muted border-subtle/30";
|
|
7
|
+
};
|
|
8
|
+
interface Props {
|
|
9
|
+
variant: keyof typeof variants;
|
|
10
|
+
children: React.ReactNode;
|
|
11
|
+
dot?: boolean;
|
|
12
|
+
}
|
|
13
|
+
export default function Badge({ variant, children, dot }: Props): import("react/jsx-runtime").JSX.Element;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import { type DropdownMenuItem } from './DropdownMenu';
|
|
3
|
+
export type ButtonGroupTone = 'default' | 'primary' | 'success' | 'warning' | 'danger';
|
|
4
|
+
export interface ButtonGroupItem {
|
|
5
|
+
key: string;
|
|
6
|
+
label: string;
|
|
7
|
+
icon?: ReactNode;
|
|
8
|
+
onClick: (e: React.MouseEvent<HTMLButtonElement>) => void;
|
|
9
|
+
/** Text color of the segment; `danger` for destructive actions. */
|
|
10
|
+
tone?: ButtonGroupTone;
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
/** The segment's action is in progress: a spinner instead of the icon, and the segment is disabled. */
|
|
13
|
+
loading?: boolean;
|
|
14
|
+
/** A toggle: `aria-pressed` and a filled segment while on. */
|
|
15
|
+
pressed?: boolean;
|
|
16
|
+
/** Accessible name when it should say more than the label (e.g. "Revoke deploy-token"). */
|
|
17
|
+
ariaLabel?: string;
|
|
18
|
+
}
|
|
19
|
+
/** When the labels are shown next to the icons; otherwise only the icon, with the label as tooltip and accessible name. */
|
|
20
|
+
export type ButtonGroupLabels = 'always' | 'sm' | 'xl' | 'never';
|
|
21
|
+
interface Props {
|
|
22
|
+
items: ButtonGroupItem[];
|
|
23
|
+
/** Accessible name of the group, e.g. "Actions for health-check". */
|
|
24
|
+
label: string;
|
|
25
|
+
labels?: ButtonGroupLabels;
|
|
26
|
+
/** Less used actions, in a "⋯" menu segment at the end of the group. */
|
|
27
|
+
overflow?: readonly DropdownMenuItem[];
|
|
28
|
+
className?: string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Related actions as one segmented control: joined borders, rounded only at the outer ends, a divider between
|
|
32
|
+
* segments. Each segment is 44px tall on phones (touch) and compact from `sm` up.
|
|
33
|
+
*/
|
|
34
|
+
export default function ButtonGroup({ items, label, labels, overflow, className }: Props): import("react/jsx-runtime").JSX.Element | null;
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { type CSSProperties, type ReactNode, type SyntheticEvent } from 'react';
|
|
2
|
+
/** One item of a `ChipList`: its text, or more. */
|
|
3
|
+
export interface ChipListItem {
|
|
4
|
+
/** Shown in the chip and matched by the search of the dialog. */
|
|
5
|
+
label: string;
|
|
6
|
+
/** React key; the label when left out. */
|
|
7
|
+
key?: string;
|
|
8
|
+
/** Content of the chip instead of the label (the search still matches the label). */
|
|
9
|
+
render?: ReactNode;
|
|
10
|
+
/** Tooltip of the chip. */
|
|
11
|
+
title?: string;
|
|
12
|
+
/** Makes the chip a link. */
|
|
13
|
+
href?: string;
|
|
14
|
+
/** Classes of this chip instead of the list's `chipClassName`. */
|
|
15
|
+
className?: string;
|
|
16
|
+
/** Inline style of the chip (a tag's own color). */
|
|
17
|
+
style?: CSSProperties;
|
|
18
|
+
}
|
|
19
|
+
/** What `renderLink` gets: render a link to `href` with these classes, content and click handler (it closes the dialog). */
|
|
20
|
+
export interface ChipListLinkProps {
|
|
21
|
+
href: string;
|
|
22
|
+
className: string;
|
|
23
|
+
title?: string;
|
|
24
|
+
style?: CSSProperties;
|
|
25
|
+
children: ReactNode;
|
|
26
|
+
onClick: (e: SyntheticEvent) => void;
|
|
27
|
+
}
|
|
28
|
+
export interface ChipListProps {
|
|
29
|
+
items: ReadonlyArray<string | ChipListItem>;
|
|
30
|
+
/** Chips shown before "+N more" (default 3). */
|
|
31
|
+
max?: number;
|
|
32
|
+
/** Title of the dialog with every item ("Groups of alice"); "All items (N)" otherwise. */
|
|
33
|
+
title?: ReactNode;
|
|
34
|
+
/** Accessible name of the list. */
|
|
35
|
+
label?: string;
|
|
36
|
+
/** Classes of each chip (default: a small monospace chip). */
|
|
37
|
+
chipClassName?: string;
|
|
38
|
+
/** Classes of the list in the cell. */
|
|
39
|
+
className?: string;
|
|
40
|
+
/** Shown when there are no items (default `—`). */
|
|
41
|
+
empty?: ReactNode;
|
|
42
|
+
/** The dialog gets a search field above this many items (default 10). */
|
|
43
|
+
searchThreshold?: number;
|
|
44
|
+
/** Renders an item's link, e.g. with the router's `Link`; a plain `<a href>` otherwise. */
|
|
45
|
+
renderLink?: (props: ChipListLinkProps) => ReactNode;
|
|
46
|
+
}
|
|
47
|
+
export declare const CHIP_CLASS = "font-mono text-[11px] bg-control px-1.5 py-0.5 rounded";
|
|
48
|
+
/**
|
|
49
|
+
* A list of chips that stays short: the first `max` items, then a "+N more" button opening a dialog with all of them
|
|
50
|
+
* (a bottom sheet on phones), with a search field when the list is long. Items are text or custom content, each may be
|
|
51
|
+
* a link. Clicks on the button, a link or inside the dialog do not trigger a clickable table row around it. `—` when empty.
|
|
52
|
+
*/
|
|
53
|
+
export default function ChipList({ items, max, title, label, chipClassName, className, empty, searchThreshold, renderLink, }: ChipListProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import { type ModalSize } from './Modal';
|
|
3
|
+
export interface ConfirmDialogProps {
|
|
4
|
+
open: boolean;
|
|
5
|
+
title: ReactNode;
|
|
6
|
+
/** The question, or what will happen. */
|
|
7
|
+
message: ReactNode;
|
|
8
|
+
confirmLabel?: string;
|
|
9
|
+
cancelLabel?: string;
|
|
10
|
+
/** The confirm button's text while the action runs (default "Working…"). */
|
|
11
|
+
busyLabel?: string;
|
|
12
|
+
/** `danger`: a red confirm button, for deleting, revoking, cancelling a run. */
|
|
13
|
+
tone?: 'default' | 'danger';
|
|
14
|
+
/**
|
|
15
|
+
* Runs on confirm. While its promise is pending the button shows a spinner and the dialog cannot be dismissed; when it
|
|
16
|
+
* rejects, its message is shown in the dialog, which stays open. The caller closes the dialog (sets `open`).
|
|
17
|
+
*/
|
|
18
|
+
onConfirm: () => void | Promise<void>;
|
|
19
|
+
onCancel: () => void;
|
|
20
|
+
/** Shown under the message (e.g. an error the caller reports itself). */
|
|
21
|
+
error?: ReactNode;
|
|
22
|
+
/** The caller's own pending state, for actions it tracks itself. */
|
|
23
|
+
busy?: boolean;
|
|
24
|
+
/** Wider than the default `sm` for a long message (e.g. a script to confirm). */
|
|
25
|
+
size?: ModalSize;
|
|
26
|
+
}
|
|
27
|
+
/** A yes/no question in a dialog, replacing `window.confirm`; Cancel has focus first for dangerous actions. */
|
|
28
|
+
export default function ConfirmDialog({ open, title, message, confirmLabel, cancelLabel, busyLabel, tone, onConfirm, onCancel, error, busy, size, }: ConfirmDialogProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type SortState, type SortValue } from './sortRows';
|
|
2
|
+
interface Column<T> {
|
|
3
|
+
key: string;
|
|
4
|
+
header: string;
|
|
5
|
+
render?: (row: T) => React.ReactNode;
|
|
6
|
+
className?: string;
|
|
7
|
+
/** Makes the column sortable by this value (empty values last in either direction). */
|
|
8
|
+
sortValue?: (row: T) => SortValue;
|
|
9
|
+
}
|
|
10
|
+
interface Props<T> {
|
|
11
|
+
columns: Column<T>[];
|
|
12
|
+
data: T[];
|
|
13
|
+
onRowClick?: (row: T) => void;
|
|
14
|
+
keyExtractor: (row: T) => string;
|
|
15
|
+
/** Sort shown first; the reader can change it on sortable columns. */
|
|
16
|
+
defaultSort?: SortState;
|
|
17
|
+
/** Shows one page of the rows (0-based `index`), after sorting all of them. */
|
|
18
|
+
page?: {
|
|
19
|
+
index: number;
|
|
20
|
+
size: number;
|
|
21
|
+
};
|
|
22
|
+
/** Shown instead of the rows when there are none (default: "No data"). */
|
|
23
|
+
emptyMessage?: React.ReactNode;
|
|
24
|
+
/** Without its own card (border, background), for a table inside a panel that already has them. */
|
|
25
|
+
plain?: boolean;
|
|
26
|
+
}
|
|
27
|
+
/** A failing table shows an inline error instead of breaking the page */
|
|
28
|
+
export default function DataTable<T>(props: Props<T>): import("react/jsx-runtime").JSX.Element;
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
export interface DropdownMenuItem {
|
|
3
|
+
key: string;
|
|
4
|
+
label: string;
|
|
5
|
+
icon?: ReactNode;
|
|
6
|
+
onSelect: () => void;
|
|
7
|
+
/** `danger` for destructive actions. */
|
|
8
|
+
tone?: 'default' | 'danger';
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
}
|
|
11
|
+
/** A line between groups of items. */
|
|
12
|
+
export declare const MENU_SEPARATOR: "separator";
|
|
13
|
+
interface Props {
|
|
14
|
+
items: readonly (DropdownMenuItem | typeof MENU_SEPARATOR)[];
|
|
15
|
+
/** The button's content (a label, an avatar, an icon). */
|
|
16
|
+
children: ReactNode;
|
|
17
|
+
/** Accessible name of the button (and the menu) when its content is not text. */
|
|
18
|
+
label?: string;
|
|
19
|
+
/** Which edge of the button the menu lines up with. */
|
|
20
|
+
align?: 'start' | 'end';
|
|
21
|
+
/** Classes of the button. */
|
|
22
|
+
buttonClassName?: string;
|
|
23
|
+
/** Shown above the items (e.g. who is signed in). */
|
|
24
|
+
header?: ReactNode;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* A button that opens a menu of actions (`role="menu"`): rendered at the end of the page, below the button or above it
|
|
28
|
+
* when there is no room. Arrows, Home/End and type-ahead move between items, Enter or Space runs one, Escape and Tab
|
|
29
|
+
* close it; so do a press outside it and scrolling the page. Focus returns to the button.
|
|
30
|
+
*/
|
|
31
|
+
export default function DropdownMenu({ items, children, label, align, buttonClassName, header }: Props): import("react/jsx-runtime").JSX.Element;
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Component, type ErrorInfo, type ReactNode } from 'react';
|
|
2
|
+
interface Props {
|
|
3
|
+
children: ReactNode;
|
|
4
|
+
/** What failed, shown in the fallback (e.g. "Commands table") */
|
|
5
|
+
label?: string;
|
|
6
|
+
/** `page`: large fallback for a whole page; `section` (default): inline box for one widget */
|
|
7
|
+
variant?: 'page' | 'section';
|
|
8
|
+
/**
|
|
9
|
+
* When any of these values changes (compared with `Object.is`), a shown error is
|
|
10
|
+
* cleared and the children re-render, e.g. once the widget receives new data.
|
|
11
|
+
*/
|
|
12
|
+
resetKeys?: unknown[];
|
|
13
|
+
}
|
|
14
|
+
interface State {
|
|
15
|
+
error: Error | null;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Contains a render error to the part of the UI that failed: the rest of the
|
|
19
|
+
* page (and the sidebar) keeps working, and "Retry" re-renders the part.
|
|
20
|
+
*/
|
|
21
|
+
export default class ErrorBoundary extends Component<Props, State> {
|
|
22
|
+
state: State;
|
|
23
|
+
static getDerivedStateFromError(error: Error): State;
|
|
24
|
+
componentDidCatch(error: Error, info: ErrorInfo): void;
|
|
25
|
+
componentDidUpdate(prevProps: Props, prevState: State): void;
|
|
26
|
+
private retry;
|
|
27
|
+
render(): string | number | boolean | Iterable<ReactNode> | import("react/jsx-runtime").JSX.Element | null | undefined;
|
|
28
|
+
}
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type ReactNode, type RefObject } from 'react';
|
|
2
|
+
export type ModalSize = 'sm' | 'md' | 'lg' | 'full';
|
|
3
|
+
export interface ModalProps {
|
|
4
|
+
open: boolean;
|
|
5
|
+
onClose: () => void;
|
|
6
|
+
/** Heading of the dialog and its accessible name. */
|
|
7
|
+
title: ReactNode;
|
|
8
|
+
children: ReactNode;
|
|
9
|
+
/** Buttons in the footer. */
|
|
10
|
+
actions?: ReactNode;
|
|
11
|
+
/** `sm` confirmations, `md` forms (default), `lg` long content (an error with its stack trace, logs), `full` tools. */
|
|
12
|
+
size?: ModalSize;
|
|
13
|
+
/** Escape closes it (default). */
|
|
14
|
+
closeOnEscape?: boolean;
|
|
15
|
+
/** A click on the backdrop closes it (default). */
|
|
16
|
+
closeOnBackdrop?: boolean;
|
|
17
|
+
/** The close button in the header (default). */
|
|
18
|
+
showClose?: boolean;
|
|
19
|
+
/** Gets focus when the dialog opens; otherwise an `autoFocus` field, the first control of the body or the dialog. */
|
|
20
|
+
initialFocus?: RefObject<HTMLElement | null>;
|
|
21
|
+
/** Extra text under the title, used as the dialog's description. */
|
|
22
|
+
description?: ReactNode;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* A dialog over the page: rendered at the end of the page with a backdrop, focus kept inside it (Tab cycles) and given
|
|
26
|
+
* back to the element that had it when it closes, the page behind it not scrolling. Escape and a click on the backdrop
|
|
27
|
+
* close it unless turned off. Centered from `sm` up; a bottom sheet on phones (`full`: the whole screen), padded for
|
|
28
|
+
* the safe areas. The entrance animation is skipped for reduced motion.
|
|
29
|
+
*/
|
|
30
|
+
export default function Modal({ open, onClose, title, children, actions, size, closeOnEscape, closeOnBackdrop, showClose, initialFocus, description, }: ModalProps): import("react").ReactPortal | null;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
interface Props {
|
|
2
|
+
lines: string[];
|
|
3
|
+
maxLines?: number;
|
|
4
|
+
title?: string;
|
|
5
|
+
className?: string;
|
|
6
|
+
}
|
|
7
|
+
/** A failing panel shows an inline error instead of breaking the page */
|
|
8
|
+
export default function MonoPanel(props: Props): import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
interface Props {
|
|
2
|
+
/** 0-based. */
|
|
3
|
+
page: number;
|
|
4
|
+
pageSize: number;
|
|
5
|
+
total: number;
|
|
6
|
+
onPage: (page: number) => void;
|
|
7
|
+
onPageSize: (size: number) => void;
|
|
8
|
+
}
|
|
9
|
+
/** Page controls under a list: rows per page, which rows are shown, previous and next. Nothing for one short page. */
|
|
10
|
+
export default function Pagination({ page, pageSize, total, onPage, onPageSize }: Props): import("react/jsx-runtime").JSX.Element | null;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
export interface SelectOption<V extends string = string> {
|
|
3
|
+
value: V;
|
|
4
|
+
label: string;
|
|
5
|
+
/** A second, smaller line under the label. */
|
|
6
|
+
description?: string;
|
|
7
|
+
/** Shown before the label (a color dot, an icon). */
|
|
8
|
+
icon?: ReactNode;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export type SelectSize = 'sm' | 'md';
|
|
12
|
+
export type SelectWidth = 'responsive' | 'full' | 'auto';
|
|
13
|
+
interface BaseProps<V extends string> {
|
|
14
|
+
options: readonly SelectOption<V>[];
|
|
15
|
+
/**
|
|
16
|
+
* Accessible name. Leave it out when a `<label>` wraps the select or points at its `id`; the trigger is a button,
|
|
17
|
+
* so either names it.
|
|
18
|
+
*/
|
|
19
|
+
label?: string;
|
|
20
|
+
id?: string;
|
|
21
|
+
/** Shown while nothing is selected. */
|
|
22
|
+
placeholder?: string;
|
|
23
|
+
/** A search field above the options; by default only for lists of more than 10. */
|
|
24
|
+
searchable?: boolean;
|
|
25
|
+
disabled?: boolean;
|
|
26
|
+
/** `sm`: the compact filter controls (default); `md`: form fields. */
|
|
27
|
+
size?: SelectSize;
|
|
28
|
+
/** `responsive` (default): full width on phones, from `sm` up as wide as its label; `full`; `auto`: as wide as its label. */
|
|
29
|
+
width?: SelectWidth;
|
|
30
|
+
className?: string;
|
|
31
|
+
}
|
|
32
|
+
export interface SelectProps<V extends string> extends BaseProps<V> {
|
|
33
|
+
value: V | null;
|
|
34
|
+
onChange: (value: V) => void;
|
|
35
|
+
/** Makes it clearable: a clear button while a value is selected. */
|
|
36
|
+
onClear?: () => void;
|
|
37
|
+
}
|
|
38
|
+
export interface MultiSelectProps<V extends string> extends BaseProps<V> {
|
|
39
|
+
value: readonly V[];
|
|
40
|
+
onChange: (value: V[]) => void;
|
|
41
|
+
/** A clear button while values are selected (selects none). */
|
|
42
|
+
clearable?: boolean;
|
|
43
|
+
/** Selected values shown as chips in the button before the rest is counted (default 2). */
|
|
44
|
+
maxChips?: number;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* A themed dropdown for one value: an ARIA combobox (`role="combobox"` on the button) with a listbox rendered at the
|
|
48
|
+
* end of the page (tables and dialogs do not clip it), below the button or above it when there is no room below.
|
|
49
|
+
* Keyboard: arrows, Home/End, type-ahead, Enter or Space to choose, Escape or Tab to close.
|
|
50
|
+
*/
|
|
51
|
+
export declare function Select<V extends string>(props: SelectProps<V>): import("react/jsx-runtime").JSX.Element;
|
|
52
|
+
/** Like Select, for several values: options with checkmarks, the selection as chips; it stays open while picking. */
|
|
53
|
+
export declare function MultiSelect<V extends string>(props: MultiSelectProps<V>): import("react/jsx-runtime").JSX.Element;
|
|
54
|
+
export default Select;
|