@dowel-ui/react 0.4.0 → 0.7.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/README.md +9 -5
- package/dist/blocks/admin-dashboard/meta.js +31 -0
- package/dist/blocks/admin-dashboard/meta.js.map +1 -0
- package/dist/blocks/agent-console/meta.js +27 -0
- package/dist/blocks/agent-console/meta.js.map +1 -0
- package/dist/blocks/ai-dashboard/meta.js +25 -0
- package/dist/blocks/ai-dashboard/meta.js.map +1 -0
- package/dist/blocks/ai-workspace/meta.js +33 -0
- package/dist/blocks/ai-workspace/meta.js.map +1 -0
- package/dist/blocks/analytics/meta.js +24 -0
- package/dist/blocks/analytics/meta.js.map +1 -0
- package/dist/blocks/billing/meta.js +25 -0
- package/dist/blocks/billing/meta.js.map +1 -0
- package/dist/blocks/command-center/meta.js +28 -0
- package/dist/blocks/command-center/meta.js.map +1 -0
- package/dist/blocks/crm/meta.js +32 -0
- package/dist/blocks/crm/meta.js.map +1 -0
- package/dist/blocks/onboarding/meta.js +23 -0
- package/dist/blocks/onboarding/meta.js.map +1 -0
- package/dist/components/accordion/accordion.js +1 -1
- package/dist/components/accordion/accordion.js.map +1 -1
- package/dist/components/activity-feed/activity-feed.js +1 -1
- package/dist/components/activity-feed/activity-feed.js.map +1 -1
- package/dist/components/ai-agent-plan/ai-agent-plan.js +1 -1
- package/dist/components/ai-agent-plan/ai-agent-plan.js.map +1 -1
- package/dist/components/ai-extraction-review/ai-extraction-review.d.ts +52 -0
- package/dist/components/ai-extraction-review/ai-extraction-review.d.ts.map +1 -0
- package/dist/components/ai-extraction-review/ai-extraction-review.js +249 -0
- package/dist/components/ai-extraction-review/ai-extraction-review.js.map +1 -0
- package/dist/components/ai-extraction-review/extraction-model.d.ts +94 -0
- package/dist/components/ai-extraction-review/extraction-model.d.ts.map +1 -0
- package/dist/components/ai-extraction-review/extraction-model.js +91 -0
- package/dist/components/ai-extraction-review/extraction-model.js.map +1 -0
- package/dist/components/ai-extraction-review/index.d.ts +3 -0
- package/dist/components/ai-extraction-review/index.js +3 -0
- package/dist/components/ai-extraction-review/meta.js +17 -0
- package/dist/components/ai-extraction-review/meta.js.map +1 -0
- package/dist/components/ai-prompt-input/ai-prompt-input.js +1 -1
- package/dist/components/ai-prompt-input/ai-prompt-input.js.map +1 -1
- package/dist/components/ai-reasoning/ai-reasoning.js +1 -1
- package/dist/components/ai-reasoning/ai-reasoning.js.map +1 -1
- package/dist/components/ai-response/ai-response.js +2 -2
- package/dist/components/ai-response/ai-response.js.map +1 -1
- package/dist/components/ai-suggested-value/ai-suggested-value.d.ts +72 -0
- package/dist/components/ai-suggested-value/ai-suggested-value.d.ts.map +1 -0
- package/dist/components/ai-suggested-value/ai-suggested-value.js +126 -0
- package/dist/components/ai-suggested-value/ai-suggested-value.js.map +1 -0
- package/dist/components/ai-suggested-value/index.d.ts +2 -0
- package/dist/components/ai-suggested-value/index.js +2 -0
- package/dist/components/ai-suggested-value/meta.js +17 -0
- package/dist/components/ai-suggested-value/meta.js.map +1 -0
- package/dist/components/ai-tool/ai-tool.js +2 -2
- package/dist/components/ai-tool/ai-tool.js.map +1 -1
- package/dist/components/breadcrumb/breadcrumb.d.ts +52 -0
- package/dist/components/breadcrumb/breadcrumb.d.ts.map +1 -0
- package/dist/components/breadcrumb/breadcrumb.js +141 -0
- package/dist/components/breadcrumb/breadcrumb.js.map +1 -0
- package/dist/components/breadcrumb/index.d.ts +2 -0
- package/dist/components/breadcrumb/index.js +2 -0
- package/dist/components/breadcrumb/meta.js +17 -0
- package/dist/components/breadcrumb/meta.js.map +1 -0
- package/dist/components/calendar/calendar.js +2 -2
- package/dist/components/calendar/calendar.js.map +1 -1
- package/dist/components/code-block/code-block.js +1 -1
- package/dist/components/code-block/code-block.js.map +1 -1
- package/dist/components/collapsible/collapsible.d.ts +30 -0
- package/dist/components/collapsible/collapsible.d.ts.map +1 -0
- package/dist/components/collapsible/collapsible.js +38 -0
- package/dist/components/collapsible/collapsible.js.map +1 -0
- package/dist/components/collapsible/index.d.ts +2 -0
- package/dist/components/collapsible/index.js +2 -0
- package/dist/components/collapsible/meta.js +17 -0
- package/dist/components/collapsible/meta.js.map +1 -0
- package/dist/components/combobox/combobox.js +2 -2
- package/dist/components/combobox/combobox.js.map +1 -1
- package/dist/components/command/command.js +1 -1
- package/dist/components/command/command.js.map +1 -1
- package/dist/components/confirm-typed/confirm-typed.d.ts +47 -0
- package/dist/components/confirm-typed/confirm-typed.d.ts.map +1 -0
- package/dist/components/confirm-typed/confirm-typed.js +106 -0
- package/dist/components/confirm-typed/confirm-typed.js.map +1 -0
- package/dist/components/confirm-typed/index.d.ts +2 -0
- package/dist/components/confirm-typed/index.js +2 -0
- package/dist/components/confirm-typed/meta.js +17 -0
- package/dist/components/confirm-typed/meta.js.map +1 -0
- package/dist/components/cron-editor/cron-editor.d.ts +36 -0
- package/dist/components/cron-editor/cron-editor.d.ts.map +1 -0
- package/dist/components/cron-editor/cron-editor.js +493 -0
- package/dist/components/cron-editor/cron-editor.js.map +1 -0
- package/dist/components/cron-editor/cron-expression.d.ts +82 -0
- package/dist/components/cron-editor/cron-expression.d.ts.map +1 -0
- package/dist/components/cron-editor/cron-expression.js +352 -0
- package/dist/components/cron-editor/cron-expression.js.map +1 -0
- package/dist/components/cron-editor/index.d.ts +3 -0
- package/dist/components/cron-editor/index.js +3 -0
- package/dist/components/cron-editor/meta.js +17 -0
- package/dist/components/cron-editor/meta.js.map +1 -0
- package/dist/components/data-table/data-table.d.ts.map +1 -1
- package/dist/components/data-table/data-table.js +4 -1
- package/dist/components/data-table/data-table.js.map +1 -1
- package/dist/components/dialog/dialog.js +2 -2
- package/dist/components/dialog/dialog.js.map +1 -1
- package/dist/components/diff-viewer/diff-viewer.js +4 -4
- package/dist/components/diff-viewer/diff-viewer.js.map +1 -1
- package/dist/components/direction/direction.d.ts +35 -0
- package/dist/components/direction/direction.d.ts.map +1 -0
- package/dist/components/direction/direction.js +14 -0
- package/dist/components/direction/direction.js.map +1 -0
- package/dist/components/direction/index.d.ts +2 -0
- package/dist/components/direction/index.js +2 -0
- package/dist/components/direction/meta.js +17 -0
- package/dist/components/direction/meta.js.map +1 -0
- package/dist/components/dns-record/dns-record.d.ts +61 -0
- package/dist/components/dns-record/dns-record.d.ts.map +1 -0
- package/dist/components/dns-record/dns-record.js +227 -0
- package/dist/components/dns-record/dns-record.js.map +1 -0
- package/dist/components/dns-record/index.d.ts +2 -0
- package/dist/components/dns-record/index.js +2 -0
- package/dist/components/dns-record/meta.js +17 -0
- package/dist/components/dns-record/meta.js.map +1 -0
- package/dist/components/drawer/drawer.js +1 -1
- package/dist/components/drawer/drawer.js.map +1 -1
- package/dist/components/dropdown-menu/dropdown-menu.d.ts.map +1 -1
- package/dist/components/dropdown-menu/dropdown-menu.js +9 -8
- package/dist/components/dropdown-menu/dropdown-menu.js.map +1 -1
- package/dist/components/input/input.js +1 -1
- package/dist/components/input/input.js.map +1 -1
- package/dist/components/log-viewer/log-viewer.js +2 -2
- package/dist/components/log-viewer/log-viewer.js.map +1 -1
- package/dist/components/meter/meter.js +1 -1
- package/dist/components/meter/meter.js.map +1 -1
- package/dist/components/pagination/pagination.d.ts.map +1 -1
- package/dist/components/pagination/pagination.js +3 -2
- package/dist/components/pagination/pagination.js.map +1 -1
- package/dist/components/permission-matrix/index.d.ts +3 -0
- package/dist/components/permission-matrix/index.js +3 -0
- package/dist/components/permission-matrix/meta.js +17 -0
- package/dist/components/permission-matrix/meta.js.map +1 -0
- package/dist/components/permission-matrix/permission-matrix.d.ts +46 -0
- package/dist/components/permission-matrix/permission-matrix.d.ts.map +1 -0
- package/dist/components/permission-matrix/permission-matrix.js +199 -0
- package/dist/components/permission-matrix/permission-matrix.js.map +1 -0
- package/dist/components/permission-matrix/permission-model.d.ts +53 -0
- package/dist/components/permission-matrix/permission-model.d.ts.map +1 -0
- package/dist/components/permission-matrix/permission-model.js +64 -0
- package/dist/components/permission-matrix/permission-model.js.map +1 -0
- package/dist/components/record-diff/record-diff.js +4 -4
- package/dist/components/record-diff/record-diff.js.map +1 -1
- package/dist/components/secret-field/index.d.ts +2 -0
- package/dist/components/secret-field/index.js +2 -0
- package/dist/components/secret-field/meta.js +17 -0
- package/dist/components/secret-field/meta.js.map +1 -0
- package/dist/components/secret-field/secret-field.d.ts +58 -0
- package/dist/components/secret-field/secret-field.d.ts.map +1 -0
- package/dist/components/secret-field/secret-field.js +168 -0
- package/dist/components/secret-field/secret-field.js.map +1 -0
- package/dist/components/select/select.js +2 -2
- package/dist/components/select/select.js.map +1 -1
- package/dist/components/session-expiry/index.d.ts +2 -0
- package/dist/components/session-expiry/index.js +2 -0
- package/dist/components/session-expiry/meta.js +17 -0
- package/dist/components/session-expiry/meta.js.map +1 -0
- package/dist/components/session-expiry/session-expiry.d.ts +64 -0
- package/dist/components/session-expiry/session-expiry.d.ts.map +1 -0
- package/dist/components/session-expiry/session-expiry.js +185 -0
- package/dist/components/session-expiry/session-expiry.js.map +1 -0
- package/dist/components/sheet/sheet.d.ts.map +1 -1
- package/dist/components/sheet/sheet.js +2 -2
- package/dist/components/sheet/sheet.js.map +1 -1
- package/dist/components/shortcut-recorder/index.d.ts +3 -0
- package/dist/components/shortcut-recorder/index.js +3 -0
- package/dist/components/shortcut-recorder/meta.js +17 -0
- package/dist/components/shortcut-recorder/meta.js.map +1 -0
- package/dist/components/shortcut-recorder/shortcut-model.d.ts +67 -0
- package/dist/components/shortcut-recorder/shortcut-model.d.ts.map +1 -0
- package/dist/components/shortcut-recorder/shortcut-model.js +168 -0
- package/dist/components/shortcut-recorder/shortcut-model.js.map +1 -0
- package/dist/components/shortcut-recorder/shortcut-recorder.d.ts +47 -0
- package/dist/components/shortcut-recorder/shortcut-recorder.d.ts.map +1 -0
- package/dist/components/shortcut-recorder/shortcut-recorder.js +212 -0
- package/dist/components/shortcut-recorder/shortcut-recorder.js.map +1 -0
- package/dist/components/sidebar/index.d.ts +2 -0
- package/dist/components/sidebar/index.js +2 -0
- package/dist/components/sidebar/meta.js +17 -0
- package/dist/components/sidebar/meta.js.map +1 -0
- package/dist/components/sidebar/sidebar.d.ts +69 -0
- package/dist/components/sidebar/sidebar.d.ts.map +1 -0
- package/dist/components/sidebar/sidebar.js +256 -0
- package/dist/components/sidebar/sidebar.js.map +1 -0
- package/dist/components/sync-status/index.d.ts +2 -0
- package/dist/components/sync-status/index.js +2 -0
- package/dist/components/sync-status/meta.js +17 -0
- package/dist/components/sync-status/meta.js.map +1 -0
- package/dist/components/sync-status/sync-status.d.ts +65 -0
- package/dist/components/sync-status/sync-status.d.ts.map +1 -0
- package/dist/components/sync-status/sync-status.js +103 -0
- package/dist/components/sync-status/sync-status.js.map +1 -0
- package/dist/components/table/table.js +2 -2
- package/dist/components/table/table.js.map +1 -1
- package/dist/components/tags-input/tags-input.js +1 -1
- package/dist/components/tags-input/tags-input.js.map +1 -1
- package/dist/components/textarea/index.d.ts +2 -0
- package/dist/components/textarea/index.js +2 -0
- package/dist/components/textarea/meta.js +17 -0
- package/dist/components/textarea/meta.js.map +1 -0
- package/dist/components/textarea/textarea.d.ts +43 -0
- package/dist/components/textarea/textarea.d.ts.map +1 -0
- package/dist/components/textarea/textarea.js +119 -0
- package/dist/components/textarea/textarea.js.map +1 -0
- package/dist/components/time-range-picker/time-range-picker.js +3 -3
- package/dist/components/time-range-picker/time-range-picker.js.map +1 -1
- package/dist/components/toast/toast.d.ts.map +1 -1
- package/dist/components/toast/toast.js +2 -2
- package/dist/components/toast/toast.js.map +1 -1
- package/dist/index.d.ts +36 -2
- package/dist/index.js +22 -3
- package/dist/lib/styles.d.ts +16 -1
- package/dist/lib/styles.d.ts.map +1 -1
- package/dist/lib/styles.js +16 -1
- package/dist/lib/styles.js.map +1 -1
- package/dist/registry/blocks.d.ts.map +1 -1
- package/dist/registry/blocks.js +27 -9
- package/dist/registry/blocks.js.map +1 -1
- package/dist/registry/components.d.ts.map +1 -1
- package/dist/registry/components.js +84 -54
- package/dist/registry/components.js.map +1 -1
- package/dist/registry/schema.d.ts +8 -0
- package/dist/registry/schema.d.ts.map +1 -1
- package/dist/registry/schema.js.map +1 -1
- package/package.json +5 -4
- package/src/components/accordion/accordion.tsx +1 -1
- package/src/components/activity-feed/activity-feed.tsx +1 -1
- package/src/components/ai-agent-plan/ai-agent-plan.tsx +0 -0
- package/src/components/ai-extraction-review/ai-extraction-review.tsx +492 -0
- package/src/components/ai-extraction-review/extraction-model.ts +159 -0
- package/src/components/ai-extraction-review/index.ts +13 -0
- package/src/components/ai-extraction-review/meta.ts +24 -0
- package/src/components/ai-prompt-input/ai-prompt-input.tsx +1 -1
- package/src/components/ai-reasoning/ai-reasoning.tsx +1 -1
- package/src/components/ai-response/ai-response.tsx +2 -2
- package/src/components/ai-suggested-value/ai-suggested-value.tsx +295 -0
- package/src/components/ai-suggested-value/index.ts +6 -0
- package/src/components/ai-suggested-value/meta.ts +24 -0
- package/src/components/ai-tool/ai-tool.tsx +2 -2
- package/src/components/breadcrumb/breadcrumb.tsx +157 -0
- package/src/components/breadcrumb/index.ts +10 -0
- package/src/components/breadcrumb/meta.ts +19 -0
- package/src/components/calendar/calendar.tsx +2 -2
- package/src/components/code-block/code-block.tsx +1 -1
- package/src/components/collapsible/collapsible.tsx +63 -0
- package/src/components/collapsible/index.ts +6 -0
- package/src/components/collapsible/meta.ts +16 -0
- package/src/components/combobox/combobox.tsx +2 -2
- package/src/components/command/command.tsx +1 -1
- package/src/components/confirm-typed/confirm-typed.tsx +191 -0
- package/src/components/confirm-typed/index.ts +1 -0
- package/src/components/confirm-typed/meta.ts +22 -0
- package/src/components/cron-editor/cron-editor.tsx +676 -0
- package/src/components/cron-editor/cron-expression.ts +552 -0
- package/src/components/cron-editor/index.ts +23 -0
- package/src/components/cron-editor/meta.ts +23 -0
- package/src/components/data-table/data-table.tsx +14 -3
- package/src/components/dialog/dialog.tsx +2 -2
- package/src/components/diff-viewer/diff-viewer.tsx +4 -4
- package/src/components/direction/direction.tsx +38 -0
- package/src/components/direction/index.ts +1 -0
- package/src/components/direction/meta.ts +19 -0
- package/src/components/dns-record/dns-record.tsx +315 -0
- package/src/components/dns-record/index.ts +7 -0
- package/src/components/dns-record/meta.ts +21 -0
- package/src/components/drawer/drawer.tsx +1 -1
- package/src/components/dropdown-menu/dropdown-menu.tsx +14 -8
- package/src/components/input/input.tsx +1 -1
- package/src/components/log-viewer/log-viewer.tsx +2 -2
- package/src/components/meter/meter.tsx +1 -1
- package/src/components/pagination/pagination.tsx +13 -2
- package/src/components/permission-matrix/index.ts +14 -0
- package/src/components/permission-matrix/meta.ts +23 -0
- package/src/components/permission-matrix/permission-matrix.tsx +368 -0
- package/src/components/permission-matrix/permission-model.ts +120 -0
- package/src/components/record-diff/record-diff.tsx +4 -4
- package/src/components/secret-field/index.ts +6 -0
- package/src/components/secret-field/meta.ts +21 -0
- package/src/components/secret-field/secret-field.tsx +284 -0
- package/src/components/select/select.tsx +2 -2
- package/src/components/session-expiry/index.ts +9 -0
- package/src/components/session-expiry/meta.ts +23 -0
- package/src/components/session-expiry/session-expiry.tsx +321 -0
- package/src/components/sheet/sheet.tsx +8 -4
- package/src/components/shortcut-recorder/index.ts +19 -0
- package/src/components/shortcut-recorder/meta.ts +22 -0
- package/src/components/shortcut-recorder/shortcut-model.ts +204 -0
- package/src/components/shortcut-recorder/shortcut-recorder.tsx +336 -0
- package/src/components/sidebar/index.ts +19 -0
- package/src/components/sidebar/meta.ts +25 -0
- package/src/components/sidebar/sidebar.tsx +374 -0
- package/src/components/sync-status/index.ts +9 -0
- package/src/components/sync-status/meta.ts +21 -0
- package/src/components/sync-status/sync-status.tsx +217 -0
- package/src/components/table/table.tsx +3 -3
- package/src/components/tags-input/tags-input.tsx +1 -1
- package/src/components/textarea/index.ts +1 -0
- package/src/components/textarea/meta.ts +21 -0
- package/src/components/textarea/textarea.tsx +210 -0
- package/src/components/time-range-picker/time-range-picker.tsx +3 -3
- package/src/components/toast/toast.tsx +14 -6
- package/src/index.ts +15 -0
- package/src/lib/styles.ts +16 -0
- package/src/registry/blocks.ts +18 -0
- package/src/registry/components.ts +30 -0
- package/src/registry/schema.ts +8 -0
- package/src/blocks/admin-users/admin-users.tsx +0 -251
- package/src/blocks/admin-users/index.ts +0 -1
- package/src/blocks/admin-users/meta.ts +0 -27
- package/src/blocks/ai-chat/ai-chat.tsx +0 -280
- package/src/blocks/ai-chat/index.ts +0 -7
- package/src/blocks/ai-chat/meta.ts +0 -32
- package/src/blocks/dashboard/dashboard.tsx +0 -192
- package/src/blocks/dashboard/index.ts +0 -6
- package/src/blocks/dashboard/meta.ts +0 -18
- package/src/blocks/forgot-password/forgot-password.tsx +0 -158
- package/src/blocks/forgot-password/index.ts +0 -1
- package/src/blocks/forgot-password/meta.ts +0 -18
- package/src/blocks/login/index.ts +0 -1
- package/src/blocks/login/login.tsx +0 -178
- package/src/blocks/login/meta.ts +0 -18
- package/src/blocks/pricing/index.ts +0 -1
- package/src/blocks/pricing/meta.ts +0 -18
- package/src/blocks/pricing/pricing.tsx +0 -176
- package/src/blocks/settings/index.ts +0 -6
- package/src/blocks/settings/meta.ts +0 -29
- package/src/blocks/settings/settings.tsx +0 -317
- package/src/blocks/signup/index.ts +0 -1
- package/src/blocks/signup/meta.ts +0 -18
- package/src/blocks/signup/signup.tsx +0 -240
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { Slot } from "radix-ui";
|
|
4
|
+
import {
|
|
5
|
+
createContext,
|
|
6
|
+
useContext,
|
|
7
|
+
useId,
|
|
8
|
+
useMemo,
|
|
9
|
+
useState,
|
|
10
|
+
useSyncExternalStore,
|
|
11
|
+
type ComponentPropsWithRef,
|
|
12
|
+
type ReactNode,
|
|
13
|
+
} from "react";
|
|
14
|
+
|
|
15
|
+
import { Sheet, SheetContent, SheetTitle } from "@/components/sheet";
|
|
16
|
+
import { disabledStyles, focusRing } from "@/lib/styles";
|
|
17
|
+
import { cn } from "@/lib/utils";
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The application's own navigation.
|
|
21
|
+
*
|
|
22
|
+
* Two states, not one. On a wide screen it collapses to a rail of icons and
|
|
23
|
+
* stays in the page; on a narrow one it is an overlay, which needs a focus trap
|
|
24
|
+
* and an Escape key and is therefore a Sheet rather than a div with a
|
|
25
|
+
* transform. Building one behaviour and hiding it at a breakpoint gets the
|
|
26
|
+
* mobile case wrong every time — the page behind stays reachable by Tab while
|
|
27
|
+
* the menu covers it.
|
|
28
|
+
*
|
|
29
|
+
* The collapsed rail is where these usually fail. Hiding the label leaves a
|
|
30
|
+
* button whose only content is an icon, and an icon has no accessible name. The
|
|
31
|
+
* label here is not removed but visually hidden, so the control keeps its name
|
|
32
|
+
* whether or not the text is on screen.
|
|
33
|
+
*
|
|
34
|
+
* The overlay is mounted only on a narrow screen, and it has its own open
|
|
35
|
+
* state. Mounting it always and hiding it with CSS was the first version, and
|
|
36
|
+
* it was wrong in a way no visual check catches: a modal dialog that is
|
|
37
|
+
* `display: none` is still modal. It marks the rest of the page `aria-hidden`,
|
|
38
|
+
* traps focus in an element nothing can focus, and turns pointer events off on
|
|
39
|
+
* the body — so on a desktop the whole application was invisible to a screen
|
|
40
|
+
* reader and unclickable the moment the sidebar was open, which is its default.
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
/** Below Tailwind's `md` breakpoint, which is where the rail gives way to the overlay. */
|
|
44
|
+
const NARROW_QUERY = "(max-width: 767px)";
|
|
45
|
+
|
|
46
|
+
function subscribeToNarrow(callback: () => void): () => void {
|
|
47
|
+
const query = window.matchMedia(NARROW_QUERY);
|
|
48
|
+
query.addEventListener("change", callback);
|
|
49
|
+
return () => {
|
|
50
|
+
query.removeEventListener("change", callback);
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Whether the viewport is narrow enough for the overlay.
|
|
56
|
+
*
|
|
57
|
+
* The server snapshot says "wide": the rail renders in the HTML and CSS hides
|
|
58
|
+
* it below the breakpoint, so a narrow screen shows nothing wrong before
|
|
59
|
+
* hydration and the sheet mounts, closed, straight after.
|
|
60
|
+
*/
|
|
61
|
+
function useIsNarrow(): boolean {
|
|
62
|
+
return useSyncExternalStore(
|
|
63
|
+
subscribeToNarrow,
|
|
64
|
+
() => window.matchMedia(NARROW_QUERY).matches,
|
|
65
|
+
() => false,
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
interface SidebarContextValue {
|
|
70
|
+
/** The rail is expanded rather than collapsed. */
|
|
71
|
+
open: boolean;
|
|
72
|
+
setOpen: (open: boolean) => void;
|
|
73
|
+
/** The viewport is narrow, so the navigation is an overlay. */
|
|
74
|
+
narrow: boolean;
|
|
75
|
+
/** The overlay is showing. Only meaningful when `narrow`. */
|
|
76
|
+
overlayOpen: boolean;
|
|
77
|
+
setOverlayOpen: (open: boolean) => void;
|
|
78
|
+
/** Whichever of the two states applies on this viewport. */
|
|
79
|
+
toggle: () => void;
|
|
80
|
+
/** Id of the sidebar element, for the trigger's aria-controls. */
|
|
81
|
+
sidebarId: string;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const SidebarContext = createContext<SidebarContextValue | null>(null);
|
|
85
|
+
|
|
86
|
+
function useSidebar(component: string): SidebarContextValue {
|
|
87
|
+
const context = useContext(SidebarContext);
|
|
88
|
+
if (!context) {
|
|
89
|
+
throw new Error(`${component} must be rendered inside <SidebarProvider>.`);
|
|
90
|
+
}
|
|
91
|
+
return context;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export interface SidebarProviderProps {
|
|
95
|
+
/** Controlled open state. */
|
|
96
|
+
open?: boolean;
|
|
97
|
+
defaultOpen?: boolean;
|
|
98
|
+
onOpenChange?: (open: boolean) => void;
|
|
99
|
+
children?: ReactNode;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function SidebarProvider({
|
|
103
|
+
open: openProp,
|
|
104
|
+
defaultOpen = true,
|
|
105
|
+
onOpenChange,
|
|
106
|
+
children,
|
|
107
|
+
}: SidebarProviderProps) {
|
|
108
|
+
const [uncontrolled, setUncontrolled] = useState(defaultOpen);
|
|
109
|
+
const open = openProp ?? uncontrolled;
|
|
110
|
+
// Separate from `open`, and never true to begin with: "expanded by default"
|
|
111
|
+
// is a fact about the rail. An overlay that covers the page on first load is
|
|
112
|
+
// a menu nobody asked for.
|
|
113
|
+
const [overlayOpen, setOverlayOpen] = useState(false);
|
|
114
|
+
const narrow = useIsNarrow();
|
|
115
|
+
const sidebarId = useId();
|
|
116
|
+
|
|
117
|
+
const value = useMemo<SidebarContextValue>(() => {
|
|
118
|
+
const setOpen = (next: boolean) => {
|
|
119
|
+
if (openProp === undefined) setUncontrolled(next);
|
|
120
|
+
onOpenChange?.(next);
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
return {
|
|
124
|
+
open,
|
|
125
|
+
setOpen,
|
|
126
|
+
narrow,
|
|
127
|
+
overlayOpen,
|
|
128
|
+
setOverlayOpen,
|
|
129
|
+
toggle: () => {
|
|
130
|
+
if (narrow) setOverlayOpen(!overlayOpen);
|
|
131
|
+
else setOpen(!open);
|
|
132
|
+
},
|
|
133
|
+
sidebarId,
|
|
134
|
+
};
|
|
135
|
+
}, [open, openProp, onOpenChange, narrow, overlayOpen, sidebarId]);
|
|
136
|
+
|
|
137
|
+
return <SidebarContext.Provider value={value}>{children}</SidebarContext.Provider>;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export interface SidebarProps extends ComponentPropsWithRef<"aside"> {
|
|
141
|
+
/**
|
|
142
|
+
* Names the navigation landmark.
|
|
143
|
+
*
|
|
144
|
+
* Required, not optional. A page has more than one navigation region — this,
|
|
145
|
+
* a breadcrumb, a footer — and three landmarks all called "navigation" is a
|
|
146
|
+
* list a screen reader user cannot choose from.
|
|
147
|
+
*/
|
|
148
|
+
label: string;
|
|
149
|
+
/** Title for the overlay on a narrow screen, where it is a dialog. */
|
|
150
|
+
mobileTitle?: string;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export function Sidebar({ className, label, mobileTitle, children, ...props }: SidebarProps) {
|
|
154
|
+
const { open, narrow, overlayOpen, setOverlayOpen, sidebarId } = useSidebar("Sidebar");
|
|
155
|
+
|
|
156
|
+
return (
|
|
157
|
+
<>
|
|
158
|
+
{/*
|
|
159
|
+
The overlay, on a narrow screen. A Sheet rather than a styled div: it
|
|
160
|
+
traps focus, closes on Escape and marks the rest of the page inert,
|
|
161
|
+
none of which a transform does — and without them the page behind stays
|
|
162
|
+
reachable by Tab while the menu covers it.
|
|
163
|
+
|
|
164
|
+
Mounted only when the screen is narrow. Those three behaviours are
|
|
165
|
+
exactly why it must not exist on a wide one: see the note at the top.
|
|
166
|
+
*/}
|
|
167
|
+
{narrow ? (
|
|
168
|
+
<Sheet open={overlayOpen} onOpenChange={setOverlayOpen}>
|
|
169
|
+
<SheetContent side="left" className="w-72 p-0">
|
|
170
|
+
<SheetTitle className="sr-only">{mobileTitle ?? label}</SheetTitle>
|
|
171
|
+
<nav aria-label={label} className="flex h-full flex-col gap-2 p-3">
|
|
172
|
+
{children}
|
|
173
|
+
</nav>
|
|
174
|
+
</SheetContent>
|
|
175
|
+
</Sheet>
|
|
176
|
+
) : null}
|
|
177
|
+
|
|
178
|
+
<aside
|
|
179
|
+
id={sidebarId}
|
|
180
|
+
data-slot="sidebar"
|
|
181
|
+
data-state={open ? "expanded" : "collapsed"}
|
|
182
|
+
className={cn(
|
|
183
|
+
"hidden shrink-0 border-e border-border bg-background md:block",
|
|
184
|
+
"transition-[width] duration-[var(--duration-normal)] ease-[var(--ease-out-quint)]",
|
|
185
|
+
open ? "w-60" : "w-14",
|
|
186
|
+
className,
|
|
187
|
+
)}
|
|
188
|
+
{...props}
|
|
189
|
+
>
|
|
190
|
+
<nav aria-label={label} className="flex h-full flex-col gap-2 p-3">
|
|
191
|
+
{children}
|
|
192
|
+
</nav>
|
|
193
|
+
</aside>
|
|
194
|
+
</>
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export function SidebarHeader({ className, ...props }: ComponentPropsWithRef<"div">) {
|
|
199
|
+
return (
|
|
200
|
+
<div
|
|
201
|
+
data-slot="sidebar-header"
|
|
202
|
+
className={cn("flex min-h-9 items-center gap-2 px-1", className)}
|
|
203
|
+
{...props}
|
|
204
|
+
/>
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export function SidebarContent({ className, ...props }: ComponentPropsWithRef<"div">) {
|
|
209
|
+
return (
|
|
210
|
+
<div
|
|
211
|
+
data-slot="sidebar-content"
|
|
212
|
+
className={cn("flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto", className)}
|
|
213
|
+
{...props}
|
|
214
|
+
/>
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export function SidebarFooter({ className, ...props }: ComponentPropsWithRef<"div">) {
|
|
219
|
+
return <div data-slot="sidebar-footer" className={cn("mt-auto", className)} {...props} />;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export function SidebarGroup({ className, ...props }: ComponentPropsWithRef<"div">) {
|
|
223
|
+
return <div data-slot="sidebar-group" className={cn("grid gap-1", className)} {...props} />;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* A heading for a group of links.
|
|
228
|
+
*
|
|
229
|
+
* Hidden rather than removed when the rail is collapsed, so the grouping
|
|
230
|
+
* survives for anyone not reading the layout visually.
|
|
231
|
+
*/
|
|
232
|
+
export function SidebarGroupLabel({ className, ...props }: ComponentPropsWithRef<"div">) {
|
|
233
|
+
const { open, narrow } = useSidebar("SidebarGroupLabel");
|
|
234
|
+
|
|
235
|
+
return (
|
|
236
|
+
<div
|
|
237
|
+
data-slot="sidebar-group-label"
|
|
238
|
+
className={cn(
|
|
239
|
+
"px-2 text-xs font-medium tracking-wide text-muted-foreground uppercase",
|
|
240
|
+
// The rail's collapsed state is not the overlay's: a sheet is always
|
|
241
|
+
// wide enough for its labels.
|
|
242
|
+
!open && !narrow && "sr-only",
|
|
243
|
+
className,
|
|
244
|
+
)}
|
|
245
|
+
{...props}
|
|
246
|
+
/>
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
export function SidebarMenu({ className, ...props }: ComponentPropsWithRef<"ul">) {
|
|
251
|
+
return <ul data-slot="sidebar-menu" className={cn("grid gap-0.5", className)} {...props} />;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export function SidebarMenuItem({ className, ...props }: ComponentPropsWithRef<"li">) {
|
|
255
|
+
return <li data-slot="sidebar-menu-item" className={cn("min-w-0", className)} {...props} />;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
export interface SidebarMenuButtonProps extends ComponentPropsWithRef<"a"> {
|
|
259
|
+
/** Render the child as the control, for a router's own link or a button. */
|
|
260
|
+
asChild?: boolean;
|
|
261
|
+
/** The page currently being shown. */
|
|
262
|
+
isActive?: boolean;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* One entry in the navigation.
|
|
267
|
+
*
|
|
268
|
+
* `aria-current="page"` when active, not merely a background colour: which page
|
|
269
|
+
* you are on is information, and a highlight conveys it to exactly one kind of
|
|
270
|
+
* reader.
|
|
271
|
+
*/
|
|
272
|
+
export function SidebarMenuButton({
|
|
273
|
+
className,
|
|
274
|
+
asChild = false,
|
|
275
|
+
isActive = false,
|
|
276
|
+
children,
|
|
277
|
+
...props
|
|
278
|
+
}: SidebarMenuButtonProps) {
|
|
279
|
+
const Component = asChild ? Slot.Root : "a";
|
|
280
|
+
|
|
281
|
+
return (
|
|
282
|
+
<Component
|
|
283
|
+
data-slot="sidebar-menu-button"
|
|
284
|
+
data-active={isActive || undefined}
|
|
285
|
+
aria-current={isActive ? "page" : undefined}
|
|
286
|
+
className={cn(
|
|
287
|
+
"flex h-9 w-full items-center gap-2.5 rounded-md px-2 text-sm",
|
|
288
|
+
"transition-colors duration-[var(--duration-fast)]",
|
|
289
|
+
"[&>svg]:size-4 [&>svg]:shrink-0",
|
|
290
|
+
isActive
|
|
291
|
+
? "bg-accent font-medium text-accent-foreground"
|
|
292
|
+
: "text-muted-foreground hover:bg-accent/60 hover:text-foreground",
|
|
293
|
+
focusRing,
|
|
294
|
+
disabledStyles,
|
|
295
|
+
className,
|
|
296
|
+
)}
|
|
297
|
+
{...props}
|
|
298
|
+
>
|
|
299
|
+
{children}
|
|
300
|
+
</Component>
|
|
301
|
+
);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* The text of a menu entry.
|
|
306
|
+
*
|
|
307
|
+
* Visually hidden rather than removed when the rail is collapsed. Removing it
|
|
308
|
+
* leaves a control whose only content is an icon, and an icon has no accessible
|
|
309
|
+
* name — which is how a collapsed sidebar becomes a column of buttons all
|
|
310
|
+
* announced as "link".
|
|
311
|
+
*/
|
|
312
|
+
export function SidebarMenuLabel({ className, ...props }: ComponentPropsWithRef<"span">) {
|
|
313
|
+
const { open, narrow } = useSidebar("SidebarMenuLabel");
|
|
314
|
+
|
|
315
|
+
return (
|
|
316
|
+
<span
|
|
317
|
+
data-slot="sidebar-menu-label"
|
|
318
|
+
className={cn("min-w-0 truncate", !open && !narrow && "sr-only", className)}
|
|
319
|
+
{...props}
|
|
320
|
+
/>
|
|
321
|
+
);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
export interface SidebarTriggerProps extends ComponentPropsWithRef<"button"> {
|
|
325
|
+
/** Overrides the label, which otherwise says what pressing it will do. */
|
|
326
|
+
label?: string;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
export function SidebarTrigger({ className, label, ...props }: SidebarTriggerProps) {
|
|
330
|
+
const { open, narrow, overlayOpen, toggle, sidebarId } = useSidebar("SidebarTrigger");
|
|
331
|
+
|
|
332
|
+
const expanded = narrow ? overlayOpen : open;
|
|
333
|
+
const fallback = narrow
|
|
334
|
+
? overlayOpen
|
|
335
|
+
? "Close navigation"
|
|
336
|
+
: "Open navigation"
|
|
337
|
+
: open
|
|
338
|
+
? "Collapse navigation"
|
|
339
|
+
: "Expand navigation";
|
|
340
|
+
|
|
341
|
+
return (
|
|
342
|
+
<button
|
|
343
|
+
type="button"
|
|
344
|
+
data-slot="sidebar-trigger"
|
|
345
|
+
aria-expanded={expanded}
|
|
346
|
+
// The rail is what this controls. The overlay is a dialog that names
|
|
347
|
+
// itself, and pointing at an element CSS has hidden helps nobody.
|
|
348
|
+
aria-controls={narrow ? undefined : sidebarId}
|
|
349
|
+
// Says what pressing it does, not what the state currently is. "Collapse
|
|
350
|
+
// navigation" while it is expanded is the useful half.
|
|
351
|
+
aria-label={label ?? fallback}
|
|
352
|
+
onClick={toggle}
|
|
353
|
+
className={cn(
|
|
354
|
+
"grid size-9 shrink-0 place-items-center rounded-md text-muted-foreground",
|
|
355
|
+
"transition-colors duration-[var(--duration-fast)] hover:bg-accent hover:text-foreground",
|
|
356
|
+
focusRing,
|
|
357
|
+
className,
|
|
358
|
+
)}
|
|
359
|
+
{...props}
|
|
360
|
+
>
|
|
361
|
+
<svg viewBox="0 0 24 24" fill="none" aria-hidden className="size-4">
|
|
362
|
+
<rect x="3" y="4" width="18" height="16" rx="2" stroke="currentColor" strokeWidth="2" />
|
|
363
|
+
<path d="M9 4v16" stroke="currentColor" strokeWidth="2" />
|
|
364
|
+
</svg>
|
|
365
|
+
</button>
|
|
366
|
+
);
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/** The region the sidebar sits beside. */
|
|
370
|
+
export function SidebarInset({ className, ...props }: ComponentPropsWithRef<"main">) {
|
|
371
|
+
return (
|
|
372
|
+
<main data-slot="sidebar-inset" className={cn("min-w-0 flex-1", className)} {...props} />
|
|
373
|
+
);
|
|
374
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { defineMeta } from "@/registry/schema";
|
|
2
|
+
|
|
3
|
+
export const meta = defineMeta({
|
|
4
|
+
name: "sync-status",
|
|
5
|
+
title: "Sync Status",
|
|
6
|
+
description: "Offline, saving, saved or failed — with the count of changes being held.",
|
|
7
|
+
category: "feedback",
|
|
8
|
+
status: "stable",
|
|
9
|
+
dependencies: [],
|
|
10
|
+
registryDependencies: ["button"],
|
|
11
|
+
files: ["sync-status.tsx"],
|
|
12
|
+
a11y:
|
|
13
|
+
"The word is the status and the coloured dot is decoration, hidden from assistive " +
|
|
14
|
+
"technology. The visible text is not a live region: every save flips it and a region on it " +
|
|
15
|
+
"would narrate the whole session. A separate region, present from the first render, " +
|
|
16
|
+
"announces transitions only — went offline with what will happen to the changes, came back " +
|
|
17
|
+
"with what is being saved, could not save, saved after a failure — and never the churn of " +
|
|
18
|
+
"saving itself. Announcing is on by default because going offline is the one thing a reader " +
|
|
19
|
+
"who is typing has to be told, and it can be turned off. The server render assumes online, " +
|
|
20
|
+
"since a page with no interface to report has no business saying offline.",
|
|
21
|
+
});
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useState, useSyncExternalStore, type ComponentPropsWithRef } from "react";
|
|
4
|
+
|
|
5
|
+
import { Button } from "@/components/button";
|
|
6
|
+
import { cn } from "@/lib/utils";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* "Offline — 3 changes will sync when you're back."
|
|
10
|
+
*
|
|
11
|
+
* Linear, Notion, Figma and Google Docs each built this, and nothing in a
|
|
12
|
+
* component library touches network state at all. It is small, and it is
|
|
13
|
+
* the difference between an app that loses work and one that says it is
|
|
14
|
+
* holding it: the moment a request fails, the reader needs to know whether
|
|
15
|
+
* to keep typing, and whether what they typed a minute ago is anywhere.
|
|
16
|
+
*
|
|
17
|
+
* Two things this gets right that the obvious version gets wrong.
|
|
18
|
+
*
|
|
19
|
+
* `navigator.onLine` is believed in one direction only. False is reliable —
|
|
20
|
+
* the interface is down. True means only that there is an interface, not
|
|
21
|
+
* that the server is reachable, so an application's own failed request is
|
|
22
|
+
* the real signal and takes precedence. The hook is exported for the rest
|
|
23
|
+
* of the app to share the same reading.
|
|
24
|
+
*
|
|
25
|
+
* Announcements are for transitions, not states. Every save flips
|
|
26
|
+
* "Saving…" to "Saved", and a live region on that text narrates the whole
|
|
27
|
+
* session. So the visible text is not live; a separate region says something
|
|
28
|
+
* only when the situation changes — went offline, came back, could not sync —
|
|
29
|
+
* which is when a reader who is typing needs to be told.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
export type SyncState = "synced" | "pending" | "syncing" | "offline" | "error";
|
|
33
|
+
|
|
34
|
+
export interface SyncInput {
|
|
35
|
+
/** From `useOnlineStatus`, or your own reading. */
|
|
36
|
+
online: boolean;
|
|
37
|
+
/** Changes waiting to be sent. */
|
|
38
|
+
pending?: number;
|
|
39
|
+
/** A send is in flight. */
|
|
40
|
+
syncing?: boolean;
|
|
41
|
+
/** The last send failed, in the reader's language. Takes precedence over `online`. */
|
|
42
|
+
error?: string | null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Which state the inputs amount to. Error beats offline beats syncing beats
|
|
47
|
+
* pending beats synced: each one is the thing the reader most needs to know
|
|
48
|
+
* given the others.
|
|
49
|
+
*/
|
|
50
|
+
export function syncState({
|
|
51
|
+
online,
|
|
52
|
+
pending = 0,
|
|
53
|
+
syncing = false,
|
|
54
|
+
error,
|
|
55
|
+
}: SyncInput): SyncState {
|
|
56
|
+
if (error) return "error";
|
|
57
|
+
if (!online) return "offline";
|
|
58
|
+
if (syncing) return "syncing";
|
|
59
|
+
if (pending > 0) return "pending";
|
|
60
|
+
return "synced";
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const changes = (n: number) => `${String(n)} ${n === 1 ? "change" : "changes"}`;
|
|
64
|
+
|
|
65
|
+
/** The state as a sentence. Used for the visible text and the announcement. */
|
|
66
|
+
export function describeSyncState(
|
|
67
|
+
state: SyncState,
|
|
68
|
+
pending = 0,
|
|
69
|
+
error?: string | null,
|
|
70
|
+
): string {
|
|
71
|
+
switch (state) {
|
|
72
|
+
case "synced":
|
|
73
|
+
return "All changes saved";
|
|
74
|
+
case "pending":
|
|
75
|
+
return `${changes(pending)} waiting to save`;
|
|
76
|
+
case "syncing":
|
|
77
|
+
return pending > 0 ? `Saving ${changes(pending)}…` : "Saving…";
|
|
78
|
+
case "offline":
|
|
79
|
+
return pending > 0
|
|
80
|
+
? `Offline. ${changes(pending)} will save when you're back online.`
|
|
81
|
+
: "Offline. Changes will save when you're back online.";
|
|
82
|
+
case "error":
|
|
83
|
+
return pending > 0
|
|
84
|
+
? `Could not save ${changes(pending)}. ${error ?? ""}`.trim()
|
|
85
|
+
: `Could not save. ${error ?? ""}`.trim();
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/* The browser's reading of the network, as an external store. The server
|
|
90
|
+
snapshot is "online": a page rendered on the server has no interface to
|
|
91
|
+
report, and rendering "offline" into HTML would be a lie until hydration. */
|
|
92
|
+
function subscribeOnline(callback: () => void) {
|
|
93
|
+
window.addEventListener("online", callback);
|
|
94
|
+
window.addEventListener("offline", callback);
|
|
95
|
+
return () => {
|
|
96
|
+
window.removeEventListener("online", callback);
|
|
97
|
+
window.removeEventListener("offline", callback);
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
const readOnline = () => navigator.onLine;
|
|
101
|
+
const readOnlineOnServer = () => true;
|
|
102
|
+
|
|
103
|
+
/** Whether the browser believes it has a network. False is reliable; true is not. */
|
|
104
|
+
export function useOnlineStatus(): boolean {
|
|
105
|
+
return useSyncExternalStore(subscribeOnline, readOnline, readOnlineOnServer);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export interface SyncStatusProps
|
|
109
|
+
extends Omit<ComponentPropsWithRef<"div">, "children">, Omit<SyncInput, "online"> {
|
|
110
|
+
/** Omit to read the browser's own status. */
|
|
111
|
+
online?: boolean;
|
|
112
|
+
/** When the last save succeeded. Shown as a time, not a relative phrase, so no clock is needed. */
|
|
113
|
+
lastSyncedAt?: Date;
|
|
114
|
+
locale?: string;
|
|
115
|
+
/** Offered when a save failed. */
|
|
116
|
+
onRetry?: () => void;
|
|
117
|
+
/**
|
|
118
|
+
* Announce transitions. On by default, because going offline is the one
|
|
119
|
+
* thing a reader who is typing has to be told; syncing itself never
|
|
120
|
+
* announces, whichever way this is set.
|
|
121
|
+
*/
|
|
122
|
+
announce?: boolean;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export function SyncStatus({
|
|
126
|
+
className,
|
|
127
|
+
online: onlineProp,
|
|
128
|
+
pending = 0,
|
|
129
|
+
syncing = false,
|
|
130
|
+
error,
|
|
131
|
+
lastSyncedAt,
|
|
132
|
+
locale,
|
|
133
|
+
onRetry,
|
|
134
|
+
announce = true,
|
|
135
|
+
...props
|
|
136
|
+
}: SyncStatusProps) {
|
|
137
|
+
const browserOnline = useOnlineStatus();
|
|
138
|
+
const online = onlineProp ?? browserOnline;
|
|
139
|
+
const state = syncState({ online, pending, syncing, error });
|
|
140
|
+
const text = describeSyncState(state, pending, error);
|
|
141
|
+
|
|
142
|
+
// Said once, when the situation changes. Adjusted during render so the
|
|
143
|
+
// announcement lands in the same commit as the state it describes. Syncing
|
|
144
|
+
// and pending are the ordinary churn of saving and are never announced.
|
|
145
|
+
const [seen, setSeen] = useState(state);
|
|
146
|
+
const [announcement, setAnnouncement] = useState("");
|
|
147
|
+
// A failure is over when a save lands, not when the retry starts, so the
|
|
148
|
+
// recovery is remembered across the syncing in between.
|
|
149
|
+
const [recovering, setRecovering] = useState(false);
|
|
150
|
+
if (seen !== state) {
|
|
151
|
+
const from = seen;
|
|
152
|
+
setSeen(state);
|
|
153
|
+
if (state === "offline" || state === "error") {
|
|
154
|
+
setAnnouncement(text);
|
|
155
|
+
setRecovering(false);
|
|
156
|
+
} else if (from === "offline") {
|
|
157
|
+
setAnnouncement(
|
|
158
|
+
pending > 0 ? `Back online. Saving ${changes(pending)}.` : "Back online.",
|
|
159
|
+
);
|
|
160
|
+
} else if ((from === "error" || recovering) && state === "synced") {
|
|
161
|
+
setAnnouncement("Saved.");
|
|
162
|
+
setRecovering(false);
|
|
163
|
+
} else if (from === "error") {
|
|
164
|
+
setRecovering(true);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const savedAt =
|
|
169
|
+
lastSyncedAt !== undefined
|
|
170
|
+
? new Intl.DateTimeFormat(locale, { timeStyle: "short" }).format(lastSyncedAt)
|
|
171
|
+
: null;
|
|
172
|
+
|
|
173
|
+
return (
|
|
174
|
+
<div
|
|
175
|
+
data-slot="sync-status"
|
|
176
|
+
data-state={state}
|
|
177
|
+
className={cn("flex flex-wrap items-center gap-x-2 gap-y-1 text-xs", className)}
|
|
178
|
+
{...props}
|
|
179
|
+
>
|
|
180
|
+
{/* The dot is decoration. The word is the status. */}
|
|
181
|
+
<span
|
|
182
|
+
aria-hidden="true"
|
|
183
|
+
className={cn(
|
|
184
|
+
"size-2 shrink-0 rounded-full",
|
|
185
|
+
state === "synced" && "bg-success",
|
|
186
|
+
state === "pending" && "bg-muted-foreground",
|
|
187
|
+
state === "syncing" && "animate-pulse-soft bg-info",
|
|
188
|
+
state === "offline" && "bg-warning",
|
|
189
|
+
state === "error" && "bg-destructive",
|
|
190
|
+
)}
|
|
191
|
+
/>
|
|
192
|
+
<span
|
|
193
|
+
data-slot="sync-status-text"
|
|
194
|
+
className={cn(
|
|
195
|
+
state === "offline" && "text-warning",
|
|
196
|
+
state === "error" && "text-destructive",
|
|
197
|
+
(state === "synced" || state === "pending" || state === "syncing") &&
|
|
198
|
+
"text-muted-foreground",
|
|
199
|
+
)}
|
|
200
|
+
>
|
|
201
|
+
{text}
|
|
202
|
+
{savedAt && state === "synced" ? ` at ${savedAt}` : null}
|
|
203
|
+
</span>
|
|
204
|
+
|
|
205
|
+
{state === "error" && onRetry ? (
|
|
206
|
+
<Button variant="outline" size="sm" className="h-6 px-2 text-xs" onClick={onRetry}>
|
|
207
|
+
Retry
|
|
208
|
+
</Button>
|
|
209
|
+
) : null}
|
|
210
|
+
|
|
211
|
+
{/* Present from the start, so the first transition is heard. */}
|
|
212
|
+
<span role="status" aria-live={announce ? "polite" : "off"} className="sr-only">
|
|
213
|
+
{announce ? announcement : ""}
|
|
214
|
+
</span>
|
|
215
|
+
</div>
|
|
216
|
+
);
|
|
217
|
+
}
|
|
@@ -98,8 +98,8 @@ export function TableHead({ className, ...props }: ComponentPropsWithRef<"th">)
|
|
|
98
98
|
<th
|
|
99
99
|
data-slot="table-head"
|
|
100
100
|
className={cn(
|
|
101
|
-
"h-10 px-3 text-
|
|
102
|
-
"[&:has([role=checkbox])]:w-px [&:has([role=checkbox])]:
|
|
101
|
+
"h-10 px-3 text-start align-middle text-xs font-medium whitespace-nowrap text-muted-foreground",
|
|
102
|
+
"[&:has([role=checkbox])]:w-px [&:has([role=checkbox])]:pe-0",
|
|
103
103
|
className,
|
|
104
104
|
)}
|
|
105
105
|
{...props}
|
|
@@ -113,7 +113,7 @@ export function TableCell({ className, ...props }: ComponentPropsWithRef<"td">)
|
|
|
113
113
|
data-slot="table-cell"
|
|
114
114
|
className={cn(
|
|
115
115
|
"px-3 py-2.5 align-middle",
|
|
116
|
-
"[&:has([role=checkbox])]:w-px [&:has([role=checkbox])]:
|
|
116
|
+
"[&:has([role=checkbox])]:w-px [&:has([role=checkbox])]:pe-0",
|
|
117
117
|
className,
|
|
118
118
|
)}
|
|
119
119
|
{...props}
|
|
@@ -232,7 +232,7 @@ export function TagsInput({
|
|
|
232
232
|
removeAt(index);
|
|
233
233
|
}}
|
|
234
234
|
className={cn(
|
|
235
|
-
"-
|
|
235
|
+
"-me-0.5 grid size-4 place-items-center rounded-full",
|
|
236
236
|
"transition-colors hover:bg-foreground/10",
|
|
237
237
|
focusRing,
|
|
238
238
|
disabledStyles,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Textarea, textareaVariants, type TextareaProps } from "./textarea";
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { defineMeta } from "@/registry/schema";
|
|
2
|
+
|
|
3
|
+
export const meta = defineMeta({
|
|
4
|
+
name: "textarea",
|
|
5
|
+
title: "Textarea",
|
|
6
|
+
description:
|
|
7
|
+
"A multi-line text field, with optional auto-resize and a character count that knows when to stay quiet.",
|
|
8
|
+
category: "form",
|
|
9
|
+
status: "stable",
|
|
10
|
+
dependencies: ["class-variance-authority"],
|
|
11
|
+
registryDependencies: [],
|
|
12
|
+
files: ["textarea.tsx"],
|
|
13
|
+
a11y:
|
|
14
|
+
"Pair with a Label via htmlFor/id. The error state is driven by aria-invalid, so assistive " +
|
|
15
|
+
"technology and styling stay in sync. The character count is described by the field rather " +
|
|
16
|
+
"than announced on every keystroke — a permanently live counter reads the remaining number " +
|
|
17
|
+
"between every letter typed, which is unusable — so it goes live only once the limit is " +
|
|
18
|
+
"close, and states the remainder in words rather than as a bare ratio that is read aloud as " +
|
|
19
|
+
"two unlabelled numbers. Horizontal resizing is off by default, because a field dragged " +
|
|
20
|
+
"wider than its container is a broken layout.",
|
|
21
|
+
});
|