@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/checkbox.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkbox.js","names":[],"sources":["../../../../packages/react/src/checkbox.tsx"],"sourcesContent":["import { within } from \"@kirana-ui/core\"\nimport type { StateOf } from \"@kirana-ui/core\"\nimport { createCheckbox } from \"@kirana-ui/core/checkbox\"\nimport type { Checkbox as Controller, CheckboxProps } from \"@kirana-ui/core/checkbox\"\nimport type { Vocabulary } from \"@kirana-ui/core/vocabulary\"\nimport { createContext, useContext } from \"react\"\nimport type { ReactElement, ReactNode } from \"react\"\n\nimport { CheckboxGroupContext } from \"./checkbox-group-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[\"checkbox\"]\n\nconst Context = createContext<Controller | null>(null)\n\nfunction useCheckbox(part: string): Controller {\n const controller = useContext(Context)\n if (!controller) throw new Error(`<Checkbox.${part}> must be inside <Checkbox.Root>`)\n return controller\n}\n\nexport type RootProps = PartComponentProps<\n \"span\",\n StateOf<Parts[\"root\"]>,\n Omit<CheckboxProps, \"id\"> & { id?: string
|
|
1
|
+
{"version":3,"file":"checkbox.js","names":[],"sources":["../../../../packages/react/src/checkbox.tsx"],"sourcesContent":["import { within } from \"@kirana-ui/core\"\nimport type { StateOf } from \"@kirana-ui/core\"\nimport { createCheckbox } from \"@kirana-ui/core/checkbox\"\nimport type { Checkbox as Controller, CheckboxProps } from \"@kirana-ui/core/checkbox\"\nimport type { Vocabulary } from \"@kirana-ui/core/vocabulary\"\nimport { createContext, useContext } from \"react\"\nimport type { ReactElement, ReactNode } from \"react\"\n\nimport { CheckboxGroupContext } from \"./checkbox-group-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[\"checkbox\"]\n\nconst Context = createContext<Controller | null>(null)\n\nfunction useCheckbox(part: string): Controller {\n const controller = useContext(Context)\n if (!controller) throw new Error(`<Checkbox.${part}> must be inside <Checkbox.Root>`)\n return controller\n}\n\nexport type RootProps = PartComponentProps<\n \"span\",\n StateOf<Parts[\"root\"]>,\n Omit<CheckboxProps, \"id\"> & {\n /** The id of the box's hidden native checkbox, not of the box: 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 indeterminate,\n parent,\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 group = useContext(CheckboxGroupContext) ?? undefined\n const create = within(createCheckbox, { field, group })\n const controller = useController(create, {\n checked,\n defaultChecked,\n onCheckedChange,\n indeterminate,\n parent,\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(useCheckbox(\"Root\").input, \"input\", {})\n\n/**\n * A dash while mixed and a tick while checked, from the part's state: `<Checkbox.Indicator\n * render={(props, state) => <span {...props}>{state.indeterminate ? \"–\" : \"✓\"}</span>} />`.\n */\nexport type IndicatorProps = PartComponentProps<\n \"span\",\n StateOf<Parts[\"indicator\"]>,\n {\n /** Keeps the mark in the page while the box is unchecked. */\n keepMounted?: boolean\n }\n>\n\nfunction Indicator({ keepMounted, ...props }: IndicatorProps): ReactElement | null {\n const controller = useCheckbox(\"Indicator\")\n const mounted = useSignal(controller.indicatorMounted)\n if (!mounted && !keepMounted) return null\n return <PartElement of={controller.indicator} tag=\"span\" {...props} />\n}\n\nexport const Checkbox = /* @__PURE__ */ parts(\"Checkbox\", { Root, Indicator })\n"],"mappings":";;;;;;;;AAeA,MAAM,UAAU,cAAiC,IAAI;AAErD,SAAS,YAAY,MAA0B;CAC7C,MAAM,aAAa,WAAW,OAAO;CACrC,IAAI,CAAC,YAAY,MAAM,IAAI,MAAM,aAAa,KAAK,iCAAiC;CACpF,OAAO;AACT;AAWA,SAAS,KAAK,EACZ,SACA,gBACA,iBACA,eACA,QACA,UACA,UACA,UACA,MACA,MACA,OACA,IACA,GAAG,QACuB;CAC1B,MAAM,QAAQ,WAAW,YAAY,KAAK,KAAA;CAC1C,MAAM,QAAQ,WAAW,oBAAoB,KAAK,KAAA;CAClD,MAAM,SAAS,OAAO,gBAAgB;EAAE;EAAO;CAAM,CAAC;CACtD,MAAM,aAAa,cAAc,QAAQ;EACvC;EACA;EACA;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,YAAY,MAAM,CAAC,CAAC,OAAO,SAAS,CAAC,CAAC;AAelE,SAAS,UAAU,EAAE,aAAa,GAAG,SAA8C;CACjF,MAAM,aAAa,YAAY,WAAW;CAE1C,IAAI,CADY,UAAU,WAAW,gBAC1B,KAAK,CAAC,aAAa,OAAO;CACrC,OAAO,oBAAC,aAAD;EAAa,IAAI,WAAW;EAAW,KAAI;EAAO,GAAI;CAAQ,CAAA;AACvE;AAEA,MAAa,WAA2B,sBAAM,YAAY;CAAE;CAAM;AAAU,CAAC"}
|
package/src/collapsible.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 { CollapsibleProps } from "@kirana-ui/core/collapsible";
|
|
5
5
|
import { Vocabulary } from "@kirana-ui/core/vocabulary";
|
|
6
6
|
type Parts = Vocabulary["collapsible"];
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { PartComponentProps } from "./runtime.js";
|
|
2
|
+
import { ReactElement } from "react";
|
|
3
|
+
import { Orientation, StateOf } from "@kirana-ui/core";
|
|
4
|
+
import { ColorPickerInputChannel, ColorPickerProps, ColorPickerSliderChannel } from "@kirana-ui/core/color-picker";
|
|
5
|
+
import { Vocabulary } from "@kirana-ui/core/vocabulary";
|
|
6
|
+
type Parts = Vocabulary["colorPicker"];
|
|
7
|
+
export type RootProps = PartComponentProps<"div", StateOf<Parts["root"]>, Omit<ColorPickerProps, "id"> & {
|
|
8
|
+
id?: string;
|
|
9
|
+
}>;
|
|
10
|
+
declare function Root({ value, defaultValue, onValueChange, onValueCommitted, format, defaultFormat, onFormatChange, alpha, thumbAlignment, disabled, readOnly, required, name, form, getAriaValueText, id, ...rest }: RootProps): ReactElement;
|
|
11
|
+
export type AreaProps = PartComponentProps<"div", StateOf<Parts["area"]>>;
|
|
12
|
+
export type AreaThumbProps = PartComponentProps<"div", StateOf<Parts["areaThumb"]>>;
|
|
13
|
+
declare const Area: (props: AreaProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
14
|
+
declare const AreaThumb: (props: AreaThumbProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
15
|
+
export type ChannelSliderProps = PartComponentProps<"div", StateOf<Parts["channelSlider"]>, {
|
|
16
|
+
/** The channel it moves: the hue, or the alpha. */
|
|
17
|
+
channel: ColorPickerSliderChannel;
|
|
18
|
+
/** The way its track runs. Default `horizontal`. */
|
|
19
|
+
orientation?: Orientation;
|
|
20
|
+
}>;
|
|
21
|
+
declare function ChannelSlider({ channel, orientation, ...props }: ChannelSliderProps): ReactElement;
|
|
22
|
+
export type ChannelSliderTrackProps = PartComponentProps<"div", StateOf<Parts["channelSliderTrack"]>>;
|
|
23
|
+
export type ChannelSliderThumbProps = PartComponentProps<"div", StateOf<Parts["channelSliderThumb"]>>;
|
|
24
|
+
declare function ChannelSliderTrack(props: ChannelSliderTrackProps): ReactElement;
|
|
25
|
+
declare function ChannelSliderThumb(props: ChannelSliderThumbProps): ReactElement;
|
|
26
|
+
export type ChannelInputProps = PartComponentProps<"input", StateOf<Parts["channelInput"]>, {
|
|
27
|
+
/** The channel it is typed in, or `hex` for the whole colour. */
|
|
28
|
+
channel: ColorPickerInputChannel;
|
|
29
|
+
}>;
|
|
30
|
+
declare function ChannelInput({ channel, ...props }: ChannelInputProps): ReactElement;
|
|
31
|
+
export type SwatchProps = PartComponentProps<"div", StateOf<Parts["swatch"]>>;
|
|
32
|
+
declare const Swatch: (props: SwatchProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
33
|
+
export type SwatchTriggerProps = PartComponentProps<"button", StateOf<Parts["swatchTrigger"]>, {
|
|
34
|
+
/** The preset's colour, in any format: pressed, the colour is this one. */
|
|
35
|
+
value: string;
|
|
36
|
+
}>;
|
|
37
|
+
declare function SwatchTrigger({ value, ...props }: SwatchTriggerProps): ReactElement;
|
|
38
|
+
export type EyeDropperTriggerProps = PartComponentProps<"button", StateOf<Parts["eyeDropperTrigger"]>>;
|
|
39
|
+
declare const EyeDropperTrigger: (props: EyeDropperTriggerProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
40
|
+
export type ValueTextProps = PartComponentProps<"span", StateOf<Parts["valueText"]>>;
|
|
41
|
+
/** Says the colour in its format unless it is given children. */
|
|
42
|
+
declare function ValueText(props: ValueTextProps): ReactElement;
|
|
43
|
+
export type FormatTriggerProps = PartComponentProps<"button", StateOf<Parts["formatTrigger"]>>;
|
|
44
|
+
/** Says the format the colour is written in unless it is given children. */
|
|
45
|
+
declare function FormatTrigger(props: FormatTriggerProps): ReactElement;
|
|
46
|
+
export declare const ColorPicker: {
|
|
47
|
+
readonly Root: typeof Root;
|
|
48
|
+
readonly Area: typeof Area;
|
|
49
|
+
readonly AreaThumb: typeof AreaThumb;
|
|
50
|
+
readonly ChannelSlider: typeof ChannelSlider;
|
|
51
|
+
readonly ChannelSliderTrack: typeof ChannelSliderTrack;
|
|
52
|
+
readonly ChannelSliderThumb: typeof ChannelSliderThumb;
|
|
53
|
+
readonly ChannelInput: typeof ChannelInput;
|
|
54
|
+
readonly Swatch: typeof Swatch;
|
|
55
|
+
readonly SwatchTrigger: typeof SwatchTrigger;
|
|
56
|
+
readonly EyeDropperTrigger: typeof EyeDropperTrigger;
|
|
57
|
+
readonly ValueText: typeof ValueText;
|
|
58
|
+
readonly FormatTrigger: typeof FormatTrigger;
|
|
59
|
+
};
|
|
60
|
+
export {};
|
|
61
|
+
//# sourceMappingURL=color-picker.d.ts.map
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { DirectionContext } from "./direction-context.js";
|
|
2
|
+
import { FieldContext } from "./field-context.js";
|
|
3
|
+
import { PartElement, parts, useController, useOwnText, usePart, useSignal } from "./runtime.js";
|
|
4
|
+
import { 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 { createColorPicker } from "@kirana-ui/core/color-picker";
|
|
8
|
+
// src/color-picker.tsx
|
|
9
|
+
const Context = createContext(null);
|
|
10
|
+
const SliderContext = createContext(null);
|
|
11
|
+
function useColorPicker(part) {
|
|
12
|
+
const controller = useContext(Context);
|
|
13
|
+
if (!controller) throw new Error(`<ColorPicker.${part}> must be inside <ColorPicker.Root>`);
|
|
14
|
+
return controller;
|
|
15
|
+
}
|
|
16
|
+
function useSliderOf(part) {
|
|
17
|
+
const slider = useContext(SliderContext);
|
|
18
|
+
if (!slider) throw new Error(`<ColorPicker.${part}> must be inside <ColorPicker.ChannelSlider>`);
|
|
19
|
+
return slider;
|
|
20
|
+
}
|
|
21
|
+
function Root({ value, defaultValue, onValueChange, onValueCommitted, format, defaultFormat, onFormatChange, alpha, thumbAlignment, disabled, readOnly, required, name, form, getAriaValueText, id, ...rest }) {
|
|
22
|
+
const field = useContext(FieldContext) ?? void 0;
|
|
23
|
+
const direction = useContext(DirectionContext) ?? void 0;
|
|
24
|
+
const create = within(createColorPicker, {
|
|
25
|
+
field,
|
|
26
|
+
direction
|
|
27
|
+
});
|
|
28
|
+
const controller = useController(create, {
|
|
29
|
+
value,
|
|
30
|
+
defaultValue,
|
|
31
|
+
onValueChange,
|
|
32
|
+
onValueCommitted,
|
|
33
|
+
format,
|
|
34
|
+
defaultFormat,
|
|
35
|
+
onFormatChange,
|
|
36
|
+
alpha,
|
|
37
|
+
thumbAlignment,
|
|
38
|
+
disabled,
|
|
39
|
+
readOnly,
|
|
40
|
+
required,
|
|
41
|
+
name,
|
|
42
|
+
form,
|
|
43
|
+
getAriaValueText,
|
|
44
|
+
id
|
|
45
|
+
});
|
|
46
|
+
return /* @__PURE__ */ jsx(Context.Provider, {
|
|
47
|
+
value: controller,
|
|
48
|
+
children: usePart(controller.root, "div", rest, void 0, (content) => /* @__PURE__ */ jsxs(Fragment$1, { children: [content, /* @__PURE__ */ jsx(PartElement, {
|
|
49
|
+
of: controller.input,
|
|
50
|
+
tag: "input"
|
|
51
|
+
})] }))
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
const Area = (props) => usePart(useColorPicker("Area").area, "div", props);
|
|
55
|
+
const AreaThumb = (props) => usePart(useColorPicker("AreaThumb").areaThumb, "div", props);
|
|
56
|
+
function ChannelSlider({ channel, orientation = "horizontal", ...props }) {
|
|
57
|
+
const controller = useColorPicker("ChannelSlider");
|
|
58
|
+
return /* @__PURE__ */ jsx(SliderContext.Provider, {
|
|
59
|
+
value: {
|
|
60
|
+
channel,
|
|
61
|
+
orientation
|
|
62
|
+
},
|
|
63
|
+
children: usePart(controller.channelSlider(channel, orientation), "div", props)
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
function ChannelSliderTrack(props) {
|
|
67
|
+
const { channel, orientation } = useSliderOf("ChannelSliderTrack");
|
|
68
|
+
const controller = useColorPicker("ChannelSliderTrack");
|
|
69
|
+
return usePart(controller.channelSliderTrack(channel, orientation), "div", props);
|
|
70
|
+
}
|
|
71
|
+
function ChannelSliderThumb(props) {
|
|
72
|
+
const { channel, orientation } = useSliderOf("ChannelSliderThumb");
|
|
73
|
+
const controller = useColorPicker("ChannelSliderThumb");
|
|
74
|
+
return usePart(controller.channelSliderThumb(channel, orientation), "div", props);
|
|
75
|
+
}
|
|
76
|
+
function ChannelInput({ channel, ...props }) {
|
|
77
|
+
const controller = useColorPicker("ChannelInput");
|
|
78
|
+
return usePart(useOwnText(controller.channelInput(channel)), "input", props);
|
|
79
|
+
}
|
|
80
|
+
const Swatch = (props) => usePart(useColorPicker("Swatch").swatch, "div", props);
|
|
81
|
+
function SwatchTrigger({ value, ...props }) {
|
|
82
|
+
return usePart(useColorPicker("SwatchTrigger").swatchTrigger(value), "button", props);
|
|
83
|
+
}
|
|
84
|
+
const EyeDropperTrigger = (props) => usePart(useColorPicker("EyeDropperTrigger").eyeDropperTrigger, "button", props);
|
|
85
|
+
/** Says the colour in its format unless it is given children. */
|
|
86
|
+
function ValueText(props) {
|
|
87
|
+
const controller = useColorPicker("ValueText");
|
|
88
|
+
const text = useSignal(controller.text);
|
|
89
|
+
return usePart(controller.valueText, "span", {
|
|
90
|
+
...props,
|
|
91
|
+
children: props.children ?? text
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
/** Says the format the colour is written in unless it is given children. */
|
|
95
|
+
function FormatTrigger(props) {
|
|
96
|
+
const controller = useColorPicker("FormatTrigger");
|
|
97
|
+
const format = useSignal(controller.format);
|
|
98
|
+
return usePart(controller.formatTrigger, "button", {
|
|
99
|
+
...props,
|
|
100
|
+
children: props.children ?? format
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
const ColorPicker = /* @__PURE__ */ parts("ColorPicker", {
|
|
104
|
+
Root,
|
|
105
|
+
Area,
|
|
106
|
+
AreaThumb,
|
|
107
|
+
ChannelSlider,
|
|
108
|
+
ChannelSliderTrack,
|
|
109
|
+
ChannelSliderThumb,
|
|
110
|
+
ChannelInput,
|
|
111
|
+
Swatch,
|
|
112
|
+
SwatchTrigger,
|
|
113
|
+
EyeDropperTrigger,
|
|
114
|
+
ValueText,
|
|
115
|
+
FormatTrigger
|
|
116
|
+
});
|
|
117
|
+
export { ColorPicker };
|
|
118
|
+
|
|
119
|
+
//# sourceMappingURL=color-picker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"color-picker.js","names":[],"sources":["../../../../packages/react/src/color-picker.tsx"],"sourcesContent":["import { within } from \"@kirana-ui/core\"\nimport type { Orientation, StateOf } from \"@kirana-ui/core\"\nimport { createColorPicker } from \"@kirana-ui/core/color-picker\"\nimport type {\n ColorPicker as Controller,\n ColorPickerInputChannel,\n ColorPickerProps,\n ColorPickerSliderChannel,\n} from \"@kirana-ui/core/color-picker\"\nimport type { Vocabulary } from \"@kirana-ui/core/vocabulary\"\nimport { createContext, useContext } from \"react\"\nimport type { ReactElement } from \"react\"\n\nimport { DirectionContext } from \"./direction-context.ts\"\nimport { FieldContext } from \"./field-context.ts\"\nimport { PartElement, parts, useController, useOwnText, usePart, useSignal } from \"./runtime.tsx\"\nimport type { PartComponentProps } from \"./runtime.tsx\"\n\ntype Parts = Vocabulary[\"colorPicker\"]\n\nconst Context = createContext<Controller | null>(null)\n\n/** The channel a slider moves and the way it runs, for its track and its thumb. */\ninterface SliderOf {\n channel: ColorPickerSliderChannel\n orientation: Orientation\n}\nconst SliderContext = createContext<SliderOf | null>(null)\n\nfunction useColorPicker(part: string): Controller {\n const controller = useContext(Context)\n if (!controller) throw new Error(`<ColorPicker.${part}> must be inside <ColorPicker.Root>`)\n return controller\n}\n\nfunction useSliderOf(part: string): SliderOf {\n const slider = useContext(SliderContext)\n if (!slider) throw new Error(`<ColorPicker.${part}> must be inside <ColorPicker.ChannelSlider>`)\n return slider\n}\n\nexport type RootProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"root\"]>,\n Omit<ColorPickerProps, \"id\"> & { id?: string }\n>\n\nfunction Root({\n value,\n defaultValue,\n onValueChange,\n onValueCommitted,\n format,\n defaultFormat,\n onFormatChange,\n alpha,\n thumbAlignment,\n disabled,\n readOnly,\n required,\n name,\n form,\n getAriaValueText,\n id,\n ...rest\n}: RootProps): ReactElement {\n const field = useContext(FieldContext) ?? undefined\n const direction = useContext(DirectionContext) ?? undefined\n const create = within(createColorPicker, { field, direction })\n const controller: Controller = useController(create, {\n value,\n defaultValue,\n onValueChange,\n onValueCommitted,\n format,\n defaultFormat,\n onFormatChange,\n alpha,\n thumbAlignment,\n disabled,\n readOnly,\n required,\n name,\n form,\n getAriaValueText,\n id,\n })\n return (\n <Context.Provider value={controller}>\n {usePart(controller.root, \"div\", rest, undefined, (content) => (\n // The input a form reads is the element's last child, whatever element the caller asked for.\n <>\n {content}\n <PartElement of={controller.input} tag=\"input\" />\n </>\n ))}\n </Context.Provider>\n )\n}\n\nexport type AreaProps = PartComponentProps<\"div\", StateOf<Parts[\"area\"]>>\nexport type AreaThumbProps = PartComponentProps<\"div\", StateOf<Parts[\"areaThumb\"]>>\n\nconst Area = (props: AreaProps) => usePart(useColorPicker(\"Area\").area, \"div\", props)\nconst AreaThumb = (props: AreaThumbProps) =>\n usePart(useColorPicker(\"AreaThumb\").areaThumb, \"div\", props)\n\nexport type ChannelSliderProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"channelSlider\"]>,\n {\n /** The channel it moves: the hue, or the alpha. */\n channel: ColorPickerSliderChannel\n /** The way its track runs. Default `horizontal`. */\n orientation?: Orientation\n }\n>\n\nfunction ChannelSlider({\n channel,\n orientation = \"horizontal\",\n ...props\n}: ChannelSliderProps): ReactElement {\n const controller = useColorPicker(\"ChannelSlider\")\n return (\n <SliderContext.Provider value={{ channel, orientation }}>\n {usePart(controller.channelSlider(channel, orientation), \"div\", props)}\n </SliderContext.Provider>\n )\n}\n\nexport type ChannelSliderTrackProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"channelSliderTrack\"]>\n>\nexport type ChannelSliderThumbProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"channelSliderThumb\"]>\n>\n\nfunction ChannelSliderTrack(props: ChannelSliderTrackProps): ReactElement {\n const { channel, orientation } = useSliderOf(\"ChannelSliderTrack\")\n const controller = useColorPicker(\"ChannelSliderTrack\")\n return usePart(controller.channelSliderTrack(channel, orientation), \"div\", props)\n}\n\nfunction ChannelSliderThumb(props: ChannelSliderThumbProps): ReactElement {\n const { channel, orientation } = useSliderOf(\"ChannelSliderThumb\")\n const controller = useColorPicker(\"ChannelSliderThumb\")\n return usePart(controller.channelSliderThumb(channel, orientation), \"div\", props)\n}\n\nexport type ChannelInputProps = PartComponentProps<\n \"input\",\n StateOf<Parts[\"channelInput\"]>,\n {\n /** The channel it is typed in, or `hex` for the whole colour. */\n channel: ColorPickerInputChannel\n }\n>\n\n// Its text is the core's own, written as the colour changes: given to React as a default.\nfunction ChannelInput({ channel, ...props }: ChannelInputProps): ReactElement {\n const controller = useColorPicker(\"ChannelInput\")\n return usePart(useOwnText(controller.channelInput(channel)), \"input\", props)\n}\n\nexport type SwatchProps = PartComponentProps<\"div\", StateOf<Parts[\"swatch\"]>>\n\nconst Swatch = (props: SwatchProps) => usePart(useColorPicker(\"Swatch\").swatch, \"div\", props)\n\nexport type SwatchTriggerProps = PartComponentProps<\n \"button\",\n StateOf<Parts[\"swatchTrigger\"]>,\n {\n /** The preset's colour, in any format: pressed, the colour is this one. */\n value: string\n }\n>\n\nfunction SwatchTrigger({ value, ...props }: SwatchTriggerProps): ReactElement {\n return usePart(useColorPicker(\"SwatchTrigger\").swatchTrigger(value), \"button\", props)\n}\n\nexport type EyeDropperTriggerProps = PartComponentProps<\n \"button\",\n StateOf<Parts[\"eyeDropperTrigger\"]>\n>\n\nconst EyeDropperTrigger = (props: EyeDropperTriggerProps) =>\n usePart(useColorPicker(\"EyeDropperTrigger\").eyeDropperTrigger, \"button\", props)\n\nexport type ValueTextProps = PartComponentProps<\"span\", StateOf<Parts[\"valueText\"]>>\n\n/** Says the colour in its format unless it is given children. */\nfunction ValueText(props: ValueTextProps): ReactElement {\n const controller = useColorPicker(\"ValueText\")\n const text = useSignal(controller.text)\n return usePart(controller.valueText, \"span\", { ...props, children: props.children ?? text })\n}\n\nexport type FormatTriggerProps = PartComponentProps<\"button\", StateOf<Parts[\"formatTrigger\"]>>\n\n/** Says the format the colour is written in unless it is given children. */\nfunction FormatTrigger(props: FormatTriggerProps): ReactElement {\n const controller = useColorPicker(\"FormatTrigger\")\n const format = useSignal(controller.format)\n return usePart(controller.formatTrigger, \"button\", {\n ...props,\n children: props.children ?? format,\n })\n}\n\nexport const ColorPicker = /* @__PURE__ */ parts(\"ColorPicker\", {\n Root,\n Area,\n AreaThumb,\n ChannelSlider,\n ChannelSliderTrack,\n ChannelSliderThumb,\n ChannelInput,\n Swatch,\n SwatchTrigger,\n EyeDropperTrigger,\n ValueText,\n FormatTrigger,\n})\n"],"mappings":";;;;;;;;AAoBA,MAAM,UAAU,cAAiC,IAAI;AAOrD,MAAM,gBAAgB,cAA+B,IAAI;AAEzD,SAAS,eAAe,MAA0B;CAChD,MAAM,aAAa,WAAW,OAAO;CACrC,IAAI,CAAC,YAAY,MAAM,IAAI,MAAM,gBAAgB,KAAK,oCAAoC;CAC1F,OAAO;AACT;AAEA,SAAS,YAAY,MAAwB;CAC3C,MAAM,SAAS,WAAW,aAAa;CACvC,IAAI,CAAC,QAAQ,MAAM,IAAI,MAAM,gBAAgB,KAAK,6CAA6C;CAC/F,OAAO;AACT;AAQA,SAAS,KAAK,EACZ,OACA,cACA,eACA,kBACA,QACA,eACA,gBACA,OACA,gBACA,UACA,UACA,UACA,MACA,MACA,kBACA,IACA,GAAG,QACuB;CAC1B,MAAM,QAAQ,WAAW,YAAY,KAAK,KAAA;CAC1C,MAAM,YAAY,WAAW,gBAAgB,KAAK,KAAA;CAClD,MAAM,SAAS,OAAO,mBAAmB;EAAE;EAAO;CAAU,CAAC;CAC7D,MAAM,aAAyB,cAAc,QAAQ;EACnD;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;GAAO,KAAI;EAAS,CAAA,CAChD,EAAA,CAAA,CACH;CACe,CAAA;AAEtB;AAKA,MAAM,QAAQ,UAAqB,QAAQ,eAAe,MAAM,CAAC,CA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,QAAQ;EAAE,GAAG;EAAO,UAAU,MAAM,YAAY;CAAK,CAAC;AAC7F;;AAKA,SAAS,cAAc,OAAyC;CAC9D,MAAM,aAAa,eAAe,eAAe;CACjD,MAAM,SAAS,UAAU,WAAW,MAAM;CAC1C,OAAO,QAAQ,WAAW,eAAe,UAAU;EACjD,GAAG;EACH,UAAU,MAAM,YAAY;CAC9B,CAAC;AACH;AAEA,MAAa,cAA8B,sBAAM,eAAe;CAC9D;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC"}
|
package/src/combobox.d.ts
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
import { PartComponentProps, PortalProps, PositionerOptions } from "./runtime.js";
|
|
2
|
-
import { StateOf } from "@kirana-ui/core";
|
|
3
2
|
import { ReactElement, ReactNode } from "react";
|
|
3
|
+
import { StateOf } from "@kirana-ui/core";
|
|
4
4
|
import { AutocompleteProps } from "@kirana-ui/core/autocomplete";
|
|
5
5
|
import { ComboboxEntry, ComboboxProps } from "@kirana-ui/core/combobox";
|
|
6
6
|
import { Vocabulary } from "@kirana-ui/core/vocabulary";
|
|
7
7
|
type Parts = Vocabulary["combobox"];
|
|
8
|
-
/**
|
|
9
|
-
|
|
8
|
+
/**
|
|
9
|
+
* `Value` is what tells an item from the others. `Multiple` is inferred from `multiple`: with
|
|
10
|
+
* `multiple`, `value`, `defaultValue` and `onValueChange` hold a list of them.
|
|
11
|
+
*/
|
|
12
|
+
export type RootProps<Value = unknown, Multiple extends boolean | undefined = false> = Omit<ComboboxProps<Value, Multiple>, "id" | "multiple"> & {
|
|
13
|
+
/** Several values: `value`, `defaultValue` and `onValueChange` then hold a list. Read once. */
|
|
14
|
+
multiple?: Multiple | undefined;
|
|
10
15
|
id?: string;
|
|
11
16
|
children?: ReactNode;
|
|
12
17
|
};
|
|
13
|
-
declare function Root<Value = unknown>({ children, ...props }: RootProps<Value>): ReactElement;
|
|
18
|
+
declare function Root<Value = unknown, Multiple extends boolean | undefined = false>({ children, ...props }: RootProps<Value, Multiple>): ReactElement;
|
|
14
19
|
export type InputProps = PartComponentProps<"input", StateOf<Parts["input"]>>;
|
|
15
20
|
export type TriggerProps = PartComponentProps<"button", StateOf<Parts["trigger"]>>;
|
|
16
21
|
export type PopupProps = PartComponentProps<"div", StateOf<Parts["popup"]>>;
|
|
@@ -18,6 +23,9 @@ export type ListProps = PartComponentProps<"div", StateOf<Parts["list"]>>;
|
|
|
18
23
|
declare const Input: (props: InputProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
19
24
|
declare const Trigger: (props: TriggerProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
20
25
|
declare const Popup: (props: PopupProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
26
|
+
export type BackdropProps = PartComponentProps<"div", StateOf<Parts["backdrop"]>>;
|
|
27
|
+
/** What lies over the page behind the list: a sheet's (`presentation`) is modal. */
|
|
28
|
+
declare const Backdrop: (props: BackdropProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
21
29
|
/**
|
|
22
30
|
* The items' own box inside the popup, when the popup holds more than items (an input): it
|
|
23
31
|
* is then the listbox.
|
|
@@ -126,6 +134,7 @@ export declare const Combobox: {
|
|
|
126
134
|
readonly Chip: typeof Chip;
|
|
127
135
|
readonly ChipRemove: typeof ChipRemove;
|
|
128
136
|
readonly Portal: typeof Portal;
|
|
137
|
+
readonly Backdrop: typeof Backdrop;
|
|
129
138
|
readonly Positioner: typeof Positioner;
|
|
130
139
|
readonly Popup: typeof Popup;
|
|
131
140
|
readonly List: typeof List;
|
package/src/combobox.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { DirectionContext } from "./direction-context.js";
|
|
1
2
|
import { FieldContext } from "./field-context.js";
|
|
2
|
-
import { PartElement, Portal as Portal$1, parts, useController, useOptions, useOwnText, usePart, usePositioning, useSignal } from "./runtime.js";
|
|
3
|
-
import { within } from "@kirana-ui/core";
|
|
3
|
+
import { PartElement, Portal as Portal$1, parts, useController, useMount, useOptions, useOwnText, usePart, usePositioning, useSignal } from "./runtime.js";
|
|
4
4
|
import { Fragment, createContext, useContext, useId, useMemo } from "react";
|
|
5
|
+
import { within } from "@kirana-ui/core";
|
|
5
6
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
6
7
|
import { createAutocomplete } from "@kirana-ui/core/autocomplete";
|
|
7
8
|
import { createCombobox } from "@kirana-ui/core/combobox";
|
|
@@ -15,7 +16,11 @@ function useCombobox(part) {
|
|
|
15
16
|
}
|
|
16
17
|
function Root({ children, ...props }) {
|
|
17
18
|
const field = useContext(FieldContext) ?? void 0;
|
|
18
|
-
const
|
|
19
|
+
const direction = useContext(DirectionContext) ?? void 0;
|
|
20
|
+
const controller = useController(within(createCombobox, {
|
|
21
|
+
field,
|
|
22
|
+
direction
|
|
23
|
+
}), props);
|
|
19
24
|
const named = useSignal(controller.named);
|
|
20
25
|
return /* @__PURE__ */ jsxs(Context.Provider, {
|
|
21
26
|
value: controller,
|
|
@@ -26,6 +31,8 @@ const HiddenInput = () => usePart(useCombobox("Root").hidden, "input", {});
|
|
|
26
31
|
const Input = (props) => usePart(useOwnText(useCombobox("Input").input), "input", props);
|
|
27
32
|
const Trigger = (props) => usePart(useCombobox("Trigger").trigger, "button", props);
|
|
28
33
|
const Popup = (props) => usePart(useCombobox("Popup").popup, "div", props);
|
|
34
|
+
/** What lies over the page behind the list: a sheet's (`presentation`) is modal. */
|
|
35
|
+
const Backdrop = (props) => usePart(useCombobox("Backdrop").backdrop, "div", props);
|
|
29
36
|
/**
|
|
30
37
|
* The items' own box inside the popup, when the popup holds more than items (an input): it
|
|
31
38
|
* is then the listbox.
|
|
@@ -85,9 +92,9 @@ function Item({ value, disabled, label, id, index, ...props }) {
|
|
|
85
92
|
function ItemIndicator({ keepMounted, ...props }) {
|
|
86
93
|
const controller = useCombobox("ItemIndicator");
|
|
87
94
|
const value = useContext(ItemContext);
|
|
88
|
-
const selected = useSignal(controller.selected(value));
|
|
89
95
|
const part = useMemo(() => controller.itemIndicator(value), [controller, value]);
|
|
90
|
-
|
|
96
|
+
useMount(part);
|
|
97
|
+
return useSignal(part.mounted) || keepMounted ? /* @__PURE__ */ jsx(PartElement, {
|
|
91
98
|
of: part,
|
|
92
99
|
tag: "span",
|
|
93
100
|
...props
|
|
@@ -176,6 +183,7 @@ const Combobox = /* @__PURE__ */ parts("Combobox", {
|
|
|
176
183
|
Chip,
|
|
177
184
|
ChipRemove,
|
|
178
185
|
Portal,
|
|
186
|
+
Backdrop,
|
|
179
187
|
Positioner,
|
|
180
188
|
Popup,
|
|
181
189
|
List,
|
package/src/combobox.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"combobox.js","names":["BodyPortal"],"sources":["../../../../packages/react/src/combobox.tsx"],"sourcesContent":["import { within } from \"@kirana-ui/core\"\nimport type { StateOf } from \"@kirana-ui/core\"\nimport { createAutocomplete } from \"@kirana-ui/core/autocomplete\"\nimport type { AutocompleteProps } from \"@kirana-ui/core/autocomplete\"\nimport { createCombobox } from \"@kirana-ui/core/combobox\"\nimport type {\n Combobox as Controller,\n ComboboxEntry,\n ComboboxGroup,\n ComboboxProps,\n} from \"@kirana-ui/core/combobox\"\nimport type { Vocabulary } from \"@kirana-ui/core/vocabulary\"\nimport { createContext, Fragment, useContext, useId, useMemo } from \"react\"\nimport type { ReactElement, ReactNode } from \"react\"\n\nimport { FieldContext } from \"./field-context.ts\"\nimport {\n Portal as BodyPortal,\n PartElement,\n parts,\n useController,\n useOptions,\n useOwnText,\n usePart,\n usePositioning,\n useSignal,\n} from \"./runtime.tsx\"\nimport type { PartComponentProps, PortalProps, PositionerOptions } from \"./runtime.tsx\"\n\nexport type { PortalProps }\n\ntype Parts = Vocabulary[\"combobox\"]\n\nconst Context = createContext<Controller | null>(null)\nconst ItemContext = createContext<unknown>(undefined)\n\nfunction useCombobox(part: string): Controller {\n const controller = useContext(Context)\n if (!controller) throw new Error(`<Combobox.${part}> must be inside <Combobox.Root>`)\n return controller\n}\n\n/** `Value` is what tells an item from the others: the type of `value`, and of `values`' entries. */\nexport type RootProps<Value = unknown> = Omit<ComboboxProps<Value>, \"id\"> & {\n id?: string\n children?: ReactNode\n}\n\nfunction Root<Value = unknown>({ children, ...props }: RootProps<Value>): ReactElement {\n const field = useContext(FieldContext) ?? undefined\n const controller: Controller = useController<ComboboxProps<Value>, Controller<Value>>(\n within(createCombobox<Value>, { field }),\n props\n )\n const named = useSignal(controller.named)\n return (\n <Context.Provider value={controller}>\n {children}\n {named ? <HiddenInput /> : null}\n </Context.Provider>\n )\n}\n\nexport type InputProps = PartComponentProps<\"input\", StateOf<Parts[\"input\"]>>\nexport type TriggerProps = PartComponentProps<\"button\", StateOf<Parts[\"trigger\"]>>\nexport type PopupProps = PartComponentProps<\"div\", StateOf<Parts[\"popup\"]>>\nexport type ListProps = PartComponentProps<\"div\", StateOf<Parts[\"list\"]>>\n\nconst HiddenInput = () => usePart(useCombobox(\"Root\").hidden, \"input\", {})\nconst Input = (props: InputProps) => usePart(useOwnText(useCombobox(\"Input\").input), \"input\", props)\nconst Trigger = (props: TriggerProps) => usePart(useCombobox(\"Trigger\").trigger, \"button\", props)\nconst Popup = (props: PopupProps) => usePart(useCombobox(\"Popup\").popup, \"div\", props)\n/**\n * The items' own box inside the popup, when the popup holds more than items (an input): it\n * is then the listbox.\n */\nconst List = (props: ListProps) => usePart(useCombobox(\"List\").list, \"div\", props)\n\nfunction Portal({ children }: PortalProps): ReactElement | null {\n const mounted = useSignal(useCombobox(\"Portal\").mounted)\n return mounted ? <BodyPortal>{children}</BodyPortal> : null\n}\n\nexport type PositionerProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"positioner\"]>,\n PositionerOptions\n>\n\nfunction Positioner(props: PositionerProps): ReactElement {\n const controller = useCombobox(\"Positioner\")\n return usePart(controller.positioner, \"div\", usePositioning(controller.positioning, props))\n}\n\nconst GroupContext = createContext<ComboboxGroup | null>(null)\n\nexport type GroupProps = PartComponentProps<\"div\", StateOf<Parts[\"group\"]>, { id?: string }>\n\n/** Items that belong together, named by their `GroupLabel`. Hidden while none is shown. */\nfunction Group({ id, ...props }: GroupProps): ReactElement {\n const controller = useCombobox(\"Group\")\n const generated = useId()\n const group = useMemo(() => controller.group(id ?? generated), [controller, id, generated])\n return (\n <GroupContext.Provider value={group}>{usePart(group.root, \"div\", props)}</GroupContext.Provider>\n )\n}\n\nexport type GroupLabelProps = PartComponentProps<\"div\", StateOf<Parts[\"groupLabel\"]>>\n\n/** A group's name. Outside a group it is plain text, and names nothing. */\nfunction GroupLabel(props: GroupLabelProps): ReactElement {\n const lone = useCombobox(\"GroupLabel\").groupLabel\n return usePart(useContext(GroupContext)?.label ?? lone, \"div\", props)\n}\n\nexport type SeparatorProps = PartComponentProps<\"div\", StateOf<Parts[\"separator\"]>>\n\n/** A line between groups. */\nconst Separator = (props: SeparatorProps) =>\n usePart(useCombobox(\"Separator\").separator, \"div\", props)\n\nexport type ItemProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"item\"]>,\n {\n /** What the combobox's value is while this item is chosen. */\n value: unknown\n /** Disables this item: it cannot be chosen, and the arrows pass over it. */\n disabled?: boolean\n /** What is filtered and what the input shows; the item's text when left out. */\n label?: string\n id?: string\n /** Its place among all the rows, in a virtualized list. */\n index?: number\n }\n>\n\nfunction Item({ value, disabled, label, id, index, ...props }: ItemProps): ReactElement {\n const controller = useCombobox(\"Item\")\n const group = useContext(GroupContext) ?? undefined\n const generated = useId()\n const options = useOptions({ disabled, label, index, id: id ?? generated })\n const part = useMemo(\n () => controller.item(value, () => options.get(), group),\n [controller, value, options, group]\n )\n return <ItemContext.Provider value={value}>{usePart(part, \"div\", props)}</ItemContext.Provider>\n}\n\nexport type ItemIndicatorProps = PartComponentProps<\n \"span\",\n StateOf<Parts[\"itemIndicator\"]>,\n {\n /** Keeps the mark in the page while its item is not chosen. */\n keepMounted?: boolean\n }\n>\n\n/** In the page while its item is a chosen one. */\nfunction ItemIndicator({ keepMounted, ...props }: ItemIndicatorProps): ReactElement | null {\n const controller = useCombobox(\"ItemIndicator\")\n const value = useContext(ItemContext)\n const selected = useSignal(controller.selected(value))\n const part = useMemo(() => controller.itemIndicator(value), [controller, value])\n return selected || keepMounted ? <PartElement of={part} tag=\"span\" {...props} /> : null\n}\n\nexport type ClearProps = PartComponentProps<\n \"button\",\n StateOf<Parts[\"clear\"]>,\n {\n /** Keeps the button in the page while there is nothing to clear. */\n keepMounted?: boolean\n }\n>\n\n/** A button that empties the input and the value. Drawn while there is something to clear. */\nfunction Clear({ keepMounted, ...props }: ClearProps): ReactElement | null {\n const controller = useCombobox(\"Clear\")\n const clearable = useSignal(controller.clearable)\n return clearable || keepMounted ? (\n <PartElement of={controller.clear} tag=\"button\" {...props} />\n ) : null\n}\n\nexport type ChipsProps = PartComponentProps<\"div\", StateOf<Parts[\"chips\"]>>\n\n/** With `multiple`: what holds the chips and the input. */\nconst Chips = (props: ChipsProps) => usePart(useCombobox(\"Chips\").chips, \"div\", props)\n\nconst ChipContext = createContext<unknown>(undefined)\n\nexport type ChipProps = PartComponentProps<\n \"span\",\n StateOf<Parts[\"chip\"]>,\n {\n /** The chosen value this chip stands for. */\n value: unknown\n }\n>\n\n/** With `multiple`: one chosen value. Its `value` is what its remove button takes away. */\nfunction Chip({ value, ...props }: ChipProps): ReactElement {\n const controller = useCombobox(\"Chip\")\n const part = useMemo(() => controller.chip(value), [controller, value])\n return <ChipContext.Provider value={value}>{usePart(part, \"span\", props)}</ChipContext.Provider>\n}\n\nexport type ChipRemoveProps = PartComponentProps<\"button\", StateOf<Parts[\"chipRemove\"]>>\n\nfunction ChipRemove(props: ChipRemoveProps): ReactElement {\n const controller = useCombobox(\"ChipRemove\")\n const value = useContext(ChipContext)\n const part = useMemo(() => controller.chipRemove(value), [controller, value])\n return usePart(part, \"button\", props)\n}\n\nexport type EmptyProps = PartComponentProps<\"div\", StateOf<Parts[\"empty\"]>>\n\n/** Drawn while no item is shown for what was typed. */\nfunction Empty(props: EmptyProps): ReactElement | null {\n const controller = useCombobox(\"Empty\")\n const empty = useSignal(controller.empty)\n return empty ? <PartElement of={controller.emptyPart} tag=\"div\" {...props} /> : null\n}\n\nexport type StatusProps = PartComponentProps<\"div\", StateOf<Parts[\"status\"]>>\n\n/**\n * Says how the list stands (\"3 results\", \"Loading\") to software that reads the page, as its\n * text changes. Keep it in the page and change what it holds: inside the popup, or beside the\n * input.\n */\nconst Status = (props: StatusProps) => usePart(useCombobox(\"Status\").status, \"div\", props)\n\nexport type ValueProps<Chosen = unknown> = {\n /** Shown while nothing is chosen. */\n placeholder?: ReactNode\n /**\n * What to show in place of the label. A function is given the value and its label (`null`\n * and `undefined` while nothing is chosen); with `multiple`, the values and their labels, in\n * the order they were chosen.\n */\n children?:\n | ReactNode\n | ((\n value: Chosen,\n label: Chosen extends readonly unknown[] ? readonly string[] : string | undefined\n ) => ReactNode)\n}\n\n/**\n * The chosen value's label, or `placeholder` while nothing is chosen; with `multiple`, the\n * chosen labels with commas between. For a button that is the combobox, its input inside the\n * popup. It draws no element.\n */\nfunction Value<Chosen = unknown>({ placeholder, children }: ValueProps<Chosen>): ReactElement {\n const controller = useCombobox(\"Value\")\n const shown = useSignal(controller.shown)\n if (typeof children !== \"function\") return <>{children ?? shown.label ?? placeholder}</>\n const draw = children as (value: unknown, label: unknown) => ReactNode\n return (\n <>{controller.multiple ? draw(shown.values, shown.labels) : draw(shown.value, shown.label)}</>\n )\n}\n\nexport type CollectionProps<Value = unknown> = {\n /** A group the root's `items` gave: its items left are then what is drawn. */\n of?: ComboboxEntry<Value> | undefined\n /** Drawn once for each item left, or for each group that has items left. */\n children: (entry: ComboboxEntry<Value>) => ReactNode\n}\n\n/**\n * Draws the list from the root's `items`: its child once for each item left for what was\n * typed, or for each group that has items left; with `of`, for each of that group's. The root\n * then filters, and no item hides itself. It draws no element.\n */\nfunction Collection<Value = unknown>({ of, children }: CollectionProps<Value>): ReactElement {\n // The same signal each time it is asked for: a group's is kept by its key.\n const controller = useCombobox(\"Collection\") as unknown as Controller<Value>\n const entries = useSignal(controller.entries(of))\n return (\n <>\n {entries.map((entry) => (\n <Fragment key={entry.key}>{children(entry)}</Fragment>\n ))}\n </>\n )\n}\n\nexport type AutocompleteRootProps = Omit<AutocompleteProps, \"id\"> & {\n id?: string\n children?: ReactNode\n}\n\n/** A combobox whose text is the value: the list only suggests. */\nfunction AutocompleteRoot({ children, ...props }: AutocompleteRootProps): ReactElement {\n const field = useContext(FieldContext) ?? undefined\n const controller = useController<AutocompleteProps, Controller>(\n within(createAutocomplete, { field }),\n props\n )\n return <Context.Provider value={controller}>{children}</Context.Provider>\n}\n\nexport const Combobox = /* @__PURE__ */ parts(\"Combobox\", {\n Root,\n Input,\n Trigger,\n Value,\n Clear,\n Chips,\n Chip,\n ChipRemove,\n Portal,\n Positioner,\n Popup,\n List,\n Collection,\n Group,\n GroupLabel,\n Separator,\n Item,\n ItemIndicator,\n Empty,\n Status,\n})\n\nexport const Autocomplete = /* @__PURE__ */ parts(\"Autocomplete\", {\n Root: AutocompleteRoot,\n Input,\n Trigger,\n Clear,\n Portal,\n Positioner,\n Popup,\n List,\n Collection,\n Group,\n GroupLabel,\n Separator,\n Item,\n Empty,\n Status,\n})\n"],"mappings":";;;;;;;;AAiCA,MAAM,UAAU,cAAiC,IAAI;AACrD,MAAM,cAAc,cAAuB,KAAA,CAAS;AAEpD,SAAS,YAAY,MAA0B;CAC7C,MAAM,aAAa,WAAW,OAAO;CACrC,IAAI,CAAC,YAAY,MAAM,IAAI,MAAM,aAAa,KAAK,iCAAiC;CACpF,OAAO;AACT;AAQA,SAAS,KAAsB,EAAE,UAAU,GAAG,SAAyC;CACrF,MAAM,QAAQ,WAAW,YAAY,KAAK,KAAA;CAC1C,MAAM,aAAyB,cAC7B,OAAO,gBAAuB,EAAE,MAAM,CAAC,GACvC,KACF;CACA,MAAM,QAAQ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,SAAS,KAAK,EAAY,GAAtC,MAAM,GAAgC,CACtD,EACD,CAAA;AAEN;;AAQA,SAAS,iBAAiB,EAAE,UAAU,GAAG,SAA8C;CACrF,MAAM,QAAQ,WAAW,YAAY,KAAK,KAAA;CAC1C,MAAM,aAAa,cACjB,OAAO,oBAAoB,EAAE,MAAM,CAAC,GACpC,KACF;CACA,OAAO,oBAAC,QAAQ,UAAT;EAAkB,OAAO;EAAa;CAA2B,CAAA;AAC1E;AAEA,MAAa,WAA2B,sBAAM,YAAY;CACxD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,MAAa,eAA+B,sBAAM,gBAAgB;CAChE,MAAM;CACN;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC"}
|
|
1
|
+
{"version":3,"file":"combobox.js","names":["BodyPortal"],"sources":["../../../../packages/react/src/combobox.tsx"],"sourcesContent":["import { within } from \"@kirana-ui/core\"\nimport type { StateOf } from \"@kirana-ui/core\"\nimport { createAutocomplete } from \"@kirana-ui/core/autocomplete\"\nimport type { AutocompleteProps } from \"@kirana-ui/core/autocomplete\"\nimport { createCombobox } from \"@kirana-ui/core/combobox\"\nimport type {\n Combobox as Controller,\n ComboboxEntry,\n ComboboxGroup,\n ComboboxProps,\n} from \"@kirana-ui/core/combobox\"\nimport type { Vocabulary } from \"@kirana-ui/core/vocabulary\"\nimport { createContext, Fragment, useContext, useId, useMemo } from \"react\"\nimport type { ReactElement, ReactNode } from \"react\"\n\nimport { DirectionContext } from \"./direction-context.ts\"\nimport { FieldContext } from \"./field-context.ts\"\nimport {\n Portal as BodyPortal,\n PartElement,\n parts,\n useController,\n useMount,\n useOptions,\n useOwnText,\n usePart,\n usePositioning,\n useSignal,\n} from \"./runtime.tsx\"\nimport type { PartComponentProps, PortalProps, PositionerOptions } from \"./runtime.tsx\"\n\nexport type { PortalProps }\n\ntype Parts = Vocabulary[\"combobox\"]\n\nconst Context = createContext<Controller | null>(null)\nconst ItemContext = createContext<unknown>(undefined)\n\nfunction useCombobox(part: string): Controller {\n const controller = useContext(Context)\n if (!controller) throw new Error(`<Combobox.${part}> must be inside <Combobox.Root>`)\n return controller\n}\n\n/**\n * `Value` is what tells an item from the others. `Multiple` is inferred from `multiple`: with\n * `multiple`, `value`, `defaultValue` and `onValueChange` hold a list of them.\n */\nexport type RootProps<Value = unknown, Multiple extends boolean | undefined = false> = Omit<\n ComboboxProps<Value, Multiple>,\n \"id\" | \"multiple\"\n> & {\n /** Several values: `value`, `defaultValue` and `onValueChange` then hold a list. Read once. */\n multiple?: Multiple | undefined\n id?: string\n children?: ReactNode\n}\n\nfunction Root<Value = unknown, Multiple extends boolean | undefined = false>({\n children,\n ...props\n}: RootProps<Value, Multiple>): ReactElement {\n const field = useContext(FieldContext) ?? undefined\n const direction = useContext(DirectionContext) ?? undefined\n const controller: Controller = useController<ComboboxProps<Value, Multiple>, Controller<Value>>(\n within(createCombobox<Value, Multiple>, { field, direction }),\n props\n )\n const named = useSignal(controller.named)\n return (\n <Context.Provider value={controller}>\n {children}\n {named ? <HiddenInput /> : null}\n </Context.Provider>\n )\n}\n\nexport type InputProps = PartComponentProps<\"input\", StateOf<Parts[\"input\"]>>\nexport type TriggerProps = PartComponentProps<\"button\", StateOf<Parts[\"trigger\"]>>\nexport type PopupProps = PartComponentProps<\"div\", StateOf<Parts[\"popup\"]>>\nexport type ListProps = PartComponentProps<\"div\", StateOf<Parts[\"list\"]>>\n\nconst HiddenInput = () => usePart(useCombobox(\"Root\").hidden, \"input\", {})\nconst Input = (props: InputProps) => usePart(useOwnText(useCombobox(\"Input\").input), \"input\", props)\nconst Trigger = (props: TriggerProps) => usePart(useCombobox(\"Trigger\").trigger, \"button\", props)\nconst Popup = (props: PopupProps) => usePart(useCombobox(\"Popup\").popup, \"div\", props)\nexport type BackdropProps = PartComponentProps<\"div\", StateOf<Parts[\"backdrop\"]>>\n/** What lies over the page behind the list: a sheet's (`presentation`) is modal. */\nconst Backdrop = (props: BackdropProps) => usePart(useCombobox(\"Backdrop\").backdrop, \"div\", props)\n/**\n * The items' own box inside the popup, when the popup holds more than items (an input): it\n * is then the listbox.\n */\nconst List = (props: ListProps) => usePart(useCombobox(\"List\").list, \"div\", props)\n\nfunction Portal({ children }: PortalProps): ReactElement | null {\n const mounted = useSignal(useCombobox(\"Portal\").mounted)\n return mounted ? <BodyPortal>{children}</BodyPortal> : null\n}\n\nexport type PositionerProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"positioner\"]>,\n PositionerOptions\n>\n\nfunction Positioner(props: PositionerProps): ReactElement {\n const controller = useCombobox(\"Positioner\")\n return usePart(controller.positioner, \"div\", usePositioning(controller.positioning, props))\n}\n\nconst GroupContext = createContext<ComboboxGroup | null>(null)\n\nexport type GroupProps = PartComponentProps<\"div\", StateOf<Parts[\"group\"]>, { id?: string }>\n\n/** Items that belong together, named by their `GroupLabel`. Hidden while none is shown. */\nfunction Group({ id, ...props }: GroupProps): ReactElement {\n const controller = useCombobox(\"Group\")\n const generated = useId()\n const group = useMemo(() => controller.group(id ?? generated), [controller, id, generated])\n return (\n <GroupContext.Provider value={group}>{usePart(group.root, \"div\", props)}</GroupContext.Provider>\n )\n}\n\nexport type GroupLabelProps = PartComponentProps<\"div\", StateOf<Parts[\"groupLabel\"]>>\n\n/** A group's name. Outside a group it is plain text, and names nothing. */\nfunction GroupLabel(props: GroupLabelProps): ReactElement {\n const lone = useCombobox(\"GroupLabel\").groupLabel\n return usePart(useContext(GroupContext)?.label ?? lone, \"div\", props)\n}\n\nexport type SeparatorProps = PartComponentProps<\"div\", StateOf<Parts[\"separator\"]>>\n\n/** A line between groups. */\nconst Separator = (props: SeparatorProps) =>\n usePart(useCombobox(\"Separator\").separator, \"div\", props)\n\nexport type ItemProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"item\"]>,\n {\n /** What the combobox's value is while this item is chosen. */\n value: unknown\n /** Disables this item: it cannot be chosen, and the arrows pass over it. */\n disabled?: boolean\n /** What is filtered and what the input shows; the item's text when left out. */\n label?: string\n id?: string\n /** Its place among all the rows, in a virtualized list. */\n index?: number\n }\n>\n\nfunction Item({ value, disabled, label, id, index, ...props }: ItemProps): ReactElement {\n const controller = useCombobox(\"Item\")\n const group = useContext(GroupContext) ?? undefined\n const generated = useId()\n const options = useOptions({ disabled, label, index, id: id ?? generated })\n const part = useMemo(\n () => controller.item(value, () => options.get(), group),\n [controller, value, options, group]\n )\n return <ItemContext.Provider value={value}>{usePart(part, \"div\", props)}</ItemContext.Provider>\n}\n\nexport type ItemIndicatorProps = PartComponentProps<\n \"span\",\n StateOf<Parts[\"itemIndicator\"]>,\n {\n /** Keeps the mark in the page while its item is not chosen. */\n keepMounted?: boolean\n }\n>\n\n/** In the page while its item is a chosen one. */\nfunction ItemIndicator({ keepMounted, ...props }: ItemIndicatorProps): ReactElement | null {\n const controller = useCombobox(\"ItemIndicator\")\n const value = useContext(ItemContext)\n const part = useMemo(() => controller.itemIndicator(value), [controller, value])\n // In the page while chosen, and through its exit.\n useMount(part)\n const mounted = useSignal(part.mounted)\n return mounted || keepMounted ? <PartElement of={part} tag=\"span\" {...props} /> : null\n}\n\nexport type ClearProps = PartComponentProps<\n \"button\",\n StateOf<Parts[\"clear\"]>,\n {\n /** Keeps the button in the page while there is nothing to clear. */\n keepMounted?: boolean\n }\n>\n\n/** A button that empties the input and the value. Drawn while there is something to clear. */\nfunction Clear({ keepMounted, ...props }: ClearProps): ReactElement | null {\n const controller = useCombobox(\"Clear\")\n const clearable = useSignal(controller.clearable)\n return clearable || keepMounted ? (\n <PartElement of={controller.clear} tag=\"button\" {...props} />\n ) : null\n}\n\nexport type ChipsProps = PartComponentProps<\"div\", StateOf<Parts[\"chips\"]>>\n\n/** With `multiple`: what holds the chips and the input. */\nconst Chips = (props: ChipsProps) => usePart(useCombobox(\"Chips\").chips, \"div\", props)\n\nconst ChipContext = createContext<unknown>(undefined)\n\nexport type ChipProps = PartComponentProps<\n \"span\",\n StateOf<Parts[\"chip\"]>,\n {\n /** The chosen value this chip stands for. */\n value: unknown\n }\n>\n\n/** With `multiple`: one chosen value. Its `value` is what its remove button takes away. */\nfunction Chip({ value, ...props }: ChipProps): ReactElement {\n const controller = useCombobox(\"Chip\")\n const part = useMemo(() => controller.chip(value), [controller, value])\n return <ChipContext.Provider value={value}>{usePart(part, \"span\", props)}</ChipContext.Provider>\n}\n\nexport type ChipRemoveProps = PartComponentProps<\"button\", StateOf<Parts[\"chipRemove\"]>>\n\nfunction ChipRemove(props: ChipRemoveProps): ReactElement {\n const controller = useCombobox(\"ChipRemove\")\n const value = useContext(ChipContext)\n const part = useMemo(() => controller.chipRemove(value), [controller, value])\n return usePart(part, \"button\", props)\n}\n\nexport type EmptyProps = PartComponentProps<\"div\", StateOf<Parts[\"empty\"]>>\n\n/** Drawn while no item is shown for what was typed. */\nfunction Empty(props: EmptyProps): ReactElement | null {\n const controller = useCombobox(\"Empty\")\n const empty = useSignal(controller.empty)\n return empty ? <PartElement of={controller.emptyPart} tag=\"div\" {...props} /> : null\n}\n\nexport type StatusProps = PartComponentProps<\"div\", StateOf<Parts[\"status\"]>>\n\n/**\n * Says how the list stands (\"3 results\", \"Loading\") to software that reads the page, as its\n * text changes. Keep it in the page and change what it holds: inside the popup, or beside the\n * input.\n */\nconst Status = (props: StatusProps) => usePart(useCombobox(\"Status\").status, \"div\", props)\n\nexport type ValueProps<Chosen = unknown> = {\n /** Shown while nothing is chosen. */\n placeholder?: ReactNode\n /**\n * What to show in place of the label. A function is given the value and its label (`null`\n * and `undefined` while nothing is chosen); with `multiple`, the values and their labels, in\n * the order they were chosen.\n */\n children?:\n | ReactNode\n | ((\n value: Chosen,\n label: Chosen extends readonly unknown[] ? readonly string[] : string | undefined\n ) => ReactNode)\n}\n\n/**\n * The chosen value's label, or `placeholder` while nothing is chosen; with `multiple`, the\n * chosen labels with commas between. For a button that is the combobox, its input inside the\n * popup. It draws no element.\n */\nfunction Value<Chosen = unknown>({ placeholder, children }: ValueProps<Chosen>): ReactElement {\n const controller = useCombobox(\"Value\")\n const shown = useSignal(controller.shown)\n if (typeof children !== \"function\") return <>{children ?? shown.label ?? placeholder}</>\n const draw = children as (value: unknown, label: unknown) => ReactNode\n return (\n <>{controller.multiple ? draw(shown.values, shown.labels) : draw(shown.value, shown.label)}</>\n )\n}\n\nexport type CollectionProps<Value = unknown> = {\n /** A group the root's `items` gave: its items left are then what is drawn. */\n of?: ComboboxEntry<Value> | undefined\n /** Drawn once for each item left, or for each group that has items left. */\n children: (entry: ComboboxEntry<Value>) => ReactNode\n}\n\n/**\n * Draws the list from the root's `items`: its child once for each item left for what was\n * typed, or for each group that has items left; with `of`, for each of that group's. The root\n * then filters, and no item hides itself. It draws no element.\n */\nfunction Collection<Value = unknown>({ of, children }: CollectionProps<Value>): ReactElement {\n // The same signal each time it is asked for: a group's is kept by its key.\n const controller = useCombobox(\"Collection\") as unknown as Controller<Value>\n const entries = useSignal(controller.entries(of))\n return (\n <>\n {entries.map((entry) => (\n <Fragment key={entry.key}>{children(entry)}</Fragment>\n ))}\n </>\n )\n}\n\nexport type AutocompleteRootProps = Omit<AutocompleteProps, \"id\"> & {\n id?: string\n children?: ReactNode\n}\n\n/** A combobox whose text is the value: the list only suggests. */\nfunction AutocompleteRoot({ children, ...props }: AutocompleteRootProps): ReactElement {\n const field = useContext(FieldContext) ?? undefined\n const controller = useController<AutocompleteProps, Controller>(\n within(createAutocomplete, { field }),\n props\n )\n return <Context.Provider value={controller}>{children}</Context.Provider>\n}\n\nexport const Combobox = /* @__PURE__ */ parts(\"Combobox\", {\n Root,\n Input,\n Trigger,\n Value,\n Clear,\n Chips,\n Chip,\n ChipRemove,\n Portal,\n Backdrop,\n Positioner,\n Popup,\n List,\n Collection,\n Group,\n GroupLabel,\n Separator,\n Item,\n ItemIndicator,\n Empty,\n Status,\n})\n\nexport const Autocomplete = /* @__PURE__ */ parts(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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 { CommandProps } from "@kirana-ui/core/command";
|
|
5
5
|
import { Vocabulary } from "@kirana-ui/core/vocabulary";
|
|
6
6
|
type Parts = Vocabulary["command"];
|
|
@@ -23,8 +23,8 @@ declare function Group({ id, ...props }: GroupProps): ReactElement;
|
|
|
23
23
|
export type GroupHeadingProps = PartComponentProps<"div", StateOf<Parts["groupHeading"]>>;
|
|
24
24
|
declare function GroupHeading(props: GroupHeadingProps): ReactElement;
|
|
25
25
|
export type ItemProps = PartComponentProps<"div", StateOf<Parts["item"]>, {
|
|
26
|
-
/** What `onSelect` is told. */
|
|
27
|
-
value
|
|
26
|
+
/** What `onSelect` is told; its `label`, or its text, when left out. */
|
|
27
|
+
value?: string;
|
|
28
28
|
/** Disables this item: it cannot be chosen, and the arrows pass over it. */
|
|
29
29
|
disabled?: boolean;
|
|
30
30
|
/** What is filtered; the item's text when left out. */
|
package/src/command.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command.js","names":[],"sources":["../../../../packages/react/src/command.tsx"],"sourcesContent":["import type { StateOf } from \"@kirana-ui/core\"\nimport { createCommand } from \"@kirana-ui/core/command\"\nimport type { CommandGroup, CommandProps, Command as Controller } from \"@kirana-ui/core/command\"\nimport type { Vocabulary } from \"@kirana-ui/core/vocabulary\"\nimport { createContext, useContext, useId, useMemo } from \"react\"\nimport type { ReactElement } from \"react\"\n\nimport {\n PartElement,\n parts,\n useController,\n useOptions,\n useOwnText,\n usePart,\n useSignal,\n} from \"./runtime.tsx\"\nimport type { PartComponentProps } from \"./runtime.tsx\"\n\ntype Parts = Vocabulary[\"command\"]\n\nconst Context = createContext<Controller | null>(null)\nconst GroupContext = createContext<CommandGroup | undefined>(undefined)\n\nfunction useCommand(part: string): Controller {\n const controller = useContext(Context)\n if (!controller) throw new Error(`<Command.${part}> must be inside <Command.Root>`)\n return controller\n}\n\nexport type RootProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"root\"]>,\n Omit<CommandProps, \"id\"> & { id?: string }\n>\n\nfunction Root({\n inputValue,\n defaultInputValue,\n onInputValueChange,\n onSelect,\n filter,\n loop,\n autoHighlight,\n disabled,\n id,\n ...rest\n}: RootProps): ReactElement {\n const controller = useController<CommandProps, Controller>(createCommand, {\n inputValue,\n defaultInputValue,\n onInputValueChange,\n onSelect,\n filter,\n loop,\n autoHighlight,\n disabled,\n id,\n })\n return (\n <Context.Provider value={controller}>\n <PartElement of={controller.root} tag=\"div\" {...rest} />\n </Context.Provider>\n )\n}\n\nexport type InputProps = PartComponentProps<\"input\", StateOf<Parts[\"input\"]>>\n\nconst Input = (props: InputProps) => usePart(useOwnText(useCommand(\"Input\").input), \"input\", props)\nexport type ListProps = PartComponentProps<\"div\", StateOf<Parts[\"list\"]>>\n\nconst List = (props: ListProps) => usePart(useCommand(\"List\").list, \"div\", props)\n\nexport type EmptyProps = PartComponentProps<\"div\", StateOf<Parts[\"empty\"]>>\n\n/** Drawn while no item is shown for what was typed. */\nfunction Empty(props: EmptyProps): ReactElement | null {\n const controller = useCommand(\"Empty\")\n const empty = useSignal(controller.empty)\n return empty ? <PartElement of={controller.emptyPart} tag=\"div\" {...props} /> : null\n}\n\nexport type GroupProps = PartComponentProps<\"div\", StateOf<Parts[\"group\"]>, { id?: string }>\n\n/** Items under a `<Command.GroupHeading>`. Hidden while none of them is shown. */\nfunction Group({ id, ...props }: GroupProps): ReactElement {\n const controller = useCommand(\"Group\")\n const generated = useId()\n const name = id ?? generated\n const group = useMemo(() => controller.group(name), [controller, name])\n return (\n <GroupContext.Provider value={group}>{usePart(group.part, \"div\", props)}</GroupContext.Provider>\n )\n}\n\nexport type GroupHeadingProps = PartComponentProps<\"div\", StateOf<Parts[\"groupHeading\"]>>\n\nfunction GroupHeading(props: GroupHeadingProps): ReactElement {\n const lone = useCommand(\"GroupHeading\").heading\n return usePart(useContext(GroupContext)?.heading ?? lone, \"div\", props)\n}\n\nexport type ItemProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"item\"]>,\n {\n /** What `onSelect` is told. */\n value
|
|
1
|
+
{"version":3,"file":"command.js","names":[],"sources":["../../../../packages/react/src/command.tsx"],"sourcesContent":["import type { StateOf } from \"@kirana-ui/core\"\nimport { createCommand } from \"@kirana-ui/core/command\"\nimport type { CommandGroup, CommandProps, Command as Controller } from \"@kirana-ui/core/command\"\nimport type { Vocabulary } from \"@kirana-ui/core/vocabulary\"\nimport { createContext, useContext, useId, useMemo } from \"react\"\nimport type { ReactElement } from \"react\"\n\nimport {\n PartElement,\n parts,\n useController,\n useOptions,\n useOwnText,\n usePart,\n useSignal,\n} from \"./runtime.tsx\"\nimport type { PartComponentProps } from \"./runtime.tsx\"\n\ntype Parts = Vocabulary[\"command\"]\n\nconst Context = createContext<Controller | null>(null)\nconst GroupContext = createContext<CommandGroup | undefined>(undefined)\n\nfunction useCommand(part: string): Controller {\n const controller = useContext(Context)\n if (!controller) throw new Error(`<Command.${part}> must be inside <Command.Root>`)\n return controller\n}\n\nexport type RootProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"root\"]>,\n Omit<CommandProps, \"id\"> & { id?: string }\n>\n\nfunction Root({\n inputValue,\n defaultInputValue,\n onInputValueChange,\n onSelect,\n filter,\n loop,\n autoHighlight,\n disabled,\n id,\n ...rest\n}: RootProps): ReactElement {\n const controller = useController<CommandProps, Controller>(createCommand, {\n inputValue,\n defaultInputValue,\n onInputValueChange,\n onSelect,\n filter,\n loop,\n autoHighlight,\n disabled,\n id,\n })\n return (\n <Context.Provider value={controller}>\n <PartElement of={controller.root} tag=\"div\" {...rest} />\n </Context.Provider>\n )\n}\n\nexport type InputProps = PartComponentProps<\"input\", StateOf<Parts[\"input\"]>>\n\nconst Input = (props: InputProps) => usePart(useOwnText(useCommand(\"Input\").input), \"input\", props)\nexport type ListProps = PartComponentProps<\"div\", StateOf<Parts[\"list\"]>>\n\nconst List = (props: ListProps) => usePart(useCommand(\"List\").list, \"div\", props)\n\nexport type EmptyProps = PartComponentProps<\"div\", StateOf<Parts[\"empty\"]>>\n\n/** Drawn while no item is shown for what was typed. */\nfunction Empty(props: EmptyProps): ReactElement | null {\n const controller = useCommand(\"Empty\")\n const empty = useSignal(controller.empty)\n return empty ? <PartElement of={controller.emptyPart} tag=\"div\" {...props} /> : null\n}\n\nexport type GroupProps = PartComponentProps<\"div\", StateOf<Parts[\"group\"]>, { id?: string }>\n\n/** Items under a `<Command.GroupHeading>`. Hidden while none of them is shown. */\nfunction Group({ id, ...props }: GroupProps): ReactElement {\n const controller = useCommand(\"Group\")\n const generated = useId()\n const name = id ?? generated\n const group = useMemo(() => controller.group(name), [controller, name])\n return (\n <GroupContext.Provider value={group}>{usePart(group.part, \"div\", props)}</GroupContext.Provider>\n )\n}\n\nexport type GroupHeadingProps = PartComponentProps<\"div\", StateOf<Parts[\"groupHeading\"]>>\n\nfunction GroupHeading(props: GroupHeadingProps): ReactElement {\n const lone = useCommand(\"GroupHeading\").heading\n return usePart(useContext(GroupContext)?.heading ?? lone, \"div\", props)\n}\n\nexport type ItemProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"item\"]>,\n {\n /** What `onSelect` is told; its `label`, or its text, when left out. */\n value?: string\n /** Disables this item: it cannot be chosen, and the arrows pass over it. */\n disabled?: boolean\n /** What is filtered; the item's text when left out. */\n label?: string\n /** Other words the item answers to. */\n keywords?: readonly string[]\n id?: string\n }\n>\n\nfunction Item({ value, disabled, label, keywords, id, ...props }: ItemProps): ReactElement {\n const controller = useCommand(\"Item\")\n const group = useContext(GroupContext)\n const generated = useId()\n const options = useOptions({ disabled, label, keywords, id: id ?? generated })\n const part = useMemo(\n () => controller.item(value, () => options.get(), group),\n [controller, value, options, group]\n )\n return usePart(part, \"div\", props)\n}\n\nexport type SeparatorProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"separator\"]>,\n {\n /** Stays while something is typed. */\n alwaysRender?: boolean\n }\n>\n\nfunction Separator({ alwaysRender, ...props }: SeparatorProps): ReactElement {\n const controller = useCommand(\"Separator\")\n const options = useOptions({ alwaysRender })\n const part = useMemo(\n () => controller.separator(() => options.get().alwaysRender),\n [controller, options]\n )\n return usePart(part, \"div\", props)\n}\n\nexport const Command = /* @__PURE__ */ parts(\"Command\", {\n Root,\n Input,\n List,\n Empty,\n Group,\n GroupHeading,\n Item,\n Separator,\n})\n"],"mappings":";;;;;AAoBA,MAAM,UAAU,cAAiC,IAAI;AACrD,MAAM,eAAe,cAAwC,KAAA,CAAS;AAEtE,SAAS,WAAW,MAA0B;CAC5C,MAAM,aAAa,WAAW,OAAO;CACrC,IAAI,CAAC,YAAY,MAAM,IAAI,MAAM,YAAY,KAAK,gCAAgC;CAClF,OAAO;AACT;AAQA,SAAS,KAAK,EACZ,YACA,mBACA,oBACA,UACA,QACA,MACA,eACA,UACA,IACA,GAAG,QACuB;CAC1B,MAAM,aAAa,cAAwC,eAAe;EACxE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;CACD,OACE,oBAAC,QAAQ,UAAT;EAAkB,OAAO;EACvB,UAAA,oBAAC,aAAD;GAAa,IAAI,WAAW;GAAM,KAAI;GAAM,GAAI;EAAO,CAAA;CACvC,CAAA;AAEtB;AAIA,MAAM,SAAS,UAAsB,QAAQ,WAAW,WAAW,OAAO,CAAC,CAAC,KAAK,GAAG,SAAS,KAAK;AAGlG,MAAM,QAAQ,UAAqB,QAAQ,WAAW,MAAM,CAAC,CAAC,MAAM,OAAO,KAAK;;AAKhF,SAAS,MAAM,OAAwC;CACrD,MAAM,aAAa,WAAW,OAAO;CAErC,OADc,UAAU,WAAW,KACxB,IAAI,oBAAC,aAAD;EAAa,IAAI,WAAW;EAAW,KAAI;EAAM,GAAI;CAAQ,CAAA,IAAI;A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
|
import { PartComponentProps } from "./runtime.js";
|
|
2
|
-
import { StateOf } from "@kirana-ui/core";
|
|
3
2
|
import { ReactElement, ReactNode } from "react";
|
|
3
|
+
import { StateOf } from "@kirana-ui/core";
|
|
4
4
|
import { DateField as DateField$1, DateFieldProps, DateFieldSegment } from "@kirana-ui/core/date-field";
|
|
5
5
|
import { Vocabulary } from "@kirana-ui/core/vocabulary";
|
|
6
6
|
type Parts = Vocabulary["dateField"];
|
|
@@ -12,7 +12,7 @@ declare const Context: import("react").Context<DateField$1 | null>;
|
|
|
12
12
|
export type RootProps = PartComponentProps<"div", StateOf<Parts["root"]>, Omit<DateFieldProps, "id"> & {
|
|
13
13
|
id?: string;
|
|
14
14
|
}>;
|
|
15
|
-
declare function Root({ value, defaultValue, onValueChange, locale, min, max, placeholders, disabled, readOnly, required, name, form, id, ...rest }: RootProps): ReactElement;
|
|
15
|
+
declare function Root({ value, defaultValue, onValueChange, locale, calendarSystem, min, max, placeholders, disabled, readOnly, required, name, form, id, ...rest }: RootProps): ReactElement;
|
|
16
16
|
export interface SegmentsProps {
|
|
17
17
|
/** Draws one piece of the date, once for each: a part that is typed, or what stands between two. */
|
|
18
18
|
children: (segment: DateFieldSegment) => ReactNode;
|
package/src/date-field.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DirectionContext } from "./direction-context.js";
|
|
2
2
|
import { parts, useController, usePart, useSignal } from "./runtime.js";
|
|
3
|
-
import { within } from "@kirana-ui/core";
|
|
4
3
|
import { Fragment, createContext, useContext } from "react";
|
|
4
|
+
import { within } from "@kirana-ui/core";
|
|
5
5
|
import { Fragment as Fragment$1, jsx } from "react/jsx-runtime";
|
|
6
6
|
import { createDateField } from "@kirana-ui/core/date-field";
|
|
7
7
|
// src/date-field.tsx
|
|
@@ -15,13 +15,14 @@ function useDateField(part) {
|
|
|
15
15
|
if (!controller) throw new Error(`<DateField.${part}> must be inside <DateField.Root>`);
|
|
16
16
|
return controller;
|
|
17
17
|
}
|
|
18
|
-
function Root({ value, defaultValue, onValueChange, locale, min, max, placeholders, disabled, readOnly, required, name, form, id, ...rest }) {
|
|
18
|
+
function Root({ value, defaultValue, onValueChange, locale, calendarSystem, min, max, placeholders, disabled, readOnly, required, name, form, id, ...rest }) {
|
|
19
19
|
const direction = useContext(DirectionContext) ?? void 0;
|
|
20
20
|
const controller = useController(within(createDateField, { direction }), {
|
|
21
21
|
value,
|
|
22
22
|
defaultValue,
|
|
23
23
|
onValueChange,
|
|
24
24
|
locale,
|
|
25
|
+
calendarSystem,
|
|
25
26
|
min,
|
|
26
27
|
max,
|
|
27
28
|
placeholders,
|
package/src/date-field.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"date-field.js","names":[],"sources":["../../../../packages/react/src/date-field.tsx"],"sourcesContent":["import { within } from \"@kirana-ui/core\"\nimport type { StateOf } from \"@kirana-ui/core\"\nimport { createDateField } from \"@kirana-ui/core/date-field\"\nimport type {\n DateField as Controller,\n DateFieldProps,\n DateFieldSegment,\n} from \"@kirana-ui/core/date-field\"\nimport type { Vocabulary } from \"@kirana-ui/core/vocabulary\"\nimport { Fragment, createContext, useContext } from \"react\"\nimport type { ReactElement, ReactNode } from \"react\"\n\nimport { DirectionContext } from \"./direction-context.ts\"\nimport { parts, useController, usePart, useSignal } from \"./runtime.tsx\"\nimport type { PartComponentProps } from \"./runtime.tsx\"\n\ntype Parts = Vocabulary[\"dateField\"]\n\n/**\n * The date field its parts are inside. Exported for a component that is made of one (a date picker\n * provides its own to the date field's parts).\n */\nconst Context = createContext<Controller | null>(null)\n/** For a component made of this one's parts: a date picker. */\nexport { Context as DateFieldContext }\n\nfunction useDateField(part: string): Controller {\n const controller = useContext(Context)\n if (!controller) throw new Error(`<DateField.${part}> must be inside <DateField.Root>`)\n return controller\n}\n\nexport type RootProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"root\"]>,\n Omit<DateFieldProps, \"id\"> & { id?: string }\n>\n\nfunction Root({\n value,\n defaultValue,\n onValueChange,\n locale,\n min,\n max,\n placeholders,\n disabled,\n readOnly,\n required,\n name,\n form,\n id,\n ...rest\n}: RootProps): ReactElement {\n const direction = useContext(DirectionContext) ?? undefined\n const controller = useController<DateFieldProps, Controller>(\n within(createDateField, { direction }),\n {\n value,\n defaultValue,\n onValueChange,\n locale,\n min,\n max,\n placeholders,\n disabled,\n readOnly,\n required,\n name,\n form,\n id,\n }\n )\n return (\n <Context.Provider value={controller}>{usePart(controller.root, \"div\", rest)}</Context.Provider>\n )\n}\n\nexport interface SegmentsProps {\n /** Draws one piece of the date, once for each: a part that is typed, or what stands between two. */\n children: (segment: DateFieldSegment) => ReactNode\n}\n\n/** Draws its child once for each piece of the date, in the locale's order. */\nfunction Segments({ children }: SegmentsProps) {\n const segments = useSignal(useDateField(\"Segments\").segments)\n return (\n <>\n {segments.map((segment) => (\n <Fragment key={`${segment.index}-${segment.type}`}>{children(segment)}</Fragment>\n ))}\n </>\n )\n}\n\nexport type SegmentProps = PartComponentProps<\n \"span\",\n StateOf<Parts[\"segment\"]>,\n {\n /** The piece it is: an entry `DateField.Segments` gave. */\n segment: DateFieldSegment\n }\n>\n\n/** One piece: a part that is typed, or what stands between two. It writes its own text. */\nfunction Segment({ segment, ...props }: SegmentProps): ReactElement {\n const { part, text } = useDateField(\"Segment\").segment(segment)\n const shown = useSignal(text)\n // Its text is the field's to write: the browser never edits it, whatever React fears.\n return usePart(part, \"span\", { ...props, suppressContentEditableWarning: true, children: shown })\n}\n\nexport type InputProps = PartComponentProps<\"input\", StateOf<Parts[\"input\"]>>\n\nconst Input = (props: InputProps) => usePart(useDateField(\"Input\").input, \"input\", props)\n\nexport const DateField = /* @__PURE__ */ parts(\"DateField\", { Root, Segments, Segment, Input })\n"],"mappings":";;;;;;;;;;;AAsBA,MAAM,UAAU,cAAiC,IAAI;AAIrD,SAAS,aAAa,MAA0B;CAC9C,MAAM,aAAa,WAAW,OAAO;CACrC,IAAI,CAAC,YAAY,MAAM,IAAI,MAAM,cAAc,KAAK,kCAAkC;CACtF,OAAO;AACT;AAQA,SAAS,KAAK,EACZ,OACA,cACA,eACA,QACA,KACA,KACA,cACA,UACA,UACA,UACA,MACA,MACA,IACA,GAAG,QACuB;CAC1B,MAAM,YAAY,WAAW,gBAAgB,KAAK,KAAA;CAClD,MAAM,aAAa,cACjB,OAAO,iBAAiB,EAAE,UAAU,CAAC,GACrC;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CACF;CACA,OACE,oBAAC,QAAQ,UAAT;EAAkB,OAAO;EAAa,UAAA,QAAQ,WAAW,MAAM,OAAO,IAAI;CAAoB,CAAA;AAElG;;AAQA,SAAS,SAAS,EAAE,YAA2B;CAC7C,MAAM,WAAW,UAAU,aAAa,UAAU,CAAC,CAAC,QAAQ;CAC5D,OACE,oBAAA,YAAA,EAAA,UACG,SAAS,KAAK,YACb,oBAAC,UAAD,EAAA,UAAoD,SAAS,OAAO,EAAY,GAAjE,GAAG,QAAQ,MAAM,GAAG,QAAQ,MAAqC,CACjF,EACD,CAAA;AAEN;;AAYA,SAAS,QAAQ,EAAE,SAAS,GAAG,SAAqC;CAClE,MAAM,EAAE,MAAM,SAAS,aAAa,SAAS,CAAC,CAAC,QAAQ,OAAO;CAC9D,MAAM,QAAQ,UAAU,IAAI;CAE5B,OAAO,QAAQ,MAAM,QAAQ;EAAE,GAAG;EAAO,gCAAgC;EAAM,UAAU;CAAM,CAAC;AAClG;AAIA,MAAM,SAAS,UAAsB,QAAQ,aAAa,OAAO,CAAC,CAAC,OAAO,SAAS,KAAK;AAExF,MAAa,YAA4B,sBAAM,aAAa;CAAE;CAAM;CAAU;CAAS;AAAM,CAAC"}
|
|
1
|
+
{"version":3,"file":"date-field.js","names":[],"sources":["../../../../packages/react/src/date-field.tsx"],"sourcesContent":["import { within } from \"@kirana-ui/core\"\nimport type { StateOf } from \"@kirana-ui/core\"\nimport { createDateField } from \"@kirana-ui/core/date-field\"\nimport type {\n DateField as Controller,\n DateFieldProps,\n DateFieldSegment,\n} from \"@kirana-ui/core/date-field\"\nimport type { Vocabulary } from \"@kirana-ui/core/vocabulary\"\nimport { Fragment, createContext, useContext } from \"react\"\nimport type { ReactElement, ReactNode } from \"react\"\n\nimport { DirectionContext } from \"./direction-context.ts\"\nimport { parts, useController, usePart, useSignal } from \"./runtime.tsx\"\nimport type { PartComponentProps } from \"./runtime.tsx\"\n\ntype Parts = Vocabulary[\"dateField\"]\n\n/**\n * The date field its parts are inside. Exported for a component that is made of one (a date picker\n * provides its own to the date field's parts).\n */\nconst Context = createContext<Controller | null>(null)\n/** For a component made of this one's parts: a date picker. */\nexport { Context as DateFieldContext }\n\nfunction useDateField(part: string): Controller {\n const controller = useContext(Context)\n if (!controller) throw new Error(`<DateField.${part}> must be inside <DateField.Root>`)\n return controller\n}\n\nexport type RootProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"root\"]>,\n Omit<DateFieldProps, \"id\"> & { id?: string }\n>\n\nfunction Root({\n value,\n defaultValue,\n onValueChange,\n locale,\n calendarSystem,\n min,\n max,\n placeholders,\n disabled,\n readOnly,\n required,\n name,\n form,\n id,\n ...rest\n}: RootProps): ReactElement {\n const direction = useContext(DirectionContext) ?? undefined\n const controller = useController<DateFieldProps, Controller>(\n within(createDateField, { direction }),\n {\n value,\n defaultValue,\n onValueChange,\n locale,\n calendarSystem,\n min,\n max,\n placeholders,\n disabled,\n readOnly,\n required,\n name,\n form,\n id,\n }\n )\n return (\n <Context.Provider value={controller}>{usePart(controller.root, \"div\", rest)}</Context.Provider>\n )\n}\n\nexport interface SegmentsProps {\n /** Draws one piece of the date, once for each: a part that is typed, or what stands between two. */\n children: (segment: DateFieldSegment) => ReactNode\n}\n\n/** Draws its child once for each piece of the date, in the locale's order. */\nfunction Segments({ children }: SegmentsProps) {\n const segments = useSignal(useDateField(\"Segments\").segments)\n return (\n <>\n {segments.map((segment) => (\n <Fragment key={`${segment.index}-${segment.type}`}>{children(segment)}</Fragment>\n ))}\n </>\n )\n}\n\nexport type SegmentProps = PartComponentProps<\n \"span\",\n StateOf<Parts[\"segment\"]>,\n {\n /** The piece it is: an entry `DateField.Segments` gave. */\n segment: DateFieldSegment\n }\n>\n\n/** One piece: a part that is typed, or what stands between two. It writes its own text. */\nfunction Segment({ segment, ...props }: SegmentProps): ReactElement {\n const { part, text } = useDateField(\"Segment\").segment(segment)\n const shown = useSignal(text)\n // Its text is the field's to write: the browser never edits it, whatever React fears.\n return usePart(part, \"span\", { ...props, suppressContentEditableWarning: true, children: shown })\n}\n\nexport type InputProps = PartComponentProps<\"input\", StateOf<Parts[\"input\"]>>\n\nconst Input = (props: InputProps) => usePart(useDateField(\"Input\").input, \"input\", props)\n\nexport const DateField = /* @__PURE__ */ parts(\"DateField\", { Root, Segments, Segment, Input })\n"],"mappings":";;;;;;;;;;;AAsBA,MAAM,UAAU,cAAiC,IAAI;AAIrD,SAAS,aAAa,MAA0B;CAC9C,MAAM,aAAa,WAAW,OAAO;CACrC,IAAI,CAAC,YAAY,MAAM,IAAI,MAAM,cAAc,KAAK,kCAAkC;CACtF,OAAO;AACT;AAQA,SAAS,KAAK,EACZ,OACA,cACA,eACA,QACA,gBACA,KACA,KACA,cACA,UACA,UACA,UACA,MACA,MACA,IACA,GAAG,QACuB;CAC1B,MAAM,YAAY,WAAW,gBAAgB,KAAK,KAAA;CAClD,MAAM,aAAa,cACjB,OAAO,iBAAiB,EAAE,UAAU,CAAC,GACrC;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CACF;CACA,OACE,oBAAC,QAAQ,UAAT;EAAkB,OAAO;EAAa,UAAA,QAAQ,WAAW,MAAM,OAAO,IAAI;CAAoB,CAAA;AAElG;;AAQA,SAAS,SAAS,EAAE,YAA2B;CAC7C,MAAM,WAAW,UAAU,aAAa,UAAU,CAAC,CAAC,QAAQ;CAC5D,OACE,oBAAA,YAAA,EAAA,UACG,SAAS,KAAK,YACb,oBAAC,UAAD,EAAA,UAAoD,SAAS,OAAO,EAAY,GAAjE,GAAG,QAAQ,MAAM,GAAG,QAAQ,MAAqC,CACjF,EACD,CAAA;AAEN;;AAYA,SAAS,QAAQ,EAAE,SAAS,GAAG,SAAqC;CAClE,MAAM,EAAE,MAAM,SAAS,aAAa,SAAS,CAAC,CAAC,QAAQ,OAAO;CAC9D,MAAM,QAAQ,UAAU,IAAI;CAE5B,OAAO,QAAQ,MAAM,QAAQ;EAAE,GAAG;EAAO,gCAAgC;EAAM,UAAU;CAAM,CAAC;AAClG;AAIA,MAAM,SAAS,UAAsB,QAAQ,aAAa,OAAO,CAAC,CAAC,OAAO,SAAS,KAAK;AAExF,MAAa,YAA4B,sBAAM,aAAa;CAAE;CAAM;CAAU;CAAS;AAAM,CAAC"}
|
package/src/date-picker.d.ts
CHANGED
|
@@ -2,23 +2,42 @@ import { InputProps, SegmentProps, SegmentsProps } from "./date-field.js";
|
|
|
2
2
|
import { PopupProps, PositionerProps, TriggerProps } from "./popover.js";
|
|
3
3
|
import { PartComponentProps, PortalProps } from "./runtime.js";
|
|
4
4
|
import { CellProps, DayProps, GridProps, HeadCellProps, HeadingProps, MonthsProps, NextProps, PreviousProps, WeekdaysProps, WeeksProps } from "./calendar.js";
|
|
5
|
-
import { StateOf } from "@kirana-ui/core";
|
|
6
|
-
import { DatePickerProps } from "@kirana-ui/core/date-picker";
|
|
7
5
|
import { ReactElement, ReactNode } from "react";
|
|
6
|
+
import { StateOf } from "@kirana-ui/core";
|
|
7
|
+
import { DatePickerMode, DatePickerProps, DatePickerRange } from "@kirana-ui/core/date-picker";
|
|
8
8
|
import { Vocabulary } from "@kirana-ui/core/vocabulary";
|
|
9
9
|
type Parts = Vocabulary["datePicker"];
|
|
10
|
-
|
|
10
|
+
/** `value` and `onValueChange` are typed by `mode`: a day, or a range. */
|
|
11
|
+
export type RootProps<Mode extends DatePickerMode = "single"> = Omit<DatePickerProps<Mode>, "id"> & {
|
|
11
12
|
id?: string;
|
|
12
13
|
children?: ReactNode;
|
|
13
14
|
};
|
|
14
15
|
/** A date field, and a calendar in a popover, with one value between them. It draws nothing. */
|
|
15
|
-
declare function Root({ children, ...props }: RootProps): ReactElement;
|
|
16
|
-
export type FieldProps = PartComponentProps<"div", StateOf<Parts["field"]
|
|
16
|
+
declare function Root<Mode extends DatePickerMode = "single">({ children, ...props }: RootProps<Mode>): ReactElement;
|
|
17
|
+
export type FieldProps = PartComponentProps<"div", StateOf<Parts["field"]>, {
|
|
18
|
+
/**
|
|
19
|
+
* With `mode="range"`: which day of the range it is typed in, the first (`"start"`, the
|
|
20
|
+
* default) or the last (`"end"`).
|
|
21
|
+
*/
|
|
22
|
+
range?: "start" | "end" | undefined;
|
|
23
|
+
}>;
|
|
17
24
|
export type CalendarProps = PartComponentProps<"div", StateOf<Parts["calendar"]>>;
|
|
18
|
-
|
|
19
|
-
|
|
25
|
+
export type ClearProps = PartComponentProps<"button", StateOf<Parts["clear"]>>;
|
|
26
|
+
export type PresetProps = PartComponentProps<"button", StateOf<Parts["preset"]>, {
|
|
27
|
+
/** The value its press gives: a day, or with `mode="range"` a range. */
|
|
28
|
+
value: string | DatePickerRange;
|
|
29
|
+
}>;
|
|
30
|
+
/**
|
|
31
|
+
* The typed date: what holds its segments and its hidden input. With `mode="range"` there are
|
|
32
|
+
* two, `range="start"` and `range="end"`, each giving its own parts their field.
|
|
33
|
+
*/
|
|
34
|
+
declare function Field({ range, ...props }: FieldProps): ReactElement;
|
|
20
35
|
/** The calendar: what holds its heading, its buttons and its grid. */
|
|
21
36
|
declare const CalendarRoot: (props: CalendarProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
37
|
+
/** Empties the value, and gives focus to the field. Disabled while there is none. */
|
|
38
|
+
declare const Clear: (props: ClearProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
39
|
+
/** Makes the value the one it is given: pressed while it is. */
|
|
40
|
+
declare const Preset: ({ value, ...props }: PresetProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
22
41
|
export declare const DatePicker: {
|
|
23
42
|
readonly Root: typeof Root;
|
|
24
43
|
readonly Field: typeof Field;
|
|
@@ -39,7 +58,9 @@ export declare const DatePicker: {
|
|
|
39
58
|
readonly HeadCell: ({ weekday, ...props }: HeadCellProps) => ReactElement;
|
|
40
59
|
readonly Weeks: ({ children }: WeeksProps) => import("react").JSX.Element;
|
|
41
60
|
readonly Cell: ({ date, ...props }: CellProps) => ReactElement;
|
|
42
|
-
readonly Day: ({ date, ...props }: DayProps) => ReactElement;
|
|
61
|
+
readonly Day: ({ date: given, ...props }: DayProps) => ReactElement;
|
|
62
|
+
readonly Clear: typeof Clear;
|
|
63
|
+
readonly Preset: typeof Preset;
|
|
43
64
|
};
|
|
44
65
|
export type { CellProps, DayProps, GridProps, HeadCellProps, HeadingProps, InputProps, MonthsProps, NextProps, PopupProps, PortalProps, PositionerProps, PreviousProps, SegmentProps, SegmentsProps, TriggerProps, WeekdaysProps, WeeksProps };
|
|
45
66
|
//# sourceMappingURL=date-picker.d.ts.map
|