@seekalfred/primitives 0.7.1 → 0.7.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +255 -5
- package/dist/alert/alert.d.ts +49 -4
- package/dist/alert/alert.js +66 -38
- package/dist/alert/alert.js.map +1 -1
- package/dist/alert/index.d.ts +2 -2
- package/dist/alert/index.js +2 -2
- package/dist/alert-dialog/alert-dialog.d.ts +31 -4
- package/dist/alert-dialog/alert-dialog.js +75 -26
- package/dist/alert-dialog/alert-dialog.js.map +1 -1
- package/dist/announcement-bar/announcement-bar.d.ts +15 -4
- package/dist/announcement-bar/announcement-bar.js +31 -6
- package/dist/announcement-bar/announcement-bar.js.map +1 -1
- package/dist/avatar/avatar.d.ts +7 -0
- package/dist/avatar/avatar.js +33 -12
- package/dist/avatar/avatar.js.map +1 -1
- package/dist/badge/badge.d.ts +1 -1
- package/dist/bar-chart/bar-chart-series.d.ts +75 -0
- package/dist/bar-chart/bar-chart-series.js +401 -0
- package/dist/bar-chart/bar-chart-series.js.map +1 -0
- package/dist/bar-chart/bar-chart.d.ts +25 -1
- package/dist/bar-chart/bar-chart.js +26 -1
- package/dist/bar-chart/bar-chart.js.map +1 -1
- package/dist/bar-chart/index.d.ts +2 -1
- package/dist/button/button.d.ts +1 -1
- package/dist/calendar/calendar.d.ts +1 -1
- package/dist/card/card.d.ts +22 -1
- package/dist/card/card.js +60 -7
- package/dist/card/card.js.map +1 -1
- package/dist/carousel/carousel.d.ts +21 -0
- package/dist/carousel/carousel.js +34 -8
- package/dist/carousel/carousel.js.map +1 -1
- package/dist/chip-group/chip-group.d.ts +11 -0
- package/dist/chip-group/chip-group.js +50 -34
- package/dist/chip-group/chip-group.js.map +1 -1
- package/dist/chip-group/index.d.ts +2 -2
- package/dist/copy-button/copy-button.d.ts +37 -5
- package/dist/copy-button/copy-button.js +35 -11
- package/dist/copy-button/copy-button.js.map +1 -1
- package/dist/donut-chart/donut-chart.d.ts +22 -0
- package/dist/donut-chart/donut-chart.js +35 -18
- package/dist/donut-chart/donut-chart.js.map +1 -1
- package/dist/donut-chart/index.d.ts +2 -2
- package/dist/empty-state/empty-state.d.ts +21 -0
- package/dist/empty-state/empty-state.js +16 -4
- package/dist/empty-state/empty-state.js.map +1 -1
- package/dist/empty-state/index.d.ts +2 -2
- package/dist/empty-state/index.js +2 -2
- package/dist/file-drop-zone/file-drop-zone.d.ts +29 -3
- package/dist/file-drop-zone/file-drop-zone.js +26 -8
- package/dist/file-drop-zone/file-drop-zone.js.map +1 -1
- package/dist/filter-bar/filter-bar.d.ts +4 -1
- package/dist/filter-bar/filter-bar.js +53 -9
- package/dist/filter-bar/filter-bar.js.map +1 -1
- package/dist/gauge/gauge.d.ts +18 -1
- package/dist/gauge/gauge.js +35 -21
- package/dist/gauge/gauge.js.map +1 -1
- package/dist/gauge/index.d.ts +2 -2
- package/dist/index.d.ts +15 -14
- package/dist/index.js +9 -9
- package/dist/input/input.d.ts +7 -0
- package/dist/input/input.js +7 -5
- package/dist/input/input.js.map +1 -1
- package/dist/lib/field-shell.js +6 -3
- package/dist/lib/field-shell.js.map +1 -1
- package/dist/lib/field-surface.js +22 -1
- package/dist/lib/field-surface.js.map +1 -1
- package/dist/lib/required-marker.js +20 -0
- package/dist/lib/required-marker.js.map +1 -0
- package/dist/lib/use-copy-feedback.js +17 -3
- package/dist/lib/use-copy-feedback.js.map +1 -1
- package/dist/line-chart/index.d.ts +2 -2
- package/dist/line-chart/line-chart.d.ts +144 -2
- package/dist/line-chart/line-chart.js +314 -46
- package/dist/line-chart/line-chart.js.map +1 -1
- package/dist/money-input/index.d.ts +2 -2
- package/dist/money-input/money-input.d.ts +36 -1
- package/dist/money-input/money-input.js +30 -14
- package/dist/money-input/money-input.js.map +1 -1
- package/dist/morph-select/morph-select.d.ts +26 -1
- package/dist/morph-select/morph-select.js +28 -6
- package/dist/morph-select/morph-select.js.map +1 -1
- package/dist/multi-select/index.d.ts +2 -2
- package/dist/multi-select/index.js +2 -2
- package/dist/multi-select/multi-select.d.ts +74 -2
- package/dist/multi-select/multi-select.js +213 -39
- package/dist/multi-select/multi-select.js.map +1 -1
- package/dist/password-field/password-field.d.ts +16 -0
- package/dist/password-field/password-field.js +37 -8
- package/dist/password-field/password-field.js.map +1 -1
- package/dist/popover/index.d.ts +2 -2
- package/dist/popover/index.js +2 -2
- package/dist/popover/popover.d.ts +39 -2
- package/dist/popover/popover.js +29 -2
- package/dist/popover/popover.js.map +1 -1
- package/dist/progress/index.d.ts +2 -2
- package/dist/progress/index.js +2 -2
- package/dist/progress/progress.d.ts +68 -3
- package/dist/progress/progress.js +156 -39
- package/dist/progress/progress.js.map +1 -1
- package/dist/radio-group/index.d.ts +2 -2
- package/dist/radio-group/index.js +2 -2
- package/dist/radio-group/radio-group.d.ts +33 -3
- package/dist/radio-group/radio-group.js +109 -9
- package/dist/radio-group/radio-group.js.map +1 -1
- package/dist/scroll-area/scroll-area.js +4 -3
- package/dist/scroll-area/scroll-area.js.map +1 -1
- package/dist/scrub-input/scrub-input.d.ts +11 -1
- package/dist/scrub-input/scrub-input.js +22 -10
- package/dist/scrub-input/scrub-input.js.map +1 -1
- package/dist/search-field/search-field.d.ts +22 -1
- package/dist/search-field/search-field.js +22 -7
- package/dist/search-field/search-field.js.map +1 -1
- package/dist/select/select.d.ts +10 -1
- package/dist/select/select.js +11 -8
- package/dist/select/select.js.map +1 -1
- package/dist/separator/separator.d.ts +21 -9
- package/dist/separator/separator.js +33 -11
- package/dist/separator/separator.js.map +1 -1
- package/dist/sparkline/sparkline.d.ts +27 -2
- package/dist/sparkline/sparkline.js +115 -18
- package/dist/sparkline/sparkline.js.map +1 -1
- package/dist/stat-card/index.d.ts +2 -2
- package/dist/stat-card/index.js +2 -2
- package/dist/stat-card/stat-card.d.ts +65 -1
- package/dist/stat-card/stat-card.js +98 -25
- package/dist/stat-card/stat-card.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/table/index.d.ts +2 -2
- package/dist/table/index.js +2 -2
- package/dist/table/table.d.ts +115 -5
- package/dist/table/table.js +374 -94
- package/dist/table/table.js.map +1 -1
- package/dist/text-shimmer/text-shimmer.d.ts +18 -2
- package/dist/text-shimmer/text-shimmer.js +5 -2
- package/dist/text-shimmer/text-shimmer.js.map +1 -1
- package/dist/textarea/textarea.d.ts +7 -0
- package/dist/textarea/textarea.js +3 -1
- package/dist/textarea/textarea.js.map +1 -1
- package/dist/time-picker/time-picker.d.ts +36 -1
- package/dist/time-picker/time-picker.js +33 -5
- package/dist/time-picker/time-picker.js.map +1 -1
- package/dist/toast/toast.d.ts +2 -2
- package/dist/usage-meter/index.d.ts +2 -2
- package/dist/usage-meter/usage-meter.d.ts +30 -0
- package/dist/usage-meter/usage-meter.js +56 -38
- package/dist/usage-meter/usage-meter.js.map +1 -1
- package/package.json +3 -3
|
@@ -2,14 +2,99 @@
|
|
|
2
2
|
import { cn, cnAll } from "../lib/cn.js";
|
|
3
3
|
import { SwapText } from "../lib/swap-text.js";
|
|
4
4
|
import { useFlip } from "../lib/flip.js";
|
|
5
|
+
import { Tooltip as Tooltip$1, TooltipTrigger as TooltipTrigger$1 } from "../tooltip/tooltip.js";
|
|
5
6
|
import { labelVariants } from "../label/label.js";
|
|
6
|
-
import { selectPopoverVariants, selectTriggerVariants, selectVariants } from "../select/select.js";
|
|
7
|
+
import { selectItemVariants, selectPopoverVariants, selectTriggerVariants, selectVariants } from "../select/select.js";
|
|
8
|
+
import { cva } from "class-variance-authority";
|
|
7
9
|
import { forwardRef, useContext, useRef, useState } from "react";
|
|
8
|
-
import { Button, ButtonContext, FieldError, Label, ListBox, Popover, Select, SelectStateContext, SelectValue } from "react-aria-components";
|
|
10
|
+
import { Autocomplete, Button, ButtonContext, FieldError, Header, Input, Label, ListBox, ListBoxItem, ListBoxSection, Popover, SearchField, Select, SelectStateContext, SelectValue, useFilter } from "react-aria-components";
|
|
9
11
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
10
12
|
//#region src/multi-select/multi-select.tsx
|
|
13
|
+
/** The key of the create row. Never reaches `onChange`. */
|
|
14
|
+
const CREATE_KEY = "__multi-select-create__";
|
|
15
|
+
const defaultCreateLabel = (value) => `Create \u201c${value}\u201d`;
|
|
16
|
+
/** Whether `text` already names an option (by its text or its key) or a pick, ignoring case. */
|
|
17
|
+
function isTaken(state, text) {
|
|
18
|
+
const want = text.toLocaleLowerCase();
|
|
19
|
+
if ((state?.value ?? []).some((key) => String(key).toLocaleLowerCase() === want)) return true;
|
|
20
|
+
if (!state) return false;
|
|
21
|
+
for (const key of state.collection.getKeys()) {
|
|
22
|
+
const node = state.collection.getItem(key);
|
|
23
|
+
if (node?.type === "item" && node.key !== CREATE_KEY && (node.textValue.toLocaleLowerCase() === want || String(node.key).toLocaleLowerCase() === want)) return true;
|
|
24
|
+
}
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The list with a search field over it (React Aria's Autocomplete): the field
|
|
29
|
+
* keeps focus and drives the options with the arrow keys, Enter picks.
|
|
30
|
+
*/
|
|
31
|
+
function SearchList({ query, onQueryChange, creatable, searchLabel, searchPlaceholder, emptyLabel, children }) {
|
|
32
|
+
const state = useContext(SelectStateContext);
|
|
33
|
+
const { contains } = useFilter({ sensitivity: "base" });
|
|
34
|
+
const text = query.trim();
|
|
35
|
+
const offerCreate = creatable && text !== "" && !isTaken(state, text);
|
|
36
|
+
return /* @__PURE__ */ jsxs(Autocomplete, {
|
|
37
|
+
inputValue: query,
|
|
38
|
+
onInputChange: onQueryChange,
|
|
39
|
+
filter: (textValue, input, node) => node.key === CREATE_KEY ? offerCreate : contains(textValue, input),
|
|
40
|
+
children: [/* @__PURE__ */ jsxs(SearchField, {
|
|
41
|
+
"aria-label": searchLabel,
|
|
42
|
+
autoFocus: true,
|
|
43
|
+
"data-slot": "multi-select-search",
|
|
44
|
+
className: multiSelectSearchClass,
|
|
45
|
+
children: [/* @__PURE__ */ jsxs("svg", {
|
|
46
|
+
"aria-hidden": "true",
|
|
47
|
+
viewBox: "0 0 16 16",
|
|
48
|
+
fill: "none",
|
|
49
|
+
stroke: "currentColor",
|
|
50
|
+
strokeWidth: "1.75",
|
|
51
|
+
strokeLinecap: "round",
|
|
52
|
+
className: "size-4 flex-none text-muted-foreground",
|
|
53
|
+
children: [/* @__PURE__ */ jsx("circle", {
|
|
54
|
+
cx: "7",
|
|
55
|
+
cy: "7",
|
|
56
|
+
r: "4.5"
|
|
57
|
+
}), /* @__PURE__ */ jsx("path", { d: "m10.5 10.5 3 3" })]
|
|
58
|
+
}), /* @__PURE__ */ jsx(Input, {
|
|
59
|
+
placeholder: searchPlaceholder,
|
|
60
|
+
"data-slot": "multi-select-search-input",
|
|
61
|
+
className: "min-w-0 flex-1 appearance-none border-0 bg-transparent p-0 font-sans text-sm text-foreground outline-none placeholder:text-muted-foreground [&::-webkit-search-cancel-button]:hidden"
|
|
62
|
+
})]
|
|
63
|
+
}), /* @__PURE__ */ jsx(ListBox, {
|
|
64
|
+
"data-slot": "multi-select-list",
|
|
65
|
+
renderEmptyState: () => /* @__PURE__ */ jsx("p", {
|
|
66
|
+
"data-slot": "multi-select-empty",
|
|
67
|
+
className: "m-0 px-2 py-1.5 text-sm text-muted-foreground",
|
|
68
|
+
children: emptyLabel
|
|
69
|
+
}),
|
|
70
|
+
className: "min-h-0 flex-1 overflow-y-auto outline-none",
|
|
71
|
+
children
|
|
72
|
+
})]
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
/** The search row: a quiet field over the list, underlined while focused. */
|
|
76
|
+
const multiSelectSearchClass = "relative mb-1 flex h-(--density-control-h-sm) flex-none items-center gap-2 border-b-(length:--border-width) border-border px-2 after:pointer-events-none after:absolute after:inset-x-0 after:bottom-0 after:h-(--focus-ring-width) after:bg-transparent has-[input:focus]:after:bg-(--color-control-edge)";
|
|
77
|
+
/** The row that creates the typed value. Kept in the collection; the filter shows it. */
|
|
78
|
+
function CreateItem({ label }) {
|
|
79
|
+
return /* @__PURE__ */ jsxs(ListBoxItem, {
|
|
80
|
+
id: CREATE_KEY,
|
|
81
|
+
textValue: label,
|
|
82
|
+
"data-slot": "multi-select-create",
|
|
83
|
+
className: cnAll(selectItemVariants(), "text-text-secondary data-[focused]:text-foreground"),
|
|
84
|
+
children: [/* @__PURE__ */ jsx("svg", {
|
|
85
|
+
"aria-hidden": "true",
|
|
86
|
+
viewBox: "0 0 16 16",
|
|
87
|
+
fill: "none",
|
|
88
|
+
stroke: "currentColor",
|
|
89
|
+
strokeWidth: "1.75",
|
|
90
|
+
strokeLinecap: "round",
|
|
91
|
+
className: "size-3.5 flex-none",
|
|
92
|
+
children: /* @__PURE__ */ jsx("path", { d: "M8 3.5v9M3.5 8h9" })
|
|
93
|
+
}), label]
|
|
94
|
+
});
|
|
95
|
+
}
|
|
11
96
|
/** The picked options as chips, then "+N", reading Select's own state. */
|
|
12
|
-
function Chips({ placeholder, maxVisible }) {
|
|
97
|
+
function Chips({ placeholder, maxVisible, moreLabel, moreRef }) {
|
|
13
98
|
const state = useContext(SelectStateContext);
|
|
14
99
|
const keys = state?.value ?? [];
|
|
15
100
|
const labelOf = (key) => state?.collection.getItem(key)?.textValue ?? String(key);
|
|
@@ -43,19 +128,50 @@ function Chips({ placeholder, maxVisible }) {
|
|
|
43
128
|
children: labelOf(key)
|
|
44
129
|
}, String(key))),
|
|
45
130
|
rest > 0 ? /* @__PURE__ */ jsxs("span", {
|
|
131
|
+
ref: moreRef,
|
|
46
132
|
"data-flip": "",
|
|
47
133
|
"data-slot": "multi-select-more",
|
|
48
134
|
className: "multi-select-chip text-text-secondary tabular-nums",
|
|
49
|
-
children: [
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
135
|
+
children: [
|
|
136
|
+
"+",
|
|
137
|
+
/* @__PURE__ */ jsx(SwapText, {
|
|
138
|
+
swapKey: String(rest),
|
|
139
|
+
dir: count.dir,
|
|
140
|
+
motion: "rise",
|
|
141
|
+
children: rest
|
|
142
|
+
}),
|
|
143
|
+
moreLabel ? /* @__PURE__ */ jsx("span", {
|
|
144
|
+
"data-slot": "multi-select-more-label",
|
|
145
|
+
className: "whitespace-pre",
|
|
146
|
+
children: ` ${moreLabel}`
|
|
147
|
+
}) : null
|
|
148
|
+
]
|
|
55
149
|
}) : null
|
|
56
150
|
]
|
|
57
151
|
});
|
|
58
152
|
}
|
|
153
|
+
/** The labels of the picks folded into "+N", in the order they were picked. */
|
|
154
|
+
function useHiddenLabels(maxVisible) {
|
|
155
|
+
const state = useContext(SelectStateContext);
|
|
156
|
+
return (state?.value ?? []).slice(maxVisible).map((key) => state?.collection.getItem(key)?.textValue ?? String(key));
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Wraps the trigger in a tooltip naming the picks hidden behind "+N", placed
|
|
160
|
+
* against the +N chip rather than the whole field. Always rendered, so turning
|
|
161
|
+
* `overflowTooltip` on or off never swaps the trigger element (and drops its
|
|
162
|
+
* focus); disabled while off or while nothing is hidden, so it never opens empty.
|
|
163
|
+
*/
|
|
164
|
+
function OverflowTooltip({ enabled, maxVisible, anchorRef, children }) {
|
|
165
|
+
const hidden = useHiddenLabels(maxVisible);
|
|
166
|
+
return /* @__PURE__ */ jsxs(TooltipTrigger$1, {
|
|
167
|
+
isDisabled: !enabled || hidden.length === 0,
|
|
168
|
+
children: [children, /* @__PURE__ */ jsx(Tooltip$1, {
|
|
169
|
+
triggerRef: anchorRef,
|
|
170
|
+
"data-slot": "multi-select-overflow-tooltip",
|
|
171
|
+
children: hidden.join(", ")
|
|
172
|
+
})]
|
|
173
|
+
});
|
|
174
|
+
}
|
|
59
175
|
/** Clears every pick. It sits outside the trigger, so it is its own tab stop. */
|
|
60
176
|
function Clear({ label, disabled }) {
|
|
61
177
|
const state = useContext(SelectStateContext);
|
|
@@ -84,9 +200,65 @@ function Clear({ label, disabled }) {
|
|
|
84
200
|
})
|
|
85
201
|
});
|
|
86
202
|
}
|
|
87
|
-
const MultiSelect = forwardRef(function MultiSelect({ children, label, labelHidden, placeholder = "Select options", errorMessage, maxVisible = 2, clearLabel = "Clear selections", size = "md", className, ...props }, ref) {
|
|
203
|
+
const MultiSelect = forwardRef(function MultiSelect({ children, label, labelHidden, placeholder = "Select options", errorMessage, maxVisible = 2, moreLabel, overflowTooltip = false, clearLabel = "Clear selections", size = "md", className, searchable = false, searchLabel = "Search options", searchPlaceholder = "Search", emptyLabel = "No options found", onCreate, createLabel = defaultCreateLabel, ...props }, ref) {
|
|
204
|
+
const moreRef = useRef(null);
|
|
205
|
+
const creatable = onCreate != null;
|
|
206
|
+
const withSearch = searchable || creatable;
|
|
207
|
+
const [query, setQuery] = useState("");
|
|
208
|
+
const [ownValue, setOwnValue] = useState(() => props.defaultValue ?? []);
|
|
209
|
+
const value = props.value ?? ownValue;
|
|
210
|
+
const creatableProps = creatable ? {
|
|
211
|
+
value,
|
|
212
|
+
defaultValue: void 0,
|
|
213
|
+
onChange: (keys) => {
|
|
214
|
+
let next = keys;
|
|
215
|
+
if (keys.includes(CREATE_KEY)) {
|
|
216
|
+
const text = query.trim();
|
|
217
|
+
next = keys.filter((key) => key !== CREATE_KEY);
|
|
218
|
+
if (text !== "" && !next.includes(text)) next.push(text);
|
|
219
|
+
setQuery("");
|
|
220
|
+
onCreate(text);
|
|
221
|
+
}
|
|
222
|
+
setOwnValue(next);
|
|
223
|
+
props.onChange?.(next);
|
|
224
|
+
}
|
|
225
|
+
} : {};
|
|
226
|
+
const trigger = /* @__PURE__ */ jsxs(Button, {
|
|
227
|
+
ref,
|
|
228
|
+
"data-slot": "multi-select-trigger",
|
|
229
|
+
className: cnAll(selectTriggerVariants({ size }), "pe-16 multi-select-trigger"),
|
|
230
|
+
children: [
|
|
231
|
+
/* @__PURE__ */ jsx(SelectValue, {
|
|
232
|
+
"data-slot": "multi-select-value",
|
|
233
|
+
className: "sr-only",
|
|
234
|
+
children: ({ isPlaceholder, selectedText }) => isPlaceholder ? placeholder : selectedText
|
|
235
|
+
}),
|
|
236
|
+
/* @__PURE__ */ jsx(Chips, {
|
|
237
|
+
placeholder,
|
|
238
|
+
maxVisible,
|
|
239
|
+
moreLabel,
|
|
240
|
+
moreRef
|
|
241
|
+
}),
|
|
242
|
+
/* @__PURE__ */ jsx("svg", {
|
|
243
|
+
"aria-hidden": "true",
|
|
244
|
+
viewBox: "0 0 16 16",
|
|
245
|
+
fill: "none",
|
|
246
|
+
stroke: "currentColor",
|
|
247
|
+
strokeWidth: "1.75",
|
|
248
|
+
strokeLinecap: "round",
|
|
249
|
+
strokeLinejoin: "round",
|
|
250
|
+
className: "absolute end-(--density-control-pad-md) text-muted-foreground motion-safe:transition-[rotate] motion-safe:duration-(--duration-gentle) motion-safe:ease-gentle group-aria-expanded/trigger:rotate-180",
|
|
251
|
+
children: /* @__PURE__ */ jsx("path", { d: "m4 6 4 4 4-4" })
|
|
252
|
+
})
|
|
253
|
+
]
|
|
254
|
+
});
|
|
88
255
|
return /* @__PURE__ */ jsxs(Select, {
|
|
89
256
|
...props,
|
|
257
|
+
...creatableProps,
|
|
258
|
+
onOpenChange: (isOpen) => {
|
|
259
|
+
if (!isOpen) setQuery("");
|
|
260
|
+
props.onOpenChange?.(isOpen);
|
|
261
|
+
},
|
|
90
262
|
selectionMode: "multiple",
|
|
91
263
|
"data-slot": "multi-select",
|
|
92
264
|
className: cn(selectVariants(), className),
|
|
@@ -98,32 +270,11 @@ const MultiSelect = forwardRef(function MultiSelect({ children, label, labelHidd
|
|
|
98
270
|
}),
|
|
99
271
|
/* @__PURE__ */ jsxs("div", {
|
|
100
272
|
className: "relative",
|
|
101
|
-
children: [/* @__PURE__ */
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
children:
|
|
106
|
-
/* @__PURE__ */ jsx(SelectValue, {
|
|
107
|
-
"data-slot": "multi-select-value",
|
|
108
|
-
className: "sr-only",
|
|
109
|
-
children: ({ isPlaceholder, selectedText }) => isPlaceholder ? placeholder : selectedText
|
|
110
|
-
}),
|
|
111
|
-
/* @__PURE__ */ jsx(Chips, {
|
|
112
|
-
placeholder,
|
|
113
|
-
maxVisible
|
|
114
|
-
}),
|
|
115
|
-
/* @__PURE__ */ jsx("svg", {
|
|
116
|
-
"aria-hidden": "true",
|
|
117
|
-
viewBox: "0 0 16 16",
|
|
118
|
-
fill: "none",
|
|
119
|
-
stroke: "currentColor",
|
|
120
|
-
strokeWidth: "1.75",
|
|
121
|
-
strokeLinecap: "round",
|
|
122
|
-
strokeLinejoin: "round",
|
|
123
|
-
className: "absolute end-(--density-control-pad-md) text-muted-foreground motion-safe:transition-[rotate] motion-safe:duration-(--duration-gentle) motion-safe:ease-gentle group-aria-expanded/trigger:rotate-180",
|
|
124
|
-
children: /* @__PURE__ */ jsx("path", { d: "m4 6 4 4 4-4" })
|
|
125
|
-
})
|
|
126
|
-
]
|
|
273
|
+
children: [/* @__PURE__ */ jsx(OverflowTooltip, {
|
|
274
|
+
enabled: overflowTooltip,
|
|
275
|
+
maxVisible,
|
|
276
|
+
anchorRef: moreRef,
|
|
277
|
+
children: trigger
|
|
127
278
|
}), /* @__PURE__ */ jsx(Clear, {
|
|
128
279
|
label: clearLabel,
|
|
129
280
|
disabled: props.isDisabled ?? false
|
|
@@ -136,8 +287,16 @@ const MultiSelect = forwardRef(function MultiSelect({ children, label, labelHidd
|
|
|
136
287
|
}),
|
|
137
288
|
/* @__PURE__ */ jsx(Popover, {
|
|
138
289
|
"data-slot": "multi-select-popover",
|
|
139
|
-
className: selectPopoverVariants(),
|
|
140
|
-
children: /* @__PURE__ */
|
|
290
|
+
className: withSearch ? cnAll(selectPopoverVariants({ reveal: "fade" }), "flex flex-col overflow-y-hidden") : selectPopoverVariants(),
|
|
291
|
+
children: withSearch ? /* @__PURE__ */ jsxs(SearchList, {
|
|
292
|
+
query,
|
|
293
|
+
onQueryChange: setQuery,
|
|
294
|
+
creatable,
|
|
295
|
+
searchLabel,
|
|
296
|
+
searchPlaceholder,
|
|
297
|
+
emptyLabel,
|
|
298
|
+
children: [children, creatable ? /* @__PURE__ */ jsx(CreateItem, { label: createLabel(query.trim()) }) : null]
|
|
299
|
+
}) : /* @__PURE__ */ jsx(ListBox, {
|
|
141
300
|
"data-slot": "multi-select-list",
|
|
142
301
|
className: "outline-none",
|
|
143
302
|
children
|
|
@@ -146,7 +305,22 @@ const MultiSelect = forwardRef(function MultiSelect({ children, label, labelHidd
|
|
|
146
305
|
]
|
|
147
306
|
});
|
|
148
307
|
});
|
|
308
|
+
const multiSelectGroupVariants = cva(["flex flex-col not-first:mt-1"]);
|
|
309
|
+
const multiSelectGroupHeaderVariants = cva(["px-2 pt-1.5 pb-1 text-xs leading-(--leading-normal) font-semibold text-muted-foreground"]);
|
|
310
|
+
const MultiSelectGroup = forwardRef(function MultiSelectGroup({ title, children, id, className }, ref) {
|
|
311
|
+
return /* @__PURE__ */ jsxs(ListBoxSection, {
|
|
312
|
+
ref,
|
|
313
|
+
id,
|
|
314
|
+
"data-slot": "multi-select-group",
|
|
315
|
+
className: cn(multiSelectGroupVariants(), className),
|
|
316
|
+
children: [/* @__PURE__ */ jsx(Header, {
|
|
317
|
+
"data-slot": "multi-select-group-header",
|
|
318
|
+
className: multiSelectGroupHeaderVariants(),
|
|
319
|
+
children: title
|
|
320
|
+
}), children]
|
|
321
|
+
});
|
|
322
|
+
});
|
|
149
323
|
//#endregion
|
|
150
|
-
export { MultiSelect };
|
|
324
|
+
export { MultiSelect, MultiSelectGroup, multiSelectGroupHeaderVariants, multiSelectGroupVariants };
|
|
151
325
|
|
|
152
326
|
//# sourceMappingURL=multi-select.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"multi-select.js","names":["AriaButton","AriaSelect","AriaLabel","AriaSelectValue","AriaFieldError","AriaPopover","AriaListBox"],"sources":["../../src/multi-select/multi-select.tsx"],"sourcesContent":["\"use client\";\n\nimport { forwardRef, useContext, useRef, useState, type ReactNode } from \"react\";\nimport {\n Button as AriaButton,\n ButtonContext,\n FieldError as AriaFieldError,\n Label as AriaLabel,\n ListBox as AriaListBox,\n Popover as AriaPopover,\n Select as AriaSelect,\n SelectStateContext,\n SelectValue as AriaSelectValue,\n type Key,\n type SelectProps as AriaSelectProps,\n} from \"react-aria-components\";\n\nimport { labelVariants } from \"../label/label.js\";\nimport { cn, cnAll } from \"../lib/cn.js\";\nimport { useFlip } from \"../lib/flip.js\";\nimport { SwapText } from \"../lib/swap-text.js\";\nimport { selectPopoverVariants, selectTriggerVariants, selectVariants } from \"../select/select.js\";\n\n/**\n * MultiSelect: pick several options from a list. A Select in multiple mode\n * (React Aria), so the keyboard, typeahead, focus and screen-reader behaviour\n * are Select's own; the list stays open while picking.\n *\n * The trigger shows the first picks as chips and the rest as \"+N\". A new chip\n * fades up from a blur and grows in on the snappy spring while the chips beside\n * it glide over; the count rolls up or down as it changes. A clear button scales\n * in beside the chevron when anything is picked. Options are `SelectItem`s, whose\n * tick pops in as an option is picked.\n */\nexport interface MultiSelectProps extends Omit<\n AriaSelectProps<object, \"multiple\">,\n \"className\" | \"style\" | \"children\" | \"items\" | \"selectionMode\"\n> {\n /** `SelectItem` children. */\n children?: ReactNode;\n /** What is being chosen, and the control's accessible name. */\n label: ReactNode;\n labelHidden?: boolean;\n /** Shown while nothing is picked. @default \"Select options\" */\n placeholder?: string;\n /** Why the selection is wrong. Rendered under the control. */\n errorMessage?: ReactNode;\n /** Chips shown in the trigger before the rest become \"+N\". @default 2 */\n maxVisible?: number;\n /** Accessible name of the clear button. @default \"Clear selections\" */\n clearLabel?: string;\n /** @default \"md\" */\n size?: \"sm\" | \"md\" | \"lg\";\n /** Extra classes for the wrapper. Merged last. */\n className?: string;\n}\n\n/** The picked options as chips, then \"+N\", reading Select's own state. */\nfunction Chips({ placeholder, maxVisible }: { placeholder: string; maxVisible: number }) {\n const state = useContext(SelectStateContext);\n const keys = (state?.value as Key[] | undefined) ?? [];\n const labelOf = (key: Key) => state?.collection.getItem(key)?.textValue ?? String(key);\n const shown = keys.slice(0, maxVisible);\n const rest = keys.length - shown.length;\n const row = useRef<HTMLSpanElement>(null);\n // The chips beside a new or removed one glide to their new place.\n useFlip(row, keys.join(\"|\"), \"var(--duration-smooth)\", \"var(--ease-smooth)\");\n // Chips there at first paint never animate; later ones grow in.\n const [initial] = useState(() => new Set(keys));\n const [count, setCount] = useState({ rest, dir: 1 });\n if (count.rest !== rest) setCount({ rest, dir: rest > count.rest ? 1 : -1 });\n return (\n <span\n ref={row}\n aria-hidden=\"true\"\n className=\"relative flex min-h-6.5 min-w-0 flex-1 items-center gap-1.5 overflow-hidden\"\n >\n {keys.length === 0 ? (\n <span\n data-slot=\"multi-select-placeholder\"\n className=\"truncate text-muted-foreground motion-safe:animate-fade-in\"\n >\n {placeholder}\n </span>\n ) : null}\n {shown.map((key) => (\n <span\n key={String(key)}\n data-flip=\"\"\n data-slot=\"multi-select-chip\"\n className={cnAll(\n \"multi-select-chip\",\n !initial.has(key) && \"motion-safe:animate-chip-reveal\",\n )}\n >\n {labelOf(key)}\n </span>\n ))}\n {rest > 0 ? (\n <span\n data-flip=\"\"\n data-slot=\"multi-select-more\"\n className=\"multi-select-chip text-text-secondary tabular-nums\"\n >\n +\n <SwapText swapKey={String(rest)} dir={count.dir} motion=\"rise\">\n {rest}\n </SwapText>\n </span>\n ) : null}\n </span>\n );\n}\n\n/** Clears every pick. It sits outside the trigger, so it is its own tab stop. */\nfunction Clear({ label, disabled }: { label: string; disabled: boolean }) {\n const state = useContext(SelectStateContext);\n const keys = (state?.value as Key[] | undefined) ?? [];\n if (!state || keys.length === 0 || disabled) return null;\n // Select hands its trigger props to every Button inside it; clear that, or this\n // button would become a second trigger named by the label.\n return (\n <ButtonContext.Provider value={null}>\n <AriaButton\n aria-label={label}\n data-slot=\"multi-select-clear\"\n onPress={() => {\n state.setValue([]);\n state.close();\n }}\n className=\"multi-select-clear motion-safe:animate-field-clear-in motion-reduce:animate-fade-in\"\n >\n <svg\n aria-hidden=\"true\"\n viewBox=\"0 0 16 16\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"1.75\"\n strokeLinecap=\"round\"\n className=\"size-3.5\"\n >\n <path d=\"m4 4 8 8M12 4l-8 8\" />\n </svg>\n </AriaButton>\n </ButtonContext.Provider>\n );\n}\n\nexport const MultiSelect = forwardRef<HTMLButtonElement, MultiSelectProps>(function MultiSelect(\n {\n children,\n label,\n labelHidden,\n placeholder = \"Select options\",\n errorMessage,\n maxVisible = 2,\n clearLabel = \"Clear selections\",\n size = \"md\",\n className,\n ...props\n },\n ref,\n) {\n return (\n <AriaSelect<object, \"multiple\">\n {...props}\n selectionMode=\"multiple\"\n data-slot=\"multi-select\"\n className={cn(selectVariants(), className)}\n >\n <AriaLabel\n data-slot=\"multi-select-label\"\n className={cnAll(labelVariants(), labelHidden && \"sr-only\")}\n >\n {label}\n </AriaLabel>\n <div className=\"relative\">\n <AriaButton\n ref={ref}\n data-slot=\"multi-select-trigger\"\n className={cnAll(selectTriggerVariants({ size }), \"pe-16 multi-select-trigger\")}\n >\n <AriaSelectValue data-slot=\"multi-select-value\" className=\"sr-only\">\n {({ isPlaceholder, selectedText }) => (isPlaceholder ? placeholder : selectedText)}\n </AriaSelectValue>\n <Chips placeholder={placeholder} maxVisible={maxVisible} />\n <svg\n aria-hidden=\"true\"\n viewBox=\"0 0 16 16\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"1.75\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n className=\"absolute end-(--density-control-pad-md) text-muted-foreground motion-safe:transition-[rotate] motion-safe:duration-(--duration-gentle) motion-safe:ease-gentle group-aria-expanded/trigger:rotate-180\"\n >\n <path d=\"m4 6 4 4 4-4\" />\n </svg>\n </AriaButton>\n <Clear label={clearLabel} disabled={props.isDisabled ?? false} />\n </div>\n {errorMessage == null ? null : (\n <AriaFieldError\n data-slot=\"multi-select-error\"\n className=\"text-sm leading-(--leading-normal) text-destructive-strong\"\n >\n {errorMessage}\n </AriaFieldError>\n )}\n <AriaPopover data-slot=\"multi-select-popover\" className={selectPopoverVariants()}>\n <AriaListBox data-slot=\"multi-select-list\" className=\"outline-none\">\n {children}\n </AriaListBox>\n </AriaPopover>\n </AriaSelect>\n );\n});\n"],"mappings":";;;;;;;;;;;AA0DA,SAAS,MAAM,EAAE,aAAa,cAA2D;CACvF,MAAM,QAAQ,WAAW,kBAAkB;CAC3C,MAAM,OAAQ,OAAO,SAA+B,CAAC;CACrD,MAAM,WAAW,QAAa,OAAO,WAAW,QAAQ,GAAG,CAAC,EAAE,aAAa,OAAO,GAAG;CACrF,MAAM,QAAQ,KAAK,MAAM,GAAG,UAAU;CACtC,MAAM,OAAO,KAAK,SAAS,MAAM;CACjC,MAAM,MAAM,OAAwB,IAAI;CAExC,QAAQ,KAAK,KAAK,KAAK,GAAG,GAAG,0BAA0B,oBAAoB;CAE3E,MAAM,CAAC,WAAW,eAAe,IAAI,IAAI,IAAI,CAAC;CAC9C,MAAM,CAAC,OAAO,YAAY,SAAS;EAAE;EAAM,KAAK;CAAE,CAAC;CACnD,IAAI,MAAM,SAAS,MAAM,SAAS;EAAE;EAAM,KAAK,OAAO,MAAM,OAAO,IAAI;CAAG,CAAC;CAC3E,OACE,qBAAC,QAAD;EACE,KAAK;EACL,eAAY;EACZ,WAAU;EAHZ,UAAA;GAKG,KAAK,WAAW,IACf,oBAAC,QAAD;IACE,aAAU;IACV,WAAU;IAET,UAAA;GACG,CAAA,IACJ;GACH,MAAM,KAAK,QACV,oBAAC,QAAD;IAEE,aAAU;IACV,aAAU;IACV,WAAW,MACT,qBACA,CAAC,QAAQ,IAAI,GAAG,KAAK,iCACvB;IAEC,UAAA,QAAQ,GAAG;GACR,GATC,OAAO,GAAG,CASX,CACP;GACA,OAAO,IACN,qBAAC,QAAD;IACE,aAAU;IACV,aAAU;IACV,WAAU;IAHZ,UAAA,CAIC,KAEC,oBAAC,UAAD;KAAU,SAAS,OAAO,IAAI;KAAG,KAAK,MAAM;KAAK,QAAO;KACrD,UAAA;IACO,CAAA,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AAQ;OACR,MAAK;OACL,QAAO;OACP,aAAY;OACZ,eAAc;OACd,gBAAe;OACf,WAAU;OAEV,UAAA,oBAAC,QAAD,EAAM,GAAE,eAAgB,CAAA;MACrB,CAAA;KACK;IACZ,CAAA,GAAA,oBAAC,OAAD;KAAO,OAAO;KAAY,UAAU,MAAM,cAAc;IAAQ,CAAA,CAC7D;;GACJ,gBAAgB,OAAO,OACtB,oBAACC,YAAD;IACE,aAAU;IACV,WAAU;IAET,UAAA;GACa,CAAA;GAElB,oBAACC,SAAD;IAAa,aAAU;IAAuB,WAAW,sBAAsB;IAC7E,UAAA,oBAACC,SAAD;KAAa,aAAU;KAAoB,WAAU;KAClD;IACU,CAAA;GACF,CAAA;EACH;;AAEhB,CAAC"}
|
|
1
|
+
{"version":3,"file":"multi-select.js","names":["AriaAutocomplete","AriaSearchField","AriaInput","AriaListBox","AriaListBoxItem","TooltipTrigger","Tooltip","AriaButton","AriaSelectValue","AriaSelect","AriaLabel","AriaFieldError","AriaPopover","AriaListBoxSection","AriaHeader"],"sources":["../../src/multi-select/multi-select.tsx"],"sourcesContent":["\"use client\";\n\nimport { cva } from \"class-variance-authority\";\nimport {\n forwardRef,\n useContext,\n useRef,\n useState,\n type ContextType,\n type ReactNode,\n type RefObject,\n} from \"react\";\nimport {\n Autocomplete as AriaAutocomplete,\n Button as AriaButton,\n ButtonContext,\n FieldError as AriaFieldError,\n Header as AriaHeader,\n Input as AriaInput,\n Label as AriaLabel,\n ListBox as AriaListBox,\n ListBoxItem as AriaListBoxItem,\n ListBoxSection as AriaListBoxSection,\n Popover as AriaPopover,\n SearchField as AriaSearchField,\n Select as AriaSelect,\n SelectStateContext,\n SelectValue as AriaSelectValue,\n type Key,\n type SelectProps as AriaSelectProps,\n useFilter,\n} from \"react-aria-components\";\n\nimport { labelVariants } from \"../label/label.js\";\nimport { cn, cnAll } from \"../lib/cn.js\";\nimport { useFlip } from \"../lib/flip.js\";\nimport { SwapText } from \"../lib/swap-text.js\";\nimport {\n selectItemVariants,\n selectPopoverVariants,\n selectTriggerVariants,\n selectVariants,\n} from \"../select/select.js\";\nimport { Tooltip, TooltipTrigger } from \"../tooltip/tooltip.js\";\n\n/**\n * MultiSelect: pick several options from a list. A Select in multiple mode\n * (React Aria), so the keyboard, typeahead, focus and screen-reader behaviour\n * are Select's own; the list stays open while picking.\n *\n * The trigger shows the first picks as chips and the rest as \"+N\". A new chip\n * fades up from a blur and grows in on the snappy spring while the chips beside\n * it glide over; the count rolls up or down as it changes. A clear button scales\n * in beside the chevron when anything is picked. Options are `SelectItem`s, whose\n * tick pops in as an option is picked; `MultiSelectGroup` gathers them under a\n * heading.\n *\n * Opt in to `searchable` for a search field at the top of the list that filters\n * the options as you type (React Aria's Autocomplete, so the arrow keys and Enter\n * work from the field). Pass `onCreate` to also offer a \"Create “…”\" row when the\n * typed text matches no option.\n */\nexport interface MultiSelectProps extends Omit<\n AriaSelectProps<object, \"multiple\">,\n \"className\" | \"style\" | \"children\" | \"items\" | \"selectionMode\"\n> {\n /** `SelectItem` children. */\n children?: ReactNode;\n /** What is being chosen, and the control's accessible name. */\n label: ReactNode;\n labelHidden?: boolean;\n /** Shown while nothing is picked. @default \"Select options\" */\n placeholder?: string;\n /** Why the selection is wrong. Rendered under the control. */\n errorMessage?: ReactNode;\n /** Chips shown in the trigger before the rest become \"+N\". @default 2 */\n maxVisible?: number;\n /**\n * Words after the overflow count, so `\"more\"` reads \"+2 more\". Off by default:\n * the count alone, \"+2\".\n */\n moreLabel?: string;\n /**\n * While some picks are folded into \"+N\", hovering or focusing the trigger shows\n * a tooltip listing them. Off by default.\n *\n * @default false\n */\n overflowTooltip?: boolean;\n /** Accessible name of the clear button. @default \"Clear selections\" */\n clearLabel?: string;\n /** @default \"md\" */\n size?: \"sm\" | \"md\" | \"lg\";\n /** Extra classes for the wrapper. Merged last. */\n className?: string;\n /**\n * Puts a search field at the top of the list. Typing filters the options (and\n * groups) by their text, ignoring case and accents; the arrow keys and Enter\n * work from the field. Cleared each time the list closes. Off by default.\n * Turned on by `onCreate` too.\n *\n * @default false\n */\n searchable?: boolean;\n /** Accessible name of the search field. @default \"Search options\" */\n searchLabel?: string;\n /** Placeholder of the search field. @default \"Search\" */\n searchPlaceholder?: string;\n /** Shown in the list while the search matches nothing. @default \"No options found\" */\n emptyLabel?: string;\n /**\n * Makes the list creatable, and searchable. While the typed text (trimmed)\n * matches no option's text or id nor a picked value, ignoring case, the list ends\n * with a \"Create “text”\" row. Picking it calls `onCreate` with the text, adds\n * the text itself as a picked key (through `onChange`, as any pick) and clears\n * the search. Render a `SelectItem` whose `id` is that text so it lists like\n * the others; until then its chip shows the text.\n */\n onCreate?: (value: string) => void;\n /** The create row's text for the typed value. @default (value) => `Create “${value}”` */\n createLabel?: (value: string) => string;\n}\n\n/** The key of the create row. Never reaches `onChange`. */\nconst CREATE_KEY = \"__multi-select-create__\";\n\nconst defaultCreateLabel = (value: string) => `Create \\u201c${value}\\u201d`;\n\ntype SelectState = NonNullable<ContextType<typeof SelectStateContext>>;\n\n/** Whether `text` already names an option (by its text or its key) or a pick, ignoring case. */\nfunction isTaken(state: SelectState | null, text: string) {\n const want = text.toLocaleLowerCase();\n const keys = (state?.value as Key[] | undefined) ?? [];\n if (keys.some((key) => String(key).toLocaleLowerCase() === want)) return true;\n if (!state) return false;\n for (const key of state.collection.getKeys()) {\n const node = state.collection.getItem(key);\n if (\n node?.type === \"item\" &&\n node.key !== CREATE_KEY &&\n // The key too: creating text equal to an unpicked option's id would pick\n // that option AND tell the owner to create a duplicate.\n (node.textValue.toLocaleLowerCase() === want || String(node.key).toLocaleLowerCase() === want)\n ) {\n return true;\n }\n }\n return false;\n}\n\n/**\n * The list with a search field over it (React Aria's Autocomplete): the field\n * keeps focus and drives the options with the arrow keys, Enter picks.\n */\nfunction SearchList({\n query,\n onQueryChange,\n creatable,\n searchLabel,\n searchPlaceholder,\n emptyLabel,\n children,\n}: {\n query: string;\n onQueryChange: (query: string) => void;\n creatable: boolean;\n searchLabel: string;\n searchPlaceholder: string;\n emptyLabel: string;\n children: ReactNode;\n}) {\n const state = useContext(SelectStateContext);\n const { contains } = useFilter({ sensitivity: \"base\" });\n const text = query.trim();\n const offerCreate = creatable && text !== \"\" && !isTaken(state, text);\n return (\n <AriaAutocomplete\n inputValue={query}\n onInputChange={onQueryChange}\n filter={(textValue, input, node) =>\n node.key === CREATE_KEY ? offerCreate : contains(textValue, input)\n }\n >\n <AriaSearchField\n aria-label={searchLabel}\n autoFocus\n data-slot=\"multi-select-search\"\n className={multiSelectSearchClass}\n >\n <svg\n aria-hidden=\"true\"\n viewBox=\"0 0 16 16\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"1.75\"\n strokeLinecap=\"round\"\n className=\"size-4 flex-none text-muted-foreground\"\n >\n <circle cx=\"7\" cy=\"7\" r=\"4.5\" />\n <path d=\"m10.5 10.5 3 3\" />\n </svg>\n <AriaInput\n placeholder={searchPlaceholder}\n data-slot=\"multi-select-search-input\"\n className=\"min-w-0 flex-1 appearance-none border-0 bg-transparent p-0 font-sans text-sm text-foreground outline-none placeholder:text-muted-foreground [&::-webkit-search-cancel-button]:hidden\"\n />\n </AriaSearchField>\n <AriaListBox\n data-slot=\"multi-select-list\"\n renderEmptyState={() => (\n <p\n data-slot=\"multi-select-empty\"\n className=\"m-0 px-2 py-1.5 text-sm text-muted-foreground\"\n >\n {emptyLabel}\n </p>\n )}\n className=\"min-h-0 flex-1 overflow-y-auto outline-none\"\n >\n {children}\n </AriaListBox>\n </AriaAutocomplete>\n );\n}\n\n/** The search row: a quiet field over the list, underlined while focused. */\nconst multiSelectSearchClass =\n \"relative mb-1 flex h-(--density-control-h-sm) flex-none items-center gap-2 border-b-(length:--border-width) border-border px-2 after:pointer-events-none after:absolute after:inset-x-0 after:bottom-0 after:h-(--focus-ring-width) after:bg-transparent has-[input:focus]:after:bg-(--color-control-edge)\";\n\n/** The row that creates the typed value. Kept in the collection; the filter shows it. */\nfunction CreateItem({ label }: { label: string }) {\n return (\n <AriaListBoxItem\n id={CREATE_KEY}\n textValue={label}\n data-slot=\"multi-select-create\"\n className={cnAll(selectItemVariants(), \"text-text-secondary data-[focused]:text-foreground\")}\n >\n <svg\n aria-hidden=\"true\"\n viewBox=\"0 0 16 16\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"1.75\"\n strokeLinecap=\"round\"\n className=\"size-3.5 flex-none\"\n >\n <path d=\"M8 3.5v9M3.5 8h9\" />\n </svg>\n {label}\n </AriaListBoxItem>\n );\n}\n\n/** The picked options as chips, then \"+N\", reading Select's own state. */\nfunction Chips({\n placeholder,\n maxVisible,\n moreLabel,\n moreRef,\n}: {\n placeholder: string;\n maxVisible: number;\n moreLabel: string | undefined;\n moreRef: RefObject<HTMLSpanElement | null>;\n}) {\n const state = useContext(SelectStateContext);\n const keys = (state?.value as Key[] | undefined) ?? [];\n const labelOf = (key: Key) => state?.collection.getItem(key)?.textValue ?? String(key);\n const shown = keys.slice(0, maxVisible);\n const rest = keys.length - shown.length;\n const row = useRef<HTMLSpanElement>(null);\n // The chips beside a new or removed one glide to their new place.\n useFlip(row, keys.join(\"|\"), \"var(--duration-smooth)\", \"var(--ease-smooth)\");\n // Chips there at first paint never animate; later ones grow in.\n const [initial] = useState(() => new Set(keys));\n const [count, setCount] = useState({ rest, dir: 1 });\n if (count.rest !== rest) setCount({ rest, dir: rest > count.rest ? 1 : -1 });\n return (\n <span\n ref={row}\n aria-hidden=\"true\"\n className=\"relative flex min-h-6.5 min-w-0 flex-1 items-center gap-1.5 overflow-hidden\"\n >\n {keys.length === 0 ? (\n <span\n data-slot=\"multi-select-placeholder\"\n className=\"truncate text-muted-foreground motion-safe:animate-fade-in\"\n >\n {placeholder}\n </span>\n ) : null}\n {shown.map((key) => (\n <span\n key={String(key)}\n data-flip=\"\"\n data-slot=\"multi-select-chip\"\n className={cnAll(\n \"multi-select-chip\",\n !initial.has(key) && \"motion-safe:animate-chip-reveal\",\n )}\n >\n {labelOf(key)}\n </span>\n ))}\n {rest > 0 ? (\n <span\n ref={moreRef}\n data-flip=\"\"\n data-slot=\"multi-select-more\"\n className=\"multi-select-chip text-text-secondary tabular-nums\"\n >\n +\n <SwapText swapKey={String(rest)} dir={count.dir} motion=\"rise\">\n {rest}\n </SwapText>\n {/* The chip is a flex box, which drops a leading space in a bare text\n node; whitespace-pre keeps \"+2 more\" from reading \"+2more\". */}\n {moreLabel ? (\n <span data-slot=\"multi-select-more-label\" className=\"whitespace-pre\">\n {` ${moreLabel}`}\n </span>\n ) : null}\n </span>\n ) : null}\n </span>\n );\n}\n\n/** The labels of the picks folded into \"+N\", in the order they were picked. */\nfunction useHiddenLabels(maxVisible: number) {\n const state = useContext(SelectStateContext);\n const keys = (state?.value as Key[] | undefined) ?? [];\n return keys\n .slice(maxVisible)\n .map((key) => state?.collection.getItem(key)?.textValue ?? String(key));\n}\n\n/**\n * Wraps the trigger in a tooltip naming the picks hidden behind \"+N\", placed\n * against the +N chip rather than the whole field. Always rendered, so turning\n * `overflowTooltip` on or off never swaps the trigger element (and drops its\n * focus); disabled while off or while nothing is hidden, so it never opens empty.\n */\nfunction OverflowTooltip({\n enabled,\n maxVisible,\n anchorRef,\n children,\n}: {\n enabled: boolean;\n maxVisible: number;\n anchorRef: RefObject<HTMLSpanElement | null>;\n children: ReactNode;\n}) {\n const hidden = useHiddenLabels(maxVisible);\n return (\n <TooltipTrigger isDisabled={!enabled || hidden.length === 0}>\n {children}\n <Tooltip triggerRef={anchorRef} data-slot=\"multi-select-overflow-tooltip\">\n {hidden.join(\", \")}\n </Tooltip>\n </TooltipTrigger>\n );\n}\n\n/** Clears every pick. It sits outside the trigger, so it is its own tab stop. */\nfunction Clear({ label, disabled }: { label: string; disabled: boolean }) {\n const state = useContext(SelectStateContext);\n const keys = (state?.value as Key[] | undefined) ?? [];\n if (!state || keys.length === 0 || disabled) return null;\n // Select hands its trigger props to every Button inside it; clear that, or this\n // button would become a second trigger named by the label.\n return (\n <ButtonContext.Provider value={null}>\n <AriaButton\n aria-label={label}\n data-slot=\"multi-select-clear\"\n onPress={() => {\n state.setValue([]);\n state.close();\n }}\n className=\"multi-select-clear motion-safe:animate-field-clear-in motion-reduce:animate-fade-in\"\n >\n <svg\n aria-hidden=\"true\"\n viewBox=\"0 0 16 16\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"1.75\"\n strokeLinecap=\"round\"\n className=\"size-3.5\"\n >\n <path d=\"m4 4 8 8M12 4l-8 8\" />\n </svg>\n </AriaButton>\n </ButtonContext.Provider>\n );\n}\n\nexport const MultiSelect = forwardRef<HTMLButtonElement, MultiSelectProps>(function MultiSelect(\n {\n children,\n label,\n labelHidden,\n placeholder = \"Select options\",\n errorMessage,\n maxVisible = 2,\n moreLabel,\n overflowTooltip = false,\n clearLabel = \"Clear selections\",\n size = \"md\",\n className,\n searchable = false,\n searchLabel = \"Search options\",\n searchPlaceholder = \"Search\",\n emptyLabel = \"No options found\",\n onCreate,\n createLabel = defaultCreateLabel,\n ...props\n },\n ref,\n) {\n const moreRef = useRef<HTMLSpanElement>(null);\n const creatable = onCreate != null;\n const withSearch = searchable || creatable;\n const [query, setQuery] = useState(\"\");\n // Creating adds a key no option has yet, so the value is held here: the create\n // row's own key is swapped for the typed text before anyone sees it.\n const [ownValue, setOwnValue] = useState<readonly Key[]>(() => props.defaultValue ?? []);\n const value = props.value ?? ownValue;\n const creatableProps: Partial<AriaSelectProps<object, \"multiple\">> = creatable\n ? {\n value,\n defaultValue: undefined,\n onChange: (keys) => {\n let next = keys;\n if (keys.includes(CREATE_KEY)) {\n const text = query.trim();\n next = keys.filter((key) => key !== CREATE_KEY);\n if (text !== \"\" && !next.includes(text)) next.push(text);\n setQuery(\"\");\n onCreate(text);\n }\n setOwnValue(next);\n props.onChange?.(next);\n },\n }\n : {};\n const trigger = (\n <AriaButton\n ref={ref}\n data-slot=\"multi-select-trigger\"\n className={cnAll(selectTriggerVariants({ size }), \"pe-16 multi-select-trigger\")}\n >\n <AriaSelectValue data-slot=\"multi-select-value\" className=\"sr-only\">\n {({ isPlaceholder, selectedText }) => (isPlaceholder ? placeholder : selectedText)}\n </AriaSelectValue>\n <Chips\n placeholder={placeholder}\n maxVisible={maxVisible}\n moreLabel={moreLabel}\n moreRef={moreRef}\n />\n <svg\n aria-hidden=\"true\"\n viewBox=\"0 0 16 16\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"1.75\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n className=\"absolute end-(--density-control-pad-md) text-muted-foreground motion-safe:transition-[rotate] motion-safe:duration-(--duration-gentle) motion-safe:ease-gentle group-aria-expanded/trigger:rotate-180\"\n >\n <path d=\"m4 6 4 4 4-4\" />\n </svg>\n </AriaButton>\n );\n return (\n <AriaSelect<object, \"multiple\">\n {...props}\n {...creatableProps}\n onOpenChange={(isOpen) => {\n // Each opening starts from the whole list.\n if (!isOpen) setQuery(\"\");\n props.onOpenChange?.(isOpen);\n }}\n selectionMode=\"multiple\"\n data-slot=\"multi-select\"\n className={cn(selectVariants(), className)}\n >\n <AriaLabel\n data-slot=\"multi-select-label\"\n className={cnAll(labelVariants(), labelHidden && \"sr-only\")}\n >\n {label}\n </AriaLabel>\n <div className=\"relative\">\n <OverflowTooltip enabled={overflowTooltip} maxVisible={maxVisible} anchorRef={moreRef}>\n {trigger}\n </OverflowTooltip>\n <Clear label={clearLabel} disabled={props.isDisabled ?? false} />\n </div>\n {errorMessage == null ? null : (\n <AriaFieldError\n data-slot=\"multi-select-error\"\n className=\"text-sm leading-(--leading-normal) text-destructive-strong\"\n >\n {errorMessage}\n </AriaFieldError>\n )}\n <AriaPopover\n data-slot=\"multi-select-popover\"\n className={\n withSearch\n ? cnAll(selectPopoverVariants({ reveal: \"fade\" }), \"flex flex-col overflow-y-hidden\")\n : selectPopoverVariants()\n }\n >\n {withSearch ? (\n <SearchList\n query={query}\n onQueryChange={setQuery}\n creatable={creatable}\n searchLabel={searchLabel}\n searchPlaceholder={searchPlaceholder}\n emptyLabel={emptyLabel}\n >\n {children}\n {creatable ? <CreateItem label={createLabel(query.trim())} /> : null}\n </SearchList>\n ) : (\n <AriaListBox data-slot=\"multi-select-list\" className=\"outline-none\">\n {children}\n </AriaListBox>\n )}\n </AriaPopover>\n </AriaSelect>\n );\n});\n\nexport const multiSelectGroupVariants = cva([\"flex flex-col not-first:mt-1\"]);\n\nexport const multiSelectGroupHeaderVariants = cva([\n \"px-2 pt-1.5 pb-1 text-xs leading-(--leading-normal) font-semibold text-muted-foreground\",\n]);\n\n/**\n * A run of options under a heading, such as \"Countries\" and \"Regions\". React\n * Aria's ListBoxSection, so the heading names the group for assistive tech and\n * the arrow keys move straight through from one group to the next.\n *\n * @example\n * <MultiSelect label=\"Markets\">\n * <MultiSelectGroup title=\"Countries\">\n * <SelectItem id=\"IN\">India</SelectItem>\n * </MultiSelectGroup>\n * <MultiSelectGroup title=\"Regions\">\n * <SelectItem id=\"europe\">Europe</SelectItem>\n * </MultiSelectGroup>\n * </MultiSelect>\n */\nexport interface MultiSelectGroupProps {\n /** The heading drawn above the group, and the group's accessible name. */\n title: ReactNode;\n /** `SelectItem` children. */\n children?: ReactNode;\n /** Identifies the group in the collection. Defaults to a generated id. */\n id?: Key;\n /** Extra classes for the group. Merged last. */\n className?: string;\n}\n\nexport const MultiSelectGroup = forwardRef<HTMLElement, MultiSelectGroupProps>(\n function MultiSelectGroup({ title, children, id, className }, ref) {\n return (\n <AriaListBoxSection\n ref={ref}\n id={id}\n data-slot=\"multi-select-group\"\n className={cn(multiSelectGroupVariants(), className)}\n >\n <AriaHeader\n data-slot=\"multi-select-group-header\"\n className={multiSelectGroupHeaderVariants()}\n >\n {title}\n </AriaHeader>\n {children}\n </AriaListBoxSection>\n );\n },\n);\n"],"mappings":";;;;;;;;;;;;;AA4HA,MAAM,aAAa;AAEnB,MAAM,sBAAsB,UAAkB,gBAAgB,MAAM;;AAKpE,SAAS,QAAQ,OAA2B,MAAc;CACxD,MAAM,OAAO,KAAK,kBAA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a,iCAAiC,IAAI,CAChD,yFACF,CAAC;AA4BD,MAAa,mBAAmB,WAC9B,SAAS,iBAAiB,EAAE,OAAO,UAAU,IAAI,aAAa,KAAK;CACjE,OACE,qBAACU,gBAAD;EACO;EACD;EACJ,aAAU;EACV,WAAW,GAAG,yBAAyB,GAAG,SAAS;EAJrD,UAAA,CAME,oBAACC,QAAD;GACE,aAAU;GACV,WAAW,+BAA+B;GAEzC,UAAA;EACS,CAAA,GACX,QACiB;;AAExB,CACF"}
|
|
@@ -17,6 +17,21 @@ export interface PasswordFieldProps extends Omit<InputProps, "className" | "styl
|
|
|
17
17
|
* after mount and changed words rise in. Nothing animates on first render.
|
|
18
18
|
*/
|
|
19
19
|
description?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Error text under the field. Sets `aria-invalid`, so the box takes its
|
|
22
|
+
* invalid border, and is announced as an alert when it appears. Opens and
|
|
23
|
+
* closes like `description`; an empty or `undefined` value closes the row.
|
|
24
|
+
* The same prop as Input's. Inside a React Aria `TextField` (which supplies
|
|
25
|
+
* the label and description) the error row is still rendered, after the
|
|
26
|
+
* control, and named in the input's `aria-describedby`.
|
|
27
|
+
*/
|
|
28
|
+
error?: string;
|
|
29
|
+
/**
|
|
30
|
+
* The field must be filled: the input is `required` (announced by screen
|
|
31
|
+
* readers, and checked by native form validation) and the label shows the
|
|
32
|
+
* required marker.
|
|
33
|
+
*/
|
|
34
|
+
isRequired?: boolean;
|
|
20
35
|
/** Translated or reworded toggle names. */
|
|
21
36
|
messages?: Partial<PasswordFieldMessages>;
|
|
22
37
|
}
|
|
@@ -31,6 +46,7 @@ export interface PasswordFieldProps extends Omit<InputProps, "className" | "styl
|
|
|
31
46
|
*
|
|
32
47
|
* @example
|
|
33
48
|
* <PasswordField label="Password" description="At least eight characters." />
|
|
49
|
+
* <PasswordField label="API secret" isRequired error={errors.secret?.message} {...register("secret")} />
|
|
34
50
|
*/
|
|
35
51
|
export declare const PasswordField: import("react").ForwardRefExoticComponent<PasswordFieldProps & import("react").RefAttributes<HTMLInputElement>>;
|
|
36
52
|
//#endregion
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { cn } from "../lib/cn.js";
|
|
3
3
|
import { fieldSurfaceVariants } from "../lib/field-surface.js";
|
|
4
|
+
import { FieldMessage } from "../lib/field-message.js";
|
|
4
5
|
import { FieldShell, useFieldWiring } from "../lib/field-shell.js";
|
|
5
6
|
import { EyeMorph } from "../lib/eye-morph.js";
|
|
6
|
-
import { forwardRef, useState } from "react";
|
|
7
|
-
import { Button, Group, Input } from "react-aria-components";
|
|
8
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
import { forwardRef, useId, useState } from "react";
|
|
8
|
+
import { Button, Group, Input, InputContext, useSlottedContext } from "react-aria-components";
|
|
9
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
9
10
|
//#region src/password-field/password-field.tsx
|
|
10
11
|
const defaultPasswordFieldMessages = {
|
|
11
12
|
showPassword: "Show password",
|
|
@@ -37,8 +38,9 @@ const toggleClass = "field-toggle-button grid size-7.5 flex-none cursor-pointer
|
|
|
37
38
|
*
|
|
38
39
|
* @example
|
|
39
40
|
* <PasswordField label="Password" description="At least eight characters." />
|
|
41
|
+
* <PasswordField label="API secret" isRequired error={errors.secret?.message} {...register("secret")} />
|
|
40
42
|
*/
|
|
41
|
-
const PasswordField = forwardRef(function PasswordField({ label, description, messages: messagesProp, className, ...props }, ref) {
|
|
43
|
+
const PasswordField = forwardRef(function PasswordField({ label, description, error, isRequired, messages: messagesProp, className, ...props }, ref) {
|
|
42
44
|
const messages = {
|
|
43
45
|
...defaultPasswordFieldMessages,
|
|
44
46
|
...messagesProp
|
|
@@ -51,20 +53,35 @@ const PasswordField = forwardRef(function PasswordField({ label, description, me
|
|
|
51
53
|
describedBy: props["aria-describedby"],
|
|
52
54
|
invalid: props["aria-invalid"],
|
|
53
55
|
description,
|
|
54
|
-
error
|
|
56
|
+
error
|
|
55
57
|
});
|
|
58
|
+
const inputContext = useSlottedContext(InputContext);
|
|
59
|
+
const generatedId = useId();
|
|
60
|
+
const insideErrorId = field.inside && error ? `${generatedId}-error` : void 0;
|
|
61
|
+
const [errorRow, setErrorRow] = useState(Boolean(insideErrorId));
|
|
62
|
+
if (insideErrorId && !errorRow) setErrorRow(true);
|
|
63
|
+
const insideProps = insideErrorId ? {
|
|
64
|
+
"aria-invalid": true,
|
|
65
|
+
"aria-describedby": [
|
|
66
|
+
inputContext?.["aria-describedby"],
|
|
67
|
+
props["aria-describedby"],
|
|
68
|
+
insideErrorId
|
|
69
|
+
].filter(Boolean).join(" ")
|
|
70
|
+
} : {};
|
|
56
71
|
const disabled = Boolean(props.disabled);
|
|
57
72
|
const ariaInvalid = props["aria-invalid"];
|
|
58
73
|
const control = /* @__PURE__ */ jsxs(Group, {
|
|
59
74
|
role: "presentation",
|
|
60
75
|
isDisabled: disabled,
|
|
61
|
-
isInvalid: ariaInvalid !== void 0 && ariaInvalid !== false && ariaInvalid !== "false",
|
|
76
|
+
isInvalid: Boolean(error) || ariaInvalid !== void 0 && ariaInvalid !== false && ariaInvalid !== "false",
|
|
62
77
|
"data-slot": "password-field-shell",
|
|
63
78
|
className: shellClass,
|
|
64
79
|
children: [/* @__PURE__ */ jsx(Input, {
|
|
65
80
|
ref,
|
|
66
81
|
...props,
|
|
82
|
+
...isRequired ? { required: true } : {},
|
|
67
83
|
...field.controlProps,
|
|
84
|
+
...insideProps,
|
|
68
85
|
type: visible ? "text" : "password",
|
|
69
86
|
"data-slot": "password-field",
|
|
70
87
|
"data-reveal": toggled ? visible ? "shown" : "hidden" : void 0,
|
|
@@ -82,14 +99,26 @@ const PasswordField = forwardRef(function PasswordField({ label, description, me
|
|
|
82
99
|
children: /* @__PURE__ */ jsx(EyeMorph, { slashed: visible })
|
|
83
100
|
})]
|
|
84
101
|
});
|
|
102
|
+
if (field.inside) return /* @__PURE__ */ jsxs(Fragment$1, { children: [control, errorRow ? /* @__PURE__ */ jsx("div", {
|
|
103
|
+
"data-slot": "password-field-error-row",
|
|
104
|
+
className: "grid min-w-0 font-sans",
|
|
105
|
+
children: /* @__PURE__ */ jsx(FieldMessage, {
|
|
106
|
+
id: insideErrorId,
|
|
107
|
+
text: error,
|
|
108
|
+
tone: "error",
|
|
109
|
+
wordExit: "sharp",
|
|
110
|
+
numbers: false
|
|
111
|
+
})
|
|
112
|
+
}) : null] });
|
|
85
113
|
if (!field.active) return control;
|
|
86
114
|
return /* @__PURE__ */ jsx(FieldShell, {
|
|
87
115
|
label,
|
|
88
116
|
controlId: field.controlId,
|
|
89
117
|
description,
|
|
90
118
|
hintId: field.hintId,
|
|
91
|
-
error
|
|
92
|
-
errorId:
|
|
119
|
+
error,
|
|
120
|
+
errorId: field.errorId,
|
|
121
|
+
required: isRequired,
|
|
93
122
|
wordExit: "sharp",
|
|
94
123
|
numbers: false,
|
|
95
124
|
children: control
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"password-field.js","names":["AriaGroup","AriaInput","AriaButton"],"sources":["../../src/password-field/password-field.tsx"],"sourcesContent":["\"use client\";\n\nimport { forwardRef, useState } from \"react\";\nimport {\n Button as AriaButton,\n Group as AriaGroup,\n Input as AriaInput,\n type InputProps as AriaInputProps,\n} from \"react-aria-components\";\n\nimport { cn } from \"../lib/cn.js\";\nimport { EyeMorph } from \"../lib/eye-morph.js\";\nimport { FieldShell, useFieldWiring } from \"../lib/field-shell.js\";\nimport { fieldSurfaceVariants } from \"../lib/field-surface.js\";\n\n/** The toggle's accessible names. Both have English defaults; pass the ones you translate. */\nexport interface PasswordFieldMessages {\n showPassword: string;\n hidePassword: string;\n}\n\nexport const defaultPasswordFieldMessages: PasswordFieldMessages = {\n showPassword: \"Show password\",\n hidePassword: \"Hide password\",\n};\n\n/**\n * The field's box. A React Aria `Group` rather than the input, because the\n * toggle sits inside the same border: it carries the shared field surface (the\n * 160ms border transition, the darker border on hover and focus, the muted\n * disabled look, the invalid border) and the input inside is borderless.\n *\n * `data-focus-within` darkens the border too. A Group reports focus-visible\n * from the input modality, so a mouse click into the input, or onto the toggle,\n * would otherwise leave the border pale; a plain Input is different because\n * React Aria treats a text input as always keyboard-focused.\n */\nconst shellClass = cn(\n fieldSurfaceVariants(),\n \"flex items-center h-(--density-control-h-md) ps-(--density-control-pad-md) field-toggle-shell [&:where([data-focus-within])]:border-border-strong\",\n);\n\n/** The input inside the box: no border, no fill, no outline of its own. */\nconst inputClass =\n \"min-w-0 flex-1 border-0 bg-transparent p-0 font-sans text-base text-foreground outline-none placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground data-[disabled]:cursor-not-allowed motion-safe:data-[reveal=shown]:animate-field-reveal-shown motion-safe:data-[reveal=hidden]:animate-field-reveal-hidden\";\n\nconst toggleClass =\n \"field-toggle-button grid size-7.5 flex-none cursor-pointer place-items-center rounded-control border-0 bg-transparent p-0 text-muted-foreground outline-none data-[hovered]:bg-muted data-[hovered]:text-foreground aria-pressed:text-foreground data-[focus-visible]:outline-solid data-[focus-visible]:outline-(length:--focus-ring-width) data-[focus-visible]:outline-offset-(--focus-ring-offset) data-[focus-visible]:outline-(--color-ring) data-[disabled]:cursor-not-allowed\";\n\nexport interface PasswordFieldProps extends Omit<\n AriaInputProps,\n \"className\" | \"style\" | \"size\" | \"type\"\n> {\n /** Extra classes for the input. Merged last, so they win conflicts with ours. */\n className?: string;\n /** The visible label, tied to the input with `htmlFor`. */\n label: string;\n /**\n * Helper text under the field, named by `aria-describedby`. A string, because\n * the copy is animated word by word: it opens on a spring when it appears\n * after mount and changed words rise in. Nothing animates on first render.\n */\n description?: string;\n /** Translated or reworded toggle names. */\n messages?: Partial<PasswordFieldMessages>;\n}\n\n/**\n * A password input with a show and hide toggle. Switching resolves the text in\n * place from a soft blur, and the eye is one outline that a slash draws across.\n * Native input props apply to the input; `disabled` also disables the toggle,\n * and `aria-invalid` gives the box its invalid border.\n *\n * The toggle's name changes with the state and it is also `aria-pressed`, so a\n * screen reader may announce both (\"Hide password, pressed\").\n *\n * @example\n * <PasswordField label=\"Password\" description=\"At least eight characters.\" />\n */\nexport const PasswordField = forwardRef<HTMLInputElement, PasswordFieldProps>(\n function PasswordField({ label, description, messages: messagesProp, className, ...props }, ref) {\n const messages = { ...defaultPasswordFieldMessages, ...messagesProp };\n const [visible, setVisible] = useState(false);\n // data-reveal only appears after the first toggle, so the animation runs on each change but never on mount.\n const [toggled, setToggled] = useState(false);\n const field = useFieldWiring({\n enabled: true,\n id: props.id,\n describedBy: props[\"aria-describedby\"],\n invalid: props[\"aria-invalid\"],\n description,\n error: undefined,\n });\n const disabled = Boolean(props.disabled);\n const ariaInvalid = props[\"aria-invalid\"];\n const invalid = ariaInvalid !== undefined && ariaInvalid !== false && ariaInvalid !== \"false\";\n\n const control = (\n <AriaGroup\n role=\"presentation\"\n isDisabled={disabled}\n isInvalid={invalid}\n data-slot=\"password-field-shell\"\n className={shellClass}\n >\n <AriaInput\n ref={ref}\n {...props}\n {...field.controlProps}\n type={visible ? \"text\" : \"password\"}\n data-slot=\"password-field\"\n data-reveal={toggled ? (visible ? \"shown\" : \"hidden\") : undefined}\n className={cn(inputClass, className)}\n />\n <AriaButton\n type=\"button\"\n isDisabled={disabled}\n aria-label={visible ? messages.hidePassword : messages.showPassword}\n aria-pressed={visible}\n onPress={() => {\n setVisible((current) => !current);\n setToggled(true);\n }}\n className={toggleClass}\n >\n <EyeMorph slashed={visible} />\n </AriaButton>\n </AriaGroup>\n );\n\n if (!field.active) return control;\n return (\n <FieldShell\n label={label}\n controlId={field.controlId}\n description={description}\n hintId={field.hintId}\n error={undefined}\n errorId={undefined}\n wordExit=\"sharp\"\n numbers={false}\n >\n {control}\n </FieldShell>\n );\n },\n);\n"],"mappings":";;;;;;;;;AAqBA,MAAa,+BAAsD;CACjE,cAAc;CACd,cAAc;AAChB;;;;;;;;;;;;AAaA,MAAM,aAAa,GACjB,qBAAqB,GACrB,mJACF;;AAGA,MAAM,aACJ;AAEF,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riaInput","AriaButton"],"sources":["../../src/password-field/password-field.tsx"],"sourcesContent":["\"use client\";\n\nimport { forwardRef, useId, useState } from \"react\";\nimport {\n Button as AriaButton,\n Group as AriaGroup,\n Input as AriaInput,\n InputContext,\n useSlottedContext,\n type InputProps as AriaInputProps,\n} from \"react-aria-components\";\n\nimport { cn } from \"../lib/cn.js\";\nimport { EyeMorph } from \"../lib/eye-morph.js\";\nimport { FieldMessage } from \"../lib/field-message.js\";\nimport { FieldShell, useFieldWiring } from \"../lib/field-shell.js\";\nimport { fieldSurfaceVariants } from \"../lib/field-surface.js\";\n\n/** The toggle's accessible names. Both have English defaults; pass the ones you translate. */\nexport interface PasswordFieldMessages {\n showPassword: string;\n hidePassword: string;\n}\n\nexport const defaultPasswordFieldMessages: PasswordFieldMessages = {\n showPassword: \"Show password\",\n hidePassword: \"Hide password\",\n};\n\n/**\n * The field's box. A React Aria `Group` rather than the input, because the\n * toggle sits inside the same border: it carries the shared field surface (the\n * 160ms border transition, the darker border on hover and focus, the muted\n * disabled look, the invalid border) and the input inside is borderless.\n *\n * `data-focus-within` darkens the border too. A Group reports focus-visible\n * from the input modality, so a mouse click into the input, or onto the toggle,\n * would otherwise leave the border pale; a plain Input is different because\n * React Aria treats a text input as always keyboard-focused.\n */\nconst shellClass = cn(\n fieldSurfaceVariants(),\n \"flex items-center h-(--density-control-h-md) ps-(--density-control-pad-md) field-toggle-shell [&:where([data-focus-within])]:border-border-strong\",\n);\n\n/** The input inside the box: no border, no fill, no outline of its own. */\nconst inputClass =\n \"min-w-0 flex-1 border-0 bg-transparent p-0 font-sans text-base text-foreground outline-none placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground data-[disabled]:cursor-not-allowed motion-safe:data-[reveal=shown]:animate-field-reveal-shown motion-safe:data-[reveal=hidden]:animate-field-reveal-hidden\";\n\nconst toggleClass =\n \"field-toggle-button grid size-7.5 flex-none cursor-pointer place-items-center rounded-control border-0 bg-transparent p-0 text-muted-foreground outline-none data-[hovered]:bg-muted data-[hovered]:text-foreground aria-pressed:text-foreground data-[focus-visible]:outline-solid data-[focus-visible]:outline-(length:--focus-ring-width) data-[focus-visible]:outline-offset-(--focus-ring-offset) data-[focus-visible]:outline-(--color-ring) data-[disabled]:cursor-not-allowed\";\n\nexport interface PasswordFieldProps extends Omit<\n AriaInputProps,\n \"className\" | \"style\" | \"size\" | \"type\"\n> {\n /** Extra classes for the input. Merged last, so they win conflicts with ours. */\n className?: string;\n /** The visible label, tied to the input with `htmlFor`. */\n label: string;\n /**\n * Helper text under the field, named by `aria-describedby`. A string, because\n * the copy is animated word by word: it opens on a spring when it appears\n * after mount and changed words rise in. Nothing animates on first render.\n */\n description?: string;\n /**\n * Error text under the field. Sets `aria-invalid`, so the box takes its\n * invalid border, and is announced as an alert when it appears. Opens and\n * closes like `description`; an empty or `undefined` value closes the row.\n * The same prop as Input's. Inside a React Aria `TextField` (which supplies\n * the label and description) the error row is still rendered, after the\n * control, and named in the input's `aria-describedby`.\n */\n error?: string;\n /**\n * The field must be filled: the input is `required` (announced by screen\n * readers, and checked by native form validation) and the label shows the\n * required marker.\n */\n isRequired?: boolean;\n /** Translated or reworded toggle names. */\n messages?: Partial<PasswordFieldMessages>;\n}\n\n/**\n * A password input with a show and hide toggle. Switching resolves the text in\n * place from a soft blur, and the eye is one outline that a slash draws across.\n * Native input props apply to the input; `disabled` also disables the toggle,\n * and `aria-invalid` gives the box its invalid border.\n *\n * The toggle's name changes with the state and it is also `aria-pressed`, so a\n * screen reader may announce both (\"Hide password, pressed\").\n *\n * @example\n * <PasswordField label=\"Password\" description=\"At least eight characters.\" />\n * <PasswordField label=\"API secret\" isRequired error={errors.secret?.message} {...register(\"secret\")} />\n */\nexport const PasswordField = forwardRef<HTMLInputElement, PasswordFieldProps>(\n function PasswordField(\n { label, description, error, isRequired, messages: messagesProp, className, ...props },\n ref,\n ) {\n const messages = { ...defaultPasswordFieldMessages, ...messagesProp };\n const [visible, setVisible] = useState(false);\n // data-reveal only appears after the first toggle, so the animation runs on each change but never on mount.\n const [toggled, setToggled] = useState(false);\n const field = useFieldWiring({\n enabled: true,\n id: props.id,\n describedBy: props[\"aria-describedby\"],\n invalid: props[\"aria-invalid\"],\n description,\n error,\n });\n // Inside a React Aria TextField the shell (and its error row) is skipped, since the\n // field supplies the label and description. The error is ours, not the field's,\n // so it is rendered after the control here and added to the input's\n // aria-describedby, after the field's own ids (an explicit prop replaces the\n // context's, so they are carried over). Without this the box turned red with no text.\n const inputContext = useSlottedContext(InputContext) as {\n \"aria-describedby\"?: string;\n } | null;\n const generatedId = useId();\n const insideErrorId = field.inside && error ? `${generatedId}-error` : undefined;\n // The row's wrapper (it carries the font the shell would) is added the first time an\n // error arrives and then kept, so the row can animate closed; without one, nothing is added.\n const [errorRow, setErrorRow] = useState(Boolean(insideErrorId));\n if (insideErrorId && !errorRow) setErrorRow(true);\n const insideProps = insideErrorId\n ? {\n \"aria-invalid\": true,\n \"aria-describedby\": [\n inputContext?.[\"aria-describedby\"],\n props[\"aria-describedby\"],\n insideErrorId,\n ]\n .filter(Boolean)\n .join(\" \"),\n }\n : {};\n const disabled = Boolean(props.disabled);\n const ariaInvalid = props[\"aria-invalid\"];\n const invalid =\n Boolean(error) ||\n (ariaInvalid !== undefined && ariaInvalid !== false && ariaInvalid !== \"false\");\n\n const control = (\n <AriaGroup\n role=\"presentation\"\n isDisabled={disabled}\n isInvalid={invalid}\n data-slot=\"password-field-shell\"\n className={shellClass}\n >\n <AriaInput\n ref={ref}\n {...props}\n {...(isRequired ? { required: true } : {})}\n {...field.controlProps}\n {...insideProps}\n type={visible ? \"text\" : \"password\"}\n data-slot=\"password-field\"\n data-reveal={toggled ? (visible ? \"shown\" : \"hidden\") : undefined}\n className={cn(inputClass, className)}\n />\n <AriaButton\n type=\"button\"\n isDisabled={disabled}\n aria-label={visible ? messages.hidePassword : messages.showPassword}\n aria-pressed={visible}\n onPress={() => {\n setVisible((current) => !current);\n setToggled(true);\n }}\n className={toggleClass}\n >\n <EyeMorph slashed={visible} />\n </AriaButton>\n </AriaGroup>\n );\n\n if (field.inside) {\n // Always this shape inside a field, so an error arriving later does not remount the input.\n return (\n <>\n {control}\n {errorRow ? (\n <div data-slot=\"password-field-error-row\" className=\"grid min-w-0 font-sans\">\n <FieldMessage\n id={insideErrorId}\n text={error}\n tone=\"error\"\n wordExit=\"sharp\"\n numbers={false}\n />\n </div>\n ) : null}\n </>\n );\n }\n if (!field.active) return control;\n return (\n <FieldShell\n label={label}\n controlId={field.controlId}\n description={description}\n hintId={field.hintId}\n error={error}\n errorId={field.errorId}\n required={isRequired}\n wordExit=\"sharp\"\n numbers={false}\n >\n {control}\n </FieldShell>\n );\n },\n);\n"],"mappings":";;;;;;;;;;AAwBA,MAAa,+BAAsD;CACjE,cAAc;CACd,cAAc;AAChB;;;;;;;;;;;;AAaA,MAAM,aAAa,GACjB,qBAAqB,GACrB,mJACF;;AAGA,MAAM,aACJ;AAEF,MAAM,cACJ;;;;;;;;;;;;;;AAgDF,MAAa,gBAAgB,WAC3B,SAAS,cACP,EAAE,OAAO,aAAa,OAAO,YAAY,UAAU,cAAc,WAAW,GAAG,SAC/E,KACA;CACA,MAAM,WAAW;EAAE,GAAG;EAA8B,GAAG;CAAa;CACpE,MAAM,CAAC,SAAS,cAAc,SAAS,KAAK;CAE5C,MAAM,CAAC,SAAS,cAAc,SAAS,KAAK;CAC5C,MAAM,QAAQ,eAAe;EAC3B,SAAS;EACT,IAAI,MAAM;EACV,aAAa,MAAM;EACnB,SAAS,MAAM;EACf;EACA;CACF,CAAC;CAMD,MAAM,eAAe,kBAAkB,YAAY;CAGnD,MAAM,cAAc,MAAM;CAC1B,MAAM,gBAAgB,MAAM,UAAU,QAAQ,GAAG,YAAY,UAAU,KAAA;CAGvE,MAAM,CAAC,UAAU,eAAe,SAAS,QAAQ,aAAa,CAAC;CAC/D,IAAI,iBAAiB,CAAC,UAAU,YAAY,IAAI;CAChD,MAAM,cAAc,gBAChB;EACE,gBAAgB;EAChB,oBAA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ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Popover, PopoverProps, PopoverTrigger, popoverVariants } from "./popover.js";
|
|
2
|
-
export { Popover, type PopoverProps, PopoverTrigger, popoverVariants };
|
|
1
|
+
import { Popover, PopoverHoverTrigger, PopoverHoverTriggerProps, PopoverProps, PopoverTrigger, popoverVariants } from "./popover.js";
|
|
2
|
+
export { Popover, PopoverHoverTrigger, type PopoverHoverTriggerProps, type PopoverProps, PopoverTrigger, popoverVariants };
|
package/dist/popover/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Popover, PopoverTrigger, popoverVariants } from "./popover.js";
|
|
2
|
-
export { Popover, PopoverTrigger, popoverVariants };
|
|
1
|
+
import { Popover, PopoverHoverTrigger, PopoverTrigger, popoverVariants } from "./popover.js";
|
|
2
|
+
export { Popover, PopoverHoverTrigger, PopoverTrigger, popoverVariants };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ReactNode } from "react";
|
|
2
|
-
import { DialogTrigger as PopoverTrigger, PopoverProps } from "react-aria-components";
|
|
1
|
+
import { JSX, ReactNode } from "react";
|
|
2
|
+
import { DialogTrigger as PopoverTrigger, PopoverProps, PreviewTriggerProps } from "react-aria-components";
|
|
3
3
|
//#region src/popover/popover.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* Popover, ported from the legacy shadcn/Radix component.
|
|
@@ -65,6 +65,43 @@ interface PopoverProps$1 extends Omit<PopoverProps, "className" | "style" | "chi
|
|
|
65
65
|
onAction?: () => void;
|
|
66
66
|
}
|
|
67
67
|
declare const Popover$1: import("react").ForwardRefExoticComponent<PopoverProps$1 & import("react").RefAttributes<HTMLElement>>;
|
|
68
|
+
export interface PopoverHoverTriggerProps extends Omit<PreviewTriggerProps, "delay" | "closeDelay"> {
|
|
69
|
+
/** The trigger, then the `Popover`. The trigger must be focusable (a `Button` or `Link`). */
|
|
70
|
+
children: ReactNode;
|
|
71
|
+
/**
|
|
72
|
+
* Milliseconds the pointer rests on the trigger, or keyboard focus sits on
|
|
73
|
+
* it, before the card opens.
|
|
74
|
+
* @default 600
|
|
75
|
+
*/
|
|
76
|
+
delay?: number;
|
|
77
|
+
/**
|
|
78
|
+
* Milliseconds after the pointer leaves the trigger and the card, or focus
|
|
79
|
+
* leaves both, before it closes. Moving onto the card keeps it open.
|
|
80
|
+
* @default 200
|
|
81
|
+
*/
|
|
82
|
+
closeDelay?: number;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Opens a popover on hover instead of press: a hover card.
|
|
86
|
+
*
|
|
87
|
+
* React Aria's `PreviewTrigger`. The card opens after `delay` when the pointer
|
|
88
|
+
* rests on the trigger or keyboard focus reaches it, and on a long press on
|
|
89
|
+
* touch. It stays open while the pointer travels onto it (a safe area covers
|
|
90
|
+
* the gap) and closes `closeDelay` after the pointer or focus leaves both.
|
|
91
|
+
* Escape closes it; Tab from the trigger moves into it. It is non-modal: no
|
|
92
|
+
* focus trap and no underlay, and the page behind stays usable.
|
|
93
|
+
*
|
|
94
|
+
* The trigger keeps its own press action, so a Link still navigates and a
|
|
95
|
+
* Button still runs `onPress`. Content anyone needs must not live only in the
|
|
96
|
+
* card: touch without a long press never sees it.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* <PopoverHoverTrigger delay={300}>
|
|
100
|
+
* <Button variant="ghost" aria-label="3 more sources">+3</Button>
|
|
101
|
+
* <Popover placement="bottom start">...</Popover>
|
|
102
|
+
* </PopoverHoverTrigger>
|
|
103
|
+
*/
|
|
104
|
+
export declare function PopoverHoverTrigger({ delay, closeDelay, ...props }: PopoverHoverTriggerProps): JSX.Element;
|
|
68
105
|
//#endregion
|
|
69
106
|
export { Popover$1 as Popover, PopoverProps$1 as PopoverProps, PopoverTrigger };
|
|
70
107
|
//# sourceMappingURL=popover.d.ts.map
|