@kirana-ui/react 0.1.0 → 0.2.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.
Files changed (172) hide show
  1. package/llms.txt +3216 -0
  2. package/package.json +124 -2
  3. package/skills/kirana-ui-primitives/SKILL.md +142 -0
  4. package/src/accordion.d.ts +26 -15
  5. package/src/accordion.js +12 -11
  6. package/src/accordion.js.map +1 -1
  7. package/src/agent.d.ts +1 -0
  8. package/src/agent.js +1 -0
  9. package/src/alert-dialog.d.ts +3 -2
  10. package/src/autocomplete.d.ts +3 -0
  11. package/src/autocomplete.js +1 -0
  12. package/src/autosize.d.ts +12 -0
  13. package/src/autosize.js +12 -0
  14. package/src/autosize.js.map +1 -0
  15. package/src/avatar.d.ts +12 -8
  16. package/src/avatar.js +19 -10
  17. package/src/avatar.js.map +1 -1
  18. package/src/button.d.ts +4 -2
  19. package/src/button.js +3 -3
  20. package/src/button.js.map +1 -1
  21. package/src/calendar.d.ts +65 -0
  22. package/src/calendar.js +89 -0
  23. package/src/calendar.js.map +1 -0
  24. package/src/carousel.d.ts +36 -0
  25. package/src/carousel.js +52 -0
  26. package/src/carousel.js.map +1 -0
  27. package/src/checkbox.d.ts +10 -7
  28. package/src/checkbox.js +19 -12
  29. package/src/checkbox.js.map +1 -1
  30. package/src/collapsible.d.ts +12 -8
  31. package/src/collapsible.js +8 -7
  32. package/src/collapsible.js.map +1 -1
  33. package/src/combobox.d.ts +119 -0
  34. package/src/combobox.js +177 -0
  35. package/src/combobox.js.map +1 -0
  36. package/src/command.d.ts +53 -0
  37. package/src/command.js +95 -0
  38. package/src/command.js.map +1 -0
  39. package/src/context-menu.d.ts +3 -0
  40. package/src/context-menu.js +1 -0
  41. package/src/date-field.d.ts +37 -0
  42. package/src/date-field.js +64 -0
  43. package/src/date-field.js.map +1 -0
  44. package/src/date-picker.d.ts +44 -0
  45. package/src/date-picker.js +62 -0
  46. package/src/date-picker.js.map +1 -0
  47. package/src/dialog.d.ts +54 -27
  48. package/src/dialog.js +23 -6
  49. package/src/dialog.js.map +1 -1
  50. package/src/direction.d.ts +1 -0
  51. package/src/direction.js +1 -1
  52. package/src/direction.js.map +1 -1
  53. package/src/drawer.d.ts +3 -0
  54. package/src/drawer.js +1 -0
  55. package/src/element.d.ts +12 -0
  56. package/src/element.js +20 -0
  57. package/src/element.js.map +1 -0
  58. package/src/field.d.ts +24 -16
  59. package/src/field.js +11 -9
  60. package/src/field.js.map +1 -1
  61. package/src/fieldset.d.ts +10 -5
  62. package/src/fieldset.js +4 -5
  63. package/src/fieldset.js.map +1 -1
  64. package/src/form.d.ts +5 -2
  65. package/src/form.js +6 -6
  66. package/src/form.js.map +1 -1
  67. package/src/hover-card.d.ts +16 -10
  68. package/src/hover-card.js +1 -1
  69. package/src/hover-card.js.map +1 -1
  70. package/src/hover-popup.d.ts +26 -12
  71. package/src/hover-popup.js +12 -12
  72. package/src/hover-popup.js.map +1 -1
  73. package/src/index.d.ts +37 -3
  74. package/src/index.js +26 -2
  75. package/src/input.d.ts +12 -0
  76. package/src/input.js +21 -0
  77. package/src/input.js.map +1 -0
  78. package/src/label.d.ts +8 -0
  79. package/src/label.js +14 -0
  80. package/src/label.js.map +1 -0
  81. package/src/listbox.d.ts +36 -0
  82. package/src/listbox.js +88 -0
  83. package/src/listbox.js.map +1 -0
  84. package/src/menu.d.ts +107 -0
  85. package/src/menu.js +206 -0
  86. package/src/menu.js.map +1 -0
  87. package/src/menubar-context.d.ts +4 -0
  88. package/src/menubar-context.js +7 -0
  89. package/src/menubar-context.js.map +1 -0
  90. package/src/menubar.d.ts +11 -0
  91. package/src/menubar.js +25 -0
  92. package/src/menubar.js.map +1 -0
  93. package/src/message-scroller.d.ts +24 -0
  94. package/src/message-scroller.js +35 -0
  95. package/src/message-scroller.js.map +1 -0
  96. package/src/meter.d.ts +18 -9
  97. package/src/meter.js +1 -1
  98. package/src/meter.js.map +1 -1
  99. package/src/navigation-menu.d.ts +58 -0
  100. package/src/navigation-menu.js +106 -0
  101. package/src/navigation-menu.js.map +1 -0
  102. package/src/number-field.d.ts +28 -0
  103. package/src/number-field.js +58 -0
  104. package/src/number-field.js.map +1 -0
  105. package/src/otp.d.ts +35 -0
  106. package/src/otp.js +64 -0
  107. package/src/otp.js.map +1 -0
  108. package/src/pagination.d.ts +37 -0
  109. package/src/pagination.js +50 -0
  110. package/src/pagination.js.map +1 -0
  111. package/src/popover.d.ts +32 -22
  112. package/src/popover.js +10 -14
  113. package/src/popover.js.map +1 -1
  114. package/src/progress.d.ts +18 -9
  115. package/src/progress.js +1 -1
  116. package/src/progress.js.map +1 -1
  117. package/src/qr-code.d.ts +21 -0
  118. package/src/qr-code.js +32 -0
  119. package/src/qr-code.js.map +1 -0
  120. package/src/radio-group.d.ts +17 -11
  121. package/src/radio-group.js +20 -22
  122. package/src/radio-group.js.map +1 -1
  123. package/src/resizable.d.ts +24 -0
  124. package/src/resizable.js +51 -0
  125. package/src/resizable.js.map +1 -0
  126. package/src/runtime.d.ts +114 -13
  127. package/src/runtime.js +205 -24
  128. package/src/runtime.js.map +1 -1
  129. package/src/scroll-area.d.ts +36 -0
  130. package/src/scroll-area.js +64 -0
  131. package/src/scroll-area.js.map +1 -0
  132. package/src/select.d.ts +79 -31
  133. package/src/select.js +86 -23
  134. package/src/select.js.map +1 -1
  135. package/src/separator.d.ts +4 -2
  136. package/src/separator.js +3 -3
  137. package/src/separator.js.map +1 -1
  138. package/src/slider.d.ts +35 -20
  139. package/src/slider.js +20 -19
  140. package/src/slider.js.map +1 -1
  141. package/src/switch.d.ts +10 -6
  142. package/src/switch.js +12 -9
  143. package/src/switch.js.map +1 -1
  144. package/src/tabs.d.ts +22 -14
  145. package/src/tabs.js +7 -8
  146. package/src/tabs.js.map +1 -1
  147. package/src/testing.d.ts +1 -0
  148. package/src/testing.js +1 -0
  149. package/src/toast.d.ts +68 -0
  150. package/src/toast.js +107 -0
  151. package/src/toast.js.map +1 -0
  152. package/src/toggle-group.d.ts +10 -0
  153. package/src/toggle-group.js +32 -0
  154. package/src/toggle-group.js.map +1 -0
  155. package/src/toggle.d.ts +5 -2
  156. package/src/toggle.js +15 -5
  157. package/src/toggle.js.map +1 -1
  158. package/src/toolbar-context.d.ts +7 -0
  159. package/src/toolbar-context.js +9 -0
  160. package/src/toolbar-context.js.map +1 -0
  161. package/src/toolbar.d.ts +35 -0
  162. package/src/toolbar.js +63 -0
  163. package/src/toolbar.js.map +1 -0
  164. package/src/tooltip.d.ts +16 -10
  165. package/src/tooltip.js +1 -1
  166. package/src/tooltip.js.map +1 -1
  167. package/src/use-render.d.ts +38 -0
  168. package/src/use-render.js +50 -0
  169. package/src/use-render.js.map +1 -0
  170. package/src/value-bar.d.ts +19 -11
  171. package/src/value-bar.js +8 -5
  172. package/src/value-bar.js.map +1 -1
