@lanfermann/ui 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/accordion/accordion.d.ts +11 -3
- package/dist/components/accordion/accordion.js +15 -10
- package/dist/components/action-bar/action-bar.d.ts +60 -0
- package/dist/components/action-bar/action-bar.js +117 -0
- package/dist/components/alert/alert.d.ts +1 -1
- package/dist/components/alert/alert.js +3 -17
- package/dist/components/alert-dialog/alert-dialog.d.ts +1 -1
- package/dist/components/app-shell/app-shell.d.ts +33 -0
- package/dist/components/app-shell/app-shell.js +93 -0
- package/dist/components/attachment/attachment.d.ts +51 -0
- package/dist/components/attachment/attachment.js +255 -0
- package/dist/components/attachment/kinds.d.ts +7 -0
- package/dist/components/attachment/kinds.js +142 -0
- package/dist/components/avatar/avatar.d.ts +14 -4
- package/dist/components/avatar/avatar.js +57 -13
- package/dist/components/avatar-group/avatar-group.d.ts +33 -0
- package/dist/components/avatar-group/avatar-group.js +110 -0
- package/dist/components/avatar-group/people.d.ts +12 -0
- package/dist/components/avatar-group/people.js +24 -0
- package/dist/components/badge/badge.d.ts +9 -3
- package/dist/components/badge/badge.js +21 -6
- package/dist/components/banner/banner.d.ts +39 -0
- package/dist/components/banner/banner.js +149 -0
- package/dist/components/button-group/button-group-variants.d.ts +4 -3
- package/dist/components/button-group/button-group-variants.js +13 -12
- package/dist/components/button-group/button-group.d.ts +3 -3
- package/dist/components/button-group/button-group.js +3 -3
- package/dist/components/card/card.d.ts +20 -4
- package/dist/components/card/card.js +32 -6
- package/dist/components/checkbox-card/checkbox-card.d.ts +21 -0
- package/dist/components/checkbox-card/checkbox-card.js +50 -0
- package/dist/components/chip/chip-group.d.ts +15 -0
- package/dist/components/chip/chip-group.js +44 -0
- package/dist/components/chip/chip-variants.d.ts +6 -0
- package/dist/components/chip/chip-variants.js +28 -0
- package/dist/components/chip/chip.d.ts +39 -0
- package/dist/components/chip/chip.js +71 -0
- package/dist/components/code-block/code-copy.d.ts +3 -11
- package/dist/components/code-block/code-copy.js +15 -62
- package/dist/components/code-block/code-keys.js +10 -22
- package/dist/components/collapsible/collapsible.js +7 -3
- package/dist/components/combobox/combobox.d.ts +53 -3
- package/dist/components/combobox/combobox.js +204 -20
- package/dist/components/command/command.d.ts +131 -0
- package/dist/components/command/command.js +335 -0
- package/dist/components/consent/consent-card.js +365 -0
- package/dist/components/consent/consent-embed.d.ts +21 -0
- package/dist/components/consent/consent-embed.js +111 -0
- package/dist/components/consent/consent-labels.d.ts +70 -0
- package/dist/components/consent/consent-labels.js +61 -0
- package/dist/components/consent/consent-record.d.ts +95 -0
- package/dist/components/consent/consent-record.js +112 -0
- package/dist/components/consent/consent-store.d.ts +26 -0
- package/dist/components/consent/consent-store.js +240 -0
- package/dist/components/consent/consent.d.ts +86 -0
- package/dist/components/consent/consent.js +306 -0
- package/dist/components/container/container.d.ts +1 -1
- package/dist/components/context-menu/context-menu.d.ts +23 -0
- package/dist/components/context-menu/context-menu.js +50 -0
- package/dist/components/conversation/conversation.d.ts +45 -0
- package/dist/components/conversation/conversation.js +295 -0
- package/dist/components/conversation/stick.js +23 -0
- package/dist/components/copy-button/copy-button.d.ts +50 -0
- package/dist/components/copy-button/copy-button.js +65 -0
- package/dist/components/copy-page/copy-page.d.ts +4 -4
- package/dist/components/copy-page/copy-page.js +16 -36
- package/dist/components/copy-pill/copy-pill.js +1 -1
- package/dist/components/description-list/description-list.d.ts +32 -0
- package/dist/components/description-list/description-list.js +51 -0
- package/dist/components/empty/empty.d.ts +38 -0
- package/dist/components/empty/empty.js +57 -0
- package/dist/components/field/field.js +1 -1
- package/dist/components/file-upload/file-upload.d.ts +96 -0
- package/dist/components/file-upload/file-upload.js +347 -0
- package/dist/components/file-upload/files.d.ts +39 -0
- package/dist/components/file-upload/files.js +74 -0
- package/dist/components/grow/grow.d.ts +15 -3
- package/dist/components/grow/grow.js +24 -9
- package/dist/components/heading/heading.d.ts +1 -1
- package/dist/components/icon/icon.d.ts +1 -1
- package/dist/components/input/input.js +1 -1
- package/dist/components/menu/menu.d.ts +20 -8
- package/dist/components/menu/menu.js +51 -29
- package/dist/components/message/message.d.ts +81 -0
- package/dist/components/message/message.js +208 -0
- package/dist/components/navigation-menu/navigation-menu.d.ts +7 -1
- package/dist/components/navigation-menu/navigation-menu.js +11 -4
- package/dist/components/otp-field/otp-field.d.ts +37 -0
- package/dist/components/otp-field/otp-field.js +161 -0
- package/dist/components/pagination/pagination.d.ts +50 -0
- package/dist/components/pagination/pagination.js +188 -0
- package/dist/components/prompt-input/keys.js +15 -0
- package/dist/components/prompt-input/prompt-input.d.ts +89 -0
- package/dist/components/prompt-input/prompt-input.js +331 -0
- package/dist/components/radio-card/radio-card.d.ts +23 -0
- package/dist/components/radio-card/radio-card.js +49 -0
- package/dist/components/rolling-number/rolling-number.d.ts +30 -0
- package/dist/components/rolling-number/rolling-number.js +149 -0
- package/dist/components/seam/seam.d.ts +1 -1
- package/dist/components/secret-field/secret-field.d.ts +53 -0
- package/dist/components/secret-field/secret-field.js +121 -0
- package/dist/components/section/section.d.ts +1 -1
- package/dist/components/segmented-control/segmented-control.js +29 -16
- package/dist/components/select/select.d.ts +5 -4
- package/dist/components/select/select.js +16 -11
- package/dist/components/shortcut/shortcut.d.ts +46 -0
- package/dist/components/shortcut/shortcut.js +87 -0
- package/dist/components/sidebar/sidebar-context.js +16 -0
- package/dist/components/sidebar/sidebar.d.ts +161 -0
- package/dist/components/sidebar/sidebar.js +588 -0
- package/dist/components/site-header/site-header.js +1 -1
- package/dist/components/skeleton/loaded.d.ts +21 -0
- package/dist/components/skeleton/loaded.js +57 -0
- package/dist/components/skeleton/skeleton.d.ts +43 -0
- package/dist/components/skeleton/skeleton.js +48 -0
- package/dist/components/sources/source-list.d.ts +17 -0
- package/dist/components/sources/source-list.js +26 -0
- package/dist/components/sources/sources.d.ts +45 -0
- package/dist/components/sources/sources.js +167 -0
- package/dist/components/stat/stat.d.ts +59 -0
- package/dist/components/stat/stat.js +112 -0
- package/dist/components/steps/steps.d.ts +57 -0
- package/dist/components/steps/steps.js +134 -0
- package/dist/components/table/table.d.ts +18 -9
- package/dist/components/table/table.js +21 -13
- package/dist/components/text/text.d.ts +1 -1
- package/dist/components/theme-switch/theme-switch.js +1 -1
- package/dist/components/time-field/time-field.js +7 -6
- package/dist/components/timeline/timeline.d.ts +45 -0
- package/dist/components/timeline/timeline.js +86 -0
- package/dist/components/toast/toast.js +10 -26
- package/dist/components/toggle/toggle.d.ts +27 -0
- package/dist/components/toggle/toggle.js +61 -0
- package/dist/components/toggle-group/toggle-group.d.ts +27 -0
- package/dist/components/toggle-group/toggle-group.js +38 -0
- package/dist/components/toolbar/toolbar-context.js +12 -0
- package/dist/components/toolbar/toolbar.d.ts +52 -0
- package/dist/components/toolbar/toolbar.js +105 -0
- package/dist/components/trace/trace.d.ts +2 -1
- package/dist/components/trace/trace.js +15 -27
- package/dist/index.d.ts +46 -3
- package/dist/index.js +44 -3
- package/dist/internal/arriving-pieces.js +56 -0
- package/dist/internal/arriving.js +171 -0
- package/dist/internal/avatar-cut.d.ts +15 -0
- package/dist/internal/avatar-cut.js +83 -0
- package/dist/internal/choice-card.d.ts +15 -0
- package/dist/internal/choice-card.js +81 -0
- package/dist/internal/clipboard.js +37 -0
- package/dist/internal/copy.js +58 -0
- package/dist/internal/disclosure.js +15 -3
- package/dist/internal/field.js +24 -4
- package/dist/internal/glyphs.js +26 -1
- package/dist/internal/key-tip.js +18 -0
- package/dist/internal/list-mark.js +39 -0
- package/dist/internal/live-list.js +41 -0
- package/dist/internal/number-places.js +157 -0
- package/dist/internal/picker-sheet.js +1 -1
- package/dist/internal/presence-dot.js +24 -0
- package/dist/internal/presence.js +104 -0
- package/dist/internal/rail-mark.d.ts +3 -0
- package/dist/internal/rail-mark.js +33 -0
- package/dist/internal/rule.js +2 -1
- package/dist/internal/status-icon.js +22 -0
- package/dist/internal/tile.js +23 -0
- package/dist/internal/travelling-mark.js +204 -0
- package/dist/lib/cn.js +10 -0
- package/dist/lib/shortcut.d.ts +11 -0
- package/dist/lib/shortcut.js +165 -0
- package/package.json +1 -1
- package/src/styles/accordion.css +176 -0
- package/src/styles/action-bar.css +28 -0
- package/src/styles/assistant.css +83 -0
- package/src/styles/avatar.css +24 -0
- package/src/styles/consent.css +65 -0
- package/src/styles/copy.css +12 -11
- package/src/styles/depth.css +120 -4
- package/src/styles/marks.css +20 -2
- package/src/styles/motion.css +3 -0
- package/src/styles/rail.css +49 -0
- package/src/styles/rolling-number.css +94 -0
- package/src/styles/segmented.css +14 -7
- package/src/styles/steps.css +98 -0
- package/src/styles/timeline.css +48 -0
- package/src/styles/travel.css +36 -0
- package/src/styles.css +10 -0
|
@@ -1,13 +1,26 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { chipDisabledLook, chipFace, chipMotion, chipRemoveKey, chipShape } from "../chip/chip-variants.js";
|
|
2
3
|
import { useGround } from "../ground/ground.js";
|
|
4
|
+
import { Grow } from "../grow/grow.js";
|
|
3
5
|
import { Icon } from "../icon/icon.js";
|
|
4
|
-
import { bareControl, fieldShell, fieldShellSize, focusFieldControl } from "../../internal/field.js";
|
|
5
|
-
import { ChevronDownGlyph, CloseGlyph } from "../../internal/glyphs.js";
|
|
6
|
+
import { bareControl, fieldShell, fieldShellGrowing, fieldShellGrowingSize, fieldShellSize, fieldText, focusFieldControl } from "../../internal/field.js";
|
|
7
|
+
import { ChevronDownGlyph, CloseGlyph, PlusGlyph } from "../../internal/glyphs.js";
|
|
8
|
+
import { ListMark, listTint } from "../../internal/list-mark.js";
|
|
6
9
|
import { listGroupLabel, listItem, listSeparator, listSheet, popupMotion } from "../../internal/popup.js";
|
|
10
|
+
import { placeInRow, placeProps, useLive, usePresence } from "../../internal/presence.js";
|
|
7
11
|
import { cn, mergeClassName } from "../../lib/cn.js";
|
|
8
12
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
13
|
+
import { createContext, useContext, useRef, useState } from "react";
|
|
9
14
|
import { Combobox as Combobox$1 } from "@base-ui/react/combobox";
|
|
10
15
|
// src/components/combobox/combobox.tsx
|
|
16
|
+
function isOption(value) {
|
|
17
|
+
return typeof value === "object" && value !== null && "label" in value;
|
|
18
|
+
}
|
|
19
|
+
function isCreateOption(value) {
|
|
20
|
+
return isOption(value) && "create" in value;
|
|
21
|
+
}
|
|
22
|
+
/** Whether several options can be chosen: their rows then carry the tick, not the disc. */
|
|
23
|
+
const MultipleContext = createContext(false);
|
|
11
24
|
/**
|
|
12
25
|
* A select you can type into: for lists too long to scan (a customer out of two hundred), where
|
|
13
26
|
* people know what they are looking for. Typing filters the list; only an entry of the list can
|
|
@@ -17,21 +30,69 @@ import { Combobox as Combobox$1 } from "@base-ui/react/combobox";
|
|
|
17
30
|
* object, is the value: `defaultValue={items[0]}`, `onValueChange={(option) => …}`. In a form
|
|
18
31
|
* its `value` is what is submitted.
|
|
19
32
|
*
|
|
33
|
+
* With `multiple` the value is a list of options and the field is a `ComboboxChips`: every
|
|
34
|
+
* chosen option is a chip in it. The list then stays open after a choice, so several can be
|
|
35
|
+
* taken in a row, and each is submitted under the field's name.
|
|
36
|
+
*
|
|
20
37
|
* Typing ignores case and accents: "gart" finds "Gärtnerei" and "cafe" finds "Café". Pass
|
|
21
38
|
* `locale` (`"de-DE"`) so that does not depend on the machine. The first match is highlighted
|
|
22
39
|
* while typing, so Enter takes it.
|
|
23
40
|
*/
|
|
24
|
-
function Combobox({ autoHighlight = true, filter, locale, ...props }) {
|
|
41
|
+
function Combobox({ autoHighlight = true, filter, locale, items, multiple, onCreate, createLabel = (label) => `„${label}“ anlegen`, inputValue, defaultInputValue, onInputValueChange, onValueChange, onOpenChange, ...props }) {
|
|
25
42
|
const folding = Combobox$1.useFilter({
|
|
26
43
|
locale,
|
|
27
44
|
usage: "sort",
|
|
28
45
|
sensitivity: "base"
|
|
29
46
|
});
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
47
|
+
const [typed, setTyped] = useState(typeof defaultInputValue === "string" ? defaultInputValue : "");
|
|
48
|
+
const ownsText = multiple === true && inputValue === void 0;
|
|
49
|
+
const wanted = onCreate ? typed.trim() : "";
|
|
50
|
+
let offered = items;
|
|
51
|
+
if (wanted !== "" && Array.isArray(items) && items.every(isOption)) {
|
|
52
|
+
const sameName = new Intl.Collator(locale, { sensitivity: "base" });
|
|
53
|
+
if (!items.some((option) => sameName.compare(option.label, wanted) === 0)) {
|
|
54
|
+
const create = {
|
|
55
|
+
value: wanted,
|
|
56
|
+
label: wanted,
|
|
57
|
+
create: createLabel(wanted)
|
|
58
|
+
};
|
|
59
|
+
offered = [...items, create];
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const changed = (next, details) => {
|
|
63
|
+
if (ownsText && details.reason === "item-press") setTyped("");
|
|
64
|
+
const chosen = Array.isArray(next) ? next : [next];
|
|
65
|
+
const made = onCreate ? chosen.find(isCreateOption) : void 0;
|
|
66
|
+
if (!made || !onCreate) {
|
|
67
|
+
onValueChange?.(next, details);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const option = onCreate(made.label);
|
|
71
|
+
const others = chosen.filter((entry) => !isCreateOption(entry));
|
|
72
|
+
const value = multiple ? option === void 0 ? others : [...others, option] : option ?? null;
|
|
73
|
+
onValueChange?.(value, details);
|
|
74
|
+
};
|
|
75
|
+
return /* @__PURE__ */ jsx(MultipleContext, {
|
|
76
|
+
value: multiple === true,
|
|
77
|
+
children: /* @__PURE__ */ jsx(Combobox$1.Root, {
|
|
78
|
+
autoHighlight,
|
|
79
|
+
locale,
|
|
80
|
+
filter: filter === void 0 ? folding.contains : filter,
|
|
81
|
+
items: offered,
|
|
82
|
+
multiple,
|
|
83
|
+
inputValue: ownsText ? typed : inputValue,
|
|
84
|
+
defaultInputValue: ownsText ? void 0 : defaultInputValue,
|
|
85
|
+
onInputValueChange: (value, details) => {
|
|
86
|
+
setTyped(value);
|
|
87
|
+
onInputValueChange?.(value, details);
|
|
88
|
+
},
|
|
89
|
+
onValueChange: changed,
|
|
90
|
+
onOpenChange: (open, details) => {
|
|
91
|
+
if (multiple && !open && details.reason === "item-press") details.cancel();
|
|
92
|
+
onOpenChange?.(open, details);
|
|
93
|
+
},
|
|
94
|
+
...props
|
|
95
|
+
})
|
|
35
96
|
});
|
|
36
97
|
}
|
|
37
98
|
/** A small quiet button inside the field: the clear cross and the chevron. */
|
|
@@ -74,6 +135,116 @@ function ComboboxInput({ className, size = "md", clearLabel = "Auswahl löschen"
|
|
|
74
135
|
]
|
|
75
136
|
});
|
|
76
137
|
}
|
|
138
|
+
const chipKey = (item) => String(isOption(item) ? item.value : item);
|
|
139
|
+
const chipText = (item) => isOption(item) ? item.label : String(item);
|
|
140
|
+
/**
|
|
141
|
+
* The chips and the input, in one row that wraps. A chip that its owner took out of the value
|
|
142
|
+
* stays where it stood until it has faded, as in a `ChipGroup`, but as a plain copy: Base UI
|
|
143
|
+
* counts its chips to know which one Backspace takes, and one that is gone must not be counted.
|
|
144
|
+
*/
|
|
145
|
+
function ChipsRow({ chosen, chipVariant, chipsLabel, removeLabel, chipsHint, placeholder, ...props }) {
|
|
146
|
+
const live = useLive();
|
|
147
|
+
const row = useRef(null);
|
|
148
|
+
const { places, left } = usePresence(chosen, chipKey, row);
|
|
149
|
+
const look = cn(chipShape, chipFace[chipVariant], "pr-0.5");
|
|
150
|
+
return /* @__PURE__ */ jsxs(Combobox$1.Chips, {
|
|
151
|
+
ref: row,
|
|
152
|
+
"data-slot": "combobox-chips",
|
|
153
|
+
"data-live": live ? "" : void 0,
|
|
154
|
+
"aria-label": chosen.length > 0 ? chipsLabel : void 0,
|
|
155
|
+
className: "flex min-h-(--field-height) min-w-0 flex-1 flex-wrap items-center gap-(--chip-gap) p-[calc((var(--field-height)-1.375rem)/2)] [--chip-gap:0.25rem]",
|
|
156
|
+
children: [places.map((place) => {
|
|
157
|
+
const text = chipText(place.item);
|
|
158
|
+
return /* @__PURE__ */ jsx("span", {
|
|
159
|
+
"data-slot": "chip-place",
|
|
160
|
+
...placeProps(place, left),
|
|
161
|
+
className: placeInRow,
|
|
162
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
163
|
+
className: "flex min-w-0 *:shrink-0",
|
|
164
|
+
children: place.leaving ? /* @__PURE__ */ jsxs("span", {
|
|
165
|
+
"aria-hidden": true,
|
|
166
|
+
"data-slot": "combobox-chip",
|
|
167
|
+
className: cn(look, "opacity-0 transition-opacity spring-leave starting:opacity-100"),
|
|
168
|
+
children: [text, /* @__PURE__ */ jsx("span", {
|
|
169
|
+
className: "flex size-[1.125rem] items-center justify-center text-fg-muted",
|
|
170
|
+
children: /* @__PURE__ */ jsx(CloseGlyph, {
|
|
171
|
+
width: 8,
|
|
172
|
+
height: 8
|
|
173
|
+
})
|
|
174
|
+
})]
|
|
175
|
+
}) : /* @__PURE__ */ jsxs(Combobox$1.Chip, {
|
|
176
|
+
"data-slot": "combobox-chip",
|
|
177
|
+
"aria-label": text,
|
|
178
|
+
className: cn(look, chipDisabledLook, "data-disabled:pr-2", chipMotion, "focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-accent"),
|
|
179
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
180
|
+
"data-slot": "chip-label",
|
|
181
|
+
className: "truncate",
|
|
182
|
+
children: text
|
|
183
|
+
}), /* @__PURE__ */ jsx(Combobox$1.ChipRemove, {
|
|
184
|
+
"data-slot": "chip-remove",
|
|
185
|
+
"aria-label": `${text} ${removeLabel}`,
|
|
186
|
+
className: cn(chipRemoveKey, "data-disabled:hidden"),
|
|
187
|
+
children: /* @__PURE__ */ jsx(CloseGlyph, {
|
|
188
|
+
width: 8,
|
|
189
|
+
height: 8
|
|
190
|
+
})
|
|
191
|
+
})]
|
|
192
|
+
})
|
|
193
|
+
})
|
|
194
|
+
}, place.key);
|
|
195
|
+
}), /* @__PURE__ */ jsx(Combobox$1.Input, {
|
|
196
|
+
"data-slot": "combobox-input",
|
|
197
|
+
"data-field-control": "",
|
|
198
|
+
placeholder: chosen.length > 0 ? void 0 : placeholder,
|
|
199
|
+
"aria-description": chosen.length > 0 ? chipsHint(chosen.length) : void 0,
|
|
200
|
+
className: cn("h-[1.375rem] bg-transparent px-1.5 text-control text-fg focus:outline-hidden data-disabled:text-on-disabled", "w-12 max-w-full min-w-12 grow supports-[field-sizing:content]:[field-sizing:content] supports-[field-sizing:content]:w-auto supports-[field-sizing:content]:min-w-6", "first:pl-[calc(var(--field-pad)-(var(--field-height)-1.375rem)/2)]", fieldText),
|
|
201
|
+
...props
|
|
202
|
+
})]
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* The field of a `Combobox multiple`: every chosen option is a chip in it, and the input stands
|
|
207
|
+
* after the last one. Backspace in the empty input takes the last chip, Arrow left walks into
|
|
208
|
+
* the chips, and each chip has a key that takes it away.
|
|
209
|
+
*
|
|
210
|
+
* A chip that joins seats into its place, one that leaves fades while its neighbours close up,
|
|
211
|
+
* and when the chips need another line the field eases to its new height, so what stands below
|
|
212
|
+
* is pushed and does not jump. Give it a name with a `FieldLabel` or an `aria-label`; the
|
|
213
|
+
* placeholder is an example and shows only while nothing is chosen.
|
|
214
|
+
*/
|
|
215
|
+
function ComboboxChips({ className, size = "md", chipVariant = "flat", chipsLabel = "Ausgewählt", removeLabel = "entfernen", chipsHint = (count) => `${count} ausgewählt. Am Anfang des Felds führt die Pfeiltaste nach links zu den gewählten Einträgen.`, clearLabel = "Auswahl löschen", openLabel = "Liste öffnen", ...props }) {
|
|
216
|
+
return /* @__PURE__ */ jsxs(Combobox$1.InputGroup, {
|
|
217
|
+
"data-slot": "combobox-input-group",
|
|
218
|
+
"data-size": size,
|
|
219
|
+
render: /* @__PURE__ */ jsx(Grow, {
|
|
220
|
+
contentClassName: "flex items-start",
|
|
221
|
+
className: cn(fieldShellGrowing, fieldShellGrowingSize[size], "has-[[data-slot=combobox-chip]:focus-visible]:depth-field-focus", className)
|
|
222
|
+
}),
|
|
223
|
+
onMouseDown: focusFieldControl,
|
|
224
|
+
children: [
|
|
225
|
+
/* @__PURE__ */ jsx(Combobox$1.Value, { children: (chosen) => /* @__PURE__ */ jsx(ChipsRow, {
|
|
226
|
+
chosen: chosen ?? [],
|
|
227
|
+
chipVariant,
|
|
228
|
+
chipsLabel,
|
|
229
|
+
removeLabel,
|
|
230
|
+
chipsHint,
|
|
231
|
+
...props
|
|
232
|
+
}) }),
|
|
233
|
+
/* @__PURE__ */ jsx(Combobox$1.Clear, {
|
|
234
|
+
"data-slot": "combobox-clear",
|
|
235
|
+
"aria-label": clearLabel,
|
|
236
|
+
className: cn(innerButton, "mt-1 transition-[opacity,scale] spring-snap data-disabled:hidden data-starting-style:scale-75 data-starting-style:opacity-0", "data-ending-style:opacity-0 data-ending-style:spring-leave"),
|
|
237
|
+
children: /* @__PURE__ */ jsx(CloseGlyph, {})
|
|
238
|
+
}),
|
|
239
|
+
/* @__PURE__ */ jsx(Combobox$1.Trigger, {
|
|
240
|
+
"data-slot": "combobox-trigger",
|
|
241
|
+
"aria-label": openLabel,
|
|
242
|
+
className: cn(innerButton, "mt-1"),
|
|
243
|
+
children: /* @__PURE__ */ jsx(ChevronDownGlyph, {})
|
|
244
|
+
})
|
|
245
|
+
]
|
|
246
|
+
});
|
|
247
|
+
}
|
|
77
248
|
/**
|
|
78
249
|
* The list, as a sheet that grows out of the field and is at least as wide. It looks and behaves
|
|
79
250
|
* like the list of a `Select` or a `Menu`.
|
|
@@ -109,41 +280,54 @@ function ComboboxContent({ className, side = "bottom", align = "start", sideOffs
|
|
|
109
280
|
})
|
|
110
281
|
}) });
|
|
111
282
|
}
|
|
112
|
-
function isOption(value) {
|
|
113
|
-
return typeof value === "object" && value !== null && "label" in value;
|
|
114
|
-
}
|
|
115
283
|
/**
|
|
116
284
|
* One row. Pass the option as `value`; its label, icon and detail are shown unless you give
|
|
117
|
-
* children or props of your own.
|
|
285
|
+
* children or props of your own. As in a `Select`, the chosen row carries its mark at the right
|
|
286
|
+
* end (the disc, or the tick where several can be chosen), or stands on the tint where the rows
|
|
287
|
+
* have a detail; chosen rows that touch are one shape.
|
|
118
288
|
*/
|
|
119
289
|
function ComboboxItem({ className, children, icon, detail, value, ...props }) {
|
|
120
290
|
const itemValue = value;
|
|
121
291
|
const option = isOption(itemValue) ? itemValue : void 0;
|
|
122
292
|
const resolvedIcon = icon ?? option?.icon;
|
|
123
293
|
const resolvedDetail = detail ?? option?.detail;
|
|
294
|
+
const multiple = useContext(MultipleContext);
|
|
295
|
+
const create = isCreateOption(itemValue);
|
|
296
|
+
const tinted = resolvedDetail !== void 0;
|
|
124
297
|
return /* @__PURE__ */ jsxs(Combobox$1.Item, {
|
|
125
298
|
"data-slot": "combobox-item",
|
|
126
299
|
value: itemValue,
|
|
127
|
-
className: mergeClassName([
|
|
300
|
+
className: mergeClassName([
|
|
301
|
+
"group",
|
|
302
|
+
listItem,
|
|
303
|
+
tinted && listTint
|
|
304
|
+
], className),
|
|
128
305
|
...props,
|
|
129
306
|
children: [
|
|
130
|
-
/* @__PURE__ */ jsx("span", {
|
|
307
|
+
create ? /* @__PURE__ */ jsx("span", {
|
|
131
308
|
"aria-hidden": true,
|
|
132
|
-
className: "
|
|
133
|
-
|
|
134
|
-
|
|
309
|
+
className: "flex size-4 shrink-0 items-center justify-center text-fg-muted",
|
|
310
|
+
children: /* @__PURE__ */ jsx(PlusGlyph, {
|
|
311
|
+
width: 10,
|
|
312
|
+
height: 10
|
|
313
|
+
})
|
|
314
|
+
}) : resolvedIcon && /* @__PURE__ */ jsx(Icon, {
|
|
135
315
|
icon: resolvedIcon,
|
|
136
|
-
className: "text-fg-muted"
|
|
316
|
+
className: "text-fg-muted group-data-highlighted:text-fg"
|
|
137
317
|
}),
|
|
138
318
|
/* @__PURE__ */ jsx("span", {
|
|
139
319
|
"data-slot": "combobox-item-text",
|
|
140
320
|
className: "min-w-0 truncate",
|
|
141
|
-
children: children ?? option?.label
|
|
321
|
+
children: children ?? (create ? itemValue.create : option?.label)
|
|
142
322
|
}),
|
|
143
323
|
resolvedDetail !== void 0 && /* @__PURE__ */ jsx("span", {
|
|
144
324
|
"data-slot": "combobox-item-detail",
|
|
145
325
|
className: "ml-auto shrink-0 pl-3 whitespace-nowrap text-fg-muted tabular-nums",
|
|
146
326
|
children: resolvedDetail
|
|
327
|
+
}),
|
|
328
|
+
!create && !tinted && /* @__PURE__ */ jsx(ListMark, {
|
|
329
|
+
kind: multiple ? "multiple" : "single",
|
|
330
|
+
className: "ml-auto"
|
|
147
331
|
})
|
|
148
332
|
]
|
|
149
333
|
});
|
|
@@ -166,4 +350,4 @@ function ComboboxSeparator({ className, ...props }) {
|
|
|
166
350
|
...props
|
|
167
351
|
});
|
|
168
352
|
}
|
|
169
|
-
export { Combobox, ComboboxCollection, ComboboxContent, ComboboxGroup, ComboboxGroupLabel, ComboboxInput, ComboboxItem, ComboboxSeparator };
|
|
353
|
+
export { Combobox, ComboboxChips, ComboboxCollection, ComboboxContent, ComboboxGroup, ComboboxGroupLabel, ComboboxInput, ComboboxItem, ComboboxSeparator };
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { IconSvgElement } from "../icon/icon.js";
|
|
2
|
+
import { ComponentProps, ReactNode } from "react";
|
|
3
|
+
import { Autocomplete } from "@base-ui/react/autocomplete";
|
|
4
|
+
import { Dialog } from "@base-ui/react/dialog";
|
|
5
|
+
/** One thing the palette offers: a page to go to, or something to do. */
|
|
6
|
+
export type CommandEntry = {
|
|
7
|
+
/** Tells the entries apart. */
|
|
8
|
+
value: string;
|
|
9
|
+
/** What is shown and typed against. */
|
|
10
|
+
label: string;
|
|
11
|
+
/** Stands before the label. Give every entry of a list one or none. */
|
|
12
|
+
icon?: IconSvgElement;
|
|
13
|
+
/** Other words it is found by: "neu" and "erstellen" for "Angebot schreiben". */
|
|
14
|
+
keywords?: readonly string[];
|
|
15
|
+
/** A quiet fact at the end of the row: where it belongs, how many there are. */
|
|
16
|
+
detail?: ReactNode;
|
|
17
|
+
/** The shortcut that does the same without the palette, written as `Shortcut` writes one. */
|
|
18
|
+
shortcut?: string;
|
|
19
|
+
/** What choosing it does. The palette closes afterwards. */
|
|
20
|
+
onSelect?: () => void;
|
|
21
|
+
/**
|
|
22
|
+
* Entries of its own. Choosing it then opens them as a second list in the same sheet,
|
|
23
|
+
* instead of closing: "Kunde zuweisen …" opens the customers.
|
|
24
|
+
*/
|
|
25
|
+
page?: CommandItems;
|
|
26
|
+
/** The placeholder of the field while its page is open: an example of one of its entries. */
|
|
27
|
+
pagePlaceholder?: string;
|
|
28
|
+
disabled?: boolean;
|
|
29
|
+
};
|
|
30
|
+
/** Entries that belong together, under their name (`value`). */
|
|
31
|
+
export type CommandSection = {
|
|
32
|
+
value: string;
|
|
33
|
+
items: readonly CommandEntry[];
|
|
34
|
+
};
|
|
35
|
+
/** What a list holds: entries, or sections of entries. */
|
|
36
|
+
export type CommandItems = readonly CommandEntry[] | readonly CommandSection[];
|
|
37
|
+
export type CommandProps = {
|
|
38
|
+
/** What the palette offers: entries, or sections of entries. */
|
|
39
|
+
items: CommandItems;
|
|
40
|
+
/** Whether the palette is open (controlled). */
|
|
41
|
+
open?: boolean;
|
|
42
|
+
/** Whether the palette is open at first. */
|
|
43
|
+
defaultOpen?: boolean;
|
|
44
|
+
onOpenChange?: (open: boolean) => void;
|
|
45
|
+
/** The shortcut that opens and closes it, written as `Shortcut` writes one. `false` for none. */
|
|
46
|
+
shortcut?: string | false;
|
|
47
|
+
/** What stands in the field when the palette opens. Nothing unless set. */
|
|
48
|
+
defaultQuery?: string;
|
|
49
|
+
/** Called with what is typed, for a palette that fetches its entries. */
|
|
50
|
+
onQueryChange?: (query: string) => void;
|
|
51
|
+
/** The name of the palette and of its field for assistive tech. */
|
|
52
|
+
label?: string;
|
|
53
|
+
/** The language entries are compared in while typing (`"de-DE"`). The machine's unless set. */
|
|
54
|
+
locale?: Intl.LocalesArgument;
|
|
55
|
+
/**
|
|
56
|
+
* Whether the page behind is inert. Leave it on: the palette is a dialog. `false` is for a
|
|
57
|
+
* palette that is shown standing open, as in a picture of it.
|
|
58
|
+
*/
|
|
59
|
+
modal?: boolean;
|
|
60
|
+
children: ReactNode;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* The command palette: every page and every action of an app, reached by typing a few letters.
|
|
64
|
+
* It opens on ⌘K over whatever one is doing, and leaves as soon as something is chosen. It is
|
|
65
|
+
* for people who know what they want; everything in it must also be reachable by pointing.
|
|
66
|
+
*
|
|
67
|
+
* Give it the entries as `items` and put a `CommandContent` inside, with a `CommandInput`, a
|
|
68
|
+
* `CommandList` and a `CommandFooter`. An entry does something (`onSelect`) or opens a list of
|
|
69
|
+
* its own (`page`). Typing filters by label and keywords, ignoring case and accents.
|
|
70
|
+
*
|
|
71
|
+
* Word an entry like a button, the thing first and the action last ("Angebot schreiben"), or
|
|
72
|
+
* as the place it leads to ("Einstellungen"). An entry that opens a second list ends in an
|
|
73
|
+
* ellipsis ("Kunde zuweisen …").
|
|
74
|
+
*/
|
|
75
|
+
export declare function Command({ items, open: controlled, defaultOpen, onOpenChange, shortcut, defaultQuery, onQueryChange, label, locale, modal, children }: CommandProps): import("react").JSX.Element;
|
|
76
|
+
/**
|
|
77
|
+
* A button that opens the palette, for those who do not know the shortcut yet. Render a
|
|
78
|
+
* `Button` through it and show the shortcut inside:
|
|
79
|
+
* `<CommandTrigger render={<Button />}>Suchen <Shortcut keys="mod+k" /></CommandTrigger>`.
|
|
80
|
+
*/
|
|
81
|
+
export declare function CommandTrigger(props: Dialog.Trigger.Props): import("react").JSX.Element;
|
|
82
|
+
export type CommandContentProps = Dialog.Popup.Props;
|
|
83
|
+
/**
|
|
84
|
+
* The sheet, with its scrim: the page behind is dimmed as it is behind a dialog. It stands in
|
|
85
|
+
* the upper third of the window, where the eyes are and where a phone's keyboard leaves it
|
|
86
|
+
* alone.
|
|
87
|
+
*
|
|
88
|
+
* It is opened many times a day, mostly from the keyboard, so it does not make an entrance: it
|
|
89
|
+
* is there on `snap`, grown by a fiftieth and without travel, and it leaves by fading.
|
|
90
|
+
*/
|
|
91
|
+
export declare function CommandContent({ className, children, ...props }: CommandContentProps): import("react").JSX.Element;
|
|
92
|
+
export type CommandInputProps = Omit<Autocomplete.Input.Props, "className"> & {
|
|
93
|
+
className?: string;
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* The field one types into. It has no frame of its own: it is the head of the sheet. A page
|
|
97
|
+
* that was opened stands before the text as a small plug, and Backspace in the empty field
|
|
98
|
+
* goes back out of it.
|
|
99
|
+
*
|
|
100
|
+
* The placeholder is an example of what can be typed ("z. B. Angebot schreiben"), not an
|
|
101
|
+
* instruction.
|
|
102
|
+
*/
|
|
103
|
+
export declare function CommandInput({ className, placeholder, onKeyDown, ...props }: CommandInputProps): import("react").JSX.Element;
|
|
104
|
+
export type CommandListProps = Omit<ComponentProps<"div">, "children"> & {
|
|
105
|
+
/**
|
|
106
|
+
* What stands there when nothing matches: one sentence that names the kind of thing that was
|
|
107
|
+
* looked for ("Zu dieser Suche wurde nichts gefunden.").
|
|
108
|
+
*/
|
|
109
|
+
empty?: ReactNode;
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
* The entries that match what was typed, in their sections. The first one is highlighted, so
|
|
113
|
+
* Enter takes it; the arrows move the highlight, which is instant like a menu's. The list is
|
|
114
|
+
* as tall as what it holds, up to a limit, and the sheet follows it instead of jumping.
|
|
115
|
+
*/
|
|
116
|
+
export declare function CommandList({ empty, className, ...props }: CommandListProps): import("react").JSX.Element;
|
|
117
|
+
export type CommandFooterProps = ComponentProps<"div"> & {
|
|
118
|
+
/** What Enter does with the highlighted entry. */
|
|
119
|
+
chooseLabel?: string;
|
|
120
|
+
/** What the arrow keys do. */
|
|
121
|
+
moveLabel?: string;
|
|
122
|
+
/** What Backspace does inside a page. */
|
|
123
|
+
backLabel?: string;
|
|
124
|
+
/** What Escape does. */
|
|
125
|
+
closeLabel?: string;
|
|
126
|
+
};
|
|
127
|
+
/**
|
|
128
|
+
* The foot of the sheet: the keys that work here, said once. It is for the eye only, and it is
|
|
129
|
+
* not there on a touch screen, which has no keys. Pass children to put something else there.
|
|
130
|
+
*/
|
|
131
|
+
export declare function CommandFooter({ chooseLabel, moveLabel, backLabel, closeLabel, className, children, ...props }: CommandFooterProps): import("react").JSX.Element;
|