@kirana-ui/solid 0.0.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/dom/accordion.js +106 -0
- package/dom/alert-dialog.js +2 -0
- package/dom/autocomplete.js +2 -0
- package/dom/autosize.js +19 -0
- package/dom/avatar.js +68 -0
- package/dom/button.js +18 -0
- package/dom/calendar.js +141 -0
- package/dom/carousel.js +83 -0
- package/dom/checkbox.js +77 -0
- package/dom/collapsible.js +64 -0
- package/dom/combobox.js +281 -0
- package/dom/command.js +129 -0
- package/dom/context-menu.js +2 -0
- package/dom/date-field.js +86 -0
- package/dom/date-picker.js +103 -0
- package/dom/dialog.js +101 -0
- package/dom/direction-context.js +3 -0
- package/dom/direction.js +27 -0
- package/dom/drawer.js +2 -0
- package/dom/field-context.js +3 -0
- package/dom/field.js +88 -0
- package/dom/fieldset.js +41 -0
- package/dom/form.js +29 -0
- package/dom/hover-card.js +3 -0
- package/dom/hover-popup.js +78 -0
- package/dom/index.js +47 -0
- package/dom/input.js +26 -0
- package/dom/label.js +18 -0
- package/dom/listbox.js +114 -0
- package/dom/menu.js +261 -0
- package/dom/menubar-context.js +3 -0
- package/dom/menubar.js +33 -0
- package/dom/message-scroller.js +56 -0
- package/dom/meter.js +3 -0
- package/dom/navigation-menu.js +150 -0
- package/dom/number-field.js +82 -0
- package/dom/otp.js +95 -0
- package/dom/pagination.js +74 -0
- package/dom/popover.js +70 -0
- package/dom/progress.js +3 -0
- package/dom/qr-code.js +48 -0
- package/dom/radio-group.js +101 -0
- package/dom/resizable.js +65 -0
- package/dom/runtime.js +133 -0
- package/dom/scroll-area.js +99 -0
- package/dom/select.js +213 -0
- package/dom/separator.js +17 -0
- package/dom/slider.js +93 -0
- package/dom/switch.js +63 -0
- package/dom/tabs.js +97 -0
- package/dom/toast.js +113 -0
- package/dom/toggle-group.js +37 -0
- package/dom/toggle.js +28 -0
- package/dom/toolbar-context.js +5 -0
- package/dom/toolbar.js +71 -0
- package/dom/tooltip.js +3 -0
- package/dom/value-bar.js +62 -0
- package/llms.txt +1838 -0
- package/package.json +437 -6
- package/server/accordion.js +106 -0
- package/server/alert-dialog.js +2 -0
- package/server/autocomplete.js +2 -0
- package/server/autosize.js +19 -0
- package/server/avatar.js +68 -0
- package/server/button.js +18 -0
- package/server/calendar.js +140 -0
- package/server/carousel.js +83 -0
- package/server/checkbox.js +77 -0
- package/server/collapsible.js +64 -0
- package/server/combobox.js +281 -0
- package/server/command.js +129 -0
- package/server/context-menu.js +2 -0
- package/server/date-field.js +86 -0
- package/server/date-picker.js +103 -0
- package/server/dialog.js +101 -0
- package/server/direction-context.js +3 -0
- package/server/direction.js +27 -0
- package/server/drawer.js +2 -0
- package/server/field-context.js +3 -0
- package/server/field.js +87 -0
- package/server/fieldset.js +41 -0
- package/server/form.js +29 -0
- package/server/hover-card.js +3 -0
- package/server/hover-popup.js +78 -0
- package/server/index.js +47 -0
- package/server/input.js +26 -0
- package/server/label.js +18 -0
- package/server/listbox.js +114 -0
- package/server/menu.js +261 -0
- package/server/menubar-context.js +3 -0
- package/server/menubar.js +33 -0
- package/server/message-scroller.js +56 -0
- package/server/meter.js +3 -0
- package/server/navigation-menu.js +144 -0
- package/server/number-field.js +81 -0
- package/server/otp.js +94 -0
- package/server/pagination.js +74 -0
- package/server/popover.js +70 -0
- package/server/progress.js +3 -0
- package/server/qr-code.js +48 -0
- package/server/radio-group.js +101 -0
- package/server/resizable.js +65 -0
- package/server/runtime.js +132 -0
- package/server/scroll-area.js +99 -0
- package/server/select.js +213 -0
- package/server/separator.js +17 -0
- package/server/slider.js +92 -0
- package/server/switch.js +62 -0
- package/server/tabs.js +97 -0
- package/server/toast.js +113 -0
- package/server/toggle-group.js +37 -0
- package/server/toggle.js +28 -0
- package/server/toolbar-context.js +5 -0
- package/server/toolbar.js +71 -0
- package/server/tooltip.js +3 -0
- package/server/value-bar.js +61 -0
- package/src/accordion.jsx +68 -0
- package/src/alert-dialog.js +2 -0
- package/src/autocomplete.jsx +2 -0
- package/src/autosize.jsx +8 -0
- package/src/avatar.jsx +35 -0
- package/src/button.jsx +9 -0
- package/src/calendar.jsx +104 -0
- package/src/carousel.jsx +51 -0
- package/src/checkbox.jsx +59 -0
- package/src/collapsible.jsx +35 -0
- package/src/combobox.jsx +179 -0
- package/src/command.jsx +81 -0
- package/src/context-menu.js +2 -0
- package/src/date-field.jsx +67 -0
- package/src/date-picker.jsx +72 -0
- package/src/dialog.jsx +67 -0
- package/src/direction-context.js +3 -0
- package/src/direction.jsx +17 -0
- package/src/drawer.js +2 -0
- package/src/field-context.js +3 -0
- package/src/field.jsx +64 -0
- package/src/fieldset.jsx +24 -0
- package/src/form.jsx +26 -0
- package/src/hover-card.jsx +3 -0
- package/src/hover-popup.jsx +48 -0
- package/src/index.js +47 -0
- package/src/input.jsx +17 -0
- package/src/label.jsx +9 -0
- package/src/listbox.jsx +81 -0
- package/src/menu.jsx +164 -0
- package/src/menubar-context.js +3 -0
- package/src/menubar.jsx +21 -0
- package/src/message-scroller.jsx +27 -0
- package/src/meter.jsx +3 -0
- package/src/navigation-menu.jsx +95 -0
- package/src/number-field.jsx +75 -0
- package/src/otp.jsx +73 -0
- package/src/pagination.jsx +60 -0
- package/src/popover.jsx +51 -0
- package/src/progress.jsx +3 -0
- package/src/qr-code.jsx +25 -0
- package/src/radio-group.jsx +68 -0
- package/src/resizable.jsx +46 -0
- package/src/runtime.jsx +119 -0
- package/src/scroll-area.jsx +53 -0
- package/src/select.jsx +129 -0
- package/src/separator.jsx +8 -0
- package/src/slider.jsx +76 -0
- package/src/switch.jsx +49 -0
- package/src/tabs.jsx +58 -0
- package/src/toast.jsx +58 -0
- package/src/toggle-group.jsx +32 -0
- package/src/toggle.jsx +24 -0
- package/src/toolbar-context.js +5 -0
- package/src/toolbar.jsx +43 -0
- package/src/tooltip.jsx +3 -0
- package/src/value-bar.jsx +45 -0
- package/types/accordion.d.ts +30 -0
- package/types/alert-dialog.d.ts +1 -0
- package/types/autocomplete.d.ts +1 -0
- package/types/autosize.d.ts +8 -0
- package/types/avatar.d.ts +15 -0
- package/types/button.d.ts +9 -0
- package/types/calendar.d.ts +40 -0
- package/types/carousel.d.ts +26 -0
- package/types/checkbox.d.ts +26 -0
- package/types/collapsible.d.ts +21 -0
- package/types/combobox.d.ts +106 -0
- package/types/command.d.ts +45 -0
- package/types/context-menu.d.ts +1 -0
- package/types/date-field.d.ts +23 -0
- package/types/date-picker.d.ts +49 -0
- package/types/dialog.d.ts +61 -0
- package/types/direction-context.d.ts +3 -0
- package/types/direction.d.ts +14 -0
- package/types/drawer.d.ts +1 -0
- package/types/field-context.d.ts +3 -0
- package/types/field.d.ts +28 -0
- package/types/fieldset.d.ts +14 -0
- package/types/form.d.ts +7 -0
- package/types/hover-card.d.ts +13 -0
- package/types/hover-popup.d.ts +29 -0
- package/types/index.d.ts +50 -0
- package/types/input.d.ts +12 -0
- package/types/label.d.ts +4 -0
- package/types/listbox.d.ts +38 -0
- package/types/menu.d.ts +91 -0
- package/types/menubar-context.d.ts +3 -0
- package/types/menubar.d.ts +10 -0
- package/types/message-scroller.d.ts +16 -0
- package/types/meter.d.ts +9 -0
- package/types/navigation-menu.d.ts +44 -0
- package/types/number-field.d.ts +15 -0
- package/types/otp.d.ts +32 -0
- package/types/pagination.d.ts +23 -0
- package/types/popover.d.ts +31 -0
- package/types/progress.d.ts +9 -0
- package/types/qr-code.d.ts +14 -0
- package/types/radio-group.d.ts +29 -0
- package/types/resizable.d.ts +24 -0
- package/types/runtime.d.ts +49 -0
- package/types/scroll-area.d.ts +20 -0
- package/types/select.d.ts +74 -0
- package/types/separator.d.ts +6 -0
- package/types/slider.d.ts +24 -0
- package/types/switch.d.ts +21 -0
- package/types/tabs.d.ts +32 -0
- package/types/toast.d.ts +33 -0
- package/types/toggle-group.d.ts +14 -0
- package/types/toggle.d.ts +12 -0
- package/types/toolbar-context.d.ts +6 -0
- package/types/toolbar.d.ts +23 -0
- package/types/tooltip.d.ts +13 -0
- package/types/value-bar.d.ts +17 -0
- package/README.md +0 -7
- package/index.js +0 -5
package/src/carousel.jsx
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { within } from "@kirana-ui/core";
|
|
2
|
+
import { createCarousel } from "@kirana-ui/core/carousel";
|
|
3
|
+
import { createContext, createUniqueId, splitProps, useContext } from "solid-js";
|
|
4
|
+
import { DirectionContext } from "./direction-context.js";
|
|
5
|
+
import { Part, controller } from "./runtime.jsx";
|
|
6
|
+
const Context = createContext();
|
|
7
|
+
function useCarousel() {
|
|
8
|
+
const made = useContext(Context);
|
|
9
|
+
if (!made)
|
|
10
|
+
throw new Error("A Carousel part must be inside <Carousel.Root>");
|
|
11
|
+
return made;
|
|
12
|
+
}
|
|
13
|
+
function Root(props) {
|
|
14
|
+
const [local, rest] = splitProps(props, [
|
|
15
|
+
"index",
|
|
16
|
+
"defaultIndex",
|
|
17
|
+
"onIndexChange",
|
|
18
|
+
"orientation",
|
|
19
|
+
"loop",
|
|
20
|
+
"id",
|
|
21
|
+
]);
|
|
22
|
+
const generated = createUniqueId();
|
|
23
|
+
const direction = useContext(DirectionContext);
|
|
24
|
+
const made = controller(within(createCarousel, { direction }), () => ({
|
|
25
|
+
id: local.id ?? generated,
|
|
26
|
+
index: local.index,
|
|
27
|
+
defaultIndex: local.defaultIndex,
|
|
28
|
+
orientation: local.orientation,
|
|
29
|
+
loop: local.loop,
|
|
30
|
+
onIndexChange: (index, details) => local.onIndexChange?.(index, details),
|
|
31
|
+
}));
|
|
32
|
+
return (<Context.Provider value={made}>
|
|
33
|
+
<Part part={made.root} tag="div" {...rest}/>
|
|
34
|
+
</Context.Provider>);
|
|
35
|
+
}
|
|
36
|
+
const Viewport = (props) => (<Part part={useCarousel().viewport} tag="div" {...props}/>);
|
|
37
|
+
function Item(props) {
|
|
38
|
+
const [local, rest] = splitProps(props, ["index"]);
|
|
39
|
+
// A slide is its place for as long as it is in the page.
|
|
40
|
+
const part = useCarousel().item(local.index);
|
|
41
|
+
return <Part part={part} tag="div" {...rest}/>;
|
|
42
|
+
}
|
|
43
|
+
const Previous = (props) => (<Part part={useCarousel().previous} tag="button" {...props}/>);
|
|
44
|
+
const Next = (props) => (<Part part={useCarousel().next} tag="button" {...props}/>);
|
|
45
|
+
function Indicator(props) {
|
|
46
|
+
const [local, rest] = splitProps(props, ["index"]);
|
|
47
|
+
// A button is its slide for as long as it is in the page.
|
|
48
|
+
const part = useCarousel().indicator(local.index);
|
|
49
|
+
return <Part part={part} tag="button" {...rest}/>;
|
|
50
|
+
}
|
|
51
|
+
export const Carousel = { Root, Viewport, Item, Previous, Next, Indicator };
|
package/src/checkbox.jsx
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { within } from "@kirana-ui/core";
|
|
2
|
+
import { createCheckbox } from "@kirana-ui/core/checkbox";
|
|
3
|
+
import { Show, createContext, createUniqueId, splitProps, useContext } from "solid-js";
|
|
4
|
+
import { FieldContext } from "./field-context.js";
|
|
5
|
+
import { Part, controller, fromSignal } from "./runtime.jsx";
|
|
6
|
+
const Context = createContext();
|
|
7
|
+
function useCheckbox() {
|
|
8
|
+
const made = useContext(Context);
|
|
9
|
+
if (!made)
|
|
10
|
+
throw new Error("A Checkbox part must be inside <Checkbox.Root>");
|
|
11
|
+
return made;
|
|
12
|
+
}
|
|
13
|
+
function Root(props) {
|
|
14
|
+
const [local, rest] = splitProps(props, [
|
|
15
|
+
"checked",
|
|
16
|
+
"defaultChecked",
|
|
17
|
+
"onCheckedChange",
|
|
18
|
+
"indeterminate",
|
|
19
|
+
"disabled",
|
|
20
|
+
"readOnly",
|
|
21
|
+
"required",
|
|
22
|
+
"name",
|
|
23
|
+
"form",
|
|
24
|
+
"value",
|
|
25
|
+
"id",
|
|
26
|
+
"children",
|
|
27
|
+
]);
|
|
28
|
+
const generated = createUniqueId();
|
|
29
|
+
const field = useContext(FieldContext);
|
|
30
|
+
const made = controller(within(createCheckbox, { field }), () => ({
|
|
31
|
+
id: local.id ?? generated,
|
|
32
|
+
checked: local.checked,
|
|
33
|
+
defaultChecked: local.defaultChecked,
|
|
34
|
+
indeterminate: local.indeterminate,
|
|
35
|
+
disabled: local.disabled,
|
|
36
|
+
readOnly: local.readOnly,
|
|
37
|
+
required: local.required,
|
|
38
|
+
name: local.name,
|
|
39
|
+
form: local.form,
|
|
40
|
+
value: local.value,
|
|
41
|
+
onCheckedChange: (checked, details) => local.onCheckedChange?.(checked, details),
|
|
42
|
+
}));
|
|
43
|
+
return (<Context.Provider value={made}>
|
|
44
|
+
<Part part={made.root} tag="span" {...rest}>
|
|
45
|
+
{local.children}
|
|
46
|
+
<Part part={made.input} tag="input"/>
|
|
47
|
+
</Part>
|
|
48
|
+
</Context.Provider>);
|
|
49
|
+
}
|
|
50
|
+
/** `keepMounted` keeps the mark in the page while the box is unchecked. */
|
|
51
|
+
function Indicator(props) {
|
|
52
|
+
const [local, rest] = splitProps(props, ["keepMounted"]);
|
|
53
|
+
const made = useCheckbox();
|
|
54
|
+
const mounted = fromSignal(made.indicatorMounted);
|
|
55
|
+
return (<Show when={mounted() || local.keepMounted}>
|
|
56
|
+
<Part part={made.indicator} tag="span" {...rest}/>
|
|
57
|
+
</Show>);
|
|
58
|
+
}
|
|
59
|
+
export const Checkbox = { Root, Indicator };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { createCollapsible } from "@kirana-ui/core/collapsible";
|
|
2
|
+
import { Show, createContext, createUniqueId, splitProps, useContext } from "solid-js";
|
|
3
|
+
import { Part, controller, fromSignal } from "./runtime.jsx";
|
|
4
|
+
const Context = createContext();
|
|
5
|
+
function useCollapsible() {
|
|
6
|
+
const made = useContext(Context);
|
|
7
|
+
if (!made)
|
|
8
|
+
throw new Error("A Collapsible part must be inside <Collapsible.Root>");
|
|
9
|
+
return made;
|
|
10
|
+
}
|
|
11
|
+
function Root(props) {
|
|
12
|
+
const [local, rest] = splitProps(props, ["open", "defaultOpen", "onOpenChange", "disabled", "id"]);
|
|
13
|
+
const generated = createUniqueId();
|
|
14
|
+
const made = controller(createCollapsible, () => ({
|
|
15
|
+
id: local.id ?? generated,
|
|
16
|
+
open: local.open,
|
|
17
|
+
defaultOpen: local.defaultOpen,
|
|
18
|
+
disabled: local.disabled,
|
|
19
|
+
onOpenChange: (open, details) => local.onOpenChange?.(open, details),
|
|
20
|
+
}));
|
|
21
|
+
return (<Context.Provider value={made}>
|
|
22
|
+
<Part part={made.root} tag="div" {...rest}/>
|
|
23
|
+
</Context.Provider>);
|
|
24
|
+
}
|
|
25
|
+
const Trigger = (props) => (<Part part={useCollapsible().trigger} tag="button" {...props}/>);
|
|
26
|
+
/** `keepMounted` keeps the closed panel in the page, `hidden`. */
|
|
27
|
+
function Panel(props) {
|
|
28
|
+
const [local, rest] = splitProps(props, ["keepMounted"]);
|
|
29
|
+
const made = useCollapsible();
|
|
30
|
+
const mounted = fromSignal(made.mounted);
|
|
31
|
+
return (<Show when={mounted() || local.keepMounted}>
|
|
32
|
+
<Part part={made.panel} tag="div" {...rest}/>
|
|
33
|
+
</Show>);
|
|
34
|
+
}
|
|
35
|
+
export const Collapsible = { Root, Trigger, Panel };
|
package/src/combobox.jsx
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { within } from "@kirana-ui/core";
|
|
2
|
+
import { createAutocomplete } from "@kirana-ui/core/autocomplete";
|
|
3
|
+
import { createCombobox } from "@kirana-ui/core/combobox";
|
|
4
|
+
import { Show, createContext, createUniqueId, splitProps, untrack, useContext } from "solid-js";
|
|
5
|
+
import { FieldContext } from "./field-context.js";
|
|
6
|
+
import { positioned } from "./popover.jsx";
|
|
7
|
+
import { Part, Portal as BodyPortal, controller, fromSignal, toSignal } from "./runtime.jsx";
|
|
8
|
+
const Context = createContext();
|
|
9
|
+
const ItemContext = createContext();
|
|
10
|
+
function useCombobox() {
|
|
11
|
+
const made = useContext(Context);
|
|
12
|
+
if (!made)
|
|
13
|
+
throw new Error("A Combobox part must be inside <Combobox.Root>");
|
|
14
|
+
return made;
|
|
15
|
+
}
|
|
16
|
+
function Root(props) {
|
|
17
|
+
const generated = createUniqueId();
|
|
18
|
+
const field = useContext(FieldContext);
|
|
19
|
+
const made = controller(within(createCombobox, { field }), () => ({
|
|
20
|
+
id: props.id ?? generated,
|
|
21
|
+
value: props.value,
|
|
22
|
+
defaultValue: props.defaultValue,
|
|
23
|
+
inputValue: props.inputValue,
|
|
24
|
+
defaultInputValue: props.defaultInputValue,
|
|
25
|
+
open: props.open,
|
|
26
|
+
defaultOpen: props.defaultOpen,
|
|
27
|
+
disabled: props.disabled,
|
|
28
|
+
required: props.required,
|
|
29
|
+
multiple: props.multiple,
|
|
30
|
+
values: props.values,
|
|
31
|
+
defaultValues: props.defaultValues,
|
|
32
|
+
onValuesChange: (values, details) => props.onValuesChange?.(values, details),
|
|
33
|
+
inline: props.inline,
|
|
34
|
+
virtualized: props.virtualized,
|
|
35
|
+
name: props.name,
|
|
36
|
+
form: props.form,
|
|
37
|
+
items: props.items,
|
|
38
|
+
filter: props.filter,
|
|
39
|
+
onValueChange: (value, details) => props.onValueChange?.(value, details),
|
|
40
|
+
onInputValueChange: (value, details) => props.onInputValueChange?.(value, details),
|
|
41
|
+
onOpenChange: (open, details) => props.onOpenChange?.(open, details),
|
|
42
|
+
}));
|
|
43
|
+
const named = fromSignal(made.named);
|
|
44
|
+
return (<Context.Provider value={made}>
|
|
45
|
+
{props.children}
|
|
46
|
+
<Show when={named()}>
|
|
47
|
+
<Part part={made.hidden} tag="input"/>
|
|
48
|
+
</Show>
|
|
49
|
+
</Context.Provider>);
|
|
50
|
+
}
|
|
51
|
+
const Portal = (props) => (<BodyPortal mounted={useCombobox().mounted}>{props.children}</BodyPortal>);
|
|
52
|
+
function Positioner(props) {
|
|
53
|
+
const made = useCombobox();
|
|
54
|
+
return <Part part={made.positioner} tag="div" {...positioned(props, made.positioning)}/>;
|
|
55
|
+
}
|
|
56
|
+
/** `label` is what is filtered and what the input shows; the item's text when left out. */
|
|
57
|
+
function Item(props) {
|
|
58
|
+
const [local, rest] = splitProps(props, ["value", "disabled", "label", "id", "index"]);
|
|
59
|
+
// An item is its value for as long as it is in the page.
|
|
60
|
+
const value = untrack(() => local.value);
|
|
61
|
+
const generated = createUniqueId();
|
|
62
|
+
const options = toSignal(() => ({
|
|
63
|
+
disabled: local.disabled,
|
|
64
|
+
label: local.label,
|
|
65
|
+
index: local.index,
|
|
66
|
+
id: local.id ?? generated,
|
|
67
|
+
}));
|
|
68
|
+
const part = useCombobox().item(value, () => options.get(), useContext(GroupContext));
|
|
69
|
+
return (<ItemContext.Provider value={value}>
|
|
70
|
+
<Part part={part} tag="div" {...rest}/>
|
|
71
|
+
</ItemContext.Provider>);
|
|
72
|
+
}
|
|
73
|
+
function ItemIndicator(props) {
|
|
74
|
+
const [local, rest] = splitProps(props, ["keepMounted"]);
|
|
75
|
+
const made = useCombobox();
|
|
76
|
+
const value = useContext(ItemContext);
|
|
77
|
+
const selected = fromSignal(made.selected(value));
|
|
78
|
+
return (<Show when={selected() || local.keepMounted}>
|
|
79
|
+
<Part part={made.itemIndicator(value)} tag="span" {...rest}/>
|
|
80
|
+
</Show>);
|
|
81
|
+
}
|
|
82
|
+
/** A button that empties the input and the value. Drawn while there is something to clear. */
|
|
83
|
+
function Clear(props) {
|
|
84
|
+
const [local, rest] = splitProps(props, ["keepMounted"]);
|
|
85
|
+
const made = useCombobox();
|
|
86
|
+
const clearable = fromSignal(made.clearable);
|
|
87
|
+
return (<Show when={clearable() || local.keepMounted}>
|
|
88
|
+
<Part part={made.clear} tag="button" {...rest}/>
|
|
89
|
+
</Show>);
|
|
90
|
+
}
|
|
91
|
+
const ChipContext = createContext();
|
|
92
|
+
/** With `multiple`: one chosen value. Its `value` is what its remove button takes away. */
|
|
93
|
+
function Chip(props) {
|
|
94
|
+
const [local, rest] = splitProps(props, ["value"]);
|
|
95
|
+
// A chip is its value for as long as it is in the page.
|
|
96
|
+
const value = untrack(() => local.value);
|
|
97
|
+
return (<ChipContext.Provider value={value}>
|
|
98
|
+
<Part part={useCombobox().chip(value)} tag="span" {...rest}/>
|
|
99
|
+
</ChipContext.Provider>);
|
|
100
|
+
}
|
|
101
|
+
const ChipRemove = (props) => (<Part part={useCombobox().chipRemove(useContext(ChipContext))} tag="button" {...props}/>);
|
|
102
|
+
/** Drawn while no item is shown for what was typed. */
|
|
103
|
+
function Empty(props) {
|
|
104
|
+
const made = useCombobox();
|
|
105
|
+
const empty = fromSignal(made.empty);
|
|
106
|
+
return (<Show when={empty()}>
|
|
107
|
+
<Part part={made.emptyPart} tag="div" {...props}/>
|
|
108
|
+
</Show>);
|
|
109
|
+
}
|
|
110
|
+
const GroupContext = createContext();
|
|
111
|
+
/** Items that belong together, named by their `GroupLabel`. Hidden while none is shown. */
|
|
112
|
+
function Group(props) {
|
|
113
|
+
const [local, rest] = splitProps(props, ["id"]);
|
|
114
|
+
const generated = createUniqueId();
|
|
115
|
+
const group = useCombobox().group(untrack(() => local.id) ?? generated);
|
|
116
|
+
return (<GroupContext.Provider value={group}>
|
|
117
|
+
<Part part={group.root} tag="div" {...rest}/>
|
|
118
|
+
</GroupContext.Provider>);
|
|
119
|
+
}
|
|
120
|
+
/** Names the group it is in. With no group around it, it is plain text. */
|
|
121
|
+
const GroupLabel = (props) => (<Part part={useContext(GroupContext)?.label ?? useCombobox().groupLabel} tag="div" {...props}/>);
|
|
122
|
+
const part = (name, tag) => (props) => <Part part={useCombobox()[name]} tag={tag} {...props}/>;
|
|
123
|
+
/** A combobox whose text is the value: the list only suggests. */
|
|
124
|
+
function AutocompleteRoot(props) {
|
|
125
|
+
const generated = createUniqueId();
|
|
126
|
+
const field = useContext(FieldContext);
|
|
127
|
+
const made = controller(within(createAutocomplete, { field }), () => ({
|
|
128
|
+
id: props.id ?? generated,
|
|
129
|
+
value: props.value,
|
|
130
|
+
defaultValue: props.defaultValue,
|
|
131
|
+
open: props.open,
|
|
132
|
+
defaultOpen: props.defaultOpen,
|
|
133
|
+
mode: props.mode,
|
|
134
|
+
filter: props.filter,
|
|
135
|
+
openOnInputClick: props.openOnInputClick,
|
|
136
|
+
disabled: props.disabled,
|
|
137
|
+
required: props.required,
|
|
138
|
+
name: props.name,
|
|
139
|
+
form: props.form,
|
|
140
|
+
virtualized: props.virtualized,
|
|
141
|
+
onValueChange: (value, details) => props.onValueChange?.(value, details),
|
|
142
|
+
onOpenChange: (open, details) => props.onOpenChange?.(open, details),
|
|
143
|
+
}));
|
|
144
|
+
return <Context.Provider value={made}>{props.children}</Context.Provider>;
|
|
145
|
+
}
|
|
146
|
+
export const Combobox = {
|
|
147
|
+
Root,
|
|
148
|
+
Input: part("input", "input"),
|
|
149
|
+
Trigger: part("trigger", "button"),
|
|
150
|
+
Clear,
|
|
151
|
+
/** With `multiple`: what holds the chips and the input. */
|
|
152
|
+
Chips: part("chips", "div"),
|
|
153
|
+
Chip,
|
|
154
|
+
ChipRemove,
|
|
155
|
+
Portal,
|
|
156
|
+
Positioner,
|
|
157
|
+
Popup: part("popup", "div"),
|
|
158
|
+
Group,
|
|
159
|
+
GroupLabel,
|
|
160
|
+
/** A line between groups. */
|
|
161
|
+
Separator: part("separator", "div"),
|
|
162
|
+
Item,
|
|
163
|
+
ItemIndicator,
|
|
164
|
+
Empty,
|
|
165
|
+
};
|
|
166
|
+
export const Autocomplete = {
|
|
167
|
+
Root: AutocompleteRoot,
|
|
168
|
+
Input: Combobox.Input,
|
|
169
|
+
Trigger: Combobox.Trigger,
|
|
170
|
+
Clear: Combobox.Clear,
|
|
171
|
+
Portal: Combobox.Portal,
|
|
172
|
+
Positioner: Combobox.Positioner,
|
|
173
|
+
Popup: Combobox.Popup,
|
|
174
|
+
Group: Combobox.Group,
|
|
175
|
+
GroupLabel: Combobox.GroupLabel,
|
|
176
|
+
Separator: Combobox.Separator,
|
|
177
|
+
Item: Combobox.Item,
|
|
178
|
+
Empty: Combobox.Empty,
|
|
179
|
+
};
|
package/src/command.jsx
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { createCommand } from "@kirana-ui/core/command";
|
|
2
|
+
import { Show, createContext, createUniqueId, splitProps, untrack, useContext } from "solid-js";
|
|
3
|
+
import { Part, controller, fromSignal, toSignal } from "./runtime.jsx";
|
|
4
|
+
const Context = createContext();
|
|
5
|
+
const GroupContext = createContext();
|
|
6
|
+
function useCommand() {
|
|
7
|
+
const made = useContext(Context);
|
|
8
|
+
if (!made)
|
|
9
|
+
throw new Error("A Command part must be inside <Command.Root>");
|
|
10
|
+
return made;
|
|
11
|
+
}
|
|
12
|
+
function Root(props) {
|
|
13
|
+
const [local, rest] = splitProps(props, [
|
|
14
|
+
"inputValue",
|
|
15
|
+
"defaultInputValue",
|
|
16
|
+
"onInputValueChange",
|
|
17
|
+
"onSelect",
|
|
18
|
+
"filter",
|
|
19
|
+
"loop",
|
|
20
|
+
"disabled",
|
|
21
|
+
"id",
|
|
22
|
+
]);
|
|
23
|
+
const generated = createUniqueId();
|
|
24
|
+
const made = controller(createCommand, () => ({
|
|
25
|
+
id: local.id ?? generated,
|
|
26
|
+
inputValue: local.inputValue,
|
|
27
|
+
defaultInputValue: local.defaultInputValue,
|
|
28
|
+
filter: local.filter,
|
|
29
|
+
loop: local.loop,
|
|
30
|
+
disabled: local.disabled,
|
|
31
|
+
onInputValueChange: (value, details) => local.onInputValueChange?.(value, details),
|
|
32
|
+
onSelect: (value, details) => local.onSelect?.(value, details),
|
|
33
|
+
}));
|
|
34
|
+
return (<Context.Provider value={made}>
|
|
35
|
+
<Part part={made.root} tag="div" {...rest}/>
|
|
36
|
+
</Context.Provider>);
|
|
37
|
+
}
|
|
38
|
+
const Input = (props) => (<Part part={useCommand().input} tag="input" {...props}/>);
|
|
39
|
+
const List = (props) => <Part part={useCommand().list} tag="div" {...props}/>;
|
|
40
|
+
/** Drawn while no item is shown for what was typed. */
|
|
41
|
+
function Empty(props) {
|
|
42
|
+
const made = useCommand();
|
|
43
|
+
const empty = fromSignal(made.empty);
|
|
44
|
+
return (<Show when={empty()}>
|
|
45
|
+
<Part part={made.emptyPart} tag="div" {...props}/>
|
|
46
|
+
</Show>);
|
|
47
|
+
}
|
|
48
|
+
/** Items under a `<Command.GroupHeading>`. Hidden while none of them is shown. */
|
|
49
|
+
function Group(props) {
|
|
50
|
+
const [local, rest] = splitProps(props, ["id"]);
|
|
51
|
+
const generated = createUniqueId();
|
|
52
|
+
const group = useCommand().group(untrack(() => local.id) ?? generated);
|
|
53
|
+
return (<GroupContext.Provider value={group}>
|
|
54
|
+
<Part part={group.part} tag="div" {...rest}/>
|
|
55
|
+
</GroupContext.Provider>);
|
|
56
|
+
}
|
|
57
|
+
function GroupHeading(props) {
|
|
58
|
+
const part = useContext(GroupContext)?.heading ?? useCommand().heading;
|
|
59
|
+
return <Part part={part} tag="div" {...props}/>;
|
|
60
|
+
}
|
|
61
|
+
/** `label` is what is filtered, the item's text when left out; `keywords` are other words for it. */
|
|
62
|
+
function Item(props) {
|
|
63
|
+
const [local, rest] = splitProps(props, ["value", "disabled", "label", "keywords", "id"]);
|
|
64
|
+
const generated = createUniqueId();
|
|
65
|
+
const options = toSignal(() => ({
|
|
66
|
+
disabled: local.disabled,
|
|
67
|
+
label: local.label,
|
|
68
|
+
keywords: local.keywords,
|
|
69
|
+
id: local.id ?? generated,
|
|
70
|
+
}));
|
|
71
|
+
const part = useCommand().item(untrack(() => local.value), () => options.get(), useContext(GroupContext));
|
|
72
|
+
return <Part part={part} tag="div" {...rest}/>;
|
|
73
|
+
}
|
|
74
|
+
/** A line between groups: gone while something is typed, unless `alwaysRender`. */
|
|
75
|
+
function Separator(props) {
|
|
76
|
+
const [local, rest] = splitProps(props, ["alwaysRender"]);
|
|
77
|
+
const options = toSignal(() => ({ alwaysRender: local.alwaysRender }));
|
|
78
|
+
const part = useCommand().separator(() => options.get().alwaysRender);
|
|
79
|
+
return <Part part={part} tag="div" {...rest}/>;
|
|
80
|
+
}
|
|
81
|
+
export const Command = { Root, Input, List, Empty, Group, GroupHeading, Item, Separator };
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { within } from "@kirana-ui/core";
|
|
2
|
+
import { createDateField } from "@kirana-ui/core/date-field";
|
|
3
|
+
import { For, createContext, createUniqueId, splitProps, useContext } from "solid-js";
|
|
4
|
+
import { DirectionContext } from "./direction-context.js";
|
|
5
|
+
import { Part, controller, fromSignal } from "./runtime.jsx";
|
|
6
|
+
const Context = createContext();
|
|
7
|
+
/** For a component made of this one's parts: a date picker. */
|
|
8
|
+
export { Context as DateFieldContext };
|
|
9
|
+
function useDateField() {
|
|
10
|
+
const made = useContext(Context);
|
|
11
|
+
if (!made)
|
|
12
|
+
throw new Error("A DateField part must be inside <DateField.Root>");
|
|
13
|
+
return made;
|
|
14
|
+
}
|
|
15
|
+
function Root(props) {
|
|
16
|
+
const [local, rest] = splitProps(props, [
|
|
17
|
+
"value",
|
|
18
|
+
"defaultValue",
|
|
19
|
+
"onValueChange",
|
|
20
|
+
"locale",
|
|
21
|
+
"min",
|
|
22
|
+
"max",
|
|
23
|
+
"placeholders",
|
|
24
|
+
"disabled",
|
|
25
|
+
"readOnly",
|
|
26
|
+
"required",
|
|
27
|
+
"name",
|
|
28
|
+
"form",
|
|
29
|
+
"id",
|
|
30
|
+
]);
|
|
31
|
+
const generated = createUniqueId();
|
|
32
|
+
const direction = useContext(DirectionContext);
|
|
33
|
+
const made = controller(within(createDateField, { direction }), () => ({
|
|
34
|
+
id: local.id ?? generated,
|
|
35
|
+
value: local.value,
|
|
36
|
+
defaultValue: local.defaultValue,
|
|
37
|
+
locale: local.locale,
|
|
38
|
+
min: local.min,
|
|
39
|
+
max: local.max,
|
|
40
|
+
placeholders: local.placeholders,
|
|
41
|
+
disabled: local.disabled,
|
|
42
|
+
readOnly: local.readOnly,
|
|
43
|
+
required: local.required,
|
|
44
|
+
name: local.name,
|
|
45
|
+
form: local.form,
|
|
46
|
+
onValueChange: (value, details) => local.onValueChange?.(value, details),
|
|
47
|
+
}));
|
|
48
|
+
return (<Context.Provider value={made}>
|
|
49
|
+
<Part part={made.root} tag="div" {...rest}/>
|
|
50
|
+
</Context.Provider>);
|
|
51
|
+
}
|
|
52
|
+
/** Draws its child once for each piece of the date, in the locale's order. */
|
|
53
|
+
function Segments(props) {
|
|
54
|
+
const segments = fromSignal(useDateField().segments);
|
|
55
|
+
return <For each={segments()}>{(segment) => props.children(segment)}</For>;
|
|
56
|
+
}
|
|
57
|
+
/** One piece: a part that is typed, or what stands between two. It writes its own text. */
|
|
58
|
+
function Segment(props) {
|
|
59
|
+
const [local, rest] = splitProps(props, ["segment"]);
|
|
60
|
+
const made = useDateField().segment(local.segment);
|
|
61
|
+
const shown = fromSignal(made.text);
|
|
62
|
+
return (<Part part={made.part} tag="span" {...rest}>
|
|
63
|
+
{shown()}
|
|
64
|
+
</Part>);
|
|
65
|
+
}
|
|
66
|
+
const Input = (props) => (<Part part={useDateField().input} tag="input" {...props}/>);
|
|
67
|
+
export const DateField = { Root, Segments, Segment, Input };
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { within } from "@kirana-ui/core";
|
|
2
|
+
import { createDatePicker } from "@kirana-ui/core/date-picker";
|
|
3
|
+
import { createContext, createUniqueId, useContext } from "solid-js";
|
|
4
|
+
import { Calendar, CalendarContext } from "./calendar.jsx";
|
|
5
|
+
import { DateField, DateFieldContext } from "./date-field.jsx";
|
|
6
|
+
import { DirectionContext } from "./direction-context.js";
|
|
7
|
+
import { Popover, PopoverContext } from "./popover.jsx";
|
|
8
|
+
import { Part, controller } from "./runtime.jsx";
|
|
9
|
+
const Context = createContext();
|
|
10
|
+
function useDatePicker() {
|
|
11
|
+
const made = useContext(Context);
|
|
12
|
+
if (!made)
|
|
13
|
+
throw new Error("A DatePicker part must be inside <DatePicker.Root>");
|
|
14
|
+
return made;
|
|
15
|
+
}
|
|
16
|
+
/** A date field, and a calendar in a popover, with one value between them. It draws nothing. */
|
|
17
|
+
function Root(props) {
|
|
18
|
+
const generated = createUniqueId();
|
|
19
|
+
const made = controller(within(createDatePicker, { direction: useContext(DirectionContext) }), () => ({
|
|
20
|
+
id: props.id ?? generated,
|
|
21
|
+
value: props.value,
|
|
22
|
+
defaultValue: props.defaultValue,
|
|
23
|
+
open: props.open,
|
|
24
|
+
defaultOpen: props.defaultOpen,
|
|
25
|
+
locale: props.locale,
|
|
26
|
+
min: props.min,
|
|
27
|
+
max: props.max,
|
|
28
|
+
isDateUnavailable: props.isDateUnavailable,
|
|
29
|
+
calendarSystem: props.calendarSystem,
|
|
30
|
+
fixedWeeks: props.fixedWeeks,
|
|
31
|
+
placeholders: props.placeholders,
|
|
32
|
+
disabled: props.disabled,
|
|
33
|
+
readOnly: props.readOnly,
|
|
34
|
+
required: props.required,
|
|
35
|
+
name: props.name,
|
|
36
|
+
form: props.form,
|
|
37
|
+
onValueChange: (value, details) => props.onValueChange?.(value, details),
|
|
38
|
+
onOpenChange: (open, details) => props.onOpenChange?.(open, details),
|
|
39
|
+
}));
|
|
40
|
+
return (<Context.Provider value={made}>
|
|
41
|
+
<DateFieldContext.Provider value={made.field}>
|
|
42
|
+
<PopoverContext.Provider value={made.popover}>
|
|
43
|
+
<CalendarContext.Provider value={made.calendar}>
|
|
44
|
+
{props.children}
|
|
45
|
+
</CalendarContext.Provider>
|
|
46
|
+
</PopoverContext.Provider>
|
|
47
|
+
</DateFieldContext.Provider>
|
|
48
|
+
</Context.Provider>);
|
|
49
|
+
}
|
|
50
|
+
export const DatePicker = {
|
|
51
|
+
Root,
|
|
52
|
+
/** The typed date: what holds its segments and its hidden input. */
|
|
53
|
+
Field: (props) => (<Part part={useDatePicker().field.root} tag="div" {...props}/>),
|
|
54
|
+
Segments: DateField.Segments,
|
|
55
|
+
Segment: DateField.Segment,
|
|
56
|
+
Input: DateField.Input,
|
|
57
|
+
Trigger: Popover.Trigger,
|
|
58
|
+
Portal: Popover.Portal,
|
|
59
|
+
Positioner: Popover.Positioner,
|
|
60
|
+
Popup: Popover.Popup,
|
|
61
|
+
/** The calendar: what holds its heading, its buttons and its grid. */
|
|
62
|
+
Calendar: (props) => (<Part part={useDatePicker().calendar.root} tag="div" {...props}/>),
|
|
63
|
+
Heading: Calendar.Heading,
|
|
64
|
+
Previous: Calendar.Previous,
|
|
65
|
+
Next: Calendar.Next,
|
|
66
|
+
Grid: Calendar.Grid,
|
|
67
|
+
Weekdays: Calendar.Weekdays,
|
|
68
|
+
HeadCell: Calendar.HeadCell,
|
|
69
|
+
Weeks: Calendar.Weeks,
|
|
70
|
+
Cell: Calendar.Cell,
|
|
71
|
+
Day: Calendar.Day,
|
|
72
|
+
};
|
package/src/dialog.jsx
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { createAlertDialog } from "@kirana-ui/core/alert-dialog";
|
|
2
|
+
import { createDialog } from "@kirana-ui/core/dialog";
|
|
3
|
+
import { createDrawer } from "@kirana-ui/core/drawer";
|
|
4
|
+
import { createContext, createUniqueId, useContext } from "solid-js";
|
|
5
|
+
import { Part, Portal as BodyPortal, controller } from "./runtime.jsx";
|
|
6
|
+
const Context = createContext();
|
|
7
|
+
function useDialog() {
|
|
8
|
+
const made = useContext(Context);
|
|
9
|
+
if (!made)
|
|
10
|
+
throw new Error("A Dialog part must be inside <Dialog.Root>");
|
|
11
|
+
return made;
|
|
12
|
+
}
|
|
13
|
+
function Root(props) {
|
|
14
|
+
const generated = createUniqueId();
|
|
15
|
+
const made = controller(createDialog, () => ({
|
|
16
|
+
id: props.id ?? generated,
|
|
17
|
+
open: props.open,
|
|
18
|
+
defaultOpen: props.defaultOpen,
|
|
19
|
+
modal: props.modal,
|
|
20
|
+
dismissible: props.dismissible,
|
|
21
|
+
onOpenChange: (open, details) => props.onOpenChange?.(open, details),
|
|
22
|
+
}));
|
|
23
|
+
return <Context.Provider value={made}>{props.children}</Context.Provider>;
|
|
24
|
+
}
|
|
25
|
+
const Portal = (props) => (<BodyPortal mounted={useDialog().mounted}>{props.children}</BodyPortal>);
|
|
26
|
+
const part = (name, tag) => (props) => <Part part={useDialog()[name]} tag={tag} {...props}/>;
|
|
27
|
+
function AlertRoot(props) {
|
|
28
|
+
const generated = createUniqueId();
|
|
29
|
+
const made = controller(createAlertDialog, () => ({
|
|
30
|
+
id: props.id ?? generated,
|
|
31
|
+
open: props.open,
|
|
32
|
+
defaultOpen: props.defaultOpen,
|
|
33
|
+
onOpenChange: (open, details) => props.onOpenChange?.(open, details),
|
|
34
|
+
}));
|
|
35
|
+
return <Context.Provider value={made}>{props.children}</Context.Provider>;
|
|
36
|
+
}
|
|
37
|
+
export const Dialog = {
|
|
38
|
+
Root,
|
|
39
|
+
Portal,
|
|
40
|
+
Trigger: part("trigger", "button"),
|
|
41
|
+
Backdrop: part("backdrop", "div"),
|
|
42
|
+
Popup: part("popup", "div"),
|
|
43
|
+
Title: part("title", "h2"),
|
|
44
|
+
Description: part("description", "p"),
|
|
45
|
+
Close: part("close", "button"),
|
|
46
|
+
};
|
|
47
|
+
/** A dialog that asks for an answer: a press outside it does not close it. Its parts are a dialog's. */
|
|
48
|
+
export const AlertDialog = { ...Dialog, Root: AlertRoot };
|
|
49
|
+
function DrawerRoot(props) {
|
|
50
|
+
const generated = createUniqueId();
|
|
51
|
+
const made = controller(createDrawer, () => ({
|
|
52
|
+
id: props.id ?? generated,
|
|
53
|
+
open: props.open,
|
|
54
|
+
defaultOpen: props.defaultOpen,
|
|
55
|
+
modal: props.modal,
|
|
56
|
+
dismissible: props.dismissible,
|
|
57
|
+
swipeDirection: props.swipeDirection,
|
|
58
|
+
snapPoints: props.snapPoints,
|
|
59
|
+
snapPoint: props.snapPoint,
|
|
60
|
+
defaultSnapPoint: props.defaultSnapPoint,
|
|
61
|
+
onSnapPointChange: (snapPoint, details) => props.onSnapPointChange?.(snapPoint, details),
|
|
62
|
+
onOpenChange: (open, details) => props.onOpenChange?.(open, details),
|
|
63
|
+
}));
|
|
64
|
+
return <Context.Provider value={made}>{props.children}</Context.Provider>;
|
|
65
|
+
}
|
|
66
|
+
/** A dialog that comes from an edge and is dragged back to it. Its parts are a dialog's. */
|
|
67
|
+
export const Drawer = { ...Dialog, Root: DrawerRoot };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { signal } from "@kirana-ui/core";
|
|
2
|
+
import { createDirection } from "@kirana-ui/core/direction";
|
|
3
|
+
import { useContext } from "solid-js";
|
|
4
|
+
import { DirectionContext } from "./direction-context.js";
|
|
5
|
+
import { controller, fromSignal } from "./runtime.jsx";
|
|
6
|
+
/**
|
|
7
|
+
* States the reading direction for the components inside. It draws nothing: set the page's own
|
|
8
|
+
* `dir` attribute with it.
|
|
9
|
+
*/
|
|
10
|
+
export function DirectionProvider(props) {
|
|
11
|
+
const made = controller(createDirection, () => ({ direction: props.direction }));
|
|
12
|
+
return (<DirectionContext.Provider value={made.direction}>{props.children}</DirectionContext.Provider>);
|
|
13
|
+
}
|
|
14
|
+
/** The direction the nearest provider states; `ltr` outside one. */
|
|
15
|
+
export function useDirection() {
|
|
16
|
+
return fromSignal(useContext(DirectionContext) ?? signal("ltr"));
|
|
17
|
+
}
|
package/src/drawer.js
ADDED