@ui-sdk/react 0.0.0-stage → 0.1.0-beta.1
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/LICENSE +202 -0
- package/README.md +10 -2
- package/dist/accordion.d.ts +331 -0
- package/dist/accordion.js +25 -0
- package/dist/agent.d.ts +2 -0
- package/dist/agent.js +8 -0
- package/dist/alert-dialog.d.ts +56 -0
- package/dist/alert-dialog.js +45 -0
- package/dist/async-options.d.ts +22 -0
- package/dist/async-options.js +56 -0
- package/dist/autocomplete.d.ts +102 -0
- package/dist/autocomplete.js +195 -0
- package/dist/avatar.d.ts +301 -0
- package/dist/avatar.js +17 -0
- package/dist/button.d.ts +21 -0
- package/dist/button.js +45 -0
- package/dist/calendar-context.d.ts +10 -0
- package/dist/calendar-context.js +9 -0
- package/dist/calendar.d.ts +80 -0
- package/dist/calendar.js +257 -0
- package/dist/carousel.d.ts +52 -0
- package/dist/carousel.js +151 -0
- package/dist/checkbox.d.ts +24 -0
- package/dist/checkbox.js +98 -0
- package/dist/children.d.ts +38 -0
- package/dist/children.js +63 -0
- package/dist/collapsible.d.ts +302 -0
- package/dist/collapsible.js +19 -0
- package/dist/color-picker.d.ts +72 -0
- package/dist/color-picker.js +133 -0
- package/dist/color.d.ts +2 -0
- package/dist/color.js +22 -0
- package/dist/combobox.d.ts +152 -0
- package/dist/combobox.js +338 -0
- package/dist/command.d.ts +88 -0
- package/dist/command.js +233 -0
- package/dist/controller-target.d.ts +3 -0
- package/dist/controller-target.js +59 -0
- package/dist/date-input.d.ts +19 -0
- package/dist/date-input.js +58 -0
- package/dist/date-picker.d.ts +47 -0
- package/dist/date-picker.js +310 -0
- package/dist/date.d.ts +2 -0
- package/dist/date.js +60 -0
- package/dist/dialog-parts.d.ts +23 -0
- package/dist/dialog-parts.js +142 -0
- package/dist/dialog.d.ts +57 -0
- package/dist/dialog.js +32 -0
- package/dist/drawer.d.ts +70 -0
- package/dist/drawer.js +158 -0
- package/dist/editor-context.d.ts +4 -0
- package/dist/editor-context.js +9 -0
- package/dist/field-context.d.ts +47 -0
- package/dist/field-context.js +87 -0
- package/dist/field.d.ts +49 -0
- package/dist/field.js +169 -0
- package/dist/file-input.d.ts +46 -0
- package/dist/file-input.js +170 -0
- package/dist/form-inputs.d.ts +5 -0
- package/dist/form-inputs.js +22 -0
- package/dist/gesture.d.ts +1 -0
- package/dist/gesture.js +16 -0
- package/dist/history.d.ts +2 -0
- package/dist/history.js +12 -0
- package/dist/hover-card.d.ts +33 -0
- package/dist/hover-card.js +84 -0
- package/dist/image-cropper.d.ts +333 -0
- package/dist/image-cropper.js +37 -0
- package/dist/image.d.ts +2 -0
- package/dist/image.js +6 -0
- package/dist/input.d.ts +22 -0
- package/dist/input.js +51 -0
- package/dist/label.d.ts +294 -0
- package/dist/label.js +9 -0
- package/dist/list-items.d.ts +15 -0
- package/dist/list-items.js +39 -0
- package/dist/list-text.d.ts +4 -0
- package/dist/list-text.js +15 -0
- package/dist/listbox.d.ts +56 -0
- package/dist/listbox.js +122 -0
- package/dist/menu.d.ts +116 -0
- package/dist/menu.js +426 -0
- package/dist/menubar-context.d.ts +4 -0
- package/dist/menubar-context.js +7 -0
- package/dist/menubar.d.ts +11 -0
- package/dist/menubar.js +32 -0
- package/dist/meter.d.ts +312 -0
- package/dist/meter.js +30 -0
- package/dist/navigation-menu.d.ts +61 -0
- package/dist/navigation-menu.js +169 -0
- package/dist/number-input.d.ts +44 -0
- package/dist/number-input.js +185 -0
- package/dist/number.d.ts +2 -0
- package/dist/number.js +40 -0
- package/dist/observe.d.ts +2 -0
- package/dist/observe.js +8 -0
- package/dist/otp-input.d.ts +29 -0
- package/dist/otp-input.js +94 -0
- package/dist/overlays.d.ts +26 -0
- package/dist/overlays.js +82 -0
- package/dist/pagination.d.ts +336 -0
- package/dist/pagination.js +71 -0
- package/dist/password-input.d.ts +23 -0
- package/dist/password-input.js +65 -0
- package/dist/popover.d.ts +54 -0
- package/dist/popover.js +151 -0
- package/dist/popup.d.ts +41 -0
- package/dist/popup.js +180 -0
- package/dist/preferences.d.ts +35 -0
- package/dist/preferences.js +93 -0
- package/dist/primitive.d.ts +2 -0
- package/dist/primitive.js +14 -0
- package/dist/progress.d.ts +312 -0
- package/dist/progress.js +30 -0
- package/dist/radio.d.ts +22 -0
- package/dist/radio.js +86 -0
- package/dist/rating.d.ts +20 -0
- package/dist/rating.js +94 -0
- package/dist/render-element.d.ts +35 -0
- package/dist/render-element.js +103 -0
- package/dist/resizable.d.ts +302 -0
- package/dist/resizable.js +23 -0
- package/dist/scroll-area.d.ts +324 -0
- package/dist/scroll-area.js +49 -0
- package/dist/segmented-control.d.ts +24 -0
- package/dist/segmented-control.js +78 -0
- package/dist/segmented-input.d.ts +15 -0
- package/dist/segmented-input.js +48 -0
- package/dist/select.d.ts +125 -0
- package/dist/select.js +330 -0
- package/dist/separator.d.ts +290 -0
- package/dist/separator.js +9 -0
- package/dist/shortcuts.d.ts +32 -0
- package/dist/shortcuts.js +61 -0
- package/dist/slider.d.ts +38 -0
- package/dist/slider.js +163 -0
- package/dist/switch.d.ts +15 -0
- package/dist/switch.js +39 -0
- package/dist/tabs.d.ts +331 -0
- package/dist/tabs.js +28 -0
- package/dist/text-control.d.ts +22 -0
- package/dist/text-control.js +24 -0
- package/dist/text-match.d.ts +2 -0
- package/dist/text-match.js +8 -0
- package/dist/textarea.d.ts +10 -0
- package/dist/textarea.js +48 -0
- package/dist/time-input.d.ts +19 -0
- package/dist/time-input.js +63 -0
- package/dist/timeline.d.ts +327 -0
- package/dist/timeline.js +31 -0
- package/dist/toast-parts.d.ts +63 -0
- package/dist/toast-parts.js +144 -0
- package/dist/toast.d.ts +2 -0
- package/dist/toast.js +22 -0
- package/dist/toggle.d.ts +23 -0
- package/dist/toggle.js +76 -0
- package/dist/token-input.d.ts +35 -0
- package/dist/token-input.js +100 -0
- package/dist/toolbar-context.d.ts +6 -0
- package/dist/toolbar-context.js +16 -0
- package/dist/toolbar.d.ts +38 -0
- package/dist/toolbar.js +63 -0
- package/dist/tooltip.d.ts +39 -0
- package/dist/tooltip.js +108 -0
- package/dist/tree.d.ts +51 -0
- package/dist/tree.js +150 -0
- package/dist/trigger-menu.d.ts +83 -0
- package/dist/trigger-menu.js +167 -0
- package/dist/use-primitive.d.ts +178 -0
- package/dist/use-primitive.js +674 -0
- package/dist/waterfall.d.ts +80 -0
- package/dist/waterfall.js +108 -0
- package/docs/README.md +89 -0
- package/docs/agents.md +1523 -0
- package/docs/components/accordion.md +1391 -0
- package/docs/components/alert-dialog.md +850 -0
- package/docs/components/autocomplete.md +1963 -0
- package/docs/components/avatar.md +252 -0
- package/docs/components/button.md +444 -0
- package/docs/components/calendar.md +1687 -0
- package/docs/components/carousel.md +1244 -0
- package/docs/components/checkbox.md +1069 -0
- package/docs/components/collapsible.md +567 -0
- package/docs/components/color-picker.md +736 -0
- package/docs/components/combobox.md +3647 -0
- package/docs/components/command.md +1573 -0
- package/docs/components/date-input.md +608 -0
- package/docs/components/date-picker.md +1266 -0
- package/docs/components/dialog.md +1469 -0
- package/docs/components/drawer.md +1197 -0
- package/docs/components/field.md +549 -0
- package/docs/components/file-input.md +609 -0
- package/docs/components/hover-card.md +514 -0
- package/docs/components/image-cropper.md +579 -0
- package/docs/components/input.md +301 -0
- package/docs/components/label.md +217 -0
- package/docs/components/listbox.md +1130 -0
- package/docs/components/menu.md +1286 -0
- package/docs/components/menubar.md +455 -0
- package/docs/components/meter.md +304 -0
- package/docs/components/navigation-menu.md +1581 -0
- package/docs/components/number-input.md +1086 -0
- package/docs/components/otp-input.md +565 -0
- package/docs/components/pagination.md +648 -0
- package/docs/components/password-input.md +737 -0
- package/docs/components/popover.md +1552 -0
- package/docs/components/preferences.md +220 -0
- package/docs/components/progress.md +443 -0
- package/docs/components/radio.md +846 -0
- package/docs/components/rating.md +458 -0
- package/docs/components/resizable.md +982 -0
- package/docs/components/scroll-area.md +980 -0
- package/docs/components/segmented-control.md +465 -0
- package/docs/components/select.md +2133 -0
- package/docs/components/separator.md +243 -0
- package/docs/components/slider.md +1169 -0
- package/docs/components/switch.md +613 -0
- package/docs/components/tabs.md +1014 -0
- package/docs/components/textarea.md +318 -0
- package/docs/components/time-input.md +231 -0
- package/docs/components/timeline.md +677 -0
- package/docs/components/toast.md +1395 -0
- package/docs/components/toggle.md +541 -0
- package/docs/components/token-input.md +1007 -0
- package/docs/components/toolbar.md +787 -0
- package/docs/components/tooltip.md +884 -0
- package/docs/components/tree.md +1346 -0
- package/docs/components/trigger-menu.md +1257 -0
- package/docs/components/waterfall.md +754 -0
- package/docs/controllers.md +89 -0
- package/docs/core.md +8027 -0
- package/docs/custom-parts.md +120 -0
- package/docs/first-component.md +83 -0
- package/docs/forms.md +148 -0
- package/docs/hooks/async-options.md +366 -0
- package/docs/hooks/shortcuts.md +221 -0
- package/docs/installation.md +45 -0
- package/docs/introduction.md +32 -0
- package/docs/lists-and-menus.md +170 -0
- package/docs/llms.txt +1844 -0
- package/docs/parts-and-composition.md +93 -0
- package/docs/popups.md +117 -0
- package/docs/rendering.md +121 -0
- package/docs/server-rendering.md +253 -0
- package/docs/state-and-events.md +105 -0
- package/docs/styling-and-animation.md +176 -0
- package/package.json +333 -3
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { AlertDialogOptions, AlertDialogTriggerProps } from "@ui-sdk/core/dialog";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { type TriggerPartProps } from "./dialog-parts.js";
|
|
4
|
+
/**
|
|
5
|
+
* The props of `AlertDialog`.
|
|
6
|
+
* @stable
|
|
7
|
+
*/
|
|
8
|
+
type AlertDialogProps = AlertDialogOptions & {
|
|
9
|
+
children?: React.ReactNode;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* A modal dialog that interrupts the user with something important and waits for an answer, like "Delete this
|
|
13
|
+
* file?".
|
|
14
|
+
* @stable
|
|
15
|
+
*/
|
|
16
|
+
declare function AlertDialog(props: AlertDialogProps): React.JSX.Element;
|
|
17
|
+
/**
|
|
18
|
+
* The button that opens the alert dialog. A trigger outside the alert dialog connects through `controller`.
|
|
19
|
+
* @stable
|
|
20
|
+
*/
|
|
21
|
+
declare function AlertDialogTrigger(props: TriggerPartProps & Pick<AlertDialogTriggerProps, "controller">): React.JSX.Element;
|
|
22
|
+
/**
|
|
23
|
+
* A dim behind the alert dialog. Pressing it does nothing.
|
|
24
|
+
* @stable
|
|
25
|
+
*/
|
|
26
|
+
declare const AlertDialogBackdrop: (props: import("./use-primitive.js").PartProps<"div", import("@ui-sdk/core/dialog").DialogBackdropState>) => React.JSX.Element | null;
|
|
27
|
+
/**
|
|
28
|
+
* The alert dialog itself, with the `alertdialog` role, named by its title. Put the title, the description
|
|
29
|
+
* and the buttons that answer it inside.
|
|
30
|
+
* @stable
|
|
31
|
+
*/
|
|
32
|
+
declare const AlertDialogContent: <Payload = unknown>({ initialFocus, finalFocus, keepMounted, container, render, ...props }: import("./dialog-parts.js").ContentPartProps<Payload>) => React.JSX.Element | null;
|
|
33
|
+
/**
|
|
34
|
+
* The alert dialog's title, which names it. A level 2 heading by default.
|
|
35
|
+
* @stable
|
|
36
|
+
*/
|
|
37
|
+
declare const AlertDialogTitle: import("./use-primitive.js").PartComponent<import("@ui-sdk/core/dialog").DialogPrimitive, "title", "h2">;
|
|
38
|
+
/**
|
|
39
|
+
* Describes the alert dialog while it's rendered. A paragraph by default.
|
|
40
|
+
* @stable
|
|
41
|
+
*/
|
|
42
|
+
declare const AlertDialogDescription: import("./use-primitive.js").PartComponent<import("@ui-sdk/core/dialog").DialogPrimitive, "description", "p">;
|
|
43
|
+
/**
|
|
44
|
+
* A button that closes the alert dialog, like Cancel or Delete. An `action` runs first, and a Promise it
|
|
45
|
+
* returns keeps the alert dialog open until it settles.
|
|
46
|
+
* @stable
|
|
47
|
+
*/
|
|
48
|
+
declare const AlertDialogClose: import("./use-primitive.js").PartComponent<import("@ui-sdk/core/dialog").DialogPrimitive, "close", "button">;
|
|
49
|
+
/**
|
|
50
|
+
* Shows a trigger's shortcut inside the trigger.
|
|
51
|
+
* @stable
|
|
52
|
+
*/
|
|
53
|
+
declare const AlertDialogShortcut: (props: import("./dialog-parts.js").ShortcutPartProps) => React.JSX.Element | null;
|
|
54
|
+
export { confirm, createAlertDialogController, createConfirm, } from "@ui-sdk/core/alert-dialog";
|
|
55
|
+
export type { AlertDialogBackdropState, AlertDialogCloseActionDetails, AlertDialogCloseProps, AlertDialogCloseState, AlertDialogContentProps, AlertDialogContentState, AlertDialogController, AlertDialogOpenChangeReason, AlertDialogOptions, AlertDialogPayloadChangeReason, AlertDialogPrimitive, AlertDialogShortcutProps, AlertDialogShortcutState, AlertDialogTriggerProps, AlertDialogTriggerState, ConfirmEntry, ConfirmOptions, } from "@ui-sdk/core/alert-dialog";
|
|
56
|
+
export { AlertDialog, AlertDialogBackdrop, AlertDialogClose, AlertDialogContent, AlertDialogDescription, type AlertDialogProps, AlertDialogShortcut, AlertDialogTitle, AlertDialogTrigger, };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
// src/alert-dialog.tsx
|
|
3
|
+
import { alertDialog as alertDialogPrimitive } from "@ui-sdk/core/alert-dialog";
|
|
4
|
+
import "react";
|
|
5
|
+
import { dialogParts } from "./dialog-parts.js";
|
|
6
|
+
import {
|
|
7
|
+
confirm,
|
|
8
|
+
createAlertDialogController,
|
|
9
|
+
createConfirm
|
|
10
|
+
} from "@ui-sdk/core/alert-dialog";
|
|
11
|
+
import { jsx } from "react/jsx-runtime";
|
|
12
|
+
var alertParts = dialogParts(
|
|
13
|
+
alertDialogPrimitive,
|
|
14
|
+
"AlertDialog"
|
|
15
|
+
);
|
|
16
|
+
function AlertDialog(props) {
|
|
17
|
+
return /* @__PURE__ */ jsx(
|
|
18
|
+
alertParts.Root,
|
|
19
|
+
{
|
|
20
|
+
...props
|
|
21
|
+
}
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
function AlertDialogTrigger(props) {
|
|
25
|
+
return /* @__PURE__ */ jsx(alertParts.Trigger, { ...props });
|
|
26
|
+
}
|
|
27
|
+
var AlertDialogBackdrop = alertParts.Backdrop;
|
|
28
|
+
var AlertDialogContent = alertParts.Content;
|
|
29
|
+
var AlertDialogTitle = alertParts.Title;
|
|
30
|
+
var AlertDialogDescription = alertParts.Description;
|
|
31
|
+
var AlertDialogClose = alertParts.Close;
|
|
32
|
+
var AlertDialogShortcut = alertParts.Shortcut;
|
|
33
|
+
export {
|
|
34
|
+
AlertDialog,
|
|
35
|
+
AlertDialogBackdrop,
|
|
36
|
+
AlertDialogClose,
|
|
37
|
+
AlertDialogContent,
|
|
38
|
+
AlertDialogDescription,
|
|
39
|
+
AlertDialogShortcut,
|
|
40
|
+
AlertDialogTitle,
|
|
41
|
+
AlertDialogTrigger,
|
|
42
|
+
confirm,
|
|
43
|
+
createAlertDialogController,
|
|
44
|
+
createConfirm
|
|
45
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type AsyncOptionsContext, type AsyncOptionsOptions } from "@ui-sdk/core/async-options";
|
|
2
|
+
/**
|
|
3
|
+
* Options loaded for what the user types, latest first. Pass `items`, `status`
|
|
4
|
+
* and `setQuery` (as `onQueryChange`) to a combobox with `filter={false}`.
|
|
5
|
+
* @stable
|
|
6
|
+
*/
|
|
7
|
+
declare function useAsyncOptions<Item>(load: (query: string, context: AsyncOptionsContext) => Promise<Item[] | {
|
|
8
|
+
items: Item[];
|
|
9
|
+
hasMore?: boolean;
|
|
10
|
+
}>, options?: AsyncOptionsOptions): {
|
|
11
|
+
setQuery: (next: string) => void;
|
|
12
|
+
reload: () => void;
|
|
13
|
+
loadMore: () => void;
|
|
14
|
+
status: import("@ui-sdk/core/async-options").AsyncOptionsStatus;
|
|
15
|
+
query: string;
|
|
16
|
+
items: Item[];
|
|
17
|
+
error: unknown;
|
|
18
|
+
hasMore: boolean;
|
|
19
|
+
};
|
|
20
|
+
export { createAsyncOptions } from "@ui-sdk/core/async-options";
|
|
21
|
+
export type { AsyncOptions, AsyncOptionsContext, AsyncOptionsOptions, AsyncOptionsState, AsyncOptionsStatus, } from "@ui-sdk/core/async-options";
|
|
22
|
+
export { useAsyncOptions };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
// src/async-options.ts
|
|
3
|
+
import {
|
|
4
|
+
createAsyncOptions
|
|
5
|
+
} from "@ui-sdk/core/async-options";
|
|
6
|
+
import * as React from "react";
|
|
7
|
+
import { createAsyncOptions as createAsyncOptions2 } from "@ui-sdk/core/async-options";
|
|
8
|
+
function useAsyncOptions(load, options) {
|
|
9
|
+
const latest = React.useRef(load);
|
|
10
|
+
React.useLayoutEffect(() => {
|
|
11
|
+
latest.current = load;
|
|
12
|
+
});
|
|
13
|
+
const [{ helper, immediate, initial }] = React.useState(() => {
|
|
14
|
+
const helper2 = createAsyncOptions(
|
|
15
|
+
(query, context) => latest.current(query, context),
|
|
16
|
+
{
|
|
17
|
+
...options,
|
|
18
|
+
immediate: false
|
|
19
|
+
}
|
|
20
|
+
);
|
|
21
|
+
return {
|
|
22
|
+
helper: helper2,
|
|
23
|
+
immediate: !!options?.immediate,
|
|
24
|
+
initial: helper2.getState()
|
|
25
|
+
};
|
|
26
|
+
});
|
|
27
|
+
const mounted = React.useRef(false);
|
|
28
|
+
React.useEffect(() => {
|
|
29
|
+
mounted.current = true;
|
|
30
|
+
const { status, items } = helper.getState();
|
|
31
|
+
if (immediate && status === "idle" && !items.length) {
|
|
32
|
+
helper.reload();
|
|
33
|
+
}
|
|
34
|
+
return () => {
|
|
35
|
+
mounted.current = false;
|
|
36
|
+
queueMicrotask(() => !mounted.current && helper.cancel());
|
|
37
|
+
};
|
|
38
|
+
}, [helper, immediate]);
|
|
39
|
+
const state = React.useSyncExternalStore(
|
|
40
|
+
helper.subscribe,
|
|
41
|
+
helper.getState,
|
|
42
|
+
helper.getState
|
|
43
|
+
);
|
|
44
|
+
return {
|
|
45
|
+
...state,
|
|
46
|
+
// Until it starts, an immediate load shows as loading, so nothing says "no match" first.
|
|
47
|
+
...immediate && state === initial && { status: "loading" },
|
|
48
|
+
setQuery: helper.setQuery,
|
|
49
|
+
reload: helper.reload,
|
|
50
|
+
loadMore: helper.loadMore
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
export {
|
|
54
|
+
createAsyncOptions2 as createAsyncOptions,
|
|
55
|
+
useAsyncOptions
|
|
56
|
+
};
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { type AutocompleteContentProps, type AutocompleteContentState, type AutocompleteEmptyState, type AutocompleteInputState, type AutocompleteItemProps, type AutocompleteItemState, type AutocompleteItemTextState, type AutocompleteOptions, type ListData } from "@ui-sdk/core/autocomplete";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { type PartProps } from "./use-primitive.js";
|
|
4
|
+
type Clashing = "value" | "defaultValue" | "onChange" | "onSelect" | "onSubmit";
|
|
5
|
+
/**
|
|
6
|
+
* The props of `Autocomplete`.
|
|
7
|
+
* @stable
|
|
8
|
+
*/
|
|
9
|
+
type AutocompleteProps = AutocompleteOptions & {
|
|
10
|
+
children?: React.ReactNode;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* A text field that suggests as you type. The text is the value. Renders no element of its own.
|
|
14
|
+
* @stable
|
|
15
|
+
*/
|
|
16
|
+
declare function Autocomplete({ children, container, ...options }: AutocompleteProps): React.JSX.Element;
|
|
17
|
+
/**
|
|
18
|
+
* A visible label for the field.
|
|
19
|
+
* @stable
|
|
20
|
+
*/
|
|
21
|
+
declare const AutocompleteLabel: import("./use-primitive.js").PartComponent<import("@ui-sdk/core/autocomplete").AutocompletePrimitive, "label", "label">;
|
|
22
|
+
/**
|
|
23
|
+
* The text field. It's the form control, so the text submits under the autocomplete's `name`.
|
|
24
|
+
* @stable
|
|
25
|
+
*/
|
|
26
|
+
declare function AutocompleteInput({ render, ...props }: Omit<PartProps<"input", AutocompleteInputState>, "value" | "defaultValue" | "children" | "readOnly">): React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | null;
|
|
27
|
+
/**
|
|
28
|
+
* A button that opens and closes the suggestions, out of the tab order.
|
|
29
|
+
* @stable
|
|
30
|
+
*/
|
|
31
|
+
declare const AutocompleteTrigger: import("./use-primitive.js").PartComponent<import("@ui-sdk/core/autocomplete").AutocompletePrimitive, "trigger", "button">;
|
|
32
|
+
/**
|
|
33
|
+
* A button that empties the field. Shown while there's text to clear. Name it with `aria-label`.
|
|
34
|
+
* @stable
|
|
35
|
+
*/
|
|
36
|
+
declare const AutocompleteClear: import("./use-primitive.js").PartComponent<import("@ui-sdk/core/autocomplete").AutocompletePrimitive, "clear", "button">;
|
|
37
|
+
/**
|
|
38
|
+
* The popup that holds the suggestions, positioned against the field.
|
|
39
|
+
* @stable
|
|
40
|
+
*/
|
|
41
|
+
declare function AutocompleteContent({ side, align, sideOffset, alignOffset, collisionPadding, arrowPadding, anchor, keepMounted, container, render, children, ...props }: PartProps<"div", AutocompleteContentState> & AutocompleteContentProps): React.JSX.Element | null;
|
|
42
|
+
/**
|
|
43
|
+
* The listbox. Without children, it renders the autocomplete's `items`, filtered.
|
|
44
|
+
* @stable
|
|
45
|
+
*/
|
|
46
|
+
declare function AutocompleteList({ children, ...props }: PartProps<"div", AutocompleteContentState>): React.JSX.Element | null;
|
|
47
|
+
/**
|
|
48
|
+
* A suggestion. Choosing it fills the field in with its text.
|
|
49
|
+
* @stable
|
|
50
|
+
*/
|
|
51
|
+
declare const AutocompleteItem: (props: Omit<PartProps<"div", AutocompleteItemState>, Clashing> & AutocompleteItemProps) => React.ReactNode;
|
|
52
|
+
/**
|
|
53
|
+
* The suggestion's text, with the part the field's text matched in `<mark>`. Without string content, it shows the suggestion's label.
|
|
54
|
+
* @stable
|
|
55
|
+
*/
|
|
56
|
+
declare function AutocompleteItemText({ children, ...props }: PartProps<"span", AutocompleteItemTextState>): React.JSX.Element | null;
|
|
57
|
+
/**
|
|
58
|
+
* An icon inside a suggestion. Screen readers, typeahead and filtering skip it, and `mirror` flips
|
|
59
|
+
* it in right-to-left text.
|
|
60
|
+
* @stable
|
|
61
|
+
*/
|
|
62
|
+
declare const AutocompleteItemIcon: import("./use-primitive.js").PartComponent<import("@ui-sdk/core/autocomplete").AutocompletePrimitive, "item-icon", "span">;
|
|
63
|
+
/**
|
|
64
|
+
* A group of items, named by its `AutocompleteGroupLabel`, and hidden while none of its items shows.
|
|
65
|
+
* @stable
|
|
66
|
+
*/
|
|
67
|
+
declare const AutocompleteGroup: import("./use-primitive.js").PartComponent<import("@ui-sdk/core/autocomplete").AutocompletePrimitive, "group", "div">;
|
|
68
|
+
/**
|
|
69
|
+
* The group's heading, which names the group.
|
|
70
|
+
* @stable
|
|
71
|
+
*/
|
|
72
|
+
declare const AutocompleteGroupLabel: import("./use-primitive.js").PartComponent<import("@ui-sdk/core/autocomplete").AutocompletePrimitive, "group-label", "div">;
|
|
73
|
+
/**
|
|
74
|
+
* A line between items or groups, hidden from screen readers.
|
|
75
|
+
* @stable
|
|
76
|
+
*/
|
|
77
|
+
declare const AutocompleteSeparator: import("./use-primitive.js").PartComponent<import("@ui-sdk/core/autocomplete").AutocompletePrimitive, "separator", "div">;
|
|
78
|
+
/**
|
|
79
|
+
* Shown while no suggestion matches. Its message is announced when it appears.
|
|
80
|
+
* @stable
|
|
81
|
+
*/
|
|
82
|
+
declare function AutocompleteEmpty({ children, ...props }: PartProps<"div", AutocompleteEmptyState>): React.JSX.Element | null;
|
|
83
|
+
/**
|
|
84
|
+
* A polite live region for loading and result counts. Its content is yours, usually a function of its state.
|
|
85
|
+
* @stable
|
|
86
|
+
*/
|
|
87
|
+
declare const AutocompleteStatus: import("./use-primitive.js").PartComponent<import("@ui-sdk/core/autocomplete").AutocompletePrimitive, "status", "div">;
|
|
88
|
+
/**
|
|
89
|
+
* An arrow on the popup's edge that points at the field.
|
|
90
|
+
* @stable
|
|
91
|
+
*/
|
|
92
|
+
declare const AutocompleteArrow: import("./use-primitive.js").PartComponent<import("@ui-sdk/core/autocomplete").AutocompletePrimitive, "arrow", "div">;
|
|
93
|
+
/**
|
|
94
|
+
* Renders data suggestions. Used by data autocompletes, and available for custom layouts.
|
|
95
|
+
* @stable
|
|
96
|
+
*/
|
|
97
|
+
declare function AutocompleteItems({ items }: {
|
|
98
|
+
items: ListData<string>;
|
|
99
|
+
}): React.JSX.Element;
|
|
100
|
+
export { createAutocompleteController } from "@ui-sdk/core/autocomplete";
|
|
101
|
+
export type { AutocompleteApi, AutocompleteArrowState, AutocompleteChangeOptions, AutocompleteClearProps, AutocompleteClearState, AutocompleteContentProps, AutocompleteContentState, AutocompleteController, AutocompleteDismissReason, AutocompleteEmptyState, AutocompleteInputState, AutocompleteItemIconProps, AutocompleteItemIconState, AutocompleteItemProps, AutocompleteItemState, AutocompleteItemTextState, AutocompleteOpenChangeReason, AutocompleteOptions, AutocompletePrimitive, AutocompleteStatusState, AutocompleteSubmitDetails, AutocompleteTriggerState, AutocompleteValueChangeReason, ListAnnouncement, ListData, ListFilter, ListGroup, ListHighlightDetails, ListItem, ListSeparator, MatchSegment, SearchFilter, } from "@ui-sdk/core/autocomplete";
|
|
102
|
+
export { Autocomplete, AutocompleteArrow, AutocompleteClear, AutocompleteContent, AutocompleteEmpty, AutocompleteGroup, AutocompleteGroupLabel, AutocompleteInput, AutocompleteItem, AutocompleteItemIcon, AutocompleteItems, AutocompleteItemText, AutocompleteLabel, AutocompleteList, type AutocompleteProps, AutocompleteSeparator, AutocompleteStatus, AutocompleteTrigger, };
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
// src/autocomplete.tsx
|
|
3
|
+
import {
|
|
4
|
+
autocomplete as autocompletePrimitive
|
|
5
|
+
} from "@ui-sdk/core/autocomplete";
|
|
6
|
+
import * as React from "react";
|
|
7
|
+
import { hasChild, Placed, usePlaceContent, usePlacedContent } from "./children.js";
|
|
8
|
+
import { controlRender, useFieldControl } from "./field-context.js";
|
|
9
|
+
import { markSegments, textToMark } from "./list-text.js";
|
|
10
|
+
import {
|
|
11
|
+
renderPopup,
|
|
12
|
+
SheetHeaderContext,
|
|
13
|
+
inSheetHeader,
|
|
14
|
+
sheetHeader,
|
|
15
|
+
sheetViewport,
|
|
16
|
+
useControllerEntry,
|
|
17
|
+
useOwnContainer,
|
|
18
|
+
usePopupContainer
|
|
19
|
+
} from "./popup.js";
|
|
20
|
+
import { ListItems } from "./list-items.js";
|
|
21
|
+
import {
|
|
22
|
+
createParts,
|
|
23
|
+
HandleScope,
|
|
24
|
+
useAround,
|
|
25
|
+
useHandle,
|
|
26
|
+
usePart,
|
|
27
|
+
usePrimitive
|
|
28
|
+
} from "./use-primitive.js";
|
|
29
|
+
import { createAutocompleteController } from "@ui-sdk/core/autocomplete";
|
|
30
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
31
|
+
var parts = createParts(autocompletePrimitive, {
|
|
32
|
+
label: "label",
|
|
33
|
+
trigger: "button",
|
|
34
|
+
clear: "button",
|
|
35
|
+
item: "div",
|
|
36
|
+
"item-icon": "span",
|
|
37
|
+
group: "div",
|
|
38
|
+
"group-label": "div",
|
|
39
|
+
separator: "div",
|
|
40
|
+
status: "div",
|
|
41
|
+
arrow: "div"
|
|
42
|
+
});
|
|
43
|
+
var ContainerContext = React.createContext(void 0);
|
|
44
|
+
function useAutocomplete() {
|
|
45
|
+
return useHandle(autocompletePrimitive);
|
|
46
|
+
}
|
|
47
|
+
function Autocomplete({ children, container, ...options }) {
|
|
48
|
+
const field = useFieldControl();
|
|
49
|
+
const autocomplete = usePrimitive(autocompletePrimitive, {
|
|
50
|
+
...options,
|
|
51
|
+
name: options.name ?? field?.name,
|
|
52
|
+
disabled: options.disabled || field?.disabled
|
|
53
|
+
});
|
|
54
|
+
useControllerEntry(options.controller, autocomplete);
|
|
55
|
+
const header = React.useState(null);
|
|
56
|
+
const found = hasChild(children, AutocompleteContent);
|
|
57
|
+
const [placed, place] = usePlacedContent(!!options.items && !found);
|
|
58
|
+
const own = placed || found;
|
|
59
|
+
return /* @__PURE__ */ jsx(HandleScope, { handle: autocomplete, children: /* @__PURE__ */ jsx(ContainerContext.Provider, { value: container, children: /* @__PURE__ */ jsxs(SheetHeaderContext.Provider, { value: header, children: [
|
|
60
|
+
/* @__PURE__ */ jsx(Placed, { value: place, children }),
|
|
61
|
+
/* @__PURE__ */ jsx(Placed, { value: null, children: options.items && !own && /* @__PURE__ */ jsx(AutocompleteContent, {}) })
|
|
62
|
+
] }) }) });
|
|
63
|
+
}
|
|
64
|
+
var AutocompleteLabel = parts.Label;
|
|
65
|
+
function AutocompleteInput({
|
|
66
|
+
render,
|
|
67
|
+
...props
|
|
68
|
+
}) {
|
|
69
|
+
const [header] = React.useContext(SheetHeaderContext);
|
|
70
|
+
const element = {
|
|
71
|
+
...props,
|
|
72
|
+
render: controlRender(useFieldControl(props), "input", render)
|
|
73
|
+
};
|
|
74
|
+
const input = usePart(autocompletePrimitive, "input", {}, element, "input");
|
|
75
|
+
return input && inSheetHeader(input, header);
|
|
76
|
+
}
|
|
77
|
+
var AutocompleteTrigger = parts.Trigger;
|
|
78
|
+
var AutocompleteClear = parts.Clear;
|
|
79
|
+
function AutocompleteContent({
|
|
80
|
+
side,
|
|
81
|
+
align,
|
|
82
|
+
sideOffset,
|
|
83
|
+
alignOffset,
|
|
84
|
+
collisionPadding,
|
|
85
|
+
arrowPadding,
|
|
86
|
+
anchor,
|
|
87
|
+
keepMounted,
|
|
88
|
+
container,
|
|
89
|
+
render,
|
|
90
|
+
children,
|
|
91
|
+
...props
|
|
92
|
+
}) {
|
|
93
|
+
usePlaceContent();
|
|
94
|
+
const autocomplete = useAutocomplete();
|
|
95
|
+
const target = usePopupContainer(useOwnContainer(container, ContainerContext));
|
|
96
|
+
const content = {
|
|
97
|
+
side,
|
|
98
|
+
align,
|
|
99
|
+
sideOffset,
|
|
100
|
+
alignOffset,
|
|
101
|
+
collisionPadding,
|
|
102
|
+
arrowPadding,
|
|
103
|
+
anchor,
|
|
104
|
+
keepMounted
|
|
105
|
+
};
|
|
106
|
+
const [, setHeader] = React.useContext(SheetHeaderContext);
|
|
107
|
+
const body = (state) => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
108
|
+
sheetHeader(autocomplete, setHeader),
|
|
109
|
+
typeof children === "function" ? children(state) : children ?? (state.items && autocomplete.state.items && /* @__PURE__ */ jsx(AutocompleteList, {}))
|
|
110
|
+
] });
|
|
111
|
+
const element = usePart(autocomplete, "content", content, {
|
|
112
|
+
...props,
|
|
113
|
+
children: body,
|
|
114
|
+
render: sheetViewport(autocomplete, render)
|
|
115
|
+
});
|
|
116
|
+
return element && renderPopup(element, target);
|
|
117
|
+
}
|
|
118
|
+
function AutocompleteList({
|
|
119
|
+
children = listItems,
|
|
120
|
+
...props
|
|
121
|
+
}) {
|
|
122
|
+
return usePart(autocompletePrimitive, "list", {}, { ...props, children });
|
|
123
|
+
}
|
|
124
|
+
var listItems = (state) => /* @__PURE__ */ jsx(AutocompleteItems, { items: state.items });
|
|
125
|
+
var AutocompleteItem = parts.Item;
|
|
126
|
+
function AutocompleteItemText({
|
|
127
|
+
children,
|
|
128
|
+
...props
|
|
129
|
+
}) {
|
|
130
|
+
const item = useAround(autocompletePrimitive, "item");
|
|
131
|
+
if (!item) {
|
|
132
|
+
throw new Error(
|
|
133
|
+
"<AutocompleteItemText> must be used inside <AutocompleteItem>."
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
const part = {
|
|
137
|
+
id: item.value,
|
|
138
|
+
text: textToMark(children, item.label ?? item.value)
|
|
139
|
+
};
|
|
140
|
+
const content = typeof children === "function" ? children : (state) => markSegments(state.segments);
|
|
141
|
+
return usePart(
|
|
142
|
+
autocompletePrimitive,
|
|
143
|
+
"item-text",
|
|
144
|
+
part,
|
|
145
|
+
{ ...props, children: content },
|
|
146
|
+
"span"
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
var AutocompleteItemIcon = parts.ItemIcon;
|
|
150
|
+
var AutocompleteGroup = parts.Group;
|
|
151
|
+
var AutocompleteGroupLabel = parts.GroupLabel;
|
|
152
|
+
var AutocompleteSeparator = parts.Separator;
|
|
153
|
+
function AutocompleteEmpty({
|
|
154
|
+
children,
|
|
155
|
+
...props
|
|
156
|
+
}) {
|
|
157
|
+
const content = (state) => typeof children === "function" ? children(state) : state.empty ? children : null;
|
|
158
|
+
return usePart(
|
|
159
|
+
autocompletePrimitive,
|
|
160
|
+
"empty",
|
|
161
|
+
{},
|
|
162
|
+
{ ...props, children: content }
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
var AutocompleteStatus = parts.Status;
|
|
166
|
+
var AutocompleteArrow = parts.Arrow;
|
|
167
|
+
function AutocompleteItems({ items }) {
|
|
168
|
+
return /* @__PURE__ */ jsx(ListItems, { items, parts: listParts, keyOf: String });
|
|
169
|
+
}
|
|
170
|
+
var listParts = {
|
|
171
|
+
Item: AutocompleteItem,
|
|
172
|
+
Group: AutocompleteGroup,
|
|
173
|
+
GroupLabel: AutocompleteGroupLabel,
|
|
174
|
+
Separator: AutocompleteSeparator
|
|
175
|
+
};
|
|
176
|
+
export {
|
|
177
|
+
Autocomplete,
|
|
178
|
+
AutocompleteArrow,
|
|
179
|
+
AutocompleteClear,
|
|
180
|
+
AutocompleteContent,
|
|
181
|
+
AutocompleteEmpty,
|
|
182
|
+
AutocompleteGroup,
|
|
183
|
+
AutocompleteGroupLabel,
|
|
184
|
+
AutocompleteInput,
|
|
185
|
+
AutocompleteItem,
|
|
186
|
+
AutocompleteItemIcon,
|
|
187
|
+
AutocompleteItemText,
|
|
188
|
+
AutocompleteItems,
|
|
189
|
+
AutocompleteLabel,
|
|
190
|
+
AutocompleteList,
|
|
191
|
+
AutocompleteSeparator,
|
|
192
|
+
AutocompleteStatus,
|
|
193
|
+
AutocompleteTrigger,
|
|
194
|
+
createAutocompleteController
|
|
195
|
+
};
|