@@ -0,0 +1,119 @@
1
+ import { PartComponentProps, PortalProps, PositionerOptions } from "./runtime.js";
2
+ import { StateOf } 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
+ import { Vocabulary } from "@kirana-ui/core/vocabulary";
7
+ type Parts = Vocabulary["combobox"];
8
+ /** `Value` is what tells an item from the others: the type of `value`, and of `values`' entries. */
9
+ export type RootProps<Value = unknown> = Omit<ComboboxProps<Value>, "id"> & {
10
+ id?: string;
11
+ children?: ReactNode;
12
+ };
13
+ declare function Root<Value = unknown>({ children, ...props }: RootProps<Value>): ReactElement;
14
+ export type InputProps = PartComponentProps<"input", StateOf<Parts["input"]>>;
15
+ export type TriggerProps = PartComponentProps<"button", StateOf<Parts["trigger"]>>;
16
+ export type PopupProps = PartComponentProps<"div", StateOf<Parts["popup"]>>;
17
+ export type ListProps = PartComponentProps<"div", StateOf<Parts["list"]>>;
18
+ declare const Input: (props: InputProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
19
+ declare const Trigger: (props: TriggerProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
20
+ declare const Popup: (props: PopupProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
21
+ /**
22
+ * The items' own box inside the popup, when the popup holds more than items (an input): it
23
+ * is then the listbox.
24
+ */
25
+ declare const List: (props: ListProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
26
+ declare function Portal({ children }: PortalProps): ReactElement | null;
27
+ export type PositionerProps = PartComponentProps<"div", StateOf<Parts["positioner"]>, PositionerOptions>;
28
+ declare function Positioner(props: PositionerProps): ReactElement;
29
+ export type GroupProps = PartComponentProps<"div", StateOf<Parts["group"]>, {
30
+ id?: string;
31
+ }>;
32
+ /** Items that belong together, named by their `GroupLabel`. Hidden while none is shown. */
33
+ declare function Group({ id, ...props }: GroupProps): ReactElement;
34
+ export type GroupLabelProps = PartComponentProps<"div", StateOf<Parts["groupLabel"]>>;
35
+ /** A group's name. Outside a group it is plain text, and names nothing. */
36
+ declare function GroupLabel(props: GroupLabelProps): ReactElement;
37
+ export type SeparatorProps = PartComponentProps<"div", StateOf<Parts["separator"]>>;
38
+ /** A line between groups. */
39
+ declare const Separator: (props: SeparatorProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
40
+ export type ItemProps = PartComponentProps<"div", StateOf<Parts["item"]>, {
41
+ /** What the combobox's value is while this item is chosen. */
42
+ value: unknown;
43
+ /** Disables this item: it cannot be chosen, and the arrows pass over it. */
44
+ disabled?: boolean;
45
+ /** What is filtered and what the input shows; the item's text when left out. */
46
+ label?: string;
47
+ id?: string;
48
+ /** Its place among all the rows, in a virtualized list. */
49
+ index?: number;
50
+ }>;
51
+ declare function Item({ value, disabled, label, id, index, ...props }: ItemProps): ReactElement;
52
+ export type ItemIndicatorProps = PartComponentProps<"span", StateOf<Parts["itemIndicator"]>, {
53
+ /** Keeps the mark in the page while its item is not chosen. */
54
+ keepMounted?: boolean;
55
+ }>;
56
+ /** In the page while its item is a chosen one. */
57
+ declare function ItemIndicator({ keepMounted, ...props }: ItemIndicatorProps): ReactElement | null;
58
+ export type ClearProps = PartComponentProps<"button", StateOf<Parts["clear"]>, {
59
+ /** Keeps the button in the page while there is nothing to clear. */
60
+ keepMounted?: boolean;
61
+ }>;
62
+ /** A button that empties the input and the value. Drawn while there is something to clear. */
63
+ declare function Clear({ keepMounted, ...props }: ClearProps): ReactElement | null;
64
+ export type ChipsProps = PartComponentProps<"div", StateOf<Parts["chips"]>>;
65
+ /** With `multiple`: what holds the chips and the input. */
66
+ declare const Chips: (props: ChipsProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
67
+ export type ChipProps = PartComponentProps<"span", StateOf<Parts["chip"]>, {
68
+ /** The chosen value this chip stands for. */
69
+ value: unknown;
70
+ }>;
71
+ /** With `multiple`: one chosen value. Its `value` is what its remove button takes away. */
72
+ declare function Chip({ value, ...props }: ChipProps): ReactElement;
73
+ export type ChipRemoveProps = PartComponentProps<"button", StateOf<Parts["chipRemove"]>>;
74
+ declare function ChipRemove(props: ChipRemoveProps): ReactElement;
75
+ export type EmptyProps = PartComponentProps<"div", StateOf<Parts["empty"]>>;
76
+ /** Drawn while no item is shown for what was typed. */
77
+ declare function Empty(props: EmptyProps): ReactElement | null;
78
+ export type AutocompleteRootProps = Omit<AutocompleteProps, "id"> & {
79
+ id?: string;
80
+ children?: ReactNode;
81
+ };
82
+ /** A combobox whose text is the value: the list only suggests. */
83
+ declare function AutocompleteRoot({ children, ...props }: AutocompleteRootProps): ReactElement;
84
+ export declare const Combobox: {
85
+ readonly Root: typeof Root;
86
+ readonly Input: typeof Input;
87
+ readonly Trigger: typeof Trigger;
88
+ readonly Clear: typeof Clear;
89
+ readonly Chips: typeof Chips;
90
+ readonly Chip: typeof Chip;
91
+ readonly ChipRemove: typeof ChipRemove;
92
+ readonly Portal: typeof Portal;
93
+ readonly Positioner: typeof Positioner;
94
+ readonly Popup: typeof Popup;
95
+ readonly List: typeof List;
96
+ readonly Group: typeof Group;
97
+ readonly GroupLabel: typeof GroupLabel;
98
+ readonly Separator: typeof Separator;
99
+ readonly Item: typeof Item;
100
+ readonly ItemIndicator: typeof ItemIndicator;
101
+ readonly Empty: typeof Empty;
102
+ };
103
+ export declare const Autocomplete: {
104
+ readonly Root: typeof AutocompleteRoot;
105
+ readonly Input: typeof Input;
106
+ readonly Trigger: typeof Trigger;
107
+ readonly Clear: typeof Clear;
108
+ readonly Portal: typeof Portal;
109
+ readonly Positioner: typeof Positioner;
110
+ readonly Popup: typeof Popup;
111
+ readonly List: typeof List;
112
+ readonly Group: typeof Group;
113
+ readonly GroupLabel: typeof GroupLabel;
114
+ readonly Separator: typeof Separator;
115
+ readonly Item: typeof Item;
116
+ readonly Empty: typeof Empty;
117
+ };
118
+ export type { PortalProps };
119
+ //# sourceMappingURL=combobox.d.ts.map
@@ -0,0 +1,177 @@
1
+ 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 { 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
+ /**
30
+ * The items' own box inside the popup, when the popup holds more than items (an input): it
31
+ * is then the listbox.
32
+ */
33
+ const List = (props) => usePart(useCombobox("List").list, "div", props);
34
+ function Portal({ children }) {
35
+ return useSignal(useCombobox("Portal").mounted) ? /* @__PURE__ */ jsx(Portal$1, { children }) : null;
36
+ }
37
+ function Positioner(props) {
38
+ const controller = useCombobox("Positioner");
39
+ return usePart(controller.positioner, "div", usePositioning(controller.positioning, props));
40
+ }
41
+ const GroupContext = createContext(null);
42
+ /** Items that belong together, named by their `GroupLabel`. Hidden while none is shown. */
43
+ function Group({ id, ...props }) {
44
+ const controller = useCombobox("Group");
45
+ const generated = useId();
46
+ const group = useMemo(() => controller.group(id ?? generated), [
47
+ controller,
48
+ id,
49
+ generated
50
+ ]);
51
+ return /* @__PURE__ */ jsx(GroupContext.Provider, {
52
+ value: group,
53
+ children: usePart(group.root, "div", props)
54
+ });
55
+ }
56
+ /** A group's name. Outside a group it is plain text, and names nothing. */
57
+ function GroupLabel(props) {
58
+ const lone = useCombobox("GroupLabel").groupLabel;
59
+ return usePart(useContext(GroupContext)?.label ?? lone, "div", props);
60
+ }
61
+ /** A line between groups. */
62
+ const Separator = (props) => usePart(useCombobox("Separator").separator, "div", props);
63
+ function Item({ value, disabled, label, id, index, ...props }) {
64
+ const controller = useCombobox("Item");
65
+ const group = useContext(GroupContext) ?? void 0;
66
+ const generated = useId();
67
+ const options = useOptions({
68
+ disabled,
69
+ label,
70
+ index,
71
+ id: id ?? generated
72
+ });
73
+ const part = useMemo(() => controller.item(value, () => options.get(), group), [
74
+ controller,
75
+ value,
76
+ options,
77
+ group
78
+ ]);
79
+ return /* @__PURE__ */ jsx(ItemContext.Provider, {
80
+ value,
81
+ children: usePart(part, "div", props)
82
+ });
83
+ }
84
+ /** In the page while its item is a chosen one. */
85
+ function ItemIndicator({ keepMounted, ...props }) {
86
+ const controller = useCombobox("ItemIndicator");
87
+ const value = useContext(ItemContext);
88
+ const selected = useSignal(controller.selected(value));
89
+ const part = useMemo(() => controller.itemIndicator(value), [controller, value]);
90
+ return selected || keepMounted ? /* @__PURE__ */ jsx(PartElement, {
91
+ of: part,
92
+ tag: "span",
93
+ ...props
94
+ }) : null;
95
+ }
96
+ /** A button that empties the input and the value. Drawn while there is something to clear. */
97
+ function Clear({ keepMounted, ...props }) {
98
+ const controller = useCombobox("Clear");
99
+ return useSignal(controller.clearable) || keepMounted ? /* @__PURE__ */ jsx(PartElement, {
100
+ of: controller.clear,
101
+ tag: "button",
102
+ ...props
103
+ }) : null;
104
+ }
105
+ /** With `multiple`: what holds the chips and the input. */
106
+ const Chips = (props) => usePart(useCombobox("Chips").chips, "div", props);
107
+ const ChipContext = createContext(void 0);
108
+ /** With `multiple`: one chosen value. Its `value` is what its remove button takes away. */
109
+ function Chip({ value, ...props }) {
110
+ const controller = useCombobox("Chip");
111
+ const part = useMemo(() => controller.chip(value), [controller, value]);
112
+ return /* @__PURE__ */ jsx(ChipContext.Provider, {
113
+ value,
114
+ children: usePart(part, "span", props)
115
+ });
116
+ }
117
+ function ChipRemove(props) {
118
+ const controller = useCombobox("ChipRemove");
119
+ const value = useContext(ChipContext);
120
+ const part = useMemo(() => controller.chipRemove(value), [controller, value]);
121
+ return usePart(part, "button", props);
122
+ }
123
+ /** Drawn while no item is shown for what was typed. */
124
+ function Empty(props) {
125
+ const controller = useCombobox("Empty");
126
+ return useSignal(controller.empty) ? /* @__PURE__ */ jsx(PartElement, {
127
+ of: controller.emptyPart,
128
+ tag: "div",
129
+ ...props
130
+ }) : null;
131
+ }
132
+ /** A combobox whose text is the value: the list only suggests. */
133
+ function AutocompleteRoot({ children, ...props }) {
134
+ const field = useContext(FieldContext) ?? void 0;
135
+ const controller = useController(within(createAutocomplete, { field }), props);
136
+ return /* @__PURE__ */ jsx(Context.Provider, {
137
+ value: controller,
138
+ children
139
+ });
140
+ }
141
+ const Combobox = /* @__PURE__ */ parts("Combobox", {
142
+ Root,
143
+ Input,
144
+ Trigger,
145
+ Clear,
146
+ Chips,
147
+ Chip,
148
+ ChipRemove,
149
+ Portal,
150
+ Positioner,
151
+ Popup,
152
+ List,
153
+ Group,
154
+ GroupLabel,
155
+ Separator,
156
+ Item,
157
+ ItemIndicator,
158
+ Empty
159
+ });
160
+ const Autocomplete = /* @__PURE__ */ parts("Autocomplete", {
161
+ Root: AutocompleteRoot,
162
+ Input,
163
+ Trigger,
164
+ Clear,
165
+ Portal,
166
+ Positioner,
167
+ Popup,
168
+ List,
169
+ Group,
170
+ GroupLabel,
171
+ Separator,
172
+ Item,
173
+ Empty
174
+ });
175
+ export { Autocomplete, Combobox };
176
+
177
+ //# sourceMappingURL=combobox.js.map
@@ -0,0 +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,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YAAY,MAAM;CACrC,MAAM,OAAO,cAAc,WAAW,KAAK,KAAK,GAAG,CAAC,YAAY,KAAK,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"}
@@ -0,0 +1,53 @@
1
+ import { PartComponentProps } from "./runtime.js";
2
+ import { StateOf } from "@kirana-ui/core";
3
+ import { ReactElement } from "react";
4
+ import { CommandProps } from "@kirana-ui/core/command";
5
+ import { Vocabulary } from "@kirana-ui/core/vocabulary";
6
+ type Parts = Vocabulary["command"];
7
+ export type RootProps = PartComponentProps<"div", StateOf<Parts["root"]>, Omit<CommandProps, "id"> & {
8
+ id?: string;
9
+ }>;
10
+ declare function Root({ inputValue, defaultInputValue, onInputValueChange, onSelect, filter, loop, disabled, id, ...rest }: RootProps): ReactElement;
11
+ export type InputProps = PartComponentProps<"input", StateOf<Parts["input"]>>;
12
+ declare const Input: (props: InputProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
13
+ export type ListProps = PartComponentProps<"div", StateOf<Parts["list"]>>;
14
+ declare const List: (props: ListProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
15
+ export type EmptyProps = PartComponentProps<"div", StateOf<Parts["empty"]>>;
16
+ /** Drawn while no item is shown for what was typed. */
17
+ declare function Empty(props: EmptyProps): ReactElement | null;
18
+ export type GroupProps = PartComponentProps<"div", StateOf<Parts["group"]>, {
19
+ id?: string;
20
+ }>;
21
+ /** Items under a `<Command.GroupHeading>`. Hidden while none of them is shown. */
22
+ declare function Group({ id, ...props }: GroupProps): ReactElement;
23
+ export type GroupHeadingProps = PartComponentProps<"div", StateOf<Parts["groupHeading"]>>;
24
+ declare function GroupHeading(props: GroupHeadingProps): ReactElement;
25
+ export type ItemProps = PartComponentProps<"div", StateOf<Parts["item"]>, {
26
+ /** What `onSelect` is told. */
27
+ value: string;
28
+ /** Disables this item: it cannot be chosen, and the arrows pass over it. */
29
+ disabled?: boolean;
30
+ /** What is filtered; the item's text when left out. */
31
+ label?: string;
32
+ /** Other words the item answers to. */
33
+ keywords?: readonly string[];
34
+ id?: string;
35
+ }>;
36
+ declare function Item({ value, disabled, label, keywords, id, ...props }: ItemProps): ReactElement;
37
+ export type SeparatorProps = PartComponentProps<"div", StateOf<Parts["separator"]>, {
38
+ /** Stays while something is typed. */
39
+ alwaysRender?: boolean;
40
+ }>;
41
+ declare function Separator({ alwaysRender, ...props }: SeparatorProps): ReactElement;
42
+ export declare const Command: {
43
+ readonly Root: typeof Root;
44
+ readonly Input: typeof Input;
45
+ readonly List: typeof List;
46
+ readonly Empty: typeof Empty;
47
+ readonly Group: typeof Group;
48
+ readonly GroupHeading: typeof GroupHeading;
49
+ readonly Item: typeof Item;
50
+ readonly Separator: typeof Separator;
51
+ };
52
+ export {};
53
+ //# sourceMappingURL=command.d.ts.map
package/src/command.js ADDED
@@ -0,0 +1,95 @@
1
+ import { PartElement, parts, 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(PartElement, {
27
+ of: controller.root,
28
+ tag: "div",
29
+ ...rest
30
+ })
31
+ });
32
+ }
33
+ const Input = (props) => usePart(useOwnText(useCommand("Input").input), "input", props);
34
+ const List = (props) => usePart(useCommand("List").list, "div", props);
35
+ /** Drawn while no item is shown for what was typed. */
36
+ function Empty(props) {
37
+ const controller = useCommand("Empty");
38
+ return useSignal(controller.empty) ? /* @__PURE__ */ jsx(PartElement, {
39
+ of: controller.emptyPart,
40
+ tag: "div",
41
+ ...props
42
+ }) : null;
43
+ }
44
+ /** Items under a `<Command.GroupHeading>`. Hidden while none of them is shown. */
45
+ function Group({ id, ...props }) {
46
+ const controller = useCommand("Group");
47
+ const generated = useId();
48
+ const name = id ?? generated;
49
+ const group = useMemo(() => controller.group(name), [controller, name]);
50
+ return /* @__PURE__ */ jsx(GroupContext.Provider, {
51
+ value: group,
52
+ children: usePart(group.part, "div", props)
53
+ });
54
+ }
55
+ function GroupHeading(props) {
56
+ const lone = useCommand("GroupHeading").heading;
57
+ return usePart(useContext(GroupContext)?.heading ?? lone, "div", props);
58
+ }
59
+ function Item({ value, disabled, label, keywords, id, ...props }) {
60
+ const controller = useCommand("Item");
61
+ const group = useContext(GroupContext);
62
+ const generated = useId();
63
+ const options = useOptions({
64
+ disabled,
65
+ label,
66
+ keywords,
67
+ id: id ?? generated
68
+ });
69
+ const part = useMemo(() => controller.item(value, () => options.get(), group), [
70
+ controller,
71
+ value,
72
+ options,
73
+ group
74
+ ]);
75
+ return usePart(part, "div", props);
76
+ }
77
+ function Separator({ alwaysRender, ...props }) {
78
+ const controller = useCommand("Separator");
79
+ const options = useOptions({ alwaysRender });
80
+ const part = useMemo(() => controller.separator(() => options.get().alwaysRender), [controller, options]);
81
+ return usePart(part, "div", props);
82
+ }
83
+ const Command = /* @__PURE__ */ parts("Command", {
84
+ Root,
85
+ Input,
86
+ List,
87
+ Empty,
88
+ Group,
89
+ GroupHeading,
90
+ Item,
91
+ Separator
92
+ });
93
+ export { Command };
94
+
95
+ //# sourceMappingURL=command.js.map
@@ -0,0 +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: 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,UACA,IACA,GAAG,QACuB;CAC1B,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E,MAAM,OAAO,cACL,WAAW,KAAK,aAAa,QAAQ,IAAI,GAAG,KAAK,GACvD;EAAC;EAAY;EAAO;EAAS;CAAK,CACpC;CACA,OAAO,QAAQ,MAAM,OAAO,KAAK;AACnC;AAWA,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,UAA0B,sBAAM,WAAW;CACtD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { PortalProps } from "./runtime.js";
2
+ import { ArrowProps, CheckboxItemIndicatorProps, CheckboxItemProps, ContextMenu, ContextTriggerProps, GroupLabelProps, GroupProps, ItemProps, LinkItemProps, PopupProps, PositionerProps, RadioGroupProps, RadioItemIndicatorProps, RadioItemProps, RootProps, SeparatorProps, SubmenuRootProps, SubmenuTriggerProps } from "./menu.js";
3
+ export { type ArrowProps, type CheckboxItemIndicatorProps, type CheckboxItemProps, ContextMenu, type GroupLabelProps, type GroupProps, type ItemProps, type LinkItemProps, type PopupProps, type PortalProps, type PositionerProps, type RadioGroupProps, type RadioItemIndicatorProps, type RadioItemProps, type RootProps, type SeparatorProps, type SubmenuRootProps, type SubmenuTriggerProps, type ContextTriggerProps as TriggerProps };
@@ -0,0 +1 @@
1
+ export { ContextMenu } from "./menu.js";
@@ -0,0 +1,37 @@
1
+ import { PartComponentProps } from "./runtime.js";
2
+ import { StateOf } from "@kirana-ui/core";
3
+ import { ReactElement, ReactNode } from "react";
4
+ import { DateField as DateField$1, DateFieldProps, DateFieldSegment } from "@kirana-ui/core/date-field";
5
+ import { Vocabulary } from "@kirana-ui/core/vocabulary";
6
+ type Parts = Vocabulary["dateField"];
7
+ /**
8
+ * The date field its parts are inside. Exported for a component that is made of one (a date picker
9
+ * provides its own to the date field's parts).
10
+ */
11
+ declare const Context: import("react").Context<DateField$1 | null>;
12
+ export type RootProps = PartComponentProps<"div", StateOf<Parts["root"]>, Omit<DateFieldProps, "id"> & {
13
+ id?: string;
14
+ }>;
15
+ declare function Root({ value, defaultValue, onValueChange, locale, min, max, placeholders, disabled, readOnly, required, name, form, id, ...rest }: RootProps): ReactElement;
16
+ export interface SegmentsProps {
17
+ /** Draws one piece of the date, once for each: a part that is typed, or what stands between two. */
18
+ children: (segment: DateFieldSegment) => ReactNode;
19
+ }
20
+ /** Draws its child once for each piece of the date, in the locale's order. */
21
+ declare function Segments({ children }: SegmentsProps): import("react").JSX.Element;
22
+ export type SegmentProps = PartComponentProps<"span", StateOf<Parts["segment"]>, {
23
+ /** The piece it is: an entry `DateField.Segments` gave. */
24
+ segment: DateFieldSegment;
25
+ }>;
26
+ /** One piece: a part that is typed, or what stands between two. It writes its own text. */
27
+ declare function Segment({ segment, ...props }: SegmentProps): ReactElement;
28
+ export type InputProps = PartComponentProps<"input", StateOf<Parts["input"]>>;
29
+ declare const Input: (props: InputProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
30
+ export declare const DateField: {
31
+ readonly Root: typeof Root;
32
+ readonly Segments: typeof Segments;
33
+ readonly Segment: typeof Segment;
34
+ readonly Input: typeof Input;
35
+ };
36
+ export { Context as DateFieldContext };
37
+ //# sourceMappingURL=date-field.d.ts.map
@@ -0,0 +1,64 @@
1
+ import { DirectionContext } from "./direction-context.js";
2
+ import { parts, 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
+ /**
9
+ * The date field its parts are inside. Exported for a component that is made of one (a date picker
10
+ * provides its own to the date field's parts).
11
+ */
12
+ const Context = createContext(null);
13
+ function useDateField(part) {
14
+ const controller = useContext(Context);
15
+ if (!controller) throw new Error(`<DateField.${part}> must be inside <DateField.Root>`);
16
+ return controller;
17
+ }
18
+ function Root({ value, defaultValue, onValueChange, locale, min, max, placeholders, disabled, readOnly, required, name, form, id, ...rest }) {
19
+ const direction = useContext(DirectionContext) ?? void 0;
20
+ const controller = useController(within(createDateField, { direction }), {
21
+ value,
22
+ defaultValue,
23
+ onValueChange,
24
+ locale,
25
+ min,
26
+ max,
27
+ placeholders,
28
+ disabled,
29
+ readOnly,
30
+ required,
31
+ name,
32
+ form,
33
+ id
34
+ });
35
+ return /* @__PURE__ */ jsx(Context.Provider, {
36
+ value: controller,
37
+ children: usePart(controller.root, "div", rest)
38
+ });
39
+ }
40
+ /** Draws its child once for each piece of the date, in the locale's order. */
41
+ function Segments({ children }) {
42
+ const segments = useSignal(useDateField("Segments").segments);
43
+ return /* @__PURE__ */ jsx(Fragment$1, { children: segments.map((segment) => /* @__PURE__ */ jsx(Fragment, { children: children(segment) }, `${segment.index}-${segment.type}`)) });
44
+ }
45
+ /** One piece: a part that is typed, or what stands between two. It writes its own text. */
46
+ function Segment({ segment, ...props }) {
47
+ const { part, text } = useDateField("Segment").segment(segment);
48
+ const shown = useSignal(text);
49
+ return usePart(part, "span", {
50
+ ...props,
51
+ suppressContentEditableWarning: true,
52
+ children: shown
53
+ });
54
+ }
55
+ const Input = (props) => usePart(useDateField("Input").input, "input", props);
56
+ const DateField = /* @__PURE__ */ parts("DateField", {
57
+ Root,
58
+ Segments,
59
+ Segment,
60
+ Input
61
+ });
62
+ export { DateField, Context as DateFieldContext };
63
+
64
+ //# 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 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\", { 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,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;;AAQA,SAAS,SAAS,EAAE,YAA2B;CAC7C,MAAM,WAAW,UAAU,aAAa,UAAU,CAAC,CAAC,QAAQ;CAC5D,OACE,oBAAA,YAAA,EAAA,UACG,SAAS,KAAK,YACb,oBAAC,U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