@forwardreach/saas-ui 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/CHANGELOG.md +75 -0
- package/dist/components/account-menu.d.ts +42 -0
- package/dist/components/account-menu.js +41 -0
- package/dist/components/button.d.ts +1 -1
- package/dist/components/choice-card.d.ts +33 -0
- package/dist/components/choice-card.js +40 -0
- package/dist/components/combobox.d.ts +37 -0
- package/dist/components/combobox.js +103 -0
- package/dist/components/dropdown-menu.d.ts +9 -1
- package/dist/components/dropdown-menu.js +8 -5
- package/dist/components/form-field.d.ts +48 -0
- package/dist/components/form-field.js +51 -0
- package/dist/components/index.d.ts +12 -0
- package/dist/components/index.js +12 -0
- package/dist/components/input.js +2 -1
- package/dist/components/overflow-menu.d.ts +40 -0
- package/dist/components/overflow-menu.js +15 -0
- package/dist/components/rail-toggle.d.ts +19 -0
- package/dist/components/rail-toggle.js +17 -0
- package/dist/components/select.d.ts +9 -0
- package/dist/components/select.js +12 -0
- package/dist/components/settings-layout.d.ts +10 -0
- package/dist/components/settings-layout.js +10 -0
- package/dist/components/settings-nav.d.ts +46 -0
- package/dist/components/settings-nav.js +21 -0
- package/dist/components/switch.d.ts +20 -0
- package/dist/components/switch.js +28 -0
- package/dist/components/textarea.js +2 -1
- package/dist/components/time-zone-field.d.ts +30 -0
- package/dist/components/time-zone-field.js +72 -0
- package/dist/components/workspace-switcher.d.ts +33 -0
- package/dist/components/workspace-switcher.js +34 -0
- package/dist/styles/index.css +3 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/time-zones.d.ts +26 -0
- package/dist/utils/time-zones.js +79 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,80 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.7.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Add the settings shell and form primitive kit:
|
|
8
|
+
|
|
9
|
+
- `SettingsLayout` / `SettingsNav` — centered max-width settings shell with a
|
|
10
|
+
grouped, icon-capable sidebar nav (horizontal-scroll row on small screens).
|
|
11
|
+
Router-agnostic: active state comes from `activeHref` or an `isActive`
|
|
12
|
+
predicate and links render through an injectable `linkComponent`.
|
|
13
|
+
- `FormField` — label/description/control/error wrapper that generates and
|
|
14
|
+
threads `id`/`aria-describedby`/`aria-invalid` to package controls via
|
|
15
|
+
context; `Input`, `Textarea`, `Select`, `Switch`, and `Combobox` participate.
|
|
16
|
+
- `Select` — native select styled to match `Input`, with chevron.
|
|
17
|
+
- `Switch` — `role="switch"` toggle themed by new optional
|
|
18
|
+
`--ssui-switch-track` / `--ssui-switch-track-checked` / `--ssui-switch-thumb`
|
|
19
|
+
tokens (neutral fallbacks); optional form participation via `name`.
|
|
20
|
+
- `ChoiceCardGroup` / `ChoiceCard` — radio group rendered as selectable
|
|
21
|
+
bordered cards over native radios.
|
|
22
|
+
- `Combobox` — filterable single-select with WAI-ARIA combobox semantics,
|
|
23
|
+
wrap-around active-option keyboard navigation, and Enter-commit of the
|
|
24
|
+
highlighted option.
|
|
25
|
+
- `TimeZoneField` — auto/fixed time-zone composite (detected zone shown in
|
|
26
|
+
the auto card, zone combobox with offset-aware search in fixed mode) that
|
|
27
|
+
submits `timeZoneMode`/`timeZone`/`browserTimeZone` hidden inputs.
|
|
28
|
+
- Time-zone utilities (`timeZoneOptions`, `formatTimeZoneOffset`,
|
|
29
|
+
`detectBrowserTimeZone`, `COMMON_TIME_ZONES`) exported for server-side reuse.
|
|
30
|
+
|
|
31
|
+
## 0.6.0
|
|
32
|
+
|
|
33
|
+
### Minor Changes
|
|
34
|
+
|
|
35
|
+
- Add `RailToggle` (icon-only rail collapse/expand toggle with tooltip + shortcut hint, presentational) and polish `WorkspaceSwitcher`/`AccountMenu` popup presentation: 10px side offset, panel min-width tied to the trigger width, and trigger chevrons that rotate while the menu is open.
|
|
36
|
+
|
|
37
|
+
- Add `AccountMenu` and `WorkspaceSwitcher` — the shared app-shell menu pair.
|
|
38
|
+
|
|
39
|
+
`AccountMenu` is the bottom-left identity menu: a full-width account card
|
|
40
|
+
trigger (avatar, name, email, chevron-up; avatar-only with a name tooltip when
|
|
41
|
+
`collapsed`) opening a Radix menu with a fixed anatomy — identity header,
|
|
42
|
+
optional theme selector row, consumer-provided items (`AccountMenuItem`), then
|
|
43
|
+
a separated Sign out. The theme row is a segmented `menuitemradio` control
|
|
44
|
+
(Sun/Moon/Monitor) that supports both two-option (light/dark) and three-option
|
|
45
|
+
(light/dark/system) configurations and keeps the menu open on selection.
|
|
46
|
+
|
|
47
|
+
`WorkspaceSwitcher` is the top-left workspace context menu: a brand badge +
|
|
48
|
+
active workspace name + chevron-down trigger (badge-only with a tooltip when
|
|
49
|
+
`collapsed`) opening a list of workspaces with the active row checked and not
|
|
50
|
+
re-selectable, plus an optional separated "New workspace" action. Selection is
|
|
51
|
+
callback-based (`onSelect(id)`).
|
|
52
|
+
|
|
53
|
+
Both components support the collapsed icon-rail state (menus open to the
|
|
54
|
+
right) and wrap their tooltips in a local `TooltipProvider`, so consumers need
|
|
55
|
+
no extra setup.
|
|
56
|
+
|
|
57
|
+
## 0.5.0
|
|
58
|
+
|
|
59
|
+
### Minor Changes
|
|
60
|
+
|
|
61
|
+
- 523e143: Add `OverflowMenu` — a "⋯" icon-button that opens a dropdown of low-frequency,
|
|
62
|
+
whole-object actions, composed from the existing Radix `DropdownMenu` primitives.
|
|
63
|
+
Panel contents are composed with the exported `OverflowMenuItem` and
|
|
64
|
+
`OverflowMenuSeparator` aliases.
|
|
65
|
+
|
|
66
|
+
Menu-item highlight (hover/keyboard) now uses the translucent
|
|
67
|
+
`--ssui-overlay-hover` token instead of `--ssui-surface-muted`, and also styles
|
|
68
|
+
Radix's `data-highlighted` state. Solid `surface-muted` was invisible on themes
|
|
69
|
+
where it matches `surface-elevated` (the panel background); a translucent
|
|
70
|
+
overlay reads on any surface.
|
|
71
|
+
|
|
72
|
+
`DropdownMenuContent` (and `OverflowMenu`) also accept a new `portal` prop.
|
|
73
|
+
It defaults to `true`, preserving today's portal-to-`document.body` behavior;
|
|
74
|
+
pass `false` to render the panel inline next to the trigger, which keeps it
|
|
75
|
+
inside the trigger's DOM subtree — needed when the menu lives in a surface that
|
|
76
|
+
tracks focus, such as a click-to-edit editor that persists on blur.
|
|
77
|
+
|
|
3
78
|
## 0.4.0
|
|
4
79
|
|
|
5
80
|
### Minor Changes
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
export type AccountMenuThemeValue = "light" | "dark" | "system";
|
|
3
|
+
export interface AccountMenuTheme {
|
|
4
|
+
/** Currently active theme. */
|
|
5
|
+
value: AccountMenuThemeValue;
|
|
6
|
+
/** Which options to offer. Defaults to all three (light/dark/system). */
|
|
7
|
+
options?: ReadonlyArray<AccountMenuThemeValue>;
|
|
8
|
+
onChange: (value: AccountMenuThemeValue) => void;
|
|
9
|
+
}
|
|
10
|
+
export interface AccountMenuProps {
|
|
11
|
+
name: string;
|
|
12
|
+
email?: string;
|
|
13
|
+
/** Avatar image URL; initials fall back from `name`. */
|
|
14
|
+
image?: string | null;
|
|
15
|
+
/** Icon-only rail state: avatar-only trigger with a name tooltip, menu opens right. */
|
|
16
|
+
collapsed?: boolean;
|
|
17
|
+
/** Omit to hide the theme row entirely. */
|
|
18
|
+
theme?: AccountMenuTheme;
|
|
19
|
+
/** Label for the theme row. Defaults to "Theme". */
|
|
20
|
+
themeLabel?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Consumer menu entries (e.g. a Settings link), rendered between the theme
|
|
23
|
+
* row and the separated Sign out item. Use `AccountMenuItem`s.
|
|
24
|
+
*/
|
|
25
|
+
children?: React.ReactNode;
|
|
26
|
+
onSignOut: () => void | Promise<void>;
|
|
27
|
+
/** Defaults to "Sign out". */
|
|
28
|
+
signOutLabel?: string;
|
|
29
|
+
/** Open the menu by default (uncontrolled). Mainly useful in tests. */
|
|
30
|
+
defaultOpen?: boolean;
|
|
31
|
+
/** Extra classes for the trigger card. */
|
|
32
|
+
className?: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Bottom-left identity menu for the app shell: a full-width account card
|
|
36
|
+
* (avatar, name, email, chevron-up) opening a menu with a fixed anatomy —
|
|
37
|
+
* identity header, optional theme selector row, consumer items, then a
|
|
38
|
+
* separated Sign out. Workspace switching deliberately does not belong here;
|
|
39
|
+
* that's the top-left `WorkspaceSwitcher`.
|
|
40
|
+
*/
|
|
41
|
+
export declare function AccountMenu({ name, email, image, collapsed, theme, themeLabel, children, onSignOut, signOutLabel, defaultOpen, className, }: AccountMenuProps): import("react/jsx-runtime").JSX.Element;
|
|
42
|
+
export { DropdownMenuItem as AccountMenuItem, DropdownMenuSeparator as AccountMenuSeparator, } from "./dropdown-menu.js";
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu";
|
|
4
|
+
import { ChevronUp, LogOut, Monitor, Moon, Sun } from "lucide-react";
|
|
5
|
+
import * as React from "react";
|
|
6
|
+
import { cn } from "../utils/cn.js";
|
|
7
|
+
import { Avatar } from "./avatar.js";
|
|
8
|
+
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuRadioGroup, DropdownMenuSeparator, DropdownMenuTrigger, } from "./dropdown-menu.js";
|
|
9
|
+
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "./tooltip.js";
|
|
10
|
+
const THEME_OPTION_META = {
|
|
11
|
+
light: { icon: Sun, label: "Light" },
|
|
12
|
+
dark: { icon: Moon, label: "Dark" },
|
|
13
|
+
system: { icon: Monitor, label: "System" },
|
|
14
|
+
};
|
|
15
|
+
const ALL_THEME_OPTIONS = ["light", "dark", "system"];
|
|
16
|
+
/**
|
|
17
|
+
* Bottom-left identity menu for the app shell: a full-width account card
|
|
18
|
+
* (avatar, name, email, chevron-up) opening a menu with a fixed anatomy —
|
|
19
|
+
* identity header, optional theme selector row, consumer items, then a
|
|
20
|
+
* separated Sign out. Workspace switching deliberately does not belong here;
|
|
21
|
+
* that's the top-left `WorkspaceSwitcher`.
|
|
22
|
+
*/
|
|
23
|
+
export function AccountMenu({ name, email, image, collapsed = false, theme, themeLabel = "Theme", children, onSignOut, signOutLabel = "Sign out", defaultOpen, className, }) {
|
|
24
|
+
const themeOptions = theme?.options ?? ALL_THEME_OPTIONS;
|
|
25
|
+
// Mirror open state for the chevron cue: the trigger's data-state is
|
|
26
|
+
// unreliable here because TooltipTrigger's own data-state wins the
|
|
27
|
+
// asChild prop merge over DropdownMenuTrigger's.
|
|
28
|
+
const [open, setOpen] = React.useState(defaultOpen ?? false);
|
|
29
|
+
return (_jsxs(DropdownMenu, { open: open, onOpenChange: setOpen, children: [_jsx(TooltipProvider, { delayDuration: 300, children: _jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { asChild: true, children: _jsx(DropdownMenuTrigger, { asChild: true, children: _jsxs("button", { type: "button", "aria-label": collapsed ? name : "Account", className: cn("flex h-10 w-full items-center gap-2 rounded-[var(--ssui-radius)] px-1.5 text-left outline-none transition-colors hover:bg-[color:var(--ssui-overlay-hover)] focus-visible:ring-2 focus-visible:ring-[color:var(--ssui-focus-ring)]", collapsed
|
|
30
|
+
? // Collapsed = avatar-only: the text column/chevron are omitted
|
|
31
|
+
// from the layout entirely (not just faded) so the trigger
|
|
32
|
+
// truly fits an icon rail instead of relying on clipping.
|
|
33
|
+
"justify-center px-0"
|
|
34
|
+
: "border border-[color:var(--ssui-border)] bg-[color:var(--ssui-surface)]", className), children: [_jsx(Avatar, { className: "shrink-0", name: name, size: 28, src: image }), !collapsed && (_jsxs(_Fragment, { children: [_jsxs("span", { className: "flex min-w-0 flex-1 flex-col", children: [_jsx("span", { className: "truncate text-[13px] font-medium leading-tight text-[color:var(--ssui-text)]", children: name }), email ? (_jsx("span", { className: "truncate text-[11px] leading-tight text-[color:var(--ssui-text-muted)]", children: email })) : null] }), _jsx(ChevronUp, { className: cn("size-4 shrink-0 text-[color:var(--ssui-text-subtle)] transition-transform duration-150", open && "rotate-180") })] }))] }) }) }), collapsed ? _jsx(TooltipContent, { side: "right", children: name }) : null] }) }), _jsxs(DropdownMenuContent, { align: collapsed ? "end" : "start", className: "w-60 min-w-[var(--radix-dropdown-menu-trigger-width)]", side: collapsed ? "right" : "top", sideOffset: 10, children: [_jsx(DropdownMenuLabel, { children: _jsxs("span", { className: "flex min-w-0 flex-col gap-0.5", children: [_jsx("span", { className: "truncate text-sm font-medium text-[color:var(--ssui-text)]", children: name }), email ? (_jsx("span", { className: "truncate text-xs font-normal text-[color:var(--ssui-text-muted)]", children: email })) : null] }) }), _jsx(DropdownMenuSeparator, {}), theme ? (_jsx(DropdownMenuRadioGroup, { value: theme.value, onValueChange: (value) => theme.onChange(value), children: _jsxs("div", { className: "flex items-center justify-between gap-2 px-2 py-1.5", children: [_jsx("span", { className: "text-xs text-[color:var(--ssui-text-muted)]", children: themeLabel }), _jsx("div", { className: "flex gap-0.5 rounded-[var(--ssui-radius-sm)] border border-[color:var(--ssui-border)] p-0.5", children: themeOptions.map((option) => {
|
|
35
|
+
const { icon: Icon, label } = THEME_OPTION_META[option];
|
|
36
|
+
return (_jsx(DropdownMenuPrimitive.RadioItem, { "aria-label": label, className: "flex size-7 cursor-default select-none items-center justify-center rounded-[calc(var(--ssui-radius-sm)-1px)] text-[color:var(--ssui-text-muted)] outline-none transition-colors focus:bg-[color:var(--ssui-overlay-hover)] data-[highlighted]:bg-[color:var(--ssui-overlay-hover)] data-[state=checked]:bg-[color:var(--ssui-overlay-hover)] data-[state=checked]:text-[color:var(--ssui-text)]",
|
|
37
|
+
// Keep the menu open: theme picking is a tweak-and-compare loop.
|
|
38
|
+
onSelect: (event) => event.preventDefault(), title: label, value: option, children: _jsx(Icon, { className: "size-4" }) }, option));
|
|
39
|
+
}) })] }) })) : null, children, theme || children ? _jsx(DropdownMenuSeparator, {}) : null, _jsxs(DropdownMenuItem, { onSelect: () => void onSignOut(), children: [_jsx(LogOut, { className: "size-4 text-[color:var(--ssui-text-muted)]" }), signOutLabel] })] })] }));
|
|
40
|
+
}
|
|
41
|
+
export { DropdownMenuItem as AccountMenuItem, DropdownMenuSeparator as AccountMenuSeparator, } from "./dropdown-menu.js";
|
|
@@ -2,7 +2,7 @@ import { type VariantProps } from "class-variance-authority";
|
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
export declare const buttonVariants: (props?: ({
|
|
4
4
|
variant?: "link" | "primary" | "outline" | "secondary" | "ghost" | "ghost-accent" | "destructive" | null | undefined;
|
|
5
|
-
size?: "
|
|
5
|
+
size?: "sm" | "md" | "lg" | "icon" | "icon-sm" | "icon-lg" | null | undefined;
|
|
6
6
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
7
7
|
export interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement>, VariantProps<typeof buttonVariants> {
|
|
8
8
|
asChild?: boolean;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
export interface ChoiceCardGroupProps extends Omit<React.HTMLAttributes<HTMLDivElement>, "onChange"> {
|
|
3
|
+
/** Form field name shared by the underlying radios. */
|
|
4
|
+
name?: string;
|
|
5
|
+
/** Controlled selected value. */
|
|
6
|
+
value?: string;
|
|
7
|
+
/** Uncontrolled initial value. */
|
|
8
|
+
defaultValue?: string;
|
|
9
|
+
onValueChange?: (value: string) => void;
|
|
10
|
+
/** Accessible label for the radio group. */
|
|
11
|
+
"aria-label"?: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Radio group rendered as selectable bordered cards. Uses native radio
|
|
15
|
+
* inputs, so form participation and arrow-key navigation between cards come
|
|
16
|
+
* from the browser. Children are `ChoiceCard`s.
|
|
17
|
+
*/
|
|
18
|
+
export declare function ChoiceCardGroup({ name, value, defaultValue, onValueChange, className, children, ...props }: ChoiceCardGroupProps): import("react/jsx-runtime").JSX.Element;
|
|
19
|
+
export interface ChoiceCardProps extends Omit<React.LabelHTMLAttributes<HTMLLabelElement>, "title"> {
|
|
20
|
+
/** Value submitted when this card is selected. */
|
|
21
|
+
value: string;
|
|
22
|
+
/** Card title. */
|
|
23
|
+
title: React.ReactNode;
|
|
24
|
+
/** Optional supporting copy under the title. */
|
|
25
|
+
description?: React.ReactNode;
|
|
26
|
+
disabled?: boolean;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* One selectable card inside a `ChoiceCardGroup`: a bordered label wrapping a
|
|
30
|
+
* native radio plus title and supporting text. The selected card gets the
|
|
31
|
+
* emphasized border and muted fill.
|
|
32
|
+
*/
|
|
33
|
+
export declare function ChoiceCard({ value, title, description, disabled, className, children, ...props }: ChoiceCardProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { cn } from "../utils/cn.js";
|
|
5
|
+
const ChoiceCardGroupContext = React.createContext(null);
|
|
6
|
+
/**
|
|
7
|
+
* Radio group rendered as selectable bordered cards. Uses native radio
|
|
8
|
+
* inputs, so form participation and arrow-key navigation between cards come
|
|
9
|
+
* from the browser. Children are `ChoiceCard`s.
|
|
10
|
+
*/
|
|
11
|
+
export function ChoiceCardGroup({ name, value, defaultValue, onValueChange, className, children, ...props }) {
|
|
12
|
+
const generatedName = React.useId();
|
|
13
|
+
const [uncontrolledValue, setUncontrolledValue] = React.useState(defaultValue);
|
|
14
|
+
const selected = value ?? uncontrolledValue;
|
|
15
|
+
const contextValue = React.useMemo(() => ({
|
|
16
|
+
name: name ?? generatedName,
|
|
17
|
+
value: selected,
|
|
18
|
+
setValue: (next) => {
|
|
19
|
+
if (value === undefined)
|
|
20
|
+
setUncontrolledValue(next);
|
|
21
|
+
onValueChange?.(next);
|
|
22
|
+
},
|
|
23
|
+
}), [name, generatedName, selected, value, onValueChange]);
|
|
24
|
+
return (_jsx("div", { role: "radiogroup", className: cn("grid gap-2 md:grid-cols-2", className), ...props, children: _jsx(ChoiceCardGroupContext.Provider, { value: contextValue, children: children }) }));
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* One selectable card inside a `ChoiceCardGroup`: a bordered label wrapping a
|
|
28
|
+
* native radio plus title and supporting text. The selected card gets the
|
|
29
|
+
* emphasized border and muted fill.
|
|
30
|
+
*/
|
|
31
|
+
export function ChoiceCard({ value, title, description, disabled, className, children, ...props }) {
|
|
32
|
+
const group = React.useContext(ChoiceCardGroupContext);
|
|
33
|
+
if (!group) {
|
|
34
|
+
throw new Error("ChoiceCard must be rendered inside a ChoiceCardGroup");
|
|
35
|
+
}
|
|
36
|
+
const selected = group.value === value;
|
|
37
|
+
return (_jsxs("label", { className: cn("flex cursor-pointer gap-2 rounded-[var(--ssui-radius)] border px-3 py-2 transition-colors has-[:focus-visible]:ring-2 has-[:focus-visible]:ring-[color:var(--ssui-focus-ring)]", selected
|
|
38
|
+
? "border-[color:var(--ssui-border-strong)] bg-[color:var(--ssui-surface-muted)] text-[color:var(--ssui-text)]"
|
|
39
|
+
: "border-[color:var(--ssui-border)] text-[color:var(--ssui-text-muted)] hover:bg-[color:var(--ssui-overlay-hover)]", disabled && "cursor-not-allowed opacity-50", className), ...props, children: [_jsx("input", { checked: selected, className: "mt-0.5 size-4 shrink-0 accent-current focus-visible:outline-none", disabled: disabled, name: group.name, onChange: () => group.setValue(value), type: "radio", value: value }), _jsxs("span", { className: "min-w-0", children: [_jsx("span", { className: "block text-sm font-medium", children: title }), description ? (_jsx("span", { className: "block text-xs text-[color:var(--ssui-text-subtle)]", children: description })) : null, children] })] }));
|
|
40
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
export interface ComboboxOption {
|
|
3
|
+
value: string;
|
|
4
|
+
label: string;
|
|
5
|
+
/** Optional trailing content (e.g. a GMT offset) shown right-aligned. */
|
|
6
|
+
trailing?: React.ReactNode;
|
|
7
|
+
}
|
|
8
|
+
export interface ComboboxProps {
|
|
9
|
+
/** Full option list; the component filters it against the typed query. */
|
|
10
|
+
options: ComboboxOption[];
|
|
11
|
+
/** Selected option value. */
|
|
12
|
+
value?: string;
|
|
13
|
+
onValueChange?: (value: string) => void;
|
|
14
|
+
/**
|
|
15
|
+
* Filter predicate; defaults to case-insensitive substring match on the
|
|
16
|
+
* option label and value with spaces treated as underscores.
|
|
17
|
+
*/
|
|
18
|
+
filter?: (option: ComboboxOption, query: string) => boolean;
|
|
19
|
+
placeholder?: string;
|
|
20
|
+
disabled?: boolean;
|
|
21
|
+
/** Message shown when no option matches. Defaults to "No matches". */
|
|
22
|
+
emptyMessage?: React.ReactNode;
|
|
23
|
+
id?: string;
|
|
24
|
+
name?: string;
|
|
25
|
+
"aria-label"?: string;
|
|
26
|
+
"aria-describedby"?: string;
|
|
27
|
+
"aria-invalid"?: React.AriaAttributes["aria-invalid"];
|
|
28
|
+
className?: string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Filterable single-select following the WAI-ARIA combobox pattern: a text
|
|
32
|
+
* input filtering a listbox popup. ArrowUp/ArrowDown move the active-option
|
|
33
|
+
* highlight with wrap-around and scroll-into-view, Enter commits the active
|
|
34
|
+
* option, Escape closes, and losing focus closes without committing a
|
|
35
|
+
* partial value. Selection submits via a hidden input when `name` is set.
|
|
36
|
+
*/
|
|
37
|
+
export declare const Combobox: React.ForwardRefExoticComponent<ComboboxProps & React.RefAttributes<HTMLInputElement>>;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { ChevronDown } from "lucide-react";
|
|
4
|
+
import * as React from "react";
|
|
5
|
+
import { cn } from "../utils/cn.js";
|
|
6
|
+
import { useFormFieldProps } from "./form-field.js";
|
|
7
|
+
function defaultFilter(option, query) {
|
|
8
|
+
const normalized = query.trim().toLowerCase().replaceAll(" ", "_");
|
|
9
|
+
if (!normalized)
|
|
10
|
+
return true;
|
|
11
|
+
return (option.value.toLowerCase().includes(normalized) ||
|
|
12
|
+
option.label.toLowerCase().replaceAll(" ", "_").includes(normalized));
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Filterable single-select following the WAI-ARIA combobox pattern: a text
|
|
16
|
+
* input filtering a listbox popup. ArrowUp/ArrowDown move the active-option
|
|
17
|
+
* highlight with wrap-around and scroll-into-view, Enter commits the active
|
|
18
|
+
* option, Escape closes, and losing focus closes without committing a
|
|
19
|
+
* partial value. Selection submits via a hidden input when `name` is set.
|
|
20
|
+
*/
|
|
21
|
+
export const Combobox = React.forwardRef(({ options, value, onValueChange, filter = defaultFilter, placeholder, disabled, emptyMessage = "No matches", className, name, ...ariaProps }, ref) => {
|
|
22
|
+
const fieldProps = useFormFieldProps(ariaProps);
|
|
23
|
+
const generatedId = React.useId();
|
|
24
|
+
const id = fieldProps.id ?? generatedId;
|
|
25
|
+
const listboxId = `${id}-listbox`;
|
|
26
|
+
const [open, setOpen] = React.useState(false);
|
|
27
|
+
const [query, setQuery] = React.useState(null);
|
|
28
|
+
const [activeIndex, setActiveIndex] = React.useState(-1);
|
|
29
|
+
const listRef = React.useRef(null);
|
|
30
|
+
const selectedOption = options.find((option) => option.value === value);
|
|
31
|
+
const filtered = query === null
|
|
32
|
+
? options
|
|
33
|
+
: options.filter((option) => filter(option, query));
|
|
34
|
+
const inputValue = query ?? selectedOption?.label ?? "";
|
|
35
|
+
const activeOption = activeIndex >= 0 ? filtered[activeIndex] : undefined;
|
|
36
|
+
function openList() {
|
|
37
|
+
setOpen(true);
|
|
38
|
+
setActiveIndex(-1);
|
|
39
|
+
}
|
|
40
|
+
function close() {
|
|
41
|
+
setOpen(false);
|
|
42
|
+
setQuery(null);
|
|
43
|
+
setActiveIndex(-1);
|
|
44
|
+
}
|
|
45
|
+
function commit(option) {
|
|
46
|
+
onValueChange?.(option.value);
|
|
47
|
+
close();
|
|
48
|
+
}
|
|
49
|
+
function moveActive(delta) {
|
|
50
|
+
if (filtered.length === 0)
|
|
51
|
+
return;
|
|
52
|
+
const next = activeIndex < 0
|
|
53
|
+
? delta === 1
|
|
54
|
+
? 0
|
|
55
|
+
: filtered.length - 1
|
|
56
|
+
: (activeIndex + delta + filtered.length) % filtered.length;
|
|
57
|
+
setActiveIndex(next);
|
|
58
|
+
listRef.current
|
|
59
|
+
?.querySelector(`[data-index="${next}"]`)
|
|
60
|
+
?.scrollIntoView({ block: "nearest" });
|
|
61
|
+
}
|
|
62
|
+
function handleKeyDown(event) {
|
|
63
|
+
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
64
|
+
event.preventDefault();
|
|
65
|
+
if (!open) {
|
|
66
|
+
openList();
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
moveActive(event.key === "ArrowDown" ? 1 : -1);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
if (event.key === "Enter") {
|
|
73
|
+
if (open && activeOption) {
|
|
74
|
+
event.preventDefault();
|
|
75
|
+
commit(activeOption);
|
|
76
|
+
}
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (event.key === "Escape") {
|
|
80
|
+
if (open) {
|
|
81
|
+
event.stopPropagation();
|
|
82
|
+
close();
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return (_jsxs("div", { className: cn("relative", className), onBlur: (event) => {
|
|
87
|
+
if (!event.currentTarget.contains(event.relatedTarget)) {
|
|
88
|
+
close();
|
|
89
|
+
}
|
|
90
|
+
}, children: [_jsx("input", { ...fieldProps, ref: ref, id: id, role: "combobox", type: "text", "aria-autocomplete": "list", "aria-controls": listboxId, "aria-expanded": open, "aria-haspopup": "listbox", "aria-activedescendant": open && activeOption ? `${id}-option-${activeOption.value}` : undefined, autoComplete: "off", className: "flex h-10 w-full rounded-[var(--ssui-radius)] border border-[color:var(--ssui-border)] bg-[color:var(--ssui-surface)] py-2 pl-3 pr-9 text-sm text-[color:var(--ssui-text)] shadow-sm transition-colors placeholder:text-[color:var(--ssui-text-subtle)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[color:var(--ssui-focus-ring)] focus-visible:ring-offset-2 focus-visible:ring-offset-[color:var(--ssui-bg)] disabled:cursor-not-allowed disabled:bg-[color:var(--ssui-surface-muted)] disabled:opacity-70", disabled: disabled, onChange: (event) => {
|
|
91
|
+
setQuery(event.target.value);
|
|
92
|
+
setOpen(true);
|
|
93
|
+
setActiveIndex(-1);
|
|
94
|
+
}, onFocus: openList, onKeyDown: handleKeyDown, placeholder: placeholder, value: inputValue }), _jsx("button", { "aria-label": "Show options", className: "absolute right-1 top-1 grid size-8 place-items-center rounded-[var(--ssui-radius-sm)] text-[color:var(--ssui-text-subtle)] transition-colors hover:bg-[color:var(--ssui-overlay-hover)] hover:text-[color:var(--ssui-text)] disabled:pointer-events-none disabled:opacity-50", disabled: disabled, onClick: () => {
|
|
95
|
+
setQuery(null);
|
|
96
|
+
openList();
|
|
97
|
+
document.getElementById(id)?.focus();
|
|
98
|
+
}, tabIndex: -1, type: "button", children: _jsx(ChevronDown, { "aria-hidden": "true", className: "size-4" }) }), name ? _jsx("input", { name: name, type: "hidden", value: value ?? "" }) : null, open ? (_jsx("div", { className: "absolute z-50 mt-1 max-h-64 w-full overflow-y-auto rounded-[var(--ssui-radius)] border border-[color:var(--ssui-border)] bg-[color:var(--ssui-surface-elevated)] p-1 shadow-[var(--ssui-shadow-md)]", id: listboxId, ref: listRef, role: "listbox", children: filtered.length > 0 ? (filtered.map((option, index) => (_jsxs("button", { "aria-selected": option.value === value, className: cn("flex w-full items-center justify-between gap-3 rounded-[var(--ssui-radius-sm)] px-2 py-1.5 text-left text-sm transition-colors", index === activeIndex &&
|
|
99
|
+
"bg-[color:var(--ssui-overlay-hover)]", option.value === value
|
|
100
|
+
? "bg-[color:var(--ssui-surface-muted)] text-[color:var(--ssui-text)]"
|
|
101
|
+
: "text-[color:var(--ssui-text-muted)] hover:bg-[color:var(--ssui-overlay-hover)]"), "data-index": index, id: `${id}-option-${option.value}`, onClick: () => commit(option), onMouseDown: (event) => event.preventDefault(), onMouseMove: () => setActiveIndex(index), role: "option", tabIndex: -1, type: "button", children: [_jsx("span", { className: "truncate", children: option.label }), option.trailing !== undefined ? (_jsx("span", { className: "shrink-0 font-mono text-xs text-[color:var(--ssui-text-subtle)]", children: option.trailing })) : null] }, option.value)))) : (_jsx("div", { className: "px-2 py-1.5 text-sm text-[color:var(--ssui-text-subtle)]", children: emptyMessage })) })) : null] }));
|
|
102
|
+
});
|
|
103
|
+
Combobox.displayName = "Combobox";
|
|
@@ -10,7 +10,15 @@ export declare const DropdownMenuSubTrigger: React.ForwardRefExoticComponent<Omi
|
|
|
10
10
|
inset?: boolean;
|
|
11
11
|
} & React.RefAttributes<HTMLDivElement>>;
|
|
12
12
|
export declare const DropdownMenuSubContent: React.ForwardRefExoticComponent<Omit<DropdownMenuPrimitive.DropdownMenuSubContentProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
13
|
-
export declare const DropdownMenuContent: React.ForwardRefExoticComponent<Omit<DropdownMenuPrimitive.DropdownMenuContentProps & React.RefAttributes<HTMLDivElement>, "ref"> &
|
|
13
|
+
export declare const DropdownMenuContent: React.ForwardRefExoticComponent<Omit<DropdownMenuPrimitive.DropdownMenuContentProps & React.RefAttributes<HTMLDivElement>, "ref"> & {
|
|
14
|
+
/**
|
|
15
|
+
* Render the panel through a portal to `document.body` (the default). Pass
|
|
16
|
+
* `false` to render it inline, next to the trigger — useful when the menu
|
|
17
|
+
* lives inside a subtree that tracks focus (e.g. a click-to-edit editor that
|
|
18
|
+
* persists on blur) and must keep the open panel within its own DOM.
|
|
19
|
+
*/
|
|
20
|
+
portal?: boolean;
|
|
21
|
+
} & React.RefAttributes<HTMLDivElement>>;
|
|
14
22
|
export declare const DropdownMenuItem: React.ForwardRefExoticComponent<Omit<DropdownMenuPrimitive.DropdownMenuItemProps & React.RefAttributes<HTMLDivElement>, "ref"> & {
|
|
15
23
|
inset?: boolean;
|
|
16
24
|
} & React.RefAttributes<HTMLDivElement>>;
|
|
@@ -9,17 +9,20 @@ export const DropdownMenuGroup = DropdownMenuPrimitive.Group;
|
|
|
9
9
|
export const DropdownMenuPortal = DropdownMenuPrimitive.Portal;
|
|
10
10
|
export const DropdownMenuSub = DropdownMenuPrimitive.Sub;
|
|
11
11
|
export const DropdownMenuRadioGroup = DropdownMenuPrimitive.RadioGroup;
|
|
12
|
-
export const DropdownMenuSubTrigger = React.forwardRef(({ children, className, inset, ...props }, ref) => (_jsxs(DropdownMenuPrimitive.SubTrigger, { ref: ref, className: cn("flex cursor-default select-none items-center rounded-[var(--ssui-radius-sm)] px-2 py-1.5 text-sm text-[color:var(--ssui-text)] outline-none focus:bg-[color:var(--ssui-
|
|
12
|
+
export const DropdownMenuSubTrigger = React.forwardRef(({ children, className, inset, ...props }, ref) => (_jsxs(DropdownMenuPrimitive.SubTrigger, { ref: ref, className: cn("flex cursor-default select-none items-center rounded-[var(--ssui-radius-sm)] px-2 py-1.5 text-sm text-[color:var(--ssui-text)] outline-none focus:bg-[color:var(--ssui-overlay-hover)] data-[highlighted]:bg-[color:var(--ssui-overlay-hover)] data-[state=open]:bg-[color:var(--ssui-overlay-hover)]", inset && "pl-8", className), ...props, children: [children, _jsx(ChevronRight, { className: "ml-auto size-4" })] })));
|
|
13
13
|
DropdownMenuSubTrigger.displayName = DropdownMenuPrimitive.SubTrigger.displayName;
|
|
14
14
|
export const DropdownMenuSubContent = React.forwardRef(({ className, ...props }, ref) => (_jsx(DropdownMenuPrimitive.SubContent, { ref: ref, className: cn("z-50 min-w-40 overflow-hidden rounded-[var(--ssui-radius)] border border-[color:var(--ssui-border)] bg-[color:var(--ssui-surface-elevated)] p-1 text-[color:var(--ssui-text)] shadow-[var(--ssui-shadow-md)]", className), ...props })));
|
|
15
15
|
DropdownMenuSubContent.displayName = DropdownMenuPrimitive.SubContent.displayName;
|
|
16
|
-
export const DropdownMenuContent = React.forwardRef(({ className, sideOffset = 6, ...props }, ref) =>
|
|
16
|
+
export const DropdownMenuContent = React.forwardRef(({ className, portal = true, sideOffset = 6, ...props }, ref) => {
|
|
17
|
+
const content = (_jsx(DropdownMenuPrimitive.Content, { ref: ref, sideOffset: sideOffset, className: cn("z-50 min-w-44 overflow-hidden rounded-[var(--ssui-radius)] border border-[color:var(--ssui-border)] bg-[color:var(--ssui-surface-elevated)] p-1 text-[color:var(--ssui-text)] shadow-[var(--ssui-shadow-md)]", className), ...props }));
|
|
18
|
+
return portal ? _jsx(DropdownMenuPrimitive.Portal, { children: content }) : content;
|
|
19
|
+
});
|
|
17
20
|
DropdownMenuContent.displayName = DropdownMenuPrimitive.Content.displayName;
|
|
18
|
-
export const DropdownMenuItem = React.forwardRef(({ className, inset, ...props }, ref) => (_jsx(DropdownMenuPrimitive.Item, { ref: ref, className: cn("relative flex cursor-default select-none items-center gap-2 rounded-[var(--ssui-radius-sm)] px-2 py-1.5 text-sm outline-none transition-colors focus:bg-[color:var(--ssui-
|
|
21
|
+
export const DropdownMenuItem = React.forwardRef(({ className, inset, ...props }, ref) => (_jsx(DropdownMenuPrimitive.Item, { ref: ref, className: cn("relative flex cursor-default select-none items-center gap-2 rounded-[var(--ssui-radius-sm)] px-2 py-1.5 text-sm outline-none transition-colors focus:bg-[color:var(--ssui-overlay-hover)] data-[highlighted]:bg-[color:var(--ssui-overlay-hover)] data-[disabled]:pointer-events-none data-[disabled]:opacity-50", inset && "pl-8", className), ...props })));
|
|
19
22
|
DropdownMenuItem.displayName = DropdownMenuPrimitive.Item.displayName;
|
|
20
|
-
export const DropdownMenuCheckboxItem = React.forwardRef(({ children, className, checked, ...props }, ref) => (_jsxs(DropdownMenuPrimitive.CheckboxItem, { ref: ref, checked: checked, className: cn("relative flex cursor-default select-none items-center rounded-[var(--ssui-radius-sm)] py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-[color:var(--ssui-
|
|
23
|
+
export const DropdownMenuCheckboxItem = React.forwardRef(({ children, className, checked, ...props }, ref) => (_jsxs(DropdownMenuPrimitive.CheckboxItem, { ref: ref, checked: checked, className: cn("relative flex cursor-default select-none items-center rounded-[var(--ssui-radius-sm)] py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-[color:var(--ssui-overlay-hover)] data-[highlighted]:bg-[color:var(--ssui-overlay-hover)] data-[disabled]:pointer-events-none data-[disabled]:opacity-50", className), ...props, children: [_jsx("span", { className: "absolute left-2 flex size-3.5 items-center justify-center", children: _jsx(DropdownMenuPrimitive.ItemIndicator, { children: _jsx(Check, { className: "size-4" }) }) }), children] })));
|
|
21
24
|
DropdownMenuCheckboxItem.displayName = DropdownMenuPrimitive.CheckboxItem.displayName;
|
|
22
|
-
export const DropdownMenuRadioItem = React.forwardRef(({ children, className, ...props }, ref) => (_jsxs(DropdownMenuPrimitive.RadioItem, { ref: ref, className: cn("relative flex cursor-default select-none items-center rounded-[var(--ssui-radius-sm)] py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-[color:var(--ssui-
|
|
25
|
+
export const DropdownMenuRadioItem = React.forwardRef(({ children, className, ...props }, ref) => (_jsxs(DropdownMenuPrimitive.RadioItem, { ref: ref, className: cn("relative flex cursor-default select-none items-center rounded-[var(--ssui-radius-sm)] py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-[color:var(--ssui-overlay-hover)] data-[highlighted]:bg-[color:var(--ssui-overlay-hover)] data-[disabled]:pointer-events-none data-[disabled]:opacity-50", className), ...props, children: [_jsx("span", { className: "absolute left-2 flex size-3.5 items-center justify-center", children: _jsx(DropdownMenuPrimitive.ItemIndicator, { children: _jsx(Circle, { className: "size-2 fill-current" }) }) }), children] })));
|
|
23
26
|
DropdownMenuRadioItem.displayName = DropdownMenuPrimitive.RadioItem.displayName;
|
|
24
27
|
export const DropdownMenuLabel = React.forwardRef(({ className, inset, ...props }, ref) => (_jsx(DropdownMenuPrimitive.Label, { ref: ref, className: cn("px-2 py-1.5 text-xs font-medium text-[color:var(--ssui-text-muted)]", inset && "pl-8", className), ...props })));
|
|
25
28
|
DropdownMenuLabel.displayName = DropdownMenuPrimitive.Label.displayName;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
export interface FormFieldContextValue {
|
|
3
|
+
/** Id the participating control should adopt. */
|
|
4
|
+
id: string;
|
|
5
|
+
/** Space-separated ids of the description/error elements, if any. */
|
|
6
|
+
describedBy?: string;
|
|
7
|
+
/** True when the field is in an error state. */
|
|
8
|
+
invalid: boolean;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Read the enclosing `FormField` context, if any. Package controls use this
|
|
12
|
+
* to adopt the generated `id`/`aria-describedby`/`aria-invalid` wiring;
|
|
13
|
+
* standalone controls (no enclosing field) get `null` and render unchanged.
|
|
14
|
+
*/
|
|
15
|
+
export declare function useFormField(): FormFieldContextValue | null;
|
|
16
|
+
/**
|
|
17
|
+
* Merge `FormField` context wiring into a control's own props. The field owns
|
|
18
|
+
* the control's `id` so the label and control stay associated (customize it via
|
|
19
|
+
* `FormField`'s `htmlFor`, not the control). An explicit `aria-describedby` on
|
|
20
|
+
* the control is concatenated with — not replaced by — the field's
|
|
21
|
+
* description/error ids so error announcement is never dropped. An explicit
|
|
22
|
+
* `aria-invalid` still wins.
|
|
23
|
+
*/
|
|
24
|
+
export declare function useFormFieldProps<T extends {
|
|
25
|
+
id?: string;
|
|
26
|
+
"aria-describedby"?: string;
|
|
27
|
+
"aria-invalid"?: React.AriaAttributes["aria-invalid"];
|
|
28
|
+
}>(props: T): T;
|
|
29
|
+
export interface FormFieldProps extends Omit<React.HTMLAttributes<HTMLDivElement>, "children"> {
|
|
30
|
+
/** Field label. */
|
|
31
|
+
label: React.ReactNode;
|
|
32
|
+
/** Optional supporting copy shown under the label. */
|
|
33
|
+
description?: React.ReactNode;
|
|
34
|
+
/** Error message; when set the field is marked invalid. */
|
|
35
|
+
error?: React.ReactNode;
|
|
36
|
+
/** Explicit control id; defaults to a generated id. */
|
|
37
|
+
htmlFor?: string;
|
|
38
|
+
/** The control. Package controls pick up the field wiring automatically. */
|
|
39
|
+
children: React.ReactNode;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Label + description + control + error wrapper with standardized typography
|
|
43
|
+
* and accessibility wiring. Generates an id shared between the label's
|
|
44
|
+
* `htmlFor` and the control, and threads `aria-describedby`/`aria-invalid`
|
|
45
|
+
* to package controls (`Input`, `Textarea`, `Select`, `Combobox`) via
|
|
46
|
+
* context. Non-package controls can adopt the same id manually via `htmlFor`.
|
|
47
|
+
*/
|
|
48
|
+
export declare function FormField({ label, description, error, htmlFor, className, children, ...props }: FormFieldProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { cn } from "../utils/cn.js";
|
|
4
|
+
const FormFieldContext = React.createContext(null);
|
|
5
|
+
/**
|
|
6
|
+
* Read the enclosing `FormField` context, if any. Package controls use this
|
|
7
|
+
* to adopt the generated `id`/`aria-describedby`/`aria-invalid` wiring;
|
|
8
|
+
* standalone controls (no enclosing field) get `null` and render unchanged.
|
|
9
|
+
*/
|
|
10
|
+
export function useFormField() {
|
|
11
|
+
return React.useContext(FormFieldContext);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Merge `FormField` context wiring into a control's own props. The field owns
|
|
15
|
+
* the control's `id` so the label and control stay associated (customize it via
|
|
16
|
+
* `FormField`'s `htmlFor`, not the control). An explicit `aria-describedby` on
|
|
17
|
+
* the control is concatenated with — not replaced by — the field's
|
|
18
|
+
* description/error ids so error announcement is never dropped. An explicit
|
|
19
|
+
* `aria-invalid` still wins.
|
|
20
|
+
*/
|
|
21
|
+
export function useFormFieldProps(props) {
|
|
22
|
+
const field = useFormField();
|
|
23
|
+
if (!field)
|
|
24
|
+
return props;
|
|
25
|
+
const describedBy = [props["aria-describedby"], field.describedBy].filter(Boolean).join(" ") ||
|
|
26
|
+
undefined;
|
|
27
|
+
return {
|
|
28
|
+
...props,
|
|
29
|
+
id: field.id,
|
|
30
|
+
"aria-describedby": describedBy,
|
|
31
|
+
"aria-invalid": props["aria-invalid"] ?? (field.invalid || undefined),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Label + description + control + error wrapper with standardized typography
|
|
36
|
+
* and accessibility wiring. Generates an id shared between the label's
|
|
37
|
+
* `htmlFor` and the control, and threads `aria-describedby`/`aria-invalid`
|
|
38
|
+
* to package controls (`Input`, `Textarea`, `Select`, `Combobox`) via
|
|
39
|
+
* context. Non-package controls can adopt the same id manually via `htmlFor`.
|
|
40
|
+
*/
|
|
41
|
+
export function FormField({ label, description, error, htmlFor, className, children, ...props }) {
|
|
42
|
+
const generatedId = React.useId();
|
|
43
|
+
const id = htmlFor ?? generatedId;
|
|
44
|
+
const descriptionId = `${id}-description`;
|
|
45
|
+
const errorId = `${id}-error`;
|
|
46
|
+
const describedBy = [description ? descriptionId : null, error ? errorId : null]
|
|
47
|
+
.filter(Boolean)
|
|
48
|
+
.join(" ") || undefined;
|
|
49
|
+
const contextValue = React.useMemo(() => ({ id, describedBy, invalid: Boolean(error) }), [id, describedBy, error]);
|
|
50
|
+
return (_jsxs("div", { className: cn("space-y-1.5", className), ...props, children: [_jsx("label", { className: "block text-sm font-medium text-[color:var(--ssui-text)]", htmlFor: id, children: label }), description ? (_jsx("p", { className: "text-xs text-[color:var(--ssui-text-muted)]", id: descriptionId, children: description })) : null, _jsx(FormFieldContext.Provider, { value: contextValue, children: children }), error ? (_jsx("p", { className: "text-xs text-[color:var(--ssui-destructive)]", id: errorId, children: error })) : null] }));
|
|
51
|
+
}
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
+
export * from "./account-menu.js";
|
|
1
2
|
export * from "./audit-log.js";
|
|
2
3
|
export * from "./avatar.js";
|
|
3
4
|
export * from "./badge.js";
|
|
4
5
|
export * from "./brand-icons.js";
|
|
5
6
|
export * from "./button.js";
|
|
7
|
+
export * from "./choice-card.js";
|
|
8
|
+
export * from "./combobox.js";
|
|
6
9
|
export * from "./confirm-dialog.js";
|
|
10
|
+
export * from "./form-field.js";
|
|
7
11
|
export * from "./copy-field.js";
|
|
8
12
|
export * from "./dialog.js";
|
|
9
13
|
export * from "./dropdown-menu.js";
|
|
@@ -15,15 +19,23 @@ export * from "./inline-rename-input.js";
|
|
|
15
19
|
export * from "./input.js";
|
|
16
20
|
export * from "./list-shell.js";
|
|
17
21
|
export * from "./login.js";
|
|
22
|
+
export * from "./overflow-menu.js";
|
|
18
23
|
export * from "./page-header.js";
|
|
24
|
+
export * from "./rail-toggle.js";
|
|
19
25
|
export * from "./request-access.js";
|
|
20
26
|
export * from "./scroll-area.js";
|
|
21
27
|
export * from "./search-input.js";
|
|
28
|
+
export * from "./select.js";
|
|
22
29
|
export * from "./separator.js";
|
|
30
|
+
export * from "./settings-layout.js";
|
|
31
|
+
export * from "./settings-nav.js";
|
|
23
32
|
export * from "./settings-section.js";
|
|
24
33
|
export * from "./skeleton.js";
|
|
25
34
|
export * from "./status-pill.js";
|
|
35
|
+
export * from "./switch.js";
|
|
26
36
|
export * from "./tabs.js";
|
|
27
37
|
export * from "./textarea.js";
|
|
38
|
+
export * from "./time-zone-field.js";
|
|
28
39
|
export * from "./toolbar.js";
|
|
29
40
|
export * from "./tooltip.js";
|
|
41
|
+
export * from "./workspace-switcher.js";
|
package/dist/components/index.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
+
export * from "./account-menu.js";
|
|
1
2
|
export * from "./audit-log.js";
|
|
2
3
|
export * from "./avatar.js";
|
|
3
4
|
export * from "./badge.js";
|
|
4
5
|
export * from "./brand-icons.js";
|
|
5
6
|
export * from "./button.js";
|
|
7
|
+
export * from "./choice-card.js";
|
|
8
|
+
export * from "./combobox.js";
|
|
6
9
|
export * from "./confirm-dialog.js";
|
|
10
|
+
export * from "./form-field.js";
|
|
7
11
|
export * from "./copy-field.js";
|
|
8
12
|
export * from "./dialog.js";
|
|
9
13
|
export * from "./dropdown-menu.js";
|
|
@@ -15,15 +19,23 @@ export * from "./inline-rename-input.js";
|
|
|
15
19
|
export * from "./input.js";
|
|
16
20
|
export * from "./list-shell.js";
|
|
17
21
|
export * from "./login.js";
|
|
22
|
+
export * from "./overflow-menu.js";
|
|
18
23
|
export * from "./page-header.js";
|
|
24
|
+
export * from "./rail-toggle.js";
|
|
19
25
|
export * from "./request-access.js";
|
|
20
26
|
export * from "./scroll-area.js";
|
|
21
27
|
export * from "./search-input.js";
|
|
28
|
+
export * from "./select.js";
|
|
22
29
|
export * from "./separator.js";
|
|
30
|
+
export * from "./settings-layout.js";
|
|
31
|
+
export * from "./settings-nav.js";
|
|
23
32
|
export * from "./settings-section.js";
|
|
24
33
|
export * from "./skeleton.js";
|
|
25
34
|
export * from "./status-pill.js";
|
|
35
|
+
export * from "./switch.js";
|
|
26
36
|
export * from "./tabs.js";
|
|
27
37
|
export * from "./textarea.js";
|
|
38
|
+
export * from "./time-zone-field.js";
|
|
28
39
|
export * from "./toolbar.js";
|
|
29
40
|
export * from "./tooltip.js";
|
|
41
|
+
export * from "./workspace-switcher.js";
|