@kirana-ui/react 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +140 -0
- package/llms.txt +1800 -187
- package/package.json +48 -3
- package/skills/kirana-ui-primitives/SKILL.md +53 -12
- package/src/accordion.d.ts +2 -2
- package/src/accordion.js +3 -2
- package/src/accordion.js.map +1 -1
- package/src/alert-dialog.d.ts +2 -2
- package/src/autocomplete.d.ts +2 -2
- package/src/autosize.d.ts +1 -1
- package/src/avatar.d.ts +28 -7
- package/src/avatar.js +22 -9
- package/src/avatar.js.map +1 -1
- package/src/button.d.ts +5 -2
- package/src/button.js +4 -1
- package/src/button.js.map +1 -1
- package/src/calendar.d.ts +23 -8
- package/src/calendar.js +50 -13
- package/src/calendar.js.map +1 -1
- package/src/carousel.d.ts +6 -3
- package/src/carousel.js +1 -1
- package/src/carousel.js.map +1 -1
- package/src/checkbox-group-context.d.ts +4 -0
- package/src/checkbox-group-context.js +7 -0
- package/src/checkbox-group-context.js.map +1 -0
- package/src/checkbox-group.d.ts +15 -0
- package/src/checkbox-group.js +30 -0
- package/src/checkbox-group.js.map +1 -0
- package/src/checkbox.d.ts +7 -2
- package/src/checkbox.js +9 -3
- package/src/checkbox.js.map +1 -1
- package/src/collapsible.d.ts +1 -1
- package/src/color-picker.d.ts +61 -0
- package/src/color-picker.js +119 -0
- package/src/color-picker.js.map +1 -0
- package/src/combobox.d.ts +54 -5
- package/src/combobox.js +49 -8
- package/src/combobox.js.map +1 -1
- package/src/command.d.ts +4 -4
- package/src/command.js +2 -1
- package/src/command.js.map +1 -1
- package/src/date-field.d.ts +2 -2
- package/src/date-field.js +3 -2
- package/src/date-field.js.map +1 -1
- package/src/date-picker.d.ts +33 -11
- package/src/date-picker.js +22 -5
- package/src/date-picker.js.map +1 -1
- package/src/dialog.d.ts +11 -6
- package/src/dialog.js +27 -8
- package/src/dialog.js.map +1 -1
- package/src/direction.d.ts +1 -1
- package/src/direction.js +1 -1
- package/src/editable.d.ts +32 -0
- package/src/editable.js +63 -0
- package/src/editable.js.map +1 -0
- package/src/field.d.ts +1 -1
- package/src/fieldset.d.ts +1 -1
- package/src/file-upload.d.ts +54 -0
- package/src/file-upload.js +96 -0
- package/src/file-upload.js.map +1 -0
- package/src/form.d.ts +1 -1
- package/src/hover-popup.d.ts +1 -1
- package/src/hover-popup.js +1 -1
- package/src/index.d.ts +28 -7
- package/src/index.js +12 -1
- package/src/input.d.ts +1 -1
- package/src/input.js +1 -1
- package/src/label.d.ts +1 -1
- package/src/listbox.d.ts +1 -1
- package/src/listbox.js +1 -1
- package/src/menu.d.ts +5 -5
- package/src/menu.js +14 -9
- package/src/menu.js.map +1 -1
- package/src/menubar.d.ts +2 -2
- package/src/menubar.js +4 -2
- package/src/menubar.js.map +1 -1
- package/src/message-scroller.d.ts +1 -1
- package/src/navigation-menu.d.ts +5 -5
- package/src/navigation-menu.js +14 -4
- package/src/navigation-menu.js.map +1 -1
- package/src/number-field.d.ts +11 -2
- package/src/number-field.js +20 -3
- package/src/number-field.js.map +1 -1
- package/src/otp.d.ts +3 -2
- package/src/otp.js +10 -2
- package/src/otp.js.map +1 -1
- package/src/pagination.d.ts +1 -1
- package/src/password-input.d.ts +23 -0
- package/src/password-input.js +40 -0
- package/src/password-input.js.map +1 -0
- package/src/popover.d.ts +12 -4
- package/src/popover.js +14 -1
- package/src/popover.js.map +1 -1
- package/src/qr-code.d.ts +1 -1
- package/src/radio-group.d.ts +4 -2
- package/src/radio-group.js +6 -3
- package/src/radio-group.js.map +1 -1
- package/src/rating.d.ts +28 -0
- package/src/rating.js +59 -0
- package/src/rating.js.map +1 -0
- package/src/resizable.d.ts +1 -1
- package/src/resizable.js +1 -1
- package/src/runtime.d.ts +18 -8
- package/src/runtime.js +24 -5
- package/src/runtime.js.map +1 -1
- package/src/scroll-area.d.ts +1 -1
- package/src/scroll-area.js +1 -1
- package/src/select.d.ts +17 -6
- package/src/select.js +6 -3
- package/src/select.js.map +1 -1
- package/src/separator.d.ts +1 -1
- package/src/slider.d.ts +2 -2
- package/src/slider.js +3 -2
- package/src/slider.js.map +1 -1
- package/src/steps.d.ts +51 -0
- package/src/steps.js +69 -0
- package/src/steps.js.map +1 -0
- package/src/switch.d.ts +2 -1
- package/src/switch.js +1 -1
- package/src/switch.js.map +1 -1
- package/src/tabs.d.ts +2 -2
- package/src/tabs.js +4 -3
- package/src/tabs.js.map +1 -1
- package/src/tags-input.d.ts +47 -0
- package/src/tags-input.js +92 -0
- package/src/tags-input.js.map +1 -0
- package/src/time-field.d.ts +32 -0
- package/src/time-field.js +67 -0
- package/src/time-field.js.map +1 -0
- package/src/toast.d.ts +1 -1
- package/src/toggle-group.d.ts +2 -2
- package/src/toggle-group.js +4 -3
- package/src/toggle-group.js.map +1 -1
- package/src/toggle.d.ts +1 -1
- package/src/toggle.js +1 -1
- package/src/toolbar.d.ts +14 -6
- package/src/toolbar.js +19 -9
- package/src/toolbar.js.map +1 -1
- package/src/tour.d.ts +61 -0
- package/src/tour.js +68 -0
- package/src/tour.js.map +1 -0
- package/src/tree.d.ts +45 -0
- package/src/tree.js +93 -0
- package/src/tree.js.map +1 -0
- package/src/use-render.d.ts +1 -1
- package/src/use-render.js +1 -1
- package/src/use-render.js.map +1 -1
- package/src/value-bar.d.ts +1 -1
package/src/combobox.d.ts
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
import { PartComponentProps, PortalProps, PositionerOptions } from "./runtime.js";
|
|
2
|
-
import { StateOf } from "@kirana-ui/core";
|
|
3
2
|
import { ReactElement, ReactNode } from "react";
|
|
3
|
+
import { StateOf } from "@kirana-ui/core";
|
|
4
4
|
import { AutocompleteProps } from "@kirana-ui/core/autocomplete";
|
|
5
|
-
import { ComboboxProps } from "@kirana-ui/core/combobox";
|
|
5
|
+
import { ComboboxEntry, ComboboxProps } from "@kirana-ui/core/combobox";
|
|
6
6
|
import { Vocabulary } from "@kirana-ui/core/vocabulary";
|
|
7
7
|
type Parts = Vocabulary["combobox"];
|
|
8
|
-
/**
|
|
9
|
-
|
|
8
|
+
/**
|
|
9
|
+
* `Value` is what tells an item from the others. `Multiple` is inferred from `multiple`: with
|
|
10
|
+
* `multiple`, `value`, `defaultValue` and `onValueChange` hold a list of them.
|
|
11
|
+
*/
|
|
12
|
+
export type RootProps<Value = unknown, Multiple extends boolean | undefined = false> = Omit<ComboboxProps<Value, Multiple>, "id" | "multiple"> & {
|
|
13
|
+
/** Several values: `value`, `defaultValue` and `onValueChange` then hold a list. Read once. */
|
|
14
|
+
multiple?: Multiple | undefined;
|
|
10
15
|
id?: string;
|
|
11
16
|
children?: ReactNode;
|
|
12
17
|
};
|
|
13
|
-
declare function Root<Value = unknown>({ children, ...props }: RootProps<Value>): ReactElement;
|
|
18
|
+
declare function Root<Value = unknown, Multiple extends boolean | undefined = false>({ children, ...props }: RootProps<Value, Multiple>): ReactElement;
|
|
14
19
|
export type InputProps = PartComponentProps<"input", StateOf<Parts["input"]>>;
|
|
15
20
|
export type TriggerProps = PartComponentProps<"button", StateOf<Parts["trigger"]>>;
|
|
16
21
|
export type PopupProps = PartComponentProps<"div", StateOf<Parts["popup"]>>;
|
|
@@ -18,6 +23,9 @@ export type ListProps = PartComponentProps<"div", StateOf<Parts["list"]>>;
|
|
|
18
23
|
declare const Input: (props: InputProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
19
24
|
declare const Trigger: (props: TriggerProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
20
25
|
declare const Popup: (props: PopupProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
26
|
+
export type BackdropProps = PartComponentProps<"div", StateOf<Parts["backdrop"]>>;
|
|
27
|
+
/** What lies over the page behind the list: a sheet's (`presentation`) is modal. */
|
|
28
|
+
declare const Backdrop: (props: BackdropProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
21
29
|
/**
|
|
22
30
|
* The items' own box inside the popup, when the popup holds more than items (an input): it
|
|
23
31
|
* is then the listbox.
|
|
@@ -75,6 +83,41 @@ declare function ChipRemove(props: ChipRemoveProps): ReactElement;
|
|
|
75
83
|
export type EmptyProps = PartComponentProps<"div", StateOf<Parts["empty"]>>;
|
|
76
84
|
/** Drawn while no item is shown for what was typed. */
|
|
77
85
|
declare function Empty(props: EmptyProps): ReactElement | null;
|
|
86
|
+
export type StatusProps = PartComponentProps<"div", StateOf<Parts["status"]>>;
|
|
87
|
+
/**
|
|
88
|
+
* Says how the list stands ("3 results", "Loading") to software that reads the page, as its
|
|
89
|
+
* text changes. Keep it in the page and change what it holds: inside the popup, or beside the
|
|
90
|
+
* input.
|
|
91
|
+
*/
|
|
92
|
+
declare const Status: (props: StatusProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
93
|
+
export type ValueProps<Chosen = unknown> = {
|
|
94
|
+
/** Shown while nothing is chosen. */
|
|
95
|
+
placeholder?: ReactNode;
|
|
96
|
+
/**
|
|
97
|
+
* What to show in place of the label. A function is given the value and its label (`null`
|
|
98
|
+
* and `undefined` while nothing is chosen); with `multiple`, the values and their labels, in
|
|
99
|
+
* the order they were chosen.
|
|
100
|
+
*/
|
|
101
|
+
children?: ReactNode | ((value: Chosen, label: Chosen extends readonly unknown[] ? readonly string[] : string | undefined) => ReactNode);
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* The chosen value's label, or `placeholder` while nothing is chosen; with `multiple`, the
|
|
105
|
+
* chosen labels with commas between. For a button that is the combobox, its input inside the
|
|
106
|
+
* popup. It draws no element.
|
|
107
|
+
*/
|
|
108
|
+
declare function Value<Chosen = unknown>({ placeholder, children }: ValueProps<Chosen>): ReactElement;
|
|
109
|
+
export type CollectionProps<Value = unknown> = {
|
|
110
|
+
/** A group the root's `items` gave: its items left are then what is drawn. */
|
|
111
|
+
of?: ComboboxEntry<Value> | undefined;
|
|
112
|
+
/** Drawn once for each item left, or for each group that has items left. */
|
|
113
|
+
children: (entry: ComboboxEntry<Value>) => ReactNode;
|
|
114
|
+
};
|
|
115
|
+
/**
|
|
116
|
+
* Draws the list from the root's `items`: its child once for each item left for what was
|
|
117
|
+
* typed, or for each group that has items left; with `of`, for each of that group's. The root
|
|
118
|
+
* then filters, and no item hides itself. It draws no element.
|
|
119
|
+
*/
|
|
120
|
+
declare function Collection<Value = unknown>({ of, children }: CollectionProps<Value>): ReactElement;
|
|
78
121
|
export type AutocompleteRootProps = Omit<AutocompleteProps, "id"> & {
|
|
79
122
|
id?: string;
|
|
80
123
|
children?: ReactNode;
|
|
@@ -85,20 +128,24 @@ export declare const Combobox: {
|
|
|
85
128
|
readonly Root: typeof Root;
|
|
86
129
|
readonly Input: typeof Input;
|
|
87
130
|
readonly Trigger: typeof Trigger;
|
|
131
|
+
readonly Value: typeof Value;
|
|
88
132
|
readonly Clear: typeof Clear;
|
|
89
133
|
readonly Chips: typeof Chips;
|
|
90
134
|
readonly Chip: typeof Chip;
|
|
91
135
|
readonly ChipRemove: typeof ChipRemove;
|
|
92
136
|
readonly Portal: typeof Portal;
|
|
137
|
+
readonly Backdrop: typeof Backdrop;
|
|
93
138
|
readonly Positioner: typeof Positioner;
|
|
94
139
|
readonly Popup: typeof Popup;
|
|
95
140
|
readonly List: typeof List;
|
|
141
|
+
readonly Collection: typeof Collection;
|
|
96
142
|
readonly Group: typeof Group;
|
|
97
143
|
readonly GroupLabel: typeof GroupLabel;
|
|
98
144
|
readonly Separator: typeof Separator;
|
|
99
145
|
readonly Item: typeof Item;
|
|
100
146
|
readonly ItemIndicator: typeof ItemIndicator;
|
|
101
147
|
readonly Empty: typeof Empty;
|
|
148
|
+
readonly Status: typeof Status;
|
|
102
149
|
};
|
|
103
150
|
export declare const Autocomplete: {
|
|
104
151
|
readonly Root: typeof AutocompleteRoot;
|
|
@@ -109,11 +156,13 @@ export declare const Autocomplete: {
|
|
|
109
156
|
readonly Positioner: typeof Positioner;
|
|
110
157
|
readonly Popup: typeof Popup;
|
|
111
158
|
readonly List: typeof List;
|
|
159
|
+
readonly Collection: typeof Collection;
|
|
112
160
|
readonly Group: typeof Group;
|
|
113
161
|
readonly GroupLabel: typeof GroupLabel;
|
|
114
162
|
readonly Separator: typeof Separator;
|
|
115
163
|
readonly Item: typeof Item;
|
|
116
164
|
readonly Empty: typeof Empty;
|
|
165
|
+
readonly Status: typeof Status;
|
|
117
166
|
};
|
|
118
167
|
export type { PortalProps };
|
|
119
168
|
//# sourceMappingURL=combobox.d.ts.map
|
package/src/combobox.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { DirectionContext } from "./direction-context.js";
|
|
1
2
|
import { FieldContext } from "./field-context.js";
|
|
2
|
-
import { PartElement, Portal as Portal$1, parts, useController, useOptions, useOwnText, usePart, usePositioning, useSignal } from "./runtime.js";
|
|
3
|
+
import { PartElement, Portal as Portal$1, parts, useController, useMount, useOptions, useOwnText, usePart, usePositioning, useSignal } from "./runtime.js";
|
|
4
|
+
import { Fragment, createContext, useContext, useId, useMemo } from "react";
|
|
3
5
|
import { within } from "@kirana-ui/core";
|
|
4
|
-
import {
|
|
5
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
6
7
|
import { createAutocomplete } from "@kirana-ui/core/autocomplete";
|
|
7
8
|
import { createCombobox } from "@kirana-ui/core/combobox";
|
|
8
9
|
// src/combobox.tsx
|
|
@@ -15,7 +16,11 @@ function useCombobox(part) {
|
|
|
15
16
|
}
|
|
16
17
|
function Root({ children, ...props }) {
|
|
17
18
|
const field = useContext(FieldContext) ?? void 0;
|
|
18
|
-
const
|
|
19
|
+
const direction = useContext(DirectionContext) ?? void 0;
|
|
20
|
+
const controller = useController(within(createCombobox, {
|
|
21
|
+
field,
|
|
22
|
+
direction
|
|
23
|
+
}), props);
|
|
19
24
|
const named = useSignal(controller.named);
|
|
20
25
|
return /* @__PURE__ */ jsxs(Context.Provider, {
|
|
21
26
|
value: controller,
|
|
@@ -26,6 +31,8 @@ const HiddenInput = () => usePart(useCombobox("Root").hidden, "input", {});
|
|
|
26
31
|
const Input = (props) => usePart(useOwnText(useCombobox("Input").input), "input", props);
|
|
27
32
|
const Trigger = (props) => usePart(useCombobox("Trigger").trigger, "button", props);
|
|
28
33
|
const Popup = (props) => usePart(useCombobox("Popup").popup, "div", props);
|
|
34
|
+
/** What lies over the page behind the list: a sheet's (`presentation`) is modal. */
|
|
35
|
+
const Backdrop = (props) => usePart(useCombobox("Backdrop").backdrop, "div", props);
|
|
29
36
|
/**
|
|
30
37
|
* The items' own box inside the popup, when the popup holds more than items (an input): it
|
|
31
38
|
* is then the listbox.
|
|
@@ -85,9 +92,9 @@ function Item({ value, disabled, label, id, index, ...props }) {
|
|
|
85
92
|
function ItemIndicator({ keepMounted, ...props }) {
|
|
86
93
|
const controller = useCombobox("ItemIndicator");
|
|
87
94
|
const value = useContext(ItemContext);
|
|
88
|
-
const selected = useSignal(controller.selected(value));
|
|
89
95
|
const part = useMemo(() => controller.itemIndicator(value), [controller, value]);
|
|
90
|
-
|
|
96
|
+
useMount(part);
|
|
97
|
+
return useSignal(part.mounted) || keepMounted ? /* @__PURE__ */ jsx(PartElement, {
|
|
91
98
|
of: part,
|
|
92
99
|
tag: "span",
|
|
93
100
|
...props
|
|
@@ -129,6 +136,34 @@ function Empty(props) {
|
|
|
129
136
|
...props
|
|
130
137
|
}) : null;
|
|
131
138
|
}
|
|
139
|
+
/**
|
|
140
|
+
* Says how the list stands ("3 results", "Loading") to software that reads the page, as its
|
|
141
|
+
* text changes. Keep it in the page and change what it holds: inside the popup, or beside the
|
|
142
|
+
* input.
|
|
143
|
+
*/
|
|
144
|
+
const Status = (props) => usePart(useCombobox("Status").status, "div", props);
|
|
145
|
+
/**
|
|
146
|
+
* The chosen value's label, or `placeholder` while nothing is chosen; with `multiple`, the
|
|
147
|
+
* chosen labels with commas between. For a button that is the combobox, its input inside the
|
|
148
|
+
* popup. It draws no element.
|
|
149
|
+
*/
|
|
150
|
+
function Value({ placeholder, children }) {
|
|
151
|
+
const controller = useCombobox("Value");
|
|
152
|
+
const shown = useSignal(controller.shown);
|
|
153
|
+
if (typeof children !== "function") return /* @__PURE__ */ jsx(Fragment$1, { children: children ?? shown.label ?? placeholder });
|
|
154
|
+
const draw = children;
|
|
155
|
+
return /* @__PURE__ */ jsx(Fragment$1, { children: controller.multiple ? draw(shown.values, shown.labels) : draw(shown.value, shown.label) });
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Draws the list from the root's `items`: its child once for each item left for what was
|
|
159
|
+
* typed, or for each group that has items left; with `of`, for each of that group's. The root
|
|
160
|
+
* then filters, and no item hides itself. It draws no element.
|
|
161
|
+
*/
|
|
162
|
+
function Collection({ of, children }) {
|
|
163
|
+
const controller = useCombobox("Collection");
|
|
164
|
+
const entries = useSignal(controller.entries(of));
|
|
165
|
+
return /* @__PURE__ */ jsx(Fragment$1, { children: entries.map((entry) => /* @__PURE__ */ jsx(Fragment, { children: children(entry) }, entry.key)) });
|
|
166
|
+
}
|
|
132
167
|
/** A combobox whose text is the value: the list only suggests. */
|
|
133
168
|
function AutocompleteRoot({ children, ...props }) {
|
|
134
169
|
const field = useContext(FieldContext) ?? void 0;
|
|
@@ -142,20 +177,24 @@ const Combobox = /* @__PURE__ */ parts("Combobox", {
|
|
|
142
177
|
Root,
|
|
143
178
|
Input,
|
|
144
179
|
Trigger,
|
|
180
|
+
Value,
|
|
145
181
|
Clear,
|
|
146
182
|
Chips,
|
|
147
183
|
Chip,
|
|
148
184
|
ChipRemove,
|
|
149
185
|
Portal,
|
|
186
|
+
Backdrop,
|
|
150
187
|
Positioner,
|
|
151
188
|
Popup,
|
|
152
189
|
List,
|
|
190
|
+
Collection,
|
|
153
191
|
Group,
|
|
154
192
|
GroupLabel,
|
|
155
193
|
Separator,
|
|
156
194
|
Item,
|
|
157
195
|
ItemIndicator,
|
|
158
|
-
Empty
|
|
196
|
+
Empty,
|
|
197
|
+
Status
|
|
159
198
|
});
|
|
160
199
|
const Autocomplete = /* @__PURE__ */ parts("Autocomplete", {
|
|
161
200
|
Root: AutocompleteRoot,
|
|
@@ -166,11 +205,13 @@ const Autocomplete = /* @__PURE__ */ parts("Autocomplete", {
|
|
|
166
205
|
Positioner,
|
|
167
206
|
Popup,
|
|
168
207
|
List,
|
|
208
|
+
Collection,
|
|
169
209
|
Group,
|
|
170
210
|
GroupLabel,
|
|
171
211
|
Separator,
|
|
172
212
|
Item,
|
|
173
|
-
Empty
|
|
213
|
+
Empty,
|
|
214
|
+
Status
|
|
174
215
|
});
|
|
175
216
|
export { Autocomplete, Combobox };
|
|
176
217
|
|
package/src/combobox.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"combobox.js","names":["BodyPortal"],"sources":["../../../../packages/react/src/combobox.tsx"],"sourcesContent":["import { within } from \"@kirana-ui/core\"\nimport type { StateOf } from \"@kirana-ui/core\"\nimport { createAutocomplete } from \"@kirana-ui/core/autocomplete\"\nimport type { AutocompleteProps } from \"@kirana-ui/core/autocomplete\"\nimport { createCombobox } from \"@kirana-ui/core/combobox\"\nimport type { Combobox as Controller, ComboboxGroup, ComboboxProps } from \"@kirana-ui/core/combobox\"\nimport type { Vocabulary } from \"@kirana-ui/core/vocabulary\"\nimport { createContext, useContext, useId, useMemo } from \"react\"\nimport type { ReactElement, ReactNode } from \"react\"\n\nimport { FieldContext } from \"./field-context.ts\"\nimport {\n Portal as BodyPortal,\n PartElement,\n parts,\n useController,\n useOptions,\n useOwnText,\n usePart,\n usePositioning,\n useSignal,\n} from \"./runtime.tsx\"\nimport type { PartComponentProps, PortalProps, PositionerOptions } from \"./runtime.tsx\"\n\nexport type { PortalProps }\n\ntype Parts = Vocabulary[\"combobox\"]\n\nconst Context = createContext<Controller | null>(null)\nconst ItemContext = createContext<unknown>(undefined)\n\nfunction useCombobox(part: string): Controller {\n const controller = useContext(Context)\n if (!controller) throw new Error(`<Combobox.${part}> must be inside <Combobox.Root>`)\n return controller\n}\n\n/** `Value` is what tells an item from the others: the type of `value`, and of `values`' entries. */\nexport type RootProps<Value = unknown> = Omit<ComboboxProps<Value>, \"id\"> & {\n id?: string\n children?: ReactNode\n}\n\nfunction Root<Value = unknown>({ children, ...props }: RootProps<Value>): ReactElement {\n const field = useContext(FieldContext) ?? undefined\n const controller: Controller = useController<ComboboxProps<Value>, Controller<Value>>(\n within(createCombobox<Value>, { field }),\n props\n )\n const named = useSignal(controller.named)\n return (\n <Context.Provider value={controller}>\n {children}\n {named ? <HiddenInput /> : null}\n </Context.Provider>\n )\n}\n\nexport type InputProps = PartComponentProps<\"input\", StateOf<Parts[\"input\"]>>\nexport type TriggerProps = PartComponentProps<\"button\", StateOf<Parts[\"trigger\"]>>\nexport type PopupProps = PartComponentProps<\"div\", StateOf<Parts[\"popup\"]>>\nexport type ListProps = PartComponentProps<\"div\", StateOf<Parts[\"list\"]>>\n\nconst HiddenInput = () => usePart(useCombobox(\"Root\").hidden, \"input\", {})\nconst Input = (props: InputProps) => usePart(useOwnText(useCombobox(\"Input\").input), \"input\", props)\nconst Trigger = (props: TriggerProps) => usePart(useCombobox(\"Trigger\").trigger, \"button\", props)\nconst Popup = (props: PopupProps) => usePart(useCombobox(\"Popup\").popup, \"div\", props)\n/**\n * The items' own box inside the popup, when the popup holds more than items (an input): it\n * is then the listbox.\n */\nconst List = (props: ListProps) => usePart(useCombobox(\"List\").list, \"div\", props)\n\nfunction Portal({ children }: PortalProps): ReactElement | null {\n const mounted = useSignal(useCombobox(\"Portal\").mounted)\n return mounted ? <BodyPortal>{children}</BodyPortal> : null\n}\n\nexport type PositionerProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"positioner\"]>,\n PositionerOptions\n>\n\nfunction Positioner(props: PositionerProps): ReactElement {\n const controller = useCombobox(\"Positioner\")\n return usePart(controller.positioner, \"div\", usePositioning(controller.positioning, props))\n}\n\nconst GroupContext = createContext<ComboboxGroup | null>(null)\n\nexport type GroupProps = PartComponentProps<\"div\", StateOf<Parts[\"group\"]>, { id?: string }>\n\n/** Items that belong together, named by their `GroupLabel`. Hidden while none is shown. */\nfunction Group({ id, ...props }: GroupProps): ReactElement {\n const controller = useCombobox(\"Group\")\n const generated = useId()\n const group = useMemo(() => controller.group(id ?? generated), [controller, id, generated])\n return (\n <GroupContext.Provider value={group}>{usePart(group.root, \"div\", props)}</GroupContext.Provider>\n )\n}\n\nexport type GroupLabelProps = PartComponentProps<\"div\", StateOf<Parts[\"groupLabel\"]>>\n\n/** A group's name. Outside a group it is plain text, and names nothing. */\nfunction GroupLabel(props: GroupLabelProps): ReactElement {\n const lone = useCombobox(\"GroupLabel\").groupLabel\n return usePart(useContext(GroupContext)?.label ?? lone, \"div\", props)\n}\n\nexport type SeparatorProps = PartComponentProps<\"div\", StateOf<Parts[\"separator\"]>>\n\n/** A line between groups. */\nconst Separator = (props: SeparatorProps) =>\n usePart(useCombobox(\"Separator\").separator, \"div\", props)\n\nexport type ItemProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"item\"]>,\n {\n /** What the combobox's value is while this item is chosen. */\n value: unknown\n /** Disables this item: it cannot be chosen, and the arrows pass over it. */\n disabled?: boolean\n /** What is filtered and what the input shows; the item's text when left out. */\n label?: string\n id?: string\n /** Its place among all the rows, in a virtualized list. */\n index?: number\n }\n>\n\nfunction Item({ value, disabled, label, id, index, ...props }: ItemProps): ReactElement {\n const controller = useCombobox(\"Item\")\n const group = useContext(GroupContext) ?? undefined\n const generated = useId()\n const options = useOptions({ disabled, label, index, id: id ?? generated })\n const part = useMemo(\n () => controller.item(value, () => options.get(), group),\n [controller, value, options, group]\n )\n return <ItemContext.Provider value={value}>{usePart(part, \"div\", props)}</ItemContext.Provider>\n}\n\nexport type ItemIndicatorProps = PartComponentProps<\n \"span\",\n StateOf<Parts[\"itemIndicator\"]>,\n {\n /** Keeps the mark in the page while its item is not chosen. */\n keepMounted?: boolean\n }\n>\n\n/** In the page while its item is a chosen one. */\nfunction ItemIndicator({ keepMounted, ...props }: ItemIndicatorProps): ReactElement | null {\n const controller = useCombobox(\"ItemIndicator\")\n const value = useContext(ItemContext)\n const selected = useSignal(controller.selected(value))\n const part = useMemo(() => controller.itemIndicator(value), [controller, value])\n return selected || keepMounted ? <PartElement of={part} tag=\"span\" {...props} /> : null\n}\n\nexport type ClearProps = PartComponentProps<\n \"button\",\n StateOf<Parts[\"clear\"]>,\n {\n /** Keeps the button in the page while there is nothing to clear. */\n keepMounted?: boolean\n }\n>\n\n/** A button that empties the input and the value. Drawn while there is something to clear. */\nfunction Clear({ keepMounted, ...props }: ClearProps): ReactElement | null {\n const controller = useCombobox(\"Clear\")\n const clearable = useSignal(controller.clearable)\n return clearable || keepMounted ? (\n <PartElement of={controller.clear} tag=\"button\" {...props} />\n ) : null\n}\n\nexport type ChipsProps = PartComponentProps<\"div\", StateOf<Parts[\"chips\"]>>\n\n/** With `multiple`: what holds the chips and the input. */\nconst Chips = (props: ChipsProps) => usePart(useCombobox(\"Chips\").chips, \"div\", props)\n\nconst ChipContext = createContext<unknown>(undefined)\n\nexport type ChipProps = PartComponentProps<\n \"span\",\n StateOf<Parts[\"chip\"]>,\n {\n /** The chosen value this chip stands for. */\n value: unknown\n }\n>\n\n/** With `multiple`: one chosen value. Its `value` is what its remove button takes away. */\nfunction Chip({ value, ...props }: ChipProps): ReactElement {\n const controller = useCombobox(\"Chip\")\n const part = useMemo(() => controller.chip(value), [controller, value])\n return <ChipContext.Provider value={value}>{usePart(part, \"span\", props)}</ChipContext.Provider>\n}\n\nexport type ChipRemoveProps = PartComponentProps<\"button\", StateOf<Parts[\"chipRemove\"]>>\n\nfunction ChipRemove(props: ChipRemoveProps): ReactElement {\n const controller = useCombobox(\"ChipRemove\")\n const value = useContext(ChipContext)\n const part = useMemo(() => controller.chipRemove(value), [controller, value])\n return usePart(part, \"button\", props)\n}\n\nexport type EmptyProps = PartComponentProps<\"div\", StateOf<Parts[\"empty\"]>>\n\n/** Drawn while no item is shown for what was typed. */\nfunction Empty(props: EmptyProps): ReactElement | null {\n const controller = useCombobox(\"Empty\")\n const empty = useSignal(controller.empty)\n return empty ? <PartElement of={controller.emptyPart} tag=\"div\" {...props} /> : null\n}\n\nexport type AutocompleteRootProps = Omit<AutocompleteProps, \"id\"> & {\n id?: string\n children?: ReactNode\n}\n\n/** A combobox whose text is the value: the list only suggests. */\nfunction AutocompleteRoot({ children, ...props }: AutocompleteRootProps): ReactElement {\n const field = useContext(FieldContext) ?? undefined\n const controller = useController<AutocompleteProps, Controller>(\n within(createAutocomplete, { field }),\n props\n )\n return <Context.Provider value={controller}>{children}</Context.Provider>\n}\n\nexport const Combobox = /* @__PURE__ */ parts(\"Combobox\", {\n Root,\n Input,\n Trigger,\n Clear,\n Chips,\n Chip,\n ChipRemove,\n Portal,\n Positioner,\n Popup,\n List,\n Group,\n GroupLabel,\n Separator,\n Item,\n ItemIndicator,\n Empty,\n})\n\nexport const Autocomplete = /* @__PURE__ */ parts(\"Autocomplete\", {\n Root: AutocompleteRoot,\n Input,\n Trigger,\n Clear,\n Portal,\n Positioner,\n Popup,\n List,\n Group,\n GroupLabel,\n Separator,\n Item,\n Empty,\n})\n"],"mappings":";;;;;;;;AA4BA,MAAM,UAAU,cAAiC,IAAI;AACrD,MAAM,cAAc,cAAuB,KAAA,CAAS;AAEpD,SAAS,YAAY,MAA0B;CAC7C,MAAM,aAAa,WAAW,OAAO;CACrC,IAAI,CAAC,YAAY,MAAM,IAAI,MAAM,aAAa,KAAK,iCAAiC;CACpF,OAAO;AACT;AAQA,SAAS,KAAsB,EAAE,UAAU,GAAG,SAAyC;CACrF,MAAM,QAAQ,WAAW,YAAY,KAAK,KAAA;CAC1C,MAAM,aAAyB,cAC7B,OAAO,gBAAuB,EAAE,MAAM,CAAC,GACvC,KACF;CACA,MAAM,QAAQ,UAAU,WAAW,KAAK;CACxC,OACE,qBAAC,QAAQ,UAAT;EAAkB,OAAO;EAAzB,UAAA,CACG,UACA,QAAQ,oBAA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AAK,CAAC;CACtE,OAAO,oBAAC,YAAY,UAAb;EAA6B;EAAQ,UAAA,QAAQ,MAAM,QAAQ,KAAK;CAAwB,CAAA;AACjG;AAIA,SAAS,WAAW,OAAsC;CACxD,MAAM,aAAa,YAAY,YAAY;CAC3C,MAAM,QAAQ,WAAW,WAAW;CACpC,MAAM,OAAO,cAAc,WAAW,WAAW,KAAK,GAAG,CAAC,YAAY,KAAK,CAAC;CAC5E,OAAO,QAAQ,MAAM,UAAU,KAAK;AACtC;;AAKA,SAAS,MAAM,OAAwC;CACrD,MAAM,aAAa,YAAY,OAAO;CAEtC,OADc,UAAU,WAAW,KACxB,IAAI,oBAAC,aAAD;EAAa,IAAI,WAAW;EAAW,KAAI;EAAM,GAAI;CAAQ,CAAA,IAAI;AAClF;;AAQA,SAAS,iBAAiB,EAAE,UAAU,GAAG,SAA8C;CACrF,MAAM,QAAQ,WAAW,YAAY,KAAK,KAAA;CAC1C,MAAM,aAAa,cACjB,OAAO,oBAAoB,EAAE,MAAM,CAAC,GACpC,KACF;CACA,OAAO,oBAAC,QAAQ,UAAT;EAAkB,OAAO;EAAa;CAA2B,CAAA;AAC1E;AAEA,MAAa,WAA2B,sBAAM,YAAY;CACxD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,MAAa,eAA+B,sBAAM,gBAAgB;CAChE,MAAM;CACN;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC"}
|
|
1
|
+
{"version":3,"file":"combobox.js","names":["BodyPortal"],"sources":["../../../../packages/react/src/combobox.tsx"],"sourcesContent":["import { within } from \"@kirana-ui/core\"\nimport type { StateOf } from \"@kirana-ui/core\"\nimport { createAutocomplete } from \"@kirana-ui/core/autocomplete\"\nimport type { AutocompleteProps } from \"@kirana-ui/core/autocomplete\"\nimport { createCombobox } from \"@kirana-ui/core/combobox\"\nimport type {\n Combobox as Controller,\n ComboboxEntry,\n ComboboxGroup,\n ComboboxProps,\n} from \"@kirana-ui/core/combobox\"\nimport type { Vocabulary } from \"@kirana-ui/core/vocabulary\"\nimport { createContext, Fragment, useContext, useId, useMemo } from \"react\"\nimport type { ReactElement, ReactNode } from \"react\"\n\nimport { DirectionContext } from \"./direction-context.ts\"\nimport { FieldContext } from \"./field-context.ts\"\nimport {\n Portal as BodyPortal,\n PartElement,\n parts,\n useController,\n useMount,\n useOptions,\n useOwnText,\n usePart,\n usePositioning,\n useSignal,\n} from \"./runtime.tsx\"\nimport type { PartComponentProps, PortalProps, PositionerOptions } from \"./runtime.tsx\"\n\nexport type { PortalProps }\n\ntype Parts = Vocabulary[\"combobox\"]\n\nconst Context = createContext<Controller | null>(null)\nconst ItemContext = createContext<unknown>(undefined)\n\nfunction useCombobox(part: string): Controller {\n const controller = useContext(Context)\n if (!controller) throw new Error(`<Combobox.${part}> must be inside <Combobox.Root>`)\n return controller\n}\n\n/**\n * `Value` is what tells an item from the others. `Multiple` is inferred from `multiple`: with\n * `multiple`, `value`, `defaultValue` and `onValueChange` hold a list of them.\n */\nexport type RootProps<Value = unknown, Multiple extends boolean | undefined = false> = Omit<\n ComboboxProps<Value, Multiple>,\n \"id\" | \"multiple\"\n> & {\n /** Several values: `value`, `defaultValue` and `onValueChange` then hold a list. Read once. */\n multiple?: Multiple | undefined\n id?: string\n children?: ReactNode\n}\n\nfunction Root<Value = unknown, Multiple extends boolean | undefined = false>({\n children,\n ...props\n}: RootProps<Value, Multiple>): ReactElement {\n const field = useContext(FieldContext) ?? undefined\n const direction = useContext(DirectionContext) ?? undefined\n const controller: Controller = useController<ComboboxProps<Value, Multiple>, Controller<Value>>(\n within(createCombobox<Value, Multiple>, { field, direction }),\n props\n )\n const named = useSignal(controller.named)\n return (\n <Context.Provider value={controller}>\n {children}\n {named ? <HiddenInput /> : null}\n </Context.Provider>\n )\n}\n\nexport type InputProps = PartComponentProps<\"input\", StateOf<Parts[\"input\"]>>\nexport type TriggerProps = PartComponentProps<\"button\", StateOf<Parts[\"trigger\"]>>\nexport type PopupProps = PartComponentProps<\"div\", StateOf<Parts[\"popup\"]>>\nexport type ListProps = PartComponentProps<\"div\", StateOf<Parts[\"list\"]>>\n\nconst HiddenInput = () => usePart(useCombobox(\"Root\").hidden, \"input\", {})\nconst Input = (props: InputProps) => usePart(useOwnText(useCombobox(\"Input\").input), \"input\", props)\nconst Trigger = (props: TriggerProps) => usePart(useCombobox(\"Trigger\").trigger, \"button\", props)\nconst Popup = (props: PopupProps) => usePart(useCombobox(\"Popup\").popup, \"div\", props)\nexport type BackdropProps = PartComponentProps<\"div\", StateOf<Parts[\"backdrop\"]>>\n/** What lies over the page behind the list: a sheet's (`presentation`) is modal. */\nconst Backdrop = (props: BackdropProps) => usePart(useCombobox(\"Backdrop\").backdrop, \"div\", props)\n/**\n * The items' own box inside the popup, when the popup holds more than items (an input): it\n * is then the listbox.\n */\nconst List = (props: ListProps) => usePart(useCombobox(\"List\").list, \"div\", props)\n\nfunction Portal({ children }: PortalProps): ReactElement | null {\n const mounted = useSignal(useCombobox(\"Portal\").mounted)\n return mounted ? <BodyPortal>{children}</BodyPortal> : null\n}\n\nexport type PositionerProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"positioner\"]>,\n PositionerOptions\n>\n\nfunction Positioner(props: PositionerProps): ReactElement {\n const controller = useCombobox(\"Positioner\")\n return usePart(controller.positioner, \"div\", usePositioning(controller.positioning, props))\n}\n\nconst GroupContext = createContext<ComboboxGroup | null>(null)\n\nexport type GroupProps = PartComponentProps<\"div\", StateOf<Parts[\"group\"]>, { id?: string }>\n\n/** Items that belong together, named by their `GroupLabel`. Hidden while none is shown. */\nfunction Group({ id, ...props }: GroupProps): ReactElement {\n const controller = useCombobox(\"Group\")\n const generated = useId()\n const group = useMemo(() => controller.group(id ?? generated), [controller, id, generated])\n return (\n <GroupContext.Provider value={group}>{usePart(group.root, \"div\", props)}</GroupContext.Provider>\n )\n}\n\nexport type GroupLabelProps = PartComponentProps<\"div\", StateOf<Parts[\"groupLabel\"]>>\n\n/** A group's name. Outside a group it is plain text, and names nothing. */\nfunction GroupLabel(props: GroupLabelProps): ReactElement {\n const lone = useCombobox(\"GroupLabel\").groupLabel\n return usePart(useContext(GroupContext)?.label ?? lone, \"div\", props)\n}\n\nexport type SeparatorProps = PartComponentProps<\"div\", StateOf<Parts[\"separator\"]>>\n\n/** A line between groups. */\nconst Separator = (props: SeparatorProps) =>\n usePart(useCombobox(\"Separator\").separator, \"div\", props)\n\nexport type ItemProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"item\"]>,\n {\n /** What the combobox's value is while this item is chosen. */\n value: unknown\n /** Disables this item: it cannot be chosen, and the arrows pass over it. */\n disabled?: boolean\n /** What is filtered and what the input shows; the item's text when left out. */\n label?: string\n id?: string\n /** Its place among all the rows, in a virtualized list. */\n index?: number\n }\n>\n\nfunction Item({ value, disabled, label, id, index, ...props }: ItemProps): ReactElement {\n const controller = useCombobox(\"Item\")\n const group = useContext(GroupContext) ?? undefined\n const generated = useId()\n const options = useOptions({ disabled, label, index, id: id ?? generated })\n const part = useMemo(\n () => controller.item(value, () => options.get(), group),\n [controller, value, options, group]\n )\n return <ItemContext.Provider value={value}>{usePart(part, \"div\", props)}</ItemContext.Provider>\n}\n\nexport type ItemIndicatorProps = PartComponentProps<\n \"span\",\n StateOf<Parts[\"itemIndicator\"]>,\n {\n /** Keeps the mark in the page while its item is not chosen. */\n keepMounted?: boolean\n }\n>\n\n/** In the page while its item is a chosen one. */\nfunction ItemIndicator({ keepMounted, ...props }: ItemIndicatorProps): ReactElement | null {\n const controller = useCombobox(\"ItemIndicator\")\n const value = useContext(ItemContext)\n const part = useMemo(() => controller.itemIndicator(value), [controller, value])\n // In the page while chosen, and through its exit.\n useMount(part)\n const mounted = useSignal(part.mounted)\n return mounted || keepMounted ? <PartElement of={part} tag=\"span\" {...props} /> : null\n}\n\nexport type ClearProps = PartComponentProps<\n \"button\",\n StateOf<Parts[\"clear\"]>,\n {\n /** Keeps the button in the page while there is nothing to clear. */\n keepMounted?: boolean\n }\n>\n\n/** A button that empties the input and the value. Drawn while there is something to clear. */\nfunction Clear({ keepMounted, ...props }: ClearProps): ReactElement | null {\n const controller = useCombobox(\"Clear\")\n const clearable = useSignal(controller.clearable)\n return clearable || keepMounted ? (\n <PartElement of={controller.clear} tag=\"button\" {...props} />\n ) : null\n}\n\nexport type ChipsProps = PartComponentProps<\"div\", StateOf<Parts[\"chips\"]>>\n\n/** With `multiple`: what holds the chips and the input. */\nconst Chips = (props: ChipsProps) => usePart(useCombobox(\"Chips\").chips, \"div\", props)\n\nconst ChipContext = createContext<unknown>(undefined)\n\nexport type ChipProps = PartComponentProps<\n \"span\",\n StateOf<Parts[\"chip\"]>,\n {\n /** The chosen value this chip stands for. */\n value: unknown\n }\n>\n\n/** With `multiple`: one chosen value. Its `value` is what its remove button takes away. */\nfunction Chip({ value, ...props }: ChipProps): ReactElement {\n const controller = useCombobox(\"Chip\")\n const part = useMemo(() => controller.chip(value), [controller, value])\n return <ChipContext.Provider value={value}>{usePart(part, \"span\", props)}</ChipContext.Provider>\n}\n\nexport type ChipRemoveProps = PartComponentProps<\"button\", StateOf<Parts[\"chipRemove\"]>>\n\nfunction ChipRemove(props: ChipRemoveProps): ReactElement {\n const controller = useCombobox(\"ChipRemove\")\n const value = useContext(ChipContext)\n const part = useMemo(() => controller.chipRemove(value), [controller, value])\n return usePart(part, \"button\", props)\n}\n\nexport type EmptyProps = PartComponentProps<\"div\", StateOf<Parts[\"empty\"]>>\n\n/** Drawn while no item is shown for what was typed. */\nfunction Empty(props: EmptyProps): ReactElement | null {\n const controller = useCombobox(\"Empty\")\n const empty = useSignal(controller.empty)\n return empty ? <PartElement of={controller.emptyPart} tag=\"div\" {...props} /> : null\n}\n\nexport type StatusProps = PartComponentProps<\"div\", StateOf<Parts[\"status\"]>>\n\n/**\n * Says how the list stands (\"3 results\", \"Loading\") to software that reads the page, as its\n * text changes. Keep it in the page and change what it holds: inside the popup, or beside the\n * input.\n */\nconst Status = (props: StatusProps) => usePart(useCombobox(\"Status\").status, \"div\", props)\n\nexport type ValueProps<Chosen = unknown> = {\n /** Shown while nothing is chosen. */\n placeholder?: ReactNode\n /**\n * What to show in place of the label. A function is given the value and its label (`null`\n * and `undefined` while nothing is chosen); with `multiple`, the values and their labels, in\n * the order they were chosen.\n */\n children?:\n | ReactNode\n | ((\n value: Chosen,\n label: Chosen extends readonly unknown[] ? readonly string[] : string | undefined\n ) => ReactNode)\n}\n\n/**\n * The chosen value's label, or `placeholder` while nothing is chosen; with `multiple`, the\n * chosen labels with commas between. For a button that is the combobox, its input inside the\n * popup. It draws no element.\n */\nfunction Value<Chosen = unknown>({ placeholder, children }: ValueProps<Chosen>): ReactElement {\n const controller = useCombobox(\"Value\")\n const shown = useSignal(controller.shown)\n if (typeof children !== \"function\") return <>{children ?? shown.label ?? placeholder}</>\n const draw = children as (value: unknown, label: unknown) => ReactNode\n return (\n <>{controller.multiple ? draw(shown.values, shown.labels) : draw(shown.value, shown.label)}</>\n )\n}\n\nexport type CollectionProps<Value = unknown> = {\n /** A group the root's `items` gave: its items left are then what is drawn. */\n of?: ComboboxEntry<Value> | undefined\n /** Drawn once for each item left, or for each group that has items left. */\n children: (entry: ComboboxEntry<Value>) => ReactNode\n}\n\n/**\n * Draws the list from the root's `items`: its child once for each item left for what was\n * typed, or for each group that has items left; with `of`, for each of that group's. The root\n * then filters, and no item hides itself. It draws no element.\n */\nfunction Collection<Value = unknown>({ of, children }: CollectionProps<Value>): ReactElement {\n // The same signal each time it is asked for: a group's is kept by its key.\n const controller = useCombobox(\"Collection\") as unknown as Controller<Value>\n const entries = useSignal(controller.entries(of))\n return (\n <>\n {entries.map((entry) => (\n <Fragment key={entry.key}>{children(entry)}</Fragment>\n ))}\n </>\n )\n}\n\nexport type AutocompleteRootProps = Omit<AutocompleteProps, \"id\"> & {\n id?: string\n children?: ReactNode\n}\n\n/** A combobox whose text is the value: the list only suggests. */\nfunction AutocompleteRoot({ children, ...props }: AutocompleteRootProps): ReactElement {\n const field = useContext(FieldContext) ?? undefined\n const controller = useController<AutocompleteProps, Controller>(\n within(createAutocomplete, { field }),\n props\n )\n return <Context.Provider value={controller}>{children}</Context.Provider>\n}\n\nexport const Combobox = /* @__PURE__ */ parts(\"Combobox\", {\n Root,\n Input,\n Trigger,\n Value,\n Clear,\n Chips,\n Chip,\n ChipRemove,\n Portal,\n Backdrop,\n Positioner,\n Popup,\n List,\n Collection,\n Group,\n GroupLabel,\n Separator,\n Item,\n ItemIndicator,\n Empty,\n Status,\n})\n\nexport const Autocomplete = /* @__PURE__ */ parts(\"Autocomplete\", {\n Root: AutocompleteRoot,\n Input,\n Trigger,\n Clear,\n Portal,\n Positioner,\n Popup,\n List,\n Collection,\n Group,\n GroupLabel,\n Separator,\n Item,\n Empty,\n Status,\n})\n"],"mappings":";;;;;;;;;AAmCA,MAAM,UAAU,cAAiC,IAAI;AACrD,MAAM,cAAc,cAAuB,KAAA,CAAS;AAEpD,SAAS,YAAY,MAA0B;CAC7C,MAAM,aAAa,WAAW,OAAO;CACrC,IAAI,CAAC,YAAY,MAAM,IAAI,MAAM,aAAa,KAAK,iCAAiC;CACpF,OAAO;AACT;AAgBA,SAAS,KAAoE,EAC3E,UACA,GAAG,SACwC;CAC3C,MAAM,QAAQ,WAAW,YAAY,KAAK,KAAA;CAC1C,MAAM,YAAY,WAAW,gBAAgB,KAAK,KAAA;CAClD,MAAM,aAAyB,cAC7B,OAAO,gBAAiC;EAAE;EAAO;CAAU,CAAC,GAC5D,KACF;CACA,MAAM,QAAQ,UAAU,WAAW,KAAK;CACxC,OACE,qBAAC,QAAQ,UAAT;EAAkB,OAAO;EAAzB,UAAA,CACG,UACA,QAAQ,oBAAC,aAAD,CAAc,CAAA,IAAI,IACX;;AAEtB;AAOA,MAAM,oBAAoB,QAAQ,YAAY,MAAM,CAAC,CAAC,QAAQ,SAAS,CAAC,CAAC;AACzE,MAAM,SAAS,UAAsB,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,OAAO,oBAAoB,EAAE,MAAM,CAAC,GACpC,KACF;CACA,OAAO,oBAAC,QAAQ,UAAT;EAAkB,OAAO;EAAa;CAA2B,CAAA;AAC1E;AAEA,MAAa,WAA2B,sBAAM,YAAY;CACxD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,MAAa,eAA+B,sBAAM,gBAAgB;CAChE,MAAM;CACN;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC"}
|
package/src/command.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { PartComponentProps } from "./runtime.js";
|
|
2
|
-
import { StateOf } from "@kirana-ui/core";
|
|
3
2
|
import { ReactElement } from "react";
|
|
3
|
+
import { StateOf } from "@kirana-ui/core";
|
|
4
4
|
import { CommandProps } from "@kirana-ui/core/command";
|
|
5
5
|
import { Vocabulary } from "@kirana-ui/core/vocabulary";
|
|
6
6
|
type Parts = Vocabulary["command"];
|
|
7
7
|
export type RootProps = PartComponentProps<"div", StateOf<Parts["root"]>, Omit<CommandProps, "id"> & {
|
|
8
8
|
id?: string;
|
|
9
9
|
}>;
|
|
10
|
-
declare function Root({ inputValue, defaultInputValue, onInputValueChange, onSelect, filter, loop, disabled, id, ...rest }: RootProps): ReactElement;
|
|
10
|
+
declare function Root({ inputValue, defaultInputValue, onInputValueChange, onSelect, filter, loop, autoHighlight, disabled, id, ...rest }: RootProps): ReactElement;
|
|
11
11
|
export type InputProps = PartComponentProps<"input", StateOf<Parts["input"]>>;
|
|
12
12
|
declare const Input: (props: InputProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
13
13
|
export type ListProps = PartComponentProps<"div", StateOf<Parts["list"]>>;
|
|
@@ -23,8 +23,8 @@ declare function Group({ id, ...props }: GroupProps): ReactElement;
|
|
|
23
23
|
export type GroupHeadingProps = PartComponentProps<"div", StateOf<Parts["groupHeading"]>>;
|
|
24
24
|
declare function GroupHeading(props: GroupHeadingProps): ReactElement;
|
|
25
25
|
export type ItemProps = PartComponentProps<"div", StateOf<Parts["item"]>, {
|
|
26
|
-
/** What `onSelect` is told. */
|
|
27
|
-
value
|
|
26
|
+
/** What `onSelect` is told; its `label`, or its text, when left out. */
|
|
27
|
+
value?: string;
|
|
28
28
|
/** Disables this item: it cannot be chosen, and the arrows pass over it. */
|
|
29
29
|
disabled?: boolean;
|
|
30
30
|
/** What is filtered; the item's text when left out. */
|
package/src/command.js
CHANGED
|
@@ -10,7 +10,7 @@ function useCommand(part) {
|
|
|
10
10
|
if (!controller) throw new Error(`<Command.${part}> must be inside <Command.Root>`);
|
|
11
11
|
return controller;
|
|
12
12
|
}
|
|
13
|
-
function Root({ inputValue, defaultInputValue, onInputValueChange, onSelect, filter, loop, disabled, id, ...rest }) {
|
|
13
|
+
function Root({ inputValue, defaultInputValue, onInputValueChange, onSelect, filter, loop, autoHighlight, disabled, id, ...rest }) {
|
|
14
14
|
const controller = useController(createCommand, {
|
|
15
15
|
inputValue,
|
|
16
16
|
defaultInputValue,
|
|
@@ -18,6 +18,7 @@ function Root({ inputValue, defaultInputValue, onInputValueChange, onSelect, fil
|
|
|
18
18
|
onSelect,
|
|
19
19
|
filter,
|
|
20
20
|
loop,
|
|
21
|
+
autoHighlight,
|
|
21
22
|
disabled,
|
|
22
23
|
id
|
|
23
24
|
});
|
package/src/command.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command.js","names":[],"sources":["../../../../packages/react/src/command.tsx"],"sourcesContent":["import type { StateOf } from \"@kirana-ui/core\"\nimport { createCommand } from \"@kirana-ui/core/command\"\nimport type { CommandGroup, CommandProps, Command as Controller } from \"@kirana-ui/core/command\"\nimport type { Vocabulary } from \"@kirana-ui/core/vocabulary\"\nimport { createContext, useContext, useId, useMemo } from \"react\"\nimport type { ReactElement } from \"react\"\n\nimport {\n PartElement,\n parts,\n useController,\n useOptions,\n useOwnText,\n usePart,\n useSignal,\n} from \"./runtime.tsx\"\nimport type { PartComponentProps } from \"./runtime.tsx\"\n\ntype Parts = Vocabulary[\"command\"]\n\nconst Context = createContext<Controller | null>(null)\nconst GroupContext = createContext<CommandGroup | undefined>(undefined)\n\nfunction useCommand(part: string): Controller {\n const controller = useContext(Context)\n if (!controller) throw new Error(`<Command.${part}> must be inside <Command.Root>`)\n return controller\n}\n\nexport type RootProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"root\"]>,\n Omit<CommandProps, \"id\"> & { id?: string }\n>\n\nfunction Root({\n inputValue,\n defaultInputValue,\n onInputValueChange,\n onSelect,\n filter,\n loop,\n disabled,\n id,\n ...rest\n}: RootProps): ReactElement {\n const controller = useController<CommandProps, Controller>(createCommand, {\n inputValue,\n defaultInputValue,\n onInputValueChange,\n onSelect,\n filter,\n loop,\n disabled,\n id,\n })\n return (\n <Context.Provider value={controller}>\n <PartElement of={controller.root} tag=\"div\" {...rest} />\n </Context.Provider>\n )\n}\n\nexport type InputProps = PartComponentProps<\"input\", StateOf<Parts[\"input\"]>>\n\nconst Input = (props: InputProps) => usePart(useOwnText(useCommand(\"Input\").input), \"input\", props)\nexport type ListProps = PartComponentProps<\"div\", StateOf<Parts[\"list\"]>>\n\nconst List = (props: ListProps) => usePart(useCommand(\"List\").list, \"div\", props)\n\nexport type EmptyProps = PartComponentProps<\"div\", StateOf<Parts[\"empty\"]>>\n\n/** Drawn while no item is shown for what was typed. */\nfunction Empty(props: EmptyProps): ReactElement | null {\n const controller = useCommand(\"Empty\")\n const empty = useSignal(controller.empty)\n return empty ? <PartElement of={controller.emptyPart} tag=\"div\" {...props} /> : null\n}\n\nexport type GroupProps = PartComponentProps<\"div\", StateOf<Parts[\"group\"]>, { id?: string }>\n\n/** Items under a `<Command.GroupHeading>`. Hidden while none of them is shown. */\nfunction Group({ id, ...props }: GroupProps): ReactElement {\n const controller = useCommand(\"Group\")\n const generated = useId()\n const name = id ?? generated\n const group = useMemo(() => controller.group(name), [controller, name])\n return (\n <GroupContext.Provider value={group}>{usePart(group.part, \"div\", props)}</GroupContext.Provider>\n )\n}\n\nexport type GroupHeadingProps = PartComponentProps<\"div\", StateOf<Parts[\"groupHeading\"]>>\n\nfunction GroupHeading(props: GroupHeadingProps): ReactElement {\n const lone = useCommand(\"GroupHeading\").heading\n return usePart(useContext(GroupContext)?.heading ?? lone, \"div\", props)\n}\n\nexport type ItemProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"item\"]>,\n {\n /** What `onSelect` is told. */\n value
|
|
1
|
+
{"version":3,"file":"command.js","names":[],"sources":["../../../../packages/react/src/command.tsx"],"sourcesContent":["import type { StateOf } from \"@kirana-ui/core\"\nimport { createCommand } from \"@kirana-ui/core/command\"\nimport type { CommandGroup, CommandProps, Command as Controller } from \"@kirana-ui/core/command\"\nimport type { Vocabulary } from \"@kirana-ui/core/vocabulary\"\nimport { createContext, useContext, useId, useMemo } from \"react\"\nimport type { ReactElement } from \"react\"\n\nimport {\n PartElement,\n parts,\n useController,\n useOptions,\n useOwnText,\n usePart,\n useSignal,\n} from \"./runtime.tsx\"\nimport type { PartComponentProps } from \"./runtime.tsx\"\n\ntype Parts = Vocabulary[\"command\"]\n\nconst Context = createContext<Controller | null>(null)\nconst GroupContext = createContext<CommandGroup | undefined>(undefined)\n\nfunction useCommand(part: string): Controller {\n const controller = useContext(Context)\n if (!controller) throw new Error(`<Command.${part}> must be inside <Command.Root>`)\n return controller\n}\n\nexport type RootProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"root\"]>,\n Omit<CommandProps, \"id\"> & { id?: string }\n>\n\nfunction Root({\n inputValue,\n defaultInputValue,\n onInputValueChange,\n onSelect,\n filter,\n loop,\n autoHighlight,\n disabled,\n id,\n ...rest\n}: RootProps): ReactElement {\n const controller = useController<CommandProps, Controller>(createCommand, {\n inputValue,\n defaultInputValue,\n onInputValueChange,\n onSelect,\n filter,\n loop,\n autoHighlight,\n disabled,\n id,\n })\n return (\n <Context.Provider value={controller}>\n <PartElement of={controller.root} tag=\"div\" {...rest} />\n </Context.Provider>\n )\n}\n\nexport type InputProps = PartComponentProps<\"input\", StateOf<Parts[\"input\"]>>\n\nconst Input = (props: InputProps) => usePart(useOwnText(useCommand(\"Input\").input), \"input\", props)\nexport type ListProps = PartComponentProps<\"div\", StateOf<Parts[\"list\"]>>\n\nconst List = (props: ListProps) => usePart(useCommand(\"List\").list, \"div\", props)\n\nexport type EmptyProps = PartComponentProps<\"div\", StateOf<Parts[\"empty\"]>>\n\n/** Drawn while no item is shown for what was typed. */\nfunction Empty(props: EmptyProps): ReactElement | null {\n const controller = useCommand(\"Empty\")\n const empty = useSignal(controller.empty)\n return empty ? <PartElement of={controller.emptyPart} tag=\"div\" {...props} /> : null\n}\n\nexport type GroupProps = PartComponentProps<\"div\", StateOf<Parts[\"group\"]>, { id?: string }>\n\n/** Items under a `<Command.GroupHeading>`. Hidden while none of them is shown. */\nfunction Group({ id, ...props }: GroupProps): ReactElement {\n const controller = useCommand(\"Group\")\n const generated = useId()\n const name = id ?? generated\n const group = useMemo(() => controller.group(name), [controller, name])\n return (\n <GroupContext.Provider value={group}>{usePart(group.part, \"div\", props)}</GroupContext.Provider>\n )\n}\n\nexport type GroupHeadingProps = PartComponentProps<\"div\", StateOf<Parts[\"groupHeading\"]>>\n\nfunction GroupHeading(props: GroupHeadingProps): ReactElement {\n const lone = useCommand(\"GroupHeading\").heading\n return usePart(useContext(GroupContext)?.heading ?? lone, \"div\", props)\n}\n\nexport type ItemProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"item\"]>,\n {\n /** What `onSelect` is told; its `label`, or its text, when left out. */\n value?: string\n /** Disables this item: it cannot be chosen, and the arrows pass over it. */\n disabled?: boolean\n /** What is filtered; the item's text when left out. */\n label?: string\n /** Other words the item answers to. */\n keywords?: readonly string[]\n id?: string\n }\n>\n\nfunction Item({ value, disabled, label, keywords, id, ...props }: ItemProps): ReactElement {\n const controller = useCommand(\"Item\")\n const group = useContext(GroupContext)\n const generated = useId()\n const options = useOptions({ disabled, label, keywords, id: id ?? generated })\n const part = useMemo(\n () => controller.item(value, () => options.get(), group),\n [controller, value, options, group]\n )\n return usePart(part, \"div\", props)\n}\n\nexport type SeparatorProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"separator\"]>,\n {\n /** Stays while something is typed. */\n alwaysRender?: boolean\n }\n>\n\nfunction Separator({ alwaysRender, ...props }: SeparatorProps): ReactElement {\n const controller = useCommand(\"Separator\")\n const options = useOptions({ alwaysRender })\n const part = useMemo(\n () => controller.separator(() => options.get().alwaysRender),\n [controller, options]\n )\n return usePart(part, \"div\", props)\n}\n\nexport const Command = /* @__PURE__ */ parts(\"Command\", {\n Root,\n Input,\n List,\n Empty,\n Group,\n GroupHeading,\n Item,\n Separator,\n})\n"],"mappings":";;;;;AAoBA,MAAM,UAAU,cAAiC,IAAI;AACrD,MAAM,eAAe,cAAwC,KAAA,CAAS;AAEtE,SAAS,WAAW,MAA0B;CAC5C,MAAM,aAAa,WAAW,OAAO;CACrC,IAAI,CAAC,YAAY,MAAM,IAAI,MAAM,YAAY,KAAK,gCAAgC;CAClF,OAAO;AACT;AAQA,SAAS,KAAK,EACZ,YACA,mBACA,oBACA,UACA,QACA,MACA,eACA,UACA,IACA,GAAG,QACuB;CAC1B,MAAM,aAAa,cAAwC,eAAe;EACxE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;CACD,OACE,oBAAC,QAAQ,UAAT;EAAkB,OAAO;EACvB,UAAA,oBAAC,aAAD;GAAa,IAAI,WAAW;GAAM,KAAI;GAAM,GAAI;EAAO,CAAA;CACvC,CAAA;AAEtB;AAIA,MAAM,SAAS,UAAsB,QAAQ,WAAW,WAAW,OAAO,CAAC,CAAC,KAAK,GAAG,SAAS,KAAK;AAGlG,MAAM,QAAQ,UAAqB,QAAQ,WAAW,MAAM,CAAC,CAAC,MAAM,OAAO,KAAK;;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MAAM,OAAO,KAAK;AACnC;AAEA,MAAa,UAA0B,sBAAM,WAAW;CACtD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC"}
|
package/src/date-field.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PartComponentProps } from "./runtime.js";
|
|
2
|
-
import { StateOf } from "@kirana-ui/core";
|
|
3
2
|
import { ReactElement, ReactNode } from "react";
|
|
3
|
+
import { StateOf } from "@kirana-ui/core";
|
|
4
4
|
import { DateField as DateField$1, DateFieldProps, DateFieldSegment } from "@kirana-ui/core/date-field";
|
|
5
5
|
import { Vocabulary } from "@kirana-ui/core/vocabulary";
|
|
6
6
|
type Parts = Vocabulary["dateField"];
|
|
@@ -12,7 +12,7 @@ declare const Context: import("react").Context<DateField$1 | null>;
|
|
|
12
12
|
export type RootProps = PartComponentProps<"div", StateOf<Parts["root"]>, Omit<DateFieldProps, "id"> & {
|
|
13
13
|
id?: string;
|
|
14
14
|
}>;
|
|
15
|
-
declare function Root({ value, defaultValue, onValueChange, locale, min, max, placeholders, disabled, readOnly, required, name, form, id, ...rest }: RootProps): ReactElement;
|
|
15
|
+
declare function Root({ value, defaultValue, onValueChange, locale, calendarSystem, min, max, placeholders, disabled, readOnly, required, name, form, id, ...rest }: RootProps): ReactElement;
|
|
16
16
|
export interface SegmentsProps {
|
|
17
17
|
/** Draws one piece of the date, once for each: a part that is typed, or what stands between two. */
|
|
18
18
|
children: (segment: DateFieldSegment) => ReactNode;
|
package/src/date-field.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DirectionContext } from "./direction-context.js";
|
|
2
2
|
import { parts, useController, usePart, useSignal } from "./runtime.js";
|
|
3
|
-
import { within } from "@kirana-ui/core";
|
|
4
3
|
import { Fragment, createContext, useContext } from "react";
|
|
4
|
+
import { within } from "@kirana-ui/core";
|
|
5
5
|
import { Fragment as Fragment$1, jsx } from "react/jsx-runtime";
|
|
6
6
|
import { createDateField } from "@kirana-ui/core/date-field";
|
|
7
7
|
// src/date-field.tsx
|
|
@@ -15,13 +15,14 @@ function useDateField(part) {
|
|
|
15
15
|
if (!controller) throw new Error(`<DateField.${part}> must be inside <DateField.Root>`);
|
|
16
16
|
return controller;
|
|
17
17
|
}
|
|
18
|
-
function Root({ value, defaultValue, onValueChange, locale, min, max, placeholders, disabled, readOnly, required, name, form, id, ...rest }) {
|
|
18
|
+
function Root({ value, defaultValue, onValueChange, locale, calendarSystem, min, max, placeholders, disabled, readOnly, required, name, form, id, ...rest }) {
|
|
19
19
|
const direction = useContext(DirectionContext) ?? void 0;
|
|
20
20
|
const controller = useController(within(createDateField, { direction }), {
|
|
21
21
|
value,
|
|
22
22
|
defaultValue,
|
|
23
23
|
onValueChange,
|
|
24
24
|
locale,
|
|
25
|
+
calendarSystem,
|
|
25
26
|
min,
|
|
26
27
|
max,
|
|
27
28
|
placeholders,
|
package/src/date-field.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"date-field.js","names":[],"sources":["../../../../packages/react/src/date-field.tsx"],"sourcesContent":["import { within } from \"@kirana-ui/core\"\nimport type { StateOf } from \"@kirana-ui/core\"\nimport { createDateField } from \"@kirana-ui/core/date-field\"\nimport type {\n DateField as Controller,\n DateFieldProps,\n DateFieldSegment,\n} from \"@kirana-ui/core/date-field\"\nimport type { Vocabulary } from \"@kirana-ui/core/vocabulary\"\nimport { Fragment, createContext, useContext } from \"react\"\nimport type { ReactElement, ReactNode } from \"react\"\n\nimport { DirectionContext } from \"./direction-context.ts\"\nimport { parts, useController, usePart, useSignal } from \"./runtime.tsx\"\nimport type { PartComponentProps } from \"./runtime.tsx\"\n\ntype Parts = Vocabulary[\"dateField\"]\n\n/**\n * The date field its parts are inside. Exported for a component that is made of one (a date picker\n * provides its own to the date field's parts).\n */\nconst Context = createContext<Controller | null>(null)\n/** For a component made of this one's parts: a date picker. */\nexport { Context as DateFieldContext }\n\nfunction useDateField(part: string): Controller {\n const controller = useContext(Context)\n if (!controller) throw new Error(`<DateField.${part}> must be inside <DateField.Root>`)\n return controller\n}\n\nexport type RootProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"root\"]>,\n Omit<DateFieldProps, \"id\"> & { id?: string }\n>\n\nfunction Root({\n value,\n defaultValue,\n onValueChange,\n locale,\n min,\n max,\n placeholders,\n disabled,\n readOnly,\n required,\n name,\n form,\n id,\n ...rest\n}: RootProps): ReactElement {\n const direction = useContext(DirectionContext) ?? undefined\n const controller = useController<DateFieldProps, Controller>(\n within(createDateField, { direction }),\n {\n value,\n defaultValue,\n onValueChange,\n locale,\n min,\n max,\n placeholders,\n disabled,\n readOnly,\n required,\n name,\n form,\n id,\n }\n )\n return (\n <Context.Provider value={controller}>{usePart(controller.root, \"div\", rest)}</Context.Provider>\n )\n}\n\nexport interface SegmentsProps {\n /** Draws one piece of the date, once for each: a part that is typed, or what stands between two. */\n children: (segment: DateFieldSegment) => ReactNode\n}\n\n/** Draws its child once for each piece of the date, in the locale's order. */\nfunction Segments({ children }: SegmentsProps) {\n const segments = useSignal(useDateField(\"Segments\").segments)\n return (\n <>\n {segments.map((segment) => (\n <Fragment key={`${segment.index}-${segment.type}`}>{children(segment)}</Fragment>\n ))}\n </>\n )\n}\n\nexport type SegmentProps = PartComponentProps<\n \"span\",\n StateOf<Parts[\"segment\"]>,\n {\n /** The piece it is: an entry `DateField.Segments` gave. */\n segment: DateFieldSegment\n }\n>\n\n/** One piece: a part that is typed, or what stands between two. It writes its own text. */\nfunction Segment({ segment, ...props }: SegmentProps): ReactElement {\n const { part, text } = useDateField(\"Segment\").segment(segment)\n const shown = useSignal(text)\n // Its text is the field's to write: the browser never edits it, whatever React fears.\n return usePart(part, \"span\", { ...props, suppressContentEditableWarning: true, children: shown })\n}\n\nexport type InputProps = PartComponentProps<\"input\", StateOf<Parts[\"input\"]>>\n\nconst Input = (props: InputProps) => usePart(useDateField(\"Input\").input, \"input\", props)\n\nexport const DateField = /* @__PURE__ */ parts(\"DateField\",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}
|
|
1
|
+
{"version":3,"file":"date-field.js","names":[],"sources":["../../../../packages/react/src/date-field.tsx"],"sourcesContent":["import { within } from \"@kirana-ui/core\"\nimport type { StateOf } from \"@kirana-ui/core\"\nimport { createDateField } from \"@kirana-ui/core/date-field\"\nimport type {\n DateField as Controller,\n DateFieldProps,\n DateFieldSegment,\n} from \"@kirana-ui/core/date-field\"\nimport type { Vocabulary } from \"@kirana-ui/core/vocabulary\"\nimport { Fragment, createContext, useContext } from \"react\"\nimport type { ReactElement, ReactNode } from \"react\"\n\nimport { DirectionContext } from \"./direction-context.ts\"\nimport { parts, useController, usePart, useSignal } from \"./runtime.tsx\"\nimport type { PartComponentProps } from \"./runtime.tsx\"\n\ntype Parts = Vocabulary[\"dateField\"]\n\n/**\n * The date field its parts are inside. Exported for a component that is made of one (a date picker\n * provides its own to the date field's parts).\n */\nconst Context = createContext<Controller | null>(null)\n/** For a component made of this one's parts: a date picker. */\nexport { Context as DateFieldContext }\n\nfunction useDateField(part: string): Controller {\n const controller = useContext(Context)\n if (!controller) throw new Error(`<DateField.${part}> must be inside <DateField.Root>`)\n return controller\n}\n\nexport type RootProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"root\"]>,\n Omit<DateFieldProps, \"id\"> & { id?: string }\n>\n\nfunction Root({\n value,\n defaultValue,\n onValueChange,\n locale,\n calendarSystem,\n min,\n max,\n placeholders,\n disabled,\n readOnly,\n required,\n name,\n form,\n id,\n ...rest\n}: RootProps): ReactElement {\n const direction = useContext(DirectionContext) ?? undefined\n const controller = useController<DateFieldProps, Controller>(\n within(createDateField, { direction }),\n {\n value,\n defaultValue,\n onValueChange,\n locale,\n calendarSystem,\n min,\n max,\n placeholders,\n disabled,\n readOnly,\n required,\n name,\n form,\n id,\n }\n )\n return (\n <Context.Provider value={controller}>{usePart(controller.root, \"div\", rest)}</Context.Provider>\n )\n}\n\nexport interface SegmentsProps {\n /** Draws one piece of the date, once for each: a part that is typed, or what stands between two. */\n children: (segment: DateFieldSegment) => ReactNode\n}\n\n/** Draws its child once for each piece of the date, in the locale's order. */\nfunction Segments({ children }: SegmentsProps) {\n const segments = useSignal(useDateField(\"Segments\").segments)\n return (\n <>\n {segments.map((segment) => (\n <Fragment key={`${segment.index}-${segment.type}`}>{children(segment)}</Fragment>\n ))}\n </>\n )\n}\n\nexport type SegmentProps = PartComponentProps<\n \"span\",\n StateOf<Parts[\"segment\"]>,\n {\n /** The piece it is: an entry `DateField.Segments` gave. */\n segment: DateFieldSegment\n }\n>\n\n/** One piece: a part that is typed, or what stands between two. It writes its own text. */\nfunction Segment({ segment, ...props }: SegmentProps): ReactElement {\n const { part, text } = useDateField(\"Segment\").segment(segment)\n const shown = useSignal(text)\n // Its text is the field's to write: the browser never edits it, whatever React fears.\n return usePart(part, \"span\", { ...props, suppressContentEditableWarning: true, children: shown })\n}\n\nexport type InputProps = PartComponentProps<\"input\", StateOf<Parts[\"input\"]>>\n\nconst Input = (props: InputProps) => usePart(useDateField(\"Input\").input, \"input\", props)\n\nexport const DateField = /* @__PURE__ */ parts(\"DateField\", { Root, Segments, Segment, Input })\n"],"mappings":";;;;;;;;;;;AAsBA,MAAM,UAAU,cAAiC,IAAI;AAIrD,SAAS,aAAa,MAA0B;CAC9C,MAAM,aAAa,WAAW,OAAO;CACrC,IAAI,CAAC,YAAY,MAAM,IAAI,MAAM,cAAc,KAAK,kCAAkC;CACtF,OAAO;AACT;AAQA,SAAS,KAAK,EACZ,OACA,cACA,eACA,QACA,gBACA,KACA,KACA,cACA,UACA,UACA,UACA,MACA,MACA,IACA,GAAG,QACuB;CAC1B,MAAM,YAAY,WAAW,gBAAgB,KAAK,KAAA;CAClD,MAAM,aAAa,cACjB,OAAO,iBAAiB,EAAE,UAAU,CAAC,GACrC;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CACF;CACA,OACE,oBAAC,QAAQ,UAAT;EAAkB,OAAO;EAAa,UAAA,QAAQ,WAAW,MAAM,OAAO,IAAI;CAAoB,CAAA;AAElG;;AAQA,SAAS,SAAS,EAAE,YAA2B;CAC7C,MAAM,WAAW,UAAU,aAAa,UAAU,CAAC,CAAC,QAAQ;CAC5D,OACE,oBAAA,YAAA,EAAA,UACG,SAAS,KAAK,YACb,oBAAC,UAAD,EAAA,UAAoD,SAAS,OAAO,EAAY,GAAjE,GAAG,QAAQ,MAAM,GAAG,QAAQ,MAAqC,CACjF,EACD,CAAA;AAEN;;AAYA,SAAS,QAAQ,EAAE,SAAS,GAAG,SAAqC;CAClE,MAAM,EAAE,MAAM,SAAS,aAAa,SAAS,CAAC,CAAC,QAAQ,OAAO;CAC9D,MAAM,QAAQ,UAAU,IAAI;CAE5B,OAAO,QAAQ,MAAM,QAAQ;EAAE,GAAG;EAAO,gCAAgC;EAAM,UAAU;CAAM,CAAC;AAClG;AAIA,MAAM,SAAS,UAAsB,QAAQ,aAAa,OAAO,CAAC,CAAC,OAAO,SAAS,KAAK;AAExF,MAAa,YAA4B,sBAAM,aAAa;CAAE;CAAM;CAAU;CAAS;AAAM,CAAC"}
|
package/src/date-picker.d.ts
CHANGED
|
@@ -1,31 +1,50 @@
|
|
|
1
1
|
import { InputProps, SegmentProps, SegmentsProps } from "./date-field.js";
|
|
2
2
|
import { PopupProps, PositionerProps, TriggerProps } from "./popover.js";
|
|
3
3
|
import { PartComponentProps, PortalProps } from "./runtime.js";
|
|
4
|
-
import { CellProps, DayProps, GridProps, HeadCellProps, HeadingProps, NextProps, PreviousProps, WeekdaysProps, WeeksProps } from "./calendar.js";
|
|
5
|
-
import { StateOf } from "@kirana-ui/core";
|
|
6
|
-
import { DatePickerProps } from "@kirana-ui/core/date-picker";
|
|
4
|
+
import { CellProps, DayProps, GridProps, HeadCellProps, HeadingProps, MonthsProps, NextProps, PreviousProps, WeekdaysProps, WeeksProps } from "./calendar.js";
|
|
7
5
|
import { ReactElement, ReactNode } from "react";
|
|
6
|
+
import { StateOf } from "@kirana-ui/core";
|
|
7
|
+
import { DatePickerMode, DatePickerProps, DatePickerRange } from "@kirana-ui/core/date-picker";
|
|
8
8
|
import { Vocabulary } from "@kirana-ui/core/vocabulary";
|
|
9
9
|
type Parts = Vocabulary["datePicker"];
|
|
10
|
-
|
|
10
|
+
/** `value` and `onValueChange` are typed by `mode`: a day, or a range. */
|
|
11
|
+
export type RootProps<Mode extends DatePickerMode = "single"> = Omit<DatePickerProps<Mode>, "id"> & {
|
|
11
12
|
id?: string;
|
|
12
13
|
children?: ReactNode;
|
|
13
14
|
};
|
|
14
15
|
/** A date field, and a calendar in a popover, with one value between them. It draws nothing. */
|
|
15
|
-
declare function Root({ children, ...props }: RootProps): ReactElement;
|
|
16
|
-
export type FieldProps = PartComponentProps<"div", StateOf<Parts["field"]
|
|
16
|
+
declare function Root<Mode extends DatePickerMode = "single">({ children, ...props }: RootProps<Mode>): ReactElement;
|
|
17
|
+
export type FieldProps = PartComponentProps<"div", StateOf<Parts["field"]>, {
|
|
18
|
+
/**
|
|
19
|
+
* With `mode="range"`: which day of the range it is typed in, the first (`"start"`, the
|
|
20
|
+
* default) or the last (`"end"`).
|
|
21
|
+
*/
|
|
22
|
+
range?: "start" | "end" | undefined;
|
|
23
|
+
}>;
|
|
17
24
|
export type CalendarProps = PartComponentProps<"div", StateOf<Parts["calendar"]>>;
|
|
18
|
-
|
|
19
|
-
|
|
25
|
+
export type ClearProps = PartComponentProps<"button", StateOf<Parts["clear"]>>;
|
|
26
|
+
export type PresetProps = PartComponentProps<"button", StateOf<Parts["preset"]>, {
|
|
27
|
+
/** The value its press gives: a day, or with `mode="range"` a range. */
|
|
28
|
+
value: string | DatePickerRange;
|
|
29
|
+
}>;
|
|
30
|
+
/**
|
|
31
|
+
* The typed date: what holds its segments and its hidden input. With `mode="range"` there are
|
|
32
|
+
* two, `range="start"` and `range="end"`, each giving its own parts their field.
|
|
33
|
+
*/
|
|
34
|
+
declare function Field({ range, ...props }: FieldProps): ReactElement;
|
|
20
35
|
/** The calendar: what holds its heading, its buttons and its grid. */
|
|
21
36
|
declare const CalendarRoot: (props: CalendarProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
37
|
+
/** Empties the value, and gives focus to the field. Disabled while there is none. */
|
|
38
|
+
declare const Clear: (props: ClearProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
39
|
+
/** Makes the value the one it is given: pressed while it is. */
|
|
40
|
+
declare const Preset: ({ value, ...props }: PresetProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
22
41
|
export declare const DatePicker: {
|
|
23
42
|
readonly Root: typeof Root;
|
|
24
43
|
readonly Field: typeof Field;
|
|
25
44
|
readonly Segments: ({ children }: SegmentsProps) => import("react").JSX.Element;
|
|
26
45
|
readonly Segment: ({ segment, ...props }: SegmentProps) => ReactElement;
|
|
27
46
|
readonly Input: (props: InputProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
28
|
-
readonly Trigger: (props: TriggerProps) => ReactElement
|
|
47
|
+
readonly Trigger: ({ openOnHover, delay, closeDelay, ...props }: TriggerProps) => ReactElement;
|
|
29
48
|
readonly Portal: ({ children }: PortalProps) => ReactElement | null;
|
|
30
49
|
readonly Positioner: (props: PositionerProps) => ReactElement;
|
|
31
50
|
readonly Popup: (props: PopupProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
@@ -33,12 +52,15 @@ export declare const DatePicker: {
|
|
|
33
52
|
readonly Heading: ({ children, ...props }: HeadingProps) => ReactElement;
|
|
34
53
|
readonly Previous: (props: PreviousProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
35
54
|
readonly Next: (props: NextProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
55
|
+
readonly Months: ({ children }: MonthsProps) => import("react").JSX.Element;
|
|
36
56
|
readonly Grid: (props: GridProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
37
57
|
readonly Weekdays: ({ children }: WeekdaysProps) => import("react").JSX.Element;
|
|
38
58
|
readonly HeadCell: ({ weekday, ...props }: HeadCellProps) => ReactElement;
|
|
39
59
|
readonly Weeks: ({ children }: WeeksProps) => import("react").JSX.Element;
|
|
40
60
|
readonly Cell: ({ date, ...props }: CellProps) => ReactElement;
|
|
41
|
-
readonly Day: ({ date, ...props }: DayProps) => ReactElement;
|
|
61
|
+
readonly Day: ({ date: given, ...props }: DayProps) => ReactElement;
|
|
62
|
+
readonly Clear: typeof Clear;
|
|
63
|
+
readonly Preset: typeof Preset;
|
|
42
64
|
};
|
|
43
|
-
export type { CellProps, DayProps, GridProps, HeadCellProps, HeadingProps, InputProps, NextProps, PopupProps, PortalProps, PositionerProps, PreviousProps, SegmentProps, SegmentsProps, TriggerProps, WeekdaysProps, WeeksProps };
|
|
65
|
+
export type { CellProps, DayProps, GridProps, HeadCellProps, HeadingProps, InputProps, MonthsProps, NextProps, PopupProps, PortalProps, PositionerProps, PreviousProps, SegmentProps, SegmentsProps, TriggerProps, WeekdaysProps, WeeksProps };
|
|
44
66
|
//# sourceMappingURL=date-picker.d.ts.map
|
package/src/date-picker.js
CHANGED
|
@@ -3,10 +3,10 @@ import { DateField, DateFieldContext as Context$2 } from "./date-field.js";
|
|
|
3
3
|
import { DirectionContext } from "./direction-context.js";
|
|
4
4
|
import { Popover, PopoverContext as Context$3 } from "./popover.js";
|
|
5
5
|
import { parts, useController, usePart } from "./runtime.js";
|
|
6
|
-
import { within } from "@kirana-ui/core";
|
|
7
|
-
import { createDatePicker } from "@kirana-ui/core/date-picker";
|
|
8
6
|
import { createContext, useContext } from "react";
|
|
7
|
+
import { within } from "@kirana-ui/core";
|
|
9
8
|
import { jsx } from "react/jsx-runtime";
|
|
9
|
+
import { createDatePicker } from "@kirana-ui/core/date-picker";
|
|
10
10
|
// src/date-picker.tsx
|
|
11
11
|
const Context = createContext(null);
|
|
12
12
|
function useDatePicker(part) {
|
|
@@ -32,10 +32,24 @@ function Root({ children, ...props }) {
|
|
|
32
32
|
})
|
|
33
33
|
});
|
|
34
34
|
}
|
|
35
|
-
/**
|
|
36
|
-
|
|
35
|
+
/**
|
|
36
|
+
* The typed date: what holds its segments and its hidden input. With `mode="range"` there are
|
|
37
|
+
* two, `range="start"` and `range="end"`, each giving its own parts their field.
|
|
38
|
+
*/
|
|
39
|
+
function Field({ range, ...props }) {
|
|
40
|
+
const picker = useDatePicker("Field");
|
|
41
|
+
const field = range === "end" && picker.endField || picker.field;
|
|
42
|
+
return /* @__PURE__ */ jsx(Context$2.Provider, {
|
|
43
|
+
value: field,
|
|
44
|
+
children: usePart(field.root, "div", props)
|
|
45
|
+
});
|
|
46
|
+
}
|
|
37
47
|
/** The calendar: what holds its heading, its buttons and its grid. */
|
|
38
48
|
const CalendarRoot = (props) => usePart(useDatePicker("Calendar").calendar.root, "div", props);
|
|
49
|
+
/** Empties the value, and gives focus to the field. Disabled while there is none. */
|
|
50
|
+
const Clear = (props) => usePart(useDatePicker("Clear").clear, "button", props);
|
|
51
|
+
/** Makes the value the one it is given: pressed while it is. */
|
|
52
|
+
const Preset = ({ value, ...props }) => usePart(useDatePicker("Preset").preset(value), "button", props);
|
|
39
53
|
const DatePicker = /* @__PURE__ */ parts("DatePicker", {
|
|
40
54
|
Root,
|
|
41
55
|
Field,
|
|
@@ -50,12 +64,15 @@ const DatePicker = /* @__PURE__ */ parts("DatePicker", {
|
|
|
50
64
|
Heading: Calendar.Heading,
|
|
51
65
|
Previous: Calendar.Previous,
|
|
52
66
|
Next: Calendar.Next,
|
|
67
|
+
Months: Calendar.Months,
|
|
53
68
|
Grid: Calendar.Grid,
|
|
54
69
|
Weekdays: Calendar.Weekdays,
|
|
55
70
|
HeadCell: Calendar.HeadCell,
|
|
56
71
|
Weeks: Calendar.Weeks,
|
|
57
72
|
Cell: Calendar.Cell,
|
|
58
|
-
Day: Calendar.Day
|
|
73
|
+
Day: Calendar.Day,
|
|
74
|
+
Clear,
|
|
75
|
+
Preset
|
|
59
76
|
});
|
|
60
77
|
export { DatePicker };
|
|
61
78
|
|