@lanfermann/ui 0.4.0 → 0.6.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/action-bar/action-bar.d.ts +59 -0
- package/dist/components/action-bar/action-bar.js +116 -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 +46 -0
- package/dist/components/attachment/attachment.js +222 -0
- package/dist/components/attachment/kinds.d.ts +7 -0
- package/dist/components/attachment/kinds.js +100 -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/card/card.d.ts +11 -3
- package/dist/components/card/card.js +18 -4
- package/dist/components/checkbox-card/checkbox-card.d.ts +21 -0
- package/dist/components/checkbox-card/checkbox-card.js +49 -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-block-live.d.ts +13 -1
- package/dist/components/code-block/code-block-live.js +10 -4
- package/dist/components/code-block/code-block.d.ts +1 -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/code-block/code-lines-live.d.ts +7 -0
- package/dist/components/code-block/code-lines-live.js +167 -0
- package/dist/components/code-block/code-lines-view.d.ts +1 -0
- package/dist/components/code-block/code-lines-view.js +50 -18
- package/dist/components/code-block/code-lines.d.ts +3 -0
- package/dist/components/code-block/code-tabs.d.ts +1 -0
- package/dist/components/code-block/highlight.d.ts +1 -0
- package/dist/components/code-block/line-diff.js +135 -0
- package/dist/components/combobox/combobox.d.ts +50 -2
- package/dist/components/combobox/combobox.js +178 -9
- 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.js +7 -17
- 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 +31 -10
- 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/message/message.d.ts +73 -0
- package/dist/components/message/message.js +196 -0
- package/dist/components/otp-field/otp-field.d.ts +37 -0
- package/dist/components/otp-field/otp-field.js +126 -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 +48 -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/select/select.d.ts +1 -1
- package/dist/components/select/select.js +1 -1
- 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 +57 -0
- package/dist/components/stat/stat.js +110 -0
- package/dist/components/steps/steps.d.ts +57 -0
- package/dist/components/steps/steps.js +131 -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 +1 -1
- 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 +24 -0
- package/dist/components/toggle/toggle.js +53 -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 +45 -0
- package/dist/components/toolbar/toolbar.js +92 -0
- package/dist/components/trace/trace.d.ts +2 -1
- package/dist/components/trace/trace.js +14 -26
- 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 +65 -0
- package/dist/internal/clipboard.js +37 -0
- package/dist/internal/copy.js +58 -0
- package/dist/internal/field.js +24 -4
- package/dist/internal/glyphs.js +26 -1
- package/dist/internal/live-list.js +41 -0
- package/dist/internal/number-places.js +156 -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/status-icon.js +22 -0
- package/dist/internal/travelling-mark.js +204 -0
- package/dist/lib/cn.js +4 -0
- package/dist/lib/shortcut.d.ts +11 -0
- package/dist/lib/shortcut.js +165 -0
- package/package.json +1 -1
- 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/code.css +89 -1
- package/src/styles/consent.css +65 -0
- package/src/styles/copy.css +12 -11
- package/src/styles/depth.css +46 -2
- package/src/styles/marks.css +20 -2
- package/src/styles/rail.css +49 -0
- package/src/styles/rolling-number.css +94 -0
- 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 +9 -0
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Button } from "../button/button.js";
|
|
3
|
+
import { ButtonGroup } from "../button-group/button-group.js";
|
|
4
|
+
import { buttonGroupKeyDisabledLook, buttonGroupKeyVariants } from "../button-group/button-group-variants.js";
|
|
5
|
+
import { ChevronLeftGlyph, ChevronRightGlyph, GapGlyph } from "../../internal/glyphs.js";
|
|
6
|
+
import { useTravellingMark } from "../../internal/travelling-mark.js";
|
|
7
|
+
import { cn } from "../../lib/cn.js";
|
|
8
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
9
|
+
import { useRef } from "react";
|
|
10
|
+
// src/components/pagination/pagination.tsx
|
|
11
|
+
/** A gap between page numbers, where pages were left out. */
|
|
12
|
+
const GAP = "gap";
|
|
13
|
+
/**
|
|
14
|
+
* The page numbers to show: the first and the last, the current one with its neighbours, and a
|
|
15
|
+
* gap where pages are left out. The row always has the same number of places, whatever page is
|
|
16
|
+
* current, so it never changes its width while one pages through.
|
|
17
|
+
*/
|
|
18
|
+
function pageRange(page, pages, siblings = 1) {
|
|
19
|
+
const places = siblings * 2 + 5;
|
|
20
|
+
if (pages <= places) return Array.from({ length: pages }, (_, index) => index + 1);
|
|
21
|
+
const run = (from, to) => Array.from({ length: to - from + 1 }, (_, index) => from + index);
|
|
22
|
+
if (page <= siblings + 3) return [
|
|
23
|
+
...run(1, places - 2),
|
|
24
|
+
GAP,
|
|
25
|
+
pages
|
|
26
|
+
];
|
|
27
|
+
if (page >= pages - siblings - 2) return [
|
|
28
|
+
1,
|
|
29
|
+
GAP,
|
|
30
|
+
...run(pages - places + 3, pages)
|
|
31
|
+
];
|
|
32
|
+
return [
|
|
33
|
+
1,
|
|
34
|
+
GAP,
|
|
35
|
+
...run(page - siblings, page + siblings),
|
|
36
|
+
GAP,
|
|
37
|
+
pages
|
|
38
|
+
];
|
|
39
|
+
}
|
|
40
|
+
const focusRing = "focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-accent";
|
|
41
|
+
const place = "flex size-(--control-md) items-center justify-center rounded-md text-control tabular-nums select-none";
|
|
42
|
+
/**
|
|
43
|
+
* On a touch screen a place grows to 44px up and down, never sideways: its neighbours stand
|
|
44
|
+
* 2px beside it, and two places must not take each other's taps.
|
|
45
|
+
*/
|
|
46
|
+
const reach = "relative pointer-coarse:after:absolute pointer-coarse:after:inset-x-0 pointer-coarse:after:top-1/2 pointer-coarse:after:h-11 pointer-coarse:after:-translate-y-1/2 pointer-coarse:after:content-['']";
|
|
47
|
+
/** A pattern with its numbers put in: `{page}` and `{pages}`. */
|
|
48
|
+
function fill(pattern, page, pages) {
|
|
49
|
+
return pattern.replaceAll("{page}", String(page)).replaceAll("{pages}", String(pages));
|
|
50
|
+
}
|
|
51
|
+
/** An arrow leans a pixel the way it leads while the pointer is on it. */
|
|
52
|
+
const lean = "transition-[translate] spring-seat group-hover/arrow:spring-snap";
|
|
53
|
+
/**
|
|
54
|
+
* The pages of a long list. The page that shows stands on the tint, and the tint travels to
|
|
55
|
+
* the next number when the page changes. The row keeps its width from the first page to the
|
|
56
|
+
* last, so the arrows stay under the pointer while one pages through.
|
|
57
|
+
*
|
|
58
|
+
* Give it `href` wherever the page is part of the address, which is nearly always: the numbers
|
|
59
|
+
* are then links. Say beside it what the pages hold ("21 bis 40 von 248 Angeboten"); that
|
|
60
|
+
* line is yours to word.
|
|
61
|
+
*/
|
|
62
|
+
function Pagination({ page, pages, href, onPageChange, variant = "numbered", siblings = 1, "aria-label": label = "Seiten", pageLabel = "Seite {page}", positionLabel = "Seite {page} von {pages}", previousLabel = "Vorherige Seite", nextLabel = "Nächste Seite", className, ...props }) {
|
|
63
|
+
const list = useRef(null);
|
|
64
|
+
const mark = useRef(null);
|
|
65
|
+
useTravellingMark(list, mark, { enabled: variant === "numbered" });
|
|
66
|
+
const hrefOf = (to) => typeof href === "string" ? fill(href, to, pages) : href?.(to);
|
|
67
|
+
const nameOf = (to) => typeof pageLabel === "string" ? fill(pageLabel, to, pages) : pageLabel(to);
|
|
68
|
+
/**
|
|
69
|
+
* What an arrow or a number says and does. One that leads nowhere (back from the first page,
|
|
70
|
+
* on from the last) keeps its place, so nothing shifts, and stays in reach of the keyboard:
|
|
71
|
+
* whoever pages to the end with Enter still holds the focus there and hears that it ends.
|
|
72
|
+
*/
|
|
73
|
+
const leads = (to, name) => {
|
|
74
|
+
const off = to < 1 || to > pages;
|
|
75
|
+
return {
|
|
76
|
+
off,
|
|
77
|
+
"aria-label": name,
|
|
78
|
+
"aria-current": to === page ? "page" : void 0,
|
|
79
|
+
"aria-disabled": off || void 0,
|
|
80
|
+
onClick: (event) => {
|
|
81
|
+
if (off) event.preventDefault();
|
|
82
|
+
else onPageChange?.(to, event);
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
/** What makes it a link while it leads somewhere, and says it is one while it does not. */
|
|
87
|
+
const address = (to, off) => off ? {
|
|
88
|
+
role: "link",
|
|
89
|
+
tabIndex: 0
|
|
90
|
+
} : { href: hrefOf(to) };
|
|
91
|
+
if (variant === "compact") {
|
|
92
|
+
const step = (to, name, glyph) => {
|
|
93
|
+
const { off, ...says } = leads(to, name);
|
|
94
|
+
return href ? /* @__PURE__ */ jsx("a", {
|
|
95
|
+
...address(to, off),
|
|
96
|
+
...says,
|
|
97
|
+
"data-slot": "button",
|
|
98
|
+
"data-group-key": "",
|
|
99
|
+
"data-disabled": off ? "" : void 0,
|
|
100
|
+
className: cn(buttonGroupKeyVariants({
|
|
101
|
+
size: "sm",
|
|
102
|
+
iconOnly: true
|
|
103
|
+
}), buttonGroupKeyDisabledLook),
|
|
104
|
+
children: glyph
|
|
105
|
+
}) : /* @__PURE__ */ jsx(Button, {
|
|
106
|
+
iconOnly: true,
|
|
107
|
+
disabled: off,
|
|
108
|
+
focusableWhenDisabled: true,
|
|
109
|
+
...says,
|
|
110
|
+
"aria-label": name,
|
|
111
|
+
children: glyph
|
|
112
|
+
});
|
|
113
|
+
};
|
|
114
|
+
return /* @__PURE__ */ jsxs("nav", {
|
|
115
|
+
"data-slot": "pagination",
|
|
116
|
+
"data-variant": "compact",
|
|
117
|
+
"aria-label": label,
|
|
118
|
+
className: cn("flex items-center gap-3", className),
|
|
119
|
+
...props,
|
|
120
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
121
|
+
"data-slot": "pagination-position",
|
|
122
|
+
className: "text-sm text-fg-muted tabular-nums",
|
|
123
|
+
children: typeof positionLabel === "string" ? fill(positionLabel, page, pages) : positionLabel(page, pages)
|
|
124
|
+
}), /* @__PURE__ */ jsxs(ButtonGroup, {
|
|
125
|
+
size: "sm",
|
|
126
|
+
"aria-label": label,
|
|
127
|
+
children: [step(page - 1, previousLabel, /* @__PURE__ */ jsx(ChevronLeftGlyph, {})), step(page + 1, nextLabel, /* @__PURE__ */ jsx(ChevronRightGlyph, {}))]
|
|
128
|
+
})]
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
/** A link where the page has an address, a button where it has none. */
|
|
132
|
+
const go = (to, more) => {
|
|
133
|
+
const { off, ...says } = leads(to, more.label);
|
|
134
|
+
return href ? /* @__PURE__ */ jsx("a", {
|
|
135
|
+
...address(to, off),
|
|
136
|
+
...says,
|
|
137
|
+
className: more.className,
|
|
138
|
+
children: more.children
|
|
139
|
+
}) : /* @__PURE__ */ jsx("button", {
|
|
140
|
+
type: "button",
|
|
141
|
+
...says,
|
|
142
|
+
className: more.className,
|
|
143
|
+
children: more.children
|
|
144
|
+
});
|
|
145
|
+
};
|
|
146
|
+
const arrow = cn(place, reach, "group/arrow text-fg-muted hover:bg-hover hover:text-fg", "aria-disabled:pointer-events-none aria-disabled:text-on-disabled", focusRing);
|
|
147
|
+
return /* @__PURE__ */ jsx("nav", {
|
|
148
|
+
"data-slot": "pagination",
|
|
149
|
+
"data-variant": "numbered",
|
|
150
|
+
"aria-label": label,
|
|
151
|
+
className,
|
|
152
|
+
...props,
|
|
153
|
+
children: /* @__PURE__ */ jsxs("ul", {
|
|
154
|
+
ref: list,
|
|
155
|
+
"data-slot": "pagination-list",
|
|
156
|
+
className: "relative isolate flex items-center gap-0.5 [--pagination-current:var(--lf-tint)] data-placed:[--pagination-current:transparent]",
|
|
157
|
+
children: [
|
|
158
|
+
/* @__PURE__ */ jsx("li", { children: go(page - 1, {
|
|
159
|
+
label: previousLabel,
|
|
160
|
+
className: arrow,
|
|
161
|
+
children: /* @__PURE__ */ jsx(ChevronLeftGlyph, { className: cn(lean, "motion-safe:group-hover/arrow:-translate-x-px") })
|
|
162
|
+
}) }),
|
|
163
|
+
pageRange(page, pages, siblings).map((entry, index) => entry === GAP ? /* @__PURE__ */ jsx("li", {
|
|
164
|
+
"aria-hidden": true,
|
|
165
|
+
className: cn(place, "text-fg-muted"),
|
|
166
|
+
children: /* @__PURE__ */ jsx(GapGlyph, {})
|
|
167
|
+
}, `gap-${index}`) : /* @__PURE__ */ jsx("li", { children: go(entry, {
|
|
168
|
+
label: nameOf(entry),
|
|
169
|
+
className: cn(place, reach, "text-fg-body hover:text-fg not-aria-[current=page]:hover:bg-hover", "aria-[current=page]:bg-(--pagination-current) aria-[current=page]:font-medium aria-[current=page]:text-fg", "forced-colors:aria-[current=page]:outline forced-colors:aria-[current=page]:-outline-offset-1", focusRing),
|
|
170
|
+
children: entry
|
|
171
|
+
}) }, entry)),
|
|
172
|
+
/* @__PURE__ */ jsx("li", { children: go(page + 1, {
|
|
173
|
+
label: nextLabel,
|
|
174
|
+
className: arrow,
|
|
175
|
+
children: /* @__PURE__ */ jsx(ChevronRightGlyph, { className: cn(lean, "motion-safe:group-hover/arrow:translate-x-px") })
|
|
176
|
+
}) }),
|
|
177
|
+
/* @__PURE__ */ jsx("li", {
|
|
178
|
+
ref: mark,
|
|
179
|
+
"aria-hidden": true,
|
|
180
|
+
role: "presentation",
|
|
181
|
+
"data-slot": "pagination-mark",
|
|
182
|
+
className: "travels -z-10 rounded-md bg-tint"
|
|
183
|
+
})
|
|
184
|
+
]
|
|
185
|
+
})
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
export { Pagination, pageRange };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// src/components/prompt-input/keys.ts
|
|
2
|
+
/**
|
|
3
|
+
* A screen that is only touched: there Enter breaks the line and the key sends. An iPad with a
|
|
4
|
+
* keyboard and a trackpad also has a fine pointer, so Enter sends there as on a computer.
|
|
5
|
+
*/
|
|
6
|
+
const TOUCH_ONLY = "(pointer: coarse) and (not (any-pointer: fine))";
|
|
7
|
+
function promptKey(event, { touchOnly, running }) {
|
|
8
|
+
if (event.key !== "Enter") return "type";
|
|
9
|
+
if (event.isComposing || event.keyCode === 229) return "type";
|
|
10
|
+
if (event.shiftKey || event.altKey) return "type";
|
|
11
|
+
const modified = event.metaKey || event.ctrlKey;
|
|
12
|
+
if (touchOnly && !modified) return "type";
|
|
13
|
+
return running ? "hold" : "send";
|
|
14
|
+
}
|
|
15
|
+
export { TOUCH_ONLY, promptKey };
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { FileRejection } from "../file-upload/files.js";
|
|
2
|
+
import { ComponentProps, ReactElement } from "react";
|
|
3
|
+
export type PromptInputProps = Omit<ComponentProps<"form">, "onSubmit" | "defaultValue" | "onChange"> & {
|
|
4
|
+
/** The text (controlled). */
|
|
5
|
+
value?: string;
|
|
6
|
+
/** The text at first. */
|
|
7
|
+
defaultValue?: string;
|
|
8
|
+
onValueChange?: (value: string) => void;
|
|
9
|
+
/**
|
|
10
|
+
* Sends the prompt: called with the text, trimmed. The field is emptied at once; when the
|
|
11
|
+
* promise rejects, the text comes back if nothing new was typed.
|
|
12
|
+
*/
|
|
13
|
+
onSubmit?: (text: string) => void | Promise<void>;
|
|
14
|
+
/** An answer is being written: the send key is the stop key. The field stays open. */
|
|
15
|
+
running?: boolean;
|
|
16
|
+
/** Halts the answer being written. */
|
|
17
|
+
onStop?: () => void;
|
|
18
|
+
/** Files that were chosen, dropped or pasted and are of a kind and size it takes. */
|
|
19
|
+
onFilesAdded?: (files: File[]) => void;
|
|
20
|
+
/** Files it did not take, each with its reason. */
|
|
21
|
+
onReject?: (rejections: FileRejection[]) => void;
|
|
22
|
+
/** As on a file input: `.pdf,image/*`. */
|
|
23
|
+
accept?: string;
|
|
24
|
+
/** The largest size a file may have, in bytes. */
|
|
25
|
+
maxSize?: number;
|
|
26
|
+
disabled?: boolean;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* The field a prompt to an assistant is written in: one socket that holds the text, the files
|
|
30
|
+
* attached to it, the attach key and the send key, so the halo goes around all of it. Put a
|
|
31
|
+
* `PromptInputAttachments`, a `PromptInputTextarea` and `PromptInputActions` (with a
|
|
32
|
+
* `PromptInputAttach` and a `PromptInputSubmit`) inside.
|
|
33
|
+
*
|
|
34
|
+
* The text stands on top and the keys in a row of their own under it, the paper clip at the
|
|
35
|
+
* left and send at the right, where there is room for more keys (Justin, 2026-11-19).
|
|
36
|
+
*
|
|
37
|
+
* Enter sends and Shift+Enter breaks the line; on a screen that is only touched, Enter breaks
|
|
38
|
+
* the line and the key sends. A word being composed (Japanese, Chinese) is never sent. While
|
|
39
|
+
* an answer is written (`running`) the send key is the stop key, in the same place, and the
|
|
40
|
+
* field stays open, so the next prompt can be written; Enter waits.
|
|
41
|
+
*
|
|
42
|
+
* The field grows with its text up to about ten lines and then scrolls; its height follows on
|
|
43
|
+
* `settle`, and the line being typed is readable from its first frame. Files come by the attach
|
|
44
|
+
* key, by a drop on the field (it wears the halo while one hangs over it) and by paste. It
|
|
45
|
+
* sorts them by kind and size and hands them on; it does not upload.
|
|
46
|
+
*/
|
|
47
|
+
export declare function PromptInput({ value: valueProp, defaultValue, onValueChange, onSubmit, running, onStop, onFilesAdded, onReject, accept, maxSize, disabled, className, children, ...props }: PromptInputProps): import("react").JSX.Element;
|
|
48
|
+
export type PromptInputTextareaProps = Omit<ComponentProps<"textarea">, "value" | "defaultValue" | "id"> & {
|
|
49
|
+
/** The name of the field for assistive tech, where no label stands beside it. */
|
|
50
|
+
label?: string;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* The text of the prompt. It grows with what is written, measured from a copy of the text laid
|
|
54
|
+
* out beside it, so it grows the same in every browser, up to about ten lines; then it scrolls
|
|
55
|
+
* and fades at its top where more stands above.
|
|
56
|
+
*/
|
|
57
|
+
export declare function PromptInputTextarea({ label, className, onKeyDown, onPaste, placeholder, ...props }: PromptInputTextareaProps): import("react").JSX.Element;
|
|
58
|
+
/** The keys of the prompt: attach, send, and whatever else belongs there. */
|
|
59
|
+
export declare function PromptInputActions({ className, ...props }: ComponentProps<"div">): import("react").JSX.Element;
|
|
60
|
+
export type PromptInputAttachProps = Omit<ComponentProps<"button">, "children" | "onClick" | "type"> & {
|
|
61
|
+
label?: string;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* The paper clip: opens the file picker. What is chosen is sorted like a drop and handed to
|
|
65
|
+
* `onFilesAdded`; the same file can be chosen again.
|
|
66
|
+
*/
|
|
67
|
+
export declare function PromptInputAttach({ label, className }: PromptInputAttachProps): import("react").JSX.Element;
|
|
68
|
+
export type PromptInputSubmitProps = {
|
|
69
|
+
sendLabel?: string;
|
|
70
|
+
stopLabel?: string;
|
|
71
|
+
className?: string;
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* The send key, the committed key of the prompt. With nothing to send it lies flat and stands
|
|
75
|
+
* up with the first word. While an answer is written it is the stop key, in the same place and
|
|
76
|
+
* size: the arrow shrinks away and the square seats. Pressing it keeps the keyboard in the text.
|
|
77
|
+
*/
|
|
78
|
+
export declare function PromptInputSubmit({ sendLabel, stopLabel, className }: PromptInputSubmitProps): import("react").JSX.Element;
|
|
79
|
+
export type PromptInputAttachmentsProps = Omit<ComponentProps<"div">, "children"> & {
|
|
80
|
+
/** `Attachment`s, each with a `key`: they are chips here. */
|
|
81
|
+
children?: ReactElement | ReactElement[] | false | null;
|
|
82
|
+
label?: string;
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* The files attached to the prompt, as chips above the text. One that joins opens its place
|
|
86
|
+
* and seats; one taken away fades while its place closes. Backspace in the empty text takes the
|
|
87
|
+
* last one away. Empty, the row takes no room.
|
|
88
|
+
*/
|
|
89
|
+
export declare function PromptInputAttachments({ label, className, children, ...props }: PromptInputAttachmentsProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { AttachmentVariantContext } from "../attachment/attachment.js";
|
|
3
|
+
import { Button } from "../button/button.js";
|
|
4
|
+
import { ChipGroup } from "../chip/chip-group.js";
|
|
5
|
+
import { sortFiles } from "../file-upload/files.js";
|
|
6
|
+
import { Grow } from "../grow/grow.js";
|
|
7
|
+
import { Icon } from "../icon/icon.js";
|
|
8
|
+
import { useScrollEdges } from "../scroll-fade/use-scroll-edges.js";
|
|
9
|
+
import { Tooltip, TooltipContent, TooltipTrigger } from "../tooltip/tooltip.js";
|
|
10
|
+
import { fieldShellGrowing, focusFieldControl } from "../../internal/field.js";
|
|
11
|
+
import { StopGlyph } from "../../internal/glyphs.js";
|
|
12
|
+
import { cn } from "../../lib/cn.js";
|
|
13
|
+
import { TOUCH_ONLY, promptKey } from "./keys.js";
|
|
14
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
15
|
+
import { Children, createContext, isValidElement, useCallback, useContext, useId, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
16
|
+
import { ArrowUp02Icon, Attachment01Icon } from "@hugeicons/core-free-icons";
|
|
17
|
+
// src/components/prompt-input/prompt-input.tsx
|
|
18
|
+
const PromptContext = createContext(null);
|
|
19
|
+
function usePrompt(part) {
|
|
20
|
+
const context = useContext(PromptContext);
|
|
21
|
+
if (!context) throw new Error(`${part} belongs inside a PromptInput.`);
|
|
22
|
+
return context;
|
|
23
|
+
}
|
|
24
|
+
function subscribeTouch(notify) {
|
|
25
|
+
const query = window.matchMedia(TOUCH_ONLY);
|
|
26
|
+
query.addEventListener("change", notify);
|
|
27
|
+
return () => query.removeEventListener("change", notify);
|
|
28
|
+
}
|
|
29
|
+
/** Whether the screen is only touched (no mouse, no trackpad). False on the server. */
|
|
30
|
+
function useTouchOnly() {
|
|
31
|
+
return useSyncExternalStore(subscribeTouch, () => window.matchMedia(TOUCH_ONLY).matches, () => false);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The field a prompt to an assistant is written in: one socket that holds the text, the files
|
|
35
|
+
* attached to it, the attach key and the send key, so the halo goes around all of it. Put a
|
|
36
|
+
* `PromptInputAttachments`, a `PromptInputTextarea` and `PromptInputActions` (with a
|
|
37
|
+
* `PromptInputAttach` and a `PromptInputSubmit`) inside.
|
|
38
|
+
*
|
|
39
|
+
* The text stands on top and the keys in a row of their own under it, the paper clip at the
|
|
40
|
+
* left and send at the right, where there is room for more keys (Justin, 2026-11-19).
|
|
41
|
+
*
|
|
42
|
+
* Enter sends and Shift+Enter breaks the line; on a screen that is only touched, Enter breaks
|
|
43
|
+
* the line and the key sends. A word being composed (Japanese, Chinese) is never sent. While
|
|
44
|
+
* an answer is written (`running`) the send key is the stop key, in the same place, and the
|
|
45
|
+
* field stays open, so the next prompt can be written; Enter waits.
|
|
46
|
+
*
|
|
47
|
+
* The field grows with its text up to about ten lines and then scrolls; its height follows on
|
|
48
|
+
* `settle`, and the line being typed is readable from its first frame. Files come by the attach
|
|
49
|
+
* key, by a drop on the field (it wears the halo while one hangs over it) and by paste. It
|
|
50
|
+
* sorts them by kind and size and hands them on; it does not upload.
|
|
51
|
+
*/
|
|
52
|
+
function PromptInput({ value: valueProp, defaultValue = "", onValueChange, onSubmit, running = false, onStop, onFilesAdded, onReject, accept, maxSize, disabled = false, className, children, ...props }) {
|
|
53
|
+
const [own, setOwn] = useState(defaultValue);
|
|
54
|
+
const value = valueProp ?? own;
|
|
55
|
+
const setValue = (next) => {
|
|
56
|
+
setOwn(next);
|
|
57
|
+
onValueChange?.(next);
|
|
58
|
+
};
|
|
59
|
+
const [attachments, setAttachmentCount] = useState(0);
|
|
60
|
+
const removeLastRef = useRef(void 0);
|
|
61
|
+
const setAttachments = useCallback((count, removeLast) => {
|
|
62
|
+
setAttachmentCount(count);
|
|
63
|
+
removeLastRef.current = removeLast;
|
|
64
|
+
}, []);
|
|
65
|
+
const [dragging, setDragging] = useState(false);
|
|
66
|
+
const drags = useRef(0);
|
|
67
|
+
const touchOnly = useTouchOnly();
|
|
68
|
+
const textareaId = useId();
|
|
69
|
+
const canSend = !disabled && (value.trim() !== "" || attachments > 0);
|
|
70
|
+
const focusText = () => document.getElementById(textareaId)?.focus();
|
|
71
|
+
const send = () => {
|
|
72
|
+
if (running || !canSend) return;
|
|
73
|
+
const sent = value;
|
|
74
|
+
setValue("");
|
|
75
|
+
const result = onSubmit?.(sent.trim());
|
|
76
|
+
if (result instanceof Promise) result.catch(() => {
|
|
77
|
+
setOwn((now) => {
|
|
78
|
+
if (now !== "") return now;
|
|
79
|
+
onValueChange?.(sent);
|
|
80
|
+
return sent;
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
const addFiles = (files) => {
|
|
85
|
+
if (disabled || files.length === 0) return;
|
|
86
|
+
const { accepted, rejected } = sortFiles(files, {
|
|
87
|
+
accept,
|
|
88
|
+
maxSize,
|
|
89
|
+
multiple: true
|
|
90
|
+
});
|
|
91
|
+
if (accepted.length > 0) onFilesAdded?.(accepted);
|
|
92
|
+
if (rejected.length > 0) onReject?.(rejected);
|
|
93
|
+
};
|
|
94
|
+
const context = {
|
|
95
|
+
value,
|
|
96
|
+
setValue,
|
|
97
|
+
running,
|
|
98
|
+
disabled,
|
|
99
|
+
canSend,
|
|
100
|
+
touchOnly,
|
|
101
|
+
textareaId,
|
|
102
|
+
send,
|
|
103
|
+
stop: () => onStop?.(),
|
|
104
|
+
addFiles,
|
|
105
|
+
accept,
|
|
106
|
+
setAttachments,
|
|
107
|
+
removeLast: () => {
|
|
108
|
+
if (!removeLastRef.current) return false;
|
|
109
|
+
removeLastRef.current();
|
|
110
|
+
return true;
|
|
111
|
+
},
|
|
112
|
+
focusText
|
|
113
|
+
};
|
|
114
|
+
const hasFiles = (event) => event.dataTransfer.types.includes("Files");
|
|
115
|
+
return /* @__PURE__ */ jsx(PromptContext, {
|
|
116
|
+
value: context,
|
|
117
|
+
children: /* @__PURE__ */ jsx("form", {
|
|
118
|
+
"data-slot": "prompt-input",
|
|
119
|
+
"data-running": running ? "" : void 0,
|
|
120
|
+
"data-dragging": dragging ? "" : void 0,
|
|
121
|
+
className: cn("w-full min-w-0", className),
|
|
122
|
+
onSubmit: (event) => {
|
|
123
|
+
event.preventDefault();
|
|
124
|
+
send();
|
|
125
|
+
},
|
|
126
|
+
onDragEnter: (event) => {
|
|
127
|
+
if (!hasFiles(event) || disabled) return;
|
|
128
|
+
event.preventDefault();
|
|
129
|
+
drags.current += 1;
|
|
130
|
+
setDragging(true);
|
|
131
|
+
},
|
|
132
|
+
onDragOver: (event) => {
|
|
133
|
+
if (!hasFiles(event)) return;
|
|
134
|
+
event.preventDefault();
|
|
135
|
+
event.dataTransfer.dropEffect = disabled ? "none" : "copy";
|
|
136
|
+
},
|
|
137
|
+
onDragLeave: (event) => {
|
|
138
|
+
if (!hasFiles(event)) return;
|
|
139
|
+
drags.current = Math.max(0, drags.current - 1);
|
|
140
|
+
if (drags.current === 0) setDragging(false);
|
|
141
|
+
},
|
|
142
|
+
onDrop: (event) => {
|
|
143
|
+
if (!hasFiles(event)) return;
|
|
144
|
+
event.preventDefault();
|
|
145
|
+
drags.current = 0;
|
|
146
|
+
setDragging(false);
|
|
147
|
+
addFiles([...event.dataTransfer.files]);
|
|
148
|
+
focusText();
|
|
149
|
+
},
|
|
150
|
+
...props,
|
|
151
|
+
children: /* @__PURE__ */ jsx(Grow, {
|
|
152
|
+
"data-slot": "prompt-input-field",
|
|
153
|
+
className: cn(fieldShellGrowing, "flex flex-col justify-end rounded-xl [--field-pad:0.75rem] [--field-radius:var(--radius-xl)]", "in-data-dragging:depth-field-focus"),
|
|
154
|
+
contentClassName: "grid p-1",
|
|
155
|
+
onMouseDown: focusFieldControl,
|
|
156
|
+
children
|
|
157
|
+
})
|
|
158
|
+
})
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
/** The text and its look, the same for the field and for the copy it is measured by. */
|
|
162
|
+
const textLook = "col-start-1 row-start-1 min-w-0 px-2 py-2 text-control leading-6 break-words whitespace-pre-wrap pointer-coarse:text-base";
|
|
163
|
+
/**
|
|
164
|
+
* The text of the prompt. It grows with what is written, measured from a copy of the text laid
|
|
165
|
+
* out beside it, so it grows the same in every browser, up to about ten lines; then it scrolls
|
|
166
|
+
* and fades at its top where more stands above.
|
|
167
|
+
*/
|
|
168
|
+
function PromptInputTextarea({ label = "Nachricht an die KI", className, onKeyDown, onPaste, placeholder, ...props }) {
|
|
169
|
+
const prompt = usePrompt("PromptInputTextarea");
|
|
170
|
+
const area = useRef(null);
|
|
171
|
+
useScrollEdges(area, "y");
|
|
172
|
+
const keyDown = (event) => {
|
|
173
|
+
onKeyDown?.(event);
|
|
174
|
+
if (event.defaultPrevented) return;
|
|
175
|
+
if (event.key === "Backspace" && prompt.value === "" && !event.repeat) {
|
|
176
|
+
if (prompt.removeLast()) event.preventDefault();
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
const outcome = promptKey(event.nativeEvent, {
|
|
180
|
+
touchOnly: prompt.touchOnly,
|
|
181
|
+
running: prompt.running
|
|
182
|
+
});
|
|
183
|
+
if (outcome === "type") return;
|
|
184
|
+
event.preventDefault();
|
|
185
|
+
if (outcome === "send") prompt.send();
|
|
186
|
+
};
|
|
187
|
+
const paste = (event) => {
|
|
188
|
+
onPaste?.(event);
|
|
189
|
+
if (event.defaultPrevented) return;
|
|
190
|
+
const files = [...event.clipboardData.files];
|
|
191
|
+
if (files.length === 0) return;
|
|
192
|
+
event.preventDefault();
|
|
193
|
+
prompt.addFiles(files);
|
|
194
|
+
};
|
|
195
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
196
|
+
"data-slot": "prompt-input-text",
|
|
197
|
+
className: "grid min-w-0 [grid-area:text]",
|
|
198
|
+
children: [/* @__PURE__ */ jsx("textarea", {
|
|
199
|
+
ref: area,
|
|
200
|
+
id: prompt.textareaId,
|
|
201
|
+
"data-slot": "prompt-input-textarea",
|
|
202
|
+
"data-field-control": "",
|
|
203
|
+
"data-disabled": prompt.disabled ? "" : void 0,
|
|
204
|
+
"data-scroll-fade": "y",
|
|
205
|
+
"data-fade-edges": "start",
|
|
206
|
+
"aria-label": label,
|
|
207
|
+
rows: 1,
|
|
208
|
+
value: prompt.value,
|
|
209
|
+
disabled: prompt.disabled,
|
|
210
|
+
placeholder,
|
|
211
|
+
enterKeyHint: prompt.touchOnly ? "enter" : "send",
|
|
212
|
+
onChange: (event) => prompt.setValue(event.target.value),
|
|
213
|
+
onKeyDown: keyDown,
|
|
214
|
+
onPaste: paste,
|
|
215
|
+
className: cn(textLook, "h-full resize-none overflow-y-auto bg-transparent text-fg", "placeholder:text-fg-muted placeholder:italic focus:outline-hidden", "data-disabled:text-on-disabled", className),
|
|
216
|
+
...props
|
|
217
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
218
|
+
"aria-hidden": true,
|
|
219
|
+
"data-slot": "prompt-input-measure",
|
|
220
|
+
className: cn(textLook, "invisible max-h-60 overflow-hidden text-fg"),
|
|
221
|
+
children: [prompt.value || placeholder || " ", ""]
|
|
222
|
+
})]
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
/** The keys of the prompt: attach, send, and whatever else belongs there. */
|
|
226
|
+
function PromptInputActions({ className, ...props }) {
|
|
227
|
+
return /* @__PURE__ */ jsx("div", {
|
|
228
|
+
"data-slot": "prompt-input-actions",
|
|
229
|
+
className: cn(className),
|
|
230
|
+
...props
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
/** A quiet key inside the field, cut concentric to its corner. */
|
|
234
|
+
const innerKey = "rounded-[calc(var(--field-radius)-4px)]";
|
|
235
|
+
/**
|
|
236
|
+
* The paper clip: opens the file picker. What is chosen is sorted like a drop and handed to
|
|
237
|
+
* `onFilesAdded`; the same file can be chosen again.
|
|
238
|
+
*/
|
|
239
|
+
function PromptInputAttach({ label = "Datei anhängen", className }) {
|
|
240
|
+
const prompt = usePrompt("PromptInputAttach");
|
|
241
|
+
const input = useRef(null);
|
|
242
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs(Tooltip, { children: [/* @__PURE__ */ jsx(TooltipTrigger, { render: /* @__PURE__ */ jsx(Button, {
|
|
243
|
+
iconOnly: true,
|
|
244
|
+
variant: "quiet",
|
|
245
|
+
"aria-label": label,
|
|
246
|
+
"data-slot": "prompt-input-attach",
|
|
247
|
+
disabled: prompt.disabled,
|
|
248
|
+
onClick: () => input.current?.click(),
|
|
249
|
+
className: cn(innerKey, "text-fg-muted hover:text-fg", className),
|
|
250
|
+
children: /* @__PURE__ */ jsx(Icon, {
|
|
251
|
+
icon: Attachment01Icon,
|
|
252
|
+
size: 16
|
|
253
|
+
})
|
|
254
|
+
}) }), /* @__PURE__ */ jsx(TooltipContent, { children: label })] }), /* @__PURE__ */ jsx("input", {
|
|
255
|
+
ref: input,
|
|
256
|
+
type: "file",
|
|
257
|
+
multiple: true,
|
|
258
|
+
hidden: true,
|
|
259
|
+
tabIndex: -1,
|
|
260
|
+
accept: prompt.accept,
|
|
261
|
+
"data-slot": "prompt-input-file",
|
|
262
|
+
onChange: (event) => {
|
|
263
|
+
prompt.addFiles([...event.target.files ?? []]);
|
|
264
|
+
event.target.value = "";
|
|
265
|
+
prompt.focusText();
|
|
266
|
+
}
|
|
267
|
+
})] });
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* The send key, the committed key of the prompt. With nothing to send it lies flat and stands
|
|
271
|
+
* up with the first word. While an answer is written it is the stop key, in the same place and
|
|
272
|
+
* size: the arrow shrinks away and the square seats. Pressing it keeps the keyboard in the text.
|
|
273
|
+
*/
|
|
274
|
+
function PromptInputSubmit({ sendLabel = "Senden", stopLabel = "Anhalten", className }) {
|
|
275
|
+
const prompt = usePrompt("PromptInputSubmit");
|
|
276
|
+
const label = prompt.running ? stopLabel : sendLabel;
|
|
277
|
+
return /* @__PURE__ */ jsxs(Tooltip, { children: [/* @__PURE__ */ jsx(TooltipTrigger, { render: /* @__PURE__ */ jsx(Button, {
|
|
278
|
+
iconOnly: true,
|
|
279
|
+
variant: "primary",
|
|
280
|
+
"aria-label": label,
|
|
281
|
+
"data-slot": "prompt-input-submit",
|
|
282
|
+
type: prompt.running ? "button" : "submit",
|
|
283
|
+
disabled: !prompt.running && !prompt.canSend,
|
|
284
|
+
focusableWhenDisabled: true,
|
|
285
|
+
onClick: prompt.running ? prompt.stop : void 0,
|
|
286
|
+
onMouseDown: (event) => {
|
|
287
|
+
if (document.activeElement?.id === prompt.textareaId) event.preventDefault();
|
|
288
|
+
},
|
|
289
|
+
className: cn(innerKey, className),
|
|
290
|
+
children: /* @__PURE__ */ jsxs("span", {
|
|
291
|
+
className: "grid place-items-center *:col-start-1 *:row-start-1",
|
|
292
|
+
children: [/* @__PURE__ */ jsx(Icon, {
|
|
293
|
+
icon: ArrowUp02Icon,
|
|
294
|
+
size: 16,
|
|
295
|
+
"data-slot": "prompt-input-send-symbol"
|
|
296
|
+
}), /* @__PURE__ */ jsx(StopGlyph, {
|
|
297
|
+
width: 12,
|
|
298
|
+
height: 12,
|
|
299
|
+
"data-slot": "prompt-input-stop-symbol"
|
|
300
|
+
})]
|
|
301
|
+
})
|
|
302
|
+
}) }), /* @__PURE__ */ jsx(TooltipContent, { children: label })] });
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* The files attached to the prompt, as chips above the text. One that joins opens its place
|
|
306
|
+
* and seats; one taken away fades while its place closes. Backspace in the empty text takes the
|
|
307
|
+
* last one away. Empty, the row takes no room.
|
|
308
|
+
*/
|
|
309
|
+
function PromptInputAttachments({ label = "Anhänge", className, children, ...props }) {
|
|
310
|
+
const prompt = usePrompt("PromptInputAttachments");
|
|
311
|
+
const items = useMemo(() => Children.toArray(children).filter(isValidElement), [children]);
|
|
312
|
+
const last = items.at(-1)?.props.onRemove;
|
|
313
|
+
const { setAttachments } = prompt;
|
|
314
|
+
useLayoutEffect(() => setAttachments(items.length, last), [
|
|
315
|
+
setAttachments,
|
|
316
|
+
items.length,
|
|
317
|
+
last
|
|
318
|
+
]);
|
|
319
|
+
useLayoutEffect(() => () => setAttachments(0, void 0), [setAttachments]);
|
|
320
|
+
return /* @__PURE__ */ jsx(AttachmentVariantContext, {
|
|
321
|
+
value: "chip",
|
|
322
|
+
children: /* @__PURE__ */ jsx(ChipGroup, {
|
|
323
|
+
"aria-label": label,
|
|
324
|
+
"data-slot": "prompt-input-attachments",
|
|
325
|
+
className: cn("px-1 pt-1 pb-0.5 empty:hidden", className),
|
|
326
|
+
...props,
|
|
327
|
+
children: items
|
|
328
|
+
})
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
export { PromptInput, PromptInputActions, PromptInputAttach, PromptInputAttachments, PromptInputSubmit, PromptInputTextarea };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ChoiceCardText } from "../../internal/choice-card.js";
|
|
2
|
+
import { Radio } from "@base-ui/react/radio";
|
|
3
|
+
export type RadioCardProps = Omit<Radio.Root.Props, "children" | "className" | "render" | "title"> & ChoiceCardText & {
|
|
4
|
+
/**
|
|
5
|
+
* How the chosen card shows it. `edge` (the default): the accent as its edge, and the mark
|
|
6
|
+
* closed to a disc. `mark`: the mark alone, for a place where coloured edges would be too
|
|
7
|
+
* much.
|
|
8
|
+
*/
|
|
9
|
+
chosen?: "edge" | "mark";
|
|
10
|
+
className?: string;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* One choice out of a few whose options need a sentence each: a plan, an answer in a set-up.
|
|
14
|
+
* The whole card is the control and the target. It is a softly raised sheet that stands still:
|
|
15
|
+
* a press anywhere on it dips its radio. Chosen, it takes the accent as its edge and the disc
|
|
16
|
+
* seats into its radio's socket, as in a plain `Radio`.
|
|
17
|
+
*
|
|
18
|
+
* Put the cards into a `RadioGroup` and lay them out with a class on it (`grid sm:grid-cols-3`
|
|
19
|
+
* with `gap-3`). The title names the choice, the sentence says what it means; keep both the
|
|
20
|
+
* same length from card to card. For options that are a word each, plain `Radio`s in rows are
|
|
21
|
+
* calmer.
|
|
22
|
+
*/
|
|
23
|
+
export declare function RadioCard({ title, description, detail, icon, chosen, className, children, ...props }: RadioCardProps): import("react").JSX.Element;
|