@funstack/ui 0.1.0-alpha.19 → 0.1.0-alpha.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/accordion/accordion-item.mjs +2 -2
- package/dist/accordion/accordion-item.mjs.map +1 -1
- package/dist/accordion/accordion-trigger.d.mts.map +1 -1
- package/dist/accordion/accordion-trigger.mjs +3 -20
- package/dist/accordion/accordion-trigger.mjs.map +1 -1
- package/dist/alert-dialog/alert-dialog-action.d.mts +73 -0
- package/dist/alert-dialog/alert-dialog-action.d.mts.map +1 -0
- package/dist/alert-dialog/alert-dialog-action.mjs +23 -0
- package/dist/alert-dialog/alert-dialog-action.mjs.map +1 -0
- package/dist/alert-dialog/alert-dialog-cancel.d.mts +31 -0
- package/dist/alert-dialog/alert-dialog-cancel.d.mts.map +1 -0
- package/dist/alert-dialog/alert-dialog-cancel.mjs +50 -0
- package/dist/alert-dialog/alert-dialog-cancel.mjs.map +1 -0
- package/dist/alert-dialog/alert-dialog-context.mjs +24 -0
- package/dist/alert-dialog/alert-dialog-context.mjs.map +1 -0
- package/dist/alert-dialog/alert-dialog-description.d.mts +25 -0
- package/dist/alert-dialog/alert-dialog-description.d.mts.map +1 -0
- package/dist/alert-dialog/alert-dialog-description.mjs +20 -0
- package/dist/alert-dialog/alert-dialog-description.mjs.map +1 -0
- package/dist/alert-dialog/alert-dialog-form.d.mts +27 -0
- package/dist/alert-dialog/alert-dialog-form.d.mts.map +1 -0
- package/dist/alert-dialog/alert-dialog-form.mjs +22 -0
- package/dist/alert-dialog/alert-dialog-form.mjs.map +1 -0
- package/dist/alert-dialog/alert-dialog-popup.d.mts +42 -0
- package/dist/alert-dialog/alert-dialog-popup.d.mts.map +1 -0
- package/dist/alert-dialog/alert-dialog-popup.mjs +53 -0
- package/dist/alert-dialog/alert-dialog-popup.mjs.map +1 -0
- package/dist/alert-dialog/alert-dialog-root.d.mts +31 -0
- package/dist/alert-dialog/alert-dialog-root.d.mts.map +1 -0
- package/dist/alert-dialog/alert-dialog-root.mjs +22 -0
- package/dist/alert-dialog/alert-dialog-root.mjs.map +1 -0
- package/dist/alert-dialog/alert-dialog-title.d.mts +23 -0
- package/dist/alert-dialog/alert-dialog-title.d.mts.map +1 -0
- package/dist/alert-dialog/alert-dialog-title.mjs +18 -0
- package/dist/alert-dialog/alert-dialog-title.mjs.map +1 -0
- package/dist/alert-dialog/alert-dialog-trigger.d.mts +23 -0
- package/dist/alert-dialog/alert-dialog-trigger.d.mts.map +1 -0
- package/dist/alert-dialog/alert-dialog-trigger.mjs +18 -0
- package/dist/alert-dialog/alert-dialog-trigger.mjs.map +1 -0
- package/dist/alert-dialog/index.d.mts +33 -0
- package/dist/alert-dialog/index.d.mts.map +1 -0
- package/dist/alert-dialog/index.mjs +33 -0
- package/dist/alert-dialog/index.mjs.map +1 -0
- package/dist/checkbox-group/checkbox-group-parent.mjs +1 -1
- package/dist/collapsible/collapsible-context.mjs +8 -0
- package/dist/collapsible/collapsible-context.mjs.map +1 -0
- package/dist/collapsible/collapsible-panel.d.mts +53 -0
- package/dist/collapsible/collapsible-panel.d.mts.map +1 -0
- package/dist/collapsible/collapsible-panel.mjs +41 -0
- package/dist/collapsible/collapsible-panel.mjs.map +1 -0
- package/dist/collapsible/collapsible-root.d.mts +108 -0
- package/dist/collapsible/collapsible-root.d.mts.map +1 -0
- package/dist/collapsible/collapsible-root.mjs +147 -0
- package/dist/collapsible/collapsible-root.mjs.map +1 -0
- package/dist/collapsible/collapsible-trigger.d.mts +45 -0
- package/dist/collapsible/collapsible-trigger.d.mts.map +1 -0
- package/dist/collapsible/collapsible-trigger.mjs +62 -0
- package/dist/collapsible/collapsible-trigger.mjs.map +1 -0
- package/dist/collapsible/index.d.mts +21 -0
- package/dist/collapsible/index.d.mts.map +1 -0
- package/dist/collapsible/index.mjs +21 -0
- package/dist/collapsible/index.mjs.map +1 -0
- package/dist/combobox/chip-text.mjs +24 -0
- package/dist/combobox/chip-text.mjs.map +1 -0
- package/dist/combobox/combobox-chips.d.mts +159 -0
- package/dist/combobox/combobox-chips.d.mts.map +1 -0
- package/dist/combobox/combobox-chips.mjs +198 -0
- package/dist/combobox/combobox-chips.mjs.map +1 -0
- package/dist/combobox/combobox-clear.d.mts +5 -2
- package/dist/combobox/combobox-clear.d.mts.map +1 -1
- package/dist/combobox/combobox-clear.mjs +3 -1
- package/dist/combobox/combobox-clear.mjs.map +1 -1
- package/dist/combobox/combobox-context.mjs +4 -5
- package/dist/combobox/combobox-context.mjs.map +1 -1
- package/dist/combobox/combobox-input.d.mts +10 -3
- package/dist/combobox/combobox-input.d.mts.map +1 -1
- package/dist/combobox/combobox-input.mjs +13 -5
- package/dist/combobox/combobox-input.mjs.map +1 -1
- package/dist/combobox/combobox-keyboard.mjs +50 -4
- package/dist/combobox/combobox-keyboard.mjs.map +1 -1
- package/dist/combobox/combobox-list.d.mts +1 -1
- package/dist/combobox/combobox-list.mjs +2 -1
- package/dist/combobox/combobox-list.mjs.map +1 -1
- package/dist/combobox/combobox-option.d.mts +5 -2
- package/dist/combobox/combobox-option.d.mts.map +1 -1
- package/dist/combobox/combobox-option.mjs +4 -3
- package/dist/combobox/combobox-option.mjs.map +1 -1
- package/dist/combobox/combobox-root.d.mts +127 -35
- package/dist/combobox/combobox-root.d.mts.map +1 -1
- package/dist/combobox/combobox-root.mjs +396 -44
- package/dist/combobox/combobox-root.mjs.map +1 -1
- package/dist/combobox/index.d.mts +8 -2
- package/dist/combobox/index.d.mts.map +1 -1
- package/dist/combobox/index.mjs +7 -1
- package/dist/combobox/index.mjs.map +1 -1
- package/dist/combobox/use-combobox-form.mjs +2 -3
- package/dist/combobox/use-combobox-form.mjs.map +1 -1
- package/dist/dialog/dialog-close.d.mts +9 -5
- package/dist/dialog/dialog-close.d.mts.map +1 -1
- package/dist/dialog/dialog-close.mjs +19 -8
- package/dist/dialog/dialog-close.mjs.map +1 -1
- package/dist/dialog/dialog-context.d.mts +2 -0
- package/dist/dialog/dialog-context.mjs +14 -2
- package/dist/dialog/dialog-context.mjs.map +1 -1
- package/dist/dialog/dialog-description.d.mts +2 -1
- package/dist/dialog/dialog-description.d.mts.map +1 -1
- package/dist/dialog/dialog-description.mjs +8 -4
- package/dist/dialog/dialog-description.mjs.map +1 -1
- package/dist/dialog/dialog-form.d.mts +2 -1
- package/dist/dialog/dialog-form.d.mts.map +1 -1
- package/dist/dialog/dialog-form.mjs +11 -6
- package/dist/dialog/dialog-form.mjs.map +1 -1
- package/dist/dialog/dialog-popup.d.mts +2 -1
- package/dist/dialog/dialog-popup.d.mts.map +1 -1
- package/dist/dialog/dialog-popup.mjs +23 -14
- package/dist/dialog/dialog-popup.mjs.map +1 -1
- package/dist/dialog/dialog-root.d.mts +2 -1
- package/dist/dialog/dialog-root.d.mts.map +1 -1
- package/dist/dialog/dialog-root.mjs +15 -5
- package/dist/dialog/dialog-root.mjs.map +1 -1
- package/dist/dialog/dialog-title.d.mts +2 -1
- package/dist/dialog/dialog-title.d.mts.map +1 -1
- package/dist/dialog/dialog-title.mjs +8 -4
- package/dist/dialog/dialog-title.mjs.map +1 -1
- package/dist/dialog/dialog-trigger.d.mts +2 -1
- package/dist/dialog/dialog-trigger.d.mts.map +1 -1
- package/dist/dialog/dialog-trigger.mjs +14 -9
- package/dist/dialog/dialog-trigger.mjs.map +1 -1
- package/dist/docs/components/accordion.md +2 -0
- package/dist/docs/components/alert-dialog.md +546 -0
- package/dist/docs/components/collapsible.md +408 -0
- package/dist/docs/components/combobox.md +288 -26
- package/dist/docs/components/dialog.md +7 -5
- package/dist/docs/components/field.md +180 -3
- package/dist/docs/components/hover-card.md +494 -0
- package/dist/docs/components/multi-select.md +622 -0
- package/dist/docs/components/number-field.md +1 -1
- package/dist/docs/components/popover.md +4 -4
- package/dist/docs/components/select.md +9 -1
- package/dist/docs/components/separator.md +182 -0
- package/dist/docs/components/slider.md +1 -1
- package/dist/docs/components/tooltip.md +1 -1
- package/dist/docs/concepts/experimental.md +3 -3
- package/dist/docs/concepts/server-components.md +1 -1
- package/dist/docs/index.md +7 -2
- package/dist/docs/roadmap.md +8 -0
- package/dist/field/field-control.d.mts +13 -4
- package/dist/field/field-control.d.mts.map +1 -1
- package/dist/field/field-control.mjs +39 -10
- package/dist/field/field-control.mjs.map +1 -1
- package/dist/field/field-label.d.mts +6 -2
- package/dist/field/field-label.d.mts.map +1 -1
- package/dist/field/field-label.mjs +12 -2
- package/dist/field/field-label.mjs.map +1 -1
- package/dist/field/field-root.mjs +9 -1
- package/dist/field/field-root.mjs.map +1 -1
- package/dist/hover-card/hover-card-context.mjs +13 -0
- package/dist/hover-card/hover-card-context.mjs.map +1 -0
- package/dist/hover-card/hover-card-popup.d.mts +102 -0
- package/dist/hover-card/hover-card-popup.d.mts.map +1 -0
- package/dist/hover-card/hover-card-popup.mjs +80 -0
- package/dist/hover-card/hover-card-popup.mjs.map +1 -0
- package/dist/hover-card/hover-card-root.d.mts +94 -0
- package/dist/hover-card/hover-card-root.d.mts.map +1 -0
- package/dist/hover-card/hover-card-root.mjs +74 -0
- package/dist/hover-card/hover-card-root.mjs.map +1 -0
- package/dist/hover-card/hover-card-trigger.d.mts +65 -0
- package/dist/hover-card/hover-card-trigger.d.mts.map +1 -0
- package/dist/hover-card/hover-card-trigger.mjs +109 -0
- package/dist/hover-card/hover-card-trigger.mjs.map +1 -0
- package/dist/hover-card/index.d.mts +24 -0
- package/dist/hover-card/index.d.mts.map +1 -0
- package/dist/hover-card/index.mjs +24 -0
- package/dist/hover-card/index.mjs.map +1 -0
- package/dist/hover-card/use-hover-card-interest.mjs +242 -0
- package/dist/hover-card/use-hover-card-interest.mjs.map +1 -0
- package/dist/index.d.mts +38 -9
- package/dist/index.mjs +6 -1
- package/dist/internal/action/use-multiple-selection.mjs +83 -0
- package/dist/internal/action/use-multiple-selection.mjs.map +1 -0
- package/dist/internal/details-summary.mjs +56 -0
- package/dist/internal/details-summary.mjs.map +1 -0
- package/dist/internal/form/field-context.mjs.map +1 -1
- package/dist/internal/form/hidden-values.mjs +29 -0
- package/dist/internal/form/hidden-values.mjs.map +1 -0
- package/dist/internal/form/validity.mjs +3 -1
- package/dist/internal/form/validity.mjs.map +1 -1
- package/dist/internal/overlay/use-interest-dismiss.mjs +2 -1
- package/dist/internal/overlay/use-interest-dismiss.mjs.map +1 -1
- package/dist/internal/overlay/use-overlay-close.mjs +5 -3
- package/dist/internal/overlay/use-overlay-close.mjs.map +1 -1
- package/dist/internal/overlay/use-overlay-root.mjs +4 -1
- package/dist/internal/overlay/use-overlay-root.mjs.map +1 -1
- package/dist/internal/overlay/use-popover-popup.mjs +20 -7
- package/dist/internal/overlay/use-popover-popup.mjs.map +1 -1
- package/dist/internal/overlay/use-popover-trigger.d.mts +1 -1
- package/dist/internal/typeahead.mjs +52 -0
- package/dist/internal/typeahead.mjs.map +1 -0
- package/dist/{combobox → internal}/use-active-option.mjs +8 -6
- package/dist/internal/use-active-option.mjs.map +1 -0
- package/dist/{combobox → internal}/use-deferred-leave.mjs +20 -12
- package/dist/internal/use-deferred-leave.mjs.map +1 -0
- package/dist/internal/use-name-warning.mjs +57 -1
- package/dist/internal/use-name-warning.mjs.map +1 -1
- package/dist/internal/use-option-registry.mjs +70 -0
- package/dist/internal/use-option-registry.mjs.map +1 -0
- package/dist/menu/use-menu-keyboard.mjs +7 -27
- package/dist/menu/use-menu-keyboard.mjs.map +1 -1
- package/dist/multi-select/index.d.mts +37 -0
- package/dist/multi-select/index.d.mts.map +1 -0
- package/dist/multi-select/index.mjs +37 -0
- package/dist/multi-select/index.mjs.map +1 -0
- package/dist/multi-select/multi-select-context.mjs +19 -0
- package/dist/multi-select/multi-select-context.mjs.map +1 -0
- package/dist/multi-select/multi-select-group.d.mts +120 -0
- package/dist/multi-select/multi-select-group.d.mts.map +1 -0
- package/dist/multi-select/multi-select-group.mjs +111 -0
- package/dist/multi-select/multi-select-group.mjs.map +1 -0
- package/dist/multi-select/multi-select-keyboard.mjs +145 -0
- package/dist/multi-select/multi-select-keyboard.mjs.map +1 -0
- package/dist/multi-select/multi-select-label.d.mts +42 -0
- package/dist/multi-select/multi-select-label.d.mts.map +1 -0
- package/dist/multi-select/multi-select-label.mjs +41 -0
- package/dist/multi-select/multi-select-label.mjs.map +1 -0
- package/dist/multi-select/multi-select-list.d.mts +47 -0
- package/dist/multi-select/multi-select-list.d.mts.map +1 -0
- package/dist/multi-select/multi-select-list.mjs +65 -0
- package/dist/multi-select/multi-select-list.mjs.map +1 -0
- package/dist/multi-select/multi-select-option.d.mts +68 -0
- package/dist/multi-select/multi-select-option.d.mts.map +1 -0
- package/dist/multi-select/multi-select-option.mjs +93 -0
- package/dist/multi-select/multi-select-option.mjs.map +1 -0
- package/dist/multi-select/multi-select-popup.d.mts +58 -0
- package/dist/multi-select/multi-select-popup.d.mts.map +1 -0
- package/dist/multi-select/multi-select-popup.mjs +71 -0
- package/dist/multi-select/multi-select-popup.mjs.map +1 -0
- package/dist/multi-select/multi-select-root.d.mts +125 -0
- package/dist/multi-select/multi-select-root.d.mts.map +1 -0
- package/dist/multi-select/multi-select-root.mjs +257 -0
- package/dist/multi-select/multi-select-root.mjs.map +1 -0
- package/dist/multi-select/multi-select-trigger.d.mts +66 -0
- package/dist/multi-select/multi-select-trigger.d.mts.map +1 -0
- package/dist/multi-select/multi-select-trigger.mjs +169 -0
- package/dist/multi-select/multi-select-trigger.mjs.map +1 -0
- package/dist/multi-select/multi-select-value.d.mts +57 -0
- package/dist/multi-select/multi-select-value.d.mts.map +1 -0
- package/dist/multi-select/multi-select-value.mjs +41 -0
- package/dist/multi-select/multi-select-value.mjs.map +1 -0
- package/dist/number-field/number-field-root.mjs +1 -1
- package/dist/number-field/use-step-button.d.mts.map +1 -1
- package/dist/number-field/use-step-button.mjs +11 -2
- package/dist/number-field/use-step-button.mjs.map +1 -1
- package/dist/popover/popover-close.d.mts +6 -3
- package/dist/popover/popover-close.d.mts.map +1 -1
- package/dist/popover/popover-close.mjs +3 -2
- package/dist/popover/popover-close.mjs.map +1 -1
- package/dist/popover/popover-popup.mjs +1 -1
- package/dist/select/select-root.d.mts +1 -1
- package/dist/select/select-root.d.mts.map +1 -1
- package/dist/select/select-root.mjs +5 -1
- package/dist/select/select-root.mjs.map +1 -1
- package/dist/separator/index.d.mts +3 -0
- package/dist/separator/index.mjs +1 -0
- package/dist/separator/separator.d.mts +58 -0
- package/dist/separator/separator.d.mts.map +1 -0
- package/dist/separator/separator.mjs +41 -0
- package/dist/separator/separator.mjs.map +1 -0
- package/dist/slider/slider-root.mjs +1 -0
- package/dist/slider/slider-root.mjs.map +1 -1
- package/dist/toast/toast-viewport.mjs +1 -1
- package/package.json +6 -1
- package/skills/funstack-ui-knowledge/SKILL.md +14 -9
- package/dist/combobox/use-active-option.mjs.map +0 -1
- package/dist/combobox/use-deferred-leave.mjs.map +0 -1
- package/dist/combobox/use-option-registry.mjs +0 -52
- package/dist/combobox/use-option-registry.mjs.map +0 -1
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { createActionDetails } from "../internal/action/action-details.mjs";
|
|
3
|
+
import { dataAttr } from "../internal/data-attr.mjs";
|
|
4
|
+
import { useDevWarning } from "../internal/use-dev-warning.mjs";
|
|
5
|
+
import { useTransitionBoundary } from "../internal/transition-boundary.mjs";
|
|
6
|
+
import { resolveStateValue } from "../internal/render-element.mjs";
|
|
7
|
+
import { useRender } from "../internal/use-render.mjs";
|
|
8
|
+
import { transitionTypes } from "../internal/transition-types.mjs";
|
|
9
|
+
import { intendedValue, useControllableAction } from "../internal/action/use-controllable-action.mjs";
|
|
10
|
+
import { useMountFixed } from "../internal/use-mount-fixed.mjs";
|
|
11
|
+
import { useDetailsCheck } from "../internal/details-summary.mjs";
|
|
12
|
+
import { CollapsibleContext } from "./collapsible-context.mjs";
|
|
13
|
+
import { useCallback, useEffectEvent, useLayoutEffect, useMemo, useRef } from "react";
|
|
14
|
+
import { jsx } from "react/jsx-runtime";
|
|
15
|
+
//#region src/collapsible/collapsible-root.tsx
|
|
16
|
+
const isDev = process.env.NODE_ENV !== "production";
|
|
17
|
+
/** Writes `open` to the DOM; it fires `toggle`, whose handler sees DOM === committed and returns. */
|
|
18
|
+
function applyOpen(element, open) {
|
|
19
|
+
if (element.open !== open) element.open = open;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* One disclosure: the `<details>` element, which owns the open state and the transition. In
|
|
23
|
+
* library mode its `open` attribute follows committed state and `data-open` / `data-pending`
|
|
24
|
+
* follow optimistic state; in JS-free mode the browser owns `open`.
|
|
25
|
+
*
|
|
26
|
+
* @see https://ui.funstack.work/components/collapsible
|
|
27
|
+
*/
|
|
28
|
+
function CollapsibleRoot({ open, defaultOpen, openChangeAction, disabled = false, experimental_interpolateSize = false, transition, className, style, children, render, ...rest }) {
|
|
29
|
+
const isLibrary = useMountFixed(open !== void 0 || defaultOpen !== void 0 || openChangeAction !== void 0, isDev && "Collapsible.Root: the mode changed after mount (`open`, `defaultOpen` and `openChangeAction` were all absent on one render and present on another). Switching between JS-free and library mode is not supported.");
|
|
30
|
+
const { committed, optimistic, pending, dispatch, latestInFlight } = useControllableAction({
|
|
31
|
+
controlled: open,
|
|
32
|
+
defaultValue: defaultOpen,
|
|
33
|
+
initialValue: false,
|
|
34
|
+
action: openChangeAction,
|
|
35
|
+
transitionTypes: (next) => transitionTypes("collapsible", next ? "expand" : "collapse"),
|
|
36
|
+
warn: {
|
|
37
|
+
component: "Collapsible.Root",
|
|
38
|
+
prop: "open"
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
useDevWarning(!isLibrary && transition !== void 0, isDev && "Collapsible.Root: `transition` has no effect in JS-free mode; the browser toggles the <details> outside any React transition. Animate `::details-content` with CSS instead.");
|
|
42
|
+
const detailsRef = useRef(null);
|
|
43
|
+
const checkElement = useDetailsCheck("Collapsible.Root", isDev && "toggle, find-in-page, ::details-content");
|
|
44
|
+
const libraryRef = useCallback((element) => {
|
|
45
|
+
checkElement?.(element);
|
|
46
|
+
detailsRef.current = element;
|
|
47
|
+
return () => {
|
|
48
|
+
detailsRef.current = null;
|
|
49
|
+
};
|
|
50
|
+
}, [checkElement]);
|
|
51
|
+
const dispatchActivate = useCallback((next, event) => {
|
|
52
|
+
dispatch(next, createActionDetails(event, { reason: "activate" }));
|
|
53
|
+
}, [dispatch]);
|
|
54
|
+
/**
|
|
55
|
+
* The browser set `details.open` to `next` (design 2.2). Builds on what the user already
|
|
56
|
+
* intends (the latest in-flight dispatch, else the optimistic value), never on the DOM: a
|
|
57
|
+
* reveal equal to it dispatches nothing.
|
|
58
|
+
*/
|
|
59
|
+
const dispatchFromDom = (next, event) => {
|
|
60
|
+
if (next === intendedValue(latestInFlight, optimistic)) return;
|
|
61
|
+
dispatch(next, createActionDetails(event, { reason: "platform" }));
|
|
62
|
+
};
|
|
63
|
+
const onToggle = isLibrary ? (event) => {
|
|
64
|
+
const element = event.currentTarget;
|
|
65
|
+
if (element.open === committed) return;
|
|
66
|
+
if (disabled) {
|
|
67
|
+
if (!pending) applyOpen(element, committed);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
dispatchFromDom(element.open, event.nativeEvent);
|
|
71
|
+
} : void 0;
|
|
72
|
+
const reconcileOnMount = useEffectEvent(() => {
|
|
73
|
+
const element = detailsRef.current;
|
|
74
|
+
if (element === null || element.open === committed) return;
|
|
75
|
+
if (disabled) applyOpen(element, committed);
|
|
76
|
+
else dispatchFromDom(element.open, void 0);
|
|
77
|
+
});
|
|
78
|
+
useLayoutEffect(() => {
|
|
79
|
+
if (isLibrary) reconcileOnMount();
|
|
80
|
+
}, [isLibrary]);
|
|
81
|
+
useLayoutEffect(() => {
|
|
82
|
+
if (!isLibrary || pending || latestInFlight() !== null) return;
|
|
83
|
+
const element = detailsRef.current;
|
|
84
|
+
if (element !== null) applyOpen(element, committed);
|
|
85
|
+
}, [
|
|
86
|
+
isLibrary,
|
|
87
|
+
pending,
|
|
88
|
+
committed,
|
|
89
|
+
latestInFlight
|
|
90
|
+
]);
|
|
91
|
+
const committedOpen = isLibrary ? committed : void 0;
|
|
92
|
+
const optimisticOpen = isLibrary ? optimistic : void 0;
|
|
93
|
+
const rootPending = isLibrary && pending;
|
|
94
|
+
const state = {
|
|
95
|
+
open: optimisticOpen,
|
|
96
|
+
pending: rootPending,
|
|
97
|
+
disabled
|
|
98
|
+
};
|
|
99
|
+
const context = useMemo(() => ({
|
|
100
|
+
library: isLibrary,
|
|
101
|
+
disabled,
|
|
102
|
+
pending: rootPending,
|
|
103
|
+
committedOpen,
|
|
104
|
+
optimisticOpen,
|
|
105
|
+
dispatch: dispatchActivate
|
|
106
|
+
}), [
|
|
107
|
+
isLibrary,
|
|
108
|
+
disabled,
|
|
109
|
+
rootPending,
|
|
110
|
+
committedOpen,
|
|
111
|
+
optimisticOpen,
|
|
112
|
+
dispatchActivate
|
|
113
|
+
]);
|
|
114
|
+
const resolvedStyle = resolveStateValue(style, state);
|
|
115
|
+
const finalStyle = experimental_interpolateSize ? {
|
|
116
|
+
interpolateSize: "allow-keywords",
|
|
117
|
+
...resolvedStyle
|
|
118
|
+
} : resolvedStyle;
|
|
119
|
+
const element = useRender({
|
|
120
|
+
defaultElement: "details",
|
|
121
|
+
render,
|
|
122
|
+
state,
|
|
123
|
+
className,
|
|
124
|
+
style: finalStyle,
|
|
125
|
+
children,
|
|
126
|
+
ref: libraryRef,
|
|
127
|
+
props: rest,
|
|
128
|
+
libraryProps: {
|
|
129
|
+
open: isLibrary ? committed : false,
|
|
130
|
+
suppressHydrationWarning: true,
|
|
131
|
+
name: void 0,
|
|
132
|
+
...isLibrary && { onToggle },
|
|
133
|
+
"data-open": dataAttr(optimisticOpen === true),
|
|
134
|
+
"data-pending": dataAttr(rootPending),
|
|
135
|
+
"data-disabled": dataAttr(disabled)
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
return useTransitionBoundary("Collapsible.Root", isLibrary ? transition : void 0, /* @__PURE__ */ jsx(CollapsibleContext, {
|
|
139
|
+
value: context,
|
|
140
|
+
children: element
|
|
141
|
+
}));
|
|
142
|
+
}
|
|
143
|
+
CollapsibleRoot.displayName = "CollapsibleRoot";
|
|
144
|
+
//#endregion
|
|
145
|
+
export { CollapsibleRoot };
|
|
146
|
+
|
|
147
|
+
//# sourceMappingURL=collapsible-root.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collapsible-root.mjs","names":[],"sources":["../../src/collapsible/collapsible-root.tsx"],"sourcesContent":["\"use client\";\nimport { useCallback, useEffectEvent, useLayoutEffect, useMemo, useRef } from \"react\";\nimport type {\n ComponentPropsWithRef,\n CSSProperties,\n ReactNode,\n SyntheticEvent,\n ViewTransitionClass,\n} from \"react\";\nimport { createActionDetails } from \"../internal/action/action-details.js\";\nimport {\n intendedValue,\n useControllableAction,\n} from \"../internal/action/use-controllable-action.js\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport { useDetailsCheck } from \"../internal/details-summary.js\";\nimport { useTransitionBoundary } from \"../internal/transition-boundary.js\";\nimport { transitionTypes } from \"../internal/transition-types.js\";\nimport type {\n ActionDetails,\n ChangeAction,\n ChangeReason,\n RenderProp,\n StateValue,\n} from \"../internal/types.js\";\nimport { useDevWarning } from \"../internal/use-dev-warning.js\";\nimport { useMountFixed } from \"../internal/use-mount-fixed.js\";\nimport { resolveStateValue, useRender } from \"../internal/use-render.js\";\nimport { CollapsibleContext } from \"./collapsible-context.js\";\nimport type { CollapsibleContextValue } from \"./collapsible-context.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/**\n * State of `Collapsible.Root`, passed to the function forms of `className`, `style`, `children`\n * and `render`.\n */\nexport interface CollapsibleRootState {\n /** Optimistic open state. `undefined` in JS-free mode (browser-owned, unknown to React). */\n readonly open: boolean | undefined;\n /** An action dispatched through this Collapsible is in flight (library mode only). */\n readonly pending: boolean;\n /** The Root's `disabled` prop. */\n readonly disabled: boolean;\n}\n\n/** Details passed as the second argument of `openChangeAction`. */\nexport interface CollapsibleOpenChangeDetails extends ActionDetails {\n /**\n * The shared vocabulary (conventions 2.2); Collapsible dispatches two of its values.\n * `\"activate\"`: the user activated the Trigger. `\"platform\"`: the browser changed `open` itself\n * (find-in-page, a text fragment, a click before hydration); `event` is then the `toggle`\n * event, or `undefined` when the mismatch was found on mount.\n */\n readonly reason: ChangeReason;\n}\n\n/**\n * Props of `Collapsible.Root`.\n *\n * Without `open`, `defaultOpen` and `openChangeAction` the Collapsible runs in **JS-free mode**:\n * the browser owns `<details open>` and nothing runs on toggle. With any of them it runs in\n * **library mode**: the summary click is intercepted, `open` follows committed state inside a\n * transition, and the Root and Trigger show optimistic `data-open`.\n *\n * @see https://ui.funstack.work/components/collapsible\n */\nexport interface CollapsibleRootProps extends Omit<\n ComponentPropsWithRef<\"details\">,\n \"open\" | \"name\" | \"onToggle\" | \"className\" | \"style\" | \"children\"\n> {\n /** Controlled open state. `undefined` means uncontrolled. Selects library mode. */\n open?: boolean;\n /**\n * Initial open state, uncontrolled. Read once. Its presence selects library mode,\n * `defaultOpen={false}` included. Library mode without it (`open` or `openChangeAction` only)\n * starts closed, as `false`.\n *\n * @defaultValue none (JS-free mode)\n */\n defaultOpen?: boolean;\n /**\n * Called with the next open state on every change, inside the Root's transition; may be sync or\n * async (also a Server Function). Rejections reach the nearest Error Boundary. Selects library\n * mode.\n *\n * Also called with `details.reason === \"platform\"` when the browser opened or closed the\n * `<details>` itself (find-in-page, a click before hydration). The revealed content stays\n * visible while the action runs; if a controlled parent does not adopt the change, committed\n * state is re-applied to the DOM (closed again) once the action settles. A rejection goes to the\n * Error Boundary like any other.\n *\n * A `setState` placed after your own `await` is not a Transition update; wrap it in\n * `startTransition` (React limitation).\n */\n openChangeAction?: ChangeAction<boolean, CollapsibleOpenChangeDetails>;\n /**\n * The Trigger renders `aria-disabled` and never toggles. Enforced by a click handler, so in\n * JS-free mode it does not hold before hydration or with JS off.\n *\n * @defaultValue `false`\n */\n disabled?: boolean;\n /**\n * Renders `interpolate-size: allow-keywords` on the `<details>` so `::details-content` can\n * transition `height` to `auto`. Chromium-only polish today; use the `grid-template-rows` form\n * for a cross-engine animation. Merged with `style`; the consumer's declaration wins.\n *\n * @defaultValue `false`\n */\n experimental_interpolateSize?: boolean;\n /**\n * Library mode only. Forwarded as `default` to the `<ViewTransition>` around the `<details>`;\n * animates the commit that ends an action (the `open` attribute flip), not the optimistic\n * `data-open` flip. Ignored (dev warning) in JS-free mode.\n *\n * Static: setting or unsetting it remounts the element. Any value, `\"none\"` included, makes a\n * mount or `<Activity>` reveal inside a transition start a document view transition (a ~250 ms\n * page cross-fade that the next transition waits for).\n */\n transition?: ViewTransitionClass;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, CollapsibleRootState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, CollapsibleRootState>;\n /** Content, or a function of the part's state. The Trigger must be the first child. */\n children?: StateValue<ReactNode, CollapsibleRootState>;\n /** Must render a `<details>` element. */\n render?: RenderProp<ComponentPropsWithRef<\"details\">, CollapsibleRootState>;\n}\n\n/** Writes `open` to the DOM; it fires `toggle`, whose handler sees DOM === committed and returns. */\nfunction applyOpen(element: HTMLDetailsElement, open: boolean): void {\n if (element.open !== open) element.open = open;\n}\n\n/**\n * One disclosure: the `<details>` element, which owns the open state and the transition. In\n * library mode its `open` attribute follows committed state and `data-open` / `data-pending`\n * follow optimistic state; in JS-free mode the browser owns `open`.\n *\n * @see https://ui.funstack.work/components/collapsible\n */\nexport function CollapsibleRoot({\n open,\n defaultOpen,\n openChangeAction,\n disabled = false,\n experimental_interpolateSize = false,\n transition,\n className,\n style,\n children,\n render,\n ...rest\n}: CollapsibleRootProps) {\n // Mode is decided once, from the first render's props (design 2).\n const isLibraryNow =\n open !== undefined || defaultOpen !== undefined || openChangeAction !== undefined;\n const isLibrary = useMountFixed(\n isLibraryNow,\n isDev &&\n \"Collapsible.Root: the mode changed after mount (`open`, `defaultOpen` and \" +\n \"`openChangeAction` were all absent on one render and present on another). Switching \" +\n \"between JS-free and library mode is not supported.\",\n );\n\n const { committed, optimistic, pending, dispatch, latestInFlight } = useControllableAction<\n boolean,\n CollapsibleOpenChangeDetails\n >({\n controlled: open,\n defaultValue: defaultOpen,\n initialValue: false,\n action: openChangeAction,\n transitionTypes: (next) => transitionTypes(\"collapsible\", next ? \"expand\" : \"collapse\"),\n // Single-valued: no reducer, latest dispatch wins (design 4.1).\n warn: { component: \"Collapsible.Root\", prop: \"open\" },\n });\n\n useDevWarning(\n !isLibrary && transition !== undefined,\n isDev &&\n \"Collapsible.Root: `transition` has no effect in JS-free mode; the browser toggles the \" +\n \"<details> outside any React transition. Animate `::details-content` with CSS instead.\",\n );\n\n const detailsRef = useRef<HTMLDetailsElement | null>(null);\n const checkElement = useDetailsCheck(\n \"Collapsible.Root\",\n isDev && \"toggle, find-in-page, ::details-content\",\n );\n const libraryRef = useCallback(\n (element: HTMLDetailsElement) => {\n checkElement?.(element);\n detailsRef.current = element;\n return () => {\n detailsRef.current = null;\n };\n },\n [checkElement],\n );\n\n const dispatchActivate = useCallback<CollapsibleContextValue[\"dispatch\"]>(\n (next, event) => {\n dispatch(next, createActionDetails(event, { reason: \"activate\" }));\n },\n [dispatch],\n );\n\n /**\n * The browser set `details.open` to `next` (design 2.2). Builds on what the user already\n * intends (the latest in-flight dispatch, else the optimistic value), never on the DOM: a\n * reveal equal to it dispatches nothing.\n */\n const dispatchFromDom = (next: boolean, event: Event | undefined): void => {\n if (next === intendedValue(latestInFlight, optimistic)) return;\n dispatch(next, createActionDetails(event, { reason: \"platform\" }));\n };\n\n // Platform path (design 2.2): find-in-page, a text fragment or a script flipped `open`.\n const onToggle = isLibrary\n ? (event: SyntheticEvent<HTMLDetailsElement>) => {\n const element = event.currentTarget;\n // Read `details.open`, never `ToggleEvent.newState`: `toggle` is coalesced.\n if (element.open === committed) return; // our own commit echoing back\n if (disabled) {\n // A disabled Collapsible cannot be opened by the browser either; close it again now or,\n // while an action is in flight, when the re-apply effect below runs.\n if (!pending) applyOpen(element, committed);\n return;\n }\n dispatchFromDom(element.open, event.nativeEvent);\n }\n : undefined;\n\n // Mount reconciliation (design 2.2): a click before hydration left `<details open>` out of step\n // with committed state. One dispatch with reason \"platform\" and no event; a disabled Root is\n // simply put back. Runs at mount and again when an `<Activity>` re-shows the Root; the\n // StrictMode re-run is deduplicated against the dispatch just made (intended value).\n const reconcileOnMount = useEffectEvent(() => {\n const element = detailsRef.current;\n if (element === null || element.open === committed) return;\n if (disabled) applyOpen(element, committed);\n else dispatchFromDom(element.open, undefined);\n });\n useLayoutEffect(() => {\n if (isLibrary) reconcileOnMount();\n }, [isLibrary]);\n\n // Re-apply committed state to the DOM once nothing is in flight: closes what find-in-page\n // revealed and the parent refused, or what a rejected action left open.\n useLayoutEffect(() => {\n if (!isLibrary || pending || latestInFlight() !== null) return;\n const element = detailsRef.current;\n if (element !== null) applyOpen(element, committed);\n }, [isLibrary, pending, committed, latestInFlight]);\n\n const committedOpen = isLibrary ? committed : undefined;\n const optimisticOpen = isLibrary ? optimistic : undefined;\n const rootPending = isLibrary && pending;\n const state: CollapsibleRootState = { open: optimisticOpen, pending: rootPending, disabled };\n\n // Memoised: the Trigger and Panel re-render only when one of these changes.\n const context = useMemo<CollapsibleContextValue>(\n () => ({\n library: isLibrary,\n disabled,\n pending: rootPending,\n committedOpen,\n optimisticOpen,\n dispatch: dispatchActivate,\n }),\n [isLibrary, disabled, rootPending, committedOpen, optimisticOpen, dispatchActivate],\n );\n\n const resolvedStyle = resolveStateValue(style, state);\n const finalStyle: CSSProperties | undefined = experimental_interpolateSize\n ? { interpolateSize: \"allow-keywords\", ...resolvedStyle }\n : resolvedStyle;\n\n const element = useRender<ComponentPropsWithRef<\"details\">, CollapsibleRootState>({\n defaultElement: \"details\",\n render,\n state,\n className,\n style: finalStyle,\n children,\n ref: libraryRef,\n props: rest,\n // Library-controlled layer: `open`, `name` and `onToggle` are owned by the library in at\n // least one mode, so a `render` element cannot override them either (conventions 1.2).\n libraryProps: {\n // JS-free mode: always `false`, so React never rewrites the attribute the browser owns.\n open: isLibrary ? committed : false,\n // A click before hydration changes `open` under React's feet in both modes; the mismatch is\n // expected and reconciled (library mode) or the browser's business (JS-free mode).\n suppressHydrationWarning: true,\n // A second, platform-level writer of `open`; an exclusive group is `Accordion.Root exclusive`.\n name: undefined,\n // Only installed in library mode; owning the key in JS-free mode would strip a render\n // element's own `onToggle`.\n ...(isLibrary && { onToggle }),\n \"data-open\": dataAttr(optimisticOpen === true),\n \"data-pending\": dataAttr(rootPending),\n \"data-disabled\": dataAttr(disabled),\n },\n });\n\n return useTransitionBoundary(\n \"Collapsible.Root\",\n isLibrary ? transition : undefined,\n <CollapsibleContext value={context}>{element}</CollapsibleContext>,\n );\n}\n\nCollapsibleRoot.displayName = \"CollapsibleRoot\";\n"],"mappings":";;;;;;;;;;;;;;;AA+BA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;AAqGvC,SAAS,UAAU,SAA6B,MAAqB;CACnE,IAAI,QAAQ,SAAS,MAAM,QAAQ,OAAO;AAC5C;;;;;;;;AASA,SAAgB,gBAAgB,EAC9B,MACA,aACA,kBACA,WAAW,OACX,+BAA+B,OAC/B,YACA,WACA,OACA,UACA,QACA,GAAG,QACoB;CAIvB,MAAM,YAAY,cADhB,SAAS,KAAA,KAAa,gBAAgB,KAAA,KAAa,qBAAqB,KAAA,GAGxE,SACE,kNAGJ;CAEA,MAAM,EAAE,WAAW,YAAY,SAAS,UAAU,mBAAmB,sBAGnE;EACA,YAAY;EACZ,cAAc;EACd,cAAc;EACd,QAAQ;EACR,kBAAkB,SAAS,gBAAgB,eAAe,OAAO,WAAW,UAAU;EAEtF,MAAM;GAAE,WAAW;GAAoB,MAAM;EAAO;CACtD,CAAC;CAED,cACE,CAAC,aAAa,eAAe,KAAA,GAC7B,SACE,6KAEJ;CAEA,MAAM,aAAa,OAAkC,IAAI;CACzD,MAAM,eAAe,gBACnB,oBACA,SAAS,yCACX;CACA,MAAM,aAAa,aAChB,YAAgC;EAC/B,eAAe,OAAO;EACtB,WAAW,UAAU;EACrB,aAAa;GACX,WAAW,UAAU;EACvB;CACF,GACA,CAAC,YAAY,CACf;CAEA,MAAM,mBAAmB,aACtB,MAAM,UAAU;EACf,SAAS,MAAM,oBAAoB,OAAO,EAAE,QAAQ,WAAW,CAAC,CAAC;CACnE,GACA,CAAC,QAAQ,CACX;;;;;;CAOA,MAAM,mBAAmB,MAAe,UAAmC;EACzE,IAAI,SAAS,cAAc,gBAAgB,UAAU,GAAG;EACxD,SAAS,MAAM,oBAAoB,OAAO,EAAE,QAAQ,WAAW,CAAC,CAAC;CACnE;CAGA,MAAM,WAAW,aACZ,UAA8C;EAC7C,MAAM,UAAU,MAAM;EAEtB,IAAI,QAAQ,SAAS,WAAW;EAChC,IAAI,UAAU;GAGZ,IAAI,CAAC,SAAS,UAAU,SAAS,SAAS;GAC1C;EACF;EACA,gBAAgB,QAAQ,MAAM,MAAM,WAAW;CACjD,IACA,KAAA;CAMJ,MAAM,mBAAmB,qBAAqB;EAC5C,MAAM,UAAU,WAAW;EAC3B,IAAI,YAAY,QAAQ,QAAQ,SAAS,WAAW;EACpD,IAAI,UAAU,UAAU,SAAS,SAAS;OACrC,gBAAgB,QAAQ,MAAM,KAAA,CAAS;CAC9C,CAAC;CACD,sBAAsB;EACpB,IAAI,WAAW,iBAAiB;CAClC,GAAG,CAAC,SAAS,CAAC;CAId,sBAAsB;EACpB,IAAI,CAAC,aAAa,WAAW,eAAe,MAAM,MAAM;EACxD,MAAM,UAAU,WAAW;EAC3B,IAAI,YAAY,MAAM,UAAU,SAAS,SAAS;CACpD,GAAG;EAAC;EAAW;EAAS;EAAW;CAAc,CAAC;CAElD,MAAM,gBAAgB,YAAY,YAAY,KAAA;CAC9C,MAAM,iBAAiB,YAAY,aAAa,KAAA;CAChD,MAAM,cAAc,aAAa;CACjC,MAAM,QAA8B;EAAE,MAAM;EAAgB,SAAS;EAAa;CAAS;CAG3F,MAAM,UAAU,eACP;EACL,SAAS;EACT;EACA,SAAS;EACT;EACA;EACA,UAAU;CACZ,IACA;EAAC;EAAW;EAAU;EAAa;EAAe;EAAgB;CAAgB,CACpF;CAEA,MAAM,gBAAgB,kBAAkB,OAAO,KAAK;CACpD,MAAM,aAAwC,+BAC1C;EAAE,iBAAiB;EAAkB,GAAG;CAAc,IACtD;CAEJ,MAAM,UAAU,UAAkE;EAChF,gBAAgB;EAChB;EACA;EACA;EACA,OAAO;EACP;EACA,KAAK;EACL,OAAO;EAGP,cAAc;GAEZ,MAAM,YAAY,YAAY;GAG9B,0BAA0B;GAE1B,MAAM,KAAA;GAGN,GAAI,aAAa,EAAE,SAAS;GAC5B,aAAa,SAAS,mBAAmB,IAAI;GAC7C,gBAAgB,SAAS,WAAW;GACpC,iBAAiB,SAAS,QAAQ;EACpC;CACF,CAAC;CAED,OAAO,sBACL,oBACA,YAAY,aAAa,KAAA,GACzB,oBAAC,oBAAD;EAAoB,OAAO;EAAU,UAAA;CAA4B,CAAA,CACnE;AACF;AAEA,gBAAgB,cAAc"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { RenderProp, StateValue } from "../internal/types.mjs";
|
|
2
|
+
import { CollapsibleRootState } from "./collapsible-root.mjs";
|
|
3
|
+
import { CSSProperties, ComponentPropsWithRef, ReactNode, ViewTransitionClass } from "react";
|
|
4
|
+
//#region src/collapsible/collapsible-trigger.d.ts
|
|
5
|
+
/** The trigger is the Root's control; it renders the Root's state object. */
|
|
6
|
+
export type CollapsibleTriggerState = CollapsibleRootState;
|
|
7
|
+
/**
|
|
8
|
+
* Props of `Collapsible.Trigger`.
|
|
9
|
+
*
|
|
10
|
+
* @see https://ui.funstack.work/components/collapsible
|
|
11
|
+
*/
|
|
12
|
+
export interface CollapsibleTriggerProps extends Omit<ComponentPropsWithRef<"summary">, "onClick" | "className" | "style" | "children"> {
|
|
13
|
+
/**
|
|
14
|
+
* Library mode only. Forwarded as `default` to the `<ViewTransition>` around the `<summary>`.
|
|
15
|
+
* Animates only the commit that ends an action (for example a spinner rendered from `pending`
|
|
16
|
+
* disappearing); the optimistic `data-open` flip is a CSS job.
|
|
17
|
+
*
|
|
18
|
+
* Static: setting or unsetting it remounts the element. Any value, `"none"` included, makes a
|
|
19
|
+
* mount or `<Activity>` reveal inside a transition start a document view transition (a ~250 ms
|
|
20
|
+
* page cross-fade that the next transition waits for).
|
|
21
|
+
*/
|
|
22
|
+
transition?: ViewTransitionClass;
|
|
23
|
+
/** Class name, or a function of the part's state that returns one. */
|
|
24
|
+
className?: StateValue<string | undefined, CollapsibleTriggerState>;
|
|
25
|
+
/** Inline style, or a function of the part's state that returns one. */
|
|
26
|
+
style?: StateValue<CSSProperties | undefined, CollapsibleTriggerState>;
|
|
27
|
+
/** Rendered from optimistic state; must not suspend. */
|
|
28
|
+
children?: StateValue<ReactNode, CollapsibleTriggerState>;
|
|
29
|
+
/** Must render a `<summary>` element. */
|
|
30
|
+
render?: RenderProp<ComponentPropsWithRef<"summary">, CollapsibleTriggerState>;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The disclosure control: the `<summary>`, which must be the first child of the Root. In library
|
|
34
|
+
* mode the click is intercepted and dispatched through the Root's transition; the element shows
|
|
35
|
+
* optimistic `data-open` and `data-pending`. The platform forbids `aria-expanded` on a summary,
|
|
36
|
+
* so assistive technology hears the committed state (from `<details open>`).
|
|
37
|
+
*
|
|
38
|
+
* @see https://ui.funstack.work/components/collapsible
|
|
39
|
+
*/
|
|
40
|
+
export declare function CollapsibleTrigger({ transition, className, style, children, render, ...rest }: CollapsibleTriggerProps): ReactNode;
|
|
41
|
+
export declare namespace CollapsibleTrigger {
|
|
42
|
+
var displayName: string;
|
|
43
|
+
}
|
|
44
|
+
//#endregion
|
|
45
|
+
//# sourceMappingURL=collapsible-trigger.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collapsible-trigger.d.mts","names":[],"sources":["../../src/collapsible/collapsible-trigger.tsx"],"mappings":";;;;;YAqBY,0BAA0B;;;;;;iBAOrB,gCAAgC,KAC/C;;;;;;;;;;EAYA,aAAa;;EAEb,YAAY,+BAA+B;;EAE3C,QAAQ,WAAW,2BAA2B;;EAE9C,WAAW,WAAW,WAAW;;EAEjC,SAAS,WAAW,kCAAkC;;;;;;;;;;wBAWxC,qBACd,YACA,WACA,OACA,UACA,WACG,QACF,0BAAuB;yBAPV"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { dataAttr } from "../internal/data-attr.mjs";
|
|
3
|
+
import { useDevWarning } from "../internal/use-dev-warning.mjs";
|
|
4
|
+
import { useTransitionBoundary } from "../internal/transition-boundary.mjs";
|
|
5
|
+
import { useRender } from "../internal/use-render.mjs";
|
|
6
|
+
import { interceptSummaryClick, useSummaryCheck } from "../internal/details-summary.mjs";
|
|
7
|
+
import { CollapsibleContext } from "./collapsible-context.mjs";
|
|
8
|
+
import { use, useCallback } from "react";
|
|
9
|
+
//#region src/collapsible/collapsible-trigger.tsx
|
|
10
|
+
const isDev = process.env.NODE_ENV !== "production";
|
|
11
|
+
/**
|
|
12
|
+
* The disclosure control: the `<summary>`, which must be the first child of the Root. In library
|
|
13
|
+
* mode the click is intercepted and dispatched through the Root's transition; the element shows
|
|
14
|
+
* optimistic `data-open` and `data-pending`. The platform forbids `aria-expanded` on a summary,
|
|
15
|
+
* so assistive technology hears the committed state (from `<details open>`).
|
|
16
|
+
*
|
|
17
|
+
* @see https://ui.funstack.work/components/collapsible
|
|
18
|
+
*/
|
|
19
|
+
function CollapsibleTrigger({ transition, className, style, children, render, ...rest }) {
|
|
20
|
+
const root = use(CollapsibleContext);
|
|
21
|
+
if (root === null) throw new Error("Collapsible.Trigger must be rendered inside a Collapsible.Root.");
|
|
22
|
+
const isLibrary = root.library;
|
|
23
|
+
useDevWarning(!isLibrary && transition !== void 0, isDev && "Collapsible.Trigger: `transition` has no effect in JS-free mode; the browser toggles the <details> outside any React transition.");
|
|
24
|
+
const checkElement = useSummaryCheck("Collapsible.Trigger");
|
|
25
|
+
const libraryRef = useCallback((element) => {
|
|
26
|
+
checkElement?.(element);
|
|
27
|
+
return () => {};
|
|
28
|
+
}, [checkElement]);
|
|
29
|
+
const state = {
|
|
30
|
+
open: root.optimisticOpen,
|
|
31
|
+
pending: root.pending,
|
|
32
|
+
disabled: root.disabled
|
|
33
|
+
};
|
|
34
|
+
const onClick = isLibrary || root.disabled ? (event) => {
|
|
35
|
+
if (!interceptSummaryClick(event)) return;
|
|
36
|
+
if (root.disabled || !isLibrary) return;
|
|
37
|
+
root.dispatch(!root.optimisticOpen, event.nativeEvent);
|
|
38
|
+
} : void 0;
|
|
39
|
+
const element = useRender({
|
|
40
|
+
defaultElement: "summary",
|
|
41
|
+
render,
|
|
42
|
+
state,
|
|
43
|
+
className,
|
|
44
|
+
style,
|
|
45
|
+
children,
|
|
46
|
+
ref: libraryRef,
|
|
47
|
+
props: rest,
|
|
48
|
+
libraryProps: {
|
|
49
|
+
"aria-disabled": root.disabled ? true : void 0,
|
|
50
|
+
"data-open": dataAttr(root.optimisticOpen === true),
|
|
51
|
+
"data-pending": dataAttr(root.pending),
|
|
52
|
+
"data-disabled": dataAttr(root.disabled),
|
|
53
|
+
...onClick && { onClick }
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
return useTransitionBoundary("Collapsible.Trigger", isLibrary ? transition : void 0, element);
|
|
57
|
+
}
|
|
58
|
+
CollapsibleTrigger.displayName = "CollapsibleTrigger";
|
|
59
|
+
//#endregion
|
|
60
|
+
export { CollapsibleTrigger };
|
|
61
|
+
|
|
62
|
+
//# sourceMappingURL=collapsible-trigger.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collapsible-trigger.mjs","names":[],"sources":["../../src/collapsible/collapsible-trigger.tsx"],"sourcesContent":["\"use client\";\nimport { use, useCallback } from \"react\";\nimport type {\n ComponentPropsWithRef,\n CSSProperties,\n MouseEvent,\n ReactNode,\n ViewTransitionClass,\n} from \"react\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport { interceptSummaryClick, useSummaryCheck } from \"../internal/details-summary.js\";\nimport { useTransitionBoundary } from \"../internal/transition-boundary.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useDevWarning } from \"../internal/use-dev-warning.js\";\nimport { useRender } from \"../internal/use-render.js\";\nimport { CollapsibleContext } from \"./collapsible-context.js\";\nimport type { CollapsibleRootState } from \"./collapsible-root.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/** The trigger is the Root's control; it renders the Root's state object. */\nexport type CollapsibleTriggerState = CollapsibleRootState;\n\n/**\n * Props of `Collapsible.Trigger`.\n *\n * @see https://ui.funstack.work/components/collapsible\n */\nexport interface CollapsibleTriggerProps extends Omit<\n ComponentPropsWithRef<\"summary\">,\n \"onClick\" | \"className\" | \"style\" | \"children\"\n> {\n /**\n * Library mode only. Forwarded as `default` to the `<ViewTransition>` around the `<summary>`.\n * Animates only the commit that ends an action (for example a spinner rendered from `pending`\n * disappearing); the optimistic `data-open` flip is a CSS job.\n *\n * Static: setting or unsetting it remounts the element. Any value, `\"none\"` included, makes a\n * mount or `<Activity>` reveal inside a transition start a document view transition (a ~250 ms\n * page cross-fade that the next transition waits for).\n */\n transition?: ViewTransitionClass;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, CollapsibleTriggerState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, CollapsibleTriggerState>;\n /** Rendered from optimistic state; must not suspend. */\n children?: StateValue<ReactNode, CollapsibleTriggerState>;\n /** Must render a `<summary>` element. */\n render?: RenderProp<ComponentPropsWithRef<\"summary\">, CollapsibleTriggerState>;\n}\n\n/**\n * The disclosure control: the `<summary>`, which must be the first child of the Root. In library\n * mode the click is intercepted and dispatched through the Root's transition; the element shows\n * optimistic `data-open` and `data-pending`. The platform forbids `aria-expanded` on a summary,\n * so assistive technology hears the committed state (from `<details open>`).\n *\n * @see https://ui.funstack.work/components/collapsible\n */\nexport function CollapsibleTrigger({\n transition,\n className,\n style,\n children,\n render,\n ...rest\n}: CollapsibleTriggerProps) {\n const root = use(CollapsibleContext);\n if (root === null) {\n throw new Error(\"Collapsible.Trigger must be rendered inside a Collapsible.Root.\");\n }\n const isLibrary = root.library;\n\n useDevWarning(\n !isLibrary && transition !== undefined,\n isDev &&\n \"Collapsible.Trigger: `transition` has no effect in JS-free mode; the browser toggles the \" +\n \"<details> outside any React transition.\",\n );\n\n const checkElement = useSummaryCheck(\"Collapsible.Trigger\");\n const libraryRef = useCallback(\n (element: HTMLElement) => {\n checkElement?.(element);\n // Always return a cleanup so the merged ref never calls back with `null`.\n return () => {};\n },\n [checkElement],\n );\n\n const state: CollapsibleTriggerState = {\n open: root.optimisticOpen,\n pending: root.pending,\n disabled: root.disabled,\n };\n\n // JS-free mode attaches no click handler unless disabled (design 2.1 and 6).\n const onClick =\n isLibrary || root.disabled\n ? (event: MouseEvent<HTMLElement>) => {\n // A nested control never toggles; any other click is cancelled, which is what keeps the\n // browser from touching `open`.\n if (!interceptSummaryClick(event)) return;\n if (root.disabled || !isLibrary) return;\n // `next` comes from the optimistic value: a second click while pending reverses the\n // first (design 2.2).\n root.dispatch(!root.optimisticOpen, event.nativeEvent);\n }\n : undefined;\n\n const element = useRender<ComponentPropsWithRef<\"summary\">, CollapsibleTriggerState>({\n defaultElement: \"summary\",\n render,\n state,\n className,\n style,\n children,\n ref: libraryRef,\n props: rest,\n // Library-controlled layer: wins over a `render` element's props (conventions 1.2).\n libraryProps: {\n \"aria-disabled\": root.disabled ? true : undefined,\n \"data-open\": dataAttr(root.optimisticOpen === true),\n \"data-pending\": dataAttr(root.pending),\n \"data-disabled\": dataAttr(root.disabled),\n // Only owned when installed, so a render element keeps its own `onClick` in JS-free mode.\n ...(onClick && { onClick }),\n },\n });\n\n return useTransitionBoundary(\"Collapsible.Trigger\", isLibrary ? transition : undefined, element);\n}\n\nCollapsibleTrigger.displayName = \"CollapsibleTrigger\";\n"],"mappings":";;;;;;;;;AAkBA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;;;;;;;;AA0CvC,SAAgB,mBAAmB,EACjC,YACA,WACA,OACA,UACA,QACA,GAAG,QACuB;CAC1B,MAAM,OAAO,IAAI,kBAAkB;CACnC,IAAI,SAAS,MACX,MAAM,IAAI,MAAM,iEAAiE;CAEnF,MAAM,YAAY,KAAK;CAEvB,cACE,CAAC,aAAa,eAAe,KAAA,GAC7B,SACE,kIAEJ;CAEA,MAAM,eAAe,gBAAgB,qBAAqB;CAC1D,MAAM,aAAa,aAChB,YAAyB;EACxB,eAAe,OAAO;EAEtB,aAAa,CAAC;CAChB,GACA,CAAC,YAAY,CACf;CAEA,MAAM,QAAiC;EACrC,MAAM,KAAK;EACX,SAAS,KAAK;EACd,UAAU,KAAK;CACjB;CAGA,MAAM,UACJ,aAAa,KAAK,YACb,UAAmC;EAGlC,IAAI,CAAC,sBAAsB,KAAK,GAAG;EACnC,IAAI,KAAK,YAAY,CAAC,WAAW;EAGjC,KAAK,SAAS,CAAC,KAAK,gBAAgB,MAAM,WAAW;CACvD,IACA,KAAA;CAEN,MAAM,UAAU,UAAqE;EACnF,gBAAgB;EAChB;EACA;EACA;EACA;EACA;EACA,KAAK;EACL,OAAO;EAEP,cAAc;GACZ,iBAAiB,KAAK,WAAW,OAAO,KAAA;GACxC,aAAa,SAAS,KAAK,mBAAmB,IAAI;GAClD,gBAAgB,SAAS,KAAK,OAAO;GACrC,iBAAiB,SAAS,KAAK,QAAQ;GAEvC,GAAI,WAAW,EAAE,QAAQ;EAC3B;CACF,CAAC;CAED,OAAO,sBAAsB,uBAAuB,YAAY,aAAa,KAAA,GAAW,OAAO;AACjG;AAEA,mBAAmB,cAAc"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import "../internal/platform-attributes.mjs";
|
|
2
|
+
import { CollapsiblePanel, CollapsiblePanelProps, CollapsiblePanelState } from "./collapsible-panel.mjs";
|
|
3
|
+
import { CollapsibleOpenChangeDetails, CollapsibleRoot, CollapsibleRootProps, CollapsibleRootState } from "./collapsible-root.mjs";
|
|
4
|
+
import { CollapsibleTrigger, CollapsibleTriggerProps, CollapsibleTriggerState } from "./collapsible-trigger.mjs";
|
|
5
|
+
//#region src/collapsible/index.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* One disclosure built on `<details>`/`<summary>`: `Root` (details) > `Trigger` (summary, first
|
|
8
|
+
* child) + `Panel` (div). JS-free when the Root has none of `open`, `defaultOpen` and
|
|
9
|
+
* `openChangeAction`; a transition state owner with optimistic `data-open` and `data-pending`
|
|
10
|
+
* otherwise.
|
|
11
|
+
*
|
|
12
|
+
* @see https://ui.funstack.work/components/collapsible
|
|
13
|
+
*/
|
|
14
|
+
export declare const Collapsible: {
|
|
15
|
+
readonly Root: typeof CollapsibleRoot;
|
|
16
|
+
readonly Trigger: typeof CollapsibleTrigger;
|
|
17
|
+
readonly Panel: typeof CollapsiblePanel;
|
|
18
|
+
};
|
|
19
|
+
//#endregion
|
|
20
|
+
export type { CollapsibleOpenChangeDetails, CollapsiblePanelProps, CollapsiblePanelState, CollapsibleRootProps, CollapsibleRootState, CollapsibleTriggerProps, CollapsibleTriggerState };
|
|
21
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/collapsible/index.ts"],"mappings":";;;;;;;;;;;;;qBAea;WACX,aAAI;WACJ,gBAAO;WACP,cAAK"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { CollapsiblePanel } from "./collapsible-panel.mjs";
|
|
2
|
+
import { CollapsibleRoot } from "./collapsible-root.mjs";
|
|
3
|
+
import { CollapsibleTrigger } from "./collapsible-trigger.mjs";
|
|
4
|
+
//#region src/collapsible/index.ts
|
|
5
|
+
/**
|
|
6
|
+
* One disclosure built on `<details>`/`<summary>`: `Root` (details) > `Trigger` (summary, first
|
|
7
|
+
* child) + `Panel` (div). JS-free when the Root has none of `open`, `defaultOpen` and
|
|
8
|
+
* `openChangeAction`; a transition state owner with optimistic `data-open` and `data-pending`
|
|
9
|
+
* otherwise.
|
|
10
|
+
*
|
|
11
|
+
* @see https://ui.funstack.work/components/collapsible
|
|
12
|
+
*/
|
|
13
|
+
const Collapsible = {
|
|
14
|
+
Root: CollapsibleRoot,
|
|
15
|
+
Trigger: CollapsibleTrigger,
|
|
16
|
+
Panel: CollapsiblePanel
|
|
17
|
+
};
|
|
18
|
+
//#endregion
|
|
19
|
+
export { Collapsible };
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/collapsible/index.ts"],"sourcesContent":["// Ships the platform attribute typings with this subpath (conventions 7.4). Type-only: the\n// built JS has no import of it.\nimport \"../internal/platform-attributes.js\";\nimport { CollapsiblePanel } from \"./collapsible-panel.js\";\nimport { CollapsibleRoot } from \"./collapsible-root.js\";\nimport { CollapsibleTrigger } from \"./collapsible-trigger.js\";\n\n/**\n * One disclosure built on `<details>`/`<summary>`: `Root` (details) > `Trigger` (summary, first\n * child) + `Panel` (div). JS-free when the Root has none of `open`, `defaultOpen` and\n * `openChangeAction`; a transition state owner with optimistic `data-open` and `data-pending`\n * otherwise.\n *\n * @see https://ui.funstack.work/components/collapsible\n */\nexport const Collapsible = {\n Root: CollapsibleRoot,\n Trigger: CollapsibleTrigger,\n Panel: CollapsiblePanel,\n} as const;\n\nexport type {\n CollapsibleRootProps,\n CollapsibleRootState,\n CollapsibleOpenChangeDetails,\n} from \"./collapsible-root.js\";\nexport type { CollapsibleTriggerProps, CollapsibleTriggerState } from \"./collapsible-trigger.js\";\nexport type { CollapsiblePanelProps, CollapsiblePanelState } from \"./collapsible-panel.js\";\n"],"mappings":";;;;;;;;;;;;AAeA,MAAa,cAAc;CACzB,MAAM;CACN,SAAS;CACT,OAAO;AACT"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//#region src/combobox/chip-text.ts
|
|
2
|
+
/**
|
|
3
|
+
* The text a chip shows, for the removal announcement's last fallback (design 15.7): its text
|
|
4
|
+
* nodes, trimmed, skipping every `[aria-hidden="true"]` subtree and every element `skip` names
|
|
5
|
+
* (the chip's `ChipRemove`), so a "×" in the remove button or in an `aria-hidden` span is not
|
|
6
|
+
* read as part of the label. `textContent` would include both.
|
|
7
|
+
*/
|
|
8
|
+
function chipText(chip, skip) {
|
|
9
|
+
let text = "";
|
|
10
|
+
const walk = (node) => {
|
|
11
|
+
for (let child = node.firstChild; child !== null; child = child.nextSibling) if (child.nodeType === 3) text += child.nodeValue ?? "";
|
|
12
|
+
else if (child.nodeType === 1) {
|
|
13
|
+
const element = child;
|
|
14
|
+
if (element.getAttribute("aria-hidden") === "true" || skip(element)) continue;
|
|
15
|
+
walk(element);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
walk(chip);
|
|
19
|
+
return text.replace(/\s+/g, " ").trim();
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
export { chipText };
|
|
23
|
+
|
|
24
|
+
//# sourceMappingURL=chip-text.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chip-text.mjs","names":[],"sources":["../../src/combobox/chip-text.ts"],"sourcesContent":["// No directive: a pure DOM read (conventions 7.1).\n\n/**\n * The text a chip shows, for the removal announcement's last fallback (design 15.7): its text\n * nodes, trimmed, skipping every `[aria-hidden=\"true\"]` subtree and every element `skip` names\n * (the chip's `ChipRemove`), so a \"×\" in the remove button or in an `aria-hidden` span is not\n * read as part of the label. `textContent` would include both.\n */\nexport function chipText(chip: Element, skip: (element: Element) => boolean): string {\n let text = \"\";\n const walk = (node: Node): void => {\n for (let child = node.firstChild; child !== null; child = child.nextSibling) {\n if (child.nodeType === 3) {\n text += child.nodeValue ?? \"\";\n } else if (child.nodeType === 1) {\n const element = child as Element;\n if (element.getAttribute(\"aria-hidden\") === \"true\" || skip(element)) continue;\n walk(element);\n }\n }\n };\n walk(chip);\n return text.replace(/\\s+/g, \" \").trim();\n}\n"],"mappings":";;;;;;;AAQA,SAAgB,SAAS,MAAe,MAA6C;CACnF,IAAI,OAAO;CACX,MAAM,QAAQ,SAAqB;EACjC,KAAK,IAAI,QAAQ,KAAK,YAAY,UAAU,MAAM,QAAQ,MAAM,aAC9D,IAAI,MAAM,aAAa,GACrB,QAAQ,MAAM,aAAa;OACtB,IAAI,MAAM,aAAa,GAAG;GAC/B,MAAM,UAAU;GAChB,IAAI,QAAQ,aAAa,aAAa,MAAM,UAAU,KAAK,OAAO,GAAG;GACrE,KAAK,OAAO;EACd;CAEJ;CACA,KAAK,IAAI;CACT,OAAO,KAAK,QAAQ,QAAQ,GAAG,CAAC,CAAC,KAAK;AACxC"}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { RenderProp, StateValue } from "../internal/types.mjs";
|
|
2
|
+
import { CSSProperties, ComponentPropsWithRef, ReactNode } from "react";
|
|
3
|
+
//#region src/combobox/combobox-chips.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* State of `Combobox.Chips`, passed to the function forms of `className`, `style`, `children` and
|
|
6
|
+
* `render`.
|
|
7
|
+
*/
|
|
8
|
+
export interface ComboboxChipsState {
|
|
9
|
+
/** Optimistic selection, in pick order: render one `Chip` per value. */
|
|
10
|
+
readonly value: readonly string[];
|
|
11
|
+
/** The Root's value action is in flight. */
|
|
12
|
+
readonly pending: boolean;
|
|
13
|
+
/** The Root's `disabled` (or the Field's). */
|
|
14
|
+
readonly disabled: boolean;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Props of `Combobox.Chips`.
|
|
18
|
+
*
|
|
19
|
+
* @see https://ui.funstack.work/components/combobox
|
|
20
|
+
*/
|
|
21
|
+
export interface ComboboxChipsProps extends Omit<ComponentPropsWithRef<"div">, "role" | "onKeyDown" | "onPointerDown" | "onMouseDown" | "onClick" | "onFocus" | "onBlur" | "className" | "style" | "children"> {
|
|
22
|
+
/** Class name, or a function of the part's state that returns one. */
|
|
23
|
+
className?: StateValue<string | undefined, ComboboxChipsState>;
|
|
24
|
+
/** Inline style, or a function of the part's state that returns one. */
|
|
25
|
+
style?: StateValue<CSSProperties | undefined, ComboboxChipsState>;
|
|
26
|
+
/**
|
|
27
|
+
* Usually a function of `{ value }` rendering one `Chip` per value, keyed by the value.
|
|
28
|
+
* Rendered from optimistic state; must not suspend.
|
|
29
|
+
*/
|
|
30
|
+
children?: StateValue<ReactNode, ComboboxChipsState>;
|
|
31
|
+
/** Replace the default `<div>` (element form) or take over rendering (function form). */
|
|
32
|
+
render?: RenderProp<ComponentPropsWithRef<"div">, ComboboxChipsState>;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The selected values of `Combobox.Root multiple` as a list: `<div role="list"
|
|
36
|
+
* aria-labelledby={label}>` (no role while empty: an empty list lacks its required children).
|
|
37
|
+
* It holds the chips, not the Input: the box around both is yours. A press in it keeps focus
|
|
38
|
+
* where it is and its click focuses the Input; a focused chip takes the keys of design 15.6
|
|
39
|
+
* (arrows, Home / End, Backspace / Delete, Escape; a printable key types into the Input).
|
|
40
|
+
*
|
|
41
|
+
* Owned keys (conventions 1.2): `role`, `aria-labelledby` (token-merged, while not empty),
|
|
42
|
+
* `onKeyDown`, `onPointerDown`, `onMouseDown`, `onClick`, `onFocus`, `onBlur`, `data-empty`,
|
|
43
|
+
* `data-pending`, `data-disabled`.
|
|
44
|
+
*
|
|
45
|
+
* @see https://ui.funstack.work/components/combobox
|
|
46
|
+
*/
|
|
47
|
+
export declare function ComboboxChips({ className, style, children, render, ...rest }: ComboboxChipsProps): ReactNode;
|
|
48
|
+
export declare namespace ComboboxChips {
|
|
49
|
+
var displayName: string;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* State of `Combobox.Chip`, passed to the function forms of `className`, `style`, `children` and
|
|
53
|
+
* `render`.
|
|
54
|
+
*/
|
|
55
|
+
export interface ComboboxChipState {
|
|
56
|
+
/** The Chip's `value` prop. */
|
|
57
|
+
readonly value: string;
|
|
58
|
+
/**
|
|
59
|
+
* The text of the option with this value as the library last saw it (written at the pick);
|
|
60
|
+
* `undefined` if no Option for it was ever mounted (a preselected value before the listbox
|
|
61
|
+
* first opens).
|
|
62
|
+
*/
|
|
63
|
+
readonly label: string | undefined;
|
|
64
|
+
/** The Root's value action is pending and this value is not in the committed selection yet. */
|
|
65
|
+
readonly pending: boolean;
|
|
66
|
+
/** The Root's `disabled` (or the Field's). */
|
|
67
|
+
readonly disabled: boolean;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Props of `Combobox.Chip`.
|
|
71
|
+
*
|
|
72
|
+
* @see https://ui.funstack.work/components/combobox
|
|
73
|
+
*/
|
|
74
|
+
export interface ComboboxChipProps extends Omit<ComponentPropsWithRef<"div">, "role" | "tabIndex" | "className" | "style" | "children"> {
|
|
75
|
+
/** The selected value this chip shows. */
|
|
76
|
+
value: string;
|
|
77
|
+
/**
|
|
78
|
+
* The chip's text for the removal announcement.
|
|
79
|
+
*
|
|
80
|
+
* @defaultValue `state.label`, else the element's trimmed `textContent`
|
|
81
|
+
*/
|
|
82
|
+
label?: string;
|
|
83
|
+
/** Class name, or a function of the part's state that returns one. */
|
|
84
|
+
className?: StateValue<string | undefined, ComboboxChipState>;
|
|
85
|
+
/** Inline style, or a function of the part's state that returns one. */
|
|
86
|
+
style?: StateValue<CSSProperties | undefined, ComboboxChipState>;
|
|
87
|
+
/**
|
|
88
|
+
* Content, or a function of the part's state. Rendered from optimistic state; must not
|
|
89
|
+
* suspend.
|
|
90
|
+
*
|
|
91
|
+
* @defaultValue `label ?? value` (the state's `label`)
|
|
92
|
+
*/
|
|
93
|
+
children?: StateValue<ReactNode, ComboboxChipState>;
|
|
94
|
+
/** Replace the default `<div>` (element form) or take over rendering (function form). */
|
|
95
|
+
render?: RenderProp<ComponentPropsWithRef<"div">, ComboboxChipState>;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* One selected value: `<div role="listitem" tabindex="-1">`, focusable by the keys of design 15.6
|
|
99
|
+
* and never a Tab stop (the combobox has one, the Input). Renders from the optimistic value, so a
|
|
100
|
+
* removed chip disappears at once and comes back if its action rejects; `data-pending` while its
|
|
101
|
+
* addition is not committed.
|
|
102
|
+
*
|
|
103
|
+
* Owned keys (conventions 1.2): `role`, `tabIndex`, `data-pending`, `data-disabled`.
|
|
104
|
+
*
|
|
105
|
+
* @see https://ui.funstack.work/components/combobox
|
|
106
|
+
*/
|
|
107
|
+
export declare function ComboboxChip({ value, label, className, style, children, render, ...rest }: ComboboxChipProps): import("react").JSX.Element;
|
|
108
|
+
export declare namespace ComboboxChip {
|
|
109
|
+
var displayName: string;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* State of `Combobox.ChipRemove`, passed to the function forms of `className`, `style`,
|
|
113
|
+
* `children` and `render`.
|
|
114
|
+
*/
|
|
115
|
+
export interface ComboboxChipRemoveState {
|
|
116
|
+
/** The value of the Chip it is in. */
|
|
117
|
+
readonly value: string;
|
|
118
|
+
/** As the Chip's `pending`. */
|
|
119
|
+
readonly pending: boolean;
|
|
120
|
+
/** The Root's `disabled` (or the Field's). */
|
|
121
|
+
readonly disabled: boolean;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Props of `Combobox.ChipRemove`.
|
|
125
|
+
*
|
|
126
|
+
* @see https://ui.funstack.work/components/combobox
|
|
127
|
+
*/
|
|
128
|
+
export interface ComboboxChipRemoveProps extends Omit<ComponentPropsWithRef<"button">, "onClick" | "onPointerDown" | "onMouseDown" | "tabIndex" | "disabled" | "className" | "style" | "children"> {
|
|
129
|
+
/** Class name, or a function of the part's state that returns one. */
|
|
130
|
+
className?: StateValue<string | undefined, ComboboxChipRemoveState>;
|
|
131
|
+
/** Inline style, or a function of the part's state that returns one. */
|
|
132
|
+
style?: StateValue<CSSProperties | undefined, ComboboxChipRemoveState>;
|
|
133
|
+
/**
|
|
134
|
+
* Content, or a function of the part's state, usually an icon ("×", best in an `aria-hidden`
|
|
135
|
+
* element). It is never part of the chip's text in the removal announcement.
|
|
136
|
+
*/
|
|
137
|
+
children?: StateValue<ReactNode, ComboboxChipRemoveState>;
|
|
138
|
+
/** Should render a `<button>`. */
|
|
139
|
+
render?: RenderProp<ComponentPropsWithRef<"button">, ComboboxChipRemoveState>;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* The optional remove button of a chip: `<button type="button" tabindex="-1">`, inside a
|
|
143
|
+
* `Combobox.Chip`. A press keeps focus in the Input (as `Clear`); the click removes the chip's
|
|
144
|
+
* value, announces it and focuses the Input. While the listbox is open the press closes it (the
|
|
145
|
+
* platform's light dismiss: the button is outside the popup). Needs an accessible name
|
|
146
|
+
* (`aria-label`).
|
|
147
|
+
*
|
|
148
|
+
* Owned keys (conventions 1.2): `type` (on a `<button>`), `tabIndex`, `disabled`,
|
|
149
|
+
* `aria-disabled` (link or component `render`), `onClick`, `onPointerDown`, `onMouseDown`,
|
|
150
|
+
* `data-pending`, `data-disabled`.
|
|
151
|
+
*
|
|
152
|
+
* @see https://ui.funstack.work/components/combobox
|
|
153
|
+
*/
|
|
154
|
+
export declare function ComboboxChipRemove({ className, style, children, render, ...rest }: ComboboxChipRemoveProps): ReactNode;
|
|
155
|
+
export declare namespace ComboboxChipRemove {
|
|
156
|
+
var displayName: string;
|
|
157
|
+
}
|
|
158
|
+
//#endregion
|
|
159
|
+
//# sourceMappingURL=combobox-chips.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"combobox-chips.d.mts","names":[],"sources":["../../src/combobox/combobox-chips.tsx"],"mappings":";;;;;;;iBA8BiB;;WAEN;;WAEA;;WAEA;;;;;;;iBAQM,2BAA2B,KAC1C;;EAaA,YAAY,+BAA+B;;EAE3C,QAAQ,WAAW,2BAA2B;;;;;EAK9C,WAAW,WAAW,WAAW;;EAEjC,SAAS,WAAW,8BAA8B;;;;;;;;;;;;;;;wBAgBpC,gBAAgB,WAAW,OAAO,UAAU,WAAW,QAAQ,qBAAkB;yBAAjF;;;;;;;iBAsEC;;WAEN;;;;;;WAMA;;WAEA;;WAEA;;;;;;;iBAQM,0BAA0B,KACzC;;EAIA;;;;;;EAMA;;EAEA,YAAY,+BAA+B;;EAE3C,QAAQ,WAAW,2BAA2B;;;;;;;EAO9C,WAAW,WAAW,WAAW;;EAEjC,SAAS,WAAW,8BAA8B;;;;;;;;;;;;wBAapC,eACd,OACA,OACA,WACA,OACA,UACA,WACG,QACF,oCAAiB,IAAA;yBARJ;;;;;;;iBAuEC;;WAEN;;WAEA;;WAEA;;;;;;;iBAQM,gCAAgC,KAC/C;;EAWA,YAAY,+BAA+B;;EAE3C,QAAQ,WAAW,2BAA2B;;;;;EAK9C,WAAW,WAAW,WAAW;;EAEjC,SAAS,WAAW,iCAAiC;;;;;;;;;;;;;;;wBAgBvC,qBACd,WACA,OACA,UACA,WACG,QACF,0BAAuB;yBANV"}
|