@kirana-ui/react 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/llms.txt +1838 -0
- package/package.json +112 -2
- package/src/accordion.js +3 -3
- package/src/accordion.js.map +1 -1
- package/src/autocomplete.d.ts +2 -0
- package/src/autocomplete.js +1 -0
- package/src/autosize.d.ts +9 -0
- package/src/autosize.js +12 -0
- package/src/autosize.js.map +1 -0
- package/src/avatar.js +2 -2
- package/src/avatar.js.map +1 -1
- package/src/calendar.d.ts +44 -0
- package/src/calendar.js +85 -0
- package/src/calendar.js.map +1 -0
- package/src/carousel.d.ts +26 -0
- package/src/carousel.js +52 -0
- package/src/carousel.js.map +1 -0
- package/src/checkbox.d.ts +1 -1
- package/src/checkbox.js +2 -1
- package/src/checkbox.js.map +1 -1
- package/src/combobox.d.ts +91 -0
- package/src/combobox.js +164 -0
- package/src/combobox.js.map +1 -0
- package/src/command.d.ts +44 -0
- package/src/command.js +88 -0
- package/src/command.js.map +1 -0
- package/src/context-menu.d.ts +2 -0
- package/src/context-menu.js +1 -0
- package/src/date-field.d.ts +25 -0
- package/src/date-field.js +60 -0
- package/src/date-field.js.map +1 -0
- package/src/date-picker.d.ts +53 -0
- package/src/date-picker.js +62 -0
- package/src/date-picker.js.map +1 -0
- package/src/dialog.d.ts +17 -0
- package/src/dialog.js +14 -1
- package/src/dialog.js.map +1 -1
- package/src/direction.js +1 -1
- package/src/drawer.d.ts +2 -0
- package/src/drawer.js +1 -0
- package/src/field.js +3 -3
- package/src/field.js.map +1 -1
- package/src/hover-card.d.ts +2 -2
- package/src/hover-popup.d.ts +5 -1
- package/src/hover-popup.js +9 -1
- package/src/hover-popup.js.map +1 -1
- package/src/index.d.ts +27 -3
- package/src/index.js +26 -2
- package/src/input.d.ts +10 -0
- package/src/input.js +21 -0
- package/src/input.js.map +1 -0
- package/src/label.d.ts +5 -0
- package/src/label.js +14 -0
- package/src/label.js.map +1 -0
- package/src/listbox.d.ts +28 -0
- package/src/listbox.js +89 -0
- package/src/listbox.js.map +1 -0
- package/src/menu.d.ts +89 -0
- package/src/menu.js +214 -0
- package/src/menu.js.map +1 -0
- package/src/menubar-context.d.ts +4 -0
- package/src/menubar-context.js +7 -0
- package/src/menubar-context.js.map +1 -0
- package/src/menubar.d.ts +9 -0
- package/src/menubar.js +25 -0
- package/src/menubar.js.map +1 -0
- package/src/message-scroller.d.ts +18 -0
- package/src/message-scroller.js +35 -0
- package/src/message-scroller.js.map +1 -0
- package/src/navigation-menu.d.ts +48 -0
- package/src/navigation-menu.js +115 -0
- package/src/navigation-menu.js.map +1 -0
- package/src/number-field.d.ts +21 -0
- package/src/number-field.js +62 -0
- package/src/number-field.js.map +1 -0
- package/src/otp.d.ts +26 -0
- package/src/otp.js +70 -0
- package/src/otp.js.map +1 -0
- package/src/pagination.d.ts +27 -0
- package/src/pagination.js +50 -0
- package/src/pagination.js.map +1 -0
- package/src/popover.d.ts +3 -2
- package/src/popover.js +1 -1
- package/src/popover.js.map +1 -1
- package/src/qr-code.d.ts +16 -0
- package/src/qr-code.js +32 -0
- package/src/qr-code.js.map +1 -0
- package/src/radio-group.d.ts +1 -1
- package/src/radio-group.js +5 -4
- package/src/radio-group.js.map +1 -1
- package/src/resizable.d.ts +19 -0
- package/src/resizable.js +51 -0
- package/src/resizable.js.map +1 -0
- package/src/runtime.d.ts +28 -1
- package/src/runtime.js +97 -9
- package/src/runtime.js.map +1 -1
- package/src/scroll-area.d.ts +25 -0
- package/src/scroll-area.js +61 -0
- package/src/scroll-area.js.map +1 -0
- package/src/select.d.ts +31 -3
- package/src/select.js +63 -5
- package/src/select.js.map +1 -1
- package/src/slider.d.ts +1 -1
- package/src/slider.js +3 -1
- package/src/slider.js.map +1 -1
- package/src/switch.d.ts +1 -1
- package/src/switch.js +2 -1
- package/src/switch.js.map +1 -1
- package/src/tabs.js +3 -3
- package/src/tabs.js.map +1 -1
- package/src/toast.d.ts +32 -0
- package/src/toast.js +61 -0
- package/src/toast.js.map +1 -0
- package/src/toggle-group.d.ts +7 -0
- package/src/toggle-group.js +32 -0
- package/src/toggle-group.js.map +1 -0
- package/src/toggle.d.ts +2 -1
- package/src/toggle.js +13 -3
- package/src/toggle.js.map +1 -1
- package/src/toolbar-context.d.ts +7 -0
- package/src/toolbar-context.js +9 -0
- package/src/toolbar-context.js.map +1 -0
- package/src/toolbar.d.ts +20 -0
- package/src/toolbar.js +53 -0
- package/src/toolbar.js.map +1 -0
- package/src/tooltip.d.ts +2 -2
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { PartComponentProps } from "./runtime.js";
|
|
2
|
+
import { PositionOptions } from "@kirana-ui/core";
|
|
3
|
+
import { ReactElement, ReactNode } from "react";
|
|
4
|
+
import { AutocompleteProps } from "@kirana-ui/core/autocomplete";
|
|
5
|
+
import { ComboboxProps } from "@kirana-ui/core/combobox";
|
|
6
|
+
export type RootProps<Value> = Omit<ComboboxProps<Value>, "id"> & {
|
|
7
|
+
id?: string;
|
|
8
|
+
children?: ReactNode;
|
|
9
|
+
};
|
|
10
|
+
declare function Root<Value>({ children, ...props }: RootProps<Value>): ReactElement;
|
|
11
|
+
declare const Input: (props: PartComponentProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
12
|
+
declare const Trigger: (props: PartComponentProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
13
|
+
declare const Popup: (props: PartComponentProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
14
|
+
declare function Portal({ children }: {
|
|
15
|
+
children?: ReactNode;
|
|
16
|
+
}): ReactElement | null;
|
|
17
|
+
export type PositionerProps = PartComponentProps & Partial<PositionOptions>;
|
|
18
|
+
declare function Positioner({ side, align, sideOffset, alignOffset, collisionPadding, ...props }: PositionerProps): ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
19
|
+
/** Items that belong together, named by their `GroupLabel`. Hidden while none is shown. */
|
|
20
|
+
declare function Group({ id, ...props }: PartComponentProps & {
|
|
21
|
+
id?: string;
|
|
22
|
+
}): ReactElement;
|
|
23
|
+
/** A group's name. Outside a group it is plain text, and names nothing. */
|
|
24
|
+
declare function GroupLabel(props: PartComponentProps): ReactElement;
|
|
25
|
+
/** A line between groups. */
|
|
26
|
+
declare const Separator: (props: PartComponentProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
27
|
+
export interface ItemProps extends PartComponentProps {
|
|
28
|
+
value: unknown;
|
|
29
|
+
disabled?: boolean;
|
|
30
|
+
/** What is filtered and what the input shows; the item's text when left out. */
|
|
31
|
+
label?: string;
|
|
32
|
+
id?: string;
|
|
33
|
+
/** Its place among all the rows, in a virtualized list. */
|
|
34
|
+
index?: number;
|
|
35
|
+
}
|
|
36
|
+
declare function Item({ value, disabled, label, id, index, ...props }: ItemProps): ReactElement;
|
|
37
|
+
export interface ItemIndicatorProps extends PartComponentProps {
|
|
38
|
+
keepMounted?: boolean;
|
|
39
|
+
}
|
|
40
|
+
declare function ItemIndicator({ keepMounted, render: _render, ref: _ref, ...rest }: ItemIndicatorProps): import("react").JSX.Element | null;
|
|
41
|
+
/** A button that empties the input and the value. Drawn while there is something to clear. */
|
|
42
|
+
declare function Clear({ keepMounted, ...props }: ItemIndicatorProps): ReactElement | null;
|
|
43
|
+
/** With `multiple`: what holds the chips and the input. */
|
|
44
|
+
declare const Chips: (props: PartComponentProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
45
|
+
/** With `multiple`: one chosen value. Its `value` is what its remove button takes away. */
|
|
46
|
+
declare function Chip({ value, ...props }: PartComponentProps & {
|
|
47
|
+
value: unknown;
|
|
48
|
+
}): ReactElement;
|
|
49
|
+
declare function ChipRemove(props: PartComponentProps): ReactElement;
|
|
50
|
+
/** Drawn while no item is shown for what was typed. */
|
|
51
|
+
declare function Empty(props: PartComponentProps): ReactElement | null;
|
|
52
|
+
export type AutocompleteRootProps = Omit<AutocompleteProps, "id"> & {
|
|
53
|
+
id?: string;
|
|
54
|
+
children?: ReactNode;
|
|
55
|
+
};
|
|
56
|
+
/** A combobox whose text is the value: the list only suggests. */
|
|
57
|
+
declare function AutocompleteRoot({ children, ...props }: AutocompleteRootProps): ReactElement;
|
|
58
|
+
export declare const Autocomplete: {
|
|
59
|
+
Root: typeof AutocompleteRoot;
|
|
60
|
+
Input: typeof Input;
|
|
61
|
+
Trigger: typeof Trigger;
|
|
62
|
+
Clear: typeof Clear;
|
|
63
|
+
Portal: typeof Portal;
|
|
64
|
+
Positioner: typeof Positioner;
|
|
65
|
+
Popup: typeof Popup;
|
|
66
|
+
Group: typeof Group;
|
|
67
|
+
GroupLabel: typeof GroupLabel;
|
|
68
|
+
Separator: typeof Separator;
|
|
69
|
+
Item: typeof Item;
|
|
70
|
+
Empty: typeof Empty;
|
|
71
|
+
};
|
|
72
|
+
export declare const Combobox: {
|
|
73
|
+
Root: typeof Root;
|
|
74
|
+
Input: typeof Input;
|
|
75
|
+
Trigger: typeof Trigger;
|
|
76
|
+
Clear: typeof Clear;
|
|
77
|
+
Chips: typeof Chips;
|
|
78
|
+
Chip: typeof Chip;
|
|
79
|
+
ChipRemove: typeof ChipRemove;
|
|
80
|
+
Portal: typeof Portal;
|
|
81
|
+
Positioner: typeof Positioner;
|
|
82
|
+
Popup: typeof Popup;
|
|
83
|
+
Group: typeof Group;
|
|
84
|
+
GroupLabel: typeof GroupLabel;
|
|
85
|
+
Separator: typeof Separator;
|
|
86
|
+
Item: typeof Item;
|
|
87
|
+
ItemIndicator: typeof ItemIndicator;
|
|
88
|
+
Empty: typeof Empty;
|
|
89
|
+
};
|
|
90
|
+
export {};
|
|
91
|
+
//# sourceMappingURL=combobox.d.ts.map
|
package/src/combobox.js
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { FieldContext } from "./field-context.js";
|
|
2
|
+
import { Portal as Portal$1, useController, useOptions, useOwnText, usePart, useSignal } from "./runtime.js";
|
|
3
|
+
import { defined, within } from "@kirana-ui/core";
|
|
4
|
+
import { createContext, useContext, useId, useMemo } from "react";
|
|
5
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
import { createAutocomplete } from "@kirana-ui/core/autocomplete";
|
|
7
|
+
import { createCombobox } from "@kirana-ui/core/combobox";
|
|
8
|
+
// src/combobox.tsx
|
|
9
|
+
const Context = createContext(null);
|
|
10
|
+
const ItemContext = createContext(void 0);
|
|
11
|
+
function useCombobox(part) {
|
|
12
|
+
const controller = useContext(Context);
|
|
13
|
+
if (!controller) throw new Error(`<Combobox.${part}> must be inside <Combobox.Root>`);
|
|
14
|
+
return controller;
|
|
15
|
+
}
|
|
16
|
+
function Root({ children, ...props }) {
|
|
17
|
+
const field = useContext(FieldContext) ?? void 0;
|
|
18
|
+
const controller = useController(within(createCombobox, { field }), props);
|
|
19
|
+
const named = useSignal(controller.named);
|
|
20
|
+
return /* @__PURE__ */ jsxs(Context.Provider, {
|
|
21
|
+
value: controller,
|
|
22
|
+
children: [children, named ? /* @__PURE__ */ jsx(HiddenInput, {}) : null]
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
const HiddenInput = () => usePart(useCombobox("Root").hidden, "input", {});
|
|
26
|
+
const Input = (props) => usePart(useOwnText(useCombobox("Input").input), "input", props);
|
|
27
|
+
const Trigger = (props) => usePart(useCombobox("Trigger").trigger, "button", props);
|
|
28
|
+
const Popup = (props) => usePart(useCombobox("Popup").popup, "div", props);
|
|
29
|
+
function Portal({ children }) {
|
|
30
|
+
return useSignal(useCombobox("Portal").mounted) ? /* @__PURE__ */ jsx(Portal$1, { children }) : null;
|
|
31
|
+
}
|
|
32
|
+
function Positioner({ side, align, sideOffset, alignOffset, collisionPadding, ...props }) {
|
|
33
|
+
const controller = useCombobox("Positioner");
|
|
34
|
+
controller.positioning.set(defined({
|
|
35
|
+
side,
|
|
36
|
+
align,
|
|
37
|
+
sideOffset,
|
|
38
|
+
alignOffset,
|
|
39
|
+
collisionPadding
|
|
40
|
+
}));
|
|
41
|
+
return usePart(controller.positioner, "div", props);
|
|
42
|
+
}
|
|
43
|
+
const GroupContext = createContext(null);
|
|
44
|
+
/** Items that belong together, named by their `GroupLabel`. Hidden while none is shown. */
|
|
45
|
+
function Group({ id, ...props }) {
|
|
46
|
+
const controller = useCombobox("Group");
|
|
47
|
+
const generated = useId();
|
|
48
|
+
const group = useMemo(() => controller.group(id ?? generated), [
|
|
49
|
+
controller,
|
|
50
|
+
id,
|
|
51
|
+
generated
|
|
52
|
+
]);
|
|
53
|
+
return /* @__PURE__ */ jsx(GroupContext.Provider, {
|
|
54
|
+
value: group,
|
|
55
|
+
children: usePart(group.root, "div", props)
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
/** A group's name. Outside a group it is plain text, and names nothing. */
|
|
59
|
+
function GroupLabel(props) {
|
|
60
|
+
const lone = useCombobox("GroupLabel").groupLabel;
|
|
61
|
+
return usePart(useContext(GroupContext)?.label ?? lone, "div", props);
|
|
62
|
+
}
|
|
63
|
+
/** A line between groups. */
|
|
64
|
+
const Separator = (props) => usePart(useCombobox("Separator").separator, "div", props);
|
|
65
|
+
function Item({ value, disabled, label, id, index, ...props }) {
|
|
66
|
+
const controller = useCombobox("Item");
|
|
67
|
+
const group = useContext(GroupContext) ?? void 0;
|
|
68
|
+
const generated = useId();
|
|
69
|
+
const options = useOptions({
|
|
70
|
+
disabled,
|
|
71
|
+
label,
|
|
72
|
+
index,
|
|
73
|
+
id: id ?? generated
|
|
74
|
+
});
|
|
75
|
+
const part = useMemo(() => controller.item(value, () => options.get(), group), [
|
|
76
|
+
controller,
|
|
77
|
+
value,
|
|
78
|
+
options,
|
|
79
|
+
group
|
|
80
|
+
]);
|
|
81
|
+
return /* @__PURE__ */ jsx(ItemContext.Provider, {
|
|
82
|
+
value,
|
|
83
|
+
children: usePart(part, "div", props)
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
function ItemIndicator({ keepMounted, render: _render, ref: _ref, ...rest }) {
|
|
87
|
+
if (!useSignal(useCombobox("ItemIndicator").selected(useContext(ItemContext))) && !keepMounted) return null;
|
|
88
|
+
return /* @__PURE__ */ jsx("span", {
|
|
89
|
+
"aria-hidden": "true",
|
|
90
|
+
...rest
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
const ClearElement = (props) => usePart(useCombobox("Clear").clear, "button", props);
|
|
94
|
+
/** A button that empties the input and the value. Drawn while there is something to clear. */
|
|
95
|
+
function Clear({ keepMounted, ...props }) {
|
|
96
|
+
return useSignal(useCombobox("Clear").clearable) || keepMounted ? /* @__PURE__ */ jsx(ClearElement, { ...props }) : null;
|
|
97
|
+
}
|
|
98
|
+
/** With `multiple`: what holds the chips and the input. */
|
|
99
|
+
const Chips = (props) => usePart(useCombobox("Chips").chips, "div", props);
|
|
100
|
+
const ChipContext = createContext(void 0);
|
|
101
|
+
/** With `multiple`: one chosen value. Its `value` is what its remove button takes away. */
|
|
102
|
+
function Chip({ value, ...props }) {
|
|
103
|
+
const controller = useCombobox("Chip");
|
|
104
|
+
const part = useMemo(() => controller.chip(value), [controller, value]);
|
|
105
|
+
return /* @__PURE__ */ jsx(ChipContext.Provider, {
|
|
106
|
+
value,
|
|
107
|
+
children: usePart(part, "span", props)
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
function ChipRemove(props) {
|
|
111
|
+
const controller = useCombobox("ChipRemove");
|
|
112
|
+
const value = useContext(ChipContext);
|
|
113
|
+
const part = useMemo(() => controller.chipRemove(value), [controller, value]);
|
|
114
|
+
return usePart(part, "button", props);
|
|
115
|
+
}
|
|
116
|
+
const EmptyElement = (props) => usePart(useCombobox("Empty").emptyPart, "div", props);
|
|
117
|
+
/** Drawn while no item is shown for what was typed. */
|
|
118
|
+
function Empty(props) {
|
|
119
|
+
return useSignal(useCombobox("Empty").empty) ? /* @__PURE__ */ jsx(EmptyElement, { ...props }) : null;
|
|
120
|
+
}
|
|
121
|
+
/** A combobox whose text is the value: the list only suggests. */
|
|
122
|
+
function AutocompleteRoot({ children, ...props }) {
|
|
123
|
+
const field = useContext(FieldContext) ?? void 0;
|
|
124
|
+
const controller = useController(within(createAutocomplete, { field }), props);
|
|
125
|
+
return /* @__PURE__ */ jsx(Context.Provider, {
|
|
126
|
+
value: controller,
|
|
127
|
+
children
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
const Autocomplete = {
|
|
131
|
+
Root: AutocompleteRoot,
|
|
132
|
+
Input,
|
|
133
|
+
Trigger,
|
|
134
|
+
Clear,
|
|
135
|
+
Portal,
|
|
136
|
+
Positioner,
|
|
137
|
+
Popup,
|
|
138
|
+
Group,
|
|
139
|
+
GroupLabel,
|
|
140
|
+
Separator,
|
|
141
|
+
Item,
|
|
142
|
+
Empty
|
|
143
|
+
};
|
|
144
|
+
const Combobox = {
|
|
145
|
+
Root,
|
|
146
|
+
Input,
|
|
147
|
+
Trigger,
|
|
148
|
+
Clear,
|
|
149
|
+
Chips,
|
|
150
|
+
Chip,
|
|
151
|
+
ChipRemove,
|
|
152
|
+
Portal,
|
|
153
|
+
Positioner,
|
|
154
|
+
Popup,
|
|
155
|
+
Group,
|
|
156
|
+
GroupLabel,
|
|
157
|
+
Separator,
|
|
158
|
+
Item,
|
|
159
|
+
ItemIndicator,
|
|
160
|
+
Empty
|
|
161
|
+
};
|
|
162
|
+
export { Autocomplete, Combobox };
|
|
163
|
+
|
|
164
|
+
//# sourceMappingURL=combobox.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"combobox.js","names":["BodyPortal"],"sources":["../../../../packages/react/src/combobox.tsx"],"sourcesContent":["import { defined, within } from \"@kirana-ui/core\"\nimport type { PositionOptions } 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 { 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 useController,\n useOptions,\n useOwnText,\n usePart,\n useSignal,\n} from \"./runtime.tsx\"\nimport type { PartComponentProps } from \"./runtime.tsx\"\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\nexport type RootProps<Value> = Omit<ComboboxProps<Value>, \"id\"> & {\n id?: string\n children?: ReactNode\n}\n\nfunction Root<Value>({ children, ...props }: RootProps<Value>): ReactElement {\n const field = useContext(FieldContext) ?? undefined\n const controller = useController<ComboboxProps<Value>, Controller<Value>>(\n within(createCombobox<Value>, { field }),\n props\n ) as unknown as Controller\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\nconst HiddenInput = () => usePart(useCombobox(\"Root\").hidden, \"input\", {})\nconst Input = (props: PartComponentProps) =>\n usePart(useOwnText(useCombobox(\"Input\").input), \"input\", props)\nconst Trigger = (props: PartComponentProps) =>\n usePart(useCombobox(\"Trigger\").trigger, \"button\", props)\nconst Popup = (props: PartComponentProps) => usePart(useCombobox(\"Popup\").popup, \"div\", props)\n\nfunction Portal({ children }: { children?: ReactNode }): ReactElement | null {\n const mounted = useSignal(useCombobox(\"Portal\").mounted)\n return mounted ? <BodyPortal>{children}</BodyPortal> : null\n}\n\nexport type PositionerProps = PartComponentProps & Partial<PositionOptions>\n\nfunction Positioner({\n side,\n align,\n sideOffset,\n alignOffset,\n collisionPadding,\n ...props\n}: PositionerProps) {\n const controller = useCombobox(\"Positioner\")\n controller.positioning.set(defined({ side, align, sideOffset, alignOffset, collisionPadding }))\n return usePart(controller.positioner, \"div\", props)\n}\n\nconst GroupContext = createContext<ComboboxGroup | null>(null)\n\n/** Items that belong together, named by their `GroupLabel`. Hidden while none is shown. */\nfunction Group({ id, ...props }: PartComponentProps & { id?: string }): 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\n/** A group's name. Outside a group it is plain text, and names nothing. */\nfunction GroupLabel(props: PartComponentProps): ReactElement {\n const lone = useCombobox(\"GroupLabel\").groupLabel\n return usePart(useContext(GroupContext)?.label ?? lone, \"div\", props)\n}\n\n/** A line between groups. */\nconst Separator = (props: PartComponentProps) =>\n usePart(useCombobox(\"Separator\").separator, \"div\", props)\n\nexport interface ItemProps extends PartComponentProps {\n value: unknown\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\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 interface ItemIndicatorProps extends PartComponentProps {\n keepMounted?: boolean\n}\n\nfunction ItemIndicator({ keepMounted, render: _render, ref: _ref, ...rest }: ItemIndicatorProps) {\n const selected = useSignal(useCombobox(\"ItemIndicator\").selected(useContext(ItemContext)))\n if (!selected && !keepMounted) return null\n return <span aria-hidden=\"true\" {...(rest as object)} />\n}\n\nconst ClearElement = (props: PartComponentProps) =>\n usePart(useCombobox(\"Clear\").clear, \"button\", props)\n\n/** A button that empties the input and the value. Drawn while there is something to clear. */\nfunction Clear({ keepMounted, ...props }: ItemIndicatorProps): ReactElement | null {\n const clearable = useSignal(useCombobox(\"Clear\").clearable)\n return clearable || keepMounted ? <ClearElement {...props} /> : null\n}\n\n/** With `multiple`: what holds the chips and the input. */\nconst Chips = (props: PartComponentProps) => usePart(useCombobox(\"Chips\").chips, \"div\", props)\n\nconst ChipContext = createContext<unknown>(undefined)\n\n/** With `multiple`: one chosen value. Its `value` is what its remove button takes away. */\nfunction Chip({ value, ...props }: PartComponentProps & { value: unknown }): 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\nfunction ChipRemove(props: PartComponentProps): 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\nconst EmptyElement = (props: PartComponentProps) =>\n usePart(useCombobox(\"Empty\").emptyPart, \"div\", props)\n\n/** Drawn while no item is shown for what was typed. */\nfunction Empty(props: PartComponentProps): ReactElement | null {\n const empty = useSignal(useCombobox(\"Empty\").empty)\n return empty ? <EmptyElement {...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 Autocomplete = {\n Root: AutocompleteRoot,\n Input,\n Trigger,\n Clear,\n Portal,\n Positioner,\n Popup,\n Group,\n GroupLabel,\n Separator,\n Item,\n Empty,\n}\n\nexport const Combobox = {\n Root,\n Input,\n Trigger,\n Clear,\n Chips,\n Chip,\n ChipRemove,\n Portal,\n Positioner,\n Popup,\n Group,\n GroupLabel,\n Separator,\n Item,\n ItemIndicator,\n Empty,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B,MAAM;CACN;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,MAAa,WAAW;CACtB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF"}
|
package/src/command.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { PartComponentProps } from "./runtime.js";
|
|
2
|
+
import { ReactElement } from "react";
|
|
3
|
+
import { CommandProps } from "@kirana-ui/core/command";
|
|
4
|
+
export type RootProps = Omit<CommandProps, "id"> & {
|
|
5
|
+
id?: string;
|
|
6
|
+
} & PartComponentProps;
|
|
7
|
+
declare function Root({ inputValue, defaultInputValue, onInputValueChange, onSelect, filter, loop, disabled, id, ...rest }: RootProps): ReactElement;
|
|
8
|
+
declare const Input: (props: PartComponentProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
9
|
+
declare const List: (props: PartComponentProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
10
|
+
/** Drawn while no item is shown for what was typed. */
|
|
11
|
+
declare function Empty(props: PartComponentProps): ReactElement | null;
|
|
12
|
+
/** Items under a `<Command.GroupHeading>`. Hidden while none of them is shown. */
|
|
13
|
+
declare function Group({ id, ...props }: PartComponentProps & {
|
|
14
|
+
id?: string;
|
|
15
|
+
}): ReactElement;
|
|
16
|
+
declare function GroupHeading(props: PartComponentProps): ReactElement;
|
|
17
|
+
export interface ItemProps extends PartComponentProps {
|
|
18
|
+
/** What `onSelect` is told. */
|
|
19
|
+
value: string;
|
|
20
|
+
disabled?: boolean;
|
|
21
|
+
/** What is filtered; the item's text when left out. */
|
|
22
|
+
label?: string;
|
|
23
|
+
/** Other words the item answers to. */
|
|
24
|
+
keywords?: readonly string[];
|
|
25
|
+
id?: string;
|
|
26
|
+
}
|
|
27
|
+
declare function Item({ value, disabled, label, keywords, id, ...props }: ItemProps): ReactElement;
|
|
28
|
+
export interface SeparatorProps extends PartComponentProps {
|
|
29
|
+
/** Stays while something is typed. */
|
|
30
|
+
alwaysRender?: boolean;
|
|
31
|
+
}
|
|
32
|
+
declare function Separator({ alwaysRender, ...props }: SeparatorProps): ReactElement;
|
|
33
|
+
export declare const Command: {
|
|
34
|
+
Root: typeof Root;
|
|
35
|
+
Input: typeof Input;
|
|
36
|
+
List: typeof List;
|
|
37
|
+
Empty: typeof Empty;
|
|
38
|
+
Group: typeof Group;
|
|
39
|
+
GroupHeading: typeof GroupHeading;
|
|
40
|
+
Item: typeof Item;
|
|
41
|
+
Separator: typeof Separator;
|
|
42
|
+
};
|
|
43
|
+
export {};
|
|
44
|
+
//# sourceMappingURL=command.d.ts.map
|
package/src/command.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { useController, useOptions, useOwnText, usePart, useSignal } from "./runtime.js";
|
|
2
|
+
import { createContext, useContext, useId, useMemo } from "react";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
import { createCommand } from "@kirana-ui/core/command";
|
|
5
|
+
// src/command.tsx
|
|
6
|
+
const Context = createContext(null);
|
|
7
|
+
const GroupContext = createContext(void 0);
|
|
8
|
+
function useCommand(part) {
|
|
9
|
+
const controller = useContext(Context);
|
|
10
|
+
if (!controller) throw new Error(`<Command.${part}> must be inside <Command.Root>`);
|
|
11
|
+
return controller;
|
|
12
|
+
}
|
|
13
|
+
function Root({ inputValue, defaultInputValue, onInputValueChange, onSelect, filter, loop, disabled, id, ...rest }) {
|
|
14
|
+
const controller = useController(createCommand, {
|
|
15
|
+
inputValue,
|
|
16
|
+
defaultInputValue,
|
|
17
|
+
onInputValueChange,
|
|
18
|
+
onSelect,
|
|
19
|
+
filter,
|
|
20
|
+
loop,
|
|
21
|
+
disabled,
|
|
22
|
+
id
|
|
23
|
+
});
|
|
24
|
+
return /* @__PURE__ */ jsx(Context.Provider, {
|
|
25
|
+
value: controller,
|
|
26
|
+
children: /* @__PURE__ */ jsx(RootElement, { ...rest })
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
const RootElement = (props) => usePart(useCommand("Root").root, "div", props);
|
|
30
|
+
const Input = (props) => usePart(useOwnText(useCommand("Input").input), "input", props);
|
|
31
|
+
const List = (props) => usePart(useCommand("List").list, "div", props);
|
|
32
|
+
const EmptyElement = (props) => usePart(useCommand("Empty").emptyPart, "div", props);
|
|
33
|
+
/** Drawn while no item is shown for what was typed. */
|
|
34
|
+
function Empty(props) {
|
|
35
|
+
return useSignal(useCommand("Empty").empty) ? /* @__PURE__ */ jsx(EmptyElement, { ...props }) : null;
|
|
36
|
+
}
|
|
37
|
+
/** Items under a `<Command.GroupHeading>`. Hidden while none of them is shown. */
|
|
38
|
+
function Group({ id, ...props }) {
|
|
39
|
+
const controller = useCommand("Group");
|
|
40
|
+
const generated = useId();
|
|
41
|
+
const name = id ?? generated;
|
|
42
|
+
const group = useMemo(() => controller.group(name), [controller, name]);
|
|
43
|
+
return /* @__PURE__ */ jsx(GroupContext.Provider, {
|
|
44
|
+
value: group,
|
|
45
|
+
children: usePart(group.part, "div", props)
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
function GroupHeading(props) {
|
|
49
|
+
const lone = useCommand("GroupHeading").heading;
|
|
50
|
+
return usePart(useContext(GroupContext)?.heading ?? lone, "div", props);
|
|
51
|
+
}
|
|
52
|
+
function Item({ value, disabled, label, keywords, id, ...props }) {
|
|
53
|
+
const controller = useCommand("Item");
|
|
54
|
+
const group = useContext(GroupContext);
|
|
55
|
+
const generated = useId();
|
|
56
|
+
const options = useOptions({
|
|
57
|
+
disabled,
|
|
58
|
+
label,
|
|
59
|
+
keywords,
|
|
60
|
+
id: id ?? generated
|
|
61
|
+
});
|
|
62
|
+
const part = useMemo(() => controller.item(value, () => options.get(), group), [
|
|
63
|
+
controller,
|
|
64
|
+
value,
|
|
65
|
+
options,
|
|
66
|
+
group
|
|
67
|
+
]);
|
|
68
|
+
return usePart(part, "div", props);
|
|
69
|
+
}
|
|
70
|
+
function Separator({ alwaysRender, ...props }) {
|
|
71
|
+
const controller = useCommand("Separator");
|
|
72
|
+
const options = useOptions({ alwaysRender });
|
|
73
|
+
const part = useMemo(() => controller.separator(() => options.get().alwaysRender), [controller, options]);
|
|
74
|
+
return usePart(part, "div", props);
|
|
75
|
+
}
|
|
76
|
+
const Command = {
|
|
77
|
+
Root,
|
|
78
|
+
Input,
|
|
79
|
+
List,
|
|
80
|
+
Empty,
|
|
81
|
+
Group,
|
|
82
|
+
GroupHeading,
|
|
83
|
+
Item,
|
|
84
|
+
Separator
|
|
85
|
+
};
|
|
86
|
+
export { Command };
|
|
87
|
+
|
|
88
|
+
//# sourceMappingURL=command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command.js","names":[],"sources":["../../../../packages/react/src/command.tsx"],"sourcesContent":["import { createCommand } from \"@kirana-ui/core/command\"\nimport type { CommandGroup, CommandProps, Command as Controller } from \"@kirana-ui/core/command\"\nimport { createContext, useContext, useId, useMemo } from \"react\"\nimport type { ReactElement } from \"react\"\n\nimport { useController, useOptions, useOwnText, usePart, useSignal } from \"./runtime.tsx\"\nimport type { PartComponentProps } from \"./runtime.tsx\"\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 = Omit<CommandProps, \"id\"> & { id?: string } & PartComponentProps\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 <RootElement {...rest} />\n </Context.Provider>\n )\n}\n\nconst RootElement = (props: PartComponentProps) => usePart(useCommand(\"Root\").root, \"div\", props)\nconst Input = (props: PartComponentProps) =>\n usePart(useOwnText(useCommand(\"Input\").input), \"input\", props)\nconst List = (props: PartComponentProps) => usePart(useCommand(\"List\").list, \"div\", props)\n\nconst EmptyElement = (props: PartComponentProps) =>\n usePart(useCommand(\"Empty\").emptyPart, \"div\", props)\n\n/** Drawn while no item is shown for what was typed. */\nfunction Empty(props: PartComponentProps): ReactElement | null {\n const empty = useSignal(useCommand(\"Empty\").empty)\n return empty ? <EmptyElement {...props} /> : null\n}\n\n/** Items under a `<Command.GroupHeading>`. Hidden while none of them is shown. */\nfunction Group({ id, ...props }: PartComponentProps & { id?: string }): 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\nfunction GroupHeading(props: PartComponentProps): ReactElement {\n const lone = useCommand(\"GroupHeading\").heading\n return usePart(useContext(GroupContext)?.heading ?? lone, \"div\", props)\n}\n\nexport interface ItemProps extends PartComponentProps {\n /** What `onSelect` is told. */\n value: string\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\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 interface SeparatorProps extends PartComponentProps {\n /** Stays while something is typed. */\n alwaysRender?: boolean\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,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,OAAO;EAAQ,UAAA,QAAQ,MAAM,MAAM,OAAO,KAAK;CAAyB,CAAA;AAEnG;AAEA,SAAS,aAAa,OAAyC;CAC7D,MAAM,OAAO,WAAW,cAAc,CAAC,CAAC;CACxC,OAAO,QAAQ,WAAW,YAAY,CAAC,EAAE,WAAW,MAAM,OAAO,KAAK;AACxE;AAaA,SAAS,KAAK,EAAE,OAAO,UAAU,OAAO,UAAU,IAAI,GAAG,SAAkC;CACzF,MAAM,aAAa,WAAW,MAAM;CACpC,MAAM,QAAQ,WAAW,YAAY;CACrC,MAAM,YAAY,MAAM;CACxB,MAAM,UAAU,WAAW;EAAE;EAAU;EAAO;EAAU,IAAI,MAAM;CAAU,CAAC;CAC7E,MAAM,OAAO,cACL,WAAW,KAAK,aAAa,QAAQ,IAAI,GAAG,KAAK,GACvD;EAAC;EAAY;EAAO;EAAS;CAAK,CACpC;CACA,OAAO,QAAQ,MAAM,OAAO,KAAK;AACnC;AAOA,SAAS,UAAU,EAAE,cAAc,GAAG,SAAuC;CAC3E,MAAM,aAAa,WAAW,WAAW;CACzC,MAAM,UAAU,WAAW,EAAE,aAAa,CAAC;CAC3C,MAAM,OAAO,cACL,WAAW,gBAAgB,QAAQ,IAAI,CAAC,CAAC,YAAY,GAC3D,CAAC,YAAY,OAAO,CACtB;CACA,OAAO,QAAQ,MAAM,OAAO,KAAK;AACnC;AAEA,MAAa,UAAU;CAAE;CAAM;CAAO;CAAM;CAAO;CAAO;CAAc;CAAM;AAAU"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ContextMenu } from "./menu.js";
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { PartComponentProps } from "./runtime.js";
|
|
2
|
+
import { ReactElement, ReactNode } from "react";
|
|
3
|
+
import { DateField as DateField$1, DateFieldProps, DateFieldSegment } from "@kirana-ui/core/date-field";
|
|
4
|
+
declare const Context: import("react").Context<DateField$1 | null>;
|
|
5
|
+
export type RootProps = Omit<DateFieldProps, "id"> & {
|
|
6
|
+
id?: string;
|
|
7
|
+
} & PartComponentProps;
|
|
8
|
+
declare function Root({ value, defaultValue, onValueChange, locale, min, max, placeholders, disabled, readOnly, required, name, form, id, ...rest }: RootProps): ReactElement;
|
|
9
|
+
/** Draws its child once for each piece of the date, in the locale's order. */
|
|
10
|
+
declare function Segments({ children }: {
|
|
11
|
+
children: (segment: DateFieldSegment) => ReactNode;
|
|
12
|
+
}): import("react").JSX.Element;
|
|
13
|
+
/** One piece: a part that is typed, or what stands between two. It writes its own text. */
|
|
14
|
+
declare function Segment({ segment, ...props }: PartComponentProps & {
|
|
15
|
+
segment: DateFieldSegment;
|
|
16
|
+
}): ReactElement;
|
|
17
|
+
declare const Input: (props: PartComponentProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
18
|
+
export declare const DateField: {
|
|
19
|
+
Root: typeof Root;
|
|
20
|
+
Segments: typeof Segments;
|
|
21
|
+
Segment: typeof Segment;
|
|
22
|
+
Input: typeof Input;
|
|
23
|
+
};
|
|
24
|
+
export { Context as DateFieldContext };
|
|
25
|
+
//# sourceMappingURL=date-field.d.ts.map
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { DirectionContext } from "./direction-context.js";
|
|
2
|
+
import { useController, usePart, useSignal } from "./runtime.js";
|
|
3
|
+
import { within } from "@kirana-ui/core";
|
|
4
|
+
import { Fragment, createContext, useContext } from "react";
|
|
5
|
+
import { Fragment as Fragment$1, jsx } from "react/jsx-runtime";
|
|
6
|
+
import { createDateField } from "@kirana-ui/core/date-field";
|
|
7
|
+
// src/date-field.tsx
|
|
8
|
+
const Context = createContext(null);
|
|
9
|
+
function useDateField(part) {
|
|
10
|
+
const controller = useContext(Context);
|
|
11
|
+
if (!controller) throw new Error(`<DateField.${part}> must be inside <DateField.Root>`);
|
|
12
|
+
return controller;
|
|
13
|
+
}
|
|
14
|
+
function Root({ value, defaultValue, onValueChange, locale, min, max, placeholders, disabled, readOnly, required, name, form, id, ...rest }) {
|
|
15
|
+
const direction = useContext(DirectionContext) ?? void 0;
|
|
16
|
+
const controller = useController(within(createDateField, { direction }), {
|
|
17
|
+
value,
|
|
18
|
+
defaultValue,
|
|
19
|
+
onValueChange,
|
|
20
|
+
locale,
|
|
21
|
+
min,
|
|
22
|
+
max,
|
|
23
|
+
placeholders,
|
|
24
|
+
disabled,
|
|
25
|
+
readOnly,
|
|
26
|
+
required,
|
|
27
|
+
name,
|
|
28
|
+
form,
|
|
29
|
+
id
|
|
30
|
+
});
|
|
31
|
+
return /* @__PURE__ */ jsx(Context.Provider, {
|
|
32
|
+
value: controller,
|
|
33
|
+
children: usePart(controller.root, "div", rest)
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
/** Draws its child once for each piece of the date, in the locale's order. */
|
|
37
|
+
function Segments({ children }) {
|
|
38
|
+
const segments = useSignal(useDateField("Segments").segments);
|
|
39
|
+
return /* @__PURE__ */ jsx(Fragment$1, { children: segments.map((segment) => /* @__PURE__ */ jsx(Fragment, { children: children(segment) }, `${segment.index}-${segment.type}`)) });
|
|
40
|
+
}
|
|
41
|
+
/** One piece: a part that is typed, or what stands between two. It writes its own text. */
|
|
42
|
+
function Segment({ segment, ...props }) {
|
|
43
|
+
const { part, text } = useDateField("Segment").segment(segment);
|
|
44
|
+
const shown = useSignal(text);
|
|
45
|
+
return usePart(part, "span", {
|
|
46
|
+
...props,
|
|
47
|
+
suppressContentEditableWarning: true,
|
|
48
|
+
children: shown
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
const Input = (props) => usePart(useDateField("Input").input, "input", props);
|
|
52
|
+
const DateField = {
|
|
53
|
+
Root,
|
|
54
|
+
Segments,
|
|
55
|
+
Segment,
|
|
56
|
+
Input
|
|
57
|
+
};
|
|
58
|
+
export { DateField, Context as DateFieldContext };
|
|
59
|
+
|
|
60
|
+
//# sourceMappingURL=date-field.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date-field.js","names":[],"sources":["../../../../packages/react/src/date-field.tsx"],"sourcesContent":["import { within } 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 { Fragment, createContext, useContext } from \"react\"\nimport type { ReactElement, ReactNode } from \"react\"\n\nimport { DirectionContext } from \"./direction-context.ts\"\nimport { useController, usePart, useSignal } from \"./runtime.tsx\"\nimport type { PartComponentProps } from \"./runtime.tsx\"\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 = Omit<DateFieldProps, \"id\"> & { id?: string } & PartComponentProps\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\n/** Draws its child once for each piece of the date, in the locale's order. */\nfunction Segments({ children }: { children: (segment: DateFieldSegment) => ReactNode }) {\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\n/** One piece: a part that is typed, or what stands between two. It writes its own text. */\nfunction Segment({\n segment,\n ...props\n}: PartComponentProps & { segment: DateFieldSegment }): 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\nconst Input = (props: PartComponentProps) => usePart(useDateField(\"Input\").input, \"input\", props)\n\nexport const DateField = { Root, Segments, Segment, Input }\n"],"mappings":";;;;;;;AAcA,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;AAIA,SAAS,KAAK,EACZ,OACA,cACA,eACA,QACA,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;CACF,CACF;CACA,OACE,oBAAC,QAAQ,UAAT;EAAkB,OAAO;EAAa,UAAA,QAAQ,WAAW,MAAM,OAAO,IAAI;CAAoB,CAAA;AAElG;;AAGA,SAAS,SAAS,EAAE,YAAoE;CACtF,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;;AAGA,SAAS,QAAQ,EACf,SACA,GAAG,SACgE;CACnE,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;AAEA,MAAM,SAAS,UAA8B,QAAQ,aAAa,OAAO,CAAC,CAAC,OAAO,SAAS,KAAK;AAEhG,MAAa,YAAY;CAAE;CAAM;CAAU;CAAS;AAAM"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { PositionerProps } from "./popover.js";
|
|
2
|
+
import { PartComponentProps } from "./runtime.js";
|
|
3
|
+
import { DatePickerProps } from "@kirana-ui/core/date-picker";
|
|
4
|
+
import { ReactElement, ReactNode } from "react";
|
|
5
|
+
export type RootProps = Omit<DatePickerProps, "id"> & {
|
|
6
|
+
id?: string;
|
|
7
|
+
children?: ReactNode;
|
|
8
|
+
};
|
|
9
|
+
/** A date field, and a calendar in a popover, with one value between them. It draws nothing. */
|
|
10
|
+
declare function Root({ children, ...props }: RootProps): ReactElement;
|
|
11
|
+
/** The typed date: what holds its segments and its hidden input. */
|
|
12
|
+
declare const Field: (props: PartComponentProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
13
|
+
/** The calendar: what holds its heading, its buttons and its grid. */
|
|
14
|
+
declare const CalendarRoot: (props: PartComponentProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
15
|
+
export declare const DatePicker: {
|
|
16
|
+
Root: typeof Root;
|
|
17
|
+
Field: typeof Field;
|
|
18
|
+
Segments: ({ children }: {
|
|
19
|
+
children: (segment: import("@kirana-ui/core/date-field").DateFieldSegment) => ReactNode;
|
|
20
|
+
}) => import("react").JSX.Element;
|
|
21
|
+
Segment: ({ segment, ...props }: PartComponentProps & {
|
|
22
|
+
segment: import("@kirana-ui/core/date-field").DateFieldSegment;
|
|
23
|
+
}) => ReactElement;
|
|
24
|
+
Input: (props: PartComponentProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
25
|
+
Trigger: (props: PartComponentProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
26
|
+
Portal: ({ children }: {
|
|
27
|
+
children?: ReactNode;
|
|
28
|
+
}) => ReactElement | null;
|
|
29
|
+
Positioner: ({ side, align, sideOffset, alignOffset, collisionPadding, ...props }: PositionerProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
30
|
+
Popup: (props: PartComponentProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
31
|
+
Calendar: typeof CalendarRoot;
|
|
32
|
+
Heading: ({ children, ...props }: PartComponentProps) => ReactElement;
|
|
33
|
+
Previous: (props: PartComponentProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
34
|
+
Next: (props: PartComponentProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
35
|
+
Grid: (props: PartComponentProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
36
|
+
Weekdays: ({ children }: {
|
|
37
|
+
children: (weekday: import("@kirana-ui/core/calendar").CalendarWeekday) => ReactNode;
|
|
38
|
+
}) => import("react").JSX.Element;
|
|
39
|
+
HeadCell: ({ weekday, ...props }: PartComponentProps & {
|
|
40
|
+
weekday: import("@kirana-ui/core/calendar").CalendarWeekday;
|
|
41
|
+
}) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
42
|
+
Weeks: ({ children }: {
|
|
43
|
+
children: (week: readonly import("@kirana-ui/core/calendar").CalendarDay[]) => ReactNode;
|
|
44
|
+
}) => import("react").JSX.Element;
|
|
45
|
+
Cell: ({ date, ...props }: PartComponentProps & {
|
|
46
|
+
date: string;
|
|
47
|
+
}) => ReactElement;
|
|
48
|
+
Day: ({ date, ...props }: PartComponentProps & {
|
|
49
|
+
date: string;
|
|
50
|
+
}) => ReactElement;
|
|
51
|
+
};
|
|
52
|
+
export {};
|
|
53
|
+
//# sourceMappingURL=date-picker.d.ts.map
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Calendar, CalendarContext as Context$1 } from "./calendar.js";
|
|
2
|
+
import { DateField, DateFieldContext as Context$2 } from "./date-field.js";
|
|
3
|
+
import { DirectionContext } from "./direction-context.js";
|
|
4
|
+
import { Popover, PopoverContext as Context$3 } from "./popover.js";
|
|
5
|
+
import { useController, usePart } from "./runtime.js";
|
|
6
|
+
import { within } from "@kirana-ui/core";
|
|
7
|
+
import { createDatePicker } from "@kirana-ui/core/date-picker";
|
|
8
|
+
import { createContext, useContext } from "react";
|
|
9
|
+
import { jsx } from "react/jsx-runtime";
|
|
10
|
+
// src/date-picker.tsx
|
|
11
|
+
const Context = createContext(null);
|
|
12
|
+
function useDatePicker(part) {
|
|
13
|
+
const controller = useContext(Context);
|
|
14
|
+
if (!controller) throw new Error(`<DatePicker.${part}> must be inside <DatePicker.Root>`);
|
|
15
|
+
return controller;
|
|
16
|
+
}
|
|
17
|
+
/** A date field, and a calendar in a popover, with one value between them. It draws nothing. */
|
|
18
|
+
function Root({ children, ...props }) {
|
|
19
|
+
const direction = useContext(DirectionContext) ?? void 0;
|
|
20
|
+
const controller = useController(within(createDatePicker, { direction }), props);
|
|
21
|
+
return /* @__PURE__ */ jsx(Context.Provider, {
|
|
22
|
+
value: controller,
|
|
23
|
+
children: /* @__PURE__ */ jsx(Context$2.Provider, {
|
|
24
|
+
value: controller.field,
|
|
25
|
+
children: /* @__PURE__ */ jsx(Context$3.Provider, {
|
|
26
|
+
value: controller.popover,
|
|
27
|
+
children: /* @__PURE__ */ jsx(Context$1.Provider, {
|
|
28
|
+
value: controller.calendar,
|
|
29
|
+
children
|
|
30
|
+
})
|
|
31
|
+
})
|
|
32
|
+
})
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
/** The typed date: what holds its segments and its hidden input. */
|
|
36
|
+
const Field = (props) => usePart(useDatePicker("Field").field.root, "div", props);
|
|
37
|
+
/** The calendar: what holds its heading, its buttons and its grid. */
|
|
38
|
+
const CalendarRoot = (props) => usePart(useDatePicker("Calendar").calendar.root, "div", props);
|
|
39
|
+
const DatePicker = {
|
|
40
|
+
Root,
|
|
41
|
+
Field,
|
|
42
|
+
Segments: DateField.Segments,
|
|
43
|
+
Segment: DateField.Segment,
|
|
44
|
+
Input: DateField.Input,
|
|
45
|
+
Trigger: Popover.Trigger,
|
|
46
|
+
Portal: Popover.Portal,
|
|
47
|
+
Positioner: Popover.Positioner,
|
|
48
|
+
Popup: Popover.Popup,
|
|
49
|
+
Calendar: CalendarRoot,
|
|
50
|
+
Heading: Calendar.Heading,
|
|
51
|
+
Previous: Calendar.Previous,
|
|
52
|
+
Next: Calendar.Next,
|
|
53
|
+
Grid: Calendar.Grid,
|
|
54
|
+
Weekdays: Calendar.Weekdays,
|
|
55
|
+
HeadCell: Calendar.HeadCell,
|
|
56
|
+
Weeks: Calendar.Weeks,
|
|
57
|
+
Cell: Calendar.Cell,
|
|
58
|
+
Day: Calendar.Day
|
|
59
|
+
};
|
|
60
|
+
export { DatePicker };
|
|
61
|
+
|
|
62
|
+
//# sourceMappingURL=date-picker.js.map
|