@omer-x/tailwind-ui-kit 1.0.0-alpha.32 → 1.0.0-alpha.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +110 -0
- package/dist/components/dialog/BaseDialogPopup.js +2 -15
- package/dist/components/form/BaseAutocomplete.d.ts +198 -0
- package/dist/components/form/BaseAutocomplete.js +49 -0
- package/dist/components/form/BaseAutocompleteClear.d.ts +18 -0
- package/dist/components/form/BaseAutocompleteClear.js +7 -0
- package/dist/components/form/BaseAutocompleteCollection.d.ts +8 -0
- package/dist/components/form/BaseAutocompleteCollection.js +7 -0
- package/dist/components/form/BaseAutocompleteEmpty.d.ts +11 -0
- package/dist/components/form/BaseAutocompleteEmpty.js +10 -0
- package/dist/components/form/BaseAutocompleteGroup.d.ts +10 -0
- package/dist/components/form/BaseAutocompleteGroup.js +7 -0
- package/dist/components/form/BaseAutocompleteGroupLabel.d.ts +8 -0
- package/dist/components/form/BaseAutocompleteGroupLabel.js +7 -0
- package/dist/components/form/BaseAutocompleteIcon.d.ts +8 -0
- package/dist/components/form/BaseAutocompleteIcon.js +7 -0
- package/dist/components/form/BaseAutocompleteInput.d.ts +12 -0
- package/dist/components/form/BaseAutocompleteInput.js +12 -0
- package/dist/components/form/BaseAutocompleteInputGroup.d.ts +9 -0
- package/dist/components/form/BaseAutocompleteInputGroup.js +11 -0
- package/dist/components/form/BaseAutocompleteItem.d.ts +20 -0
- package/dist/components/form/BaseAutocompleteItem.js +11 -0
- package/dist/components/form/BaseAutocompleteList.d.ts +14 -0
- package/dist/components/form/BaseAutocompleteList.js +11 -0
- package/dist/components/form/BaseAutocompletePopup.d.ts +111 -0
- package/dist/components/form/BaseAutocompletePopup.js +45 -0
- package/dist/components/form/BaseAutocompleteRow.d.ts +8 -0
- package/dist/components/form/BaseAutocompleteRow.js +7 -0
- package/dist/components/form/BaseAutocompleteSeparator.d.ts +13 -0
- package/dist/components/form/BaseAutocompleteSeparator.js +7 -0
- package/dist/components/form/BaseAutocompleteStatus.d.ts +11 -0
- package/dist/components/form/BaseAutocompleteStatus.js +10 -0
- package/dist/components/form/BaseAutocompleteTrigger.d.ts +11 -0
- package/dist/components/form/BaseAutocompleteTrigger.js +7 -0
- package/dist/components/form/BaseAutocompleteValue.d.ts +8 -0
- package/dist/components/form/BaseAutocompleteValue.js +7 -0
- package/dist/components/form/BaseFormField.d.ts +10 -1
- package/dist/components/form/BaseFormField.js +2 -2
- package/dist/components/form/BaseInput.d.ts +2 -1
- package/dist/components/form/BaseInput.js +2 -12
- package/dist/components/form/autocompleteTypes.d.ts +16 -0
- package/dist/components/form/autocompleteTypes.js +1 -0
- package/dist/components/form/index.d.ts +11 -2
- package/dist/components/form/index.js +3 -1
- package/dist/components/form/inputSizes.d.ts +11 -0
- package/dist/components/form/inputSizes.js +19 -0
- package/dist/components/form/useAutocompleteFilter.d.ts +19 -0
- package/dist/components/form/useAutocompleteFilter.js +12 -0
- package/dist/utils/split-class-name.d.ts +15 -0
- package/dist/utils/split-class-name.js +18 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -337,6 +337,7 @@ A Base UI [`Field`](https://base-ui.com/react/components/field) made of a label,
|
|
|
337
337
|
| `schema` | `ZodType` | Source of the HTML constraints applied to the control |
|
|
338
338
|
| `label` | `string` | Label text. No label is rendered when omitted |
|
|
339
339
|
| `control` | `RenderProp<"input", FieldState>` | The input to render, as Base UI's `Field.Control` (so it gets `aria-invalid`, `data-invalid`, … and is validated). Defaults to a plain `<input>`. Pass your themed input here |
|
|
340
|
+
| `children` | `(constraints: FieldConstraints) => ReactNode` | Renders a control that isn't a single `<input>` (e.g. [`BaseAutocomplete`](#baseautocomplete)) instead of `control`. Gets the constraints read from `schema` (`required`, `minLength`, …); pass on the ones the control supports. The control takes the field's `name` by itself |
|
|
340
341
|
| `renderLabel` | `RenderProp<"label", FieldState>` | Style the label |
|
|
341
342
|
| `renderErrors` | `RenderProp<"div", FieldState>` | Style client-side and server-side error messages. Each error is its own element |
|
|
342
343
|
| `className` | `string` | Classes for the field root (a flex column by default) |
|
|
@@ -372,6 +373,115 @@ export const UserSchema = z.object({
|
|
|
372
373
|
|
|
373
374
|
The browser can check only the rules that map to HTML attributes (`required`, `minLength`, `maxLength`, `min`, `max`, …). Refinements, transforms, cross-field rules and async checks such as "username taken" only run on the server, and come back as `fieldErrors`. Users can also bypass browser checks, so **the server action must always validate the full schema**. The client constraints only give earlier feedback.
|
|
374
375
|
|
|
376
|
+
#### `BaseAutocomplete`
|
|
377
|
+
|
|
378
|
+
A Base UI [`Autocomplete`](https://base-ui.com/react/components/autocomplete): a text input that suggests matching items as you type. The input is free text; choosing an item fills it in. A simple one needs no more than this:
|
|
379
|
+
|
|
380
|
+
```tsx
|
|
381
|
+
import { BaseAutocomplete } from "@omer-x/tailwind-ui-kit/form";
|
|
382
|
+
|
|
383
|
+
<BaseAutocomplete items={fruits}>
|
|
384
|
+
<BaseAutocomplete.Input aria-label="Fruit" className="border border-neutral-300" />
|
|
385
|
+
<BaseAutocomplete.Popup sideOffset={4} className="rounded-md bg-white py-1 shadow-lg">
|
|
386
|
+
<BaseAutocomplete.Empty className="px-3 not-empty:py-1.5">No fruits found</BaseAutocomplete.Empty>
|
|
387
|
+
<BaseAutocomplete.List>
|
|
388
|
+
{(fruit: string) => (
|
|
389
|
+
<BaseAutocomplete.Item key={fruit} value={fruit} className="px-3 py-1.5 data-highlighted:bg-blue-600">
|
|
390
|
+
{fruit}
|
|
391
|
+
</BaseAutocomplete.Item>
|
|
392
|
+
)}
|
|
393
|
+
</BaseAutocomplete.List>
|
|
394
|
+
</BaseAutocomplete.Popup>
|
|
395
|
+
</BaseAutocomplete>
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
The parts are reached with dot notation, which only works in client components. Build autocompletes in a `"use client"` file, e.g. your app's themed wrapper.
|
|
399
|
+
|
|
400
|
+
| Part | Renders | Description |
|
|
401
|
+
|------|---------|-------------|
|
|
402
|
+
| `BaseAutocomplete` | nothing | Groups the parts, holds the input's value and filters `items` |
|
|
403
|
+
| `.Input` | `<input>` | The text input. Takes `size` (`"lg" \| "md" \| "sm" \| "xs"`, default `"md"`), the same sizes as `BaseInput` |
|
|
404
|
+
| `.InputGroup` | `<div>` | Optional. Wraps the input with a trigger and a clear button (`relative flex items-center`). The popup is placed against it |
|
|
405
|
+
| `.Trigger` | `<button>` | Opens the popup. `data-popup-open` while it's open |
|
|
406
|
+
| `.Icon` | `<span>` | A decorative icon, hidden from assistive technology. Bring your own icon as children |
|
|
407
|
+
| `.Clear` | `<button>` | Clears the input. Only rendered while the input has a value (`keepMounted` keeps it) |
|
|
408
|
+
| `.Value` | nothing | The input's value, or a function of it, anywhere inside the root |
|
|
409
|
+
| `.Popup` | `<div>` | The floating container, portaled and positioned. As wide as the input, never taller than the space left (max `24rem`), with scale and fade transitions |
|
|
410
|
+
| `.Status` | `<div>` | A live region for screen readers ("Loading…", "12 results") |
|
|
411
|
+
| `.Empty` | `<div>` | Its children show only when no item matches. Always rendered (it's a live region): style it with `not-empty:` / `empty:` |
|
|
412
|
+
| `.List` | `<div>` | The scrollable list. Children can be a function that renders each filtered item (or group). `data-empty` when nothing matches |
|
|
413
|
+
| `.Item` | `<div>` | An option (`flex items-center gap-2`). `value` is the item. `data-highlighted`, `data-disabled` |
|
|
414
|
+
| `.Group` | `<div>` | A group of items. Pass the group's `items` to use `.Collection` inside |
|
|
415
|
+
| `.GroupLabel` | `<div>` | Names a group |
|
|
416
|
+
| `.Collection` | nothing | Renders the filtered items of the surrounding group with a function |
|
|
417
|
+
| `.Separator` | `<div>` | A `role="separator"` line, with `data-orientation` |
|
|
418
|
+
| `.Row` | `<div>` | A row of items when the root has `grid` |
|
|
419
|
+
|
|
420
|
+
Every part takes `className` and a `render` prop. Render functions get the part's state (`AutocompleteInputState`, `AutocompleteItemState`, `AutocompletePopupState`, …), which is also set as data attributes: `data-open`, `data-popup-side`, `data-list-empty`, `data-highlighted`, `data-side`, `data-align`, `data-starting-style`, … The input, input group and trigger also carry the field's state (`data-invalid`, `data-dirty`, `data-touched`, `data-filled`, `data-focused`).
|
|
421
|
+
|
|
422
|
+
`BaseAutocomplete` props:
|
|
423
|
+
|
|
424
|
+
| Prop | Type | Description |
|
|
425
|
+
|------|------|-------------|
|
|
426
|
+
| `items` | `Item[] \| { items: Item[] }[]` | The items, flat or in groups. Filtered by the input's value and passed to `List`'s function children |
|
|
427
|
+
| `filteredItems` | same as `items` | Items you filtered yourself, shown instead |
|
|
428
|
+
| `filter` | `(item, query, itemToString?) => boolean \| null` | Decides what matches. `null` turns filtering off. Defaults to a case-insensitive "contains" |
|
|
429
|
+
| `limit` | `number` | Shows at most this many matches |
|
|
430
|
+
| `mode` | `"list" \| "both" \| "inline" \| "none"` | `list` (default) filters; `both` also fills the input with the highlighted item; `inline` only fills; `none` does neither |
|
|
431
|
+
| `itemToStringValue` | `(item) => string` | Text of an object item. `{ value, label }` objects use `label` without it |
|
|
432
|
+
| `value` / `defaultValue` | `string` | The input's value, controlled / uncontrolled |
|
|
433
|
+
| `onValueChange` | `(value, event) => void` | Called with the new value and the DOM event (none when changed from code) |
|
|
434
|
+
| `open` / `defaultOpen` | `boolean` | The popup's state |
|
|
435
|
+
| `onOpenChange` | `(open, event) => void` | Called with the new state and the DOM event |
|
|
436
|
+
| `onOpenChangeComplete` | `(open) => void` | Called after the transition ends |
|
|
437
|
+
| `openOnInputClick` | `boolean` | Opens the popup on click |
|
|
438
|
+
| `autoHighlight` | `boolean \| "always"` | Highlights the first match while typing (`"always"`: also on open) |
|
|
439
|
+
| `keepHighlight` | `boolean` | Keeps the highlight when the pointer leaves the list |
|
|
440
|
+
| `highlightItemOnHover` | `boolean` | Default `true`. `false` lets `:hover` and `data-highlighted` differ |
|
|
441
|
+
| `onItemHighlighted` | `(item, { reason, index }) => void` | `reason` is `"keyboard"`, `"pointer"` or `"none"` |
|
|
442
|
+
| `loopFocus` | `boolean` | Default `true`. Arrow keys wrap around the list |
|
|
443
|
+
| `submitOnItemClick` | `boolean` | Submits the form when an item is chosen (e.g. a search box) |
|
|
444
|
+
| `grid` | `boolean` | Items in `Row`s, navigated with all four arrow keys |
|
|
445
|
+
| `inline` | `boolean` | Renders the list in place, without a popup. Use with `open` |
|
|
446
|
+
| `modal` | `boolean` | Locks page scroll and outside pointer input while open |
|
|
447
|
+
| `virtualized` | `boolean` | For lists rendered by a virtualizer (give each item its `index`) |
|
|
448
|
+
| `locale` | `Intl.LocalesArgument` | Locale of the default filter |
|
|
449
|
+
| `name`, `form`, `id`, `required`, `disabled`, `readOnly` | | Form props. Inside `BaseFormField`, the field's `name` is used |
|
|
450
|
+
| `inputRef` | `Ref<HTMLInputElement>` | The hidden input used for validation |
|
|
451
|
+
| `actionsRef` | `RefObject<AutocompleteActions>` | `actionsRef.current?.close()` |
|
|
452
|
+
|
|
453
|
+
`BaseAutocomplete.Popup` props, besides `<div>` props:
|
|
454
|
+
|
|
455
|
+
| Prop | Description |
|
|
456
|
+
|------|-------------|
|
|
457
|
+
| `side`, `align` | Placement against the input (group). Default `"bottom"`, `"start"` |
|
|
458
|
+
| `sideOffset`, `alignOffset` | Offsets in pixels, or a function of the placement and sizes |
|
|
459
|
+
| `anchor`, `positionMethod`, `collisionBoundary`, `collisionPadding`, `collisionAvoidance`, `sticky`, `disableAnchorTracking` | Positioning control |
|
|
460
|
+
| `renderPositioner` | Replaces the element that positions the popup, e.g. `<div className="z-50" />` |
|
|
461
|
+
| `container`, `keepMounted` | Portal target (default `<body>`), and keeping the popup in the DOM while closed |
|
|
462
|
+
| `backdrop`, `renderBackdrop` | Renders a `fixed inset-0` backdrop (off by default, use it with `modal`) |
|
|
463
|
+
| `arrow`, `renderArrow`, `arrowPadding` | An arrow pointing at the input. Rendered when `arrow` (its content, e.g. an `<svg>`) or `renderArrow` is given |
|
|
464
|
+
| `finalFocus` | The element focused when the popup closes |
|
|
465
|
+
|
|
466
|
+
**Your own filtering.** `useAutocompleteFilter(options?)` returns locale-aware matchers (`contains`, `startsWith`, `endsWith`, accent- and case-insensitive by default). Pass one as `filter`, or filter items yourself and pass `filteredItems`:
|
|
467
|
+
|
|
468
|
+
```tsx
|
|
469
|
+
const filter = useAutocompleteFilter();
|
|
470
|
+
<BaseAutocomplete items={fruits} filter={filter.startsWith}>…</BaseAutocomplete>
|
|
471
|
+
```
|
|
472
|
+
|
|
473
|
+
**In a form.** Put it in `BaseFormField`'s `children`. The field gives it its `name`, label, validation, server errors and `data-invalid`, and `onlyDirty` sees its value. Only `required` is checked in the browser; other schema rules are checked by the server:
|
|
474
|
+
|
|
475
|
+
```tsx
|
|
476
|
+
<BaseFormField name="fruit" label="Fruit" schema={Schema.shape.fruit}>
|
|
477
|
+
{constraints => (
|
|
478
|
+
<BaseAutocomplete items={fruits} required={constraints.required}>
|
|
479
|
+
…
|
|
480
|
+
</BaseAutocomplete>
|
|
481
|
+
)}
|
|
482
|
+
</BaseFormField>
|
|
483
|
+
```
|
|
484
|
+
|
|
375
485
|
### `@omer-x/tailwind-ui-kit/dialog`
|
|
376
486
|
|
|
377
487
|
#### `BaseDialog`
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { Dialog } from "@base-ui/react/dialog";
|
|
3
3
|
import { cn } from "cn";
|
|
4
|
-
import
|
|
4
|
+
import "react";
|
|
5
|
+
import { splitClassName } from "../../utils/split-class-name.js";
|
|
5
6
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
7
|
// src/components/dialog/BaseDialogPopup.tsx
|
|
7
8
|
const sizes = {
|
|
@@ -10,20 +11,6 @@ const sizes = {
|
|
|
10
11
|
md: "w-96",
|
|
11
12
|
lg: "w-lg"
|
|
12
13
|
};
|
|
13
|
-
/**
|
|
14
|
-
* Base UI only joins the `className` of a `render` element with the part's own, so conflicting
|
|
15
|
-
* Tailwind classes would win by their order in the CSS. Moves it into `cn` instead, last so it wins (#14).
|
|
16
|
-
*/
|
|
17
|
-
function splitClassName(render) {
|
|
18
|
-
if (!isValidElement(render) || !render.props.className) return {
|
|
19
|
-
render,
|
|
20
|
-
className: void 0
|
|
21
|
-
};
|
|
22
|
-
return {
|
|
23
|
-
render: cloneElement(render, { className: void 0 }),
|
|
24
|
-
className: render.props.className
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
14
|
/** The dialog's window, with its portal and backdrop. Renders a `<div>`. */
|
|
28
15
|
const BaseDialogPopup = ({ size = "md", container, keepMounted, backdrop = true, renderBackdrop, className, ...otherProps }) => {
|
|
29
16
|
const backdropElement = splitClassName(renderBackdrop);
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { RenderProp } from "../../utils/render.js";
|
|
2
|
+
import { AutocompleteAlign, AutocompleteInputState, AutocompleteSide } from "./autocompleteTypes.js";
|
|
3
|
+
import "../../utils/index.js";
|
|
4
|
+
import { InputSize } from "./inputSizes.js";
|
|
5
|
+
import { AutocompleteClearState } from "./BaseAutocompleteClear.js";
|
|
6
|
+
import { AutocompleteArrowState, AutocompleteBackdropState, AutocompleteCollisionAvoidance, AutocompleteFocusTarget, AutocompleteOffsetFunction, AutocompletePopupState, AutocompletePositionerState } from "./BaseAutocompletePopup.js";
|
|
7
|
+
import { AutocompleteListState } from "./BaseAutocompleteList.js";
|
|
8
|
+
import { AutocompleteItemState } from "./BaseAutocompleteItem.js";
|
|
9
|
+
import { AutocompleteSeparatorState } from "./BaseAutocompleteSeparator.js";
|
|
10
|
+
import { ReactNode, Ref, RefObject } from "react";
|
|
11
|
+
/** A group of items in `items`: any object with an `items` array, e.g. `{ label: "Fruits", items: [...] }`. */
|
|
12
|
+
export type AutocompleteItemGroup<Item> = {
|
|
13
|
+
items: readonly Item[];
|
|
14
|
+
};
|
|
15
|
+
/** Imperative actions, through `actionsRef`. */
|
|
16
|
+
export type AutocompleteActions = {
|
|
17
|
+
/** Closes the popup. */
|
|
18
|
+
close: () => void;
|
|
19
|
+
};
|
|
20
|
+
/** Why the highlighted item changed: arrow keys, the pointer, or anything else (typing, `autoHighlight`, …). */
|
|
21
|
+
export type AutocompleteHighlightReason = "keyboard" | "pointer" | "none";
|
|
22
|
+
type BaseAutocompleteProps<Item> = {
|
|
23
|
+
/**
|
|
24
|
+
* The items, flat or in groups. They're filtered by the input's value and passed to the
|
|
25
|
+
* function children of `List` (and of `Collection` in groups).
|
|
26
|
+
*/
|
|
27
|
+
items?: readonly Item[] | readonly AutocompleteItemGroup<Item>[];
|
|
28
|
+
/**
|
|
29
|
+
* Items you filtered yourself (e.g. with `useAutocompleteFilter`), shown instead of filtering `items`.
|
|
30
|
+
* Keep the same flat or grouped shape.
|
|
31
|
+
*/
|
|
32
|
+
filteredItems?: readonly Item[] | readonly AutocompleteItemGroup<Item>[];
|
|
33
|
+
/** Decides whether an item matches the query. `null` turns filtering off. Defaults to a case-insensitive "contains". */
|
|
34
|
+
filter?: ((item: Item, query: string, itemToString?: (item: Item) => string) => boolean) | null;
|
|
35
|
+
/** Shows at most this many matching items. @default -1 (no limit) */
|
|
36
|
+
limit?: number;
|
|
37
|
+
/**
|
|
38
|
+
* - `list`: items are filtered by the input's value.
|
|
39
|
+
* - `both`: filtered, and the highlighted item fills the input temporarily (inline completion).
|
|
40
|
+
* - `inline`: not filtered, with inline completion.
|
|
41
|
+
* - `none`: not filtered, without inline completion.
|
|
42
|
+
* @default "list"
|
|
43
|
+
*/
|
|
44
|
+
mode?: "list" | "both" | "inline" | "none";
|
|
45
|
+
/**
|
|
46
|
+
* Turns an object item into the text put in the input and submitted.
|
|
47
|
+
* `{ value, label }` objects use their `label` without it.
|
|
48
|
+
*/
|
|
49
|
+
itemToStringValue?: (item: Item) => string;
|
|
50
|
+
/** The input's value, controlled. */
|
|
51
|
+
value?: string;
|
|
52
|
+
/** The input's initial value, uncontrolled. */
|
|
53
|
+
defaultValue?: string;
|
|
54
|
+
/** Called with the new value and the DOM event that changed it (none when it was changed from code). */
|
|
55
|
+
onValueChange?: (value: string, event: Event | undefined) => void;
|
|
56
|
+
open?: boolean;
|
|
57
|
+
defaultOpen?: boolean;
|
|
58
|
+
/** Called with the new state and the DOM event that changed it (none when it was changed from code). */
|
|
59
|
+
onOpenChange?: (open: boolean, event: Event | undefined) => void;
|
|
60
|
+
/** Called after the open or close transition ends. */
|
|
61
|
+
onOpenChangeComplete?: (open: boolean) => void;
|
|
62
|
+
/** Opens the popup when the input is clicked. */
|
|
63
|
+
openOnInputClick?: boolean;
|
|
64
|
+
/** Highlights the first match while typing, or `"always"` (also when the popup opens). */
|
|
65
|
+
autoHighlight?: boolean | "always";
|
|
66
|
+
/** Keeps the highlight when the pointer leaves the list. */
|
|
67
|
+
keepHighlight?: boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Set to `false` to stop the pointer from highlighting items, so `:hover` and `data-highlighted` can differ.
|
|
70
|
+
* @default true
|
|
71
|
+
*/
|
|
72
|
+
highlightItemOnHover?: boolean;
|
|
73
|
+
/** Called when an item is highlighted, or with `undefined` when none is. */
|
|
74
|
+
onItemHighlighted?: (item: Item | undefined, details: {
|
|
75
|
+
reason: AutocompleteHighlightReason;
|
|
76
|
+
index: number;
|
|
77
|
+
}) => void;
|
|
78
|
+
/** Wraps keyboard navigation from the last item to the first and back. @default true */
|
|
79
|
+
loopFocus?: boolean;
|
|
80
|
+
/** Submits the form when an item is chosen, e.g. for a search box. */
|
|
81
|
+
submitOnItemClick?: boolean;
|
|
82
|
+
/** Lays items out in `Row`s, navigated with all four arrow keys. */
|
|
83
|
+
grid?: boolean;
|
|
84
|
+
/** Renders the list in place, without the popup. Use it with `open`. */
|
|
85
|
+
inline?: boolean;
|
|
86
|
+
/** Locks page scroll and blocks outside pointer input while open. */
|
|
87
|
+
modal?: boolean;
|
|
88
|
+
/** Set when the list is rendered by a virtualizer, with each item's `index`. */
|
|
89
|
+
virtualized?: boolean;
|
|
90
|
+
/** The locale used by the default filter. Defaults to the user's locale. */
|
|
91
|
+
locale?: Intl.LocalesArgument;
|
|
92
|
+
/** The input's `name`. Inside a `BaseFormField`, the field's name is used. */
|
|
93
|
+
name?: string;
|
|
94
|
+
/** The `id` of a `<form>` to submit with, when the autocomplete isn't inside it. */
|
|
95
|
+
form?: string;
|
|
96
|
+
/** The `id` of the input. */
|
|
97
|
+
id?: string;
|
|
98
|
+
required?: boolean;
|
|
99
|
+
disabled?: boolean;
|
|
100
|
+
readOnly?: boolean;
|
|
101
|
+
/** A ref to the hidden `<input>` used for validation. */
|
|
102
|
+
inputRef?: Ref<HTMLInputElement>;
|
|
103
|
+
/** Imperative actions, e.g. `actionsRef.current?.close()`. */
|
|
104
|
+
actionsRef?: RefObject<AutocompleteActions | null>;
|
|
105
|
+
children?: ReactNode;
|
|
106
|
+
};
|
|
107
|
+
declare const _default: (<Item>({ onValueChange, onOpenChange, onItemHighlighted, ...otherProps }: BaseAutocompleteProps<Item>) => import("react").JSX.Element) & {
|
|
108
|
+
InputGroup: ({ className, ...otherProps }: import("react").ClassAttributes<HTMLDivElement> & import("react").HTMLAttributes<HTMLDivElement> & {
|
|
109
|
+
render?: RenderProp<"div", AutocompleteInputState>;
|
|
110
|
+
}) => import("react").JSX.Element;
|
|
111
|
+
Input: ({ size, className, ...otherProps }: Omit<import("react").DetailedHTMLProps<import("react").InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, "defaultValue" | "value" | "size"> & {
|
|
112
|
+
size?: InputSize;
|
|
113
|
+
render?: RenderProp<"input", AutocompleteInputState>;
|
|
114
|
+
}) => import("react").JSX.Element;
|
|
115
|
+
Trigger: (props: import("react").ClassAttributes<HTMLButtonElement> & import("react").ButtonHTMLAttributes<HTMLButtonElement> & {
|
|
116
|
+
render?: RenderProp<"button", AutocompleteInputState>;
|
|
117
|
+
nativeButton?: boolean;
|
|
118
|
+
}) => import("react").JSX.Element;
|
|
119
|
+
Icon: (props: import("react").ClassAttributes<HTMLSpanElement> & import("react").HTMLAttributes<HTMLSpanElement> & {
|
|
120
|
+
render?: RenderProp<"span">;
|
|
121
|
+
}) => import("react").JSX.Element;
|
|
122
|
+
Clear: (props: import("react").ClassAttributes<HTMLButtonElement> & import("react").ButtonHTMLAttributes<HTMLButtonElement> & {
|
|
123
|
+
render?: RenderProp<"button", AutocompleteClearState>;
|
|
124
|
+
keepMounted?: boolean;
|
|
125
|
+
nativeButton?: boolean;
|
|
126
|
+
}) => import("react").JSX.Element;
|
|
127
|
+
Value: (props: {
|
|
128
|
+
children?: ReactNode | ((value: string) => ReactNode);
|
|
129
|
+
}) => import("react").JSX.Element;
|
|
130
|
+
Popup: ({ container, keepMounted, anchor, positionMethod, side, sideOffset, align, alignOffset, collisionBoundary, collisionPadding, collisionAvoidance, sticky, arrowPadding, disableAnchorTracking, renderPositioner, backdrop, renderBackdrop, arrow, renderArrow, className, children, ...otherProps }: import("react").ClassAttributes<HTMLDivElement> & import("react").HTMLAttributes<HTMLDivElement> & {
|
|
131
|
+
render?: RenderProp<"div", AutocompletePopupState>;
|
|
132
|
+
finalFocus?: AutocompleteFocusTarget;
|
|
133
|
+
container?: HTMLElement | ShadowRoot | RefObject<HTMLElement | ShadowRoot | null> | null;
|
|
134
|
+
keepMounted?: boolean;
|
|
135
|
+
anchor?: Element | RefObject<Element | null> | (() => Element | null) | null;
|
|
136
|
+
positionMethod?: "absolute" | "fixed";
|
|
137
|
+
side?: AutocompleteSide;
|
|
138
|
+
sideOffset?: number | AutocompleteOffsetFunction;
|
|
139
|
+
align?: AutocompleteAlign;
|
|
140
|
+
alignOffset?: number | AutocompleteOffsetFunction;
|
|
141
|
+
collisionBoundary?: "clipping-ancestors" | Element | Element[] | {
|
|
142
|
+
x: number;
|
|
143
|
+
y: number;
|
|
144
|
+
width: number;
|
|
145
|
+
height: number;
|
|
146
|
+
};
|
|
147
|
+
collisionPadding?: number | {
|
|
148
|
+
top?: number;
|
|
149
|
+
right?: number;
|
|
150
|
+
bottom?: number;
|
|
151
|
+
left? /** Called with the new state and the DOM event that changed it (none when it was changed from code). */ : number;
|
|
152
|
+
};
|
|
153
|
+
collisionAvoidance?: AutocompleteCollisionAvoidance;
|
|
154
|
+
sticky?: boolean;
|
|
155
|
+
arrowPadding?: number;
|
|
156
|
+
disableAnchorTracking?: boolean;
|
|
157
|
+
renderPositioner?: RenderProp<"div", AutocompletePositionerState>;
|
|
158
|
+
backdrop?: boolean;
|
|
159
|
+
renderBackdrop?: RenderProp<"div", AutocompleteBackdropState>;
|
|
160
|
+
arrow?: ReactNode;
|
|
161
|
+
renderArrow?: RenderProp<"div", AutocompleteArrowState>;
|
|
162
|
+
}) => import("react").JSX.Element;
|
|
163
|
+
Status: (props: import("react").ClassAttributes<HTMLDivElement> & import("react").HTMLAttributes<HTMLDivElement> & {
|
|
164
|
+
render?: RenderProp<"div">;
|
|
165
|
+
}) => import("react").JSX.Element;
|
|
166
|
+
Empty: (props: import("react").ClassAttributes<HTMLDivElement> & import("react").HTMLAttributes<HTMLDivElement> & {
|
|
167
|
+
render?: RenderProp<"div">;
|
|
168
|
+
}) => import("react").JSX.Element;
|
|
169
|
+
List: <Item>({ className, ...otherProps }: Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "children"> & {
|
|
170
|
+
render?: RenderProp<"div", AutocompleteListState>;
|
|
171
|
+
children?: ReactNode | ((item: Item, index: number) => ReactNode);
|
|
172
|
+
}) => import("react").JSX.Element;
|
|
173
|
+
Row: (props: import("react").ClassAttributes<HTMLDivElement> & import("react").HTMLAttributes<HTMLDivElement> & {
|
|
174
|
+
render?: RenderProp<"div">;
|
|
175
|
+
}) => import("react").JSX.Element;
|
|
176
|
+
Item: ({ className, ...otherProps }: Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "id"> & {
|
|
177
|
+
render?: RenderProp<"div", AutocompleteItemState>;
|
|
178
|
+
value?: unknown;
|
|
179
|
+
index?: number;
|
|
180
|
+
disabled?: boolean;
|
|
181
|
+
nativeButton?: boolean;
|
|
182
|
+
}) => import("react").JSX.Element;
|
|
183
|
+
Separator: (props: import("react").ClassAttributes<HTMLDivElement> & import("react").HTMLAttributes<HTMLDivElement> & {
|
|
184
|
+
render?: RenderProp<"div", AutocompleteSeparatorState>;
|
|
185
|
+
orientation?: "horizontal" | "vertical";
|
|
186
|
+
}) => import("react").JSX.Element;
|
|
187
|
+
Group: (props: import("react").ClassAttributes<HTMLDivElement> & import("react").HTMLAttributes<HTMLDivElement> & {
|
|
188
|
+
render?: RenderProp<"div">;
|
|
189
|
+
items?: readonly unknown[];
|
|
190
|
+
}) => import("react").JSX.Element;
|
|
191
|
+
GroupLabel: (props: import("react").ClassAttributes<HTMLDivElement> & import("react").HTMLAttributes<HTMLDivElement> & {
|
|
192
|
+
render?: RenderProp<"div">;
|
|
193
|
+
}) => import("react").JSX.Element;
|
|
194
|
+
Collection: <Item>({ children }: {
|
|
195
|
+
children: (item: Item, index: number) => ReactNode;
|
|
196
|
+
}) => import("react").JSX.Element;
|
|
197
|
+
};
|
|
198
|
+
export { _default as default };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Autocomplete } from "@base-ui/react/autocomplete";
|
|
3
|
+
import BaseAutocompleteClear from "./BaseAutocompleteClear.js";
|
|
4
|
+
import BaseAutocompleteCollection from "./BaseAutocompleteCollection.js";
|
|
5
|
+
import BaseAutocompleteEmpty from "./BaseAutocompleteEmpty.js";
|
|
6
|
+
import BaseAutocompleteGroup from "./BaseAutocompleteGroup.js";
|
|
7
|
+
import BaseAutocompleteGroupLabel from "./BaseAutocompleteGroupLabel.js";
|
|
8
|
+
import BaseAutocompleteIcon from "./BaseAutocompleteIcon.js";
|
|
9
|
+
import BaseAutocompleteInput from "./BaseAutocompleteInput.js";
|
|
10
|
+
import BaseAutocompleteInputGroup from "./BaseAutocompleteInputGroup.js";
|
|
11
|
+
import BaseAutocompleteItem from "./BaseAutocompleteItem.js";
|
|
12
|
+
import BaseAutocompleteList from "./BaseAutocompleteList.js";
|
|
13
|
+
import BaseAutocompletePopup from "./BaseAutocompletePopup.js";
|
|
14
|
+
import BaseAutocompleteRow from "./BaseAutocompleteRow.js";
|
|
15
|
+
import BaseAutocompleteSeparator from "./BaseAutocompleteSeparator.js";
|
|
16
|
+
import BaseAutocompleteStatus from "./BaseAutocompleteStatus.js";
|
|
17
|
+
import BaseAutocompleteTrigger from "./BaseAutocompleteTrigger.js";
|
|
18
|
+
import BaseAutocompleteValue from "./BaseAutocompleteValue.js";
|
|
19
|
+
import { jsx } from "react/jsx-runtime";
|
|
20
|
+
// src/components/form/BaseAutocomplete.tsx
|
|
21
|
+
/** Groups the parts of an autocomplete and holds its value. Renders no element. */
|
|
22
|
+
const BaseAutocomplete = ({ onValueChange, onOpenChange, onItemHighlighted, ...otherProps }) => /* @__PURE__ */ jsx(Autocomplete.Root, {
|
|
23
|
+
...otherProps,
|
|
24
|
+
onValueChange: onValueChange && ((value, details) => onValueChange(value, details.event)),
|
|
25
|
+
onOpenChange: onOpenChange && ((open, details) => onOpenChange(open, details.event)),
|
|
26
|
+
onItemHighlighted: onItemHighlighted && ((item, details) => onItemHighlighted(item, {
|
|
27
|
+
reason: details.reason,
|
|
28
|
+
index: details.index
|
|
29
|
+
}))
|
|
30
|
+
});
|
|
31
|
+
var BaseAutocomplete_default = Object.assign(BaseAutocomplete, {
|
|
32
|
+
InputGroup: BaseAutocompleteInputGroup,
|
|
33
|
+
Input: BaseAutocompleteInput,
|
|
34
|
+
Trigger: BaseAutocompleteTrigger,
|
|
35
|
+
Icon: BaseAutocompleteIcon,
|
|
36
|
+
Clear: BaseAutocompleteClear,
|
|
37
|
+
Value: BaseAutocompleteValue,
|
|
38
|
+
Popup: BaseAutocompletePopup,
|
|
39
|
+
Status: BaseAutocompleteStatus,
|
|
40
|
+
Empty: BaseAutocompleteEmpty,
|
|
41
|
+
List: BaseAutocompleteList,
|
|
42
|
+
Row: BaseAutocompleteRow,
|
|
43
|
+
Item: BaseAutocompleteItem,
|
|
44
|
+
Separator: BaseAutocompleteSeparator,
|
|
45
|
+
Group: BaseAutocompleteGroup,
|
|
46
|
+
GroupLabel: BaseAutocompleteGroupLabel,
|
|
47
|
+
Collection: BaseAutocompleteCollection
|
|
48
|
+
});
|
|
49
|
+
export { BaseAutocomplete_default as default };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { RenderProp } from "../../utils/render.js";
|
|
2
|
+
import { ComponentProps } from "react";
|
|
3
|
+
export type AutocompleteClearState = {
|
|
4
|
+
open: boolean;
|
|
5
|
+
disabled: boolean;
|
|
6
|
+
/** Whether the input has a value to clear. */
|
|
7
|
+
visible: boolean;
|
|
8
|
+
};
|
|
9
|
+
type BaseAutocompleteClearProps = ComponentProps<"button"> & {
|
|
10
|
+
render?: RenderProp<"button", AutocompleteClearState>;
|
|
11
|
+
/** Keeps the button in the DOM while the input is empty. */
|
|
12
|
+
keepMounted?: boolean;
|
|
13
|
+
/** Set to `false` when `render` doesn't render a `<button>`. */
|
|
14
|
+
nativeButton?: boolean;
|
|
15
|
+
};
|
|
16
|
+
/** A button that clears the input. Renders a `<button>`, only while the input has a value. */
|
|
17
|
+
declare const BaseAutocompleteClear: (props: BaseAutocompleteClearProps) => import("react").JSX.Element;
|
|
18
|
+
export { BaseAutocompleteClear as default };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Autocomplete } from "@base-ui/react/autocomplete";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
// src/components/form/BaseAutocompleteClear.tsx
|
|
5
|
+
/** A button that clears the input. Renders a `<button>`, only while the input has a value. */
|
|
6
|
+
const BaseAutocompleteClear = (props) => /* @__PURE__ */ jsx(Autocomplete.Clear, { ...props });
|
|
7
|
+
export { BaseAutocompleteClear as default };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
|
+
type BaseAutocompleteCollectionProps<Item> = {
|
|
3
|
+
/** Renders each filtered item of the surrounding `Group`'s `items`. */
|
|
4
|
+
children: (item: Item, index: number) => ReactNode;
|
|
5
|
+
};
|
|
6
|
+
/** Renders the filtered items of a group. Renders no element. */
|
|
7
|
+
declare const BaseAutocompleteCollection: <Item>({ children }: BaseAutocompleteCollectionProps<Item>) => import("react").JSX.Element;
|
|
8
|
+
export { BaseAutocompleteCollection as default };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Autocomplete } from "@base-ui/react/autocomplete";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
// src/components/form/BaseAutocompleteCollection.tsx
|
|
5
|
+
/** Renders the filtered items of a group. Renders no element. */
|
|
6
|
+
const BaseAutocompleteCollection = ({ children }) => /* @__PURE__ */ jsx(Autocomplete.Collection, { children });
|
|
7
|
+
export { BaseAutocompleteCollection as default };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { RenderProp } from "../../utils/render.js";
|
|
2
|
+
import { ComponentProps } from "react";
|
|
3
|
+
type BaseAutocompleteEmptyProps = ComponentProps<"div"> & {
|
|
4
|
+
render?: RenderProp<"div">;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Its children are shown only when no item matches. Renders a `<div>` that is always there (it's a
|
|
8
|
+
* live region), so give it spacing with `not-empty:` or remove it with `empty:` variants.
|
|
9
|
+
*/
|
|
10
|
+
declare const BaseAutocompleteEmpty: (props: BaseAutocompleteEmptyProps) => import("react").JSX.Element;
|
|
11
|
+
export { BaseAutocompleteEmpty as default };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Autocomplete } from "@base-ui/react/autocomplete";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
// src/components/form/BaseAutocompleteEmpty.tsx
|
|
5
|
+
/**
|
|
6
|
+
* Its children are shown only when no item matches. Renders a `<div>` that is always there (it's a
|
|
7
|
+
* live region), so give it spacing with `not-empty:` or remove it with `empty:` variants.
|
|
8
|
+
*/
|
|
9
|
+
const BaseAutocompleteEmpty = (props) => /* @__PURE__ */ jsx(Autocomplete.Empty, { ...props });
|
|
10
|
+
export { BaseAutocompleteEmpty as default };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { RenderProp } from "../../utils/render.js";
|
|
2
|
+
import { ComponentProps } from "react";
|
|
3
|
+
type BaseAutocompleteGroupProps = ComponentProps<"div"> & {
|
|
4
|
+
render?: RenderProp<"div">;
|
|
5
|
+
/** The group's filtered items, for `BaseAutocomplete.Collection` inside it. */
|
|
6
|
+
items?: readonly unknown[];
|
|
7
|
+
};
|
|
8
|
+
/** Groups related items under a `GroupLabel`. Renders a `<div>`. */
|
|
9
|
+
declare const BaseAutocompleteGroup: (props: BaseAutocompleteGroupProps) => import("react").JSX.Element;
|
|
10
|
+
export { BaseAutocompleteGroup as default };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Autocomplete } from "@base-ui/react/autocomplete";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
// src/components/form/BaseAutocompleteGroup.tsx
|
|
5
|
+
/** Groups related items under a `GroupLabel`. Renders a `<div>`. */
|
|
6
|
+
const BaseAutocompleteGroup = (props) => /* @__PURE__ */ jsx(Autocomplete.Group, { ...props });
|
|
7
|
+
export { BaseAutocompleteGroup as default };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { RenderProp } from "../../utils/render.js";
|
|
2
|
+
import { ComponentProps } from "react";
|
|
3
|
+
type BaseAutocompleteGroupLabelProps = ComponentProps<"div"> & {
|
|
4
|
+
render?: RenderProp<"div">;
|
|
5
|
+
};
|
|
6
|
+
/** The heading that names a group. Renders a `<div>`. */
|
|
7
|
+
declare const BaseAutocompleteGroupLabel: (props: BaseAutocompleteGroupLabelProps) => import("react").JSX.Element;
|
|
8
|
+
export { BaseAutocompleteGroupLabel as default };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Autocomplete } from "@base-ui/react/autocomplete";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
// src/components/form/BaseAutocompleteGroupLabel.tsx
|
|
5
|
+
/** The heading that names a group. Renders a `<div>`. */
|
|
6
|
+
const BaseAutocompleteGroupLabel = (props) => /* @__PURE__ */ jsx(Autocomplete.GroupLabel, { ...props });
|
|
7
|
+
export { BaseAutocompleteGroupLabel as default };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { RenderProp } from "../../utils/render.js";
|
|
2
|
+
import { ComponentProps } from "react";
|
|
3
|
+
type BaseAutocompleteIconProps = ComponentProps<"span"> & {
|
|
4
|
+
render?: RenderProp<"span">;
|
|
5
|
+
};
|
|
6
|
+
/** A decorative icon, hidden from assistive technology. Renders a `<span>`. Bring your own icon as children. */
|
|
7
|
+
declare const BaseAutocompleteIcon: (props: BaseAutocompleteIconProps) => import("react").JSX.Element;
|
|
8
|
+
export { BaseAutocompleteIcon as default };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Autocomplete } from "@base-ui/react/autocomplete";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
// src/components/form/BaseAutocompleteIcon.tsx
|
|
5
|
+
/** A decorative icon, hidden from assistive technology. Renders a `<span>`. Bring your own icon as children. */
|
|
6
|
+
const BaseAutocompleteIcon = (props) => /* @__PURE__ */ jsx(Autocomplete.Icon, { ...props });
|
|
7
|
+
export { BaseAutocompleteIcon as default };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { InputSize } from "./inputSizes.js";
|
|
2
|
+
import { AutocompleteInputState } from "./autocompleteTypes.js";
|
|
3
|
+
import { RenderProp } from "../../utils/render.js";
|
|
4
|
+
import { ComponentProps } from "react";
|
|
5
|
+
type BaseAutocompleteInputProps = Omit<ComponentProps<"input">, "size" | "value" | "defaultValue"> & {
|
|
6
|
+
/** The same sizes as `BaseInput`. */
|
|
7
|
+
size?: InputSize;
|
|
8
|
+
render?: RenderProp<"input", AutocompleteInputState>;
|
|
9
|
+
};
|
|
10
|
+
/** The text input the user types in. Renders an `<input>`, sized like `BaseInput`. */
|
|
11
|
+
declare const BaseAutocompleteInput: ({ size, className, ...otherProps }: BaseAutocompleteInputProps) => import("react").JSX.Element;
|
|
12
|
+
export { BaseAutocompleteInput as default };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Autocomplete } from "@base-ui/react/autocomplete";
|
|
3
|
+
import { cn } from "cn";
|
|
4
|
+
import { inputBaseClasses, inputSizeClasses } from "./inputSizes.js";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
// src/components/form/BaseAutocompleteInput.tsx
|
|
7
|
+
/** The text input the user types in. Renders an `<input>`, sized like `BaseInput`. */
|
|
8
|
+
const BaseAutocompleteInput = ({ size = "md", className, ...otherProps }) => /* @__PURE__ */ jsx(Autocomplete.Input, {
|
|
9
|
+
...otherProps,
|
|
10
|
+
className: cn(inputSizeClasses(size), inputBaseClasses, className)
|
|
11
|
+
});
|
|
12
|
+
export { BaseAutocompleteInput as default };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AutocompleteInputState } from "./autocompleteTypes.js";
|
|
2
|
+
import { RenderProp } from "../../utils/render.js";
|
|
3
|
+
import { ComponentProps } from "react";
|
|
4
|
+
type BaseAutocompleteInputGroupProps = ComponentProps<"div"> & {
|
|
5
|
+
render?: RenderProp<"div", AutocompleteInputState>;
|
|
6
|
+
};
|
|
7
|
+
/** Groups the input with its trigger and clear button. The popup is placed against it. Renders a `<div>`. */
|
|
8
|
+
declare const BaseAutocompleteInputGroup: ({ className, ...otherProps }: BaseAutocompleteInputGroupProps) => import("react").JSX.Element;
|
|
9
|
+
export { BaseAutocompleteInputGroup as default };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Autocomplete } from "@base-ui/react/autocomplete";
|
|
3
|
+
import { cn } from "cn";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
// src/components/form/BaseAutocompleteInputGroup.tsx
|
|
6
|
+
/** Groups the input with its trigger and clear button. The popup is placed against it. Renders a `<div>`. */
|
|
7
|
+
const BaseAutocompleteInputGroup = ({ className, ...otherProps }) => /* @__PURE__ */ jsx(Autocomplete.InputGroup, {
|
|
8
|
+
...otherProps,
|
|
9
|
+
className: cn("relative flex items-center", className)
|
|
10
|
+
});
|
|
11
|
+
export { BaseAutocompleteInputGroup as default };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { RenderProp } from "../../utils/render.js";
|
|
2
|
+
import { ComponentProps } from "react";
|
|
3
|
+
export type AutocompleteItemState = {
|
|
4
|
+
disabled: boolean;
|
|
5
|
+
/** Whether the item is highlighted with the keyboard or the pointer. */
|
|
6
|
+
highlighted: boolean;
|
|
7
|
+
};
|
|
8
|
+
type BaseAutocompleteItemProps = Omit<ComponentProps<"div">, "id"> & {
|
|
9
|
+
render?: RenderProp<"div", AutocompleteItemState>;
|
|
10
|
+
/** The item. Its text (or `itemToStringValue`'s result) fills the input when the item is chosen. */
|
|
11
|
+
value?: unknown;
|
|
12
|
+
/** The item's position in the list. Saves the lookup in long lists. */
|
|
13
|
+
index?: number;
|
|
14
|
+
disabled?: boolean;
|
|
15
|
+
/** Set to `true` when `render` renders a `<button>`. */
|
|
16
|
+
nativeButton?: boolean;
|
|
17
|
+
};
|
|
18
|
+
/** An option in the list. Renders a `<div>`, with `data-highlighted` and `data-disabled`. */
|
|
19
|
+
declare const BaseAutocompleteItem: ({ className, ...otherProps }: BaseAutocompleteItemProps) => import("react").JSX.Element;
|
|
20
|
+
export { BaseAutocompleteItem as default };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Autocomplete } from "@base-ui/react/autocomplete";
|
|
3
|
+
import { cn } from "cn";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
// src/components/form/BaseAutocompleteItem.tsx
|
|
6
|
+
/** An option in the list. Renders a `<div>`, with `data-highlighted` and `data-disabled`. */
|
|
7
|
+
const BaseAutocompleteItem = ({ className, ...otherProps }) => /* @__PURE__ */ jsx(Autocomplete.Item, {
|
|
8
|
+
...otherProps,
|
|
9
|
+
className: cn("flex cursor-default items-center gap-2 outline-none select-none", className)
|
|
10
|
+
});
|
|
11
|
+
export { BaseAutocompleteItem as default };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { RenderProp } from "../../utils/render.js";
|
|
2
|
+
import { ComponentProps, ReactNode } from "react";
|
|
3
|
+
export type AutocompleteListState = {
|
|
4
|
+
/** Whether no item matches. */
|
|
5
|
+
empty: boolean;
|
|
6
|
+
};
|
|
7
|
+
type BaseAutocompleteListProps<Item> = Omit<ComponentProps<"div">, "children"> & {
|
|
8
|
+
render?: RenderProp<"div", AutocompleteListState>;
|
|
9
|
+
/** The items, or a function that renders each filtered item (or group) of `BaseAutocomplete`'s `items`. */
|
|
10
|
+
children?: ReactNode | ((item: Item, index: number) => ReactNode);
|
|
11
|
+
};
|
|
12
|
+
/** The scrollable list of items. Renders a `<div>`, with `data-empty` when no item matches. */
|
|
13
|
+
declare const BaseAutocompleteList: <Item>({ className, ...otherProps }: BaseAutocompleteListProps<Item>) => import("react").JSX.Element;
|
|
14
|
+
export { BaseAutocompleteList as default };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Autocomplete } from "@base-ui/react/autocomplete";
|
|
3
|
+
import { cn } from "cn";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
// src/components/form/BaseAutocompleteList.tsx
|
|
6
|
+
/** The scrollable list of items. Renders a `<div>`, with `data-empty` when no item matches. */
|
|
7
|
+
const BaseAutocompleteList = ({ className, ...otherProps }) => /* @__PURE__ */ jsx(Autocomplete.List, {
|
|
8
|
+
...otherProps,
|
|
9
|
+
className: cn("min-h-0 flex-1 overflow-y-auto overscroll-contain outline-none", className)
|
|
10
|
+
});
|
|
11
|
+
export { BaseAutocompleteList as default };
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { AutocompleteAlign, AutocompleteInteractionType, AutocompleteSide } from "./autocompleteTypes.js";
|
|
2
|
+
import { RenderProp } from "../../utils/render.js";
|
|
3
|
+
import { ComponentProps, ReactNode, RefObject } from "react";
|
|
4
|
+
export type AutocompletePopupState = {
|
|
5
|
+
open: boolean;
|
|
6
|
+
side: AutocompleteSide;
|
|
7
|
+
align: AutocompleteAlign;
|
|
8
|
+
/** Whether the input the popup is placed against is scrolled out of view. */
|
|
9
|
+
anchorHidden: boolean;
|
|
10
|
+
/** Whether no item matches. */
|
|
11
|
+
empty: boolean;
|
|
12
|
+
};
|
|
13
|
+
export type AutocompletePositionerState = AutocompletePopupState;
|
|
14
|
+
export type AutocompleteArrowState = {
|
|
15
|
+
open: boolean;
|
|
16
|
+
side: AutocompleteSide;
|
|
17
|
+
align: AutocompleteAlign;
|
|
18
|
+
/** Whether the arrow can't point at the center of the input. */
|
|
19
|
+
uncentered: boolean;
|
|
20
|
+
};
|
|
21
|
+
export type AutocompleteBackdropState = {
|
|
22
|
+
open: boolean;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* - `true`: the default.
|
|
26
|
+
* - `false`: don't move focus.
|
|
27
|
+
* - a ref: focus that element.
|
|
28
|
+
* - a function: return an element, `true` for the default, or `false` / `undefined` to not move focus.
|
|
29
|
+
*/
|
|
30
|
+
export type AutocompleteFocusTarget = boolean | RefObject<HTMLElement | null> | ((interactionType: AutocompleteInteractionType) => boolean | HTMLElement | null | void);
|
|
31
|
+
/** Computes an offset from the popup's placement and the sizes of the input and the popup. */
|
|
32
|
+
export type AutocompleteOffsetFunction = (data: {
|
|
33
|
+
side: AutocompleteSide;
|
|
34
|
+
align: AutocompleteAlign;
|
|
35
|
+
anchor: {
|
|
36
|
+
width: number;
|
|
37
|
+
height: number;
|
|
38
|
+
};
|
|
39
|
+
positioner: {
|
|
40
|
+
width: number;
|
|
41
|
+
height: number;
|
|
42
|
+
};
|
|
43
|
+
}) => number;
|
|
44
|
+
/** How the popup avoids the edges of `collisionBoundary`. */
|
|
45
|
+
export type AutocompleteCollisionAvoidance = {
|
|
46
|
+
side?: "flip" | "none";
|
|
47
|
+
align?: "flip" | "shift" | "none";
|
|
48
|
+
fallbackAxisSide?: "start" | "end" | "none";
|
|
49
|
+
} | {
|
|
50
|
+
side?: "shift" | "none";
|
|
51
|
+
align?: "shift" | "none";
|
|
52
|
+
fallbackAxisSide?: "start" | "end" | "none";
|
|
53
|
+
};
|
|
54
|
+
type Rect = {
|
|
55
|
+
x: number;
|
|
56
|
+
y: number;
|
|
57
|
+
width: number;
|
|
58
|
+
height: number;
|
|
59
|
+
};
|
|
60
|
+
type BaseAutocompletePopupProps = ComponentProps<"div"> & {
|
|
61
|
+
render?: RenderProp<"div", AutocompletePopupState>;
|
|
62
|
+
/** The element focused when the popup closes. */
|
|
63
|
+
finalFocus?: AutocompleteFocusTarget;
|
|
64
|
+
/** Where the popup is portaled to. Defaults to `<body>`. */
|
|
65
|
+
container?: HTMLElement | ShadowRoot | RefObject<HTMLElement | ShadowRoot | null> | null;
|
|
66
|
+
/** Keeps the popup in the DOM while it's closed. */
|
|
67
|
+
keepMounted?: boolean;
|
|
68
|
+
/** The element the popup is placed against. Defaults to the input group, or the input. */
|
|
69
|
+
anchor?: Element | RefObject<Element | null> | (() => Element | null) | null;
|
|
70
|
+
/** @default "absolute" */
|
|
71
|
+
positionMethod?: "absolute" | "fixed";
|
|
72
|
+
/** @default "bottom" */
|
|
73
|
+
side?: AutocompleteSide;
|
|
74
|
+
/** Distance from the input in pixels. @default 0 */
|
|
75
|
+
sideOffset?: number | AutocompleteOffsetFunction;
|
|
76
|
+
/** @default "start" */
|
|
77
|
+
align?: AutocompleteAlign;
|
|
78
|
+
/** Shift along the side in pixels. @default 0 */
|
|
79
|
+
alignOffset?: number | AutocompleteOffsetFunction;
|
|
80
|
+
/** @default "clipping-ancestors" */
|
|
81
|
+
collisionBoundary?: "clipping-ancestors" | Element | Element[] | Rect;
|
|
82
|
+
/** Space kept from the boundary's edges, in pixels. @default 5 */
|
|
83
|
+
collisionPadding?: number | {
|
|
84
|
+
top?: number;
|
|
85
|
+
right?: number;
|
|
86
|
+
bottom?: number;
|
|
87
|
+
left?: number;
|
|
88
|
+
};
|
|
89
|
+
collisionAvoidance?: AutocompleteCollisionAvoidance;
|
|
90
|
+
/** Keeps the popup in view while the input is scrolled out of view. */
|
|
91
|
+
sticky?: boolean;
|
|
92
|
+
/** Minimum distance between the arrow and the popup's corners, in pixels. @default 5 */
|
|
93
|
+
arrowPadding?: number;
|
|
94
|
+
/** Stops following the input when it moves (e.g. on scroll). */
|
|
95
|
+
disableAnchorTracking?: boolean;
|
|
96
|
+
/** Replaces the element that positions the popup. Give it e.g. a `z-index`. */
|
|
97
|
+
renderPositioner?: RenderProp<"div", AutocompletePositionerState>;
|
|
98
|
+
/** Renders a backdrop under the popup. Use it with `modal` on `BaseAutocomplete`. */
|
|
99
|
+
backdrop?: boolean;
|
|
100
|
+
/** A `className` on the element replaces the kit's conflicting classes. */
|
|
101
|
+
renderBackdrop?: RenderProp<"div", AutocompleteBackdropState>;
|
|
102
|
+
/** The arrow's content (e.g. an `<svg>`). The arrow is rendered when this or `renderArrow` is given. */
|
|
103
|
+
arrow?: ReactNode;
|
|
104
|
+
renderArrow?: RenderProp<"div", AutocompleteArrowState>;
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* The floating list container, with its portal, positioner and an optional backdrop and arrow.
|
|
108
|
+
* As wide as the input by default, never taller than the space left in the viewport. Renders a `<div>`.
|
|
109
|
+
*/
|
|
110
|
+
declare const BaseAutocompletePopup: ({ container, keepMounted, anchor, positionMethod, side, sideOffset, align, alignOffset, collisionBoundary, collisionPadding, collisionAvoidance, sticky, arrowPadding, disableAnchorTracking, renderPositioner, backdrop, renderBackdrop, arrow, renderArrow, className, children, ...otherProps }: BaseAutocompletePopupProps) => import("react").JSX.Element;
|
|
111
|
+
export { BaseAutocompletePopup as default };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Autocomplete } from "@base-ui/react/autocomplete";
|
|
3
|
+
import { cn } from "cn";
|
|
4
|
+
import { splitClassName } from "../../utils/split-class-name.js";
|
|
5
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
// src/components/form/BaseAutocompletePopup.tsx
|
|
7
|
+
/**
|
|
8
|
+
* The floating list container, with its portal, positioner and an optional backdrop and arrow.
|
|
9
|
+
* As wide as the input by default, never taller than the space left in the viewport. Renders a `<div>`.
|
|
10
|
+
*/
|
|
11
|
+
const BaseAutocompletePopup = ({ container, keepMounted, anchor, positionMethod, side, sideOffset, align, alignOffset, collisionBoundary, collisionPadding, collisionAvoidance, sticky, arrowPadding, disableAnchorTracking, renderPositioner, backdrop = false, renderBackdrop, arrow, renderArrow, className, children, ...otherProps }) => {
|
|
12
|
+
const backdropElement = splitClassName(renderBackdrop);
|
|
13
|
+
return /* @__PURE__ */ jsxs(Autocomplete.Portal, {
|
|
14
|
+
container,
|
|
15
|
+
keepMounted,
|
|
16
|
+
children: [backdrop && /* @__PURE__ */ jsx(Autocomplete.Backdrop, {
|
|
17
|
+
render: backdropElement.render,
|
|
18
|
+
className: cn("fixed inset-0", backdropElement.className)
|
|
19
|
+
}), /* @__PURE__ */ jsx(Autocomplete.Positioner, {
|
|
20
|
+
anchor,
|
|
21
|
+
positionMethod,
|
|
22
|
+
side,
|
|
23
|
+
sideOffset,
|
|
24
|
+
align,
|
|
25
|
+
alignOffset,
|
|
26
|
+
collisionBoundary,
|
|
27
|
+
collisionPadding,
|
|
28
|
+
collisionAvoidance,
|
|
29
|
+
sticky,
|
|
30
|
+
arrowPadding,
|
|
31
|
+
disableAnchorTracking,
|
|
32
|
+
render: renderPositioner,
|
|
33
|
+
className: "outline-none",
|
|
34
|
+
children: /* @__PURE__ */ jsxs(Autocomplete.Popup, {
|
|
35
|
+
...otherProps,
|
|
36
|
+
className: cn("flex", "flex-col", "w-(--anchor-width)", "max-w-(--available-width)", "max-h-[min(var(--available-height),24rem)]", "origin-(--transform-origin)", "transition-[opacity,scale]", "duration-150", "data-ending-style:scale-95", "data-ending-style:opacity-0", "data-starting-style:scale-95", "data-starting-style:opacity-0", className),
|
|
37
|
+
children: [(typeof arrow !== "undefined" || renderArrow) && /* @__PURE__ */ jsx(Autocomplete.Arrow, {
|
|
38
|
+
render: renderArrow,
|
|
39
|
+
children: arrow
|
|
40
|
+
}), children]
|
|
41
|
+
})
|
|
42
|
+
})]
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
export { BaseAutocompletePopup as default };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { RenderProp } from "../../utils/render.js";
|
|
2
|
+
import { ComponentProps } from "react";
|
|
3
|
+
type BaseAutocompleteRowProps = ComponentProps<"div"> & {
|
|
4
|
+
render?: RenderProp<"div">;
|
|
5
|
+
};
|
|
6
|
+
/** A row of items in a grid list (`BaseAutocomplete` with `grid`). Renders a `<div>`. */
|
|
7
|
+
declare const BaseAutocompleteRow: (props: BaseAutocompleteRowProps) => import("react").JSX.Element;
|
|
8
|
+
export { BaseAutocompleteRow as default };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Autocomplete } from "@base-ui/react/autocomplete";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
// src/components/form/BaseAutocompleteRow.tsx
|
|
5
|
+
/** A row of items in a grid list (`BaseAutocomplete` with `grid`). Renders a `<div>`. */
|
|
6
|
+
const BaseAutocompleteRow = (props) => /* @__PURE__ */ jsx(Autocomplete.Row, { ...props });
|
|
7
|
+
export { BaseAutocompleteRow as default };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { RenderProp } from "../../utils/render.js";
|
|
2
|
+
import { ComponentProps } from "react";
|
|
3
|
+
export type AutocompleteSeparatorState = {
|
|
4
|
+
orientation: "horizontal" | "vertical";
|
|
5
|
+
};
|
|
6
|
+
type BaseAutocompleteSeparatorProps = ComponentProps<"div"> & {
|
|
7
|
+
render?: RenderProp<"div", AutocompleteSeparatorState>;
|
|
8
|
+
/** @default "horizontal" */
|
|
9
|
+
orientation?: "horizontal" | "vertical";
|
|
10
|
+
};
|
|
11
|
+
/** A line between items or groups. Renders a `<div>` with `role="separator"` and `data-orientation`. */
|
|
12
|
+
declare const BaseAutocompleteSeparator: (props: BaseAutocompleteSeparatorProps) => import("react").JSX.Element;
|
|
13
|
+
export { BaseAutocompleteSeparator as default };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Autocomplete } from "@base-ui/react/autocomplete";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
// src/components/form/BaseAutocompleteSeparator.tsx
|
|
5
|
+
/** A line between items or groups. Renders a `<div>` with `role="separator"` and `data-orientation`. */
|
|
6
|
+
const BaseAutocompleteSeparator = (props) => /* @__PURE__ */ jsx(Autocomplete.Separator, { ...props });
|
|
7
|
+
export { BaseAutocompleteSeparator as default };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { RenderProp } from "../../utils/render.js";
|
|
2
|
+
import { ComponentProps } from "react";
|
|
3
|
+
type BaseAutocompleteStatusProps = ComponentProps<"div"> & {
|
|
4
|
+
render?: RenderProp<"div">;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* A live region announced by screen readers, e.g. "Loading…" or "12 results".
|
|
8
|
+
* Renders a `<div>`. Keep it mounted and change its children.
|
|
9
|
+
*/
|
|
10
|
+
declare const BaseAutocompleteStatus: (props: BaseAutocompleteStatusProps) => import("react").JSX.Element;
|
|
11
|
+
export { BaseAutocompleteStatus as default };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Autocomplete } from "@base-ui/react/autocomplete";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
// src/components/form/BaseAutocompleteStatus.tsx
|
|
5
|
+
/**
|
|
6
|
+
* A live region announced by screen readers, e.g. "Loading…" or "12 results".
|
|
7
|
+
* Renders a `<div>`. Keep it mounted and change its children.
|
|
8
|
+
*/
|
|
9
|
+
const BaseAutocompleteStatus = (props) => /* @__PURE__ */ jsx(Autocomplete.Status, { ...props });
|
|
10
|
+
export { BaseAutocompleteStatus as default };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { AutocompleteInputState } from "./autocompleteTypes.js";
|
|
2
|
+
import { RenderProp } from "../../utils/render.js";
|
|
3
|
+
import { ComponentProps } from "react";
|
|
4
|
+
type BaseAutocompleteTriggerProps = ComponentProps<"button"> & {
|
|
5
|
+
render?: RenderProp<"button", AutocompleteInputState>;
|
|
6
|
+
/** Set to `false` when `render` doesn't render a `<button>`. */
|
|
7
|
+
nativeButton?: boolean;
|
|
8
|
+
};
|
|
9
|
+
/** A button that opens the popup. Renders a `<button>`, with `data-popup-open` while the popup is open. */
|
|
10
|
+
declare const BaseAutocompleteTrigger: (props: BaseAutocompleteTriggerProps) => import("react").JSX.Element;
|
|
11
|
+
export { BaseAutocompleteTrigger as default };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Autocomplete } from "@base-ui/react/autocomplete";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
// src/components/form/BaseAutocompleteTrigger.tsx
|
|
5
|
+
/** A button that opens the popup. Renders a `<button>`, with `data-popup-open` while the popup is open. */
|
|
6
|
+
const BaseAutocompleteTrigger = (props) => /* @__PURE__ */ jsx(Autocomplete.Trigger, { ...props });
|
|
7
|
+
export { BaseAutocompleteTrigger as default };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
|
+
type BaseAutocompleteValueProps = {
|
|
3
|
+
/** Shown as is, or a function of the input's value. Without children, renders the value. */
|
|
4
|
+
children?: ReactNode | ((value: string) => ReactNode);
|
|
5
|
+
};
|
|
6
|
+
/** The input's current value, anywhere inside `BaseAutocomplete`. Renders no element. */
|
|
7
|
+
declare const BaseAutocompleteValue: (props: BaseAutocompleteValueProps) => import("react").JSX.Element;
|
|
8
|
+
export { BaseAutocompleteValue as default };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Autocomplete } from "@base-ui/react/autocomplete";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
// src/components/form/BaseAutocompleteValue.tsx
|
|
5
|
+
/** The input's current value, anywhere inside `BaseAutocomplete`. Renders no element. */
|
|
6
|
+
const BaseAutocompleteValue = (props) => /* @__PURE__ */ jsx(Autocomplete.Value, { ...props });
|
|
7
|
+
export { BaseAutocompleteValue as default };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { RenderProp } from "../../utils/render.js";
|
|
2
|
+
import { ComponentProps, ReactNode } from "react";
|
|
2
3
|
import { ZodType } from "zod";
|
|
3
4
|
export type FieldState = {
|
|
4
5
|
disabled: boolean;
|
|
@@ -11,14 +12,22 @@ export type FieldState = {
|
|
|
11
12
|
filled: boolean;
|
|
12
13
|
focused: boolean;
|
|
13
14
|
};
|
|
15
|
+
/** The native constraints read from the field's schema. */
|
|
16
|
+
export type FieldConstraints = Pick<ComponentProps<"input">, "type" | "required" | "minLength" | "maxLength" | "min" | "max">;
|
|
14
17
|
type BaseFormFieldProps = {
|
|
15
18
|
schema: ZodType;
|
|
16
19
|
name: string;
|
|
17
20
|
label?: string;
|
|
18
21
|
control?: RenderProp<"input", FieldState>;
|
|
22
|
+
/**
|
|
23
|
+
* Renders a control that isn't a single `<input>` (e.g. `BaseAutocomplete`) instead of `control`.
|
|
24
|
+
* Gets the constraints read from `schema`; pass on the ones the control supports.
|
|
25
|
+
* The control takes the field's `name` by itself.
|
|
26
|
+
*/
|
|
27
|
+
children?: (constraints: FieldConstraints) => ReactNode;
|
|
19
28
|
renderLabel?: RenderProp<"label", FieldState>;
|
|
20
29
|
renderErrors?: RenderProp<"div", FieldState>;
|
|
21
30
|
className?: string;
|
|
22
31
|
};
|
|
23
|
-
declare const BaseFormField: ({ schema, name, label, control, renderLabel, renderErrors, className }: BaseFormFieldProps) => import("react").JSX.Element;
|
|
32
|
+
declare const BaseFormField: ({ schema, name, label, control, children, renderLabel, renderErrors, className }: BaseFormFieldProps) => import("react").JSX.Element;
|
|
24
33
|
export { BaseFormField as default };
|
|
@@ -7,7 +7,7 @@ import FieldRoot from "./FieldRoot.js";
|
|
|
7
7
|
import ServerSideError from "./ServerSideError.js";
|
|
8
8
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
9
9
|
// src/components/form/BaseFormField.tsx
|
|
10
|
-
const BaseFormField = ({ schema, name, label, control, renderLabel, renderErrors, className }) => /* @__PURE__ */ jsxs(FieldRoot, {
|
|
10
|
+
const BaseFormField = ({ schema, name, label, control, children, renderLabel, renderErrors, className }) => /* @__PURE__ */ jsxs(FieldRoot, {
|
|
11
11
|
name,
|
|
12
12
|
className: cn("flex w-full flex-col items-start gap-1", className),
|
|
13
13
|
children: [
|
|
@@ -15,7 +15,7 @@ const BaseFormField = ({ schema, name, label, control, renderLabel, renderErrors
|
|
|
15
15
|
render: renderLabel,
|
|
16
16
|
children: label
|
|
17
17
|
}),
|
|
18
|
-
/* @__PURE__ */ jsx(Field.Control, {
|
|
18
|
+
children ? children(getFieldConstraints(schema)) : /* @__PURE__ */ jsx(Field.Control, {
|
|
19
19
|
name,
|
|
20
20
|
render: control,
|
|
21
21
|
...getFieldConstraints(schema)
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { ComponentProps } from "react";
|
|
2
2
|
import JustInput from "../elements/JustInput.js";
|
|
3
|
+
import { InputSize } from "./inputSizes.js";
|
|
3
4
|
type BaseInputProps = Omit<ComponentProps<typeof JustInput>, "size"> & {
|
|
4
|
-
size?:
|
|
5
|
+
size?: InputSize;
|
|
5
6
|
};
|
|
6
7
|
declare const BaseInput: ({ size, className, ...otherProps }: BaseInputProps) => import("react").JSX.Element;
|
|
7
8
|
export { BaseInput as default };
|
|
@@ -2,21 +2,11 @@
|
|
|
2
2
|
import { cn } from "cn";
|
|
3
3
|
import "react";
|
|
4
4
|
import JustInput from "../elements/JustInput.js";
|
|
5
|
+
import { inputBaseClasses, inputSizeClasses } from "./inputSizes.js";
|
|
5
6
|
import { jsx } from "react/jsx-runtime";
|
|
6
7
|
// src/components/form/BaseInput.tsx
|
|
7
8
|
const BaseInput = ({ size = "md", className, ...otherProps }) => /* @__PURE__ */ jsx(JustInput, {
|
|
8
9
|
...otherProps,
|
|
9
|
-
className: cn(
|
|
10
|
-
"h-12 px-5 text-base": size === "lg",
|
|
11
|
-
"h-9 px-3 text-sm": size === "md",
|
|
12
|
-
"h-8 px-2.5 text-sm": size === "sm",
|
|
13
|
-
"h-7 px-2 text-xs": size === "xs"
|
|
14
|
-
}, [
|
|
15
|
-
"rounded-md",
|
|
16
|
-
"outline-2",
|
|
17
|
-
"outline-offset-2",
|
|
18
|
-
"outline-transparent",
|
|
19
|
-
"transition-colors"
|
|
20
|
-
], className)
|
|
10
|
+
className: cn(inputSizeClasses(size), inputBaseClasses, className)
|
|
21
11
|
});
|
|
22
12
|
export { BaseInput as default };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { FieldState } from "./BaseFormField.js";
|
|
2
|
+
/** The side of the input the popup is placed on. */
|
|
3
|
+
export type AutocompleteSide = "top" | "bottom" | "left" | "right" | "inline-end" | "inline-start";
|
|
4
|
+
/** How the popup is aligned along its side. */
|
|
5
|
+
export type AutocompleteAlign = "start" | "center" | "end";
|
|
6
|
+
/** State of the input, the input group and the trigger. */
|
|
7
|
+
export type AutocompleteInputState = FieldState & {
|
|
8
|
+
open: boolean;
|
|
9
|
+
readOnly: boolean;
|
|
10
|
+
/** The side the popup is placed on, `null` while it's closed. */
|
|
11
|
+
popupSide: AutocompleteSide | null;
|
|
12
|
+
/** Whether no item matches. */
|
|
13
|
+
listEmpty: boolean;
|
|
14
|
+
};
|
|
15
|
+
/** How the popup was opened or closed. Empty when it's unknown (e.g. opened from code). */
|
|
16
|
+
export type AutocompleteInteractionType = "mouse" | "touch" | "pen" | "keyboard" | "";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -3,7 +3,16 @@ import BaseSwitch, { SwitchState } from "./BaseSwitch.js";
|
|
|
3
3
|
import BaseCheckbox, { CheckboxState } from "./BaseCheckbox.js";
|
|
4
4
|
import BaseCheckboxGroup, { CheckboxGroupState } from "./BaseCheckboxGroup.js";
|
|
5
5
|
import BaseForm from "./BaseForm.js";
|
|
6
|
-
import BaseFormField, { FieldState } from "./BaseFormField.js";
|
|
6
|
+
import BaseFormField, { FieldConstraints, FieldState } from "./BaseFormField.js";
|
|
7
7
|
import useFormMessages from "./useFormMessages.js";
|
|
8
8
|
import { DisplayedFormMessage, MessageFormatter } from "./FormContext.js";
|
|
9
|
-
|
|
9
|
+
import _default, { AutocompleteActions, AutocompleteHighlightReason, AutocompleteItemGroup } from "./BaseAutocomplete.js";
|
|
10
|
+
import useAutocompleteFilter, { AutocompleteFilter, UseAutocompleteFilterOptions } from "./useAutocompleteFilter.js";
|
|
11
|
+
import { AutocompleteAlign, AutocompleteInputState, AutocompleteInteractionType, AutocompleteSide } from "./autocompleteTypes.js";
|
|
12
|
+
import { AutocompleteClearState } from "./BaseAutocompleteClear.js";
|
|
13
|
+
import { AutocompleteItemState } from "./BaseAutocompleteItem.js";
|
|
14
|
+
import { AutocompleteListState } from "./BaseAutocompleteList.js";
|
|
15
|
+
import { AutocompleteArrowState, AutocompleteBackdropState, AutocompleteCollisionAvoidance, AutocompleteFocusTarget, AutocompleteOffsetFunction, AutocompletePopupState, AutocompletePositionerState } from "./BaseAutocompletePopup.js";
|
|
16
|
+
import { AutocompleteSeparatorState } from "./BaseAutocompleteSeparator.js";
|
|
17
|
+
import { InputSize } from "./inputSizes.js";
|
|
18
|
+
export { type AutocompleteActions, type AutocompleteAlign, type AutocompleteArrowState, type AutocompleteBackdropState, type AutocompleteClearState, type AutocompleteCollisionAvoidance, type AutocompleteFilter, type AutocompleteFocusTarget, type AutocompleteHighlightReason, type AutocompleteInputState, type AutocompleteInteractionType, type AutocompleteItemGroup, type AutocompleteItemState, type AutocompleteListState, type AutocompleteOffsetFunction, type AutocompletePopupState, type AutocompletePositionerState, type AutocompleteSeparatorState, type AutocompleteSide, _default as BaseAutocomplete, BaseCheckbox, BaseCheckboxGroup, BaseForm, BaseFormField, BaseInput, BaseSwitch, type CheckboxGroupState, type CheckboxState, type DisplayedFormMessage, type FieldConstraints, type FieldState, type InputSize, type MessageFormatter, type SwitchState, type UseAutocompleteFilterOptions, useAutocompleteFilter, useFormMessages };
|
|
@@ -5,4 +5,6 @@ import BaseCheckboxGroup from "./BaseCheckboxGroup.js";
|
|
|
5
5
|
import BaseForm from "./BaseForm.js";
|
|
6
6
|
import BaseFormField from "./BaseFormField.js";
|
|
7
7
|
import useFormMessages from "./useFormMessages.js";
|
|
8
|
-
|
|
8
|
+
import BaseAutocomplete_default from "./BaseAutocomplete.js";
|
|
9
|
+
import useAutocompleteFilter from "./useAutocompleteFilter.js";
|
|
10
|
+
export { BaseAutocomplete_default as BaseAutocomplete, BaseCheckbox, BaseCheckboxGroup, BaseForm, BaseFormField, BaseInput, BaseSwitch, useAutocompleteFilter, useFormMessages };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** The text input sizes, shared by every input-like control so they line up in a form. */
|
|
2
|
+
export type InputSize = "lg" | "md" | "sm" | "xs";
|
|
3
|
+
/** Height, padding and text size of a text input, for `cn`. */
|
|
4
|
+
export declare function inputSizeClasses(size: InputSize): {
|
|
5
|
+
"h-12 px-5 text-base": boolean;
|
|
6
|
+
"h-9 px-3 text-sm": boolean;
|
|
7
|
+
"h-8 px-2.5 text-sm": boolean;
|
|
8
|
+
"h-7 px-2 text-xs": boolean;
|
|
9
|
+
};
|
|
10
|
+
/** The colorless base of a text input: corners, a hidden focus outline and color transitions. */
|
|
11
|
+
export declare const inputBaseClasses: string[];
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// src/components/form/inputSizes.ts
|
|
2
|
+
/** Height, padding and text size of a text input, for `cn`. */
|
|
3
|
+
function inputSizeClasses(size) {
|
|
4
|
+
return {
|
|
5
|
+
"h-12 px-5 text-base": size === "lg",
|
|
6
|
+
"h-9 px-3 text-sm": size === "md",
|
|
7
|
+
"h-8 px-2.5 text-sm": size === "sm",
|
|
8
|
+
"h-7 px-2 text-xs": size === "xs"
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
/** The colorless base of a text input: corners, a hidden focus outline and color transitions. */
|
|
12
|
+
const inputBaseClasses = [
|
|
13
|
+
"rounded-md",
|
|
14
|
+
"outline-2",
|
|
15
|
+
"outline-offset-2",
|
|
16
|
+
"outline-transparent",
|
|
17
|
+
"transition-colors"
|
|
18
|
+
];
|
|
19
|
+
export { inputBaseClasses, inputSizeClasses };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** Locale-aware string matchers. `itemToString` turns an object item into the text to match. */
|
|
2
|
+
export type AutocompleteFilter = {
|
|
3
|
+
/** Whether the item contains the query anywhere. */
|
|
4
|
+
contains: <Item>(item: Item, query: string, itemToString?: (item: Item) => string) => boolean;
|
|
5
|
+
/** Whether the item starts with the query. */
|
|
6
|
+
startsWith: <Item>(item: Item, query: string, itemToString?: (item: Item) => string) => boolean;
|
|
7
|
+
/** Whether the item ends with the query. */
|
|
8
|
+
endsWith: <Item>(item: Item, query: string, itemToString?: (item: Item) => string) => boolean;
|
|
9
|
+
};
|
|
10
|
+
export type UseAutocompleteFilterOptions = Intl.CollatorOptions & {
|
|
11
|
+
/** Defaults to the user's locale. */
|
|
12
|
+
locale?: Intl.LocalesArgument;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Returns locale-aware matchers (`Intl.Collator`, case- and accent-insensitive by default with
|
|
16
|
+
* `sensitivity: "base"`) for `BaseAutocomplete`'s `filter` prop, or for filtering items yourself
|
|
17
|
+
* (e.g. before passing `filteredItems`).
|
|
18
|
+
*/
|
|
19
|
+
export default function useAutocompleteFilter(options?: UseAutocompleteFilterOptions): AutocompleteFilter;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Autocomplete } from "@base-ui/react/autocomplete";
|
|
3
|
+
// src/components/form/useAutocompleteFilter.ts
|
|
4
|
+
/**
|
|
5
|
+
* Returns locale-aware matchers (`Intl.Collator`, case- and accent-insensitive by default with
|
|
6
|
+
* `sensitivity: "base"`) for `BaseAutocomplete`'s `filter` prop, or for filtering items yourself
|
|
7
|
+
* (e.g. before passing `filteredItems`).
|
|
8
|
+
*/
|
|
9
|
+
function useAutocompleteFilter(options) {
|
|
10
|
+
return Autocomplete.useFilter(options);
|
|
11
|
+
}
|
|
12
|
+
export { useAutocompleteFilter as default };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { IntrinsicTag, RenderProp } from "./render.js";
|
|
2
|
+
/**
|
|
3
|
+
* Base UI only joins the `className` of a `render` element with the part's own, so conflicting
|
|
4
|
+
* Tailwind classes would win by their order in the CSS. Takes it out of the element so the caller
|
|
5
|
+
* can pass it to `cn` instead, last so it wins (#14). Internal: not exported to apps.
|
|
6
|
+
*/
|
|
7
|
+
export declare function splitClassName<Tag extends IntrinsicTag, State>(render: RenderProp<Tag, State> | undefined): {
|
|
8
|
+
render: RenderProp<Tag, State> | undefined;
|
|
9
|
+
className: undefined;
|
|
10
|
+
} | {
|
|
11
|
+
render: import("react").ReactElement<{
|
|
12
|
+
className?: string;
|
|
13
|
+
}, string | import("react").JSXElementConstructor<any>>;
|
|
14
|
+
className: string;
|
|
15
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { cloneElement, isValidElement } from "react";
|
|
2
|
+
// src/utils/split-class-name.ts
|
|
3
|
+
/**
|
|
4
|
+
* Base UI only joins the `className` of a `render` element with the part's own, so conflicting
|
|
5
|
+
* Tailwind classes would win by their order in the CSS. Takes it out of the element so the caller
|
|
6
|
+
* can pass it to `cn` instead, last so it wins (#14). Internal: not exported to apps.
|
|
7
|
+
*/
|
|
8
|
+
function splitClassName(render) {
|
|
9
|
+
if (!isValidElement(render) || !render.props.className) return {
|
|
10
|
+
render,
|
|
11
|
+
className: void 0
|
|
12
|
+
};
|
|
13
|
+
return {
|
|
14
|
+
render: cloneElement(render, { className: void 0 }),
|
|
15
|
+
className: render.props.className
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export { splitClassName };
|