@kirana-ui/react 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +140 -0
- package/llms.txt +1507 -121
- package/package.json +44 -3
- package/skills/kirana-ui-primitives/SKILL.md +24 -4
- package/src/accordion.d.ts +2 -2
- package/src/accordion.js +3 -2
- package/src/accordion.js.map +1 -1
- package/src/autosize.d.ts +1 -1
- package/src/avatar.d.ts +2 -2
- package/src/avatar.js +3 -3
- package/src/avatar.js.map +1 -1
- package/src/button.d.ts +5 -2
- package/src/button.js +4 -1
- package/src/button.js.map +1 -1
- package/src/calendar.d.ts +6 -6
- package/src/calendar.js +13 -5
- package/src/calendar.js.map +1 -1
- package/src/carousel.d.ts +6 -3
- package/src/carousel.js +1 -1
- package/src/carousel.js.map +1 -1
- package/src/checkbox-group.d.ts +2 -1
- package/src/checkbox-group.js +1 -1
- package/src/checkbox-group.js.map +1 -1
- package/src/checkbox.d.ts +6 -1
- package/src/checkbox.js +1 -1
- package/src/checkbox.js.map +1 -1
- package/src/collapsible.d.ts +1 -1
- package/src/color-picker.d.ts +61 -0
- package/src/color-picker.js +119 -0
- package/src/color-picker.js.map +1 -0
- package/src/combobox.d.ts +13 -4
- package/src/combobox.js +13 -5
- package/src/combobox.js.map +1 -1
- package/src/command.d.ts +3 -3
- package/src/command.js.map +1 -1
- package/src/date-field.d.ts +2 -2
- package/src/date-field.js +3 -2
- package/src/date-field.js.map +1 -1
- package/src/date-picker.d.ts +29 -8
- package/src/date-picker.js +21 -5
- package/src/date-picker.js.map +1 -1
- package/src/dialog.d.ts +6 -6
- package/src/dialog.js +22 -7
- package/src/dialog.js.map +1 -1
- package/src/direction.d.ts +1 -1
- package/src/direction.js +1 -1
- package/src/editable.d.ts +32 -0
- package/src/editable.js +63 -0
- package/src/editable.js.map +1 -0
- package/src/field.d.ts +1 -1
- package/src/fieldset.d.ts +1 -1
- package/src/file-upload.d.ts +54 -0
- package/src/file-upload.js +96 -0
- package/src/file-upload.js.map +1 -0
- package/src/form.d.ts +1 -1
- package/src/hover-popup.d.ts +1 -1
- package/src/hover-popup.js +1 -1
- package/src/index.d.ts +26 -8
- package/src/index.js +11 -1
- package/src/input.d.ts +1 -1
- package/src/input.js +1 -1
- package/src/label.d.ts +1 -1
- package/src/listbox.d.ts +1 -1
- package/src/listbox.js +1 -1
- package/src/menu.d.ts +5 -5
- package/src/menu.js +14 -9
- package/src/menu.js.map +1 -1
- package/src/menubar.d.ts +2 -2
- package/src/menubar.js +4 -2
- package/src/menubar.js.map +1 -1
- package/src/message-scroller.d.ts +1 -1
- package/src/navigation-menu.d.ts +5 -5
- package/src/navigation-menu.js +14 -4
- package/src/navigation-menu.js.map +1 -1
- package/src/number-field.d.ts +2 -1
- package/src/number-field.js +1 -1
- package/src/number-field.js.map +1 -1
- package/src/otp.d.ts +3 -2
- package/src/otp.js +9 -2
- package/src/otp.js.map +1 -1
- package/src/pagination.d.ts +1 -1
- package/src/password-input.d.ts +23 -0
- package/src/password-input.js +40 -0
- package/src/password-input.js.map +1 -0
- package/src/popover.d.ts +1 -1
- package/src/popover.js +1 -1
- package/src/qr-code.d.ts +1 -1
- package/src/radio-group.d.ts +1 -1
- package/src/radio-group.js +1 -1
- package/src/rating.d.ts +28 -0
- package/src/rating.js +59 -0
- package/src/rating.js.map +1 -0
- package/src/resizable.d.ts +1 -1
- package/src/resizable.js +1 -1
- package/src/runtime.d.ts +10 -3
- package/src/runtime.js +18 -4
- package/src/runtime.js.map +1 -1
- package/src/scroll-area.d.ts +1 -1
- package/src/scroll-area.js +1 -1
- package/src/select.d.ts +17 -6
- package/src/select.js +6 -3
- package/src/select.js.map +1 -1
- package/src/separator.d.ts +1 -1
- package/src/slider.d.ts +1 -1
- package/src/slider.js +1 -1
- package/src/steps.d.ts +51 -0
- package/src/steps.js +69 -0
- package/src/steps.js.map +1 -0
- package/src/switch.d.ts +2 -1
- package/src/switch.js +1 -1
- package/src/switch.js.map +1 -1
- package/src/tabs.d.ts +2 -2
- package/src/tabs.js +4 -3
- package/src/tabs.js.map +1 -1
- package/src/tags-input.d.ts +47 -0
- package/src/tags-input.js +92 -0
- package/src/tags-input.js.map +1 -0
- package/src/time-field.d.ts +32 -0
- package/src/time-field.js +67 -0
- package/src/time-field.js.map +1 -0
- package/src/toast.d.ts +1 -1
- package/src/toggle-group.d.ts +2 -2
- package/src/toggle-group.js +4 -3
- package/src/toggle-group.js.map +1 -1
- package/src/toggle.d.ts +1 -1
- package/src/toggle.js +1 -1
- package/src/toolbar.d.ts +14 -6
- package/src/toolbar.js +19 -9
- package/src/toolbar.js.map +1 -1
- package/src/tour.d.ts +61 -0
- package/src/tour.js +68 -0
- package/src/tour.js.map +1 -0
- package/src/tree.d.ts +45 -0
- package/src/tree.js +93 -0
- package/src/tree.js.map +1 -0
- package/src/use-render.js +1 -1
- package/src/value-bar.d.ts +1 -1
package/src/select.d.ts
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
import { PartComponentProps, PortalProps, PositionerOptions } from "./runtime.js";
|
|
2
|
-
import { StateOf } from "@kirana-ui/core";
|
|
3
2
|
import { ReactElement, ReactNode } from "react";
|
|
3
|
+
import { StateOf } from "@kirana-ui/core";
|
|
4
4
|
import { SelectProps } from "@kirana-ui/core/select";
|
|
5
5
|
import { Vocabulary } from "@kirana-ui/core/vocabulary";
|
|
6
6
|
type Parts = Vocabulary["select"];
|
|
7
|
-
/**
|
|
8
|
-
|
|
7
|
+
/**
|
|
8
|
+
* `Value` is what tells an item from the others. `Multiple` is inferred from `multiple`: with
|
|
9
|
+
* `multiple`, `value`, `defaultValue` and `onValueChange` hold a list of them.
|
|
10
|
+
*/
|
|
11
|
+
export type RootProps<Value = unknown, Multiple extends boolean | undefined = false> = Omit<SelectProps<Value, Multiple>, "id" | "multiple"> & {
|
|
12
|
+
/** Several values: `value`, `defaultValue` and `onValueChange` then hold a list. Read once. */
|
|
13
|
+
multiple?: Multiple | undefined;
|
|
9
14
|
id?: string;
|
|
10
15
|
children?: ReactNode;
|
|
11
16
|
};
|
|
12
|
-
declare function Root<Value = unknown>({ children, ...props }: RootProps<Value>): ReactElement;
|
|
17
|
+
declare function Root<Value = unknown, Multiple extends boolean | undefined = false>({ children, ...props }: RootProps<Value, Multiple>): ReactElement;
|
|
13
18
|
export type TriggerProps = PartComponentProps<"button", StateOf<Parts["trigger"]>>;
|
|
14
19
|
declare const Trigger: (props: TriggerProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
15
20
|
export type ValueProps<Chosen = unknown> = PartComponentProps<"span", StateOf<Parts["value"]>, {
|
|
@@ -26,14 +31,19 @@ declare function Value<Chosen = unknown>({ placeholder, children, ...props }: Va
|
|
|
26
31
|
declare function Portal({ children }: PortalProps): ReactElement | null;
|
|
27
32
|
export type PositionerProps = PartComponentProps<"div", StateOf<Parts["positioner"]>, PositionerOptions & {
|
|
28
33
|
/**
|
|
29
|
-
* The list opens over its trigger, the chosen item's text on the trigger's own, where
|
|
30
|
-
*
|
|
34
|
+
* The list opens over its trigger, the chosen item's text on the trigger's own, where there is
|
|
35
|
+
* room and unless a finger opened it. While it lies there the page's scroll is held (its
|
|
36
|
+
* scrollbar's room kept), and a scroll of a box around the trigger closes the list
|
|
37
|
+
* (`"ancestor-scroll"`), as a change of the window's size does (`"window-resize"`).
|
|
31
38
|
*/
|
|
32
39
|
alignItemWithTrigger?: boolean;
|
|
33
40
|
}>;
|
|
34
41
|
declare function Positioner({ alignItemWithTrigger, ...props }: PositionerProps): ReactElement;
|
|
35
42
|
export type PopupProps = PartComponentProps<"div", StateOf<Parts["popup"]>>;
|
|
43
|
+
export type BackdropProps = PartComponentProps<"div", StateOf<Parts["backdrop"]>>;
|
|
36
44
|
declare const Popup: (props: PopupProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
45
|
+
/** What lies over the page behind the list: a sheet's (`presentation`) is modal. */
|
|
46
|
+
declare const Backdrop: (props: BackdropProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
37
47
|
export type GroupProps = PartComponentProps<"div", StateOf<Parts["group"]>, {
|
|
38
48
|
id?: string;
|
|
39
49
|
}>;
|
|
@@ -78,6 +88,7 @@ export declare const Select: {
|
|
|
78
88
|
readonly Trigger: typeof Trigger;
|
|
79
89
|
readonly Value: typeof Value;
|
|
80
90
|
readonly Portal: typeof Portal;
|
|
91
|
+
readonly Backdrop: typeof Backdrop;
|
|
81
92
|
readonly Positioner: typeof Positioner;
|
|
82
93
|
readonly Popup: typeof Popup;
|
|
83
94
|
readonly List: typeof List;
|
package/src/select.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { FieldContext } from "./field-context.js";
|
|
2
2
|
import { PartElement, Portal as Portal$1, parts, useController, useMount, useOptions, usePart, usePositioning, useSignal } from "./runtime.js";
|
|
3
|
-
import { defined, within } from "@kirana-ui/core";
|
|
4
3
|
import { createContext, useContext, useId, useMemo } from "react";
|
|
4
|
+
import { defined, within } from "@kirana-ui/core";
|
|
5
5
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
6
|
import { createSelect } from "@kirana-ui/core/select";
|
|
7
7
|
// src/select.tsx
|
|
@@ -45,6 +45,8 @@ function Positioner({ alignItemWithTrigger, ...props }) {
|
|
|
45
45
|
return usePart(controller.positioner, "div", usePositioning(controller.positioning, props));
|
|
46
46
|
}
|
|
47
47
|
const Popup = (props) => usePart(useSelect("Popup").popup, "div", props);
|
|
48
|
+
/** What lies over the page behind the list: a sheet's (`presentation`) is modal. */
|
|
49
|
+
const Backdrop = (props) => usePart(useSelect("Backdrop").backdrop, "div", props);
|
|
48
50
|
const GroupContext = createContext(null);
|
|
49
51
|
/** Items that belong together, named by their `<Select.GroupLabel>`. */
|
|
50
52
|
function Group({ id, ...props }) {
|
|
@@ -124,9 +126,9 @@ function ItemText(props) {
|
|
|
124
126
|
function ItemIndicator({ keepMounted, ...props }) {
|
|
125
127
|
const controller = useSelect("ItemIndicator");
|
|
126
128
|
const value = useContext(ItemContext);
|
|
127
|
-
const selected = useSignal(controller.selected(value));
|
|
128
129
|
const part = useMemo(() => controller.itemIndicator(value), [controller, value]);
|
|
129
|
-
|
|
130
|
+
useMount(part);
|
|
131
|
+
return useSignal(part.mounted) || keepMounted ? /* @__PURE__ */ jsx(PartElement, {
|
|
130
132
|
of: part,
|
|
131
133
|
tag: "span",
|
|
132
134
|
...props
|
|
@@ -137,6 +139,7 @@ const Select = /* @__PURE__ */ parts("Select", {
|
|
|
137
139
|
Trigger,
|
|
138
140
|
Value,
|
|
139
141
|
Portal,
|
|
142
|
+
Backdrop,
|
|
140
143
|
Positioner,
|
|
141
144
|
Popup,
|
|
142
145
|
List,
|
package/src/select.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"select.js","names":["BodyPortal"],"sources":["../../../../packages/react/src/select.tsx"],"sourcesContent":["import { defined, within } from \"@kirana-ui/core\"\nimport type { StateOf } from \"@kirana-ui/core\"\nimport { createSelect } from \"@kirana-ui/core/select\"\nimport type { Select as Controller, SelectGroup, SelectProps } from \"@kirana-ui/core/select\"\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 useMount,\n useOptions,\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[\"select\"]\n\nconst Context = createContext<Controller | null>(null)\nconst ItemContext = createContext<unknown>(undefined)\n\nfunction useSelect(part: string): Controller {\n const controller = useContext(Context)\n if (!controller) throw new Error(`<Select.${part}> must be inside <Select.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<SelectProps<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(within(createSelect<Value>, { field }), props)\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(useSelect(\"Root\").input, \"input\", {})\n\nexport type TriggerProps = PartComponentProps<\"button\", StateOf<Parts[\"trigger\"]>>\n\nconst Trigger = (props: TriggerProps) => usePart(useSelect(\"Trigger\").trigger, \"button\", props)\n\nexport type ValueProps<Chosen = unknown> = PartComponentProps<\n \"span\",\n StateOf<Parts[\"value\"]>,\n {\n /** Shown while nothing is chosen. */\n placeholder?: ReactNode\n /**\n * What to show in place of the label. A function is given the value and its label (`null`\n * and `undefined` while nothing is chosen); with `multiple`, the values and their labels, in\n * the items' order. Its first parameter's type says which: `(values: string[], labels) => …`.\n */\n children?:\n | ReactNode\n | ((\n value: Chosen,\n label: Chosen extends readonly unknown[] ? readonly string[] : string | undefined\n ) => ReactNode)\n }\n>\n\nfunction Value<Chosen = unknown>({\n placeholder,\n children,\n ...props\n}: ValueProps<Chosen>): ReactElement {\n const controller = useSelect(\"Value\")\n const shown = useSignal(controller.shown)\n let drawn: ReactNode\n if (typeof children === \"function\") {\n const draw = children as (value: unknown, label: unknown) => ReactNode\n drawn = controller.multiple ? draw(shown.values, shown.labels) : draw(shown.value, shown.label)\n } else drawn = children ?? shown.label ?? placeholder\n return usePart(controller.valuePart, \"span\", { ...props, children: drawn })\n}\n\nfunction Portal({ children }: PortalProps): ReactElement | null {\n const mounted = useSignal(useSelect(\"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 * The list opens over its trigger, the chosen item's text on the trigger's own, where\n * there is room and unless a finger opened it.\n */\n alignItemWithTrigger?: boolean\n }\n>\n\nfunction Positioner({ alignItemWithTrigger, ...props }: PositionerProps): ReactElement {\n const controller = useSelect(\"Positioner\")\n controller.alignItemWithTrigger.set(Boolean(alignItemWithTrigger))\n return usePart(controller.positioner, \"div\", usePositioning(controller.positioning, props))\n}\n\nexport type PopupProps = PartComponentProps<\"div\", StateOf<Parts[\"popup\"]>>\n\nconst Popup = (props: PopupProps) => usePart(useSelect(\"Popup\").popup, \"div\", props)\nconst GroupContext = createContext<SelectGroup | null>(null)\n\nexport type GroupProps = PartComponentProps<\"div\", StateOf<Parts[\"group\"]>, { id?: string }>\n\n/** Items that belong together, named by their `<Select.GroupLabel>`. */\nfunction Group({ id, ...props }: GroupProps): ReactElement {\n const controller = useSelect(\"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 = useSelect(\"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) => usePart(useSelect(\"Separator\").separator, \"div\", props)\n\nexport type ListProps = PartComponentProps<\"div\", StateOf<Parts[\"list\"]>>\n\n/** The items' own box inside the popup, when the popup also holds scroll arrows. */\nconst List = (props: ListProps) => usePart(useSelect(\"List\").list, \"div\", props)\n\nexport type ScrollUpArrowProps = PartComponentProps<\"div\", StateOf<Parts[\"scrollUpArrow\"]>>\nexport type ScrollDownArrowProps = PartComponentProps<\"div\", StateOf<Parts[\"scrollDownArrow\"]>>\n\n/** The arrow at one end of the list, and whether it is in the page: while there is more that way. */\nfunction useScrollArrow(name: string, direction: \"up\" | \"down\") {\n const controller = useSelect(name)\n const arrow = useMemo(() => controller.scrollArrow(direction), [controller, direction])\n useMount(arrow)\n return { part: arrow.part, mounted: useSignal(arrow.mounted) }\n}\n\n/** In the page while there is more of the list above: it scrolls it while the pointer moves over it. */\nfunction ScrollUpArrow(props: ScrollUpArrowProps): ReactElement | null {\n const { part, mounted } = useScrollArrow(\"ScrollUpArrow\", \"up\")\n return mounted ? <PartElement of={part} tag=\"div\" {...props} /> : null\n}\n\n/** In the page while there is more of the list below. */\nfunction ScrollDownArrow(props: ScrollDownArrowProps): ReactElement | null {\n const { part, mounted } = useScrollArrow(\"ScrollDownArrow\", \"down\")\n return mounted ? <PartElement of={part} tag=\"div\" {...props} /> : null\n}\n\nexport type ItemProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"item\"]>,\n {\n /** What the select'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 typeahead matches and the trigger shows; the item's text when left out. */\n label?: string\n /** Its place among all the rows, in a virtualized list. */\n index?: number\n }\n>\n\nfunction Item({ value, disabled, label, index, ...props }: ItemProps): ReactElement {\n const controller = useSelect(\"Item\")\n const options = useOptions({ disabled, label, index })\n const part = useMemo(\n () => controller.item(value, () => defined(options.get())),\n [controller, value, options]\n )\n return <ItemContext.Provider value={value}>{usePart(part, \"div\", props)}</ItemContext.Provider>\n}\n\nexport type ItemTextProps = PartComponentProps<\"span\", StateOf<Parts[\"itemText\"]>>\n\nfunction ItemText(props: ItemTextProps): ReactElement {\n const controller = useSelect(\"ItemText\")\n const value = useContext(ItemContext)\n const part = useMemo(() => controller.itemText(value), [controller, value])\n return usePart(part, \"span\", props)\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 the chosen one. */\nfunction ItemIndicator({ keepMounted, ...props }: ItemIndicatorProps): ReactElement | null {\n const controller = useSelect(\"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 const Select = /* @__PURE__ */ parts(\"Select\", {\n Root,\n Trigger,\n Value,\n Portal,\n Positioner,\n Popup,\n List,\n ScrollUpArrow,\n ScrollDownArrow,\n Group,\n GroupLabel,\n Separator,\n Item,\n ItemText,\n ItemIndicator,\n})\n"],"mappings":";;;;;;;AA0BA,MAAM,UAAU,cAAiC,IAAI;AACrD,MAAM,cAAc,cAAuB,KAAA,CAAS;AAEpD,SAAS,UAAU,MAA0B;CAC3C,MAAM,aAAa,WAAW,OAAO;CACrC,IAAI,CAAC,YAAY,MAAM,IAAI,MAAM,WAAW,KAAK,+BAA+B;CAChF,OAAO;AACT;AAQA,SAAS,KAAsB,EAAE,UAAU,GAAG,SAAyC;CACrF,MAAM,QAAQ,WAAW,YAAY,KAAK,KAAA;CAC1C,MAAM,aAAyB,cAAc,OAAO,cAAqB,EAAE,MAAM,CAAC,GAAG,KAAK;CAC1F,MAAM,QAAQ,UAAU,WAAW,KAAK;CACxC,OACE,qBAAC,QAAQ,UAAT;EAAkB,OAAO;EAAzB,UAAA,CACG,UACA,QAAQ,oBAAC,aAAD,CAAc,CAAA,IAAI,IACX;;AAEtB;AAEA,MAAM,oBAAoB,QAAQ,UAAU,MAAM,CAAC,CAAC,OAAO,SAAS,CAAC,CAAC;AAItE,MAAM,WAAW,UAAwB,QAAQ,UAAU,SAAS,CAAC,CAAC,SAAS,UAAU,KAAK;AAsB9F,SAAS,MAAwB,EAC/B,aACA,UACA,GAAG,SACgC;CACnC,MAAM,aAAa,UAAU,OAAO;CACpC,MAAM,QAAQ,UAAU,WAAW,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,GAAG,SAAkD;CACzF,MAAM,aAAa,UAAU,eAAe;CAC5C,MAAM,QAAQ,WAAW,WAAW;CACpC,MAAM,WAAW,UAAU,WAAW,SAAS,KAAK,CAAC;CACrD,MAAM,OAAO,cAAc,WAAW,cAAc,KAAK,GAAG,CAAC,YAAY,KAAK,CAAC;CAC/E,OAAO,YAAY,cAAc,oBAAC,aAAD;EAAa,IAAI;EAAM,KAAI;EAAO,GAAI;CAAQ,CAAA,IAAI;AACrF;AAEA,MAAa,SAAyB,sBAAM,UAAU;CACpD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC"}
|
|
1
|
+
{"version":3,"file":"select.js","names":["BodyPortal"],"sources":["../../../../packages/react/src/select.tsx"],"sourcesContent":["import { defined, within } from \"@kirana-ui/core\"\nimport type { StateOf } from \"@kirana-ui/core\"\nimport { createSelect } from \"@kirana-ui/core/select\"\nimport type { Select as Controller, SelectGroup, SelectProps } from \"@kirana-ui/core/select\"\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 useMount,\n useOptions,\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[\"select\"]\n\nconst Context = createContext<Controller | null>(null)\nconst ItemContext = createContext<unknown>(undefined)\n\nfunction useSelect(part: string): Controller {\n const controller = useContext(Context)\n if (!controller) throw new Error(`<Select.${part}> must be inside <Select.Root>`)\n return controller\n}\n\n/**\n * `Value` is what tells an item from the others. `Multiple` is inferred from `multiple`: with\n * `multiple`, `value`, `defaultValue` and `onValueChange` hold a list of them.\n */\nexport type RootProps<Value = unknown, Multiple extends boolean | undefined = false> = Omit<\n SelectProps<Value, Multiple>,\n \"id\" | \"multiple\"\n> & {\n /** Several values: `value`, `defaultValue` and `onValueChange` then hold a list. Read once. */\n multiple?: Multiple | undefined\n id?: string\n children?: ReactNode\n}\n\nfunction Root<Value = unknown, Multiple extends boolean | undefined = false>({\n children,\n ...props\n}: RootProps<Value, Multiple>): ReactElement {\n const field = useContext(FieldContext) ?? undefined\n const controller: Controller = useController(\n within(createSelect<Value, Multiple>, { 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\nconst HiddenInput = () => usePart(useSelect(\"Root\").input, \"input\", {})\n\nexport type TriggerProps = PartComponentProps<\"button\", StateOf<Parts[\"trigger\"]>>\n\nconst Trigger = (props: TriggerProps) => usePart(useSelect(\"Trigger\").trigger, \"button\", props)\n\nexport type ValueProps<Chosen = unknown> = PartComponentProps<\n \"span\",\n StateOf<Parts[\"value\"]>,\n {\n /** Shown while nothing is chosen. */\n placeholder?: ReactNode\n /**\n * What to show in place of the label. A function is given the value and its label (`null`\n * and `undefined` while nothing is chosen); with `multiple`, the values and their labels, in\n * the items' order. Its first parameter's type says which: `(values: string[], labels) => …`.\n */\n children?:\n | ReactNode\n | ((\n value: Chosen,\n label: Chosen extends readonly unknown[] ? readonly string[] : string | undefined\n ) => ReactNode)\n }\n>\n\nfunction Value<Chosen = unknown>({\n placeholder,\n children,\n ...props\n}: ValueProps<Chosen>): ReactElement {\n const controller = useSelect(\"Value\")\n const shown = useSignal(controller.shown)\n let drawn: ReactNode\n if (typeof children === \"function\") {\n const draw = children as (value: unknown, label: unknown) => ReactNode\n drawn = controller.multiple ? draw(shown.values, shown.labels) : draw(shown.value, shown.label)\n } else drawn = children ?? shown.label ?? placeholder\n return usePart(controller.valuePart, \"span\", { ...props, children: drawn })\n}\n\nfunction Portal({ children }: PortalProps): ReactElement | null {\n const mounted = useSignal(useSelect(\"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 * The list opens over its trigger, the chosen item's text on the trigger's own, where there is\n * room and unless a finger opened it. While it lies there the page's scroll is held (its\n * scrollbar's room kept), and a scroll of a box around the trigger closes the list\n * (`\"ancestor-scroll\"`), as a change of the window's size does (`\"window-resize\"`).\n */\n alignItemWithTrigger?: boolean\n }\n>\n\nfunction Positioner({ alignItemWithTrigger, ...props }: PositionerProps): ReactElement {\n const controller = useSelect(\"Positioner\")\n controller.alignItemWithTrigger.set(Boolean(alignItemWithTrigger))\n return usePart(controller.positioner, \"div\", usePositioning(controller.positioning, props))\n}\n\nexport type PopupProps = PartComponentProps<\"div\", StateOf<Parts[\"popup\"]>>\nexport type BackdropProps = PartComponentProps<\"div\", StateOf<Parts[\"backdrop\"]>>\n\nconst Popup = (props: PopupProps) => usePart(useSelect(\"Popup\").popup, \"div\", props)\n/** What lies over the page behind the list: a sheet's (`presentation`) is modal. */\nconst Backdrop = (props: BackdropProps) => usePart(useSelect(\"Backdrop\").backdrop, \"div\", props)\nconst GroupContext = createContext<SelectGroup | null>(null)\n\nexport type GroupProps = PartComponentProps<\"div\", StateOf<Parts[\"group\"]>, { id?: string }>\n\n/** Items that belong together, named by their `<Select.GroupLabel>`. */\nfunction Group({ id, ...props }: GroupProps): ReactElement {\n const controller = useSelect(\"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 = useSelect(\"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) => usePart(useSelect(\"Separator\").separator, \"div\", props)\n\nexport type ListProps = PartComponentProps<\"div\", StateOf<Parts[\"list\"]>>\n\n/** The items' own box inside the popup, when the popup also holds scroll arrows. */\nconst List = (props: ListProps) => usePart(useSelect(\"List\").list, \"div\", props)\n\nexport type ScrollUpArrowProps = PartComponentProps<\"div\", StateOf<Parts[\"scrollUpArrow\"]>>\nexport type ScrollDownArrowProps = PartComponentProps<\"div\", StateOf<Parts[\"scrollDownArrow\"]>>\n\n/** The arrow at one end of the list, and whether it is in the page: while there is more that way. */\nfunction useScrollArrow(name: string, direction: \"up\" | \"down\") {\n const controller = useSelect(name)\n const arrow = useMemo(() => controller.scrollArrow(direction), [controller, direction])\n useMount(arrow)\n return { part: arrow.part, mounted: useSignal(arrow.mounted) }\n}\n\n/** In the page while there is more of the list above: it scrolls it while the pointer moves over it. */\nfunction ScrollUpArrow(props: ScrollUpArrowProps): ReactElement | null {\n const { part, mounted } = useScrollArrow(\"ScrollUpArrow\", \"up\")\n return mounted ? <PartElement of={part} tag=\"div\" {...props} /> : null\n}\n\n/** In the page while there is more of the list below. */\nfunction ScrollDownArrow(props: ScrollDownArrowProps): ReactElement | null {\n const { part, mounted } = useScrollArrow(\"ScrollDownArrow\", \"down\")\n return mounted ? <PartElement of={part} tag=\"div\" {...props} /> : null\n}\n\nexport type ItemProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"item\"]>,\n {\n /** What the select'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 typeahead matches and the trigger shows; the item's text when left out. */\n label?: string\n /** Its place among all the rows, in a virtualized list. */\n index?: number\n }\n>\n\nfunction Item({ value, disabled, label, index, ...props }: ItemProps): ReactElement {\n const controller = useSelect(\"Item\")\n const options = useOptions({ disabled, label, index })\n const part = useMemo(\n () => controller.item(value, () => defined(options.get())),\n [controller, value, options]\n )\n return <ItemContext.Provider value={value}>{usePart(part, \"div\", props)}</ItemContext.Provider>\n}\n\nexport type ItemTextProps = PartComponentProps<\"span\", StateOf<Parts[\"itemText\"]>>\n\nfunction ItemText(props: ItemTextProps): ReactElement {\n const controller = useSelect(\"ItemText\")\n const value = useContext(ItemContext)\n const part = useMemo(() => controller.itemText(value), [controller, value])\n return usePart(part, \"span\", props)\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 the chosen one. */\nfunction ItemIndicator({ keepMounted, ...props }: ItemIndicatorProps): ReactElement | null {\n const controller = useSelect(\"ItemIndicator\")\n const value = useContext(ItemContext)\n const part = useMemo(() => controller.itemIndicator(value), [controller, value])\n // In the page while chosen, and through its exit.\n useMount(part)\n const mounted = useSignal(part.mounted)\n return mounted || keepMounted ? <PartElement of={part} tag=\"span\" {...props} /> : null\n}\n\nexport const Select = /* @__PURE__ */ parts(\"Select\", {\n Root,\n Trigger,\n Value,\n Portal,\n Backdrop,\n Positioner,\n Popup,\n List,\n ScrollUpArrow,\n ScrollDownArrow,\n Group,\n GroupLabel,\n Separator,\n Item,\n ItemText,\n ItemIndicator,\n})\n"],"mappings":";;;;;;;AA0BA,MAAM,UAAU,cAAiC,IAAI;AACrD,MAAM,cAAc,cAAuB,KAAA,CAAS;AAEpD,SAAS,UAAU,MAA0B;CAC3C,MAAM,aAAa,WAAW,OAAO;CACrC,IAAI,CAAC,YAAY,MAAM,IAAI,MAAM,WAAW,KAAK,+BAA+B;CAChF,OAAO;AACT;AAgBA,SAAS,KAAoE,EAC3E,UACA,GAAG,SACwC;CAC3C,MAAM,QAAQ,WAAW,YAAY,KAAK,KAAA;CAC1C,MAAM,aAAyB,cAC7B,OAAO,cAA+B,EAAE,MAAM,CAAC,GAC/C,KACF;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M;CACnC,MAAM,UAAU,WAAW;EAAE;EAAU;EAAO;CAAM,CAAC;CACrD,MAAM,OAAO,cACL,WAAW,KAAK,aAAa,QAAQ,QAAQ,IAAI,CAAC,CAAC,GACzD;EAAC;EAAY;EAAO;CAAO,CAC7B;CACA,OAAO,oBAAC,YAAY,UAAb;EAA6B;EAAQ,UAAA,QAAQ,MAAM,OAAO,KAAK;CAAwB,CAAA;AAChG;AAIA,SAAS,SAAS,OAAoC;CACpD,MAAM,aAAa,UAAU,UAAU;CACvC,MAAM,QAAQ,WAAW,WAAW;CACpC,MAAM,OAAO,cAAc,WAAW,SAAS,KAAK,GAAG,CAAC,YAAY,KAAK,CAAC;CAC1E,OAAO,QAAQ,MAAM,QAAQ,KAAK;AACpC;;AAYA,SAAS,cAAc,EAAE,aAAa,GAAG,SAAkD;CACzF,MAAM,aAAa,UAAU,eAAe;CAC5C,MAAM,QAAQ,WAAW,WAAW;CACpC,MAAM,OAAO,cAAc,WAAW,cAAc,KAAK,GAAG,CAAC,YAAY,KAAK,CAAC;CAE/E,SAAS,IAAI;CAEb,OADgB,UAAU,KAAK,OAClB,KAAK,cAAc,oBAAC,aAAD;EAAa,IAAI;EAAM,KAAI;EAAO,GAAI;CAAQ,CAAA,IAAI;AACpF;AAEA,MAAa,SAAyB,sBAAM,UAAU;CACpD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC"}
|
package/src/separator.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PartComponentProps } from "./runtime.js";
|
|
2
|
-
import { StateOf } from "@kirana-ui/core";
|
|
3
2
|
import { ReactElement } from "react";
|
|
3
|
+
import { StateOf } from "@kirana-ui/core";
|
|
4
4
|
import { SeparatorProps as SeparatorProps$1 } from "@kirana-ui/core/separator";
|
|
5
5
|
import { Vocabulary } from "@kirana-ui/core/vocabulary";
|
|
6
6
|
export type SeparatorProps = PartComponentProps<"div", StateOf<Vocabulary["separator"]["root"]>, SeparatorProps$1>;
|
package/src/slider.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PartComponentProps } from "./runtime.js";
|
|
2
|
-
import { StateOf } from "@kirana-ui/core";
|
|
3
2
|
import { ReactElement, ReactNode } from "react";
|
|
3
|
+
import { StateOf } from "@kirana-ui/core";
|
|
4
4
|
import { SliderProps, SliderValue } from "@kirana-ui/core/slider";
|
|
5
5
|
import { Vocabulary } from "@kirana-ui/core/vocabulary";
|
|
6
6
|
type Parts = Vocabulary["slider"];
|
package/src/slider.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { DirectionContext } from "./direction-context.js";
|
|
2
2
|
import { FieldContext } from "./field-context.js";
|
|
3
3
|
import { PartElement, parts, useController, usePart, useSignal } from "./runtime.js";
|
|
4
|
-
import { within } from "@kirana-ui/core";
|
|
5
4
|
import { createContext, useContext, useId } from "react";
|
|
5
|
+
import { within } from "@kirana-ui/core";
|
|
6
6
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
7
7
|
import { createSlider } from "@kirana-ui/core/slider";
|
|
8
8
|
// src/slider.tsx
|
package/src/steps.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { PartComponentProps } from "./runtime.js";
|
|
2
|
+
import { ReactElement } from "react";
|
|
3
|
+
import { StateOf } from "@kirana-ui/core";
|
|
4
|
+
import { StepsProps } from "@kirana-ui/core/steps";
|
|
5
|
+
import { Vocabulary } from "@kirana-ui/core/vocabulary";
|
|
6
|
+
type Parts = Vocabulary["steps"];
|
|
7
|
+
export type RootProps = PartComponentProps<"div", StateOf<Parts["root"]>, Omit<StepsProps, "id"> & {
|
|
8
|
+
id?: string;
|
|
9
|
+
}>;
|
|
10
|
+
declare function Root({ step, defaultStep, onStepChange, count, linear, orientation, id, ...rest }: RootProps): ReactElement;
|
|
11
|
+
export type ListProps = PartComponentProps<"div", StateOf<Parts["list"]>>;
|
|
12
|
+
declare const List: (props: ListProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
13
|
+
export type ItemProps = PartComponentProps<"div", StateOf<Parts["item"]>, {
|
|
14
|
+
/**
|
|
15
|
+
* Which step it is, from 0. Left out, its place among the items in the page, once it is
|
|
16
|
+
* there: give it on a page a server draws, which cannot count them.
|
|
17
|
+
*/
|
|
18
|
+
index?: number;
|
|
19
|
+
}>;
|
|
20
|
+
declare function Item({ index, ...props }: ItemProps): ReactElement;
|
|
21
|
+
export type TriggerProps = PartComponentProps<"button", StateOf<Parts["trigger"]>>;
|
|
22
|
+
declare const Trigger: (props: TriggerProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
23
|
+
export type IndicatorProps = PartComponentProps<"span", StateOf<Parts["indicator"]>>;
|
|
24
|
+
declare const Indicator: (props: IndicatorProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
25
|
+
export type SeparatorProps = PartComponentProps<"div", StateOf<Parts["separator"]>>;
|
|
26
|
+
declare const Separator: (props: SeparatorProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
27
|
+
export type ContentProps = PartComponentProps<"div", StateOf<Parts["content"]>, {
|
|
28
|
+
/** The step it is shown for, from 0. */
|
|
29
|
+
index: number;
|
|
30
|
+
}>;
|
|
31
|
+
declare function Content({ index, ...props }: ContentProps): ReactElement;
|
|
32
|
+
export type CompletedProps = PartComponentProps<"div", StateOf<Parts["completed"]>>;
|
|
33
|
+
declare const Completed: (props: CompletedProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
34
|
+
export type PreviousProps = PartComponentProps<"button", StateOf<Parts["previous"]>>;
|
|
35
|
+
declare const Previous: (props: PreviousProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
36
|
+
export type NextProps = PartComponentProps<"button", StateOf<Parts["next"]>>;
|
|
37
|
+
declare const Next: (props: NextProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
38
|
+
export declare const Steps: {
|
|
39
|
+
readonly Root: typeof Root;
|
|
40
|
+
readonly List: typeof List;
|
|
41
|
+
readonly Item: typeof Item;
|
|
42
|
+
readonly Trigger: typeof Trigger;
|
|
43
|
+
readonly Indicator: typeof Indicator;
|
|
44
|
+
readonly Separator: typeof Separator;
|
|
45
|
+
readonly Content: typeof Content;
|
|
46
|
+
readonly Completed: typeof Completed;
|
|
47
|
+
readonly Previous: typeof Previous;
|
|
48
|
+
readonly Next: typeof Next;
|
|
49
|
+
};
|
|
50
|
+
export {};
|
|
51
|
+
//# sourceMappingURL=steps.d.ts.map
|
package/src/steps.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { DirectionContext } from "./direction-context.js";
|
|
2
|
+
import { parts, useController, usePart } from "./runtime.js";
|
|
3
|
+
import { createContext, useContext, useMemo } from "react";
|
|
4
|
+
import { within } from "@kirana-ui/core";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
import { createSteps } from "@kirana-ui/core/steps";
|
|
7
|
+
// src/steps.tsx
|
|
8
|
+
const Context = createContext(null);
|
|
9
|
+
const ItemContext = createContext(null);
|
|
10
|
+
function useSteps(part) {
|
|
11
|
+
const controller = useContext(Context);
|
|
12
|
+
if (!controller) throw new Error(`<Steps.${part}> must be inside <Steps.Root>`);
|
|
13
|
+
return controller;
|
|
14
|
+
}
|
|
15
|
+
function useIndex(part) {
|
|
16
|
+
const index = useContext(ItemContext);
|
|
17
|
+
if (index === null) throw new Error(`<Steps.${part}> must be inside <Steps.Item>`);
|
|
18
|
+
return index;
|
|
19
|
+
}
|
|
20
|
+
function Root({ step, defaultStep, onStepChange, count, linear, orientation, id, ...rest }) {
|
|
21
|
+
const direction = useContext(DirectionContext) ?? void 0;
|
|
22
|
+
const create = within(createSteps, { direction });
|
|
23
|
+
const controller = useController(create, {
|
|
24
|
+
step,
|
|
25
|
+
defaultStep,
|
|
26
|
+
onStepChange,
|
|
27
|
+
count,
|
|
28
|
+
linear,
|
|
29
|
+
orientation,
|
|
30
|
+
id
|
|
31
|
+
});
|
|
32
|
+
return /* @__PURE__ */ jsx(Context.Provider, {
|
|
33
|
+
value: controller,
|
|
34
|
+
children: usePart(controller.root, "div", rest)
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
const List = (props) => usePart(useSteps("List").list, "div", props);
|
|
38
|
+
function Item({ index, ...props }) {
|
|
39
|
+
const controller = useSteps("Item");
|
|
40
|
+
const item = useMemo(() => controller.item(index), [controller, index]);
|
|
41
|
+
return /* @__PURE__ */ jsx(ItemContext.Provider, {
|
|
42
|
+
value: item.index,
|
|
43
|
+
children: usePart(item, "div", props)
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
const Trigger = (props) => usePart(useSteps("Trigger").trigger(useIndex("Trigger")), "button", props);
|
|
47
|
+
const Indicator = (props) => usePart(useSteps("Indicator").indicator(useIndex("Indicator")), "span", props);
|
|
48
|
+
const Separator = (props) => usePart(useSteps("Separator").separator(useIndex("Separator")), "div", props);
|
|
49
|
+
function Content({ index, ...props }) {
|
|
50
|
+
return usePart(useSteps("Content").content(index), "div", props);
|
|
51
|
+
}
|
|
52
|
+
const Completed = (props) => usePart(useSteps("Completed").completed, "div", props);
|
|
53
|
+
const Previous = (props) => usePart(useSteps("Previous").previous, "button", props);
|
|
54
|
+
const Next = (props) => usePart(useSteps("Next").next, "button", props);
|
|
55
|
+
const Steps = /* @__PURE__ */ parts("Steps", {
|
|
56
|
+
Root,
|
|
57
|
+
List,
|
|
58
|
+
Item,
|
|
59
|
+
Trigger,
|
|
60
|
+
Indicator,
|
|
61
|
+
Separator,
|
|
62
|
+
Content,
|
|
63
|
+
Completed,
|
|
64
|
+
Previous,
|
|
65
|
+
Next
|
|
66
|
+
});
|
|
67
|
+
export { Steps };
|
|
68
|
+
|
|
69
|
+
//# sourceMappingURL=steps.js.map
|
package/src/steps.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"steps.js","names":[],"sources":["../../../../packages/react/src/steps.tsx"],"sourcesContent":["import { within } from \"@kirana-ui/core\"\nimport type { StateOf, ReadonlySignal } from \"@kirana-ui/core\"\nimport { createSteps } from \"@kirana-ui/core/steps\"\nimport type { Steps as Controller, StepsProps } from \"@kirana-ui/core/steps\"\nimport type { Vocabulary } from \"@kirana-ui/core/vocabulary\"\nimport { createContext, useContext, useMemo } from \"react\"\nimport type { ReactElement } from \"react\"\n\nimport { DirectionContext } from \"./direction-context.ts\"\nimport { parts, useController, usePart } from \"./runtime.tsx\"\nimport type { PartComponentProps } from \"./runtime.tsx\"\n\ntype Parts = Vocabulary[\"steps\"]\n\nconst Context = createContext<Controller | null>(null)\n// The step an item is, for the parts inside it: given, or counted from the page.\nconst ItemContext = createContext<ReadonlySignal<number> | null>(null)\n\nfunction useSteps(part: string): Controller {\n const controller = useContext(Context)\n if (!controller) throw new Error(`<Steps.${part}> must be inside <Steps.Root>`)\n return controller\n}\n\nfunction useIndex(part: string): ReadonlySignal<number> {\n const index = useContext(ItemContext)\n if (index === null) throw new Error(`<Steps.${part}> must be inside <Steps.Item>`)\n return index\n}\n\nexport type RootProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"root\"]>,\n Omit<StepsProps, \"id\"> & { id?: string }\n>\n\nfunction Root({\n step,\n defaultStep,\n onStepChange,\n count,\n linear,\n orientation,\n id,\n ...rest\n}: RootProps): ReactElement {\n const direction = useContext(DirectionContext) ?? undefined\n const create = within(createSteps, { direction })\n const controller: Controller = useController(create, {\n step,\n defaultStep,\n onStepChange,\n count,\n linear,\n orientation,\n id,\n })\n return (\n <Context.Provider value={controller}>{usePart(controller.root, \"div\", rest)}</Context.Provider>\n )\n}\n\nexport type ListProps = PartComponentProps<\"div\", StateOf<Parts[\"list\"]>>\n\nconst List = (props: ListProps) => usePart(useSteps(\"List\").list, \"div\", props)\n\nexport type ItemProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"item\"]>,\n {\n /**\n * Which step it is, from 0. Left out, its place among the items in the page, once it is\n * there: give it on a page a server draws, which cannot count them.\n */\n index?: number\n }\n>\n\nfunction Item({ index, ...props }: ItemProps): ReactElement {\n const controller = useSteps(\"Item\")\n const item = useMemo(() => controller.item(index), [controller, index])\n return (\n <ItemContext.Provider value={item.index}>{usePart(item, \"div\", props)}</ItemContext.Provider>\n )\n}\n\nexport type TriggerProps = PartComponentProps<\"button\", StateOf<Parts[\"trigger\"]>>\n\nconst Trigger = (props: TriggerProps) =>\n usePart(useSteps(\"Trigger\").trigger(useIndex(\"Trigger\")), \"button\", props)\n\nexport type IndicatorProps = PartComponentProps<\"span\", StateOf<Parts[\"indicator\"]>>\n\nconst Indicator = (props: IndicatorProps) =>\n usePart(useSteps(\"Indicator\").indicator(useIndex(\"Indicator\")), \"span\", props)\n\nexport type SeparatorProps = PartComponentProps<\"div\", StateOf<Parts[\"separator\"]>>\n\nconst Separator = (props: SeparatorProps) =>\n usePart(useSteps(\"Separator\").separator(useIndex(\"Separator\")), \"div\", props)\n\nexport type ContentProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"content\"]>,\n {\n /** The step it is shown for, from 0. */\n index: number\n }\n>\n\nfunction Content({ index, ...props }: ContentProps): ReactElement {\n return usePart(useSteps(\"Content\").content(index), \"div\", props)\n}\n\nexport type CompletedProps = PartComponentProps<\"div\", StateOf<Parts[\"completed\"]>>\n\nconst Completed = (props: CompletedProps) => usePart(useSteps(\"Completed\").completed, \"div\", props)\n\nexport type PreviousProps = PartComponentProps<\"button\", StateOf<Parts[\"previous\"]>>\n\nconst Previous = (props: PreviousProps) => usePart(useSteps(\"Previous\").previous, \"button\", props)\n\nexport type NextProps = PartComponentProps<\"button\", StateOf<Parts[\"next\"]>>\n\nconst Next = (props: NextProps) => usePart(useSteps(\"Next\").next, \"button\", props)\n\nexport const Steps = /* @__PURE__ */ parts(\"Steps\", {\n Root,\n List,\n Item,\n Trigger,\n Indicator,\n Separator,\n Content,\n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,GAAG,QAAQ,KAAK;AAI/E,MAAM,aAAa,UACjB,QAAQ,SAAS,WAAW,CAAC,CAAC,UAAU,SAAS,WAAW,CAAC,GAAG,OAAO,KAAK;AAW9E,SAAS,QAAQ,EAAE,OAAO,GAAG,SAAqC;CAChE,OAAO,QAAQ,SAAS,SAAS,CAAC,CAAC,QAAQ,KAAK,GAAG,OAAO,KAAK;AACjE;AAIA,MAAM,aAAa,UAA0B,QAAQ,SAAS,WAAW,CAAC,CAAC,WAAW,OAAO,KAAK;AAIlG,MAAM,YAAY,UAAyB,QAAQ,SAAS,UAAU,CAAC,CAAC,UAAU,UAAU,KAAK;AAIjG,MAAM,QAAQ,UAAqB,QAAQ,SAAS,MAAM,CAAC,CAAC,MAAM,UAAU,KAAK;AAEjF,MAAa,QAAwB,sBAAM,SAAS;CAClD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC"}
|
package/src/switch.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { PartComponentProps } from "./runtime.js";
|
|
2
|
-
import { StateOf } from "@kirana-ui/core";
|
|
3
2
|
import { ReactElement } from "react";
|
|
3
|
+
import { StateOf } from "@kirana-ui/core";
|
|
4
4
|
import { SwitchProps } from "@kirana-ui/core/switch";
|
|
5
5
|
import { Vocabulary } from "@kirana-ui/core/vocabulary";
|
|
6
6
|
type Parts = Vocabulary["switch"];
|
|
7
7
|
export type RootProps = PartComponentProps<"span", StateOf<Parts["root"]>, Omit<SwitchProps, "id"> & {
|
|
8
|
+
/** The id of the switch's hidden native checkbox, not of the switch: a `<label for>` names it. Inside a `Field`, that input takes the field's id instead. */
|
|
8
9
|
id?: string;
|
|
9
10
|
}>;
|
|
10
11
|
declare function Root({ checked, defaultChecked, onCheckedChange, disabled, readOnly, required, name, form, value, id, ...rest }: RootProps): ReactElement;
|
package/src/switch.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { FieldContext } from "./field-context.js";
|
|
2
2
|
import { PartElement, parts, useController, usePart } from "./runtime.js";
|
|
3
|
-
import { within } from "@kirana-ui/core";
|
|
4
3
|
import { createContext, useContext } from "react";
|
|
4
|
+
import { within } from "@kirana-ui/core";
|
|
5
5
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
6
6
|
import { createSwitch } from "@kirana-ui/core/switch";
|
|
7
7
|
// src/switch.tsx
|
package/src/switch.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"switch.js","names":[],"sources":["../../../../packages/react/src/switch.tsx"],"sourcesContent":["import { within } from \"@kirana-ui/core\"\nimport type { StateOf } from \"@kirana-ui/core\"\nimport { createSwitch } from \"@kirana-ui/core/switch\"\nimport type { Switch as Controller, SwitchProps } from \"@kirana-ui/core/switch\"\nimport type { Vocabulary } from \"@kirana-ui/core/vocabulary\"\nimport { createContext, useContext } from \"react\"\nimport type { ReactElement, ReactNode } from \"react\"\n\nimport { FieldContext } from \"./field-context.ts\"\nimport { PartElement, parts, useController, usePart } from \"./runtime.tsx\"\nimport type { PartComponentProps } from \"./runtime.tsx\"\n\ntype Parts = Vocabulary[\"switch\"]\n\nconst Context = createContext<Controller | null>(null)\n\nfunction useSwitch(part: string): Controller {\n const controller = useContext(Context)\n if (!controller) throw new Error(`<Switch.${part}> must be inside <Switch.Root>`)\n return controller\n}\n\nexport type RootProps = PartComponentProps<\n \"span\",\n StateOf<Parts[\"root\"]>,\n Omit<SwitchProps, \"id\"> & { id?: string
|
|
1
|
+
{"version":3,"file":"switch.js","names":[],"sources":["../../../../packages/react/src/switch.tsx"],"sourcesContent":["import { within } from \"@kirana-ui/core\"\nimport type { StateOf } from \"@kirana-ui/core\"\nimport { createSwitch } from \"@kirana-ui/core/switch\"\nimport type { Switch as Controller, SwitchProps } from \"@kirana-ui/core/switch\"\nimport type { Vocabulary } from \"@kirana-ui/core/vocabulary\"\nimport { createContext, useContext } from \"react\"\nimport type { ReactElement, ReactNode } from \"react\"\n\nimport { FieldContext } from \"./field-context.ts\"\nimport { PartElement, parts, useController, usePart } from \"./runtime.tsx\"\nimport type { PartComponentProps } from \"./runtime.tsx\"\n\ntype Parts = Vocabulary[\"switch\"]\n\nconst Context = createContext<Controller | null>(null)\n\nfunction useSwitch(part: string): Controller {\n const controller = useContext(Context)\n if (!controller) throw new Error(`<Switch.${part}> must be inside <Switch.Root>`)\n return controller\n}\n\nexport type RootProps = PartComponentProps<\n \"span\",\n StateOf<Parts[\"root\"]>,\n Omit<SwitchProps, \"id\"> & {\n /** The id of the switch's hidden native checkbox, not of the switch: a `<label for>` names it. Inside a `Field`, that input takes the field's id instead. */\n id?: string\n }\n>\n\nfunction Root({\n checked,\n defaultChecked,\n onCheckedChange,\n disabled,\n readOnly,\n required,\n name,\n form,\n value,\n id,\n ...rest\n}: RootProps): ReactElement {\n const field = useContext(FieldContext) ?? undefined\n const create = within(createSwitch, { field })\n const controller = useController(create, {\n checked,\n defaultChecked,\n onCheckedChange,\n disabled,\n readOnly,\n required,\n name,\n form,\n value,\n id,\n })\n return (\n <Context.Provider value={controller}>\n <PartElement of={controller.root} tag=\"span\" hold={withInput} {...rest} />\n </Context.Provider>\n )\n}\n\n// Its native input is the element's last child, whatever element the caller asked for.\nconst withInput = (content: ReactNode) => (\n <>\n {content}\n <Input />\n </>\n)\n\nconst Input = () => usePart(useSwitch(\"Root\").input, \"input\", {})\n\nexport type ThumbProps = PartComponentProps<\"span\", StateOf<Parts[\"thumb\"]>>\n\nconst Thumb = (props: ThumbProps) => usePart(useSwitch(\"Thumb\").thumb, \"span\", props)\n\nexport const Switch = /* @__PURE__ */ parts(\"Switch\", { Root, Thumb })\n"],"mappings":";;;;;;;AAcA,MAAM,UAAU,cAAiC,IAAI;AAErD,SAAS,UAAU,MAA0B;CAC3C,MAAM,aAAa,WAAW,OAAO;CACrC,IAAI,CAAC,YAAY,MAAM,IAAI,MAAM,WAAW,KAAK,+BAA+B;CAChF,OAAO;AACT;AAWA,SAAS,KAAK,EACZ,SACA,gBACA,iBACA,UACA,UACA,UACA,MACA,MACA,OACA,IACA,GAAG,QACuB;CAC1B,MAAM,QAAQ,WAAW,YAAY,KAAK,KAAA;CAC1C,MAAM,SAAS,OAAO,cAAc,EAAE,MAAM,CAAC;CAC7C,MAAM,aAAa,cAAc,QAAQ;EACvC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;CACD,OACE,oBAAC,QAAQ,UAAT;EAAkB,OAAO;EACvB,UAAA,oBAAC,aAAD;GAAa,IAAI,WAAW;GAAM,KAAI;GAAO,MAAM;GAAW,GAAI;EAAO,CAAA;CACzD,CAAA;AAEtB;AAGA,MAAM,aAAa,YACjB,qBAAA,YAAA,EAAA,UAAA,CACG,SACD,oBAAC,OAAD,CAAQ,CAAA,CACR,EAAA,CAAA;AAGJ,MAAM,cAAc,QAAQ,UAAU,MAAM,CAAC,CAAC,OAAO,SAAS,CAAC,CAAC;AAIhE,MAAM,SAAS,UAAsB,QAAQ,UAAU,OAAO,CAAC,CAAC,OAAO,QAAQ,KAAK;AAEpF,MAAa,SAAyB,sBAAM,UAAU;CAAE;CAAM;AAAM,CAAC"}
|
package/src/tabs.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PartComponentProps } from "./runtime.js";
|
|
2
|
-
import { StateOf } from "@kirana-ui/core";
|
|
3
2
|
import { ReactElement } from "react";
|
|
3
|
+
import { StateOf } from "@kirana-ui/core";
|
|
4
4
|
import { TabsListOptions, TabsProps } from "@kirana-ui/core/tabs";
|
|
5
5
|
import { Vocabulary } from "@kirana-ui/core/vocabulary";
|
|
6
6
|
type Parts = Vocabulary["tabs"];
|
|
@@ -10,7 +10,7 @@ export type RootProps<Value = unknown> = PartComponentProps<"div", StateOf<Parts
|
|
|
10
10
|
}>;
|
|
11
11
|
declare function Root<Value = unknown>({ value, defaultValue, onValueChange, orientation, id, ...rest }: RootProps<Value>): ReactElement;
|
|
12
12
|
export type ListProps = PartComponentProps<"div", StateOf<Parts["list"]>, TabsListOptions>;
|
|
13
|
-
declare function List({ activateOnFocus, loop, ...props }: ListProps): ReactElement;
|
|
13
|
+
declare function List({ activateOnFocus, loop, loopFocus, ...props }: ListProps): ReactElement;
|
|
14
14
|
export type TabProps = PartComponentProps<"button", StateOf<Parts["tab"]>, {
|
|
15
15
|
/** What the tabs' value is while this tab is the active one. */
|
|
16
16
|
value: unknown;
|
package/src/tabs.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DirectionContext } from "./direction-context.js";
|
|
2
2
|
import { PartElement, parts, useController, useMount, useOptions, usePart, useSignal } from "./runtime.js";
|
|
3
|
-
import { defined, within } from "@kirana-ui/core";
|
|
4
3
|
import { createContext, useContext, useMemo } from "react";
|
|
4
|
+
import { defined, within } from "@kirana-ui/core";
|
|
5
5
|
import { jsx } from "react/jsx-runtime";
|
|
6
6
|
import { createTabs } from "@kirana-ui/core/tabs";
|
|
7
7
|
// src/tabs.tsx
|
|
@@ -30,11 +30,12 @@ function Root({ value, defaultValue, onValueChange, orientation, id, ...rest })
|
|
|
30
30
|
})
|
|
31
31
|
});
|
|
32
32
|
}
|
|
33
|
-
function List({ activateOnFocus, loop, ...props }) {
|
|
33
|
+
function List({ activateOnFocus, loop, loopFocus, ...props }) {
|
|
34
34
|
const controller = useTabs("List");
|
|
35
35
|
controller.listOptions.set(defined({
|
|
36
36
|
activateOnFocus,
|
|
37
|
-
loop
|
|
37
|
+
loop,
|
|
38
|
+
loopFocus
|
|
38
39
|
}));
|
|
39
40
|
return usePart(controller.list, "div", props);
|
|
40
41
|
}
|
package/src/tabs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tabs.js","names":[],"sources":["../../../../packages/react/src/tabs.tsx"],"sourcesContent":["import { defined, within } from \"@kirana-ui/core\"\nimport type { StateOf } from \"@kirana-ui/core\"\nimport { createTabs } from \"@kirana-ui/core/tabs\"\nimport type { Tabs as Controller, TabsListOptions, TabsProps } from \"@kirana-ui/core/tabs\"\nimport type { Vocabulary } from \"@kirana-ui/core/vocabulary\"\nimport { createContext, useContext, useMemo } from \"react\"\nimport type { ReactElement } from \"react\"\n\nimport { DirectionContext } from \"./direction-context.ts\"\nimport {\n PartElement,\n parts,\n useController,\n useMount,\n useOptions,\n usePart,\n useSignal,\n} from \"./runtime.tsx\"\nimport type { PartComponentProps } from \"./runtime.tsx\"\n\ntype Parts = Vocabulary[\"tabs\"]\n\nconst Context = createContext<Controller | null>(null)\n\nfunction useTabs(part: string): Controller {\n const controller = useContext(Context)\n if (!controller) throw new Error(`<Tabs.${part}> must be inside <Tabs.Root>`)\n return controller\n}\n\n/** `Value` is what tells a tab from the others: the type of `value`. */\nexport type RootProps<Value = unknown> = PartComponentProps<\n \"div\",\n StateOf<Parts[\"root\"]>,\n Omit<TabsProps<Value>, \"id\"> & { id?: string }\n>\n\nfunction Root<Value = unknown>({\n value,\n defaultValue,\n onValueChange,\n orientation,\n id,\n ...rest\n}: RootProps<Value>): ReactElement {\n const direction = useContext(DirectionContext) ?? undefined\n const create = within(createTabs<Value>, { direction })\n const controller: Controller = useController(create, {\n value,\n defaultValue,\n onValueChange,\n orientation,\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 ListProps = PartComponentProps<\"div\", StateOf<Parts[\"list\"]>, TabsListOptions>\n\nfunction List({ activateOnFocus, loop, ...props }: ListProps): ReactElement {\n const controller = useTabs(\"List\")\n // Read when a key is pressed, so written while rendering: nothing re-renders for it.\n controller.listOptions.set(defined({ activateOnFocus, loop }))\n return usePart(controller.list, \"div\", props)\n}\n\nexport type TabProps = PartComponentProps<\n \"button\",\n StateOf<Parts[\"tab\"]>,\n {\n /** What the tabs' value is while this tab is the active one. */\n value: unknown\n /** Disables this tab: it cannot be chosen. */\n disabled?: boolean\n }\n>\n\nfunction Tab({ value, disabled, ...props }: TabProps): ReactElement {\n const controller = useTabs(\"Tab\")\n const options = useOptions({ disabled })\n const part = useMemo(\n () => controller.tab(value, () => defined(options.get())),\n [controller, value, options]\n )\n return usePart(part, \"button\", props)\n}\n\nexport type IndicatorProps = PartComponentProps<\"span\", StateOf<Parts[\"indicator\"]>>\n\nconst Indicator = (props: IndicatorProps) => usePart(useTabs(\"Indicator\").indicator, \"span\", props)\n\nexport type PanelProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"panel\"]>,\n {\n /** The value of the tab this is the panel of. */\n value: unknown\n /** Keeps the panel in the page, `hidden`, while its tab is not the active one. */\n keepMounted?: boolean\n }\n>\n\nfunction Panel({ value, keepMounted, ...props }: PanelProps): ReactElement | null {\n const controller = useTabs(\"Panel\")\n const panel = useMemo(() => controller.panel(value), [controller, value])\n useMount(panel)\n const mounted = useSignal(panel.mounted)\n if (!mounted && !keepMounted) return null\n return <PartElement of={panel.part} tag=\"div\" {...props} />\n}\n\nexport const Tabs = /* @__PURE__ */ parts(\"Tabs\", { Root, List, Tab, Indicator, Panel })\n"],"mappings":";;;;;;;AAsBA,MAAM,UAAU,cAAiC,IAAI;AAErD,SAAS,QAAQ,MAA0B;CACzC,MAAM,aAAa,WAAW,OAAO;CACrC,IAAI,CAAC,YAAY,MAAM,IAAI,MAAM,SAAS,KAAK,6BAA6B;CAC5E,OAAO;AACT;AASA,SAAS,KAAsB,EAC7B,OACA,cACA,eACA,aACA,IACA,GAAG,QAC8B;CACjC,MAAM,YAAY,WAAW,gBAAgB,KAAK,KAAA;CAClD,MAAM,SAAS,OAAO,YAAmB,EAAE,UAAU,CAAC;CACtD,MAAM,aAAyB,cAAc,QAAQ;EACnD;EACA;EACA;EACA;EACA;CACF,CAAC;CACD,OACE,oBAAC,QAAQ,UAAT;EAAkB,OAAO;EACvB,UAAA,oBAAC,aAAD;GAAa,IAAI,WAAW;GAAM,KAAI;GAAM,GAAI;EAAO,CAAA;CACvC,CAAA;AAEtB;AAIA,SAAS,KAAK,EAAE,iBAAiB,MAAM,GAAG,SAAkC;
|
|
1
|
+
{"version":3,"file":"tabs.js","names":[],"sources":["../../../../packages/react/src/tabs.tsx"],"sourcesContent":["import { defined, within } from \"@kirana-ui/core\"\nimport type { StateOf } from \"@kirana-ui/core\"\nimport { createTabs } from \"@kirana-ui/core/tabs\"\nimport type { Tabs as Controller, TabsListOptions, TabsProps } from \"@kirana-ui/core/tabs\"\nimport type { Vocabulary } from \"@kirana-ui/core/vocabulary\"\nimport { createContext, useContext, useMemo } from \"react\"\nimport type { ReactElement } from \"react\"\n\nimport { DirectionContext } from \"./direction-context.ts\"\nimport {\n PartElement,\n parts,\n useController,\n useMount,\n useOptions,\n usePart,\n useSignal,\n} from \"./runtime.tsx\"\nimport type { PartComponentProps } from \"./runtime.tsx\"\n\ntype Parts = Vocabulary[\"tabs\"]\n\nconst Context = createContext<Controller | null>(null)\n\nfunction useTabs(part: string): Controller {\n const controller = useContext(Context)\n if (!controller) throw new Error(`<Tabs.${part}> must be inside <Tabs.Root>`)\n return controller\n}\n\n/** `Value` is what tells a tab from the others: the type of `value`. */\nexport type RootProps<Value = unknown> = PartComponentProps<\n \"div\",\n StateOf<Parts[\"root\"]>,\n Omit<TabsProps<Value>, \"id\"> & { id?: string }\n>\n\nfunction Root<Value = unknown>({\n value,\n defaultValue,\n onValueChange,\n orientation,\n id,\n ...rest\n}: RootProps<Value>): ReactElement {\n const direction = useContext(DirectionContext) ?? undefined\n const create = within(createTabs<Value>, { direction })\n const controller: Controller = useController(create, {\n value,\n defaultValue,\n onValueChange,\n orientation,\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 ListProps = PartComponentProps<\"div\", StateOf<Parts[\"list\"]>, TabsListOptions>\n\nfunction List({ activateOnFocus, loop, loopFocus, ...props }: ListProps): ReactElement {\n const controller = useTabs(\"List\")\n // Read when a key is pressed, so written while rendering: nothing re-renders for it.\n controller.listOptions.set(defined({ activateOnFocus, loop, loopFocus }))\n return usePart(controller.list, \"div\", props)\n}\n\nexport type TabProps = PartComponentProps<\n \"button\",\n StateOf<Parts[\"tab\"]>,\n {\n /** What the tabs' value is while this tab is the active one. */\n value: unknown\n /** Disables this tab: it cannot be chosen. */\n disabled?: boolean\n }\n>\n\nfunction Tab({ value, disabled, ...props }: TabProps): ReactElement {\n const controller = useTabs(\"Tab\")\n const options = useOptions({ disabled })\n const part = useMemo(\n () => controller.tab(value, () => defined(options.get())),\n [controller, value, options]\n )\n return usePart(part, \"button\", props)\n}\n\nexport type IndicatorProps = PartComponentProps<\"span\", StateOf<Parts[\"indicator\"]>>\n\nconst Indicator = (props: IndicatorProps) => usePart(useTabs(\"Indicator\").indicator, \"span\", props)\n\nexport type PanelProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"panel\"]>,\n {\n /** The value of the tab this is the panel of. */\n value: unknown\n /** Keeps the panel in the page, `hidden`, while its tab is not the active one. */\n keepMounted?: boolean\n }\n>\n\nfunction Panel({ value, keepMounted, ...props }: PanelProps): ReactElement | null {\n const controller = useTabs(\"Panel\")\n const panel = useMemo(() => controller.panel(value), [controller, value])\n useMount(panel)\n const mounted = useSignal(panel.mounted)\n if (!mounted && !keepMounted) return null\n return <PartElement of={panel.part} tag=\"div\" {...props} />\n}\n\nexport const Tabs = /* @__PURE__ */ parts(\"Tabs\", { Root, List, Tab, Indicator, Panel })\n"],"mappings":";;;;;;;AAsBA,MAAM,UAAU,cAAiC,IAAI;AAErD,SAAS,QAAQ,MAA0B;CACzC,MAAM,aAAa,WAAW,OAAO;CACrC,IAAI,CAAC,YAAY,MAAM,IAAI,MAAM,SAAS,KAAK,6BAA6B;CAC5E,OAAO;AACT;AASA,SAAS,KAAsB,EAC7B,OACA,cACA,eACA,aACA,IACA,GAAG,QAC8B;CACjC,MAAM,YAAY,WAAW,gBAAgB,KAAK,KAAA;CAClD,MAAM,SAAS,OAAO,YAAmB,EAAE,UAAU,CAAC;CACtD,MAAM,aAAyB,cAAc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actNode } from "react";
|
|
3
|
+
import { StateOf } from "@kirana-ui/core";
|
|
4
|
+
import { TagsInputEntry, TagsInputProps } from "@kirana-ui/core/tags-input";
|
|
5
|
+
import { Vocabulary } from "@kirana-ui/core/vocabulary";
|
|
6
|
+
type Parts = Vocabulary["tagsInput"];
|
|
7
|
+
export type RootProps = PartComponentProps<"div", StateOf<Parts["root"]>, Omit<TagsInputProps, "id"> & {
|
|
8
|
+
id?: string;
|
|
9
|
+
}>;
|
|
10
|
+
declare function Root({ value, defaultValue, onValueChange, onValueInvalid, validate, max, allowDuplicates, delimiter, addOnBlur, addOnPaste, editable, disabled, readOnly, required, name, form, id, ...rest }: RootProps): ReactElement;
|
|
11
|
+
export type ListProps = PartComponentProps<"div", StateOf<Parts["list"]>>;
|
|
12
|
+
declare const List: (props: ListProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
13
|
+
export interface ItemsProps {
|
|
14
|
+
/** Draws one tag, once for each. */
|
|
15
|
+
children: (entry: TagsInputEntry) => ReactNode;
|
|
16
|
+
}
|
|
17
|
+
/** Draws its child once for each tag, kept by the tag's key. */
|
|
18
|
+
declare function Items({ children }: ItemsProps): ReactElement;
|
|
19
|
+
export type ItemProps = PartComponentProps<"span", StateOf<Parts["item"]>, {
|
|
20
|
+
/** The tag it is, as `Items` gave it. */
|
|
21
|
+
entry: TagsInputEntry;
|
|
22
|
+
}>;
|
|
23
|
+
declare function Item({ entry, ...props }: ItemProps): ReactElement;
|
|
24
|
+
export type ItemTextProps = PartComponentProps<"span", StateOf<Parts["itemText"]>>;
|
|
25
|
+
/** Says the tag's text unless it is given children. */
|
|
26
|
+
declare function ItemText(props: ItemTextProps): ReactElement;
|
|
27
|
+
export type ItemInputProps = PartComponentProps<"input", StateOf<Parts["itemInput"]>>;
|
|
28
|
+
declare const ItemInput: (props: ItemInputProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
29
|
+
export type ItemRemoveProps = PartComponentProps<"button", StateOf<Parts["itemRemove"]>>;
|
|
30
|
+
declare const ItemRemove: (props: ItemRemoveProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
31
|
+
export type InputProps = PartComponentProps<"input", StateOf<Parts["input"]>>;
|
|
32
|
+
declare const Input: (props: InputProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
33
|
+
export type ClearProps = PartComponentProps<"button", StateOf<Parts["clear"]>>;
|
|
34
|
+
declare const Clear: (props: ClearProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
35
|
+
export declare const TagsInput: {
|
|
36
|
+
readonly Root: typeof Root;
|
|
37
|
+
readonly List: typeof List;
|
|
38
|
+
readonly Items: typeof Items;
|
|
39
|
+
readonly Item: typeof Item;
|
|
40
|
+
readonly ItemText: typeof ItemText;
|
|
41
|
+
readonly ItemInput: typeof ItemInput;
|
|
42
|
+
readonly ItemRemove: typeof ItemRemove;
|
|
43
|
+
readonly Input: typeof Input;
|
|
44
|
+
readonly Clear: typeof Clear;
|
|
45
|
+
};
|
|
46
|
+
export {};
|
|
47
|
+
//# sourceMappingURL=tags-input.d.ts.map
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { DirectionContext } from "./direction-context.js";
|
|
2
|
+
import { FieldContext } from "./field-context.js";
|
|
3
|
+
import { PartElement, parts, useController, usePart, useSignal } from "./runtime.js";
|
|
4
|
+
import { Fragment, createContext, useContext } from "react";
|
|
5
|
+
import { within } from "@kirana-ui/core";
|
|
6
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
import { createTagsInput } from "@kirana-ui/core/tags-input";
|
|
8
|
+
// src/tags-input.tsx
|
|
9
|
+
const Context = createContext(null);
|
|
10
|
+
const ItemContext = createContext(null);
|
|
11
|
+
function useTagsInput(part) {
|
|
12
|
+
const controller = useContext(Context);
|
|
13
|
+
if (!controller) throw new Error(`<TagsInput.${part}> must be inside <TagsInput.Root>`);
|
|
14
|
+
return controller;
|
|
15
|
+
}
|
|
16
|
+
function useEntry(part) {
|
|
17
|
+
const entry = useContext(ItemContext);
|
|
18
|
+
if (!entry) throw new Error(`<TagsInput.${part}> must be inside <TagsInput.Item>`);
|
|
19
|
+
return entry;
|
|
20
|
+
}
|
|
21
|
+
function Root({ value, defaultValue, onValueChange, onValueInvalid, validate, max, allowDuplicates, delimiter, addOnBlur, addOnPaste, editable, disabled, readOnly, required, name, form, id, ...rest }) {
|
|
22
|
+
const field = useContext(FieldContext) ?? void 0;
|
|
23
|
+
const direction = useContext(DirectionContext) ?? void 0;
|
|
24
|
+
const create = within(createTagsInput, {
|
|
25
|
+
field,
|
|
26
|
+
direction
|
|
27
|
+
});
|
|
28
|
+
const controller = useController(create, {
|
|
29
|
+
value,
|
|
30
|
+
defaultValue,
|
|
31
|
+
onValueChange,
|
|
32
|
+
onValueInvalid,
|
|
33
|
+
validate,
|
|
34
|
+
max,
|
|
35
|
+
allowDuplicates,
|
|
36
|
+
delimiter,
|
|
37
|
+
addOnBlur,
|
|
38
|
+
addOnPaste,
|
|
39
|
+
editable,
|
|
40
|
+
disabled,
|
|
41
|
+
readOnly,
|
|
42
|
+
required,
|
|
43
|
+
name,
|
|
44
|
+
form,
|
|
45
|
+
id
|
|
46
|
+
});
|
|
47
|
+
return /* @__PURE__ */ jsx(Context.Provider, {
|
|
48
|
+
value: controller,
|
|
49
|
+
children: usePart(controller.root, "div", rest, void 0, (content) => /* @__PURE__ */ jsxs(Fragment$1, { children: [content, /* @__PURE__ */ jsx(PartElement, {
|
|
50
|
+
of: controller.hiddenInput,
|
|
51
|
+
tag: "input"
|
|
52
|
+
})] }))
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
const List = (props) => usePart(useTagsInput("List").list, "div", props);
|
|
56
|
+
/** Draws its child once for each tag, kept by the tag's key. */
|
|
57
|
+
function Items({ children }) {
|
|
58
|
+
const entries = useSignal(useTagsInput("Items").entries);
|
|
59
|
+
return /* @__PURE__ */ jsx(Fragment$1, { children: entries.map((entry) => /* @__PURE__ */ jsx(Fragment, { children: children(entry) }, entry.key)) });
|
|
60
|
+
}
|
|
61
|
+
function Item({ entry, ...props }) {
|
|
62
|
+
return /* @__PURE__ */ jsx(ItemContext.Provider, {
|
|
63
|
+
value: entry,
|
|
64
|
+
children: usePart(useTagsInput("Item").item(entry.key), "span", props)
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
/** Says the tag's text unless it is given children. */
|
|
68
|
+
function ItemText(props) {
|
|
69
|
+
const entry = useEntry("ItemText");
|
|
70
|
+
return usePart(useTagsInput("ItemText").itemText(entry.key), "span", {
|
|
71
|
+
...props,
|
|
72
|
+
children: props.children ?? entry.value
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
const ItemInput = (props) => usePart(useTagsInput("ItemInput").itemInput(useEntry("ItemInput").key), "input", props);
|
|
76
|
+
const ItemRemove = (props) => usePart(useTagsInput("ItemRemove").itemRemove(useEntry("ItemRemove").key), "button", props);
|
|
77
|
+
const Input = (props) => usePart(useTagsInput("Input").input, "input", props);
|
|
78
|
+
const Clear = (props) => usePart(useTagsInput("Clear").clear, "button", props);
|
|
79
|
+
const TagsInput = /* @__PURE__ */ parts("TagsInput", {
|
|
80
|
+
Root,
|
|
81
|
+
List,
|
|
82
|
+
Items,
|
|
83
|
+
Item,
|
|
84
|
+
ItemText,
|
|
85
|
+
ItemInput,
|
|
86
|
+
ItemRemove,
|
|
87
|
+
Input,
|
|
88
|
+
Clear
|
|
89
|
+
});
|
|
90
|
+
export { TagsInput };
|
|
91
|
+
|
|
92
|
+
//# sourceMappingURL=tags-input.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tags-input.js","names":[],"sources":["../../../../packages/react/src/tags-input.tsx"],"sourcesContent":["import { within } from \"@kirana-ui/core\"\nimport type { StateOf } from \"@kirana-ui/core\"\nimport { createTagsInput } from \"@kirana-ui/core/tags-input\"\nimport type {\n TagsInput as Controller,\n TagsInputEntry,\n TagsInputProps,\n} from \"@kirana-ui/core/tags-input\"\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 { FieldContext } from \"./field-context.ts\"\nimport { PartElement, parts, useController, usePart, useSignal } from \"./runtime.tsx\"\nimport type { PartComponentProps } from \"./runtime.tsx\"\n\ntype Parts = Vocabulary[\"tagsInput\"]\n\nconst Context = createContext<Controller | null>(null)\n// The tag an item is, for the parts inside it.\nconst ItemContext = createContext<TagsInputEntry | null>(null)\n\nfunction useTagsInput(part: string): Controller {\n const controller = useContext(Context)\n if (!controller) throw new Error(`<TagsInput.${part}> must be inside <TagsInput.Root>`)\n return controller\n}\n\nfunction useEntry(part: string): TagsInputEntry {\n const entry = useContext(ItemContext)\n if (!entry) throw new Error(`<TagsInput.${part}> must be inside <TagsInput.Item>`)\n return entry\n}\n\nexport type RootProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"root\"]>,\n Omit<TagsInputProps, \"id\"> & { id?: string }\n>\n\nfunction Root({\n value,\n defaultValue,\n onValueChange,\n onValueInvalid,\n validate,\n max,\n allowDuplicates,\n delimiter,\n addOnBlur,\n addOnPaste,\n editable,\n disabled,\n readOnly,\n required,\n name,\n form,\n id,\n ...rest\n}: RootProps): ReactElement {\n const field = useContext(FieldContext) ?? undefined\n const direction = useContext(DirectionContext) ?? undefined\n const create = within(createTagsInput, { field, direction })\n const controller: Controller = useController(create, {\n value,\n defaultValue,\n onValueChange,\n onValueInvalid,\n validate,\n max,\n allowDuplicates,\n delimiter,\n addOnBlur,\n addOnPaste,\n editable,\n disabled,\n readOnly,\n required,\n name,\n form,\n id,\n })\n return (\n <Context.Provider value={controller}>\n {usePart(controller.root, \"div\", rest, undefined, (content) => (\n // The first of the inputs a form reads is the element's last child; the rest follow it.\n <>\n {content}\n <PartElement of={controller.hiddenInput} tag=\"input\" />\n </>\n ))}\n </Context.Provider>\n )\n}\n\nexport type ListProps = PartComponentProps<\"div\", StateOf<Parts[\"list\"]>>\n\nconst List = (props: ListProps) => usePart(useTagsInput(\"List\").list, \"div\", props)\n\nexport interface ItemsProps {\n /** Draws one tag, once for each. */\n children: (entry: TagsInputEntry) => ReactNode\n}\n\n/** Draws its child once for each tag, kept by the tag's key. */\nfunction Items({ children }: ItemsProps): ReactElement {\n const entries = useSignal(useTagsInput(\"Items\").entries)\n return (\n <>\n {entries.map((entry) => (\n <Fragment key={entry.key}>{children(entry)}</Fragment>\n ))}\n </>\n )\n}\n\nexport type ItemProps = PartComponentProps<\n \"span\",\n StateOf<Parts[\"item\"]>,\n {\n /** The tag it is, as `Items` gave it. */\n entry: TagsInputEntry\n }\n>\n\nfunction Item({ entry, ...props }: ItemProps): ReactElement {\n return (\n <ItemContext.Provider value={entry}>\n {usePart(useTagsInput(\"Item\").item(entry.key), \"span\", props)}\n </ItemContext.Provider>\n )\n}\n\nexport type ItemTextProps = PartComponentProps<\"span\", StateOf<Parts[\"itemText\"]>>\n\n/** Says the tag's text unless it is given children. */\nfunction ItemText(props: ItemTextProps): ReactElement {\n const entry = useEntry(\"ItemText\")\n return usePart(useTagsInput(\"ItemText\").itemText(entry.key), \"span\", {\n ...props,\n children: props.children ?? entry.value,\n })\n}\n\nexport type ItemInputProps = PartComponentProps<\"input\", StateOf<Parts[\"itemInput\"]>>\n\nconst ItemInput = (props: ItemInputProps) =>\n usePart(useTagsInput(\"ItemInput\").itemInput(useEntry(\"ItemInput\").key), \"input\", props)\n\nexport type ItemRemoveProps = PartComponentProps<\"button\", StateOf<Parts[\"itemRemove\"]>>\n\nconst ItemRemove = (props: ItemRemoveProps) =>\n usePart(useTagsInput(\"ItemRemove\").itemRemove(useEntry(\"ItemRemove\").key), \"button\", props)\n\nexport type InputProps = PartComponentProps<\"input\", StateOf<Parts[\"input\"]>>\n\nconst Input = (props: InputProps) => usePart(useTagsInput(\"Input\").input, \"input\", props)\n\nexport type ClearProps = PartComponentProps<\"button\", StateOf<Parts[\"clear\"]>>\n\nconst Clear = (props: ClearProps) => usePart(useTagsInput(\"Clear\").clear, \"button\", props)\n\nexport const TagsInput = /* @__PURE__ */ parts(\"TagsInput\", {\n Root,\n List,\n Items,\n Item,\n ItemText,\n ItemInput,\n ItemRemove,\n Input,\n Clear,\n})\n"],"mappings":";;;;;;;;AAmBA,MAAM,UAAU,cAAiC,IAAI;AAErD,MAAM,cAAc,cAAqC,IAAI;AAE7D,SAAS,aAAa,MAA0B;CAC9C,MAAM,aAAa,WAAW,OAAO;CACrC,IAAI,CAAC,YAAY,MAAM,IAAI,MAAM,cAAc,KAAK,kCAAkC;CACtF,OAAO;AACT;AAEA,SAAS,SAAS,MAA8B;CAC9C,MAAM,QAAQ,WAAW,WAAW;CACpC,IAAI,CAAC,OAAO,MAAM,IAAI,MAAM,cAAc,KAAK,kCAAkC;CACjF,OAAO;AACT;AAQA,SAAS,KAAK,EACZ,OACA,cACA,eACA,gBACA,UACA,KACA,iBACA,WACA,WACA,YACA,UACA,UACA,UACA,UACA,MACA,MACA,IACA,GAAG,QACuB;CAC1B,MAAM,QAAQ,WAAW,YAAY,KAAK,KAAA;CAC1C,MAAM,YAAY,WAAW,gBAAgB,KAAK,KAAA;CAClD,MAAM,SAAS,OAAO,iBAAiB;EAAE;EAAO;CAAU,CAAC;CAC3D,MAAM,aAAyB,cAAc,QAAQ;EACnD;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;CACD,OACE,oBAAC,QAAQ,UAAT;EAAkB,OAAO;EACtB,UAAA,QAAQ,WAAW,MAAM,OAAO,MAAM,KAAA,IAAY,YAEjD,qBAAA,YAAA,EAAA,UAAA,CACG,SACD,oBAAC,aAAD;GAAa,IAAI,WAAW;GAAa,KAAI;EAAS,CAAA,CACtD,EAAA,CAAA,CACH;CACe,CAAA;AAEtB;AAIA,MAAM,QAAQ,UA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