@kirana-ui/react 0.1.1 → 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.
- package/llms.txt +1601 -223
- package/package.json +14 -2
- package/skills/kirana-ui-primitives/SKILL.md +142 -0
- package/src/accordion.d.ts +26 -15
- package/src/accordion.js +11 -10
- package/src/accordion.js.map +1 -1
- package/src/agent.d.ts +1 -0
- package/src/agent.js +1 -0
- package/src/alert-dialog.d.ts +3 -2
- package/src/autocomplete.d.ts +3 -2
- package/src/autosize.d.ts +5 -2
- package/src/autosize.js +2 -2
- package/src/autosize.js.map +1 -1
- package/src/avatar.d.ts +12 -8
- package/src/avatar.js +18 -9
- package/src/avatar.js.map +1 -1
- package/src/button.d.ts +4 -2
- package/src/button.js +3 -3
- package/src/button.js.map +1 -1
- package/src/calendar.d.ts +49 -28
- package/src/calendar.js +7 -3
- package/src/calendar.js.map +1 -1
- package/src/carousel.d.ts +25 -15
- package/src/carousel.js +3 -3
- package/src/carousel.js.map +1 -1
- package/src/checkbox.d.ts +10 -7
- package/src/checkbox.js +18 -12
- package/src/checkbox.js.map +1 -1
- package/src/collapsible.d.ts +12 -8
- package/src/collapsible.js +8 -7
- package/src/collapsible.js.map +1 -1
- package/src/combobox.d.ts +88 -60
- package/src/combobox.js +44 -31
- package/src/combobox.js.map +1 -1
- package/src/command.d.ts +30 -21
- package/src/command.js +14 -7
- package/src/command.js.map +1 -1
- package/src/context-menu.d.ts +3 -2
- package/src/date-field.d.ts +25 -13
- package/src/date-field.js +7 -3
- package/src/date-field.js.map +1 -1
- package/src/date-picker.d.ts +31 -40
- package/src/date-picker.js +3 -3
- package/src/date-picker.js.map +1 -1
- package/src/dialog.d.ts +45 -35
- package/src/dialog.js +12 -8
- package/src/dialog.js.map +1 -1
- package/src/direction.d.ts +1 -0
- package/src/direction.js.map +1 -1
- package/src/drawer.d.ts +3 -2
- package/src/element.d.ts +12 -0
- package/src/element.js +20 -0
- package/src/element.js.map +1 -0
- package/src/field.d.ts +24 -16
- package/src/field.js +9 -7
- package/src/field.js.map +1 -1
- package/src/fieldset.d.ts +10 -5
- package/src/fieldset.js +4 -5
- package/src/fieldset.js.map +1 -1
- package/src/form.d.ts +5 -2
- package/src/form.js +6 -6
- package/src/form.js.map +1 -1
- package/src/hover-card.d.ts +16 -10
- package/src/hover-card.js +1 -1
- package/src/hover-card.js.map +1 -1
- package/src/hover-popup.d.ts +24 -14
- package/src/hover-popup.js +5 -13
- package/src/hover-popup.js.map +1 -1
- package/src/index.d.ts +13 -3
- package/src/input.d.ts +4 -2
- package/src/input.js +3 -3
- package/src/input.js.map +1 -1
- package/src/label.d.ts +4 -1
- package/src/label.js +3 -3
- package/src/label.js.map +1 -1
- package/src/listbox.d.ts +23 -15
- package/src/listbox.js +4 -5
- package/src/listbox.js.map +1 -1
- package/src/menu.d.ts +83 -65
- package/src/menu.js +10 -18
- package/src/menu.js.map +1 -1
- package/src/menubar.d.ts +5 -3
- package/src/menubar.js +3 -3
- package/src/menubar.js.map +1 -1
- package/src/message-scroller.d.ts +15 -9
- package/src/message-scroller.js +3 -3
- package/src/message-scroller.js.map +1 -1
- package/src/meter.d.ts +18 -9
- package/src/meter.js +1 -1
- package/src/meter.js.map +1 -1
- package/src/navigation-menu.d.ts +50 -40
- package/src/navigation-menu.js +15 -24
- package/src/navigation-menu.js.map +1 -1
- package/src/number-field.d.ts +19 -12
- package/src/number-field.js +6 -10
- package/src/number-field.js.map +1 -1
- package/src/otp.d.ts +24 -15
- package/src/otp.js +7 -13
- package/src/otp.js.map +1 -1
- package/src/pagination.d.ts +26 -16
- package/src/pagination.js +3 -3
- package/src/pagination.js.map +1 -1
- package/src/popover.d.ts +30 -21
- package/src/popover.js +9 -13
- package/src/popover.js.map +1 -1
- package/src/progress.d.ts +18 -9
- package/src/progress.js +1 -1
- package/src/progress.js.map +1 -1
- package/src/qr-code.d.ts +12 -7
- package/src/qr-code.js +3 -3
- package/src/qr-code.js.map +1 -1
- package/src/radio-group.d.ts +17 -11
- package/src/radio-group.js +16 -19
- package/src/radio-group.js.map +1 -1
- package/src/resizable.d.ts +13 -8
- package/src/resizable.js +3 -3
- package/src/resizable.js.map +1 -1
- package/src/runtime.d.ts +89 -15
- package/src/runtime.js +112 -19
- package/src/runtime.js.map +1 -1
- package/src/scroll-area.d.ts +26 -15
- package/src/scroll-area.js +9 -6
- package/src/scroll-area.js.map +1 -1
- package/src/select.d.ts +65 -45
- package/src/select.js +40 -35
- package/src/select.js.map +1 -1
- package/src/separator.d.ts +4 -2
- package/src/separator.js +3 -3
- package/src/separator.js.map +1 -1
- package/src/slider.d.ts +35 -20
- package/src/slider.js +17 -18
- package/src/slider.js.map +1 -1
- package/src/switch.d.ts +10 -6
- package/src/switch.js +11 -9
- package/src/switch.js.map +1 -1
- package/src/tabs.d.ts +22 -14
- package/src/tabs.js +5 -6
- package/src/tabs.js.map +1 -1
- package/src/testing.d.ts +1 -0
- package/src/testing.js +1 -0
- package/src/toast.d.ts +59 -23
- package/src/toast.js +59 -13
- package/src/toast.js.map +1 -1
- package/src/toggle-group.d.ts +5 -2
- package/src/toggle-group.js +3 -3
- package/src/toggle-group.js.map +1 -1
- package/src/toggle.d.ts +4 -2
- package/src/toggle.js +3 -3
- package/src/toggle.js.map +1 -1
- package/src/toolbar.d.ts +26 -11
- package/src/toolbar.js +23 -13
- package/src/toolbar.js.map +1 -1
- package/src/tooltip.d.ts +16 -10
- package/src/tooltip.js +1 -1
- package/src/tooltip.js.map +1 -1
- package/src/use-render.d.ts +38 -0
- package/src/use-render.js +50 -0
- package/src/use-render.js.map +1 -0
- package/src/value-bar.d.ts +19 -11
- package/src/value-bar.js +8 -5
- package/src/value-bar.js.map +1 -1
package/src/select.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FieldContext } from "./field-context.js";
|
|
2
|
-
import { Portal as Portal$1, useController, useMount, useOptions, usePart, useSignal } from "./runtime.js";
|
|
2
|
+
import { PartElement, Portal as Portal$1, parts, useController, useMount, useOptions, usePart, usePositioning, useSignal } from "./runtime.js";
|
|
3
3
|
import { defined, within } from "@kirana-ui/core";
|
|
4
4
|
import { createContext, useContext, useId, useMemo } from "react";
|
|
5
5
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -25,26 +25,24 @@ const HiddenInput = () => usePart(useSelect("Root").input, "input", {});
|
|
|
25
25
|
const Trigger = (props) => usePart(useSelect("Trigger").trigger, "button", props);
|
|
26
26
|
function Value({ placeholder, children, ...props }) {
|
|
27
27
|
const controller = useSelect("Value");
|
|
28
|
-
const
|
|
28
|
+
const shown = useSignal(controller.shown);
|
|
29
|
+
let drawn;
|
|
30
|
+
if (typeof children === "function") {
|
|
31
|
+
const draw = children;
|
|
32
|
+
drawn = controller.multiple ? draw(shown.values, shown.labels) : draw(shown.value, shown.label);
|
|
33
|
+
} else drawn = children ?? shown.label ?? placeholder;
|
|
29
34
|
return usePart(controller.valuePart, "span", {
|
|
30
35
|
...props,
|
|
31
|
-
children:
|
|
36
|
+
children: drawn
|
|
32
37
|
});
|
|
33
38
|
}
|
|
34
39
|
function Portal({ children }) {
|
|
35
40
|
return useSignal(useSelect("Portal").mounted) ? /* @__PURE__ */ jsx(Portal$1, { children }) : null;
|
|
36
41
|
}
|
|
37
|
-
function Positioner({
|
|
42
|
+
function Positioner({ alignItemWithTrigger, ...props }) {
|
|
38
43
|
const controller = useSelect("Positioner");
|
|
39
44
|
controller.alignItemWithTrigger.set(Boolean(alignItemWithTrigger));
|
|
40
|
-
controller.positioning
|
|
41
|
-
side,
|
|
42
|
-
align,
|
|
43
|
-
sideOffset,
|
|
44
|
-
alignOffset,
|
|
45
|
-
collisionPadding
|
|
46
|
-
}));
|
|
47
|
-
return usePart(controller.positioner, "div", props);
|
|
45
|
+
return usePart(controller.positioner, "div", usePositioning(controller.positioning, props));
|
|
48
46
|
}
|
|
49
47
|
const Popup = (props) => usePart(useSelect("Popup").popup, "div", props);
|
|
50
48
|
const GroupContext = createContext(null);
|
|
@@ -71,31 +69,33 @@ function GroupLabel(props) {
|
|
|
71
69
|
const Separator = (props) => usePart(useSelect("Separator").separator, "div", props);
|
|
72
70
|
/** The items' own box inside the popup, when the popup also holds scroll arrows. */
|
|
73
71
|
const List = (props) => usePart(useSelect("List").list, "div", props);
|
|
74
|
-
|
|
72
|
+
/** The arrow at one end of the list, and whether it is in the page: while there is more that way. */
|
|
73
|
+
function useScrollArrow(name, direction) {
|
|
74
|
+
const controller = useSelect(name);
|
|
75
|
+
const arrow = useMemo(() => controller.scrollArrow(direction), [controller, direction]);
|
|
75
76
|
useMount(arrow);
|
|
76
|
-
return
|
|
77
|
+
return {
|
|
77
78
|
part: arrow.part,
|
|
78
|
-
|
|
79
|
-
}
|
|
79
|
+
mounted: useSignal(arrow.mounted)
|
|
80
|
+
};
|
|
80
81
|
}
|
|
81
|
-
const ArrowPart = ({ part, ...props }) => usePart(part, "div", props);
|
|
82
82
|
/** In the page while there is more of the list above: it scrolls it while the pointer moves over it. */
|
|
83
83
|
function ScrollUpArrow(props) {
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
84
|
+
const { part, mounted } = useScrollArrow("ScrollUpArrow", "up");
|
|
85
|
+
return mounted ? /* @__PURE__ */ jsx(PartElement, {
|
|
86
|
+
of: part,
|
|
87
|
+
tag: "div",
|
|
88
88
|
...props
|
|
89
|
-
});
|
|
89
|
+
}) : null;
|
|
90
90
|
}
|
|
91
91
|
/** In the page while there is more of the list below. */
|
|
92
92
|
function ScrollDownArrow(props) {
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
93
|
+
const { part, mounted } = useScrollArrow("ScrollDownArrow", "down");
|
|
94
|
+
return mounted ? /* @__PURE__ */ jsx(PartElement, {
|
|
95
|
+
of: part,
|
|
96
|
+
tag: "div",
|
|
97
97
|
...props
|
|
98
|
-
});
|
|
98
|
+
}) : null;
|
|
99
99
|
}
|
|
100
100
|
function Item({ value, disabled, label, index, ...props }) {
|
|
101
101
|
const controller = useSelect("Item");
|
|
@@ -120,14 +120,19 @@ function ItemText(props) {
|
|
|
120
120
|
const part = useMemo(() => controller.itemText(value), [controller, value]);
|
|
121
121
|
return usePart(part, "span", props);
|
|
122
122
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
123
|
+
/** In the page while its item is the chosen one. */
|
|
124
|
+
function ItemIndicator({ keepMounted, ...props }) {
|
|
125
|
+
const controller = useSelect("ItemIndicator");
|
|
126
|
+
const value = useContext(ItemContext);
|
|
127
|
+
const selected = useSignal(controller.selected(value));
|
|
128
|
+
const part = useMemo(() => controller.itemIndicator(value), [controller, value]);
|
|
129
|
+
return selected || keepMounted ? /* @__PURE__ */ jsx(PartElement, {
|
|
130
|
+
of: part,
|
|
131
|
+
tag: "span",
|
|
132
|
+
...props
|
|
133
|
+
}) : null;
|
|
129
134
|
}
|
|
130
|
-
const Select = {
|
|
135
|
+
const Select = /* @__PURE__ */ parts("Select", {
|
|
131
136
|
Root,
|
|
132
137
|
Trigger,
|
|
133
138
|
Value,
|
|
@@ -143,7 +148,7 @@ const Select = {
|
|
|
143
148
|
Item,
|
|
144
149
|
ItemText,
|
|
145
150
|
ItemIndicator
|
|
146
|
-
};
|
|
151
|
+
});
|
|
147
152
|
export { Select };
|
|
148
153
|
|
|
149
154
|
//# sourceMappingURL=select.js.map
|
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 { Part, PositionOptions } from \"@kirana-ui/core\"\nimport { createSelect } from \"@kirana-ui/core/select\"\nimport type {\n Select as Controller,\n SelectGroup,\n SelectProps,\n SelectScrollArrow,\n} from \"@kirana-ui/core/select\"\nimport { createContext, useContext, useId, useMemo } from \"react\"\nimport type { ReactElement, ReactNode } from \"react\"\n\nimport { FieldContext } from \"./field-context.ts\"\nimport {\n Portal as BodyPortal,\n useController,\n useMount,\n useOptions,\n usePart,\n useSignal,\n} from \"./runtime.tsx\"\nimport type { PartComponentProps } from \"./runtime.tsx\"\n\nconst Context = createContext<Controller | null>(null)\nconst ItemContext = createContext<unknown>(undefined)\n\nfunction 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\nexport type RootProps<Value> = Omit<SelectProps<Value>, \"id\"> & {\n id?: string\n children?: ReactNode\n}\n\nfunction Root<Value>({ children, ...props }: RootProps<Value>): ReactElement {\n const field = useContext(FieldContext) ?? undefined\n const controller = useController(\n within(createSelect<Value>, { field }),\n props\n ) as unknown as Controller\n const named = useSignal(controller.named)\n return (\n <Context.Provider value={controller}>\n {children}\n {named ? <HiddenInput /> : null}\n </Context.Provider>\n )\n}\n\nconst HiddenInput = () => usePart(useSelect(\"Root\").input, \"input\", {})\n\nconst Trigger = (props: PartComponentProps) =>\n usePart(useSelect(\"Trigger\").trigger, \"button\", props)\n\nexport interface ValueProps extends PartComponentProps {\n /** Shown while nothing is chosen. */\n placeholder?: ReactNode\n}\n\nfunction Value({ placeholder, children, ...props }: ValueProps): ReactElement {\n const controller = useSelect(\"Value\")\n const label = useSignal(controller.label)\n return usePart(controller.valuePart, \"span\", {\n ...props,\n children: children ?? label ?? placeholder,\n })\n}\n\nfunction Portal({ children }: { children?: ReactNode }): ReactElement | null {\n const mounted = useSignal(useSelect(\"Portal\").mounted)\n return mounted ? <BodyPortal>{children}</BodyPortal> : null\n}\n\nexport type PositionerProps = PartComponentProps &\n Partial<PositionOptions> & {\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\nfunction Positioner({\n side,\n align,\n sideOffset,\n alignOffset,\n collisionPadding,\n alignItemWithTrigger,\n ...props\n}: PositionerProps) {\n const controller = useSelect(\"Positioner\")\n controller.alignItemWithTrigger.set(Boolean(alignItemWithTrigger))\n controller.positioning.set(defined({ side, align, sideOffset, alignOffset, collisionPadding }))\n return usePart(controller.positioner, \"div\", props)\n}\n\nconst Popup = (props: PartComponentProps) => usePart(useSelect(\"Popup\").popup, \"div\", props)\nconst GroupContext = createContext<SelectGroup | null>(null)\n\n/** Items that belong together, named by their `<Select.GroupLabel>`. */\nfunction Group({ id, ...props }: PartComponentProps & { id?: string }): 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\n/** A group's name. Outside a group it is plain text, and names nothing. */\nfunction GroupLabel(props: PartComponentProps): ReactElement {\n const lone = useSelect(\"GroupLabel\").groupLabel\n return usePart(useContext(GroupContext)?.label ?? lone, \"div\", props)\n}\n\n/** A line between groups. */\nconst Separator = (props: PartComponentProps) =>\n usePart(useSelect(\"Separator\").separator, \"div\", props)\n\n/** The items' own box inside the popup, when the popup also holds scroll arrows. */\nconst List = (props: PartComponentProps) => usePart(useSelect(\"List\").list, \"div\", props)\n\nfunction ScrollArrowElement({\n arrow,\n ...props\n}: PartComponentProps & { arrow: SelectScrollArrow }): ReactElement | null {\n useMount(arrow)\n const mounted = useSignal(arrow.mounted)\n return mounted ? <ArrowPart part={arrow.part} {...props} /> : null\n}\n\nconst ArrowPart = ({ part, ...props }: PartComponentProps & { part: Part }) =>\n usePart(part, \"div\", props)\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: PartComponentProps): ReactElement {\n const controller = useSelect(\"ScrollUpArrow\")\n const arrow = useMemo(() => controller.scrollArrow(\"up\"), [controller])\n return <ScrollArrowElement arrow={arrow} {...props} />\n}\n\n/** In the page while there is more of the list below. */\nfunction ScrollDownArrow(props: PartComponentProps): ReactElement {\n const controller = useSelect(\"ScrollDownArrow\")\n const arrow = useMemo(() => controller.scrollArrow(\"down\"), [controller])\n return <ScrollArrowElement arrow={arrow} {...props} />\n}\n\nexport interface ItemProps extends PartComponentProps {\n value: unknown\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\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\nfunction ItemText(props: PartComponentProps): 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 interface ItemIndicatorProps extends PartComponentProps {\n keepMounted?: boolean\n}\n\nfunction ItemIndicator({ keepMounted, render: _render, ref: _ref, ...rest }: ItemIndicatorProps) {\n const selected = useSignal(useSelect(\"ItemIndicator\").selected(useContext(ItemContext)))\n if (!selected && !keepMounted) return null\n return <span aria-hidden=\"true\" {...(rest as object)} />\n}\n\nexport const 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":";;;;;;;AAuBA,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;AAOA,SAAS,KAAY,EAAE,UAAU,GAAG,SAAyC;CAC3E,MAAM,QAAQ,WAAW,YAAY,KAAK,KAAA;CAC1C,MAAM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ACL,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;AAEA,SAAS,SAAS,OAAyC;CACzD,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;AAMA,SAAS,cAAc,EAAE,aAAa,QAAQ,SAAS,KAAK,MAAM,GAAG,QAA4B;CAE/F,IAAI,CADa,UAAU,UAAU,eAAe,CAAC,CAAC,SAAS,WAAW,WAAW,CAAC,CAC1E,KAAK,CAAC,aAAa,OAAO;CACtC,OAAO,oBAAC,QAAD;EAAM,eAAY;EAAO,GAAK;CAAkB,CAAA;AACzD;AAEA,MAAa,SAAS;CACpB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF"}
|
|
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,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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,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"}
|
package/src/separator.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { PartComponentProps } from "./runtime.js";
|
|
2
|
+
import { StateOf } from "@kirana-ui/core";
|
|
2
3
|
import { ReactElement } from "react";
|
|
3
4
|
import { SeparatorProps as SeparatorProps$1 } from "@kirana-ui/core/separator";
|
|
4
|
-
|
|
5
|
-
export
|
|
5
|
+
import { Vocabulary } from "@kirana-ui/core/vocabulary";
|
|
6
|
+
export type SeparatorProps = PartComponentProps<"div", StateOf<Vocabulary["separator"]["root"]>, SeparatorProps$1>;
|
|
7
|
+
export declare const Separator: ({ orientation, ...rest }: SeparatorProps) => ReactElement;
|
|
6
8
|
//# sourceMappingURL=separator.d.ts.map
|
package/src/separator.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { useController, usePart } from "./runtime.js";
|
|
1
|
+
import { component, useController, usePart } from "./runtime.js";
|
|
2
2
|
import { createSeparator } from "@kirana-ui/core/separator";
|
|
3
3
|
// src/separator.tsx
|
|
4
|
-
function Separator({ orientation, ...rest }) {
|
|
4
|
+
const Separator = /* @__PURE__ */ component("Separator", function Separator({ orientation, ...rest }) {
|
|
5
5
|
const controller = useController(createSeparator, { orientation });
|
|
6
6
|
return usePart(controller.root, "div", rest);
|
|
7
|
-
}
|
|
7
|
+
});
|
|
8
8
|
export { Separator };
|
|
9
9
|
|
|
10
10
|
//# sourceMappingURL=separator.js.map
|
package/src/separator.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"separator.js","names":[],"sources":["../../../../packages/react/src/separator.tsx"],"sourcesContent":["import { createSeparator } from \"@kirana-ui/core/separator\"\nimport type { SeparatorProps as CoreProps } from \"@kirana-ui/core/separator\"\nimport type { ReactElement } from \"react\"\n\nimport { useController, usePart } from \"./runtime.tsx\"\nimport type { PartComponentProps } from \"./runtime.tsx\"\n\nexport type SeparatorProps = CoreProps
|
|
1
|
+
{"version":3,"file":"separator.js","names":[],"sources":["../../../../packages/react/src/separator.tsx"],"sourcesContent":["import type { StateOf } from \"@kirana-ui/core\"\nimport { createSeparator } from \"@kirana-ui/core/separator\"\nimport type { SeparatorProps as CoreProps } from \"@kirana-ui/core/separator\"\nimport type { Vocabulary } from \"@kirana-ui/core/vocabulary\"\nimport type { ReactElement } from \"react\"\n\nimport { component, useController, usePart } from \"./runtime.tsx\"\nimport type { PartComponentProps } from \"./runtime.tsx\"\n\nexport type SeparatorProps = PartComponentProps<\n \"div\",\n StateOf<Vocabulary[\"separator\"][\"root\"]>,\n CoreProps\n>\n\nexport const Separator = /* @__PURE__ */ component(\n \"Separator\",\n function Separator({ orientation, ...rest }: SeparatorProps): ReactElement {\n const controller = useController(createSeparator, { orientation })\n return usePart(controller.root, \"div\", rest)\n }\n)\n"],"mappings":";;;AAeA,MAAa,YAA4B,0BACvC,aACA,SAAS,UAAU,EAAE,aAAa,GAAG,QAAsC;CACzE,MAAM,aAAa,cAAc,iBAAiB,EAAE,YAAY,CAAC;CACjE,OAAO,QAAQ,WAAW,MAAM,OAAO,IAAI;AAC7C,CACF"}
|
package/src/slider.d.ts
CHANGED
|
@@ -1,29 +1,44 @@
|
|
|
1
1
|
import { PartComponentProps } from "./runtime.js";
|
|
2
|
+
import { StateOf } from "@kirana-ui/core";
|
|
2
3
|
import { ReactElement, ReactNode } from "react";
|
|
3
|
-
import { SliderProps } from "@kirana-ui/core/slider";
|
|
4
|
-
|
|
4
|
+
import { SliderProps, SliderValue } from "@kirana-ui/core/slider";
|
|
5
|
+
import { Vocabulary } from "@kirana-ui/core/vocabulary";
|
|
6
|
+
type Parts = Vocabulary["slider"];
|
|
7
|
+
/**
|
|
8
|
+
* `Value` is what the slider is given, `value` or `defaultValue`: a number for one thumb, a
|
|
9
|
+
* list for a range. What `onValueChange` and `onValueCommitted` are told is the same kind.
|
|
10
|
+
*/
|
|
11
|
+
export type RootProps<Value extends SliderValue = SliderValue> = PartComponentProps<"div", StateOf<Parts["root"]>, Omit<SliderProps<Value>, "id"> & {
|
|
5
12
|
id?: string;
|
|
6
|
-
}
|
|
7
|
-
declare function Root({ value, defaultValue, onValueChange, onValueCommitted, min, max, step, largeStep, minStepsBetweenValues, thumbAlignment, orientation, disabled, name, form, format, locale, getAriaValueText, id, ...rest }: RootProps): ReactElement;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
+
}>;
|
|
14
|
+
declare function Root<Value extends SliderValue = number>({ value, defaultValue, onValueChange, onValueCommitted, min, max, step, largeStep, minStepsBetweenValues, thumbAlignment, orientation, disabled, name, form, format, locale, getAriaValueText, id, ...rest }: RootProps<Value>): ReactElement;
|
|
15
|
+
export type ControlProps = PartComponentProps<"div", StateOf<Parts["control"]>>;
|
|
16
|
+
export type TrackProps = PartComponentProps<"div", StateOf<Parts["track"]>>;
|
|
17
|
+
export type IndicatorProps = PartComponentProps<"div", StateOf<Parts["indicator"]>>;
|
|
18
|
+
declare const Control: (props: ControlProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
19
|
+
declare const Track: (props: TrackProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
20
|
+
declare const Indicator: (props: IndicatorProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
21
|
+
export type ThumbProps = PartComponentProps<"div", StateOf<Parts["thumb"]>, {
|
|
22
|
+
/**
|
|
23
|
+
* Which value of a range the thumb is, from 0. A thumb that is given none takes its place
|
|
24
|
+
* among the slider's thumbs, in the order they are written.
|
|
25
|
+
*/
|
|
13
26
|
index?: number;
|
|
14
|
-
}
|
|
15
|
-
declare function Thumb({ index,
|
|
16
|
-
|
|
17
|
-
|
|
27
|
+
}>;
|
|
28
|
+
declare function Thumb({ index, ...rest }: ThumbProps): ReactElement;
|
|
29
|
+
export type ValueProps = PartComponentProps<"output", StateOf<Parts["value"]>, {
|
|
30
|
+
/** Draws something else than the written value: it is given the text, and each thumb's value. */
|
|
18
31
|
children?: (text: string, values: readonly number[]) => ReactNode;
|
|
19
|
-
}
|
|
32
|
+
}>;
|
|
33
|
+
/** The written value, or what `children` makes of it and of the values. */
|
|
34
|
+
declare function Value({ children, ...props }: ValueProps): ReactElement;
|
|
20
35
|
export declare const Slider: {
|
|
21
|
-
Root: typeof Root;
|
|
22
|
-
Value: typeof Value;
|
|
23
|
-
Control: typeof Control;
|
|
24
|
-
Track: typeof Track;
|
|
25
|
-
Indicator: typeof Indicator;
|
|
26
|
-
Thumb: typeof Thumb;
|
|
36
|
+
readonly Root: typeof Root;
|
|
37
|
+
readonly Value: typeof Value;
|
|
38
|
+
readonly Control: typeof Control;
|
|
39
|
+
readonly Track: typeof Track;
|
|
40
|
+
readonly Indicator: typeof Indicator;
|
|
41
|
+
readonly Thumb: typeof Thumb;
|
|
27
42
|
};
|
|
28
43
|
export {};
|
|
29
44
|
//# sourceMappingURL=slider.d.ts.map
|
package/src/slider.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { DirectionContext } from "./direction-context.js";
|
|
2
2
|
import { FieldContext } from "./field-context.js";
|
|
3
|
-
import { useController, usePart, useSignal } from "./runtime.js";
|
|
3
|
+
import { PartElement, parts, useController, usePart, useSignal } from "./runtime.js";
|
|
4
4
|
import { within } from "@kirana-ui/core";
|
|
5
|
-
import { createContext, useContext } from "react";
|
|
6
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
import { createContext, useContext, useId } from "react";
|
|
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
|
|
9
9
|
const Context = createContext(null);
|
|
@@ -41,25 +41,24 @@ function Root({ value, defaultValue, onValueChange, onValueCommitted, min, max,
|
|
|
41
41
|
});
|
|
42
42
|
return /* @__PURE__ */ jsx(Context.Provider, {
|
|
43
43
|
value: controller,
|
|
44
|
-
children: /* @__PURE__ */ jsx(
|
|
44
|
+
children: /* @__PURE__ */ jsx(PartElement, {
|
|
45
|
+
of: controller.root,
|
|
46
|
+
tag: "div",
|
|
47
|
+
...rest
|
|
48
|
+
})
|
|
45
49
|
});
|
|
46
50
|
}
|
|
47
|
-
const RootElement = (props) => usePart(useSlider("Root").root, "div", props);
|
|
48
51
|
const Control = (props) => usePart(useSlider("Control").control, "div", props);
|
|
49
52
|
const Track = (props) => usePart(useSlider("Track").track, "div", props);
|
|
50
53
|
const Indicator = (props) => usePart(useSlider("Indicator").indicator, "div", props);
|
|
51
|
-
|
|
52
|
-
function Thumb({ index = 0, children, ...rest }) {
|
|
54
|
+
function Thumb({ index, ...rest }) {
|
|
53
55
|
const controller = useSlider("Thumb");
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
tag: "input"
|
|
61
|
-
})]
|
|
62
|
-
});
|
|
56
|
+
const generated = useId();
|
|
57
|
+
const at = index ?? generated;
|
|
58
|
+
return usePart(controller.thumb(at), "div", rest, void 0, (content) => /* @__PURE__ */ jsxs(Fragment$1, { children: [content, /* @__PURE__ */ jsx(PartElement, {
|
|
59
|
+
of: controller.thumbInput(at),
|
|
60
|
+
tag: "input"
|
|
61
|
+
})] }));
|
|
63
62
|
}
|
|
64
63
|
/** The written value, or what `children` makes of it and of the values. */
|
|
65
64
|
function Value({ children, ...props }) {
|
|
@@ -71,14 +70,14 @@ function Value({ children, ...props }) {
|
|
|
71
70
|
children: children ? children(text, values) : text
|
|
72
71
|
});
|
|
73
72
|
}
|
|
74
|
-
const Slider = {
|
|
73
|
+
const Slider = /* @__PURE__ */ parts("Slider", {
|
|
75
74
|
Root,
|
|
76
75
|
Value,
|
|
77
76
|
Control,
|
|
78
77
|
Track,
|
|
79
78
|
Indicator,
|
|
80
79
|
Thumb
|
|
81
|
-
};
|
|
80
|
+
});
|
|
82
81
|
export { Slider };
|
|
83
82
|
|
|
84
83
|
//# sourceMappingURL=slider.js.map
|
package/src/slider.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slider.js","names":[],"sources":["../../../../packages/react/src/slider.tsx"],"sourcesContent":["import { within } from \"@kirana-ui/core\"\nimport type {
|
|
1
|
+
{"version":3,"file":"slider.js","names":[],"sources":["../../../../packages/react/src/slider.tsx"],"sourcesContent":["import { within } from \"@kirana-ui/core\"\nimport type { StateOf } from \"@kirana-ui/core\"\nimport { createSlider } from \"@kirana-ui/core/slider\"\nimport type { Slider as Controller, SliderProps, SliderValue } from \"@kirana-ui/core/slider\"\nimport type { Vocabulary } from \"@kirana-ui/core/vocabulary\"\nimport { createContext, useContext, useId } 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[\"slider\"]\n\nconst Context = createContext<Controller | null>(null)\n\nfunction useSlider(part: string): Controller {\n const controller = useContext(Context)\n if (!controller) throw new Error(`<Slider.${part}> must be inside <Slider.Root>`)\n return controller\n}\n\n/**\n * `Value` is what the slider is given, `value` or `defaultValue`: a number for one thumb, a\n * list for a range. What `onValueChange` and `onValueCommitted` are told is the same kind.\n */\nexport type RootProps<Value extends SliderValue = SliderValue> = PartComponentProps<\n \"div\",\n StateOf<Parts[\"root\"]>,\n Omit<SliderProps<Value>, \"id\"> & { id?: string }\n>\n\n// Given neither `value` nor `defaultValue`, a slider has one thumb: its value is a number.\nfunction Root<Value extends SliderValue = number>({\n value,\n defaultValue,\n onValueChange,\n onValueCommitted,\n min,\n max,\n step,\n largeStep,\n minStepsBetweenValues,\n thumbAlignment,\n orientation,\n disabled,\n name,\n form,\n format,\n locale,\n getAriaValueText,\n id,\n ...rest\n}: RootProps<Value>): ReactElement {\n const field = useContext(FieldContext) ?? undefined\n const direction = useContext(DirectionContext) ?? undefined\n const create = within(createSlider<Value>, { field, direction })\n const controller = useController(create, {\n value,\n defaultValue,\n onValueChange,\n onValueCommitted,\n min,\n max,\n step,\n largeStep,\n minStepsBetweenValues,\n thumbAlignment,\n orientation,\n disabled,\n name,\n form,\n format,\n locale,\n getAriaValueText,\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 ControlProps = PartComponentProps<\"div\", StateOf<Parts[\"control\"]>>\nexport type TrackProps = PartComponentProps<\"div\", StateOf<Parts[\"track\"]>>\nexport type IndicatorProps = PartComponentProps<\"div\", StateOf<Parts[\"indicator\"]>>\n\nconst Control = (props: ControlProps) => usePart(useSlider(\"Control\").control, \"div\", props)\nconst Track = (props: TrackProps) => usePart(useSlider(\"Track\").track, \"div\", props)\nconst Indicator = (props: IndicatorProps) => usePart(useSlider(\"Indicator\").indicator, \"div\", props)\n\nexport type ThumbProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"thumb\"]>,\n {\n /**\n * Which value of a range the thumb is, from 0. A thumb that is given none takes its place\n * among the slider's thumbs, in the order they are written.\n */\n index?: number\n }\n>\n\nfunction Thumb({ index, ...rest }: ThumbProps): ReactElement {\n const controller = useSlider(\"Thumb\")\n // The same on every render of this thumb, a second one in StrictMode included.\n const generated = useId()\n const at = index ?? generated\n // Its native input is the element's last child, whatever element the caller asked for.\n return usePart(controller.thumb(at), \"div\", rest, undefined, (content) => (\n <>\n {content}\n <PartElement of={controller.thumbInput(at)} tag=\"input\" />\n </>\n ))\n}\n\nexport type ValueProps = PartComponentProps<\n \"output\",\n StateOf<Parts[\"value\"]>,\n {\n /** Draws something else than the written value: it is given the text, and each thumb's value. */\n children?: (text: string, values: readonly number[]) => ReactNode\n }\n>\n\n/** The written value, or what `children` makes of it and of the values. */\nfunction Value({ children, ...props }: ValueProps): ReactElement {\n const controller = useSlider(\"Value\")\n const text = useSignal(controller.text)\n const values = useSignal(controller.values)\n return usePart(controller.value, \"output\", {\n ...props,\n children: children ? children(text, values) : text,\n })\n}\n\nexport const Slider = /* @__PURE__ */ parts(\"Slider\", {\n Root,\n Value,\n Control,\n Track,\n Indicator,\n Thumb,\n})\n"],"mappings":";;;;;;;;AAeA,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;AAaA,SAAS,KAAyC,EAChD,OACA,cACA,eACA,kBACA,KACA,KACA,MACA,WACA,uBACA,gBACA,aACA,UACA,MACA,MACA,QACA,QACA,kBACA,IACA,GAAG,QAC8B;CACjC,MAAM,QAAQ,WAAW,YAAY,KAAK,KAAA;CAC1C,MAAM,YAAY,WAAW,gBAAgB,KAAK,KAAA;CAClD,MAAM,SAAS,OAAO,cAAqB;EAAE;EA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1
|
import { PartComponentProps } from "./runtime.js";
|
|
2
|
+
import { StateOf } from "@kirana-ui/core";
|
|
2
3
|
import { ReactElement } from "react";
|
|
3
4
|
import { SwitchProps } from "@kirana-ui/core/switch";
|
|
4
|
-
|
|
5
|
+
import { Vocabulary } from "@kirana-ui/core/vocabulary";
|
|
6
|
+
type Parts = Vocabulary["switch"];
|
|
7
|
+
export type RootProps = PartComponentProps<"span", StateOf<Parts["root"]>, Omit<SwitchProps, "id"> & {
|
|
5
8
|
id?: string;
|
|
6
|
-
}
|
|
7
|
-
declare function Root({ checked, defaultChecked, onCheckedChange, disabled, readOnly, required, name, form, value, id,
|
|
8
|
-
|
|
9
|
+
}>;
|
|
10
|
+
declare function Root({ checked, defaultChecked, onCheckedChange, disabled, readOnly, required, name, form, value, id, ...rest }: RootProps): ReactElement;
|
|
11
|
+
export type ThumbProps = PartComponentProps<"span", StateOf<Parts["thumb"]>>;
|
|
12
|
+
declare const Thumb: (props: ThumbProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
9
13
|
export declare const Switch: {
|
|
10
|
-
Root: typeof Root;
|
|
11
|
-
Thumb: typeof Thumb;
|
|
14
|
+
readonly Root: typeof Root;
|
|
15
|
+
readonly Thumb: typeof Thumb;
|
|
12
16
|
};
|
|
13
17
|
export {};
|
|
14
18
|
//# sourceMappingURL=switch.d.ts.map
|
package/src/switch.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { FieldContext } from "./field-context.js";
|
|
2
|
-
import { useController, usePart } from "./runtime.js";
|
|
2
|
+
import { PartElement, parts, useController, usePart } from "./runtime.js";
|
|
3
3
|
import { within } from "@kirana-ui/core";
|
|
4
4
|
import { createContext, useContext } from "react";
|
|
5
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
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
|
|
8
8
|
const Context = createContext(null);
|
|
@@ -11,7 +11,7 @@ function useSwitch(part) {
|
|
|
11
11
|
if (!controller) throw new Error(`<Switch.${part}> must be inside <Switch.Root>`);
|
|
12
12
|
return controller;
|
|
13
13
|
}
|
|
14
|
-
function Root({ checked, defaultChecked, onCheckedChange, disabled, readOnly, required, name, form, value, id,
|
|
14
|
+
function Root({ checked, defaultChecked, onCheckedChange, disabled, readOnly, required, name, form, value, id, ...rest }) {
|
|
15
15
|
const field = useContext(FieldContext) ?? void 0;
|
|
16
16
|
const create = within(createSwitch, { field });
|
|
17
17
|
const controller = useController(create, {
|
|
@@ -28,19 +28,21 @@ function Root({ checked, defaultChecked, onCheckedChange, disabled, readOnly, re
|
|
|
28
28
|
});
|
|
29
29
|
return /* @__PURE__ */ jsx(Context.Provider, {
|
|
30
30
|
value: controller,
|
|
31
|
-
children: /* @__PURE__ */
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
children: /* @__PURE__ */ jsx(PartElement, {
|
|
32
|
+
of: controller.root,
|
|
33
|
+
tag: "span",
|
|
34
|
+
hold: withInput,
|
|
35
|
+
...rest
|
|
34
36
|
})
|
|
35
37
|
});
|
|
36
38
|
}
|
|
37
|
-
const
|
|
39
|
+
const withInput = (content) => /* @__PURE__ */ jsxs(Fragment$1, { children: [content, /* @__PURE__ */ jsx(Input, {})] });
|
|
38
40
|
const Input = () => usePart(useSwitch("Root").input, "input", {});
|
|
39
41
|
const Thumb = (props) => usePart(useSwitch("Thumb").thumb, "span", props);
|
|
40
|
-
const Switch = {
|
|
42
|
+
const Switch = /* @__PURE__ */ parts("Switch", {
|
|
41
43
|
Root,
|
|
42
44
|
Thumb
|
|
43
|
-
};
|
|
45
|
+
});
|
|
44
46
|
export { Switch };
|
|
45
47
|
|
|
46
48
|
//# sourceMappingURL=switch.js.map
|
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 { createSwitch } from \"@kirana-ui/core/switch\"\nimport type { Switch as Controller, SwitchProps } from \"@kirana-ui/core/switch\"\nimport { createContext, useContext } from \"react\"\nimport type { ReactElement } from \"react\"\n\nimport { FieldContext } from \"./field-context.ts\"\nimport { useController, usePart } from \"./runtime.tsx\"\nimport type { PartComponentProps } from \"./runtime.tsx\"\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 = 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\"> & { id?: string }\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;AAQA,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,30 +1,38 @@
|
|
|
1
1
|
import { PartComponentProps } from "./runtime.js";
|
|
2
|
+
import { StateOf } from "@kirana-ui/core";
|
|
2
3
|
import { ReactElement } from "react";
|
|
3
4
|
import { TabsListOptions, TabsProps } from "@kirana-ui/core/tabs";
|
|
4
|
-
|
|
5
|
+
import { Vocabulary } from "@kirana-ui/core/vocabulary";
|
|
6
|
+
type Parts = Vocabulary["tabs"];
|
|
7
|
+
/** `Value` is what tells a tab from the others: the type of `value`. */
|
|
8
|
+
export type RootProps<Value = unknown> = PartComponentProps<"div", StateOf<Parts["root"]>, Omit<TabsProps<Value>, "id"> & {
|
|
5
9
|
id?: string;
|
|
6
|
-
}
|
|
7
|
-
declare function Root<Value>({ value, defaultValue, onValueChange, orientation, id, ...rest }: RootProps<Value>): ReactElement;
|
|
8
|
-
export type ListProps = PartComponentProps
|
|
10
|
+
}>;
|
|
11
|
+
declare function Root<Value = unknown>({ value, defaultValue, onValueChange, orientation, id, ...rest }: RootProps<Value>): ReactElement;
|
|
12
|
+
export type ListProps = PartComponentProps<"div", StateOf<Parts["list"]>, TabsListOptions>;
|
|
9
13
|
declare function List({ activateOnFocus, loop, ...props }: ListProps): ReactElement;
|
|
10
|
-
export
|
|
14
|
+
export type TabProps = PartComponentProps<"button", StateOf<Parts["tab"]>, {
|
|
15
|
+
/** What the tabs' value is while this tab is the active one. */
|
|
11
16
|
value: unknown;
|
|
17
|
+
/** Disables this tab: it cannot be chosen. */
|
|
12
18
|
disabled?: boolean;
|
|
13
|
-
}
|
|
19
|
+
}>;
|
|
14
20
|
declare function Tab({ value, disabled, ...props }: TabProps): ReactElement;
|
|
15
|
-
|
|
16
|
-
|
|
21
|
+
export type IndicatorProps = PartComponentProps<"span", StateOf<Parts["indicator"]>>;
|
|
22
|
+
declare const Indicator: (props: IndicatorProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
23
|
+
export type PanelProps = PartComponentProps<"div", StateOf<Parts["panel"]>, {
|
|
24
|
+
/** The value of the tab this is the panel of. */
|
|
17
25
|
value: unknown;
|
|
18
26
|
/** Keeps the panel in the page, `hidden`, while its tab is not the active one. */
|
|
19
27
|
keepMounted?: boolean;
|
|
20
|
-
}
|
|
28
|
+
}>;
|
|
21
29
|
declare function Panel({ value, keepMounted, ...props }: PanelProps): ReactElement | null;
|
|
22
30
|
export declare const Tabs: {
|
|
23
|
-
Root: typeof Root;
|
|
24
|
-
List: typeof List;
|
|
25
|
-
Tab: typeof Tab;
|
|
26
|
-
Indicator: typeof Indicator;
|
|
27
|
-
Panel: typeof Panel;
|
|
31
|
+
readonly Root: typeof Root;
|
|
32
|
+
readonly List: typeof List;
|
|
33
|
+
readonly Tab: typeof Tab;
|
|
34
|
+
readonly Indicator: typeof Indicator;
|
|
35
|
+
readonly Panel: typeof Panel;
|
|
28
36
|
};
|
|
29
37
|
export {};
|
|
30
38
|
//# sourceMappingURL=tabs.d.ts.map
|
package/src/tabs.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DirectionContext } from "./direction-context.js";
|
|
2
|
-
import { useController, useMount, useOptions, usePart, useSignal } from "./runtime.js";
|
|
2
|
+
import { PartElement, parts, useController, useMount, useOptions, usePart, useSignal } from "./runtime.js";
|
|
3
3
|
import { defined, within } from "@kirana-ui/core";
|
|
4
4
|
import { createContext, useContext, useMemo } from "react";
|
|
5
5
|
import { jsx } from "react/jsx-runtime";
|
|
@@ -24,13 +24,12 @@ function Root({ value, defaultValue, onValueChange, orientation, id, ...rest })
|
|
|
24
24
|
return /* @__PURE__ */ jsx(Context.Provider, {
|
|
25
25
|
value: controller,
|
|
26
26
|
children: /* @__PURE__ */ jsx(PartElement, {
|
|
27
|
-
|
|
27
|
+
of: controller.root,
|
|
28
28
|
tag: "div",
|
|
29
29
|
...rest
|
|
30
30
|
})
|
|
31
31
|
});
|
|
32
32
|
}
|
|
33
|
-
const PartElement = ({ part, tag, ...props }) => usePart(part, tag, props);
|
|
34
33
|
function List({ activateOnFocus, loop, ...props }) {
|
|
35
34
|
const controller = useTabs("List");
|
|
36
35
|
controller.listOptions.set(defined({
|
|
@@ -56,18 +55,18 @@ function Panel({ value, keepMounted, ...props }) {
|
|
|
56
55
|
useMount(panel);
|
|
57
56
|
if (!useSignal(panel.mounted) && !keepMounted) return null;
|
|
58
57
|
return /* @__PURE__ */ jsx(PartElement, {
|
|
59
|
-
|
|
58
|
+
of: panel.part,
|
|
60
59
|
tag: "div",
|
|
61
60
|
...props
|
|
62
61
|
});
|
|
63
62
|
}
|
|
64
|
-
const Tabs = {
|
|
63
|
+
const Tabs = /* @__PURE__ */ parts("Tabs", {
|
|
65
64
|
Root,
|
|
66
65
|
List,
|
|
67
66
|
Tab,
|
|
68
67
|
Indicator,
|
|
69
68
|
Panel
|
|
70
|
-
};
|
|
69
|
+
});
|
|
71
70
|
export { Tabs };
|
|
72
71
|
|
|
73
72
|
//# sourceMappingURL=tabs.js.map
|