@misoto22/design 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/components/Accordion/Accordion.d.ts +34 -0
- package/dist/components/Accordion/Accordion.js +37 -0
- package/dist/components/Accordion/Accordion.js.map +1 -0
- package/dist/components/Alert/Alert.d.ts +32 -0
- package/dist/components/Alert/Alert.js +49 -0
- package/dist/components/Alert/Alert.js.map +1 -0
- package/dist/components/AppShell/AppShell.d.ts +38 -0
- package/dist/components/AppShell/AppShell.js +92 -0
- package/dist/components/AppShell/AppShell.js.map +1 -0
- package/dist/components/Avatar/Avatar.d.ts +29 -0
- package/dist/components/Avatar/Avatar.js +39 -0
- package/dist/components/Avatar/Avatar.js.map +1 -0
- package/dist/components/Badge/Badge.d.ts +30 -0
- package/dist/components/Badge/Badge.js +29 -0
- package/dist/components/Badge/Badge.js.map +1 -0
- package/dist/components/Breadcrumb/Breadcrumb.d.ts +31 -0
- package/dist/components/Breadcrumb/Breadcrumb.js +31 -0
- package/dist/components/Breadcrumb/Breadcrumb.js.map +1 -0
- package/dist/components/Button/Button.d.ts +70 -0
- package/dist/components/Button/Button.js +81 -0
- package/dist/components/Button/Button.js.map +1 -0
- package/dist/components/Calendar/Calendar.d.ts +28 -0
- package/dist/components/Calendar/Calendar.js +87 -0
- package/dist/components/Calendar/Calendar.js.map +1 -0
- package/dist/components/Card/Card.d.ts +49 -0
- package/dist/components/Card/Card.js +64 -0
- package/dist/components/Card/Card.js.map +1 -0
- package/dist/components/Checkbox/Checkbox.d.ts +23 -0
- package/dist/components/Checkbox/Checkbox.js +24 -0
- package/dist/components/Checkbox/Checkbox.js.map +1 -0
- package/dist/components/Collapsible/Collapsible.d.ts +31 -0
- package/dist/components/Collapsible/Collapsible.js +35 -0
- package/dist/components/Collapsible/Collapsible.js.map +1 -0
- package/dist/components/Combobox/Combobox.d.ts +63 -0
- package/dist/components/Combobox/Combobox.js +151 -0
- package/dist/components/Combobox/Combobox.js.map +1 -0
- package/dist/components/Command/Command.d.ts +98 -0
- package/dist/components/Command/Command.js +166 -0
- package/dist/components/Command/Command.js.map +1 -0
- package/dist/components/ContextMenu/ContextMenu.d.ts +38 -0
- package/dist/components/ContextMenu/ContextMenu.js +79 -0
- package/dist/components/ContextMenu/ContextMenu.js.map +1 -0
- package/dist/components/DatePicker/DatePicker.d.ts +98 -0
- package/dist/components/DatePicker/DatePicker.js +214 -0
- package/dist/components/DatePicker/DatePicker.js.map +1 -0
- package/dist/components/Dialog/Dialog.d.ts +48 -0
- package/dist/components/Dialog/Dialog.js +72 -0
- package/dist/components/Dialog/Dialog.js.map +1 -0
- package/dist/components/DropdownMenu/DropdownMenu.d.ts +49 -0
- package/dist/components/DropdownMenu/DropdownMenu.js +89 -0
- package/dist/components/DropdownMenu/DropdownMenu.js.map +1 -0
- package/dist/components/EmptyState/EmptyState.d.ts +31 -0
- package/dist/components/EmptyState/EmptyState.js +30 -0
- package/dist/components/EmptyState/EmptyState.js.map +1 -0
- package/dist/components/ErrorState/ErrorState.d.ts +34 -0
- package/dist/components/ErrorState/ErrorState.js +32 -0
- package/dist/components/ErrorState/ErrorState.js.map +1 -0
- package/dist/components/Field/Field.d.ts +44 -0
- package/dist/components/Field/Field.js +54 -0
- package/dist/components/Field/Field.js.map +1 -0
- package/dist/components/FigureBand/FigureBand.d.ts +51 -0
- package/dist/components/FigureBand/FigureBand.js +52 -0
- package/dist/components/FigureBand/FigureBand.js.map +1 -0
- package/dist/components/FloatingIconButton/FloatingIconButton.d.ts +29 -0
- package/dist/components/FloatingIconButton/FloatingIconButton.js +32 -0
- package/dist/components/FloatingIconButton/FloatingIconButton.js.map +1 -0
- package/dist/components/Input/Input.d.ts +22 -0
- package/dist/components/Input/Input.js +21 -0
- package/dist/components/Input/Input.js.map +1 -0
- package/dist/components/Kbd/Kbd.d.ts +20 -0
- package/dist/components/Kbd/Kbd.js +21 -0
- package/dist/components/Kbd/Kbd.js.map +1 -0
- package/dist/components/LinkArrow/LinkArrow.d.ts +24 -0
- package/dist/components/LinkArrow/LinkArrow.js +24 -0
- package/dist/components/LinkArrow/LinkArrow.js.map +1 -0
- package/dist/components/NativeSelect/NativeSelect.d.ts +27 -0
- package/dist/components/NativeSelect/NativeSelect.js +46 -0
- package/dist/components/NativeSelect/NativeSelect.js.map +1 -0
- package/dist/components/NavItem/NavItem.d.ts +39 -0
- package/dist/components/NavItem/NavItem.js +31 -0
- package/dist/components/NavItem/NavItem.js.map +1 -0
- package/dist/components/Pagination/Pagination.d.ts +44 -0
- package/dist/components/Pagination/Pagination.js +109 -0
- package/dist/components/Pagination/Pagination.js.map +1 -0
- package/dist/components/Popover/Popover.d.ts +39 -0
- package/dist/components/Popover/Popover.js +57 -0
- package/dist/components/Popover/Popover.js.map +1 -0
- package/dist/components/Progress/Progress.d.ts +31 -0
- package/dist/components/Progress/Progress.js +45 -0
- package/dist/components/Progress/Progress.js.map +1 -0
- package/dist/components/RadioGroup/RadioGroup.d.ts +43 -0
- package/dist/components/RadioGroup/RadioGroup.js +43 -0
- package/dist/components/RadioGroup/RadioGroup.js.map +1 -0
- package/dist/components/ScrollArea/ScrollArea.d.ts +31 -0
- package/dist/components/ScrollArea/ScrollArea.js +54 -0
- package/dist/components/ScrollArea/ScrollArea.js.map +1 -0
- package/dist/components/SearchableMenu/SearchableMenu.d.ts +59 -0
- package/dist/components/SearchableMenu/SearchableMenu.js +79 -0
- package/dist/components/SearchableMenu/SearchableMenu.js.map +1 -0
- package/dist/components/Select/Select.d.ts +71 -0
- package/dist/components/Select/Select.js +114 -0
- package/dist/components/Select/Select.js.map +1 -0
- package/dist/components/Separator/Separator.d.ts +30 -0
- package/dist/components/Separator/Separator.js +35 -0
- package/dist/components/Separator/Separator.js.map +1 -0
- package/dist/components/Sheet/Sheet.d.ts +38 -0
- package/dist/components/Sheet/Sheet.js +68 -0
- package/dist/components/Sheet/Sheet.js.map +1 -0
- package/dist/components/Skeleton/Skeleton.d.ts +63 -0
- package/dist/components/Skeleton/Skeleton.js +44 -0
- package/dist/components/Skeleton/Skeleton.js.map +1 -0
- package/dist/components/Slider/Slider.d.ts +35 -0
- package/dist/components/Slider/Slider.js +52 -0
- package/dist/components/Slider/Slider.js.map +1 -0
- package/dist/components/Spinner/Spinner.d.ts +50 -0
- package/dist/components/Spinner/Spinner.js +48 -0
- package/dist/components/Spinner/Spinner.js.map +1 -0
- package/dist/components/StatusDot/StatusDot.d.ts +29 -0
- package/dist/components/StatusDot/StatusDot.js +44 -0
- package/dist/components/StatusDot/StatusDot.js.map +1 -0
- package/dist/components/StatusPill/StatusPill.d.ts +25 -0
- package/dist/components/StatusPill/StatusPill.js +31 -0
- package/dist/components/StatusPill/StatusPill.js.map +1 -0
- package/dist/components/Switch/Switch.d.ts +23 -0
- package/dist/components/Switch/Switch.js +23 -0
- package/dist/components/Switch/Switch.js.map +1 -0
- package/dist/components/Table/Table.d.ts +96 -0
- package/dist/components/Table/Table.js +136 -0
- package/dist/components/Table/Table.js.map +1 -0
- package/dist/components/Tabs/Tabs.d.ts +35 -0
- package/dist/components/Tabs/Tabs.js +48 -0
- package/dist/components/Tabs/Tabs.js.map +1 -0
- package/dist/components/Tag/Tag.d.ts +28 -0
- package/dist/components/Tag/Tag.js +22 -0
- package/dist/components/Tag/Tag.js.map +1 -0
- package/dist/components/Textarea/Textarea.d.ts +20 -0
- package/dist/components/Textarea/Textarea.js +32 -0
- package/dist/components/Textarea/Textarea.js.map +1 -0
- package/dist/components/Toast/Toast.d.ts +24 -0
- package/dist/components/Toast/Toast.js +41 -0
- package/dist/components/Toast/Toast.js.map +1 -0
- package/dist/components/ToggleGroup/ToggleGroup.d.ts +41 -0
- package/dist/components/ToggleGroup/ToggleGroup.js +78 -0
- package/dist/components/ToggleGroup/ToggleGroup.js.map +1 -0
- package/dist/components/Tooltip/Tooltip.d.ts +43 -0
- package/dist/components/Tooltip/Tooltip.js +40 -0
- package/dist/components/Tooltip/Tooltip.js.map +1 -0
- package/dist/fonts/hanken-grotesk-300.woff2 +0 -0
- package/dist/fonts/hanken-grotesk-400.woff2 +0 -0
- package/dist/fonts/hanken-grotesk-500.woff2 +0 -0
- package/dist/fonts/hanken-grotesk-600.woff2 +0 -0
- package/dist/fonts/hanken-grotesk-700.woff2 +0 -0
- package/dist/fonts/ibm-plex-mono-400.woff2 +0 -0
- package/dist/fonts/ibm-plex-mono-500.woff2 +0 -0
- package/dist/fonts/ibm-plex-mono-600.woff2 +0 -0
- package/dist/fonts/newsreader-300.woff2 +0 -0
- package/dist/fonts/newsreader-400.woff2 +0 -0
- package/dist/fonts/newsreader-500.woff2 +0 -0
- package/dist/fonts/newsreader-600.woff2 +0 -0
- package/dist/fonts.css +96 -0
- package/dist/index.d.ts +77 -0
- package/dist/index.js +63 -0
- package/dist/index.js.map +1 -0
- package/dist/keyframes.css +212 -0
- package/dist/lib/cn.d.ts +21 -0
- package/dist/lib/cn.js +9 -0
- package/dist/lib/cn.js.map +1 -0
- package/dist/lib/control.d.ts +31 -0
- package/dist/lib/control.js +14 -0
- package/dist/lib/control.js.map +1 -0
- package/dist/lib/index.d.ts +4 -0
- package/dist/lib/index.js +11 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/overlay-container.d.ts +38 -0
- package/dist/lib/overlay-container.js +15 -0
- package/dist/lib/overlay-container.js.map +1 -0
- package/dist/lib/useSelectionIndicator.d.ts +29 -0
- package/dist/lib/useSelectionIndicator.js +45 -0
- package/dist/lib/useSelectionIndicator.js.map +1 -0
- package/dist/semantic.css +127 -0
- package/dist/styles.css +98 -0
- package/dist/themes.css +115 -0
- package/dist/tokens/brand.d.ts +47 -0
- package/dist/tokens/brand.js +38 -0
- package/dist/tokens/brand.js.map +1 -0
- package/dist/tokens.css +323 -0
- package/dist/tokens.d.ts +153 -0
- package/dist/tokens.js +766 -0
- package/dist/tokens.json +765 -0
- package/package.json +130 -0
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Check, ChevronsUpDown, X } from "lucide-react";
|
|
4
|
+
import { useState } from "react";
|
|
5
|
+
import { cn } from "../../lib/cn.js";
|
|
6
|
+
import {
|
|
7
|
+
Command,
|
|
8
|
+
CommandEmpty,
|
|
9
|
+
CommandGroup,
|
|
10
|
+
CommandInput,
|
|
11
|
+
CommandItem,
|
|
12
|
+
CommandList
|
|
13
|
+
} from "../Command/Command.js";
|
|
14
|
+
import { Popover, PopoverContent, PopoverTrigger } from "../Popover/Popover.js";
|
|
15
|
+
const SUMMARISE_AFTER = 2;
|
|
16
|
+
function Combobox(props) {
|
|
17
|
+
const {
|
|
18
|
+
options,
|
|
19
|
+
label,
|
|
20
|
+
placeholder = "Select\u2026",
|
|
21
|
+
searchPlaceholder = "Search\u2026",
|
|
22
|
+
emptyMessage = "Nothing matches.",
|
|
23
|
+
disabled = false,
|
|
24
|
+
className
|
|
25
|
+
} = props;
|
|
26
|
+
const multiple = props.multiple === true;
|
|
27
|
+
const [open, setOpen] = useState(false);
|
|
28
|
+
const [uncontrolled, setUncontrolled] = useState(() => {
|
|
29
|
+
if (props.multiple === true) return props.defaultValue ?? [];
|
|
30
|
+
return props.defaultValue ? [props.defaultValue] : [];
|
|
31
|
+
});
|
|
32
|
+
const controlled = props.multiple === true ? props.value : props.value === void 0 ? void 0 : props.value === "" ? [] : [props.value];
|
|
33
|
+
const current = controlled ?? uncontrolled;
|
|
34
|
+
const commit = (next) => {
|
|
35
|
+
if (controlled === void 0) setUncontrolled(next);
|
|
36
|
+
if (props.multiple === true) props.onValueChange?.(next);
|
|
37
|
+
else props.onValueChange?.(next[0] ?? "");
|
|
38
|
+
};
|
|
39
|
+
const choose = (option) => {
|
|
40
|
+
if (multiple) {
|
|
41
|
+
commit(current.includes(option) ? current.filter((v) => v !== option) : [...current, option]);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
commit(current.includes(option) ? [] : [option]);
|
|
45
|
+
setOpen(false);
|
|
46
|
+
};
|
|
47
|
+
const chosen = options.filter((option) => current.includes(option.value));
|
|
48
|
+
const summary = chosen.length === 0 ? placeholder : chosen.length <= SUMMARISE_AFTER ? chosen.map((option) => option.label).join(", ") : `${chosen.length} selected`;
|
|
49
|
+
return /* @__PURE__ */ jsxs(Popover, { open, onOpenChange: setOpen, children: [
|
|
50
|
+
/* @__PURE__ */ jsxs(
|
|
51
|
+
PopoverTrigger,
|
|
52
|
+
{
|
|
53
|
+
role: "combobox",
|
|
54
|
+
"aria-expanded": open,
|
|
55
|
+
"aria-label": label,
|
|
56
|
+
disabled,
|
|
57
|
+
className: cn(
|
|
58
|
+
"group flex w-full items-center justify-between gap-2 rounded-(--radius) border border-(--rule-2) bg-(--paper) px-(--field-px) py-(--field-py) text-start text-sm transition-colors duration-(--duration-fast) hover:border-(--rule-hard) disabled:opacity-(--disabled-opacity) disabled:pointer-events-none",
|
|
59
|
+
chosen.length > 0 ? "text-(--ink)" : "text-(--ink-3-aa)",
|
|
60
|
+
className
|
|
61
|
+
),
|
|
62
|
+
children: [
|
|
63
|
+
/* @__PURE__ */ jsx("span", { className: "truncate", children: summary }),
|
|
64
|
+
/* @__PURE__ */ jsxs("span", { className: "flex shrink-0 items-center gap-1", children: [
|
|
65
|
+
multiple && chosen.length > 0 && // A `<span role="button">` rather than a nested `<button>`, which
|
|
66
|
+
// is invalid inside the trigger and which browsers reparent — the
|
|
67
|
+
// clear control then falls outside the field entirely.
|
|
68
|
+
/* @__PURE__ */ jsx(
|
|
69
|
+
"span",
|
|
70
|
+
{
|
|
71
|
+
role: "button",
|
|
72
|
+
tabIndex: 0,
|
|
73
|
+
"aria-label": `Clear ${label}`,
|
|
74
|
+
onClick: (event) => {
|
|
75
|
+
event.preventDefault();
|
|
76
|
+
event.stopPropagation();
|
|
77
|
+
commit([]);
|
|
78
|
+
},
|
|
79
|
+
onKeyDown: (event) => {
|
|
80
|
+
if (event.key !== "Enter" && event.key !== " ") return;
|
|
81
|
+
event.preventDefault();
|
|
82
|
+
event.stopPropagation();
|
|
83
|
+
commit([]);
|
|
84
|
+
},
|
|
85
|
+
className: "grid size-5 cursor-pointer place-items-center rounded-full text-(--ink-3-aa) transition-colors duration-(--duration-fast) hover:bg-(--stone) hover:text-(--ink)",
|
|
86
|
+
children: /* @__PURE__ */ jsx(X, { size: 12, strokeWidth: 2, "aria-hidden": true })
|
|
87
|
+
}
|
|
88
|
+
),
|
|
89
|
+
/* @__PURE__ */ jsx(ChevronsUpDown, { size: 14, strokeWidth: 1.5, "aria-hidden": true, className: "text-(--ink-3-aa)" })
|
|
90
|
+
] })
|
|
91
|
+
]
|
|
92
|
+
}
|
|
93
|
+
),
|
|
94
|
+
/* @__PURE__ */ jsx(
|
|
95
|
+
PopoverContent,
|
|
96
|
+
{
|
|
97
|
+
label,
|
|
98
|
+
className: "w-(--radix-popover-trigger-width) overflow-hidden p-0",
|
|
99
|
+
align: "start",
|
|
100
|
+
children: /* @__PURE__ */ jsxs(Command, { label: `${label}: ${searchPlaceholder}`, className: "rounded-none border-0", children: [
|
|
101
|
+
/* @__PURE__ */ jsx(CommandInput, { placeholder: searchPlaceholder }),
|
|
102
|
+
/* @__PURE__ */ jsxs(CommandList, { children: [
|
|
103
|
+
/* @__PURE__ */ jsx(CommandEmpty, { children: emptyMessage }),
|
|
104
|
+
/* @__PURE__ */ jsx(CommandGroup, { children: options.map((option) => {
|
|
105
|
+
const selected = current.includes(option.value);
|
|
106
|
+
return /* @__PURE__ */ jsxs(
|
|
107
|
+
CommandItem,
|
|
108
|
+
{
|
|
109
|
+
value: option.value,
|
|
110
|
+
keywords: [option.label, ...option.keywords ?? []],
|
|
111
|
+
disabled: option.disabled,
|
|
112
|
+
onSelect: choose,
|
|
113
|
+
"aria-selected": selected,
|
|
114
|
+
children: [
|
|
115
|
+
/* @__PURE__ */ jsx(
|
|
116
|
+
"span",
|
|
117
|
+
{
|
|
118
|
+
className: cn(
|
|
119
|
+
"grid size-4 shrink-0 place-items-center transition-opacity duration-(--duration-fast)",
|
|
120
|
+
multiple && "rounded-(--radius-sm) border border-(--rule-2) text-(--accent-foreground) data-[on=true]:border-(--accent) data-[on=true]:bg-(--accent)"
|
|
121
|
+
),
|
|
122
|
+
"data-on": selected,
|
|
123
|
+
children: /* @__PURE__ */ jsx(
|
|
124
|
+
Check,
|
|
125
|
+
{
|
|
126
|
+
size: 12,
|
|
127
|
+
strokeWidth: 2.5,
|
|
128
|
+
"aria-hidden": true,
|
|
129
|
+
className: selected ? "opacity-100" : "opacity-0"
|
|
130
|
+
}
|
|
131
|
+
)
|
|
132
|
+
}
|
|
133
|
+
),
|
|
134
|
+
option.label
|
|
135
|
+
]
|
|
136
|
+
},
|
|
137
|
+
option.value
|
|
138
|
+
);
|
|
139
|
+
}) })
|
|
140
|
+
] })
|
|
141
|
+
] })
|
|
142
|
+
}
|
|
143
|
+
)
|
|
144
|
+
] });
|
|
145
|
+
}
|
|
146
|
+
var Combobox_default = Combobox;
|
|
147
|
+
export {
|
|
148
|
+
Combobox,
|
|
149
|
+
Combobox_default as default
|
|
150
|
+
};
|
|
151
|
+
//# sourceMappingURL=Combobox.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/Combobox/Combobox.tsx"],"sourcesContent":["'use client'\n\nimport { Check, ChevronsUpDown, X } from 'lucide-react'\nimport { useState } from 'react'\nimport { cn } from '../../lib/cn'\nimport {\n Command,\n CommandEmpty,\n CommandGroup,\n CommandInput,\n CommandItem,\n CommandList,\n} from '../Command/Command'\nimport { Popover, PopoverContent, PopoverTrigger } from '../Popover/Popover'\n\nexport interface ComboboxOption {\n value: string\n label: string\n /** Extra text matched by the filter but not shown as the label. */\n keywords?: string[]\n disabled?: boolean\n}\n\ninterface CommonProps {\n options: ComboboxOption[]\n /** Names the control. Required — the trigger's text is a value, not a label. */\n label: string\n /** Shown on the trigger when nothing is chosen. */\n placeholder?: string\n /** Placeholder inside the filter field. */\n searchPlaceholder?: string\n /** Shown when the filter matches nothing. Say what WOULD match. */\n emptyMessage?: string\n disabled?: boolean\n className?: string\n}\n\ninterface SingleProps extends CommonProps {\n multiple?: false\n value?: string\n defaultValue?: string\n onValueChange?: (value: string) => void\n}\n\ninterface MultipleProps extends CommonProps {\n /**\n * Several at once. The trigger then summarises the choice rather than naming\n * it — \"3 selected\" past a threshold, because a trigger that grows with its\n * value reflows the form every time someone picks another one.\n */\n multiple: true\n value?: string[]\n defaultValue?: string[]\n onValueChange?: (value: string[]) => void\n}\n\nexport type ComboboxProps = SingleProps | MultipleProps\n\n/** How many labels the trigger prints before it starts counting instead. */\nconst SUMMARISE_AFTER = 2\n\n/**\n * A select you can type into, choosing one or several.\n *\n * The line against `Select` is length, and it is not a matter of taste: a\n * styled select is better up to roughly a dozen options, because a list nobody\n * can filter is faster to scan than one they have to think about. Past that,\n * this is the right answer.\n *\n * Filtering, the highlighted row and the arrow keys come from cmdk, which\n * implements the ARIA combobox pattern properly: the highlight moves through\n * `aria-activedescendant` while focus stays in the input. Hand-rolled comboboxes\n * move focus into the list instead, and the typed text stops being editable.\n *\n * Controlled or uncontrolled, like every other form control here.\n *\n * @example\n * <Combobox label=\"Framework\" options={FRAMEWORKS} placeholder=\"Pick one\" />\n * @example\n * <Combobox multiple label=\"Tags\" options={TAGS} />\n */\nexport function Combobox(props: ComboboxProps) {\n const {\n options,\n label,\n placeholder = 'Select…',\n searchPlaceholder = 'Search…',\n emptyMessage = 'Nothing matches.',\n disabled = false,\n className,\n } = props\n const multiple = props.multiple === true\n\n const [open, setOpen] = useState(false)\n const [uncontrolled, setUncontrolled] = useState<string[]>(() => {\n if (props.multiple === true) return props.defaultValue ?? []\n return props.defaultValue ? [props.defaultValue] : []\n })\n\n const controlled =\n props.multiple === true\n ? props.value\n : props.value === undefined\n ? undefined\n : props.value === ''\n ? []\n : [props.value]\n const current = controlled ?? uncontrolled\n\n const commit = (next: string[]) => {\n if (controlled === undefined) setUncontrolled(next)\n if (props.multiple === true) props.onValueChange?.(next)\n else props.onValueChange?.(next[0] ?? '')\n }\n\n const choose = (option: string) => {\n if (multiple) {\n // Toggling, and the panel stays open — picking three things should not\n // cost three round trips through the trigger.\n commit(current.includes(option) ? current.filter((v) => v !== option) : [...current, option])\n return\n }\n // Choosing the selected option again clears it, which is what a reader\n // expects from a control whose value is optional.\n commit(current.includes(option) ? [] : [option])\n setOpen(false)\n }\n\n const chosen = options.filter((option) => current.includes(option.value))\n const summary =\n chosen.length === 0\n ? placeholder\n : chosen.length <= SUMMARISE_AFTER\n ? chosen.map((option) => option.label).join(', ')\n : `${chosen.length} selected`\n\n return (\n <Popover open={open} onOpenChange={setOpen}>\n <PopoverTrigger\n // A combobox trigger is a button that OPENS a listbox; the roles for\n // the list itself belong to cmdk inside the panel.\n role=\"combobox\"\n aria-expanded={open}\n aria-label={label}\n disabled={disabled}\n className={cn(\n 'group flex w-full items-center justify-between gap-2 rounded-(--radius) border border-(--rule-2) bg-(--paper) px-(--field-px) py-(--field-py) text-start text-sm transition-colors duration-(--duration-fast) hover:border-(--rule-hard) disabled:opacity-(--disabled-opacity) disabled:pointer-events-none',\n chosen.length > 0 ? 'text-(--ink)' : 'text-(--ink-3-aa)',\n className,\n )}\n >\n <span className=\"truncate\">{summary}</span>\n <span className=\"flex shrink-0 items-center gap-1\">\n {multiple && chosen.length > 0 && (\n // A `<span role=\"button\">` rather than a nested `<button>`, which\n // is invalid inside the trigger and which browsers reparent — the\n // clear control then falls outside the field entirely.\n <span\n role=\"button\"\n tabIndex={0}\n aria-label={`Clear ${label}`}\n onClick={(event) => {\n event.preventDefault()\n event.stopPropagation()\n commit([])\n }}\n onKeyDown={(event) => {\n if (event.key !== 'Enter' && event.key !== ' ') return\n event.preventDefault()\n event.stopPropagation()\n commit([])\n }}\n className=\"grid size-5 cursor-pointer place-items-center rounded-full text-(--ink-3-aa) transition-colors duration-(--duration-fast) hover:bg-(--stone) hover:text-(--ink)\"\n >\n <X size={12} strokeWidth={2} aria-hidden />\n </span>\n )}\n <ChevronsUpDown size={14} strokeWidth={1.5} aria-hidden className=\"text-(--ink-3-aa)\" />\n </span>\n </PopoverTrigger>\n <PopoverContent\n label={label}\n // `overflow-hidden` so the panel's own corners clip the square-cornered\n // command list inside it; without it the list's edges poked through the\n // radius and the two bottom corners looked chipped.\n className=\"w-(--radix-popover-trigger-width) overflow-hidden p-0\"\n align=\"start\"\n >\n <Command label={`${label}: ${searchPlaceholder}`} className=\"rounded-none border-0\">\n {/* The panel's own name is \"<label>: <placeholder>\", set on Command\n above. cmdk points the input's aria-labelledby at it, and\n aria-labelledby beats aria-label — so naming the input directly\n did nothing, and a screen reader met two comboboxes called \"Tags\",\n one inside the other. */}\n <CommandInput placeholder={searchPlaceholder} />\n <CommandList>\n <CommandEmpty>{emptyMessage}</CommandEmpty>\n <CommandGroup>\n {options.map((option) => {\n const selected = current.includes(option.value)\n return (\n <CommandItem\n key={option.value}\n value={option.value}\n keywords={[option.label, ...(option.keywords ?? [])]}\n disabled={option.disabled}\n onSelect={choose}\n aria-selected={selected}\n >\n <span\n className={cn(\n 'grid size-4 shrink-0 place-items-center transition-opacity duration-(--duration-fast)',\n multiple &&\n 'rounded-(--radius-sm) border border-(--rule-2) text-(--accent-foreground) data-[on=true]:border-(--accent) data-[on=true]:bg-(--accent)',\n )}\n data-on={selected}\n >\n <Check\n size={12}\n strokeWidth={2.5}\n aria-hidden\n className={selected ? 'opacity-100' : 'opacity-0'}\n />\n </span>\n {option.label}\n </CommandItem>\n )\n })}\n </CommandGroup>\n </CommandList>\n </Command>\n </PopoverContent>\n </Popover>\n )\n}\n\nexport default Combobox\n"],"mappings":";AAuJQ,cACA,YADA;AArJR,SAAS,OAAO,gBAAgB,SAAS;AACzC,SAAS,gBAAgB;AACzB,SAAS,UAAU;AACnB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,SAAS,gBAAgB,sBAAsB;AA8CxD,MAAM,kBAAkB;AAsB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AAW,QAAQ,SAAS,OAAO,KAAK;AAC9C,qBACE;AAAA,gBAAC;AAAA;AAAA,kBAEC,OAAO,OAAO;AAAA,kBACd,UAAU,CAAC,OAAO,OAAO,GAAI,OAAO,YAAY,CAAC,CAAE;AAAA,kBACnD,UAAU,OAAO;AAAA,kBACjB,UAAU;AAAA,kBACV,iBAAe;AAAA,kBAEf;AAAA;AAAA,sBAAC;AAAA;AAAA,wBACC,WAAW;AAAA,0BACT;AAAA,0BACA,YACE;AAAA,wBACJ;AAAA,wBACA,WAAS;AAAA,wBAET;AAAA,0BAAC;AAAA;AAAA,4BACC,MAAM;AAAA,4BACN,aAAa;AAAA,4BACb,eAAW;AAAA,4BACX,WAAW,WAAW,gBAAgB;AAAA;AAAA,wBACxC;AAAA;AAAA,oBACF;AAAA,oBACC,OAAO;AAAA;AAAA;AAAA,gBAtBH,OAAO;AAAA,cAuBd;AAAA,YAEJ,CAAC,GACH;AAAA,aACF;AAAA,WACF;AAAA;AAAA,IACF;AAAA,KACF;AAEJ;AAEA,IAAO,mBAAQ;","names":[]}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ComponentProps, ReactNode } from 'react';
|
|
3
|
+
import { Command as Command$1 } from 'cmdk';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A filterable list of actions — the ⌘K surface.
|
|
7
|
+
*
|
|
8
|
+
* Built on cmdk rather than on a `Select` or a menu, because the interaction is
|
|
9
|
+
* neither: the list is filtered as you type, the highlighted row moves with the
|
|
10
|
+
* arrow keys while focus STAYS in the input, and Enter runs the highlighted
|
|
11
|
+
* row. That is the ARIA combobox pattern, and it is the part nobody should
|
|
12
|
+
* hand-roll — `aria-activedescendant` moving without focus moving is precisely
|
|
13
|
+
* where a home-made palette stops working with a screen reader.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* <Command label="Command palette">
|
|
17
|
+
* <CommandInput placeholder="Type a command…" />
|
|
18
|
+
* <CommandList>
|
|
19
|
+
* <CommandEmpty>Nothing matches.</CommandEmpty>
|
|
20
|
+
* <CommandGroup heading="Navigate">
|
|
21
|
+
* <CommandItem onSelect={go}>Components</CommandItem>
|
|
22
|
+
* </CommandGroup>
|
|
23
|
+
* </CommandList>
|
|
24
|
+
* </Command>
|
|
25
|
+
*/
|
|
26
|
+
declare function Command({ className, ...props }: ComponentProps<typeof Command$1>): react.JSX.Element;
|
|
27
|
+
/** The filter field. Carries the search icon and the combobox semantics. */
|
|
28
|
+
declare function CommandInput({ className, ...props }: ComponentProps<typeof Command$1.Input>): react.JSX.Element;
|
|
29
|
+
declare function CommandList({ className, ...props }: ComponentProps<typeof Command$1.List>): react.JSX.Element;
|
|
30
|
+
/** Shown when the filter matches nothing. Say what would match, not "no results". */
|
|
31
|
+
declare function CommandEmpty(props: ComponentProps<typeof Command$1.Empty>): react.JSX.Element;
|
|
32
|
+
/**
|
|
33
|
+
* The key-hint strip along the bottom.
|
|
34
|
+
*
|
|
35
|
+
* A palette is a keyboard surface whose keys are invisible: nothing on screen
|
|
36
|
+
* says the arrows move the row or that Enter runs it, and a reader who reaches
|
|
37
|
+
* for the mouse has been failed by the design rather than by themselves.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* <CommandFooter>
|
|
41
|
+
* <CommandHint keys={['↑', '↓']}>navigate</CommandHint>
|
|
42
|
+
* <CommandHint keys={['↵']}>open</CommandHint>
|
|
43
|
+
* </CommandFooter>
|
|
44
|
+
*/
|
|
45
|
+
declare function CommandFooter({ className, ...props }: ComponentProps<'div'>): react.JSX.Element;
|
|
46
|
+
interface CommandHintProps extends Omit<ComponentProps<'span'>, 'children'> {
|
|
47
|
+
/** The keys this hint describes, printed as `Kbd` chips. */
|
|
48
|
+
keys: string[];
|
|
49
|
+
/** What they do — a verb, lowercase, no sentence. */
|
|
50
|
+
children: ReactNode;
|
|
51
|
+
}
|
|
52
|
+
/** One key-and-verb pair inside a `CommandFooter`. */
|
|
53
|
+
declare function CommandHint({ keys, children, className, ...props }: CommandHintProps): react.JSX.Element;
|
|
54
|
+
declare function CommandGroup({ className, ...props }: ComponentProps<typeof Command$1.Group>): react.JSX.Element;
|
|
55
|
+
/**
|
|
56
|
+
* A divider between groups.
|
|
57
|
+
*
|
|
58
|
+
* Marked presentational, because ARIA permits a `listbox` to contain only
|
|
59
|
+
* `option` and `group` — and the library renders this as `role="separator"`,
|
|
60
|
+
* which puts a critical `aria-required-children` violation inside every palette
|
|
61
|
+
* that uses one. The grouping is already announced by the groups themselves, so
|
|
62
|
+
* removing the divider from the accessibility tree loses nothing.
|
|
63
|
+
*/
|
|
64
|
+
declare function CommandSeparator({ className, ...props }: ComponentProps<typeof Command$1.Separator>): react.JSX.Element;
|
|
65
|
+
interface CommandItemProps extends ComponentProps<typeof Command$1.Item> {
|
|
66
|
+
/** A shortcut printed at the end of the row. */
|
|
67
|
+
shortcut?: string;
|
|
68
|
+
/**
|
|
69
|
+
* A leading glyph. Pass the icon element, sized 16.
|
|
70
|
+
*
|
|
71
|
+
* It is what makes a long list scannable — the eye sorts by shape before it
|
|
72
|
+
* reads, and forty identical rows of text defeat that.
|
|
73
|
+
*/
|
|
74
|
+
icon?: ReactNode;
|
|
75
|
+
/**
|
|
76
|
+
* A quiet note at the end of the row — what kind of thing this is, or its
|
|
77
|
+
* current state. Not a description: a palette that prints a sentence per row
|
|
78
|
+
* stops being scannable at about six of them.
|
|
79
|
+
*/
|
|
80
|
+
meta?: ReactNode;
|
|
81
|
+
}
|
|
82
|
+
declare function CommandItem({ shortcut, icon, meta, className, children, ...props }: CommandItemProps): react.JSX.Element;
|
|
83
|
+
interface CommandDialogProps {
|
|
84
|
+
open: boolean;
|
|
85
|
+
onOpenChange: (open: boolean) => void;
|
|
86
|
+
/** Names the palette for assistive tech. */
|
|
87
|
+
label: string;
|
|
88
|
+
children: ReactNode;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* The palette in a modal, which is how it is nearly always used.
|
|
92
|
+
*
|
|
93
|
+
* The dialog's own padding is removed: a palette is edge-to-edge, and its input
|
|
94
|
+
* is the first thing focus lands on.
|
|
95
|
+
*/
|
|
96
|
+
declare function CommandDialog({ open, onOpenChange, label, children }: CommandDialogProps): react.JSX.Element;
|
|
97
|
+
|
|
98
|
+
export { Command, CommandDialog, type CommandDialogProps, CommandEmpty, CommandFooter, CommandGroup, CommandHint, type CommandHintProps, CommandInput, CommandItem, type CommandItemProps, CommandList, CommandSeparator, Command as default };
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Command as CommandPrimitive } from "cmdk";
|
|
4
|
+
import { Search } from "lucide-react";
|
|
5
|
+
import { cn } from "../../lib/cn.js";
|
|
6
|
+
import { Dialog, DialogContent } from "../Dialog/Dialog.js";
|
|
7
|
+
import { Kbd } from "../Kbd/Kbd.js";
|
|
8
|
+
function Command({
|
|
9
|
+
className,
|
|
10
|
+
...props
|
|
11
|
+
}) {
|
|
12
|
+
return /* @__PURE__ */ jsx(
|
|
13
|
+
CommandPrimitive,
|
|
14
|
+
{
|
|
15
|
+
className: cn(
|
|
16
|
+
"flex w-full flex-col overflow-hidden rounded-(--radius) border border-(--rule-2) bg-(--paper)",
|
|
17
|
+
className
|
|
18
|
+
),
|
|
19
|
+
...props
|
|
20
|
+
}
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
function CommandInput({
|
|
24
|
+
className,
|
|
25
|
+
...props
|
|
26
|
+
}) {
|
|
27
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2.5 border-b border-(--rule) px-3.5", children: [
|
|
28
|
+
/* @__PURE__ */ jsx(Search, { size: 16, strokeWidth: 1.5, "aria-hidden": true, className: "shrink-0 text-(--ink-3-aa)" }),
|
|
29
|
+
/* @__PURE__ */ jsx(
|
|
30
|
+
CommandPrimitive.Input,
|
|
31
|
+
{
|
|
32
|
+
className: cn(
|
|
33
|
+
"h-11 w-full bg-transparent text-sm text-(--ink) outline-none placeholder:text-(--ink-3-aa)",
|
|
34
|
+
className
|
|
35
|
+
),
|
|
36
|
+
...props
|
|
37
|
+
}
|
|
38
|
+
)
|
|
39
|
+
] });
|
|
40
|
+
}
|
|
41
|
+
function CommandList({
|
|
42
|
+
className,
|
|
43
|
+
...props
|
|
44
|
+
}) {
|
|
45
|
+
return /* @__PURE__ */ jsx(
|
|
46
|
+
CommandPrimitive.List,
|
|
47
|
+
{
|
|
48
|
+
className: cn("max-h-72 overflow-y-auto overflow-x-hidden p-2 scroll-slim", className),
|
|
49
|
+
...props
|
|
50
|
+
}
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
function CommandEmpty(props) {
|
|
54
|
+
return /* @__PURE__ */ jsx(
|
|
55
|
+
CommandPrimitive.Empty,
|
|
56
|
+
{
|
|
57
|
+
className: "px-3 py-10 text-center text-sm text-(--ink-3-aa)",
|
|
58
|
+
...props
|
|
59
|
+
}
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
function CommandFooter({ className, ...props }) {
|
|
63
|
+
return /* @__PURE__ */ jsx(
|
|
64
|
+
"div",
|
|
65
|
+
{
|
|
66
|
+
className: cn(
|
|
67
|
+
"flex items-center gap-4 border-t border-(--rule) bg-(--paper-2) px-3.5 py-2",
|
|
68
|
+
className
|
|
69
|
+
),
|
|
70
|
+
...props
|
|
71
|
+
}
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
function CommandHint({ keys, children, className, ...props }) {
|
|
75
|
+
return /* @__PURE__ */ jsxs("span", { className: cn("flex items-center gap-1.5 mono-meta text-(--ink-3-aa)", className), ...props, children: [
|
|
76
|
+
keys.map((key) => /* @__PURE__ */ jsx(Kbd, { children: key }, key)),
|
|
77
|
+
children
|
|
78
|
+
] });
|
|
79
|
+
}
|
|
80
|
+
function CommandGroup({
|
|
81
|
+
className,
|
|
82
|
+
...props
|
|
83
|
+
}) {
|
|
84
|
+
return /* @__PURE__ */ jsx(
|
|
85
|
+
CommandPrimitive.Group,
|
|
86
|
+
{
|
|
87
|
+
className: cn(
|
|
88
|
+
"overflow-hidden [&_[cmdk-group-heading]]:px-2.5 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:eyebrow [&_[cmdk-group-heading]]:text-(--ink-3-aa)",
|
|
89
|
+
className
|
|
90
|
+
),
|
|
91
|
+
...props
|
|
92
|
+
}
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
function CommandSeparator({
|
|
96
|
+
className,
|
|
97
|
+
...props
|
|
98
|
+
}) {
|
|
99
|
+
return /* @__PURE__ */ jsx(
|
|
100
|
+
CommandPrimitive.Separator,
|
|
101
|
+
{
|
|
102
|
+
role: "presentation",
|
|
103
|
+
"aria-hidden": "true",
|
|
104
|
+
className: cn("my-1 h-px bg-(--rule)", className),
|
|
105
|
+
...props
|
|
106
|
+
}
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
function CommandItem({ shortcut, icon, meta, className, children, ...props }) {
|
|
110
|
+
return /* @__PURE__ */ jsxs(
|
|
111
|
+
CommandPrimitive.Item,
|
|
112
|
+
{
|
|
113
|
+
className: cn(
|
|
114
|
+
"flex cursor-pointer items-center gap-2.5 rounded-(--radius-sm) px-2.5 py-2 text-sm text-(--ink-2) outline-none transition-colors duration-(--duration-fast)",
|
|
115
|
+
// The highlighted row is a chosen state, and law 7 says a chosen state
|
|
116
|
+
// reads --accent. The leading rule gives it an edge the eye catches
|
|
117
|
+
// while scrolling, which a fill alone does not.
|
|
118
|
+
"relative data-[selected=true]:bg-(--accent-muted) data-[selected=true]:text-(--ink)",
|
|
119
|
+
"before:absolute before:inset-y-1 before:start-0 before:w-0.5 before:rounded-(--radius-pill) before:bg-transparent data-[selected=true]:before:bg-(--accent)",
|
|
120
|
+
"data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-(--disabled-opacity)",
|
|
121
|
+
className
|
|
122
|
+
),
|
|
123
|
+
...props,
|
|
124
|
+
children: [
|
|
125
|
+
icon && /* @__PURE__ */ jsx("span", { className: "grid size-4 shrink-0 place-items-center text-(--ink-3-aa) [&_svg]:size-4", children: icon }),
|
|
126
|
+
children,
|
|
127
|
+
meta && /* @__PURE__ */ jsx("span", { className: "ms-auto ps-3 mono-meta text-(--ink-3-aa)", children: meta }),
|
|
128
|
+
shortcut && /* @__PURE__ */ jsx(Kbd, { className: cn(meta ? "" : "ms-auto"), children: shortcut })
|
|
129
|
+
]
|
|
130
|
+
}
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
function CommandDialog({ open, onOpenChange, label, children }) {
|
|
134
|
+
return /* @__PURE__ */ jsx(Dialog, { open, onOpenChange, children: /* @__PURE__ */ jsx(
|
|
135
|
+
DialogContent,
|
|
136
|
+
{
|
|
137
|
+
title: label,
|
|
138
|
+
hideTitle: true,
|
|
139
|
+
showClose: false,
|
|
140
|
+
className: "top-[12vh] w-[min(92vw,40rem)] translate-y-0 overflow-hidden p-0",
|
|
141
|
+
children: /* @__PURE__ */ jsx(
|
|
142
|
+
Command,
|
|
143
|
+
{
|
|
144
|
+
label,
|
|
145
|
+
className: "rounded-none border-0 [&_[cmdk-list]]:max-h-[22rem] [&_[cmdk-list]]:scroll-hairline",
|
|
146
|
+
children
|
|
147
|
+
}
|
|
148
|
+
)
|
|
149
|
+
}
|
|
150
|
+
) });
|
|
151
|
+
}
|
|
152
|
+
var Command_default = Command;
|
|
153
|
+
export {
|
|
154
|
+
Command,
|
|
155
|
+
CommandDialog,
|
|
156
|
+
CommandEmpty,
|
|
157
|
+
CommandFooter,
|
|
158
|
+
CommandGroup,
|
|
159
|
+
CommandHint,
|
|
160
|
+
CommandInput,
|
|
161
|
+
CommandItem,
|
|
162
|
+
CommandList,
|
|
163
|
+
CommandSeparator,
|
|
164
|
+
Command_default as default
|
|
165
|
+
};
|
|
166
|
+
//# sourceMappingURL=Command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/Command/Command.tsx"],"sourcesContent":["'use client'\n\nimport { Command as CommandPrimitive } from 'cmdk'\nimport { Search } from 'lucide-react'\nimport type { ComponentProps, ReactNode } from 'react'\nimport { cn } from '../../lib/cn'\nimport { Dialog, DialogContent } from '../Dialog/Dialog'\nimport { Kbd } from '../Kbd/Kbd'\n\n/**\n * A filterable list of actions — the ⌘K surface.\n *\n * Built on cmdk rather than on a `Select` or a menu, because the interaction is\n * neither: the list is filtered as you type, the highlighted row moves with the\n * arrow keys while focus STAYS in the input, and Enter runs the highlighted\n * row. That is the ARIA combobox pattern, and it is the part nobody should\n * hand-roll — `aria-activedescendant` moving without focus moving is precisely\n * where a home-made palette stops working with a screen reader.\n *\n * @example\n * <Command label=\"Command palette\">\n * <CommandInput placeholder=\"Type a command…\" />\n * <CommandList>\n * <CommandEmpty>Nothing matches.</CommandEmpty>\n * <CommandGroup heading=\"Navigate\">\n * <CommandItem onSelect={go}>Components</CommandItem>\n * </CommandGroup>\n * </CommandList>\n * </Command>\n */\nexport function Command({\n className,\n ...props\n}: ComponentProps<typeof CommandPrimitive>) {\n return (\n <CommandPrimitive\n className={cn(\n 'flex w-full flex-col overflow-hidden rounded-(--radius) border border-(--rule-2) bg-(--paper)',\n className,\n )}\n {...props}\n />\n )\n}\n\n/** The filter field. Carries the search icon and the combobox semantics. */\nexport function CommandInput({\n className,\n ...props\n}: ComponentProps<typeof CommandPrimitive.Input>) {\n return (\n <div className=\"flex items-center gap-2.5 border-b border-(--rule) px-3.5\">\n <Search size={16} strokeWidth={1.5} aria-hidden className=\"shrink-0 text-(--ink-3-aa)\" />\n <CommandPrimitive.Input\n className={cn(\n 'h-11 w-full bg-transparent text-sm text-(--ink) outline-none placeholder:text-(--ink-3-aa)',\n className,\n )}\n {...props}\n />\n </div>\n )\n}\n\nexport function CommandList({\n className,\n ...props\n}: ComponentProps<typeof CommandPrimitive.List>) {\n return (\n <CommandPrimitive.List\n className={cn('max-h-72 overflow-y-auto overflow-x-hidden p-2 scroll-slim', className)}\n {...props}\n />\n )\n}\n\n/** Shown when the filter matches nothing. Say what would match, not \"no results\". */\nexport function CommandEmpty(props: ComponentProps<typeof CommandPrimitive.Empty>) {\n return (\n <CommandPrimitive.Empty\n className=\"px-3 py-10 text-center text-sm text-(--ink-3-aa)\"\n {...props}\n />\n )\n}\n\n/**\n * The key-hint strip along the bottom.\n *\n * A palette is a keyboard surface whose keys are invisible: nothing on screen\n * says the arrows move the row or that Enter runs it, and a reader who reaches\n * for the mouse has been failed by the design rather than by themselves.\n *\n * @example\n * <CommandFooter>\n * <CommandHint keys={['↑', '↓']}>navigate</CommandHint>\n * <CommandHint keys={['↵']}>open</CommandHint>\n * </CommandFooter>\n */\nexport function CommandFooter({ className, ...props }: ComponentProps<'div'>) {\n return (\n <div\n className={cn(\n 'flex items-center gap-4 border-t border-(--rule) bg-(--paper-2) px-3.5 py-2',\n className,\n )}\n {...props}\n />\n )\n}\n\nexport interface CommandHintProps extends Omit<ComponentProps<'span'>, 'children'> {\n /** The keys this hint describes, printed as `Kbd` chips. */\n keys: string[]\n /** What they do — a verb, lowercase, no sentence. */\n children: ReactNode\n}\n\n/** One key-and-verb pair inside a `CommandFooter`. */\nexport function CommandHint({ keys, children, className, ...props }: CommandHintProps) {\n return (\n <span className={cn('flex items-center gap-1.5 mono-meta text-(--ink-3-aa)', className)} {...props}>\n {keys.map((key) => (\n <Kbd key={key}>{key}</Kbd>\n ))}\n {children}\n </span>\n )\n}\n\nexport function CommandGroup({\n className,\n ...props\n}: ComponentProps<typeof CommandPrimitive.Group>) {\n return (\n <CommandPrimitive.Group\n className={cn(\n 'overflow-hidden [&_[cmdk-group-heading]]:px-2.5 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:eyebrow [&_[cmdk-group-heading]]:text-(--ink-3-aa)',\n className,\n )}\n {...props}\n />\n )\n}\n\n/**\n * A divider between groups.\n *\n * Marked presentational, because ARIA permits a `listbox` to contain only\n * `option` and `group` — and the library renders this as `role=\"separator\"`,\n * which puts a critical `aria-required-children` violation inside every palette\n * that uses one. The grouping is already announced by the groups themselves, so\n * removing the divider from the accessibility tree loses nothing.\n */\nexport function CommandSeparator({\n className,\n ...props\n}: ComponentProps<typeof CommandPrimitive.Separator>) {\n return (\n <CommandPrimitive.Separator\n role=\"presentation\"\n aria-hidden=\"true\"\n className={cn('my-1 h-px bg-(--rule)', className)}\n {...props}\n />\n )\n}\n\nexport interface CommandItemProps extends ComponentProps<typeof CommandPrimitive.Item> {\n /** A shortcut printed at the end of the row. */\n shortcut?: string\n /**\n * A leading glyph. Pass the icon element, sized 16.\n *\n * It is what makes a long list scannable — the eye sorts by shape before it\n * reads, and forty identical rows of text defeat that.\n */\n icon?: ReactNode\n /**\n * A quiet note at the end of the row — what kind of thing this is, or its\n * current state. Not a description: a palette that prints a sentence per row\n * stops being scannable at about six of them.\n */\n meta?: ReactNode\n}\n\nexport function CommandItem({ shortcut, icon, meta, className, children, ...props }: CommandItemProps) {\n return (\n <CommandPrimitive.Item\n className={cn(\n 'flex cursor-pointer items-center gap-2.5 rounded-(--radius-sm) px-2.5 py-2 text-sm text-(--ink-2) outline-none transition-colors duration-(--duration-fast)',\n // The highlighted row is a chosen state, and law 7 says a chosen state\n // reads --accent. The leading rule gives it an edge the eye catches\n // while scrolling, which a fill alone does not.\n 'relative data-[selected=true]:bg-(--accent-muted) data-[selected=true]:text-(--ink)',\n 'before:absolute before:inset-y-1 before:start-0 before:w-0.5 before:rounded-(--radius-pill) before:bg-transparent data-[selected=true]:before:bg-(--accent)',\n 'data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-(--disabled-opacity)',\n className,\n )}\n {...props}\n >\n {icon && (\n <span className=\"grid size-4 shrink-0 place-items-center text-(--ink-3-aa) [&_svg]:size-4\">\n {icon}\n </span>\n )}\n {children}\n {meta && <span className=\"ms-auto ps-3 mono-meta text-(--ink-3-aa)\">{meta}</span>}\n {shortcut && <Kbd className={cn(meta ? '' : 'ms-auto')}>{shortcut}</Kbd>}\n </CommandPrimitive.Item>\n )\n}\n\nexport interface CommandDialogProps {\n open: boolean\n onOpenChange: (open: boolean) => void\n /** Names the palette for assistive tech. */\n label: string\n children: ReactNode\n}\n\n/**\n * The palette in a modal, which is how it is nearly always used.\n *\n * The dialog's own padding is removed: a palette is edge-to-edge, and its input\n * is the first thing focus lands on.\n */\nexport function CommandDialog({ open, onOpenChange, label, children }: CommandDialogProps) {\n return (\n <Dialog open={open} onOpenChange={onOpenChange}>\n <DialogContent\n title={label}\n hideTitle\n showClose={false}\n // Above centre, not at it. A palette is read as a layer over the page\n // rather than as a message about it, and centring it puts the list\n // under the reader's own hands on a laptop.\n className=\"top-[12vh] w-[min(92vw,40rem)] translate-y-0 overflow-hidden p-0\"\n >\n {/* The modal has the whole screen, so its list may be taller than the\n default an inline menu should keep.\n\n `scroll-hairline` rather than `scroll-slim`: eleven pixels of grey\n down the side of a palette is the widest thing in it. */}\n <Command\n label={label}\n className=\"rounded-none border-0 [&_[cmdk-list]]:max-h-[22rem] [&_[cmdk-list]]:scroll-hairline\"\n >\n {children}\n </Command>\n </DialogContent>\n </Dialog>\n )\n}\n\nexport default Command\n"],"mappings":";AAmCI,cAgBA,YAhBA;AAjCJ,SAAS,WAAW,wBAAwB;AAC5C,SAAS,cAAc;AAEvB,SAAS,UAAU;AACnB,SAAS,QAAQ,qBAAqB;AACtC,SAAS,WAAW;AAuBb,SAAS,QAAQ;AAAA,EACtB;AAAA,EACA,GAAG;AACL,GAA4C;AAC1C,SACE;AAAA,IAAC;AAAA;AAAA,MACC,WAAW;AAAA,QACT;AAAA,QACA;AAAA,MACF;AAAA,MACC,GAAG;AAAA;AAAA,EACN;AAEJ;AAGO,SAAS,aAAa;AAAA,EAC3B;AAAA,EACA,GAAG;AACL,GAAkD;AAChD,SACE,qBAAC,SAAI,WAAU,6DACb;AAAA,wBAAC,UAAO,MAAM,IAAI,aAAa,KAAK,eAAW,MAAC,WAAU,8BAA6B;AAAA,IACvF;AAAA,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AAAA,EACN;AAEJ;AAoBO,SAAS,YAAY,EAAE,UAAU,MAAM,MAAM,WAAW,UAAU,GAAG,MAAM,GAAqB;AACrG,SACE;AAAA,IAAC,iBAAiB;AAAA,IAAjB;AAAA,MACC,WAAW;AAAA,QACT;AAAA;AAAA;AAAA;AAAA,QAIA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,MACC,GAAG;AAAA,MAEH;AAAA,gBACC,oBAAC,UAAK,WAAU,4EACb,gBACH;AAAA,QAED;AAAA,QACA,QAAQ,oBAAC,UAAK,WAAU,4CAA4C,gBAAK;AAAA,QACzE,YAAY,oBAAC,OAAI,WAAW,GAAG,OAAO,KAAK,SAAS,GAAI,oBAAS;AAAA;AAAA;AAAA,EACpE;AAEJ;AAgBO,SAAS,cAAc,EAAE,MAAM,cAAc,OAAO,SAAS,GAAuB;AACzF,SACE,oBAAC,UAAO,MAAY,cAClB;AAAA,IAAC;AAAA;AAAA,MACC,OAAO;AAAA,MACP,WAAS;AAAA,MACT,WAAW;AAAA,MAIX,WAAU;AAAA,MAOV;AAAA,QAAC;AAAA;AAAA,UACC;AAAA,UACA,WAAU;AAAA,UAET;AAAA;AAAA,MACH;AAAA;AAAA,EACF,GACF;AAEJ;AAEA,IAAO,kBAAQ;","names":[]}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ComponentProps } from 'react';
|
|
3
|
+
import * as ContextMenuPrimitive from '@radix-ui/react-context-menu';
|
|
4
|
+
import { LucideIcon } from 'lucide-react';
|
|
5
|
+
|
|
6
|
+
/** Radix ContextMenu root and trigger, as typed passthroughs. */
|
|
7
|
+
declare const ContextMenu: react.FC<ContextMenuPrimitive.ContextMenuProps>;
|
|
8
|
+
declare const ContextMenuTrigger: react.ForwardRefExoticComponent<ContextMenuPrimitive.ContextMenuTriggerProps & react.RefAttributes<HTMLSpanElement>>;
|
|
9
|
+
/**
|
|
10
|
+
* The menu a right-click opens.
|
|
11
|
+
*
|
|
12
|
+
* Never the only way to reach an action. A context menu is opened by a
|
|
13
|
+
* secondary pointer button or a keyboard's own menu key, and a meaningful share
|
|
14
|
+
* of readers have neither — a touch user, someone on a trackpad they have not
|
|
15
|
+
* configured, anyone driving the page by keyboard alone. Whatever is in here
|
|
16
|
+
* belongs somewhere reachable too: a row's overflow button, a toolbar.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* <ContextMenu>
|
|
20
|
+
* <ContextMenuTrigger asChild><Card>Right-click me</Card></ContextMenuTrigger>
|
|
21
|
+
* <ContextMenuContent>
|
|
22
|
+
* <ContextMenuItem icon={Copy}>Copy</ContextMenuItem>
|
|
23
|
+
* </ContextMenuContent>
|
|
24
|
+
* </ContextMenu>
|
|
25
|
+
*/
|
|
26
|
+
declare function ContextMenuContent({ className, ...rest }: ComponentProps<typeof ContextMenuPrimitive.Content>): react.JSX.Element;
|
|
27
|
+
interface ContextMenuItemProps extends ComponentProps<typeof ContextMenuPrimitive.Item> {
|
|
28
|
+
icon?: LucideIcon;
|
|
29
|
+
destructive?: boolean;
|
|
30
|
+
}
|
|
31
|
+
/** A row. Highlight follows `data-highlighted`, which covers hover and keyboard. */
|
|
32
|
+
declare function ContextMenuItem({ icon: Icon, destructive, className, children, ...rest }: ContextMenuItemProps): react.JSX.Element;
|
|
33
|
+
/** Hairline divider between groups. */
|
|
34
|
+
declare function ContextMenuSeparator({ className, ...rest }: ComponentProps<typeof ContextMenuPrimitive.Separator>): react.JSX.Element;
|
|
35
|
+
/** Mono eyebrow heading for a group. */
|
|
36
|
+
declare function ContextMenuLabel({ className, ...rest }: ComponentProps<typeof ContextMenuPrimitive.Label>): react.JSX.Element;
|
|
37
|
+
|
|
38
|
+
export { ContextMenu, ContextMenuContent, ContextMenuItem, type ContextMenuItemProps, ContextMenuLabel, ContextMenuSeparator, ContextMenuTrigger, ContextMenu as default };
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import * as ContextMenuPrimitive from "@radix-ui/react-context-menu";
|
|
4
|
+
import { cn } from "../../lib/cn.js";
|
|
5
|
+
import { useOverlayContainer } from "../../lib/overlay-container.js";
|
|
6
|
+
const ContextMenu = ContextMenuPrimitive.Root;
|
|
7
|
+
const ContextMenuTrigger = ContextMenuPrimitive.Trigger;
|
|
8
|
+
function ContextMenuContent({
|
|
9
|
+
className,
|
|
10
|
+
...rest
|
|
11
|
+
}) {
|
|
12
|
+
const container = useOverlayContainer();
|
|
13
|
+
return /* @__PURE__ */ jsx(ContextMenuPrimitive.Portal, { container: container ?? void 0, children: /* @__PURE__ */ jsx(
|
|
14
|
+
ContextMenuPrimitive.Content,
|
|
15
|
+
{
|
|
16
|
+
collisionBoundary: container ?? void 0,
|
|
17
|
+
collisionPadding: 8,
|
|
18
|
+
"data-m22-animated": true,
|
|
19
|
+
className: cn(
|
|
20
|
+
"z-(--z-dropdown) min-w-44 rounded-(--radius) border border-(--rule-2) bg-(--paper) p-1.5",
|
|
21
|
+
"data-[state=open]:animate-[m22-pop-in_var(--duration-fast)_var(--ease-out-expo)] data-[state=closed]:animate-[m22-pop-out_var(--duration-fast)_var(--ease)] origin-(--radix-popper-transform-origin)",
|
|
22
|
+
className
|
|
23
|
+
),
|
|
24
|
+
...rest
|
|
25
|
+
}
|
|
26
|
+
) });
|
|
27
|
+
}
|
|
28
|
+
function ContextMenuItem({
|
|
29
|
+
icon: Icon,
|
|
30
|
+
destructive = false,
|
|
31
|
+
className,
|
|
32
|
+
children,
|
|
33
|
+
...rest
|
|
34
|
+
}) {
|
|
35
|
+
return /* @__PURE__ */ jsxs(
|
|
36
|
+
ContextMenuPrimitive.Item,
|
|
37
|
+
{
|
|
38
|
+
className: cn(
|
|
39
|
+
"flex cursor-pointer items-center gap-2.5 rounded-(--radius-sm) px-2.5 py-2 text-sm outline-none transition-colors duration-(--duration-fast) data-[highlighted]:bg-(--stone) data-[disabled]:pointer-events-none data-[disabled]:opacity-(--disabled-opacity)",
|
|
40
|
+
destructive ? "text-(--danger)" : "text-(--ink-2) data-[highlighted]:text-(--ink)",
|
|
41
|
+
className
|
|
42
|
+
),
|
|
43
|
+
...rest,
|
|
44
|
+
children: [
|
|
45
|
+
Icon && /* @__PURE__ */ jsx(Icon, { size: 16, strokeWidth: 1.5, className: "shrink-0", "aria-hidden": true }),
|
|
46
|
+
children
|
|
47
|
+
]
|
|
48
|
+
}
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
function ContextMenuSeparator({
|
|
52
|
+
className,
|
|
53
|
+
...rest
|
|
54
|
+
}) {
|
|
55
|
+
return /* @__PURE__ */ jsx(ContextMenuPrimitive.Separator, { className: cn("my-1 h-px bg-(--rule)", className), ...rest });
|
|
56
|
+
}
|
|
57
|
+
function ContextMenuLabel({
|
|
58
|
+
className,
|
|
59
|
+
...rest
|
|
60
|
+
}) {
|
|
61
|
+
return /* @__PURE__ */ jsx(
|
|
62
|
+
ContextMenuPrimitive.Label,
|
|
63
|
+
{
|
|
64
|
+
className: cn("px-2.5 py-1.5 eyebrow text-(--ink-3-aa)", className),
|
|
65
|
+
...rest
|
|
66
|
+
}
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
var ContextMenu_default = ContextMenu;
|
|
70
|
+
export {
|
|
71
|
+
ContextMenu,
|
|
72
|
+
ContextMenuContent,
|
|
73
|
+
ContextMenuItem,
|
|
74
|
+
ContextMenuLabel,
|
|
75
|
+
ContextMenuSeparator,
|
|
76
|
+
ContextMenuTrigger,
|
|
77
|
+
ContextMenu_default as default
|
|
78
|
+
};
|
|
79
|
+
//# sourceMappingURL=ContextMenu.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/ContextMenu/ContextMenu.tsx"],"sourcesContent":["'use client'\n\nimport * as ContextMenuPrimitive from '@radix-ui/react-context-menu'\nimport type { LucideIcon } from 'lucide-react'\nimport type { ComponentProps } from 'react'\nimport { cn } from '../../lib/cn'\nimport { useOverlayContainer } from '../../lib/overlay-container'\n\n/** Radix ContextMenu root and trigger, as typed passthroughs. */\nexport const ContextMenu = ContextMenuPrimitive.Root\nexport const ContextMenuTrigger = ContextMenuPrimitive.Trigger\n\n/**\n * The menu a right-click opens.\n *\n * Never the only way to reach an action. A context menu is opened by a\n * secondary pointer button or a keyboard's own menu key, and a meaningful share\n * of readers have neither — a touch user, someone on a trackpad they have not\n * configured, anyone driving the page by keyboard alone. Whatever is in here\n * belongs somewhere reachable too: a row's overflow button, a toolbar.\n *\n * @example\n * <ContextMenu>\n * <ContextMenuTrigger asChild><Card>Right-click me</Card></ContextMenuTrigger>\n * <ContextMenuContent>\n * <ContextMenuItem icon={Copy}>Copy</ContextMenuItem>\n * </ContextMenuContent>\n * </ContextMenu>\n */\nexport function ContextMenuContent({\n className,\n ...rest\n}: ComponentProps<typeof ContextMenuPrimitive.Content>) {\n const container = useOverlayContainer()\n\n return (\n <ContextMenuPrimitive.Portal container={container ?? undefined}>\n <ContextMenuPrimitive.Content\n collisionBoundary={container ?? undefined}\n collisionPadding={8}\n data-m22-animated\n className={cn(\n 'z-(--z-dropdown) min-w-44 rounded-(--radius) border border-(--rule-2) bg-(--paper) p-1.5',\n 'data-[state=open]:animate-[m22-pop-in_var(--duration-fast)_var(--ease-out-expo)] data-[state=closed]:animate-[m22-pop-out_var(--duration-fast)_var(--ease)] origin-(--radix-popper-transform-origin)',\n className,\n )}\n {...rest}\n />\n </ContextMenuPrimitive.Portal>\n )\n}\n\nexport interface ContextMenuItemProps\n extends ComponentProps<typeof ContextMenuPrimitive.Item> {\n icon?: LucideIcon\n destructive?: boolean\n}\n\n/** A row. Highlight follows `data-highlighted`, which covers hover and keyboard. */\nexport function ContextMenuItem({\n icon: Icon,\n destructive = false,\n className,\n children,\n ...rest\n}: ContextMenuItemProps) {\n return (\n <ContextMenuPrimitive.Item\n className={cn(\n 'flex cursor-pointer items-center gap-2.5 rounded-(--radius-sm) px-2.5 py-2 text-sm outline-none transition-colors duration-(--duration-fast) data-[highlighted]:bg-(--stone) data-[disabled]:pointer-events-none data-[disabled]:opacity-(--disabled-opacity)',\n destructive ? 'text-(--danger)' : 'text-(--ink-2) data-[highlighted]:text-(--ink)',\n className,\n )}\n {...rest}\n >\n {Icon && <Icon size={16} strokeWidth={1.5} className=\"shrink-0\" aria-hidden />}\n {children}\n </ContextMenuPrimitive.Item>\n )\n}\n\n/** Hairline divider between groups. */\nexport function ContextMenuSeparator({\n className,\n ...rest\n}: ComponentProps<typeof ContextMenuPrimitive.Separator>) {\n return (\n <ContextMenuPrimitive.Separator className={cn('my-1 h-px bg-(--rule)', className)} {...rest} />\n )\n}\n\n/** Mono eyebrow heading for a group. */\nexport function ContextMenuLabel({\n className,\n ...rest\n}: ComponentProps<typeof ContextMenuPrimitive.Label>) {\n return (\n <ContextMenuPrimitive.Label\n className={cn('px-2.5 py-1.5 eyebrow text-(--ink-3-aa)', className)}\n {...rest}\n />\n )\n}\n\nexport default ContextMenu\n"],"mappings":";AAqCM,cA8BF,YA9BE;AAnCN,YAAY,0BAA0B;AAGtC,SAAS,UAAU;AACnB,SAAS,2BAA2B;AAG7B,MAAM,cAAc,qBAAqB;AACzC,MAAM,qBAAqB,qBAAqB;AAmBhD,SAAS,mBAAmB;AAAA,EACjC;AAAA,EACA,GAAG;AACL,GAAwD;AACtD,QAAM,YAAY,oBAAoB;AAEtC,SACE,oBAAC,qBAAqB,QAArB,EAA4B,WAAW,aAAa,QACnD;AAAA,IAAC,qBAAqB;AAAA,IAArB;AAAA,MACC,mBAAmB,aAAa;AAAA,MAChC,kBAAkB;AAAA,MAClB,qBAAiB;AAAA,MACjB,WAAW;AAAA,QACT;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,MACC,GAAG;AAAA;AAAA,EACN,GACF;AAEJ;AASO,SAAS,gBAAgB;AAAA,EAC9B,MAAM;AAAA,EACN,cAAc;AAAA,EACd;AAAA,EACA;AAAA,EACA,GAAG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