@kirana-ui/solid 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dom/accordion.js +9 -6
- package/dom/agent.js +3 -0
- package/dom/autocomplete.js +2 -0
- package/dom/autosize.js +19 -0
- package/dom/avatar.js +3 -3
- package/dom/button.js +1 -1
- package/dom/calendar.js +145 -0
- package/dom/carousel.js +83 -0
- package/dom/checkbox.js +5 -4
- package/dom/collapsible.js +3 -3
- package/dom/combobox.js +289 -0
- package/dom/command.js +129 -0
- package/dom/context-menu.js +2 -0
- package/dom/date-field.js +90 -0
- package/dom/date-picker.js +103 -0
- package/dom/dialog.js +32 -1
- package/dom/drawer.js +2 -0
- package/dom/field.js +3 -3
- package/dom/fieldset.js +2 -2
- package/dom/form.js +1 -1
- package/dom/hover-popup.js +19 -4
- package/dom/index.js +26 -1
- 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/navigation-menu.js +147 -0
- package/dom/number-field.js +82 -0
- package/dom/otp.js +95 -0
- package/dom/pagination.js +74 -0
- package/dom/popover.js +22 -7
- package/dom/qr-code.js +48 -0
- package/dom/radio-group.js +6 -5
- package/dom/resizable.js +65 -0
- package/dom/runtime.js +59 -9
- package/dom/scroll-area.js +99 -0
- package/dom/select.js +91 -15
- package/dom/separator.js +1 -1
- package/dom/slider.js +11 -8
- package/dom/switch.js +5 -4
- package/dom/tabs.js +5 -5
- package/dom/testing.js +3 -0
- package/dom/toast.js +150 -0
- package/dom/toggle-group.js +37 -0
- package/dom/toggle.js +12 -4
- package/dom/toolbar-context.js +5 -0
- package/dom/toolbar.js +71 -0
- package/dom/value-bar.js +3 -3
- package/llms.txt +3202 -0
- package/package.json +236 -2
- package/server/accordion.js +9 -6
- package/server/agent.js +3 -0
- package/server/autocomplete.js +2 -0
- package/server/autosize.js +19 -0
- package/server/avatar.js +3 -3
- package/server/button.js +1 -1
- package/server/calendar.js +144 -0
- package/server/carousel.js +83 -0
- package/server/checkbox.js +5 -4
- package/server/collapsible.js +3 -3
- package/server/combobox.js +289 -0
- package/server/command.js +129 -0
- package/server/context-menu.js +2 -0
- package/server/date-field.js +90 -0
- package/server/date-picker.js +103 -0
- package/server/dialog.js +32 -1
- package/server/drawer.js +2 -0
- package/server/field.js +3 -3
- package/server/fieldset.js +2 -2
- package/server/form.js +1 -1
- package/server/hover-popup.js +19 -4
- package/server/index.js +26 -1
- 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/navigation-menu.js +147 -0
- package/server/number-field.js +81 -0
- package/server/otp.js +94 -0
- package/server/pagination.js +74 -0
- package/server/popover.js +22 -7
- package/server/qr-code.js +48 -0
- package/server/radio-group.js +6 -5
- package/server/resizable.js +65 -0
- package/server/runtime.js +58 -8
- package/server/scroll-area.js +99 -0
- package/server/select.js +91 -15
- package/server/separator.js +1 -1
- package/server/slider.js +11 -8
- package/server/switch.js +5 -4
- package/server/tabs.js +5 -5
- package/server/testing.js +3 -0
- package/server/toast.js +150 -0
- package/server/toggle-group.js +37 -0
- package/server/toggle.js +12 -4
- package/server/toolbar-context.js +5 -0
- package/server/toolbar.js +71 -0
- package/server/value-bar.js +3 -3
- package/skills/kirana-ui-primitives/SKILL.md +142 -0
- package/src/accordion.jsx +10 -7
- package/src/agent.js +3 -0
- package/src/autocomplete.jsx +2 -0
- package/src/autosize.jsx +8 -0
- package/src/avatar.jsx +3 -3
- package/src/button.jsx +1 -1
- package/src/calendar.jsx +108 -0
- package/src/carousel.jsx +51 -0
- package/src/checkbox.jsx +5 -3
- package/src/collapsible.jsx +3 -3
- package/src/combobox.jsx +187 -0
- package/src/command.jsx +81 -0
- package/src/context-menu.js +2 -0
- package/src/date-field.jsx +71 -0
- package/src/date-picker.jsx +72 -0
- package/src/dialog.jsx +27 -1
- package/src/drawer.js +2 -0
- package/src/field.jsx +3 -3
- package/src/fieldset.jsx +2 -2
- package/src/form.jsx +1 -1
- package/src/hover-popup.jsx +12 -4
- package/src/index.js +26 -1
- 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/navigation-menu.jsx +96 -0
- package/src/number-field.jsx +75 -0
- package/src/otp.jsx +73 -0
- package/src/pagination.jsx +60 -0
- package/src/popover.jsx +22 -4
- package/src/qr-code.jsx +25 -0
- package/src/radio-group.jsx +7 -5
- package/src/resizable.jsx +46 -0
- package/src/runtime.jsx +54 -9
- package/src/scroll-area.jsx +53 -0
- package/src/select.jsx +72 -14
- package/src/separator.jsx +1 -1
- package/src/slider.jsx +13 -8
- package/src/switch.jsx +5 -3
- package/src/tabs.jsx +6 -6
- package/src/testing.js +3 -0
- package/src/toast.jsx +86 -0
- package/src/toggle-group.jsx +32 -0
- package/src/toggle.jsx +9 -3
- package/src/toolbar-context.js +5 -0
- package/src/toolbar.jsx +43 -0
- package/src/value-bar.jsx +3 -3
- package/types/accordion.d.ts +21 -19
- package/types/agent.d.ts +1 -0
- package/types/alert-dialog.d.ts +1 -0
- package/types/autocomplete.d.ts +2 -0
- package/types/autosize.d.ts +11 -0
- package/types/avatar.d.ts +12 -5
- package/types/button.d.ts +4 -2
- package/types/calendar.d.ts +57 -0
- package/types/carousel.d.ts +34 -0
- package/types/checkbox.d.ts +10 -6
- package/types/collapsible.d.ts +11 -7
- package/types/combobox.d.ts +105 -0
- package/types/command.d.ts +55 -0
- package/types/context-menu.d.ts +2 -0
- package/types/date-field.d.ts +34 -0
- package/types/date-picker.d.ts +40 -0
- package/types/dialog.d.ts +52 -20
- package/types/direction.d.ts +1 -0
- package/types/drawer.d.ts +2 -0
- package/types/field.d.ts +19 -11
- package/types/fieldset.d.ts +8 -3
- package/types/form.d.ts +5 -2
- package/types/hover-card.d.ts +16 -7
- package/types/hover-popup.d.ts +23 -10
- package/types/index.d.ts +39 -2
- package/types/input.d.ts +13 -0
- package/types/label.d.ts +7 -0
- package/types/listbox.d.ts +36 -0
- package/types/menu.d.ts +105 -0
- package/types/menubar-context.d.ts +3 -0
- package/types/menubar.d.ts +12 -0
- package/types/message-scroller.d.ts +22 -0
- package/types/meter.d.ts +16 -7
- package/types/navigation-menu.d.ts +50 -0
- package/types/number-field.d.ts +22 -0
- package/types/otp.d.ts +39 -0
- package/types/pagination.d.ts +31 -0
- package/types/popover.d.ts +41 -13
- package/types/progress.d.ts +16 -7
- package/types/qr-code.d.ts +20 -0
- package/types/radio-group.d.ts +15 -16
- package/types/resizable.d.ts +29 -0
- package/types/runtime.d.ts +53 -11
- package/types/scroll-area.d.ts +28 -0
- package/types/select.d.ts +66 -33
- package/types/separator.d.ts +5 -3
- package/types/slider.d.ts +25 -13
- package/types/switch.d.ts +8 -4
- package/types/tabs.d.ts +20 -16
- package/types/testing.d.ts +1 -0
- package/types/toast.d.ts +57 -0
- package/types/toggle-group.d.ts +9 -0
- package/types/toggle.d.ts +6 -3
- package/types/toolbar-context.d.ts +6 -0
- package/types/toolbar.d.ts +28 -0
- package/types/tooltip.d.ts +16 -7
- package/types/value-bar.d.ts +21 -10
package/src/field.jsx
CHANGED
|
@@ -28,7 +28,7 @@ function Root(props) {
|
|
|
28
28
|
validate: (value) => local.validate?.(value) ?? null,
|
|
29
29
|
}));
|
|
30
30
|
return (<FieldContext.Provider value={made}>
|
|
31
|
-
<Part
|
|
31
|
+
<Part of={made.root} tag="div" {...rest}/>
|
|
32
32
|
</FieldContext.Provider>);
|
|
33
33
|
}
|
|
34
34
|
/**
|
|
@@ -43,7 +43,7 @@ function FieldError(props) {
|
|
|
43
43
|
const mounted = fromSignal(error.mounted);
|
|
44
44
|
const text = fromSignal(error.text);
|
|
45
45
|
return (<Show when={mounted()}>
|
|
46
|
-
<Part
|
|
46
|
+
<Part of={error.part} tag="div" {...rest}>
|
|
47
47
|
{local.children ?? text()}
|
|
48
48
|
</Part>
|
|
49
49
|
</Show>);
|
|
@@ -52,7 +52,7 @@ function FieldError(props) {
|
|
|
52
52
|
function Validity(props) {
|
|
53
53
|
return props.children(fromSignal(useField().validity));
|
|
54
54
|
}
|
|
55
|
-
const part = (key, tag) => (props) =>
|
|
55
|
+
const part = (key, tag) => (props) => <Part of={useField()[key]} tag={tag} {...props}/>;
|
|
56
56
|
export const Field = {
|
|
57
57
|
Root,
|
|
58
58
|
Label: part("label", "label"),
|
package/src/fieldset.jsx
CHANGED
|
@@ -17,8 +17,8 @@ function Root(props) {
|
|
|
17
17
|
disabled: local.disabled,
|
|
18
18
|
}));
|
|
19
19
|
return (<FieldsetContext.Provider value={made}>
|
|
20
|
-
<Part
|
|
20
|
+
<Part of={made.root} tag="fieldset" {...rest}/>
|
|
21
21
|
</FieldsetContext.Provider>);
|
|
22
22
|
}
|
|
23
|
-
const Legend = (props) =>
|
|
23
|
+
const Legend = (props) => <Part of={useFieldset().legend} tag="div" {...props}/>;
|
|
24
24
|
export const Fieldset = { Root, Legend };
|
package/src/form.jsx
CHANGED
|
@@ -21,6 +21,6 @@ export function Form(props) {
|
|
|
21
21
|
onClearErrors: (errors) => local.onClearErrors?.(errors),
|
|
22
22
|
}));
|
|
23
23
|
return (<FormContext.Provider value={made}>
|
|
24
|
-
<Part
|
|
24
|
+
<Part of={made.root} tag="form" {...rest}/>
|
|
25
25
|
</FormContext.Provider>);
|
|
26
26
|
}
|
package/src/hover-popup.jsx
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { defined } from "@kirana-ui/core";
|
|
2
|
+
import { createComputed, createContext, createUniqueId, splitProps, useContext } from "solid-js";
|
|
2
3
|
import { positioned } from "./popover.jsx";
|
|
3
4
|
import { Part, Portal as BodyPortal, controller } from "./runtime.jsx";
|
|
4
5
|
/** The parts of a popup the pointer opens: a tooltip's, a hover card's. */
|
|
@@ -26,14 +27,21 @@ export function hoverPopup(name, create, triggerTag) {
|
|
|
26
27
|
const Portal = (props) => (<BodyPortal mounted={use().mounted}>{props.children}</BodyPortal>);
|
|
27
28
|
function Positioner(props) {
|
|
28
29
|
const made = use();
|
|
29
|
-
return <Part
|
|
30
|
+
return <Part of={made.positioner} tag="div" {...positioned(props, made.positioning)}/>;
|
|
31
|
+
}
|
|
32
|
+
const part = (key, tag) => (props) => <Part of={use()[key]} tag={tag} {...props}/>;
|
|
33
|
+
/** `delay` and `closeDelay` here come before the root's. */
|
|
34
|
+
function Trigger(props) {
|
|
35
|
+
const [local, rest] = splitProps(props, ["delay", "closeDelay"]);
|
|
36
|
+
const made = use();
|
|
37
|
+
createComputed(() => made.timing.set(defined({ ...local })));
|
|
38
|
+
return <Part of={made.trigger} tag={triggerTag} {...rest}/>;
|
|
30
39
|
}
|
|
31
|
-
const part = (key, tag) => (props) => (<Part part={use()[key]} tag={tag} {...props}/>);
|
|
32
40
|
return {
|
|
33
41
|
Root,
|
|
34
42
|
Portal,
|
|
35
43
|
Positioner,
|
|
36
|
-
Trigger
|
|
44
|
+
Trigger,
|
|
37
45
|
Popup: part("popup", "div"),
|
|
38
46
|
Arrow: part("arrow", "div"),
|
|
39
47
|
};
|
package/src/index.js
CHANGED
|
@@ -1,8 +1,29 @@
|
|
|
1
1
|
export { Accordion } from "./accordion.jsx";
|
|
2
2
|
export { Checkbox } from "./checkbox.jsx";
|
|
3
3
|
export { Collapsible } from "./collapsible.jsx";
|
|
4
|
-
export { AlertDialog, Dialog } from "./dialog.jsx";
|
|
4
|
+
export { AlertDialog, Dialog, Drawer } from "./dialog.jsx";
|
|
5
|
+
export { MessageScroller } from "./message-scroller.jsx";
|
|
5
6
|
export { HoverCard } from "./hover-card.jsx";
|
|
7
|
+
export { Combobox } from "./combobox.jsx";
|
|
8
|
+
export { Listbox } from "./listbox.jsx";
|
|
9
|
+
export { ContextMenu, Menu } from "./menu.jsx";
|
|
10
|
+
export { Menubar } from "./menubar.jsx";
|
|
11
|
+
export { NavigationMenu } from "./navigation-menu.jsx";
|
|
12
|
+
export { Otp } from "./otp.jsx";
|
|
13
|
+
export { DateField } from "./date-field.jsx";
|
|
14
|
+
export { Input } from "./input.jsx";
|
|
15
|
+
export { Label } from "./label.jsx";
|
|
16
|
+
export { Command } from "./command.jsx";
|
|
17
|
+
export { NumberField } from "./number-field.jsx";
|
|
18
|
+
export { Autocomplete } from "./autocomplete.jsx";
|
|
19
|
+
export { Pagination } from "./pagination.jsx";
|
|
20
|
+
export { DatePicker } from "./date-picker.jsx";
|
|
21
|
+
export { Calendar } from "./calendar.jsx";
|
|
22
|
+
export { QrCode } from "./qr-code.jsx";
|
|
23
|
+
export { Autosize } from "./autosize.jsx";
|
|
24
|
+
export { Carousel } from "./carousel.jsx";
|
|
25
|
+
export { Toast, createToaster } from "./toast.jsx";
|
|
26
|
+
export { Resizable } from "./resizable.jsx";
|
|
6
27
|
export { Popover } from "./popover.jsx";
|
|
7
28
|
export { RadioGroup } from "./radio-group.jsx";
|
|
8
29
|
export { Select } from "./select.jsx";
|
|
@@ -15,8 +36,12 @@ export { Meter } from "./meter.jsx";
|
|
|
15
36
|
export { Progress } from "./progress.jsx";
|
|
16
37
|
export { Separator } from "./separator.jsx";
|
|
17
38
|
export { Toggle } from "./toggle.jsx";
|
|
39
|
+
export { ToggleGroup } from "./toggle-group.jsx";
|
|
40
|
+
export { Toolbar } from "./toolbar.jsx";
|
|
41
|
+
export { ScrollArea } from "./scroll-area.jsx";
|
|
18
42
|
export { Slider } from "./slider.jsx";
|
|
19
43
|
export { Field } from "./field.jsx";
|
|
20
44
|
export { Fieldset } from "./fieldset.jsx";
|
|
21
45
|
export { Form } from "./form.jsx";
|
|
22
46
|
export { DirectionProvider, useDirection } from "./direction.jsx";
|
|
47
|
+
export { PortalProvider } from "./runtime.jsx";
|
package/src/input.jsx
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { within } from "@kirana-ui/core";
|
|
2
|
+
import { createInput } from "@kirana-ui/core/input";
|
|
3
|
+
import { splitProps, useContext } from "solid-js";
|
|
4
|
+
import { FieldContext } from "./field-context.js";
|
|
5
|
+
import { Part, controller } from "./runtime.jsx";
|
|
6
|
+
/**
|
|
7
|
+
* An `<input>`; `as="textarea"` for a text area. It takes what an `<input>` takes, and inside
|
|
8
|
+
* a `<Field.Root>` it is the field's control.
|
|
9
|
+
*/
|
|
10
|
+
export function Input(props) {
|
|
11
|
+
const [local, rest] = splitProps(props, ["disabled", "onValueChange"]);
|
|
12
|
+
const made = controller(within(createInput, { field: useContext(FieldContext) }), () => ({
|
|
13
|
+
disabled: local.disabled,
|
|
14
|
+
onValueChange: (value, details) => local.onValueChange?.(value, details),
|
|
15
|
+
}));
|
|
16
|
+
return <Part of={made.input} tag="input" {...rest}/>;
|
|
17
|
+
}
|
package/src/label.jsx
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { createLabel } from "@kirana-ui/core/label";
|
|
2
|
+
import { useContext } from "solid-js";
|
|
3
|
+
import { FieldContext } from "./field-context.js";
|
|
4
|
+
import { Part } from "./runtime.jsx";
|
|
5
|
+
/** A `<label>`. Inside a `<Field.Root>` it is the field's label. */
|
|
6
|
+
export function Label(props) {
|
|
7
|
+
const made = createLabel({ field: useContext(FieldContext) });
|
|
8
|
+
return <Part of={made.label} tag="label" {...props}/>;
|
|
9
|
+
}
|
package/src/listbox.jsx
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { defined } from "@kirana-ui/core";
|
|
2
|
+
import { createListbox } from "@kirana-ui/core/listbox";
|
|
3
|
+
import { Show, createContext, createUniqueId, splitProps, untrack, useContext } from "solid-js";
|
|
4
|
+
import { Part, controller, fromSignal, toSignal } from "./runtime.jsx";
|
|
5
|
+
const Context = createContext();
|
|
6
|
+
const ItemContext = createContext();
|
|
7
|
+
const GroupContext = createContext();
|
|
8
|
+
function useListbox() {
|
|
9
|
+
const made = useContext(Context);
|
|
10
|
+
if (!made)
|
|
11
|
+
throw new Error("A Listbox part must be inside <Listbox.Root>");
|
|
12
|
+
return made;
|
|
13
|
+
}
|
|
14
|
+
function Root(props) {
|
|
15
|
+
const [local, rest] = splitProps(props, [
|
|
16
|
+
"value",
|
|
17
|
+
"defaultValue",
|
|
18
|
+
"onValueChange",
|
|
19
|
+
"multiple",
|
|
20
|
+
"disabled",
|
|
21
|
+
"loop",
|
|
22
|
+
"name",
|
|
23
|
+
"form",
|
|
24
|
+
"virtualized",
|
|
25
|
+
"id",
|
|
26
|
+
]);
|
|
27
|
+
const generated = createUniqueId();
|
|
28
|
+
const made = controller((createListbox), () => ({
|
|
29
|
+
id: local.id ?? generated,
|
|
30
|
+
value: local.value,
|
|
31
|
+
defaultValue: local.defaultValue,
|
|
32
|
+
multiple: local.multiple,
|
|
33
|
+
disabled: local.disabled,
|
|
34
|
+
loop: local.loop,
|
|
35
|
+
name: local.name,
|
|
36
|
+
form: local.form,
|
|
37
|
+
virtualized: local.virtualized,
|
|
38
|
+
onValueChange: (value, details) => local.onValueChange?.(value, details),
|
|
39
|
+
}));
|
|
40
|
+
return (<Context.Provider value={made}>
|
|
41
|
+
<Part of={made.root} tag="div" {...rest}/>
|
|
42
|
+
</Context.Provider>);
|
|
43
|
+
}
|
|
44
|
+
function Item(props) {
|
|
45
|
+
const [local, rest] = splitProps(props, ["value", "disabled", "label", "index"]);
|
|
46
|
+
// An item is its value for as long as it is in the page.
|
|
47
|
+
const value = untrack(() => local.value);
|
|
48
|
+
const options = toSignal(() => ({
|
|
49
|
+
disabled: local.disabled,
|
|
50
|
+
label: local.label,
|
|
51
|
+
index: local.index,
|
|
52
|
+
}));
|
|
53
|
+
const part = useListbox().item(value, () => defined(options.get()));
|
|
54
|
+
return (<ItemContext.Provider value={value}>
|
|
55
|
+
<Part of={part} tag="div" {...rest}/>
|
|
56
|
+
</ItemContext.Provider>);
|
|
57
|
+
}
|
|
58
|
+
function ItemIndicator(props) {
|
|
59
|
+
const [local, rest] = splitProps(props, ["keepMounted"]);
|
|
60
|
+
const made = useListbox();
|
|
61
|
+
const value = useContext(ItemContext);
|
|
62
|
+
const selected = fromSignal(made.selected(value));
|
|
63
|
+
return (<Show when={selected() || local.keepMounted}>
|
|
64
|
+
<Part of={made.indicator(value)} tag="span" {...rest}/>
|
|
65
|
+
</Show>);
|
|
66
|
+
}
|
|
67
|
+
function Group(props) {
|
|
68
|
+
const [local, rest] = splitProps(props, ["id"]);
|
|
69
|
+
const generated = createUniqueId();
|
|
70
|
+
const group = useListbox().group(untrack(() => local.id) ?? generated);
|
|
71
|
+
return (<GroupContext.Provider value={group}>
|
|
72
|
+
<Part of={group.root} tag="div" {...rest}/>
|
|
73
|
+
</GroupContext.Provider>);
|
|
74
|
+
}
|
|
75
|
+
function GroupLabel(props) {
|
|
76
|
+
const group = useContext(GroupContext);
|
|
77
|
+
if (!group)
|
|
78
|
+
throw new Error("A Listbox.GroupLabel must be inside <Listbox.Group>");
|
|
79
|
+
return <Part of={group.label} tag="div" {...props}/>;
|
|
80
|
+
}
|
|
81
|
+
export const Listbox = { Root, Item, ItemIndicator, Group, GroupLabel };
|
package/src/menu.jsx
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { defined, within } from "@kirana-ui/core";
|
|
2
|
+
import { createMenu } from "@kirana-ui/core/menu";
|
|
3
|
+
import { Show, createContext, createUniqueId, splitProps, untrack, useContext } from "solid-js";
|
|
4
|
+
import { DirectionContext } from "./direction-context.js";
|
|
5
|
+
import { MenubarContext } from "./menubar-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 GroupContext = createContext(null);
|
|
10
|
+
const CheckboxContext = createContext();
|
|
11
|
+
const RadioGroupContext = createContext();
|
|
12
|
+
const RadioItemContext = createContext();
|
|
13
|
+
function useMenu() {
|
|
14
|
+
const made = useContext(Context);
|
|
15
|
+
if (!made)
|
|
16
|
+
throw new Error("A Menu part must be inside <Menu.Root>");
|
|
17
|
+
return made;
|
|
18
|
+
}
|
|
19
|
+
function inside(found, parent) {
|
|
20
|
+
if (!found)
|
|
21
|
+
throw new Error(`A Menu part must be inside <Menu.${parent}>`);
|
|
22
|
+
return found;
|
|
23
|
+
}
|
|
24
|
+
function make(props, kind) {
|
|
25
|
+
const generated = createUniqueId();
|
|
26
|
+
const direction = useContext(DirectionContext);
|
|
27
|
+
const parent = kind === "submenu" ? useMenu() : undefined;
|
|
28
|
+
const menubar = kind === "menu" ? (useContext(MenubarContext) ?? undefined) : undefined;
|
|
29
|
+
const around = { parent, direction, menubar, context: kind === "context" };
|
|
30
|
+
const made = controller(within(createMenu, around), () => ({
|
|
31
|
+
id: props.id ?? generated,
|
|
32
|
+
open: props.open,
|
|
33
|
+
defaultOpen: props.defaultOpen,
|
|
34
|
+
disabled: props.disabled,
|
|
35
|
+
loop: props.loop,
|
|
36
|
+
modal: props.modal,
|
|
37
|
+
onOpenChange: (open, details) => props.onOpenChange?.(open, details),
|
|
38
|
+
}));
|
|
39
|
+
return (<Context.Provider value={made}>
|
|
40
|
+
{/* A group around a submenu is not a group of the submenu's own items; nor is a menu
|
|
41
|
+
written inside a bar's menu one of the bar's. */}
|
|
42
|
+
<MenubarContext.Provider value={null}>
|
|
43
|
+
<GroupContext.Provider value={null}>{props.children}</GroupContext.Provider>
|
|
44
|
+
</MenubarContext.Provider>
|
|
45
|
+
</Context.Provider>);
|
|
46
|
+
}
|
|
47
|
+
const Root = (props) => make(props, "menu");
|
|
48
|
+
/** A menu for an area of the page, opened at the pointer. Its trigger is the area. */
|
|
49
|
+
const ContextRoot = (props) => make(props, "context");
|
|
50
|
+
/** A menu that one of this menu's items opens. Its trigger is `<Menu.SubmenuTrigger>`. */
|
|
51
|
+
const SubmenuRoot = (props) => make(props, "submenu");
|
|
52
|
+
const Portal = (props) => (<BodyPortal mounted={useMenu().mounted}>{props.children}</BodyPortal>);
|
|
53
|
+
function Positioner(props) {
|
|
54
|
+
const made = useMenu();
|
|
55
|
+
return <Part of={made.positioner} tag="div" {...positioned(props, made.positioning)}/>;
|
|
56
|
+
}
|
|
57
|
+
const ITEM = ["disabled", "label", "closeOnClick"];
|
|
58
|
+
function Item(props) {
|
|
59
|
+
const [local, rest] = splitProps(props, ITEM);
|
|
60
|
+
const options = toSignal(() => ({ ...local }));
|
|
61
|
+
const part = useMenu().item(() => defined(options.get()));
|
|
62
|
+
return <Part of={part} tag="div" {...rest}/>;
|
|
63
|
+
}
|
|
64
|
+
/** An item that is a link: `href` and the rest go to its `<a>`. */
|
|
65
|
+
function LinkItem(props) {
|
|
66
|
+
const [local, rest] = splitProps(props, ITEM);
|
|
67
|
+
const options = toSignal(() => ({ ...local }));
|
|
68
|
+
const part = useMenu().item(() => defined(options.get()));
|
|
69
|
+
return <Part of={part} tag="a" {...rest}/>;
|
|
70
|
+
}
|
|
71
|
+
function Group(props) {
|
|
72
|
+
const [local, rest] = splitProps(props, ["id"]);
|
|
73
|
+
const generated = createUniqueId();
|
|
74
|
+
const group = useMenu().group(untrack(() => local.id) ?? generated);
|
|
75
|
+
return (<GroupContext.Provider value={group}>
|
|
76
|
+
<Part of={group.root} tag="div" {...rest}/>
|
|
77
|
+
</GroupContext.Provider>);
|
|
78
|
+
}
|
|
79
|
+
/** Names the group it is in. With no group around it, it is plain text. */
|
|
80
|
+
const GroupLabel = (props) => (<Part of={useContext(GroupContext)?.label ?? useMenu().label} tag="div" {...props}/>);
|
|
81
|
+
function CheckboxItem(props) {
|
|
82
|
+
const [local, rest] = splitProps(props, [...ITEM, "checked", "defaultChecked", "onCheckedChange"]);
|
|
83
|
+
const item = controller(useMenu().checkboxItem, () => ({
|
|
84
|
+
checked: local.checked,
|
|
85
|
+
defaultChecked: local.defaultChecked,
|
|
86
|
+
disabled: local.disabled,
|
|
87
|
+
label: local.label,
|
|
88
|
+
closeOnClick: local.closeOnClick,
|
|
89
|
+
onCheckedChange: (checked, details) => local.onCheckedChange?.(checked, details),
|
|
90
|
+
}));
|
|
91
|
+
return (<CheckboxContext.Provider value={item}>
|
|
92
|
+
<Part of={item.part} tag="div" {...rest}/>
|
|
93
|
+
</CheckboxContext.Provider>);
|
|
94
|
+
}
|
|
95
|
+
function CheckboxItemIndicator(props) {
|
|
96
|
+
const [local, rest] = splitProps(props, ["keepMounted"]);
|
|
97
|
+
const item = inside(useContext(CheckboxContext), "CheckboxItem");
|
|
98
|
+
const checked = fromSignal(item.checked);
|
|
99
|
+
return (<Show when={checked() || local.keepMounted}>
|
|
100
|
+
<Part of={item.indicator} tag="span" {...rest}/>
|
|
101
|
+
</Show>);
|
|
102
|
+
}
|
|
103
|
+
function RadioGroup(props) {
|
|
104
|
+
const [local, rest] = splitProps(props, ["value", "defaultValue", "onValueChange", "disabled"]);
|
|
105
|
+
const group = controller((useMenu().radioGroup), () => ({
|
|
106
|
+
value: local.value,
|
|
107
|
+
defaultValue: local.defaultValue,
|
|
108
|
+
disabled: local.disabled,
|
|
109
|
+
onValueChange: (value, details) => local.onValueChange?.(value, details),
|
|
110
|
+
}));
|
|
111
|
+
return (<RadioGroupContext.Provider value={group}>
|
|
112
|
+
<Part of={group.root} tag="div" {...rest}/>
|
|
113
|
+
</RadioGroupContext.Provider>);
|
|
114
|
+
}
|
|
115
|
+
function RadioItem(props) {
|
|
116
|
+
const [local, rest] = splitProps(props, [...ITEM, "value"]);
|
|
117
|
+
// An item is its value for as long as it is in the page.
|
|
118
|
+
const value = untrack(() => local.value);
|
|
119
|
+
const options = toSignal(() => ({
|
|
120
|
+
disabled: local.disabled,
|
|
121
|
+
label: local.label,
|
|
122
|
+
closeOnClick: local.closeOnClick,
|
|
123
|
+
}));
|
|
124
|
+
const part = inside(useContext(RadioGroupContext), "RadioGroup").item(value, () => defined(options.get()));
|
|
125
|
+
return (<RadioItemContext.Provider value={value}>
|
|
126
|
+
<Part of={part} tag="div" {...rest}/>
|
|
127
|
+
</RadioItemContext.Provider>);
|
|
128
|
+
}
|
|
129
|
+
function RadioItemIndicator(props) {
|
|
130
|
+
const [local, rest] = splitProps(props, ["keepMounted"]);
|
|
131
|
+
const group = inside(useContext(RadioGroupContext), "RadioGroup");
|
|
132
|
+
const value = useContext(RadioItemContext);
|
|
133
|
+
const checked = fromSignal(group.checked(value));
|
|
134
|
+
return (<Show when={checked() || local.keepMounted}>
|
|
135
|
+
<Part of={group.indicator(value)} tag="span" {...rest}/>
|
|
136
|
+
</Show>);
|
|
137
|
+
}
|
|
138
|
+
const part = (name, tag) => (props) => <Part of={useMenu()[name]} tag={tag} {...props}/>;
|
|
139
|
+
export const Menu = {
|
|
140
|
+
Root,
|
|
141
|
+
Portal,
|
|
142
|
+
Positioner,
|
|
143
|
+
Trigger: part("trigger", "button"),
|
|
144
|
+
Popup: part("popup", "div"),
|
|
145
|
+
Arrow: part("arrow", "div"),
|
|
146
|
+
Item,
|
|
147
|
+
LinkItem,
|
|
148
|
+
Group,
|
|
149
|
+
GroupLabel,
|
|
150
|
+
Separator: part("separator", "div"),
|
|
151
|
+
CheckboxItem,
|
|
152
|
+
CheckboxItemIndicator,
|
|
153
|
+
RadioGroup,
|
|
154
|
+
RadioItem,
|
|
155
|
+
RadioItemIndicator,
|
|
156
|
+
SubmenuRoot,
|
|
157
|
+
SubmenuTrigger: part("trigger", "div"),
|
|
158
|
+
};
|
|
159
|
+
export const ContextMenu = {
|
|
160
|
+
...Menu,
|
|
161
|
+
Root: ContextRoot,
|
|
162
|
+
/** The area a secondary press, or a long press on a touch screen, opens the menu in. */
|
|
163
|
+
Trigger: part("area", "div"),
|
|
164
|
+
};
|
package/src/menubar.jsx
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { within } from "@kirana-ui/core";
|
|
2
|
+
import { createMenubar } from "@kirana-ui/core/menubar";
|
|
3
|
+
import { createUniqueId, splitProps, useContext } from "solid-js";
|
|
4
|
+
import { DirectionContext } from "./direction-context.js";
|
|
5
|
+
import { MenubarContext } from "./menubar-context.js";
|
|
6
|
+
import { Part, controller } from "./runtime.jsx";
|
|
7
|
+
/** A row of menus that work as one. Each `<Menu.Root>` inside it is one of its items. */
|
|
8
|
+
export function Menubar(props) {
|
|
9
|
+
const [local, rest] = splitProps(props, ["loop", "disabled", "orientation", "id"]);
|
|
10
|
+
const generated = createUniqueId();
|
|
11
|
+
const direction = useContext(DirectionContext);
|
|
12
|
+
const made = controller(within(createMenubar, { direction }), () => ({
|
|
13
|
+
id: local.id ?? generated,
|
|
14
|
+
loop: local.loop,
|
|
15
|
+
disabled: local.disabled,
|
|
16
|
+
orientation: local.orientation,
|
|
17
|
+
}));
|
|
18
|
+
return (<MenubarContext.Provider value={made}>
|
|
19
|
+
<Part of={made.root} tag="div" {...rest}/>
|
|
20
|
+
</MenubarContext.Provider>);
|
|
21
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { createMessageScroller } from "@kirana-ui/core/message-scroller";
|
|
2
|
+
import { createContext, createUniqueId, splitProps, useContext } from "solid-js";
|
|
3
|
+
import { Part, controller } from "./runtime.jsx";
|
|
4
|
+
const Context = createContext();
|
|
5
|
+
function useScroller() {
|
|
6
|
+
const made = useContext(Context);
|
|
7
|
+
if (!made)
|
|
8
|
+
throw new Error("A MessageScroller part must be inside <MessageScroller.Root>");
|
|
9
|
+
return made;
|
|
10
|
+
}
|
|
11
|
+
function Root(props) {
|
|
12
|
+
const [local, rest] = splitProps(props, ["initial", "threshold", "onAtBottomChange", "id"]);
|
|
13
|
+
const generated = createUniqueId();
|
|
14
|
+
const made = controller(createMessageScroller, () => ({
|
|
15
|
+
id: local.id ?? generated,
|
|
16
|
+
initial: local.initial,
|
|
17
|
+
threshold: local.threshold,
|
|
18
|
+
onAtBottomChange: (atBottom, details) => local.onAtBottomChange?.(atBottom, details),
|
|
19
|
+
}));
|
|
20
|
+
return (<Context.Provider value={made}>
|
|
21
|
+
<Part of={made.root} tag="div" {...rest}/>
|
|
22
|
+
</Context.Provider>);
|
|
23
|
+
}
|
|
24
|
+
const Viewport = (props) => <Part of={useScroller().viewport} tag="div" {...props}/>;
|
|
25
|
+
const Content = (props) => <Part of={useScroller().content} tag="div" {...props}/>;
|
|
26
|
+
const Button = (props) => <Part of={useScroller().button} tag="button" {...props}/>;
|
|
27
|
+
export const MessageScroller = { Root, Viewport, Content, Button };
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { defined, within } from "@kirana-ui/core";
|
|
2
|
+
import { createNavigationMenu } from "@kirana-ui/core/navigation-menu";
|
|
3
|
+
import { Show, createContext, createUniqueId, onCleanup, onMount, splitProps, untrack, useContext, } from "solid-js";
|
|
4
|
+
import { DirectionContext } from "./direction-context.js";
|
|
5
|
+
import { positioned } from "./popover.jsx";
|
|
6
|
+
import { Into, Part, Portal as BodyPortal, controller, fromSignal, toSignal } from "./runtime.jsx";
|
|
7
|
+
const Context = createContext();
|
|
8
|
+
const ItemContext = createContext();
|
|
9
|
+
function useNavigation() {
|
|
10
|
+
const made = useContext(Context);
|
|
11
|
+
if (!made)
|
|
12
|
+
throw new Error("A NavigationMenu part must be inside <NavigationMenu.Root>");
|
|
13
|
+
return made;
|
|
14
|
+
}
|
|
15
|
+
function useItem() {
|
|
16
|
+
const item = useContext(ItemContext);
|
|
17
|
+
if (!item)
|
|
18
|
+
throw new Error("A NavigationMenu part must be inside <NavigationMenu.Item>");
|
|
19
|
+
return item;
|
|
20
|
+
}
|
|
21
|
+
function Root(props) {
|
|
22
|
+
const [local, rest] = splitProps(props, [
|
|
23
|
+
"value",
|
|
24
|
+
"defaultValue",
|
|
25
|
+
"onValueChange",
|
|
26
|
+
"delay",
|
|
27
|
+
"closeDelay",
|
|
28
|
+
"orientation",
|
|
29
|
+
"id",
|
|
30
|
+
]);
|
|
31
|
+
const generated = createUniqueId();
|
|
32
|
+
const direction = useContext(DirectionContext);
|
|
33
|
+
const made = controller(within((createNavigationMenu), { direction }), () => ({
|
|
34
|
+
id: local.id ?? generated,
|
|
35
|
+
value: local.value,
|
|
36
|
+
defaultValue: local.defaultValue,
|
|
37
|
+
delay: local.delay,
|
|
38
|
+
closeDelay: local.closeDelay,
|
|
39
|
+
orientation: local.orientation,
|
|
40
|
+
onValueChange: (value, details) => local.onValueChange?.(value, details),
|
|
41
|
+
}));
|
|
42
|
+
return (<Context.Provider value={made}>
|
|
43
|
+
<Part of={made.root} tag="nav" {...rest}/>
|
|
44
|
+
</Context.Provider>);
|
|
45
|
+
}
|
|
46
|
+
/** `value` tells this item from the others; an item that is given none makes its own. */
|
|
47
|
+
function Item(props) {
|
|
48
|
+
const [local, rest] = splitProps(props, ["value"]);
|
|
49
|
+
const made = useNavigation();
|
|
50
|
+
const generated = createUniqueId();
|
|
51
|
+
const value = untrack(() => local.value);
|
|
52
|
+
const item = made.item(value === undefined ? generated : value);
|
|
53
|
+
onMount(() => onCleanup(item.mount()));
|
|
54
|
+
return (<ItemContext.Provider value={item}>
|
|
55
|
+
<Part of={made.itemPart} tag="li" {...rest}/>
|
|
56
|
+
</ItemContext.Provider>);
|
|
57
|
+
}
|
|
58
|
+
/** An item's content: drawn in `<NavigationMenu.Viewport>`, while it is shown. */
|
|
59
|
+
function Content(props) {
|
|
60
|
+
const item = useItem();
|
|
61
|
+
const mounted = fromSignal(item.mounted);
|
|
62
|
+
const viewport = fromSignal(useNavigation().viewportElement);
|
|
63
|
+
return (<Show when={mounted() ? viewport() : undefined}>
|
|
64
|
+
{(target) => (<Into target={target()}>
|
|
65
|
+
<Part of={item.content} tag="div" {...props}/>
|
|
66
|
+
</Into>)}
|
|
67
|
+
</Show>);
|
|
68
|
+
}
|
|
69
|
+
function Link(props) {
|
|
70
|
+
const [local, rest] = splitProps(props, ["active", "closeOnClick"]);
|
|
71
|
+
const options = toSignal(() => ({ ...local }));
|
|
72
|
+
const part = useNavigation().link(() => defined(options.get()));
|
|
73
|
+
return <Part of={part} tag="a" {...rest}/>;
|
|
74
|
+
}
|
|
75
|
+
const Portal = (props) => (<BodyPortal mounted={useNavigation().mounted}>{props.children}</BodyPortal>);
|
|
76
|
+
function Positioner(props) {
|
|
77
|
+
const made = useNavigation();
|
|
78
|
+
return <Part of={made.positioner} tag="div" {...positioned(props, made.positioning)}/>;
|
|
79
|
+
}
|
|
80
|
+
const part = (name, tag) => (props) => <Part of={useNavigation()[name]} tag={tag} {...props}/>;
|
|
81
|
+
const itemPart = (name, tag) => (props) => <Part of={useItem()[name]} tag={tag} {...props}/>;
|
|
82
|
+
export const NavigationMenu = {
|
|
83
|
+
Root,
|
|
84
|
+
List: part("list", "ul"),
|
|
85
|
+
Item,
|
|
86
|
+
Trigger: itemPart("trigger", "button"),
|
|
87
|
+
Icon: itemPart("icon", "span"),
|
|
88
|
+
Content,
|
|
89
|
+
Link,
|
|
90
|
+
Portal,
|
|
91
|
+
Positioner,
|
|
92
|
+
Popup: part("popup", "div"),
|
|
93
|
+
Viewport: part("viewport", "div"),
|
|
94
|
+
Arrow: part("arrow", "div"),
|
|
95
|
+
Backdrop: part("backdrop", "div"),
|
|
96
|
+
};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { within } from "@kirana-ui/core";
|
|
2
|
+
import { createNumberField } from "@kirana-ui/core/number-field";
|
|
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 useNumberField() {
|
|
8
|
+
const made = useContext(Context);
|
|
9
|
+
if (!made)
|
|
10
|
+
throw new Error("A NumberField part must be inside <NumberField.Root>");
|
|
11
|
+
return made;
|
|
12
|
+
}
|
|
13
|
+
function Root(props) {
|
|
14
|
+
const [local, rest] = splitProps(props, [
|
|
15
|
+
"value",
|
|
16
|
+
"defaultValue",
|
|
17
|
+
"onValueChange",
|
|
18
|
+
"onValueCommitted",
|
|
19
|
+
"min",
|
|
20
|
+
"max",
|
|
21
|
+
"step",
|
|
22
|
+
"smallStep",
|
|
23
|
+
"largeStep",
|
|
24
|
+
"snapOnStep",
|
|
25
|
+
"allowWheelScrub",
|
|
26
|
+
"format",
|
|
27
|
+
"locale",
|
|
28
|
+
"disabled",
|
|
29
|
+
"readOnly",
|
|
30
|
+
"required",
|
|
31
|
+
"name",
|
|
32
|
+
"form",
|
|
33
|
+
"id",
|
|
34
|
+
"children",
|
|
35
|
+
]);
|
|
36
|
+
const generated = createUniqueId();
|
|
37
|
+
const made = controller(within(createNumberField, { field: useContext(FieldContext) }), () => ({
|
|
38
|
+
id: local.id ?? generated,
|
|
39
|
+
value: local.value,
|
|
40
|
+
defaultValue: local.defaultValue,
|
|
41
|
+
min: local.min,
|
|
42
|
+
max: local.max,
|
|
43
|
+
step: local.step,
|
|
44
|
+
smallStep: local.smallStep,
|
|
45
|
+
largeStep: local.largeStep,
|
|
46
|
+
snapOnStep: local.snapOnStep,
|
|
47
|
+
allowWheelScrub: local.allowWheelScrub,
|
|
48
|
+
format: local.format,
|
|
49
|
+
locale: local.locale,
|
|
50
|
+
disabled: local.disabled,
|
|
51
|
+
readOnly: local.readOnly,
|
|
52
|
+
required: local.required,
|
|
53
|
+
name: local.name,
|
|
54
|
+
form: local.form,
|
|
55
|
+
onValueChange: (value, details) => local.onValueChange?.(value, details),
|
|
56
|
+
onValueCommitted: (value, details) => local.onValueCommitted?.(value, details),
|
|
57
|
+
}));
|
|
58
|
+
const named = fromSignal(made.named);
|
|
59
|
+
return (<Context.Provider value={made}>
|
|
60
|
+
<Part of={made.root} tag="div" {...rest}>
|
|
61
|
+
{local.children}
|
|
62
|
+
<Show when={named()}>
|
|
63
|
+
<Part of={made.hidden} tag="input"/>
|
|
64
|
+
</Show>
|
|
65
|
+
</Part>
|
|
66
|
+
</Context.Provider>);
|
|
67
|
+
}
|
|
68
|
+
const part = (name, tag) => (props) => <Part of={useNumberField()[name]} tag={tag} {...props}/>;
|
|
69
|
+
export const NumberField = {
|
|
70
|
+
Root,
|
|
71
|
+
Group: part("group", "div"),
|
|
72
|
+
Input: part("input", "input"),
|
|
73
|
+
Increment: part("increment", "button"),
|
|
74
|
+
Decrement: part("decrement", "button"),
|
|
75
|
+
};
|