@bettercms-ai/kit 3.0.0 → 3.0.2
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/brand/logo.js +67 -18
- package/dist/brand/logo.js.map +1 -1
- package/dist/context.js +8 -3
- package/dist/context.js.map +1 -1
- package/dist/controls/button.js +451 -134
- package/dist/controls/button.js.map +1 -1
- package/dist/controls/choice.js +336 -95
- package/dist/controls/choice.js.map +1 -1
- package/dist/controls/code.js +245 -72
- package/dist/controls/code.js.map +1 -1
- package/dist/controls/color.js +108 -31
- package/dist/controls/color.js.map +1 -1
- package/dist/controls/date.js +268 -83
- package/dist/controls/date.js.map +1 -1
- package/dist/controls/form-picker.js +26 -9
- package/dist/controls/form-picker.js.map +1 -1
- package/dist/controls/icon.js +341 -100
- package/dist/controls/icon.js.map +1 -1
- package/dist/controls/json.js +20 -7
- package/dist/controls/json.js.map +1 -1
- package/dist/controls/link.js +561 -156
- package/dist/controls/link.js.map +1 -1
- package/dist/controls/location.js +124 -35
- package/dist/controls/location.js.map +1 -1
- package/dist/controls/media.js +928 -267
- package/dist/controls/media.js.map +1 -1
- package/dist/controls/number.js +80 -23
- package/dist/controls/number.js.map +1 -1
- package/dist/controls/reference.js +516 -155
- package/dist/controls/reference.js.map +1 -1
- package/dist/controls/rich-text/article-shell.js +327 -86
- package/dist/controls/rich-text/article-shell.js.map +1 -1
- package/dist/controls/rich-text/author.js +78 -21
- package/dist/controls/rich-text/author.js.map +1 -1
- package/dist/controls/rich-text/blocks.js +1084 -315
- package/dist/controls/rich-text/blocks.js.map +1 -1
- package/dist/controls/rich-text/button.js +30 -9
- package/dist/controls/rich-text/button.js.map +1 -1
- package/dist/controls/rich-text/catalog.js +168 -51
- package/dist/controls/rich-text/catalog.js.map +1 -1
- package/dist/controls/rich-text/columns.js +104 -31
- package/dist/controls/rich-text/columns.js.map +1 -1
- package/dist/controls/rich-text/component-card.js +790 -209
- package/dist/controls/rich-text/component-card.js.map +1 -1
- package/dist/controls/rich-text/component-panel.js +102 -40
- package/dist/controls/rich-text/component-panel.js.map +1 -1
- package/dist/controls/rich-text/control.js +101 -32
- package/dist/controls/rich-text/control.js.map +1 -1
- package/dist/controls/rich-text/editor.js +423 -121
- package/dist/controls/rich-text/editor.js.map +1 -1
- package/dist/controls/rich-text/embed.js +184 -51
- package/dist/controls/rich-text/embed.js.map +1 -1
- package/dist/controls/rich-text/floating.js +171 -42
- package/dist/controls/rich-text/floating.js.map +1 -1
- package/dist/controls/rich-text/footnote.js +89 -28
- package/dist/controls/rich-text/footnote.js.map +1 -1
- package/dist/controls/rich-text/gallery.js +88 -27
- package/dist/controls/rich-text/gallery.js.map +1 -1
- package/dist/controls/rich-text/link-form.js +111 -34
- package/dist/controls/rich-text/link-form.js.map +1 -1
- package/dist/controls/rich-text/plain.js +8 -3
- package/dist/controls/rich-text/plain.js.map +1 -1
- package/dist/controls/rich-text/related.js +86 -25
- package/dist/controls/rich-text/related.js.map +1 -1
- package/dist/controls/rich-text/toc.js +48 -15
- package/dist/controls/rich-text/toc.js.map +1 -1
- package/dist/controls/rich-text/toolbar.js +408 -107
- package/dist/controls/rich-text/toolbar.js.map +1 -1
- package/dist/controls/scale.js +169 -52
- package/dist/controls/scale.js.map +1 -1
- package/dist/controls/slot.js +238 -73
- package/dist/controls/slot.js.map +1 -1
- package/dist/controls/table/table-editor.js +1766 -500
- package/dist/controls/table/table-editor.js.map +1 -1
- package/dist/controls/table/table-link.js +119 -38
- package/dist/controls/table/table-link.js.map +1 -1
- package/dist/controls/table/table.js +26 -9
- package/dist/controls/table/table.js.map +1 -1
- package/dist/controls/text.js +221 -68
- package/dist/controls/text.js.map +1 -1
- package/dist/controls/unknown-value.js +79 -22
- package/dist/controls/unknown-value.js.map +1 -1
- package/dist/engine/array.js +875 -233
- package/dist/engine/array.js.map +1 -1
- package/dist/engine/bits.js +38 -13
- package/dist/engine/bits.js.map +1 -1
- package/dist/engine/breadcrumb.js +25 -8
- package/dist/engine/breadcrumb.js.map +1 -1
- package/dist/engine/expand.js +38 -13
- package/dist/engine/expand.js.map +1 -1
- package/dist/engine/field-list.js +14 -5
- package/dist/engine/field-list.js.map +1 -1
- package/dist/engine/field-shell.js +849 -244
- package/dist/engine/field-shell.js.map +1 -1
- package/dist/engine/frame.js +275 -78
- package/dist/engine/frame.js.map +1 -1
- package/dist/engine/grouping.js +630 -193
- package/dist/engine/grouping.js.map +1 -1
- package/dist/engine/item-list.js +187 -50
- package/dist/engine/item-list.js.map +1 -1
- package/dist/engine/kit-field.js +320 -95
- package/dist/engine/kit-field.js.map +1 -1
- package/dist/engine/schema-form.js +101 -32
- package/dist/engine/schema-form.js.map +1 -1
- package/dist/engine/slot.js +146 -45
- package/dist/engine/slot.js.map +1 -1
- package/dist/index.js +2 -2
- package/dist/lib/icons.js +14 -5
- package/dist/lib/icons.js.map +1 -1
- package/dist/styles.css +5821 -1
- package/dist/table/table-view.js +49 -16
- package/dist/table/table-view.js.map +1 -1
- package/dist/testing/test-form.js +14 -5
- package/dist/testing/test-form.js.map +1 -1
- package/dist/theme.js +8 -3
- package/dist/theme.js.map +1 -1
- package/dist/ui/action-tray.js +97 -24
- package/dist/ui/action-tray.js.map +1 -1
- package/dist/ui/autocomplete.js +135 -38
- package/dist/ui/autocomplete.js.map +1 -1
- package/dist/ui/button.js +108 -31
- package/dist/ui/button.js.map +1 -1
- package/dist/ui/choice-switch.js +14 -5
- package/dist/ui/choice-switch.js.map +1 -1
- package/dist/ui/controls.js +279 -86
- package/dist/ui/controls.js.map +1 -1
- package/dist/ui/display.js +401 -116
- package/dist/ui/display.js.map +1 -1
- package/dist/ui/expanded-editor-modal.js +100 -27
- package/dist/ui/expanded-editor-modal.js.map +1 -1
- package/dist/ui/floating-panel.js +130 -37
- package/dist/ui/floating-panel.js.map +1 -1
- package/dist/ui/index.js +2 -2
- package/dist/ui/input.js +196 -59
- package/dist/ui/input.js.map +1 -1
- package/dist/ui/mode-bar.js +32 -11
- package/dist/ui/mode-bar.js.map +1 -1
- package/dist/ui/overlay.js +616 -179
- package/dist/ui/overlay.js.map +1 -1
- package/dist/ui/path-crumbs.js +374 -113
- package/dist/ui/path-crumbs.js.map +1 -1
- package/dist/ui/select.js +311 -78
- package/dist/ui/select.js.map +1 -1
- package/dist/ui/shortcut-hint.d.ts +3 -0
- package/dist/ui/shortcut-hint.js +33 -7
- package/dist/ui/shortcut-hint.js.map +1 -1
- package/dist/ui/spinner.js +20 -7
- package/dist/ui/spinner.js.map +1 -1
- package/dist/ui/split-button.js +35 -10
- package/dist/ui/split-button.js.map +1 -1
- package/dist/ui/tab.js +50 -17
- package/dist/ui/tab.js.map +1 -1
- package/dist/ui/toast.js +107 -30
- package/dist/ui/toast.js.map +1 -1
- package/dist/ui/tooltip-root.js +24 -7
- package/dist/ui/tooltip-root.js.map +1 -1
- package/package.json +2 -2
package/dist/ui/autocomplete.js
CHANGED
|
@@ -5,10 +5,11 @@ import { KIT_SCOPE } from "./surfaces.js";
|
|
|
5
5
|
import { IconButton } from "./button.js";
|
|
6
6
|
import { Highlight, filterOptions, nodeText } from "./select.js";
|
|
7
7
|
import * as React from "react";
|
|
8
|
-
import { Fragment,
|
|
8
|
+
import { Fragment, jsxDEV } from "react/jsx-dev-runtime";
|
|
9
9
|
import { IconX } from "@tabler/icons-react";
|
|
10
10
|
import { Autocomplete as Autocomplete$1 } from "@base-ui/react/autocomplete";
|
|
11
11
|
//#region src/ui/autocomplete.tsx
|
|
12
|
+
var _jsxFileName = "D:/Github/bettercms/bettercms-backend/packages/kit/src/ui/autocomplete.tsx";
|
|
12
13
|
var H = {
|
|
13
14
|
sm: "h-7",
|
|
14
15
|
md: "h-8",
|
|
@@ -47,56 +48,108 @@ function Autocomplete({ id, "aria-label": ariaLabel, "aria-describedby": ariaDes
|
|
|
47
48
|
setOpen(false);
|
|
48
49
|
};
|
|
49
50
|
const named = id ?? fieldId ?? ariaLabel;
|
|
50
|
-
const rows = /* @__PURE__ */
|
|
51
|
-
/* @__PURE__ */
|
|
51
|
+
const rows = /* @__PURE__ */ jsxDEV(Fragment, { children: [
|
|
52
|
+
/* @__PURE__ */ jsxDEV(Autocomplete$1.List, {
|
|
52
53
|
"aria-label": listLabel,
|
|
53
54
|
className: "max-h-72 overflow-y-auto overscroll-contain empty:hidden",
|
|
54
|
-
children: shown.map((o, i) => /* @__PURE__ */
|
|
55
|
+
children: shown.map((o, i) => /* @__PURE__ */ jsxDEV(React.Fragment, { children: [o.group && (i === 0 || shown[i - 1].group !== o.group) ? /* @__PURE__ */ jsxDEV("div", {
|
|
55
56
|
role: "presentation",
|
|
56
57
|
className: "px-2 pb-1 pt-2 text-kit-xs font-medium text-kit-fg-3 first:pt-1",
|
|
57
58
|
children: o.group
|
|
58
|
-
}
|
|
59
|
+
}, void 0, false, {
|
|
60
|
+
fileName: _jsxFileName,
|
|
61
|
+
lineNumber: 154,
|
|
62
|
+
columnNumber: 15
|
|
63
|
+
}, this) : null, /* @__PURE__ */ jsxDEV(Autocomplete$1.Item, {
|
|
59
64
|
value: o,
|
|
60
65
|
disabled: o.disabled,
|
|
61
66
|
onClick: () => onSelect?.(o),
|
|
62
67
|
"data-first-active": firstStandsIn && i === 0 ? "" : void 0,
|
|
63
68
|
className: "flex h-8 cursor-pointer select-none items-center gap-2 rounded-kit-md px-2 text-kit-sm outline-none data-[disabled]:pointer-events-none data-[disabled]:opacity-40 data-[highlighted]:bg-kit-hover data-[first-active]:bg-kit-hover",
|
|
64
69
|
children: [
|
|
65
|
-
o.icon ? /* @__PURE__ */
|
|
70
|
+
o.icon ? /* @__PURE__ */ jsxDEV("span", {
|
|
66
71
|
"aria-hidden": true,
|
|
67
72
|
className: "flex shrink-0 text-kit-fg-3 [&_svg]:size-4",
|
|
68
73
|
children: o.icon
|
|
69
|
-
}
|
|
70
|
-
|
|
74
|
+
}, void 0, false, {
|
|
75
|
+
fileName: _jsxFileName,
|
|
76
|
+
lineNumber: 166,
|
|
77
|
+
columnNumber: 17
|
|
78
|
+
}, this) : null,
|
|
79
|
+
/* @__PURE__ */ jsxDEV("span", {
|
|
71
80
|
className: "min-w-0 shrink truncate text-kit-fg",
|
|
72
|
-
children: highlightMatches && typeof o.label === "string" ? /* @__PURE__ */
|
|
81
|
+
children: highlightMatches && typeof o.label === "string" ? /* @__PURE__ */ jsxDEV(Highlight, {
|
|
73
82
|
text: o.label,
|
|
74
83
|
query: text
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
|
|
84
|
+
}, void 0, false, {
|
|
85
|
+
fileName: _jsxFileName,
|
|
86
|
+
lineNumber: 171,
|
|
87
|
+
columnNumber: 68
|
|
88
|
+
}, this) : o.label
|
|
89
|
+
}, void 0, false, {
|
|
90
|
+
fileName: _jsxFileName,
|
|
91
|
+
lineNumber: 170,
|
|
92
|
+
columnNumber: 15
|
|
93
|
+
}, this),
|
|
94
|
+
o.description ? /* @__PURE__ */ jsxDEV("span", {
|
|
78
95
|
className: "min-w-0 flex-1 truncate text-kit-xs text-kit-fg-3",
|
|
79
96
|
children: o.description
|
|
80
|
-
}
|
|
81
|
-
|
|
97
|
+
}, void 0, false, {
|
|
98
|
+
fileName: _jsxFileName,
|
|
99
|
+
lineNumber: 173,
|
|
100
|
+
columnNumber: 32
|
|
101
|
+
}, this) : /* @__PURE__ */ jsxDEV("span", { className: "flex-1" }, void 0, false, {
|
|
102
|
+
fileName: _jsxFileName,
|
|
103
|
+
lineNumber: 173,
|
|
104
|
+
columnNumber: 125
|
|
105
|
+
}, this),
|
|
106
|
+
o.meta ? /* @__PURE__ */ jsxDEV("span", {
|
|
82
107
|
className: "shrink-0 text-kit-2xs text-kit-fg-3",
|
|
83
108
|
children: o.meta
|
|
84
|
-
}
|
|
109
|
+
}, void 0, false, {
|
|
110
|
+
fileName: _jsxFileName,
|
|
111
|
+
lineNumber: 174,
|
|
112
|
+
columnNumber: 25
|
|
113
|
+
}, this) : null
|
|
85
114
|
]
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
|
|
115
|
+
}, void 0, true, {
|
|
116
|
+
fileName: _jsxFileName,
|
|
117
|
+
lineNumber: 158,
|
|
118
|
+
columnNumber: 13
|
|
119
|
+
}, this)] }, o.value, true, {
|
|
120
|
+
fileName: _jsxFileName,
|
|
121
|
+
lineNumber: 152,
|
|
122
|
+
columnNumber: 11
|
|
123
|
+
}, this))
|
|
124
|
+
}, void 0, false, {
|
|
125
|
+
fileName: _jsxFileName,
|
|
126
|
+
lineNumber: 150,
|
|
127
|
+
columnNumber: 7
|
|
128
|
+
}, this),
|
|
129
|
+
shown.length === 0 && hasEmptyNote ? /* @__PURE__ */ jsxDEV("p", {
|
|
89
130
|
role: "status",
|
|
90
131
|
className: NOTE,
|
|
91
132
|
children: emptyNote
|
|
92
|
-
}
|
|
93
|
-
|
|
133
|
+
}, void 0, false, {
|
|
134
|
+
fileName: _jsxFileName,
|
|
135
|
+
lineNumber: 180,
|
|
136
|
+
columnNumber: 9
|
|
137
|
+
}, this) : null,
|
|
138
|
+
shown.length > 0 && listNote != null && listNote !== false ? /* @__PURE__ */ jsxDEV("p", {
|
|
94
139
|
role: "status",
|
|
95
140
|
className: NOTE,
|
|
96
141
|
children: listNote
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
|
|
142
|
+
}, void 0, false, {
|
|
143
|
+
fileName: _jsxFileName,
|
|
144
|
+
lineNumber: 185,
|
|
145
|
+
columnNumber: 9
|
|
146
|
+
}, this) : null
|
|
147
|
+
] }, void 0, true, {
|
|
148
|
+
fileName: _jsxFileName,
|
|
149
|
+
lineNumber: 149,
|
|
150
|
+
columnNumber: 5
|
|
151
|
+
}, this);
|
|
152
|
+
return /* @__PURE__ */ jsxDEV(Autocomplete$1.Root, {
|
|
100
153
|
items: shown,
|
|
101
154
|
filter: null,
|
|
102
155
|
mode: "list",
|
|
@@ -114,16 +167,20 @@ function Autocomplete({ id, "aria-label": ariaLabel, "aria-describedby": ariaDes
|
|
|
114
167
|
openOnInputClick: true,
|
|
115
168
|
loopFocus: true,
|
|
116
169
|
disabled,
|
|
117
|
-
children: [/* @__PURE__ */
|
|
170
|
+
children: [/* @__PURE__ */ jsxDEV("div", {
|
|
118
171
|
className: cn("flex min-w-0 items-center rounded-kit-md border border-kit-field-border bg-kit-field-bg shadow-kit-field transition-[border-color,box-shadow] duration-150 hover:border-kit-field-border-hover focus-within:border-kit-field-border-focus focus-within:shadow-kit-ring-field", invalid && "border-[var(--kit-field-invalid)] hover:border-[var(--kit-field-invalid)]", disabled && "cursor-not-allowed bg-kit-subtle opacity-60", H[size], className),
|
|
119
172
|
children: [
|
|
120
173
|
leadingSlot,
|
|
121
|
-
leading ? /* @__PURE__ */
|
|
174
|
+
leading ? /* @__PURE__ */ jsxDEV("span", {
|
|
122
175
|
"aria-hidden": true,
|
|
123
176
|
className: "ml-2.5 flex shrink-0 text-kit-fg-3 [&_svg]:size-4",
|
|
124
177
|
children: leading
|
|
125
|
-
}
|
|
126
|
-
|
|
178
|
+
}, void 0, false, {
|
|
179
|
+
fileName: _jsxFileName,
|
|
180
|
+
lineNumber: 225,
|
|
181
|
+
columnNumber: 11
|
|
182
|
+
}, this) : null,
|
|
183
|
+
/* @__PURE__ */ jsxDEV(Autocomplete$1.Input, {
|
|
127
184
|
ref: inputRef,
|
|
128
185
|
id: id ?? fieldId,
|
|
129
186
|
"aria-label": ariaLabel,
|
|
@@ -150,29 +207,53 @@ function Autocomplete({ id, "aria-label": ariaLabel, "aria-describedby": ariaDes
|
|
|
150
207
|
} else if (!highlighted || !visible) onEnter?.(text);
|
|
151
208
|
},
|
|
152
209
|
className: "h-full min-w-0 flex-1 bg-transparent px-2 text-kit-sm text-kit-fg outline-none placeholder:text-kit-fg-3 disabled:cursor-not-allowed"
|
|
153
|
-
}
|
|
154
|
-
|
|
210
|
+
}, void 0, false, {
|
|
211
|
+
fileName: _jsxFileName,
|
|
212
|
+
lineNumber: 229,
|
|
213
|
+
columnNumber: 9
|
|
214
|
+
}, this),
|
|
215
|
+
loading ? /* @__PURE__ */ jsxDEV(Spinner, {
|
|
155
216
|
size: "sm",
|
|
156
217
|
tone: "muted",
|
|
157
218
|
label: "Loading suggestions",
|
|
158
219
|
className: "mr-2"
|
|
159
|
-
}
|
|
220
|
+
}, void 0, false, {
|
|
221
|
+
fileName: _jsxFileName,
|
|
222
|
+
lineNumber: 259,
|
|
223
|
+
columnNumber: 11
|
|
224
|
+
}, this) : text && !disabled ? /* @__PURE__ */ jsxDEV(IconButton, {
|
|
160
225
|
label: "Clear",
|
|
161
226
|
size: "xs",
|
|
162
227
|
variant: "ghost",
|
|
163
228
|
className: "mr-1",
|
|
164
229
|
onMouseDown: (e) => e.preventDefault(),
|
|
165
230
|
onClick: () => onClear ? onClear() : setText(""),
|
|
166
|
-
children: /* @__PURE__ */
|
|
167
|
-
|
|
231
|
+
children: /* @__PURE__ */ jsxDEV(IconX, { stroke: 1.5 }, void 0, false, {
|
|
232
|
+
fileName: _jsxFileName,
|
|
233
|
+
lineNumber: 262,
|
|
234
|
+
columnNumber: 13
|
|
235
|
+
}, this)
|
|
236
|
+
}, void 0, false, {
|
|
237
|
+
fileName: _jsxFileName,
|
|
238
|
+
lineNumber: 261,
|
|
239
|
+
columnNumber: 11
|
|
240
|
+
}, this) : null,
|
|
168
241
|
trailingSlot
|
|
169
242
|
]
|
|
170
|
-
}
|
|
243
|
+
}, void 0, true, {
|
|
244
|
+
fileName: _jsxFileName,
|
|
245
|
+
lineNumber: 214,
|
|
246
|
+
columnNumber: 7
|
|
247
|
+
}, this), inlineList ? visible ? /* @__PURE__ */ jsxDEV("div", {
|
|
171
248
|
...listAttrs,
|
|
172
249
|
className: cn("mt-1 rounded-kit-md border border-kit-line bg-kit-surface p-1", menuClassName),
|
|
173
250
|
onMouseDown: (e) => e.preventDefault(),
|
|
174
251
|
children: rows
|
|
175
|
-
}
|
|
252
|
+
}, void 0, false, {
|
|
253
|
+
fileName: _jsxFileName,
|
|
254
|
+
lineNumber: 270,
|
|
255
|
+
columnNumber: 11
|
|
256
|
+
}, this) : null : /* @__PURE__ */ jsxDEV(Autocomplete$1.Portal, { children: /* @__PURE__ */ jsxDEV(Autocomplete$1.Positioner, {
|
|
176
257
|
align: "start",
|
|
177
258
|
side: "bottom",
|
|
178
259
|
sideOffset: 4,
|
|
@@ -181,12 +262,28 @@ function Autocomplete({ id, "aria-label": ariaLabel, "aria-describedby": ariaDes
|
|
|
181
262
|
"data-floating-layer": "",
|
|
182
263
|
...KIT_SCOPE,
|
|
183
264
|
...listAttrs,
|
|
184
|
-
children: /* @__PURE__ */
|
|
265
|
+
children: /* @__PURE__ */ jsxDEV(Autocomplete$1.Popup, {
|
|
185
266
|
className: cn("w-[max(var(--anchor-width),280px)] max-w-[min(420px,calc(100vw-24px))] rounded-kit-lg border bg-kit-surface p-1 text-kit-fg shadow-lg outline-none data-[open]:animate-kit-pop-in", menuClassName),
|
|
186
267
|
children: rows
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
|
|
268
|
+
}, void 0, false, {
|
|
269
|
+
fileName: _jsxFileName,
|
|
270
|
+
lineNumber: 277,
|
|
271
|
+
columnNumber: 13
|
|
272
|
+
}, this)
|
|
273
|
+
}, void 0, false, {
|
|
274
|
+
fileName: _jsxFileName,
|
|
275
|
+
lineNumber: 276,
|
|
276
|
+
columnNumber: 11
|
|
277
|
+
}, this) }, void 0, false, {
|
|
278
|
+
fileName: _jsxFileName,
|
|
279
|
+
lineNumber: 275,
|
|
280
|
+
columnNumber: 9
|
|
281
|
+
}, this)]
|
|
282
|
+
}, void 0, true, {
|
|
283
|
+
fileName: _jsxFileName,
|
|
284
|
+
lineNumber: 193,
|
|
285
|
+
columnNumber: 5
|
|
286
|
+
}, this);
|
|
190
287
|
}
|
|
191
288
|
//#endregion
|
|
192
289
|
export { Autocomplete };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"autocomplete.js","names":[],"sources":["../../src/ui/autocomplete.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { Autocomplete as AutocompletePrimitive } from \"@base-ui/react/autocomplete\";\nimport { IconX } from \"@tabler/icons-react\";\nimport { cn } from \"../lib/cn\";\nimport { IconButton } from \"./button\";\nimport { useFieldDescribedBy, useFieldId, useFieldLabelledBy, useLabelFor } from \"./field-context\";\nimport { filterOptions, Highlight, nodeText, type SelectOption } from \"./select\";\nimport { Spinner } from \"./spinner\";\nimport { KIT_SCOPE } from \"./surfaces\";\n\n/* ── Autocomplete ────────────────────────────────────────────────────────\n Free text with suggestions: the value is whatever is typed; a suggestion fills it in. Select only picks fixed options.\n V2 has no component, only the pattern (kit controls link.tsx:504-650, invite-flow.tsx:197); kit-ports-spec.md §2.\n Field = the Input look; the list opens on focus or typing, only while it has rows (free text is a valid value, so\n there is no \"No matches\"); nothing is highlighted until the arrows move, so Enter commits the typed text (onEnter).\n Ranking is Select's filterOptions + Highlight.\n The link field (LinkPicker) opts into V2 link.tsx's extras: an in-flow list (inlineList), a status note when nothing\n matches (emptyNote) or under the rows (listNote), the link-type menu inside the field (leadingSlot), row 0 highlighted\n while typing (highlightFirst), a controlled open, plain row titles (highlightMatches={false}), and Escape that closes\n only the list while it is open (link.tsx:603-618). */\n\nexport interface AutocompleteProps {\n id?: string;\n \"aria-label\"?: string;\n \"aria-describedby\"?: string;\n /** the text (controlled) */\n value?: string;\n defaultValue?: string;\n /** every keystroke, and the label of a picked suggestion */\n onValueChange?: (text: string) => void;\n options: SelectOption[];\n /** a suggestion was picked (click, or Enter on a highlighted row) */\n onSelect?: (option: SelectOption) => void;\n /** Enter with no suggestion highlighted: commit the typed text */\n onEnter?: (text: string) => void;\n /** default: Select's ranking; null = the caller already filtered (async options) */\n filter?: ((options: SelectOption[], query: string) => SelectOption[]) | null;\n placeholder?: string;\n size?: \"sm\" | \"md\" | \"lg\";\n /** decorative icon before the input */\n leading?: React.ReactNode;\n /** an interactive control inside the field before the input (the link-type menu); rendered as is */\n leadingSlot?: React.ReactNode;\n loading?: boolean;\n invalid?: boolean;\n disabled?: boolean;\n /** open the suggestions when the field takes focus (default true, as V2) */\n openOnFocus?: boolean;\n /** controlled open; the list shows while open and it has rows or a note */\n open?: boolean;\n onOpenChange?: (open: boolean) => void;\n /** render the list in the flow under the field instead of a floating popup (panels, popovers) */\n inlineList?: boolean;\n /** a status row shown, with the list kept open, when no row matches */\n emptyNote?: React.ReactNode;\n /** a status row under the rows when there are rows (a partial-load error) */\n listNote?: React.ReactNode;\n /** highlight row 0 on every keystroke that leaves text, so Enter picks it; empty text highlights nothing */\n highlightFirst?: boolean;\n /** emphasise the query inside row labels (default true; V2's link rows draw the plain title) */\n highlightMatches?: boolean;\n /** the listbox's accessible name */\n listLabel?: string;\n /** a pick also writes the row's label into the text (default true); false = a pick only calls onSelect */\n fillOnSelect?: boolean;\n /** replaces the built-in clear (setText(\"\")) on the X */\n onClear?: () => void;\n /** a control inside the field after the clear button (the file-library button) */\n trailingSlot?: React.ReactNode;\n /** data-* attributes on the list's layer (the floating positioner, or the inline wrapper) */\n listAttrs?: Record<`data-${string}`, string>;\n inputRef?: React.Ref<HTMLInputElement>;\n onBlur?: (e: React.FocusEvent<HTMLInputElement>) => void;\n className?: string;\n menuClassName?: string;\n}\n\nconst H = { sm: \"h-7\", md: \"h-8\", lg: \"h-9\" } as const;\n/* V2 link.tsx:507-509 */\nconst NOTE = \"px-2 py-1.5 text-kit-xs text-kit-fg-3\";\n\nexport function Autocomplete({\n id,\n \"aria-label\": ariaLabel,\n \"aria-describedby\": ariaDescribedBy,\n value,\n defaultValue = \"\",\n onValueChange,\n options,\n onSelect,\n onEnter,\n filter = filterOptions,\n placeholder,\n size = \"md\",\n leading,\n leadingSlot,\n loading,\n invalid,\n disabled,\n openOnFocus = true,\n open: openProp,\n onOpenChange,\n inlineList = false,\n emptyNote,\n listNote,\n highlightFirst = false,\n highlightMatches = true,\n listLabel,\n fillOnSelect = true,\n onClear,\n trailingSlot,\n listAttrs,\n inputRef,\n onBlur,\n className,\n menuClassName,\n}: AutocompleteProps) {\n const fieldId = useFieldId();\n const labelledBy = useFieldLabelledBy();\n const labelFor = useLabelFor(id ?? fieldId);\n const describedBy = useFieldDescribedBy();\n const [inner, setInner] = React.useState(defaultValue);\n const text = value ?? inner;\n const setText = (t: string) => {\n if (value === undefined) setInner(t);\n onValueChange?.(t);\n };\n const [innerOpen, setInnerOpen] = React.useState(false);\n const open = openProp ?? innerOpen;\n const setOpen = (o: boolean) => {\n if (openProp === undefined) setInnerOpen(o);\n onOpenChange?.(o);\n };\n const [highlighted, setHighlighted] = React.useState<SelectOption | undefined>(undefined);\n const shown = React.useMemo(() => (filter ? filter(options, text) : options), [filter, options, text]);\n const hasEmptyNote = emptyNote != null && emptyNote !== false;\n const visible = open && (shown.length > 0 || hasEmptyNote);\n /* highlightFirst: row 0 stands in as the active row while text is typed and nothing else is highlighted (V2\n link.tsx sets its own active index to 0 on each keystroke); Base UI's autoHighlight normally does the same. */\n const firstStandsIn = highlightFirst && visible && text.trim() !== \"\" && !highlighted && shown.length > 0 && !shown[0].disabled;\n const pick = (o: SelectOption) => {\n onSelect?.(o);\n if (fillOnSelect) setText(nodeText(o.label));\n setOpen(false);\n };\n const named = id ?? fieldId ?? ariaLabel;\n\n const rows = (\n <>\n <AutocompletePrimitive.List aria-label={listLabel} className=\"max-h-72 overflow-y-auto overscroll-contain empty:hidden\">\n {shown.map((o, i) => (\n <React.Fragment key={o.value}>\n {o.group && (i === 0 || shown[i - 1].group !== o.group) ? (\n <div role=\"presentation\" className=\"px-2 pb-1 pt-2 text-kit-xs font-medium text-kit-fg-3 first:pt-1\">\n {o.group}\n </div>\n ) : null}\n <AutocompletePrimitive.Item\n value={o}\n disabled={o.disabled}\n onClick={() => onSelect?.(o)}\n data-first-active={firstStandsIn && i === 0 ? \"\" : undefined}\n className=\"flex h-8 cursor-pointer select-none items-center gap-2 rounded-kit-md px-2 text-kit-sm outline-none data-[disabled]:pointer-events-none data-[disabled]:opacity-40 data-[highlighted]:bg-kit-hover data-[first-active]:bg-kit-hover\"\n >\n {o.icon ? (\n <span aria-hidden className=\"flex shrink-0 text-kit-fg-3 [&_svg]:size-4\">\n {o.icon}\n </span>\n ) : null}\n <span className=\"min-w-0 shrink truncate text-kit-fg\">\n {highlightMatches && typeof o.label === \"string\" ? <Highlight text={o.label} query={text} /> : o.label}\n </span>\n {o.description ? <span className=\"min-w-0 flex-1 truncate text-kit-xs text-kit-fg-3\">{o.description}</span> : <span className=\"flex-1\" />}\n {o.meta ? <span className=\"shrink-0 text-kit-2xs text-kit-fg-3\">{o.meta}</span> : null}\n </AutocompletePrimitive.Item>\n </React.Fragment>\n ))}\n </AutocompletePrimitive.List>\n {shown.length === 0 && hasEmptyNote ? (\n <p role=\"status\" className={NOTE}>\n {emptyNote}\n </p>\n ) : null}\n {shown.length > 0 && listNote != null && listNote !== false ? (\n <p role=\"status\" className={NOTE}>\n {listNote}\n </p>\n ) : null}\n </>\n );\n\n return (\n <AutocompletePrimitive.Root\n items={shown}\n filter={null}\n mode=\"list\"\n value={text}\n onValueChange={(t, details) => {\n // Base UI writes a pressed row's label into the input; a host that swaps the field for a chip opts out\n if (!fillOnSelect && details.reason === \"item-press\") return;\n setText(t);\n }}\n itemToStringValue={(o: SelectOption) => nodeText(o.label)}\n open={visible}\n onOpenChange={setOpen}\n inline={inlineList}\n // highlight row 0 while typing; Base UI highlights nothing for empty text, so Enter there commits it (onEnter)\n autoHighlight={highlightFirst}\n onItemHighlighted={(o) => setHighlighted(o as SelectOption | undefined)}\n openOnInputClick\n loopFocus\n disabled={disabled}\n >\n <div\n className={cn(\n \"flex min-w-0 items-center rounded-kit-md border border-kit-field-border bg-kit-field-bg shadow-kit-field transition-[border-color,box-shadow] duration-150 hover:border-kit-field-border-hover focus-within:border-kit-field-border-focus focus-within:shadow-kit-ring-field\",\n invalid && \"border-[var(--kit-field-invalid)] hover:border-[var(--kit-field-invalid)]\",\n disabled && \"cursor-not-allowed bg-kit-subtle opacity-60\",\n H[size],\n className,\n )}\n >\n {leadingSlot}\n {leading ? (\n <span aria-hidden className=\"ml-2.5 flex shrink-0 text-kit-fg-3 [&_svg]:size-4\">\n {leading}\n </span>\n ) : null}\n <AutocompletePrimitive.Input\n ref={inputRef}\n id={id ?? fieldId}\n aria-label={ariaLabel}\n aria-labelledby={ariaLabel ? undefined : (labelFor ?? (named ? undefined : labelledBy))}\n aria-describedby={[ariaDescribedBy, describedBy].filter(Boolean).join(\" \") || undefined}\n aria-invalid={invalid || undefined}\n placeholder={placeholder}\n autoComplete=\"off\"\n spellCheck={false}\n onFocus={() => openOnFocus && setOpen(true)}\n onBlur={onBlur}\n onKeyDownCapture={(e) => {\n // V2 link.tsx:603-618: while the list shows, Escape closes only the list; the next one reaches the panel\n if (e.key === \"Escape\" && visible) {\n e.preventDefault();\n e.stopPropagation();\n setOpen(false);\n }\n }}\n onKeyDown={(e) => {\n if (e.key !== \"Enter\") return;\n if (firstStandsIn) {\n e.preventDefault();\n pick(shown[0]);\n } else if (!highlighted || !visible) onEnter?.(text);\n }}\n className=\"h-full min-w-0 flex-1 bg-transparent px-2 text-kit-sm text-kit-fg outline-none placeholder:text-kit-fg-3 disabled:cursor-not-allowed\"\n />\n {loading ? (\n <Spinner size=\"sm\" tone=\"muted\" label=\"Loading suggestions\" className=\"mr-2\" />\n ) : text && !disabled ? (\n <IconButton label=\"Clear\" size=\"xs\" variant=\"ghost\" className=\"mr-1\" onMouseDown={(e) => e.preventDefault()} onClick={() => (onClear ? onClear() : setText(\"\"))}>\n <IconX stroke={1.5} />\n </IconButton>\n ) : null}\n {trailingSlot}\n </div>\n {inlineList ? (\n visible ? (\n /* V2 link.tsx:646-649: the in-flow list under the field */\n <div {...listAttrs} className={cn(\"mt-1 rounded-kit-md border border-kit-line bg-kit-surface p-1\", menuClassName)} onMouseDown={(e) => e.preventDefault()}>\n {rows}\n </div>\n ) : null\n ) : (\n <AutocompletePrimitive.Portal>\n <AutocompletePrimitive.Positioner align=\"start\" side=\"bottom\" sideOffset={4} collisionPadding={12} className=\"z-[var(--kit-z-menu,80)]\" data-floating-layer=\"\" {...KIT_SCOPE} {...listAttrs}>\n <AutocompletePrimitive.Popup\n className={cn(\n \"w-[max(var(--anchor-width),280px)] max-w-[min(420px,calc(100vw-24px))] rounded-kit-lg border bg-kit-surface p-1 text-kit-fg shadow-lg outline-none data-[open]:animate-kit-pop-in\",\n menuClassName,\n )}\n >\n {rows}\n </AutocompletePrimitive.Popup>\n </AutocompletePrimitive.Positioner>\n </AutocompletePrimitive.Portal>\n )}\n </AutocompletePrimitive.Root>\n );\n}\n"],"mappings":";;;;;;;;;;;AA6EA,IAAM,IAAI;CAAE,IAAI;CAAO,IAAI;CAAO,IAAI;AAAM;AAE5C,IAAM,OAAO;AAEb,SAAgB,aAAa,EAC3B,IACA,cAAc,WACd,oBAAoB,iBACpB,OACA,eAAe,IACf,eACA,SACA,UACA,SACA,SAAS,eACT,aACA,OAAO,MACP,SACA,aACA,SACA,SACA,UACA,cAAc,MACd,MAAM,UACN,cACA,aAAa,OACb,WACA,UACA,iBAAiB,OACjB,mBAAmB,MACnB,WACA,eAAe,MACf,SACA,cACA,WACA,UACA,QACA,WACA,iBACoB;CACpB,MAAM,UAAU,WAAW;CAC3B,MAAM,aAAa,mBAAmB;CACtC,MAAM,WAAW,YAAY,MAAM,OAAO;CAC1C,MAAM,cAAc,oBAAoB;CACxC,MAAM,CAAC,OAAO,YAAY,MAAM,SAAS,YAAY;CACrD,MAAM,OAAO,SAAS;CACtB,MAAM,WAAW,MAAc;EAC7B,IAAI,UAAU,KAAA,GAAW,SAAS,CAAC;EACnC,gBAAgB,CAAC;CACnB;CACA,MAAM,CAAC,WAAW,gBAAgB,MAAM,SAAS,KAAK;CACtD,MAAM,OAAO,YAAY;CACzB,MAAM,WAAW,MAAe;EAC9B,IAAI,aAAa,KAAA,GAAW,aAAa,CAAC;EAC1C,eAAe,CAAC;CAClB;CACA,MAAM,CAAC,aAAa,kBAAkB,MAAM,SAAmC,KAAA,CAAS;CACxF,MAAM,QAAQ,MAAM,cAAe,SAAS,OAAO,SAAS,IAAI,IAA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EAAE,eAAe;OACjB,EAAE,gBAAgB;OAClB,QAAQ,KAAK;MACf;KACF;KACA,YAAY,MAAM;MAChB,IAAI,EAAE,QAAQ,SAAS;MACvB,IAAI,eAAe;OACjB,EAAE,eAAe;OACjB,KAAK,MAAM,EAAE;MACf,OAAO,IAAI,CAAC,eAAe,CAAC,SAAS,UAAU,IAAI;KACrD;KACA,WAAU;IACX,CAAA;IACA,UACC,oBAAC,SAAD;KAAS,MAAK;KAAK,MAAK;KAAQ,OAAM;KAAsB,WAAU;IAAQ,CAAA,IAC5E,QAAQ,CAAC,WACX,oBAAC,YAAD;KAAY,OAAM;KAAQ,MAAK;KAAK,SAAQ;KAAQ,WAAU;KAAO,cAAc,MAAM,EAAE,eAAe;KAAG,eAAgB,UAAU,QAAQ,IAAI,QAAQ,EAAE;KAC3J,UAAA,oBAAC,OAAD,EAAO,QAAQ,IAAM,CAAA;IACX,CAAA,IACV;IACH;GACE;EACJ,CAAA,GAAA,aACC,UAEE,oBAAC,OAAD;GAAK,GAAI;GAAW,WAAW,GAAG,iEAAiE,aAAa;GAAG,cAAc,MAAM,EAAE,eAAe;GACrJ,UAAA;EACE,CAAA,IACH,OAEJ,oBAAC,eAAsB,QAAvB,EAAA,UACE,oBAAC,eAAsB,YAAvB;GAAkC,OAAM;GAAQ,MAAK;GAAS,YAAY;GAAG,kBAAkB;GAAI,WAAU;GAA2B,uBAAoB;GAAG,GAAI;GAAW,GAAI;GAChL,UAAA,oBAAC,eAAsB,OAAvB;IACE,WAAW,GACT,qLACA,aACF;IAEC,UAAA;GAC0B,CAAA;EACG,CAAA,EACN,CAAA,CAEN;;AAEhC"}
|
|
1
|
+
{"version":3,"file":"autocomplete.js","names":[],"sources":["../../src/ui/autocomplete.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { Autocomplete as AutocompletePrimitive } from \"@base-ui/react/autocomplete\";\nimport { IconX } from \"@tabler/icons-react\";\nimport { cn } from \"../lib/cn\";\nimport { IconButton } from \"./button\";\nimport { useFieldDescribedBy, useFieldId, useFieldLabelledBy, useLabelFor } from \"./field-context\";\nimport { filterOptions, Highlight, nodeText, type SelectOption } from \"./select\";\nimport { Spinner } from \"./spinner\";\nimport { KIT_SCOPE } from \"./surfaces\";\n\n/* ── Autocomplete ────────────────────────────────────────────────────────\n Free text with suggestions: the value is whatever is typed; a suggestion fills it in. Select only picks fixed options.\n V2 has no component, only the pattern (kit controls link.tsx:504-650, invite-flow.tsx:197); kit-ports-spec.md §2.\n Field = the Input look; the list opens on focus or typing, only while it has rows (free text is a valid value, so\n there is no \"No matches\"); nothing is highlighted until the arrows move, so Enter commits the typed text (onEnter).\n Ranking is Select's filterOptions + Highlight.\n The link field (LinkPicker) opts into V2 link.tsx's extras: an in-flow list (inlineList), a status note when nothing\n matches (emptyNote) or under the rows (listNote), the link-type menu inside the field (leadingSlot), row 0 highlighted\n while typing (highlightFirst), a controlled open, plain row titles (highlightMatches={false}), and Escape that closes\n only the list while it is open (link.tsx:603-618). */\n\nexport interface AutocompleteProps {\n id?: string;\n \"aria-label\"?: string;\n \"aria-describedby\"?: string;\n /** the text (controlled) */\n value?: string;\n defaultValue?: string;\n /** every keystroke, and the label of a picked suggestion */\n onValueChange?: (text: string) => void;\n options: SelectOption[];\n /** a suggestion was picked (click, or Enter on a highlighted row) */\n onSelect?: (option: SelectOption) => void;\n /** Enter with no suggestion highlighted: commit the typed text */\n onEnter?: (text: string) => void;\n /** default: Select's ranking; null = the caller already filtered (async options) */\n filter?: ((options: SelectOption[], query: string) => SelectOption[]) | null;\n placeholder?: string;\n size?: \"sm\" | \"md\" | \"lg\";\n /** decorative icon before the input */\n leading?: React.ReactNode;\n /** an interactive control inside the field before the input (the link-type menu); rendered as is */\n leadingSlot?: React.ReactNode;\n loading?: boolean;\n invalid?: boolean;\n disabled?: boolean;\n /** open the suggestions when the field takes focus (default true, as V2) */\n openOnFocus?: boolean;\n /** controlled open; the list shows while open and it has rows or a note */\n open?: boolean;\n onOpenChange?: (open: boolean) => void;\n /** render the list in the flow under the field instead of a floating popup (panels, popovers) */\n inlineList?: boolean;\n /** a status row shown, with the list kept open, when no row matches */\n emptyNote?: React.ReactNode;\n /** a status row under the rows when there are rows (a partial-load error) */\n listNote?: React.ReactNode;\n /** highlight row 0 on every keystroke that leaves text, so Enter picks it; empty text highlights nothing */\n highlightFirst?: boolean;\n /** emphasise the query inside row labels (default true; V2's link rows draw the plain title) */\n highlightMatches?: boolean;\n /** the listbox's accessible name */\n listLabel?: string;\n /** a pick also writes the row's label into the text (default true); false = a pick only calls onSelect */\n fillOnSelect?: boolean;\n /** replaces the built-in clear (setText(\"\")) on the X */\n onClear?: () => void;\n /** a control inside the field after the clear button (the file-library button) */\n trailingSlot?: React.ReactNode;\n /** data-* attributes on the list's layer (the floating positioner, or the inline wrapper) */\n listAttrs?: Record<`data-${string}`, string>;\n inputRef?: React.Ref<HTMLInputElement>;\n onBlur?: (e: React.FocusEvent<HTMLInputElement>) => void;\n className?: string;\n menuClassName?: string;\n}\n\nconst H = { sm: \"h-7\", md: \"h-8\", lg: \"h-9\" } as const;\n/* V2 link.tsx:507-509 */\nconst NOTE = \"px-2 py-1.5 text-kit-xs text-kit-fg-3\";\n\nexport function Autocomplete({\n id,\n \"aria-label\": ariaLabel,\n \"aria-describedby\": ariaDescribedBy,\n value,\n defaultValue = \"\",\n onValueChange,\n options,\n onSelect,\n onEnter,\n filter = filterOptions,\n placeholder,\n size = \"md\",\n leading,\n leadingSlot,\n loading,\n invalid,\n disabled,\n openOnFocus = true,\n open: openProp,\n onOpenChange,\n inlineList = false,\n emptyNote,\n listNote,\n highlightFirst = false,\n highlightMatches = true,\n listLabel,\n fillOnSelect = true,\n onClear,\n trailingSlot,\n listAttrs,\n inputRef,\n onBlur,\n className,\n menuClassName,\n}: AutocompleteProps) {\n const fieldId = useFieldId();\n const labelledBy = useFieldLabelledBy();\n const labelFor = useLabelFor(id ?? fieldId);\n const describedBy = useFieldDescribedBy();\n const [inner, setInner] = React.useState(defaultValue);\n const text = value ?? inner;\n const setText = (t: string) => {\n if (value === undefined) setInner(t);\n onValueChange?.(t);\n };\n const [innerOpen, setInnerOpen] = React.useState(false);\n const open = openProp ?? innerOpen;\n const setOpen = (o: boolean) => {\n if (openProp === undefined) setInnerOpen(o);\n onOpenChange?.(o);\n };\n const [highlighted, setHighlighted] = React.useState<SelectOption | undefined>(undefined);\n const shown = React.useMemo(() => (filter ? filter(options, text) : options), [filter, options, text]);\n const hasEmptyNote = emptyNote != null && emptyNote !== false;\n const visible = open && (shown.length > 0 || hasEmptyNote);\n /* highlightFirst: row 0 stands in as the active row while text is typed and nothing else is highlighted (V2\n link.tsx sets its own active index to 0 on each keystroke); Base UI's autoHighlight normally does the same. */\n const firstStandsIn = highlightFirst && visible && text.trim() !== \"\" && !highlighted && shown.length > 0 && !shown[0].disabled;\n const pick = (o: SelectOption) => {\n onSelect?.(o);\n if (fillOnSelect) setText(nodeText(o.label));\n setOpen(false);\n };\n const named = id ?? fieldId ?? ariaLabel;\n\n const rows = (\n <>\n <AutocompletePrimitive.List aria-label={listLabel} className=\"max-h-72 overflow-y-auto overscroll-contain empty:hidden\">\n {shown.map((o, i) => (\n <React.Fragment key={o.value}>\n {o.group && (i === 0 || shown[i - 1].group !== o.group) ? (\n <div role=\"presentation\" className=\"px-2 pb-1 pt-2 text-kit-xs font-medium text-kit-fg-3 first:pt-1\">\n {o.group}\n </div>\n ) : null}\n <AutocompletePrimitive.Item\n value={o}\n disabled={o.disabled}\n onClick={() => onSelect?.(o)}\n data-first-active={firstStandsIn && i === 0 ? \"\" : undefined}\n className=\"flex h-8 cursor-pointer select-none items-center gap-2 rounded-kit-md px-2 text-kit-sm outline-none data-[disabled]:pointer-events-none data-[disabled]:opacity-40 data-[highlighted]:bg-kit-hover data-[first-active]:bg-kit-hover\"\n >\n {o.icon ? (\n <span aria-hidden className=\"flex shrink-0 text-kit-fg-3 [&_svg]:size-4\">\n {o.icon}\n </span>\n ) : null}\n <span className=\"min-w-0 shrink truncate text-kit-fg\">\n {highlightMatches && typeof o.label === \"string\" ? <Highlight text={o.label} query={text} /> : o.label}\n </span>\n {o.description ? <span className=\"min-w-0 flex-1 truncate text-kit-xs text-kit-fg-3\">{o.description}</span> : <span className=\"flex-1\" />}\n {o.meta ? <span className=\"shrink-0 text-kit-2xs text-kit-fg-3\">{o.meta}</span> : null}\n </AutocompletePrimitive.Item>\n </React.Fragment>\n ))}\n </AutocompletePrimitive.List>\n {shown.length === 0 && hasEmptyNote ? (\n <p role=\"status\" className={NOTE}>\n {emptyNote}\n </p>\n ) : null}\n {shown.length > 0 && listNote != null && listNote !== false ? (\n <p role=\"status\" className={NOTE}>\n {listNote}\n </p>\n ) : null}\n </>\n );\n\n return (\n <AutocompletePrimitive.Root\n items={shown}\n filter={null}\n mode=\"list\"\n value={text}\n onValueChange={(t, details) => {\n // Base UI writes a pressed row's label into the input; a host that swaps the field for a chip opts out\n if (!fillOnSelect && details.reason === \"item-press\") return;\n setText(t);\n }}\n itemToStringValue={(o: SelectOption) => nodeText(o.label)}\n open={visible}\n onOpenChange={setOpen}\n inline={inlineList}\n // highlight row 0 while typing; Base UI highlights nothing for empty text, so Enter there commits it (onEnter)\n autoHighlight={highlightFirst}\n onItemHighlighted={(o) => setHighlighted(o as SelectOption | undefined)}\n openOnInputClick\n loopFocus\n disabled={disabled}\n >\n <div\n className={cn(\n \"flex min-w-0 items-center rounded-kit-md border border-kit-field-border bg-kit-field-bg shadow-kit-field transition-[border-color,box-shadow] duration-150 hover:border-kit-field-border-hover focus-within:border-kit-field-border-focus focus-within:shadow-kit-ring-field\",\n invalid && \"border-[var(--kit-field-invalid)] hover:border-[var(--kit-field-invalid)]\",\n disabled && \"cursor-not-allowed bg-kit-subtle opacity-60\",\n H[size],\n className,\n )}\n >\n {leadingSlot}\n {leading ? (\n <span aria-hidden className=\"ml-2.5 flex shrink-0 text-kit-fg-3 [&_svg]:size-4\">\n {leading}\n </span>\n ) : null}\n <AutocompletePrimitive.Input\n ref={inputRef}\n id={id ?? fieldId}\n aria-label={ariaLabel}\n aria-labelledby={ariaLabel ? undefined : (labelFor ?? (named ? undefined : labelledBy))}\n aria-describedby={[ariaDescribedBy, describedBy].filter(Boolean).join(\" \") || undefined}\n aria-invalid={invalid || undefined}\n placeholder={placeholder}\n autoComplete=\"off\"\n spellCheck={false}\n onFocus={() => openOnFocus && setOpen(true)}\n onBlur={onBlur}\n onKeyDownCapture={(e) => {\n // V2 link.tsx:603-618: while the list shows, Escape closes only the list; the next one reaches the panel\n if (e.key === \"Escape\" && visible) {\n e.preventDefault();\n e.stopPropagation();\n setOpen(false);\n }\n }}\n onKeyDown={(e) => {\n if (e.key !== \"Enter\") return;\n if (firstStandsIn) {\n e.preventDefault();\n pick(shown[0]);\n } else if (!highlighted || !visible) onEnter?.(text);\n }}\n className=\"h-full min-w-0 flex-1 bg-transparent px-2 text-kit-sm text-kit-fg outline-none placeholder:text-kit-fg-3 disabled:cursor-not-allowed\"\n />\n {loading ? (\n <Spinner size=\"sm\" tone=\"muted\" label=\"Loading suggestions\" className=\"mr-2\" />\n ) : text && !disabled ? (\n <IconButton label=\"Clear\" size=\"xs\" variant=\"ghost\" className=\"mr-1\" onMouseDown={(e) => e.preventDefault()} onClick={() => (onClear ? onClear() : setText(\"\"))}>\n <IconX stroke={1.5} />\n </IconButton>\n ) : null}\n {trailingSlot}\n </div>\n {inlineList ? (\n visible ? (\n /* V2 link.tsx:646-649: the in-flow list under the field */\n <div {...listAttrs} className={cn(\"mt-1 rounded-kit-md border border-kit-line bg-kit-surface p-1\", menuClassName)} onMouseDown={(e) => e.preventDefault()}>\n {rows}\n </div>\n ) : null\n ) : (\n <AutocompletePrimitive.Portal>\n <AutocompletePrimitive.Positioner align=\"start\" side=\"bottom\" sideOffset={4} collisionPadding={12} className=\"z-[var(--kit-z-menu,80)]\" data-floating-layer=\"\" {...KIT_SCOPE} {...listAttrs}>\n <AutocompletePrimitive.Popup\n className={cn(\n \"w-[max(var(--anchor-width),280px)] max-w-[min(420px,calc(100vw-24px))] rounded-kit-lg border bg-kit-surface p-1 text-kit-fg shadow-lg outline-none data-[open]:animate-kit-pop-in\",\n menuClassName,\n )}\n >\n {rows}\n </AutocompletePrimitive.Popup>\n </AutocompletePrimitive.Positioner>\n </AutocompletePrimitive.Portal>\n )}\n </AutocompletePrimitive.Root>\n );\n}\n"],"mappings":";;;;;;;;;;;;AA6EA,IAAM,IAAI;CAAE,IAAI;CAAO,IAAI;CAAO,IAAI;AAAM;AAE5C,IAAM,OAAO;AAEb,SAAgB,aAAa,EAC3B,IACA,cAAc,WACd,oBAAoB,iBACpB,OACA,eAAe,IACf,eACA,SACA,UACA,SACA,SAAS,eACT,aACA,OAAO,MACP,SACA,aACA,SACA,SACA,UACA,cAAc,MACd,MAAM,UACN,cACA,aAAa,OACb,WACA,UACA,iBAAiB,OACjB,mBAAmB,MACnB,WACA,eAAe,MACf,SACA,cACA,WACA,UACA,QACA,WACA,iBACoB;CACpB,MAAM,UAAU,WAAW;CAC3B,MAAM,aAAa,mBAAmB;CACtC,MAAM,WAAW,YAAY,MAAM,OAAO;CAC1C,MAAM,cAAc,oBAAoB;CACxC,MAAM,CAAC,OAAO,YAAY,MAAM,SAAS,YAAY;CACrD,MAAM,OAAO,SAAS;CACtB,MAAM,WAAW,MAAc;EAC7B,IAAI,UAAU,KAAA,GAAW,SAAS,CAAC;EACnC,gBAAgB,CAAC;CACnB;CACA,MAAM,CAAC,WAAW,gBAAgB,MAAM,SAAS,KAAK;CACtD,MAAM,OAAO,YAAY;CACzB,MAAM,WAAW,MAAe;EAC9B,IAAI,aAAa,KAAA,GAAW,aAAa,CAAC;EAC1C,eAAe,CAAC;CAClB;CACA,MAAM,CAAC,aAAa,kBAAkB,MAAM,SAAmC,KAAA,CAAS;CACxF,MAAM,QAAQ,MAAM,cAAe,SAAS,OAAO,SAAS,IAAI,IAAI,SAAU;EAAC;EAAQ;EAAS;CAAI,CAAC;CACrG,MAAM,eAAe,aAAa,QAAQ,cAAc;CACxD,MAAM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A;;;;EACH,GAAA,IAAA,IAAA,OAEJ,uBAAC,eAAsB,QAAvB,EAAA,UACE,uBAAC,eAAsB,YAAvB;GAAkC,OAAM;GAAQ,MAAK;GAAS,YAAY;GAAG,kBAAkB;GAAI,WAAU;GAA2B,uBAAoB;GAAG,GAAI;GAAW,GAAI;GAChL,UAAA,uBAAC,eAAsB,OAAvB;IACE,WAAW,GACT,qLACA,aACF;IAEC,UAAA;GAC0B,GAAA,KAAA,GAAA,OAAA;;;;;EACG,GAAA,KAAA,GAAA,OAAA;;;;EACN,GAAA,IAAA,EAAA,GAAA,KAAA,GAAA,OAAA;;;;EAEN,GAAA,IAAA,CAAA;;;;;;AAEhC"}
|
package/dist/ui/button.js
CHANGED
|
@@ -4,10 +4,11 @@ import { Spinner } from "./spinner.js";
|
|
|
4
4
|
import { TooltipLayer, TooltipRoot } from "./tooltip-root.js";
|
|
5
5
|
import { variants } from "./variants.js";
|
|
6
6
|
import * as React from "react";
|
|
7
|
-
import {
|
|
7
|
+
import { jsxDEV } from "react/jsx-dev-runtime";
|
|
8
8
|
import { IconPlus } from "@tabler/icons-react";
|
|
9
9
|
import { Tooltip } from "@base-ui/react/tooltip";
|
|
10
10
|
//#region src/ui/button.tsx
|
|
11
|
+
var _jsxFileName = "D:/Github/bettercms/bettercms-backend/packages/kit/src/ui/button.tsx";
|
|
11
12
|
/**
|
|
12
13
|
* Button: the only button in the kit.
|
|
13
14
|
* Heights: xs 24 · sm 28 · md 32 (default) · lg 36 · xl 40. Radius 6.
|
|
@@ -62,7 +63,7 @@ var Button = React.forwardRef(({ className, variant, size, asChild, loading, lef
|
|
|
62
63
|
className: cn(classes, children.props.className),
|
|
63
64
|
ref: mergeRefs(ref, children.props.ref)
|
|
64
65
|
});
|
|
65
|
-
return /* @__PURE__ */
|
|
66
|
+
return /* @__PURE__ */ jsxDEV("button", {
|
|
66
67
|
ref,
|
|
67
68
|
type: props.type ?? "button",
|
|
68
69
|
disabled: disabled || loading,
|
|
@@ -70,12 +71,24 @@ var Button = React.forwardRef(({ className, variant, size, asChild, loading, lef
|
|
|
70
71
|
className: classes,
|
|
71
72
|
...props,
|
|
72
73
|
children: [
|
|
73
|
-
loading ? /* @__PURE__ */
|
|
74
|
-
|
|
74
|
+
loading ? /* @__PURE__ */ jsxDEV(Spinner, {}, void 0, false, {
|
|
75
|
+
fileName: _jsxFileName,
|
|
76
|
+
lineNumber: 79,
|
|
77
|
+
columnNumber: 20
|
|
78
|
+
}, void 0) : leftIcon,
|
|
79
|
+
variant === "ai" && !leftIcon && !loading ? /* @__PURE__ */ jsxDEV(Sparkle, {}, void 0, false, {
|
|
80
|
+
fileName: _jsxFileName,
|
|
81
|
+
lineNumber: 80,
|
|
82
|
+
columnNumber: 54
|
|
83
|
+
}, void 0) : null,
|
|
75
84
|
children,
|
|
76
85
|
rightIcon
|
|
77
86
|
]
|
|
78
|
-
}
|
|
87
|
+
}, void 0, true, {
|
|
88
|
+
fileName: _jsxFileName,
|
|
89
|
+
lineNumber: 77,
|
|
90
|
+
columnNumber: 7
|
|
91
|
+
}, void 0);
|
|
79
92
|
});
|
|
80
93
|
Button.displayName = "Button";
|
|
81
94
|
/** Square icon-only button. Always pass `label` (used for aria-label + tooltip). */
|
|
@@ -109,23 +122,43 @@ var TooltipScope = React.createContext(false);
|
|
|
109
122
|
* import overlay.tsx; overlay's <Tooltip> adds the shortcut slot on top of the same layer.
|
|
110
123
|
*/
|
|
111
124
|
function HintTooltip({ content, side = "top", delay = 350, children }) {
|
|
112
|
-
return /* @__PURE__ */
|
|
125
|
+
return /* @__PURE__ */ jsxDEV(TooltipScope.Provider, {
|
|
113
126
|
value: true,
|
|
114
|
-
children: /* @__PURE__ */
|
|
127
|
+
children: /* @__PURE__ */ jsxDEV(TooltipRoot, { children: [/* @__PURE__ */ jsxDEV(Tooltip.Trigger, {
|
|
115
128
|
delay,
|
|
116
129
|
render: children
|
|
117
|
-
}
|
|
130
|
+
}, void 0, false, {
|
|
131
|
+
fileName: _jsxFileName,
|
|
132
|
+
lineNumber: 135,
|
|
133
|
+
columnNumber: 9
|
|
134
|
+
}, this), /* @__PURE__ */ jsxDEV(TooltipLayer, {
|
|
118
135
|
side,
|
|
119
|
-
children: /* @__PURE__ */
|
|
136
|
+
children: /* @__PURE__ */ jsxDEV("span", {
|
|
120
137
|
className: "line-clamp-[8] min-w-0 whitespace-normal [overflow-wrap:anywhere]",
|
|
121
138
|
children: content
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
|
|
139
|
+
}, void 0, false, {
|
|
140
|
+
fileName: _jsxFileName,
|
|
141
|
+
lineNumber: 137,
|
|
142
|
+
columnNumber: 11
|
|
143
|
+
}, this)
|
|
144
|
+
}, void 0, false, {
|
|
145
|
+
fileName: _jsxFileName,
|
|
146
|
+
lineNumber: 136,
|
|
147
|
+
columnNumber: 9
|
|
148
|
+
}, this)] }, void 0, true, {
|
|
149
|
+
fileName: _jsxFileName,
|
|
150
|
+
lineNumber: 134,
|
|
151
|
+
columnNumber: 7
|
|
152
|
+
}, this)
|
|
153
|
+
}, void 0, false, {
|
|
154
|
+
fileName: _jsxFileName,
|
|
155
|
+
lineNumber: 133,
|
|
156
|
+
columnNumber: 5
|
|
157
|
+
}, this);
|
|
125
158
|
}
|
|
126
159
|
var IconButton = React.forwardRef(({ className, size, variant, label, active, children, tooltip, tooltipSide = "top", ...props }, ref) => {
|
|
127
160
|
const inTooltip = React.useContext(TooltipScope);
|
|
128
|
-
const btn = /* @__PURE__ */
|
|
161
|
+
const btn = /* @__PURE__ */ jsxDEV("button", {
|
|
129
162
|
ref,
|
|
130
163
|
type: "button",
|
|
131
164
|
"aria-label": label,
|
|
@@ -136,25 +169,33 @@ var IconButton = React.forwardRef(({ className, size, variant, label, active, ch
|
|
|
136
169
|
}), className),
|
|
137
170
|
...props,
|
|
138
171
|
children
|
|
139
|
-
}
|
|
172
|
+
}, void 0, false, {
|
|
173
|
+
fileName: _jsxFileName,
|
|
174
|
+
lineNumber: 156,
|
|
175
|
+
columnNumber: 7
|
|
176
|
+
}, void 0);
|
|
140
177
|
if (inTooltip || tooltip === false || !label) return btn;
|
|
141
|
-
return /* @__PURE__ */
|
|
178
|
+
return /* @__PURE__ */ jsxDEV(HintTooltip, {
|
|
142
179
|
content: tooltip ?? label,
|
|
143
180
|
side: tooltipSide,
|
|
144
181
|
children: btn
|
|
145
|
-
}
|
|
182
|
+
}, void 0, false, {
|
|
183
|
+
fileName: _jsxFileName,
|
|
184
|
+
lineNumber: 171,
|
|
185
|
+
columnNumber: 7
|
|
186
|
+
}, void 0);
|
|
146
187
|
});
|
|
147
188
|
IconButton.displayName = "IconButton";
|
|
148
189
|
/** The AI sparkle in the official brand gradient. Used everywhere AI appears. */
|
|
149
190
|
function Sparkle({ className, size = 16 }) {
|
|
150
191
|
const id = React.useId().replace(/:/g, "");
|
|
151
|
-
return /* @__PURE__ */
|
|
192
|
+
return /* @__PURE__ */ jsxDEV("svg", {
|
|
152
193
|
width: size,
|
|
153
194
|
height: size,
|
|
154
195
|
viewBox: "2 2 16 16",
|
|
155
196
|
className: cn("shrink-0", className),
|
|
156
197
|
"aria-hidden": true,
|
|
157
|
-
children: [/* @__PURE__ */
|
|
198
|
+
children: [/* @__PURE__ */ jsxDEV("defs", { children: /* @__PURE__ */ jsxDEV("linearGradient", {
|
|
158
199
|
id: `sp${id}`,
|
|
159
200
|
x1: "6.89",
|
|
160
201
|
y1: "4.59",
|
|
@@ -162,36 +203,72 @@ function Sparkle({ className, size = 16 }) {
|
|
|
162
203
|
y2: "23.67",
|
|
163
204
|
gradientUnits: "userSpaceOnUse",
|
|
164
205
|
children: [
|
|
165
|
-
/* @__PURE__ */
|
|
206
|
+
/* @__PURE__ */ jsxDEV("stop", {
|
|
166
207
|
offset: "0.0817",
|
|
167
208
|
style: { stopColor: "var(--kit-brand-violet)" }
|
|
168
|
-
}
|
|
169
|
-
|
|
209
|
+
}, void 0, false, {
|
|
210
|
+
fileName: _jsxFileName,
|
|
211
|
+
lineNumber: 186,
|
|
212
|
+
columnNumber: 11
|
|
213
|
+
}, this),
|
|
214
|
+
/* @__PURE__ */ jsxDEV("stop", {
|
|
170
215
|
offset: "0.4667",
|
|
171
216
|
style: { stopColor: "var(--kit-brand-coral)" }
|
|
172
|
-
}
|
|
173
|
-
|
|
217
|
+
}, void 0, false, {
|
|
218
|
+
fileName: _jsxFileName,
|
|
219
|
+
lineNumber: 187,
|
|
220
|
+
columnNumber: 11
|
|
221
|
+
}, this),
|
|
222
|
+
/* @__PURE__ */ jsxDEV("stop", {
|
|
174
223
|
offset: "1",
|
|
175
224
|
style: { stopColor: "var(--kit-brand-rose)" }
|
|
176
|
-
}
|
|
225
|
+
}, void 0, false, {
|
|
226
|
+
fileName: _jsxFileName,
|
|
227
|
+
lineNumber: 188,
|
|
228
|
+
columnNumber: 11
|
|
229
|
+
}, this)
|
|
177
230
|
]
|
|
178
|
-
}
|
|
231
|
+
}, void 0, true, {
|
|
232
|
+
fileName: _jsxFileName,
|
|
233
|
+
lineNumber: 185,
|
|
234
|
+
columnNumber: 9
|
|
235
|
+
}, this) }, void 0, false, {
|
|
236
|
+
fileName: _jsxFileName,
|
|
237
|
+
lineNumber: 184,
|
|
238
|
+
columnNumber: 7
|
|
239
|
+
}, this), /* @__PURE__ */ jsxDEV("path", {
|
|
179
240
|
d: SPARKLE_PATH,
|
|
180
241
|
fill: `url(#sp${id})`
|
|
181
|
-
}
|
|
182
|
-
|
|
242
|
+
}, void 0, false, {
|
|
243
|
+
fileName: _jsxFileName,
|
|
244
|
+
lineNumber: 191,
|
|
245
|
+
columnNumber: 7
|
|
246
|
+
}, this)]
|
|
247
|
+
}, void 0, true, {
|
|
248
|
+
fileName: _jsxFileName,
|
|
249
|
+
lineNumber: 183,
|
|
250
|
+
columnNumber: 5
|
|
251
|
+
}, this);
|
|
183
252
|
}
|
|
184
253
|
/** D15 progressive disclosure: "+ Add a message" / "+ Limit to specific sites": reveals an optional input. */
|
|
185
254
|
function RevealLink({ className, children, ...props }) {
|
|
186
|
-
return /* @__PURE__ */
|
|
255
|
+
return /* @__PURE__ */ jsxDEV("button", {
|
|
187
256
|
type: "button",
|
|
188
257
|
className: cn("inline-flex h-7 items-center gap-1 rounded-kit-md text-kit-sm font-medium text-kit-fg-2 transition-colors hover:text-kit-fg [&_svg]:size-3.5", className),
|
|
189
258
|
...props,
|
|
190
|
-
children: [/* @__PURE__ */
|
|
259
|
+
children: [/* @__PURE__ */ jsxDEV(IconPlus, {
|
|
191
260
|
stroke: 2,
|
|
192
261
|
"aria-hidden": true
|
|
193
|
-
}
|
|
194
|
-
|
|
262
|
+
}, void 0, false, {
|
|
263
|
+
fileName: _jsxFileName,
|
|
264
|
+
lineNumber: 207,
|
|
265
|
+
columnNumber: 7
|
|
266
|
+
}, this), children]
|
|
267
|
+
}, void 0, true, {
|
|
268
|
+
fileName: _jsxFileName,
|
|
269
|
+
lineNumber: 199,
|
|
270
|
+
columnNumber: 5
|
|
271
|
+
}, this);
|
|
195
272
|
}
|
|
196
273
|
//#endregion
|
|
197
274
|
export { Button, HintTooltip, IconButton, RevealLink, Sparkle, TooltipScope, buttonVariants, iconButtonVariants };
|
package/dist/ui/button.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"button.js","names":[],"sources":["../../src/ui/button.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { Tooltip as TooltipPrimitive } from \"@base-ui/react/tooltip\";\nimport { IconPlus } from \"@tabler/icons-react\";\nimport { cn } from \"../lib/cn\";\nimport { SPARKLE_PATH } from \"../brand/logo\";\nimport { Spinner } from \"./spinner\";\nimport { TooltipLayer, TooltipRoot } from \"./tooltip-root\";\nimport { variants, type VariantProps } from \"./variants\";\n\n/**\n * Button: the only button in the kit.\n * Heights: xs 24 · sm 28 · md 32 (default) · lg 36 · xl 40. Radius 6.\n * Variants: primary (ink) · accent (violet, reserved for the ONE create action per screen)\n * secondary (bordered) · ghost · soft · danger · danger-ghost · link · ai (gradient sparkle)\n * The keyboard focus ring is the global :focus-visible outline, suppressed under pointer modality (DESIGN.md 3.7).\n */\nexport const buttonVariants = variants(\n \"relative inline-flex items-center justify-center gap-1.5 whitespace-nowrap font-medium tracking-[-0.01em] select-none transition-[background-color,border-color,color,box-shadow,opacity] duration-150 ease-out disabled:pointer-events-none disabled:opacity-45 [&_svg]:shrink-0 [&_svg]:opacity-90\",\n {\n variants: {\n variant: {\n // .btn-solid: in dark a disabled primary/accent takes the solid --kit-disabled-bg / --kit-disabled-fg pair; light keeps the opacity dim.\n primary: \"bg-kit-inverse text-kit-fg-inverse shadow-kit-button-primary hover:bg-kit-inverse-hover active:bg-kit-inverse btn-solid\",\n accent: \"bg-kit-accent text-kit-accent-on shadow-kit-xs hover:bg-kit-accent-hover btn-solid\",\n secondary: \"border border-kit-line-strong bg-kit-control-bg text-kit-fg shadow-kit-xs hover:bg-kit-subtle active:bg-kit-hover\",\n ghost: \"text-kit-fg-2 hover:bg-kit-hover hover:text-kit-fg active:bg-kit-selected\",\n soft: \"bg-kit-muted text-kit-fg hover:bg-kit-selected\",\n danger: \"bg-kit-danger text-kit-danger-on shadow-kit-xs hover:brightness-95\",\n \"danger-ghost\": \"text-kit-danger-fg hover:bg-kit-danger-soft\",\n link: \"text-kit-accent-fg underline-offset-4 hover:underline px-0 h-auto active:scale-100\",\n ai: \"border border-kit-line bg-kit-control-bg text-kit-fg shadow-kit-xs hover:border-kit-accent-line hover:bg-kit-accent-softer\",\n },\n size: {\n xs: \"h-6 rounded-kit-md px-2 text-kit-xs [&_svg]:size-3.5\",\n sm: \"h-7 rounded-kit-md px-2.5 text-kit-sm [&_svg]:size-3.5\",\n md: \"h-8 rounded-kit-md px-3 text-kit-sm [&_svg]:size-4\",\n lg: \"h-9 rounded-kit-md px-3.5 text-kit-base [&_svg]:size-4\",\n xl: \"h-10 rounded-kit-md px-4 text-kit-base [&_svg]:size-[18px]\",\n },\n },\n compoundVariants: [{ variant: \"link\", className: \"h-auto px-0\" }],\n defaultVariants: { variant: \"secondary\", size: \"md\" },\n },\n);\n\nexport interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement>, VariantProps<typeof buttonVariants> {\n /** Render the single child element (a link, say) with the button's classes and props. */\n asChild?: boolean;\n loading?: boolean;\n leftIcon?: React.ReactNode;\n rightIcon?: React.ReactNode;\n}\n\ntype ChildProps = { className?: string; ref?: React.Ref<unknown> };\n\nfunction mergeRefs<T>(...refs: (React.Ref<T> | undefined)[]) {\n return (node: T | null) => {\n for (const ref of refs) {\n if (typeof ref === \"function\") ref(node);\n else if (ref) (ref as React.RefObject<T | null>).current = node;\n }\n };\n}\n\nexport const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(\n ({ className, variant, size, asChild, loading, leftIcon, rightIcon, children, disabled, ...props }, ref) => {\n const classes = cn(buttonVariants({ variant, size }), className);\n if (asChild && React.isValidElement<ChildProps>(children)) {\n return React.cloneElement(children, {\n ...props,\n ...children.props,\n className: cn(classes, children.props.className),\n ref: mergeRefs(ref as React.Ref<unknown>, children.props.ref),\n });\n }\n return (\n <button ref={ref} type={props.type ?? \"button\"} disabled={disabled || loading} aria-busy={loading || undefined} className={classes} {...props}>\n {/* the kit Spinner (decorative: the button says it is busy); the size variant's [&_svg] rule sizes its glyph */}\n {loading ? <Spinner /> : leftIcon}\n {variant === \"ai\" && !leftIcon && !loading ? <Sparkle /> : null}\n {children}\n {rightIcon}\n </button>\n );\n },\n);\nButton.displayName = \"Button\";\n\n/** Square icon-only button. Always pass `label` (used for aria-label + tooltip). */\nexport const iconButtonVariants = variants(\n \"relative inline-flex items-center justify-center shrink-0 text-kit-fg-2 transition-colors duration-150 hover:bg-kit-hover hover:text-kit-fg active:scale-[0.96] disabled:opacity-40 disabled:pointer-events-none data-[active=true]:bg-kit-selected data-[active=true]:text-kit-fg\",\n {\n variants: {\n size: {\n xs: \"size-6 rounded-kit-md [&_svg]:size-3.5\",\n sm: \"size-7 rounded-kit-md [&_svg]:size-4\",\n md: \"size-8 rounded-kit-md [&_svg]:size-4\",\n lg: \"size-9 rounded-kit-md [&_svg]:size-[18px]\",\n },\n variant: {\n ghost: \"\",\n outline: \"border border-kit-line bg-kit-control-bg shadow-kit-xs hover:border-kit-line-strong\",\n soft: \"bg-kit-muted\",\n },\n },\n defaultVariants: { size: \"md\", variant: \"ghost\" },\n },\n);\n\n/**\n * a11y: true while rendering inside a tooltip (or a surface that manages its own hints), so an IconButton nested\n * there doesn't add a second tooltip. Provided by HintTooltip and overlay.tsx's <Tooltip>.\n */\nexport const TooltipScope = React.createContext(false);\n\n/**\n * The plain ink hint (DESIGN.md 8.23: top, 6px offset, 8px collision padding, portalled, z 90, 350ms). The child\n * element is the trigger and must take a ref and DOM props. input, display and action-tray use it so they never\n * import overlay.tsx; overlay's <Tooltip> adds the shortcut slot on top of the same layer.\n */\nexport function HintTooltip({\n content,\n side = \"top\",\n delay = 350,\n children,\n}: {\n content: React.ReactNode;\n side?: \"top\" | \"bottom\" | \"left\" | \"right\";\n delay?: number;\n children: React.ReactElement;\n}) {\n return (\n <TooltipScope.Provider value>\n <TooltipRoot>\n <TooltipPrimitive.Trigger delay={delay} render={children} />\n <TooltipLayer side={side}>\n <span className=\"line-clamp-[8] min-w-0 whitespace-normal [overflow-wrap:anywhere]\">{content}</span>\n </TooltipLayer>\n </TooltipRoot>\n </TooltipScope.Provider>\n );\n}\n\nexport interface IconButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement>, VariantProps<typeof iconButtonVariants> {\n label: string;\n active?: boolean;\n /** Hover/focus hint. Defaults to `label`; pass `false` to opt out, or a node to customise. */\n tooltip?: React.ReactNode | false;\n tooltipSide?: \"top\" | \"bottom\" | \"left\" | \"right\";\n}\n\nexport const IconButton = React.forwardRef<HTMLButtonElement, IconButtonProps>(\n ({ className, size, variant, label, active, children, tooltip, tooltipSide = \"top\", ...props }, ref) => {\n const inTooltip = React.useContext(TooltipScope);\n const btn = (\n <button\n ref={ref}\n type=\"button\"\n aria-label={label}\n data-active={active ? \"true\" : undefined}\n className={cn(iconButtonVariants({ size, variant }), className)}\n {...props}\n >\n {children}\n </button>\n );\n // Every icon-only button gets a visible hint on hover AND keyboard focus (brief §11), unless a\n // parent tooltip already provides one or the caller opted out.\n if (inTooltip || tooltip === false || !label) return btn;\n return (\n <HintTooltip content={tooltip ?? label} side={tooltipSide}>\n {btn}\n </HintTooltip>\n );\n },\n);\nIconButton.displayName = \"IconButton\";\n\n/** The AI sparkle in the official brand gradient. Used everywhere AI appears. */\nexport function Sparkle({ className, size = 16 }: { className?: string; size?: number }) {\n const id = React.useId().replace(/:/g, \"\");\n return (\n <svg width={size} height={size} viewBox=\"2 2 16 16\" className={cn(\"shrink-0\", className)} aria-hidden>\n <defs>\n <linearGradient id={`sp${id}`} x1=\"6.89\" y1=\"4.59\" x2=\"18\" y2=\"23.67\" gradientUnits=\"userSpaceOnUse\">\n <stop offset=\"0.0817\" style={{ stopColor: \"var(--kit-brand-violet)\" }} />\n <stop offset=\"0.4667\" style={{ stopColor: \"var(--kit-brand-coral)\" }} />\n <stop offset=\"1\" style={{ stopColor: \"var(--kit-brand-rose)\" }} />\n </linearGradient>\n </defs>\n <path d={SPARKLE_PATH} fill={`url(#sp${id})`} />\n </svg>\n );\n}\n\n/** D15 progressive disclosure: \"+ Add a message\" / \"+ Limit to specific sites\": reveals an optional input. */\nexport function RevealLink({ className, children, ...props }: React.ButtonHTMLAttributes<HTMLButtonElement>) {\n return (\n <button\n type=\"button\"\n className={cn(\n \"inline-flex h-7 items-center gap-1 rounded-kit-md text-kit-sm font-medium text-kit-fg-2 transition-colors hover:text-kit-fg [&_svg]:size-3.5\",\n className,\n )}\n {...props}\n >\n <IconPlus stroke={2} aria-hidden />\n {children}\n </button>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAgBA,IAAa,iBAAiB,SAC5B,wSACA;CACE,UAAU;EACR,SAAS;GAEP,SAAS;GACT,QAAQ;GACR,WAAW;GACX,OAAO;GACP,MAAM;GACN,QAAQ;GACR,gBAAgB;GAChB,MAAM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GAAK,IAAG;GAAQ,eAAc;GAApF,UAAA;IACE,oBAAC,QAAD;KAAM,QAAO;KAAS,OAAO,EAAE,WAAW,0BAA0B;IAAI,CAAA;IACxE,oBAAC,QAAD;KAAM,QAAO;KAAS,OAAO,EAAE,WAAW,yBAAyB;IAAI,CAAA;IACvE,oBAAC,QAAD;KAAM,QAAO;KAAI,OAAO,EAAE,WAAW,wBAAwB;IAAI,CAAA;GACnD;EACZ,CAAA,EAAA,CAAA,GACN,oBAAC,QAAD;GAAM,GAAG;GAAc,MAAM,UAAU,GAAG;EAAK,CAAA,CAC5C;;AAET;;AAGA,SAAgB,WAAW,EAAE,WAAW,UAAU,GAAG,SAAwD;CAC3G,OACE,qBAAC,UAAD;EACE,MAAK;EACL,WAAW,GACT,gJACA,SACF;EACA,GAAI;EANN,UAAA,CAQE,oBAAC,UAAD;GAAU,QAAQ;GAAG,eAAA;EAAa,CAAA,GACjC,QACK;;AAEZ"}
|
|
1
|
+
{"version":3,"file":"button.js","names":[],"sources":["../../src/ui/button.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { Tooltip as TooltipPrimitive } from \"@base-ui/react/tooltip\";\nimport { IconPlus } from \"@tabler/icons-react\";\nimport { cn } from \"../lib/cn\";\nimport { SPARKLE_PATH } from \"../brand/logo\";\nimport { Spinner } from \"./spinner\";\nimport { TooltipLayer, TooltipRoot } from \"./tooltip-root\";\nimport { variants, type VariantProps } from \"./variants\";\n\n/**\n * Button: the only button in the kit.\n * Heights: xs 24 · sm 28 · md 32 (default) · lg 36 · xl 40. Radius 6.\n * Variants: primary (ink) · accent (violet, reserved for the ONE create action per screen)\n * secondary (bordered) · ghost · soft · danger · danger-ghost · link · ai (gradient sparkle)\n * The keyboard focus ring is the global :focus-visible outline, suppressed under pointer modality (DESIGN.md 3.7).\n */\nexport const buttonVariants = variants(\n \"relative inline-flex items-center justify-center gap-1.5 whitespace-nowrap font-medium tracking-[-0.01em] select-none transition-[background-color,border-color,color,box-shadow,opacity] duration-150 ease-out disabled:pointer-events-none disabled:opacity-45 [&_svg]:shrink-0 [&_svg]:opacity-90\",\n {\n variants: {\n variant: {\n // .btn-solid: in dark a disabled primary/accent takes the solid --kit-disabled-bg / --kit-disabled-fg pair; light keeps the opacity dim.\n primary: \"bg-kit-inverse text-kit-fg-inverse shadow-kit-button-primary hover:bg-kit-inverse-hover active:bg-kit-inverse btn-solid\",\n accent: \"bg-kit-accent text-kit-accent-on shadow-kit-xs hover:bg-kit-accent-hover btn-solid\",\n secondary: \"border border-kit-line-strong bg-kit-control-bg text-kit-fg shadow-kit-xs hover:bg-kit-subtle active:bg-kit-hover\",\n ghost: \"text-kit-fg-2 hover:bg-kit-hover hover:text-kit-fg active:bg-kit-selected\",\n soft: \"bg-kit-muted text-kit-fg hover:bg-kit-selected\",\n danger: \"bg-kit-danger text-kit-danger-on shadow-kit-xs hover:brightness-95\",\n \"danger-ghost\": \"text-kit-danger-fg hover:bg-kit-danger-soft\",\n link: \"text-kit-accent-fg underline-offset-4 hover:underline px-0 h-auto active:scale-100\",\n ai: \"border border-kit-line bg-kit-control-bg text-kit-fg shadow-kit-xs hover:border-kit-accent-line hover:bg-kit-accent-softer\",\n },\n size: {\n xs: \"h-6 rounded-kit-md px-2 text-kit-xs [&_svg]:size-3.5\",\n sm: \"h-7 rounded-kit-md px-2.5 text-kit-sm [&_svg]:size-3.5\",\n md: \"h-8 rounded-kit-md px-3 text-kit-sm [&_svg]:size-4\",\n lg: \"h-9 rounded-kit-md px-3.5 text-kit-base [&_svg]:size-4\",\n xl: \"h-10 rounded-kit-md px-4 text-kit-base [&_svg]:size-[18px]\",\n },\n },\n compoundVariants: [{ variant: \"link\", className: \"h-auto px-0\" }],\n defaultVariants: { variant: \"secondary\", size: \"md\" },\n },\n);\n\nexport interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement>, VariantProps<typeof buttonVariants> {\n /** Render the single child element (a link, say) with the button's classes and props. */\n asChild?: boolean;\n loading?: boolean;\n leftIcon?: React.ReactNode;\n rightIcon?: React.ReactNode;\n}\n\ntype ChildProps = { className?: string; ref?: React.Ref<unknown> };\n\nfunction mergeRefs<T>(...refs: (React.Ref<T> | undefined)[]) {\n return (node: T | null) => {\n for (const ref of refs) {\n if (typeof ref === \"function\") ref(node);\n else if (ref) (ref as React.RefObject<T | null>).current = node;\n }\n };\n}\n\nexport const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(\n ({ className, variant, size, asChild, loading, leftIcon, rightIcon, children, disabled, ...props }, ref) => {\n const classes = cn(buttonVariants({ variant, size }), className);\n if (asChild && React.isValidElement<ChildProps>(children)) {\n return React.cloneElement(children, {\n ...props,\n ...children.props,\n className: cn(classes, children.props.className),\n ref: mergeRefs(ref as React.Ref<unknown>, children.props.ref),\n });\n }\n return (\n <button ref={ref} type={props.type ?? \"button\"} disabled={disabled || loading} aria-busy={loading || undefined} className={classes} {...props}>\n {/* the kit Spinner (decorative: the button says it is busy); the size variant's [&_svg] rule sizes its glyph */}\n {loading ? <Spinner /> : leftIcon}\n {variant === \"ai\" && !leftIcon && !loading ? <Sparkle /> : null}\n {children}\n {rightIcon}\n </button>\n );\n },\n);\nButton.displayName = \"Button\";\n\n/** Square icon-only button. Always pass `label` (used for aria-label + tooltip). */\nexport const iconButtonVariants = variants(\n \"relative inline-flex items-center justify-center shrink-0 text-kit-fg-2 transition-colors duration-150 hover:bg-kit-hover hover:text-kit-fg active:scale-[0.96] disabled:opacity-40 disabled:pointer-events-none data-[active=true]:bg-kit-selected data-[active=true]:text-kit-fg\",\n {\n variants: {\n size: {\n xs: \"size-6 rounded-kit-md [&_svg]:size-3.5\",\n sm: \"size-7 rounded-kit-md [&_svg]:size-4\",\n md: \"size-8 rounded-kit-md [&_svg]:size-4\",\n lg: \"size-9 rounded-kit-md [&_svg]:size-[18px]\",\n },\n variant: {\n ghost: \"\",\n outline: \"border border-kit-line bg-kit-control-bg shadow-kit-xs hover:border-kit-line-strong\",\n soft: \"bg-kit-muted\",\n },\n },\n defaultVariants: { size: \"md\", variant: \"ghost\" },\n },\n);\n\n/**\n * a11y: true while rendering inside a tooltip (or a surface that manages its own hints), so an IconButton nested\n * there doesn't add a second tooltip. Provided by HintTooltip and overlay.tsx's <Tooltip>.\n */\nexport const TooltipScope = React.createContext(false);\n\n/**\n * The plain ink hint (DESIGN.md 8.23: top, 6px offset, 8px collision padding, portalled, z 90, 350ms). The child\n * element is the trigger and must take a ref and DOM props. input, display and action-tray use it so they never\n * import overlay.tsx; overlay's <Tooltip> adds the shortcut slot on top of the same layer.\n */\nexport function HintTooltip({\n content,\n side = \"top\",\n delay = 350,\n children,\n}: {\n content: React.ReactNode;\n side?: \"top\" | \"bottom\" | \"left\" | \"right\";\n delay?: number;\n children: React.ReactElement;\n}) {\n return (\n <TooltipScope.Provider value>\n <TooltipRoot>\n <TooltipPrimitive.Trigger delay={delay} render={children} />\n <TooltipLayer side={side}>\n <span className=\"line-clamp-[8] min-w-0 whitespace-normal [overflow-wrap:anywhere]\">{content}</span>\n </TooltipLayer>\n </TooltipRoot>\n </TooltipScope.Provider>\n );\n}\n\nexport interface IconButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement>, VariantProps<typeof iconButtonVariants> {\n label: string;\n active?: boolean;\n /** Hover/focus hint. Defaults to `label`; pass `false` to opt out, or a node to customise. */\n tooltip?: React.ReactNode | false;\n tooltipSide?: \"top\" | \"bottom\" | \"left\" | \"right\";\n}\n\nexport const IconButton = React.forwardRef<HTMLButtonElement, IconButtonProps>(\n ({ className, size, variant, label, active, children, tooltip, tooltipSide = \"top\", ...props }, ref) => {\n const inTooltip = React.useContext(TooltipScope);\n const btn = (\n <button\n ref={ref}\n type=\"button\"\n aria-label={label}\n data-active={active ? \"true\" : undefined}\n className={cn(iconButtonVariants({ size, variant }), className)}\n {...props}\n >\n {children}\n </button>\n );\n // Every icon-only button gets a visible hint on hover AND keyboard focus (brief §11), unless a\n // parent tooltip already provides one or the caller opted out.\n if (inTooltip || tooltip === false || !label) return btn;\n return (\n <HintTooltip content={tooltip ?? label} side={tooltipSide}>\n {btn}\n </HintTooltip>\n );\n },\n);\nIconButton.displayName = \"IconButton\";\n\n/** The AI sparkle in the official brand gradient. Used everywhere AI appears. */\nexport function Sparkle({ className, size = 16 }: { className?: string; size?: number }) {\n const id = React.useId().replace(/:/g, \"\");\n return (\n <svg width={size} height={size} viewBox=\"2 2 16 16\" className={cn(\"shrink-0\", className)} aria-hidden>\n <defs>\n <linearGradient id={`sp${id}`} x1=\"6.89\" y1=\"4.59\" x2=\"18\" y2=\"23.67\" gradientUnits=\"userSpaceOnUse\">\n <stop offset=\"0.0817\" style={{ stopColor: \"var(--kit-brand-violet)\" }} />\n <stop offset=\"0.4667\" style={{ stopColor: \"var(--kit-brand-coral)\" }} />\n <stop offset=\"1\" style={{ stopColor: \"var(--kit-brand-rose)\" }} />\n </linearGradient>\n </defs>\n <path d={SPARKLE_PATH} fill={`url(#sp${id})`} />\n </svg>\n );\n}\n\n/** D15 progressive disclosure: \"+ Add a message\" / \"+ Limit to specific sites\": reveals an optional input. */\nexport function RevealLink({ className, children, ...props }: React.ButtonHTMLAttributes<HTMLButtonElement>) {\n return (\n <button\n type=\"button\"\n className={cn(\n \"inline-flex h-7 items-center gap-1 rounded-kit-md text-kit-sm font-medium text-kit-fg-2 transition-colors hover:text-kit-fg [&_svg]:size-3.5\",\n className,\n )}\n {...props}\n >\n <IconPlus stroke={2} aria-hidden />\n {children}\n </button>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAgBA,IAAa,iBAAiB,SAC5B,wSACA;CACE,UAAU;EACR,SAAS;GAEP,SAAS;GACT,QAAQ;GACR,WAAW;GACX,OAAO;GACP,MAAM;GACN,QAAQ;GACR,gBAAgB;GAChB,MAAM;GACN,IAAI;EACN;EACA,MAAM;GACJ,IAAI;GACJ,IAAI;GACJ,IAAI;GACJ,IAAI;GACJ,IAAI;EACN;CACF;CACA,kBAAkB,CAAC;EAAE,SAAS;EAAQ,WAAW;CAAc,CAAC;CA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