@kirana-ui/solid 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/dom/accordion.js +106 -0
- package/dom/alert-dialog.js +2 -0
- package/dom/avatar.js +68 -0
- package/dom/button.js +18 -0
- package/dom/checkbox.js +76 -0
- package/dom/collapsible.js +64 -0
- package/dom/dialog.js +73 -0
- package/dom/direction-context.js +3 -0
- package/dom/direction.js +27 -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 +63 -0
- package/dom/index.js +22 -0
- package/dom/meter.js +3 -0
- package/dom/popover.js +68 -0
- package/dom/progress.js +3 -0
- package/dom/radio-group.js +100 -0
- package/dom/runtime.js +99 -0
- package/dom/select.js +149 -0
- package/dom/separator.js +17 -0
- package/dom/slider.js +93 -0
- package/dom/switch.js +62 -0
- package/dom/tabs.js +97 -0
- package/dom/toggle.js +20 -0
- package/dom/tooltip.js +3 -0
- package/dom/value-bar.js +62 -0
- package/package.json +229 -4
- package/server/accordion.js +106 -0
- package/server/alert-dialog.js +2 -0
- package/server/avatar.js +68 -0
- package/server/button.js +18 -0
- package/server/checkbox.js +76 -0
- package/server/collapsible.js +64 -0
- package/server/dialog.js +73 -0
- package/server/direction-context.js +3 -0
- package/server/direction.js +27 -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 +63 -0
- package/server/index.js +22 -0
- package/server/meter.js +3 -0
- package/server/popover.js +68 -0
- package/server/progress.js +3 -0
- package/server/radio-group.js +100 -0
- package/server/runtime.js +98 -0
- package/server/select.js +149 -0
- package/server/separator.js +17 -0
- package/server/slider.js +92 -0
- package/server/switch.js +61 -0
- package/server/tabs.js +97 -0
- package/server/toggle.js +20 -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/avatar.jsx +35 -0
- package/src/button.jsx +9 -0
- package/src/checkbox.jsx +57 -0
- package/src/collapsible.jsx +35 -0
- package/src/dialog.jsx +47 -0
- package/src/direction-context.js +3 -0
- package/src/direction.jsx +17 -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 +40 -0
- package/src/index.js +22 -0
- package/src/meter.jsx +3 -0
- package/src/popover.jsx +49 -0
- package/src/progress.jsx +3 -0
- package/src/radio-group.jsx +66 -0
- package/src/runtime.jsx +88 -0
- package/src/select.jsx +85 -0
- package/src/separator.jsx +8 -0
- package/src/slider.jsx +74 -0
- package/src/switch.jsx +47 -0
- package/src/tabs.jsx +58 -0
- package/src/toggle.jsx +18 -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/avatar.d.ts +15 -0
- package/types/button.d.ts +9 -0
- package/types/checkbox.d.ts +25 -0
- package/types/collapsible.d.ts +21 -0
- package/types/dialog.d.ts +40 -0
- package/types/direction-context.d.ts +3 -0
- package/types/direction.d.ts +14 -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 +10 -0
- package/types/hover-popup.d.ts +26 -0
- package/types/index.d.ts +24 -0
- package/types/meter.d.ts +9 -0
- package/types/popover.d.ts +28 -0
- package/types/progress.d.ts +9 -0
- package/types/radio-group.d.ts +28 -0
- package/types/runtime.d.ts +31 -0
- package/types/select.d.ts +50 -0
- package/types/separator.d.ts +6 -0
- package/types/slider.d.ts +24 -0
- package/types/switch.d.ts +20 -0
- package/types/tabs.d.ts +32 -0
- package/types/toggle.d.ts +10 -0
- package/types/tooltip.d.ts +10 -0
- package/types/value-bar.d.ts +17 -0
- package/README.md +0 -3
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { mergeProps as _$mergeProps } from "solid-js/web";
|
|
2
|
+
import { createComponent as _$createComponent } from "solid-js/web";
|
|
3
|
+
import { createContext, createUniqueId, useContext } from "solid-js";
|
|
4
|
+
import { positioned } from "./popover.js";
|
|
5
|
+
import { Part, Portal as BodyPortal, controller } from "./runtime.js";
|
|
6
|
+
/** The parts of a popup the pointer opens: a tooltip's, a hover card's. */
|
|
7
|
+
export function hoverPopup(name, create, triggerTag) {
|
|
8
|
+
const Context = createContext();
|
|
9
|
+
function use() {
|
|
10
|
+
const made = useContext(Context);
|
|
11
|
+
if (!made) throw new Error(`A ${name} part must be inside <${name}.Root>`);
|
|
12
|
+
return made;
|
|
13
|
+
}
|
|
14
|
+
function Root(props) {
|
|
15
|
+
const generated = createUniqueId();
|
|
16
|
+
const made = controller(create, () => ({
|
|
17
|
+
id: props.id ?? generated,
|
|
18
|
+
open: props.open,
|
|
19
|
+
defaultOpen: props.defaultOpen,
|
|
20
|
+
delay: props.delay,
|
|
21
|
+
closeDelay: props.closeDelay,
|
|
22
|
+
disabled: props.disabled,
|
|
23
|
+
onOpenChange: (open, details) => props.onOpenChange?.(open, details)
|
|
24
|
+
}));
|
|
25
|
+
return _$createComponent(Context.Provider, {
|
|
26
|
+
value: made,
|
|
27
|
+
get children() {
|
|
28
|
+
return props.children;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
const Portal = props => _$createComponent(BodyPortal, {
|
|
33
|
+
get mounted() {
|
|
34
|
+
return use().mounted;
|
|
35
|
+
},
|
|
36
|
+
get children() {
|
|
37
|
+
return props.children;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
function Positioner(props) {
|
|
41
|
+
const made = use();
|
|
42
|
+
return _$createComponent(Part, _$mergeProps({
|
|
43
|
+
get part() {
|
|
44
|
+
return made.positioner;
|
|
45
|
+
},
|
|
46
|
+
tag: "div"
|
|
47
|
+
}, () => positioned(props, made.positioning)));
|
|
48
|
+
}
|
|
49
|
+
const part = (key, tag) => props => _$createComponent(Part, _$mergeProps({
|
|
50
|
+
get part() {
|
|
51
|
+
return use()[key];
|
|
52
|
+
},
|
|
53
|
+
tag: tag
|
|
54
|
+
}, props));
|
|
55
|
+
return {
|
|
56
|
+
Root,
|
|
57
|
+
Portal,
|
|
58
|
+
Positioner,
|
|
59
|
+
Trigger: part("trigger", triggerTag),
|
|
60
|
+
Popup: part("popup", "div"),
|
|
61
|
+
Arrow: part("arrow", "div")
|
|
62
|
+
};
|
|
63
|
+
}
|
package/dom/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export { Accordion } from "./accordion.js";
|
|
2
|
+
export { Checkbox } from "./checkbox.js";
|
|
3
|
+
export { Collapsible } from "./collapsible.js";
|
|
4
|
+
export { AlertDialog, Dialog } from "./dialog.js";
|
|
5
|
+
export { HoverCard } from "./hover-card.js";
|
|
6
|
+
export { Popover } from "./popover.js";
|
|
7
|
+
export { RadioGroup } from "./radio-group.js";
|
|
8
|
+
export { Select } from "./select.js";
|
|
9
|
+
export { Switch } from "./switch.js";
|
|
10
|
+
export { Tabs } from "./tabs.js";
|
|
11
|
+
export { Tooltip } from "./tooltip.js";
|
|
12
|
+
export { Avatar } from "./avatar.js";
|
|
13
|
+
export { Button } from "./button.js";
|
|
14
|
+
export { Meter } from "./meter.js";
|
|
15
|
+
export { Progress } from "./progress.js";
|
|
16
|
+
export { Separator } from "./separator.js";
|
|
17
|
+
export { Toggle } from "./toggle.js";
|
|
18
|
+
export { Slider } from "./slider.js";
|
|
19
|
+
export { Field } from "./field.js";
|
|
20
|
+
export { Fieldset } from "./fieldset.js";
|
|
21
|
+
export { Form } from "./form.js";
|
|
22
|
+
export { DirectionProvider, useDirection } from "./direction.js";
|
package/dom/meter.js
ADDED
package/dom/popover.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { mergeProps as _$mergeProps } from "solid-js/web";
|
|
2
|
+
import { createComponent as _$createComponent } from "solid-js/web";
|
|
3
|
+
import { defined } from "@kirana-ui/core";
|
|
4
|
+
import { createPopover } from "@kirana-ui/core/popover";
|
|
5
|
+
import { createComputed, createContext, createUniqueId, splitProps, useContext } from "solid-js";
|
|
6
|
+
import { Part, Portal as BodyPortal, controller } from "./runtime.js";
|
|
7
|
+
const Context = createContext();
|
|
8
|
+
function usePopover() {
|
|
9
|
+
const made = useContext(Context);
|
|
10
|
+
if (!made) throw new Error("A Popover part must be inside <Popover.Root>");
|
|
11
|
+
return made;
|
|
12
|
+
}
|
|
13
|
+
function Root(props) {
|
|
14
|
+
const generated = createUniqueId();
|
|
15
|
+
const made = controller(createPopover, () => ({
|
|
16
|
+
id: props.id ?? generated,
|
|
17
|
+
open: props.open,
|
|
18
|
+
defaultOpen: props.defaultOpen,
|
|
19
|
+
onOpenChange: (open, details) => props.onOpenChange?.(open, details)
|
|
20
|
+
}));
|
|
21
|
+
return _$createComponent(Context.Provider, {
|
|
22
|
+
value: made,
|
|
23
|
+
get children() {
|
|
24
|
+
return props.children;
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
const Portal = props => _$createComponent(BodyPortal, {
|
|
29
|
+
get mounted() {
|
|
30
|
+
return usePopover().mounted;
|
|
31
|
+
},
|
|
32
|
+
get children() {
|
|
33
|
+
return props.children;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
/** A positioner's own props, written where its placement reads them, before its element attaches. */
|
|
37
|
+
export function positioned(props, positioning) {
|
|
38
|
+
const [local, rest] = splitProps(props, ["side", "align", "sideOffset", "alignOffset", "collisionPadding"]);
|
|
39
|
+
createComputed(() => positioning.set(defined({
|
|
40
|
+
...local
|
|
41
|
+
})));
|
|
42
|
+
return rest;
|
|
43
|
+
}
|
|
44
|
+
function Positioner(props) {
|
|
45
|
+
const made = usePopover();
|
|
46
|
+
return _$createComponent(Part, _$mergeProps({
|
|
47
|
+
get part() {
|
|
48
|
+
return made.positioner;
|
|
49
|
+
},
|
|
50
|
+
tag: "div"
|
|
51
|
+
}, () => positioned(props, made.positioning)));
|
|
52
|
+
}
|
|
53
|
+
const part = (name, tag) => props => _$createComponent(Part, _$mergeProps({
|
|
54
|
+
get part() {
|
|
55
|
+
return usePopover()[name];
|
|
56
|
+
},
|
|
57
|
+
tag: tag
|
|
58
|
+
}, props));
|
|
59
|
+
export const Popover = {
|
|
60
|
+
Root,
|
|
61
|
+
Portal,
|
|
62
|
+
Positioner,
|
|
63
|
+
Trigger: part("trigger", "button"),
|
|
64
|
+
Popup: part("popup", "div"),
|
|
65
|
+
Title: part("title", "h2"),
|
|
66
|
+
Description: part("description", "p"),
|
|
67
|
+
Close: part("close", "button")
|
|
68
|
+
};
|
package/dom/progress.js
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { memo as _$memo } from "solid-js/web";
|
|
2
|
+
import { createComponent as _$createComponent } from "solid-js/web";
|
|
3
|
+
import { mergeProps as _$mergeProps } from "solid-js/web";
|
|
4
|
+
import { defined, within } from "@kirana-ui/core";
|
|
5
|
+
import { createRadioGroup } from "@kirana-ui/core/radio-group";
|
|
6
|
+
import { Show, createContext, createUniqueId, onCleanup, onMount, splitProps, untrack, useContext } from "solid-js";
|
|
7
|
+
import { DirectionContext } from "./direction-context.js";
|
|
8
|
+
import { FieldContext } from "./field-context.js";
|
|
9
|
+
import { Part, controller, fromSignal, toSignal } from "./runtime.js";
|
|
10
|
+
const Context = createContext();
|
|
11
|
+
const ItemContext = createContext();
|
|
12
|
+
function useRadioGroup() {
|
|
13
|
+
const made = useContext(Context);
|
|
14
|
+
if (!made) throw new Error("A RadioGroup part must be inside <RadioGroup.Root>");
|
|
15
|
+
return made;
|
|
16
|
+
}
|
|
17
|
+
function Root(props) {
|
|
18
|
+
const [local, rest] = splitProps(props, ["value", "defaultValue", "onValueChange", "disabled", "readOnly", "required", "name", "id"]);
|
|
19
|
+
const generated = createUniqueId();
|
|
20
|
+
const field = useContext(FieldContext);
|
|
21
|
+
const made = controller(within(createRadioGroup, {
|
|
22
|
+
field,
|
|
23
|
+
direction: useContext(DirectionContext)
|
|
24
|
+
}), () => ({
|
|
25
|
+
id: local.id ?? generated,
|
|
26
|
+
value: local.value,
|
|
27
|
+
defaultValue: local.defaultValue,
|
|
28
|
+
disabled: local.disabled,
|
|
29
|
+
readOnly: local.readOnly,
|
|
30
|
+
required: local.required,
|
|
31
|
+
name: local.name,
|
|
32
|
+
onValueChange: (value, details) => local.onValueChange?.(value, details)
|
|
33
|
+
}));
|
|
34
|
+
return _$createComponent(Context.Provider, {
|
|
35
|
+
value: made,
|
|
36
|
+
get children() {
|
|
37
|
+
return _$createComponent(Part, _$mergeProps({
|
|
38
|
+
get part() {
|
|
39
|
+
return made.root;
|
|
40
|
+
},
|
|
41
|
+
tag: "div"
|
|
42
|
+
}, rest));
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
function Item(props) {
|
|
47
|
+
const [local, rest] = splitProps(props, ["value", "disabled", "children"]);
|
|
48
|
+
// An item is its value for as long as it is in the page.
|
|
49
|
+
const value = untrack(() => local.value);
|
|
50
|
+
const options = toSignal(() => ({
|
|
51
|
+
disabled: local.disabled
|
|
52
|
+
}));
|
|
53
|
+
const read = () => defined(options.get());
|
|
54
|
+
const group = useRadioGroup();
|
|
55
|
+
return _$createComponent(ItemContext.Provider, {
|
|
56
|
+
value: value,
|
|
57
|
+
get children() {
|
|
58
|
+
return _$createComponent(Part, _$mergeProps({
|
|
59
|
+
get part() {
|
|
60
|
+
return group.item(value, read);
|
|
61
|
+
},
|
|
62
|
+
tag: "span"
|
|
63
|
+
}, rest, {
|
|
64
|
+
get children() {
|
|
65
|
+
return [_$memo(() => local.children), _$createComponent(Part, {
|
|
66
|
+
get part() {
|
|
67
|
+
return group.itemInput(value, read);
|
|
68
|
+
},
|
|
69
|
+
tag: "input"
|
|
70
|
+
})];
|
|
71
|
+
}
|
|
72
|
+
}));
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
/** `keepMounted` keeps the mark in the page while its item is not the chosen one. */
|
|
77
|
+
function Indicator(props) {
|
|
78
|
+
const [local, rest] = splitProps(props, ["keepMounted"]);
|
|
79
|
+
const indicator = useRadioGroup().indicator(useContext(ItemContext));
|
|
80
|
+
onMount(() => onCleanup(indicator.mount()));
|
|
81
|
+
const mounted = fromSignal(indicator.mounted);
|
|
82
|
+
return _$createComponent(Show, {
|
|
83
|
+
get when() {
|
|
84
|
+
return mounted() || local.keepMounted;
|
|
85
|
+
},
|
|
86
|
+
get children() {
|
|
87
|
+
return _$createComponent(Part, _$mergeProps({
|
|
88
|
+
get part() {
|
|
89
|
+
return indicator.part;
|
|
90
|
+
},
|
|
91
|
+
tag: "span"
|
|
92
|
+
}, rest));
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
export const RadioGroup = {
|
|
97
|
+
Root,
|
|
98
|
+
Item,
|
|
99
|
+
Indicator
|
|
100
|
+
};
|
package/dom/runtime.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { mergeProps as _$mergeProps } from "solid-js/web";
|
|
2
|
+
import { memo as _$memo } from "solid-js/web";
|
|
3
|
+
import { createComponent as _$createComponent } from "solid-js/web";
|
|
4
|
+
import { mergeProps, sameProps, signal } from "@kirana-ui/core";
|
|
5
|
+
import { Show, createComputed, createMemo, createSignal, getOwner, onCleanup, onMount, runWithOwner, splitProps, untrack } from "solid-js";
|
|
6
|
+
import { Dynamic, Portal as SolidPortal, isServer } from "solid-js/web";
|
|
7
|
+
/** A core signal as a Solid accessor: tracked by whatever calls it. */
|
|
8
|
+
export function fromSignal(source) {
|
|
9
|
+
const [read, write] = createSignal(source.peek(), {
|
|
10
|
+
equals: false
|
|
11
|
+
});
|
|
12
|
+
if (!isServer) onCleanup(source.subscribe(() => write(() => source.peek())));
|
|
13
|
+
return read;
|
|
14
|
+
}
|
|
15
|
+
/** A core signal that follows Solid state: the core hears a changed prop before anything renders. */
|
|
16
|
+
export function toSignal(read) {
|
|
17
|
+
const source = signal(untrack(read), sameProps);
|
|
18
|
+
createComputed(() => source.set(read()));
|
|
19
|
+
return source;
|
|
20
|
+
}
|
|
21
|
+
/** A component's controller, made once, following its props. */
|
|
22
|
+
export function controller(create, read) {
|
|
23
|
+
const made = create(toSignal(read));
|
|
24
|
+
onMount(() => onCleanup(made.mount()));
|
|
25
|
+
return made;
|
|
26
|
+
}
|
|
27
|
+
// HTML's boolean attributes, which Solid sets as properties: a part's `""` means "present".
|
|
28
|
+
const BOOLEAN = new Set(["hidden", "disabled", "inert", "required", "readonly", "multiple", "checked", "novalidate"]);
|
|
29
|
+
function toSolid(props) {
|
|
30
|
+
const out = {};
|
|
31
|
+
for (const key in props) {
|
|
32
|
+
const value = props[key];
|
|
33
|
+
// Solid's `onFocus` and `onBlur` do not bubble; the core's are the ones that do.
|
|
34
|
+
if (key === "onFocus") out.onFocusIn = value;else if (key === "onBlur") out.onFocusOut = value;else out[key] = BOOLEAN.has(key) ? value === "" || value === true : value;
|
|
35
|
+
}
|
|
36
|
+
return out;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* A part's element (or the caller's, through `render`), with the caller's props merged under the
|
|
40
|
+
* part's and the part's DOM work attached once the element is in the page.
|
|
41
|
+
*/
|
|
42
|
+
export function Part(props) {
|
|
43
|
+
const [local, caller] = splitProps(props, ["part", "tag", "as", "render", "children"]);
|
|
44
|
+
const own = fromSignal(untrack(() => local.part).props);
|
|
45
|
+
// Solid hands over an element before it is in the page: the part's DOM work (focus, measures,
|
|
46
|
+
// the starting style) waits for the mount that follows. It belongs to this component, not to
|
|
47
|
+
// the effect that spreads the props (which hands the ref over again, and is torn down, each time
|
|
48
|
+
// they change): attached once per element, detached when the component goes.
|
|
49
|
+
const owner = getOwner();
|
|
50
|
+
let attached;
|
|
51
|
+
const attach = element => {
|
|
52
|
+
if (element === attached) return;
|
|
53
|
+
attached = element;
|
|
54
|
+
const part = untrack(() => local.part);
|
|
55
|
+
runWithOwner(owner, () => onMount(() => onCleanup(part.attach(element))));
|
|
56
|
+
};
|
|
57
|
+
const merged = createMemo(() => {
|
|
58
|
+
const theirs = {};
|
|
59
|
+
for (const key of Object.keys(caller)) theirs[key] = caller[key];
|
|
60
|
+
return {
|
|
61
|
+
...mergeProps(theirs, toSolid(own())),
|
|
62
|
+
ref: attach
|
|
63
|
+
};
|
|
64
|
+
});
|
|
65
|
+
return _$createComponent(Show, {
|
|
66
|
+
get when() {
|
|
67
|
+
return local.render;
|
|
68
|
+
},
|
|
69
|
+
get fallback() {
|
|
70
|
+
return _$createComponent(Dynamic, _$mergeProps({
|
|
71
|
+
get component() {
|
|
72
|
+
return local.as ?? local.tag;
|
|
73
|
+
}
|
|
74
|
+
}, merged, {
|
|
75
|
+
get children() {
|
|
76
|
+
return local.children;
|
|
77
|
+
}
|
|
78
|
+
}));
|
|
79
|
+
},
|
|
80
|
+
children: render => render()(merged)
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
/** Its children in a container at the end of the page, while `mounted`. */
|
|
84
|
+
export function Portal(props) {
|
|
85
|
+
const shown = fromSignal(untrack(() => props.mounted));
|
|
86
|
+
return _$createComponent(Show, {
|
|
87
|
+
get when() {
|
|
88
|
+
return shown();
|
|
89
|
+
},
|
|
90
|
+
get children() {
|
|
91
|
+
return _$createComponent(SolidPortal, {
|
|
92
|
+
ref: container => container.setAttribute("data-kirana-portal", ""),
|
|
93
|
+
get children() {
|
|
94
|
+
return props.children;
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
package/dom/select.js
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { mergeProps as _$mergeProps } from "solid-js/web";
|
|
2
|
+
import { createComponent as _$createComponent } from "solid-js/web";
|
|
3
|
+
import { memo as _$memo } from "solid-js/web";
|
|
4
|
+
import { defined, within } from "@kirana-ui/core";
|
|
5
|
+
import { createSelect } from "@kirana-ui/core/select";
|
|
6
|
+
import { Show, createContext, createUniqueId, splitProps, untrack, useContext } from "solid-js";
|
|
7
|
+
import { positioned } from "./popover.js";
|
|
8
|
+
import { FieldContext } from "./field-context.js";
|
|
9
|
+
import { Part, Portal as BodyPortal, controller, fromSignal, toSignal } from "./runtime.js";
|
|
10
|
+
const Context = createContext();
|
|
11
|
+
const ItemContext = createContext();
|
|
12
|
+
function useSelect() {
|
|
13
|
+
const made = useContext(Context);
|
|
14
|
+
if (!made) throw new Error("A Select part must be inside <Select.Root>");
|
|
15
|
+
return made;
|
|
16
|
+
}
|
|
17
|
+
function Root(props) {
|
|
18
|
+
const generated = createUniqueId();
|
|
19
|
+
const field = useContext(FieldContext);
|
|
20
|
+
const made = controller(within(createSelect, {
|
|
21
|
+
field
|
|
22
|
+
}), () => ({
|
|
23
|
+
id: props.id ?? generated,
|
|
24
|
+
value: props.value,
|
|
25
|
+
defaultValue: props.defaultValue,
|
|
26
|
+
open: props.open,
|
|
27
|
+
defaultOpen: props.defaultOpen,
|
|
28
|
+
disabled: props.disabled,
|
|
29
|
+
required: props.required,
|
|
30
|
+
name: props.name,
|
|
31
|
+
items: props.items,
|
|
32
|
+
onValueChange: (value, details) => props.onValueChange?.(value, details),
|
|
33
|
+
onOpenChange: (open, details) => props.onOpenChange?.(open, details)
|
|
34
|
+
}));
|
|
35
|
+
const named = fromSignal(made.named);
|
|
36
|
+
return _$createComponent(Context.Provider, {
|
|
37
|
+
value: made,
|
|
38
|
+
get children() {
|
|
39
|
+
return [_$memo(() => props.children), _$createComponent(Show, {
|
|
40
|
+
get when() {
|
|
41
|
+
return named();
|
|
42
|
+
},
|
|
43
|
+
get children() {
|
|
44
|
+
return _$createComponent(Part, {
|
|
45
|
+
get part() {
|
|
46
|
+
return made.input;
|
|
47
|
+
},
|
|
48
|
+
tag: "input"
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
})];
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
const Portal = props => _$createComponent(BodyPortal, {
|
|
56
|
+
get mounted() {
|
|
57
|
+
return useSelect().mounted;
|
|
58
|
+
},
|
|
59
|
+
get children() {
|
|
60
|
+
return props.children;
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
function Positioner(props) {
|
|
64
|
+
const made = useSelect();
|
|
65
|
+
return _$createComponent(Part, _$mergeProps({
|
|
66
|
+
get part() {
|
|
67
|
+
return made.positioner;
|
|
68
|
+
},
|
|
69
|
+
tag: "div"
|
|
70
|
+
}, () => positioned(props, made.positioning)));
|
|
71
|
+
}
|
|
72
|
+
/** Shows the chosen value's label, or `placeholder` while nothing is chosen. */
|
|
73
|
+
function Value(props) {
|
|
74
|
+
const [local, rest] = splitProps(props, ["placeholder", "children"]);
|
|
75
|
+
const made = useSelect();
|
|
76
|
+
const label = fromSignal(made.label);
|
|
77
|
+
return _$createComponent(Part, _$mergeProps({
|
|
78
|
+
get part() {
|
|
79
|
+
return made.valuePart;
|
|
80
|
+
},
|
|
81
|
+
tag: "span"
|
|
82
|
+
}, rest, {
|
|
83
|
+
get children() {
|
|
84
|
+
return local.children ?? label() ?? local.placeholder;
|
|
85
|
+
}
|
|
86
|
+
}));
|
|
87
|
+
}
|
|
88
|
+
/** `label` is what typeahead matches and the trigger shows; the item's text when left out. */
|
|
89
|
+
function Item(props) {
|
|
90
|
+
const [local, rest] = splitProps(props, ["value", "disabled", "label"]);
|
|
91
|
+
// An item is its value for as long as it is in the page.
|
|
92
|
+
const value = untrack(() => local.value);
|
|
93
|
+
const options = toSignal(() => ({
|
|
94
|
+
disabled: local.disabled,
|
|
95
|
+
label: local.label
|
|
96
|
+
}));
|
|
97
|
+
const part = useSelect().item(value, () => defined(options.get()));
|
|
98
|
+
return _$createComponent(ItemContext.Provider, {
|
|
99
|
+
value: value,
|
|
100
|
+
get children() {
|
|
101
|
+
return _$createComponent(Part, _$mergeProps({
|
|
102
|
+
part: part,
|
|
103
|
+
tag: "div"
|
|
104
|
+
}, rest));
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
const ItemText = props => _$createComponent(Part, _$mergeProps({
|
|
109
|
+
get part() {
|
|
110
|
+
return useSelect().itemText(useContext(ItemContext));
|
|
111
|
+
},
|
|
112
|
+
tag: "span"
|
|
113
|
+
}, props));
|
|
114
|
+
function ItemIndicator(props) {
|
|
115
|
+
const [local, rest] = splitProps(props, ["keepMounted"]);
|
|
116
|
+
const made = useSelect();
|
|
117
|
+
const value = useContext(ItemContext);
|
|
118
|
+
const selected = fromSignal(made.selected(value));
|
|
119
|
+
return _$createComponent(Show, {
|
|
120
|
+
get when() {
|
|
121
|
+
return selected() || local.keepMounted;
|
|
122
|
+
},
|
|
123
|
+
get children() {
|
|
124
|
+
return _$createComponent(Part, _$mergeProps({
|
|
125
|
+
get part() {
|
|
126
|
+
return made.itemIndicator(value);
|
|
127
|
+
},
|
|
128
|
+
tag: "span"
|
|
129
|
+
}, rest));
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
const part = (name, tag) => props => _$createComponent(Part, _$mergeProps({
|
|
134
|
+
get part() {
|
|
135
|
+
return useSelect()[name];
|
|
136
|
+
},
|
|
137
|
+
tag: tag
|
|
138
|
+
}, props));
|
|
139
|
+
export const Select = {
|
|
140
|
+
Root,
|
|
141
|
+
Portal,
|
|
142
|
+
Positioner,
|
|
143
|
+
Value,
|
|
144
|
+
Item,
|
|
145
|
+
ItemText,
|
|
146
|
+
ItemIndicator,
|
|
147
|
+
Trigger: part("trigger", "button"),
|
|
148
|
+
Popup: part("popup", "div")
|
|
149
|
+
};
|
package/dom/separator.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { createComponent as _$createComponent } from "solid-js/web";
|
|
2
|
+
import { mergeProps as _$mergeProps } from "solid-js/web";
|
|
3
|
+
import { createSeparator } from "@kirana-ui/core/separator";
|
|
4
|
+
import { splitProps } from "solid-js";
|
|
5
|
+
import { Part, controller } from "./runtime.js";
|
|
6
|
+
export function Separator(props) {
|
|
7
|
+
const [local, rest] = splitProps(props, ["orientation"]);
|
|
8
|
+
const made = controller(createSeparator, () => ({
|
|
9
|
+
orientation: local.orientation
|
|
10
|
+
}));
|
|
11
|
+
return _$createComponent(Part, _$mergeProps({
|
|
12
|
+
get part() {
|
|
13
|
+
return made.root;
|
|
14
|
+
},
|
|
15
|
+
tag: "div"
|
|
16
|
+
}, rest));
|
|
17
|
+
}
|
package/dom/slider.js
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { memo as _$memo } from "solid-js/web";
|
|
2
|
+
import { createComponent as _$createComponent } from "solid-js/web";
|
|
3
|
+
import { mergeProps as _$mergeProps } from "solid-js/web";
|
|
4
|
+
import { within } from "@kirana-ui/core";
|
|
5
|
+
import { createSlider } from "@kirana-ui/core/slider";
|
|
6
|
+
import { createContext, createUniqueId, splitProps, untrack, useContext } from "solid-js";
|
|
7
|
+
import { DirectionContext } from "./direction-context.js";
|
|
8
|
+
import { FieldContext } from "./field-context.js";
|
|
9
|
+
import { Part, controller, fromSignal } from "./runtime.js";
|
|
10
|
+
const Context = createContext();
|
|
11
|
+
function useSlider() {
|
|
12
|
+
const made = useContext(Context);
|
|
13
|
+
if (!made) throw new Error("A Slider part must be inside <Slider.Root>");
|
|
14
|
+
return made;
|
|
15
|
+
}
|
|
16
|
+
function Root(props) {
|
|
17
|
+
const [local, rest] = splitProps(props, ["value", "defaultValue", "onValueChange", "onValueCommitted", "min", "max", "step", "largeStep", "minStepsBetweenValues", "orientation", "disabled", "name", "format", "locale", "getAriaValueText", "id"]);
|
|
18
|
+
const generated = createUniqueId();
|
|
19
|
+
const field = useContext(FieldContext);
|
|
20
|
+
const made = controller(within(createSlider, {
|
|
21
|
+
field,
|
|
22
|
+
direction: useContext(DirectionContext)
|
|
23
|
+
}), () => ({
|
|
24
|
+
...local,
|
|
25
|
+
id: local.id ?? generated,
|
|
26
|
+
onValueChange: (value, details) => local.onValueChange?.(value, details),
|
|
27
|
+
onValueCommitted: (value, details) => local.onValueCommitted?.(value, details)
|
|
28
|
+
}));
|
|
29
|
+
return _$createComponent(Context.Provider, {
|
|
30
|
+
value: made,
|
|
31
|
+
get children() {
|
|
32
|
+
return _$createComponent(Part, _$mergeProps({
|
|
33
|
+
get part() {
|
|
34
|
+
return made.root;
|
|
35
|
+
},
|
|
36
|
+
tag: "div"
|
|
37
|
+
}, rest));
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
/** `index` is which value of a range the thumb is, from 0. */
|
|
42
|
+
function Thumb(props) {
|
|
43
|
+
const [local, rest] = splitProps(props, ["index", "children"]);
|
|
44
|
+
// A thumb is its index for as long as it is in the page.
|
|
45
|
+
const index = untrack(() => local.index ?? 0);
|
|
46
|
+
const slider = useSlider();
|
|
47
|
+
return _$createComponent(Part, _$mergeProps({
|
|
48
|
+
get part() {
|
|
49
|
+
return slider.thumb(index);
|
|
50
|
+
},
|
|
51
|
+
tag: "div"
|
|
52
|
+
}, rest, {
|
|
53
|
+
get children() {
|
|
54
|
+
return [_$memo(() => local.children), _$createComponent(Part, {
|
|
55
|
+
get part() {
|
|
56
|
+
return slider.thumbInput(index);
|
|
57
|
+
},
|
|
58
|
+
tag: "input"
|
|
59
|
+
})];
|
|
60
|
+
}
|
|
61
|
+
}));
|
|
62
|
+
}
|
|
63
|
+
/** The written value, or what its child, a function, makes of it and of the values. */
|
|
64
|
+
function Value(props) {
|
|
65
|
+
const [local, rest] = splitProps(props, ["children"]);
|
|
66
|
+
const made = useSlider();
|
|
67
|
+
const text = fromSignal(made.text);
|
|
68
|
+
const values = fromSignal(made.values);
|
|
69
|
+
return _$createComponent(Part, _$mergeProps({
|
|
70
|
+
get part() {
|
|
71
|
+
return made.value;
|
|
72
|
+
},
|
|
73
|
+
tag: "output"
|
|
74
|
+
}, rest, {
|
|
75
|
+
get children() {
|
|
76
|
+
return _$memo(() => !!local.children)() ? local.children(text, values) : text();
|
|
77
|
+
}
|
|
78
|
+
}));
|
|
79
|
+
}
|
|
80
|
+
const part = key => props => _$createComponent(Part, _$mergeProps({
|
|
81
|
+
get part() {
|
|
82
|
+
return useSlider()[key];
|
|
83
|
+
},
|
|
84
|
+
tag: "div"
|
|
85
|
+
}, props));
|
|
86
|
+
export const Slider = {
|
|
87
|
+
Root,
|
|
88
|
+
Value,
|
|
89
|
+
Control: part("control"),
|
|
90
|
+
Track: part("track"),
|
|
91
|
+
Indicator: part("indicator"),
|
|
92
|
+
Thumb
|
|
93
|
+
};
|
package/dom/switch.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { mergeProps as _$mergeProps } from "solid-js/web";
|
|
2
|
+
import { createComponent as _$createComponent } from "solid-js/web";
|
|
3
|
+
import { memo as _$memo } from "solid-js/web";
|
|
4
|
+
import { within } from "@kirana-ui/core";
|
|
5
|
+
import { createSwitch } from "@kirana-ui/core/switch";
|
|
6
|
+
import { createContext, createUniqueId, splitProps, useContext } from "solid-js";
|
|
7
|
+
import { FieldContext } from "./field-context.js";
|
|
8
|
+
import { Part, controller } from "./runtime.js";
|
|
9
|
+
const Context = createContext();
|
|
10
|
+
function useSwitch() {
|
|
11
|
+
const made = useContext(Context);
|
|
12
|
+
if (!made) throw new Error("A Switch part must be inside <Switch.Root>");
|
|
13
|
+
return made;
|
|
14
|
+
}
|
|
15
|
+
function Root(props) {
|
|
16
|
+
const [local, rest] = splitProps(props, ["checked", "defaultChecked", "onCheckedChange", "disabled", "readOnly", "required", "name", "value", "id", "children"]);
|
|
17
|
+
const generated = createUniqueId();
|
|
18
|
+
const field = useContext(FieldContext);
|
|
19
|
+
const made = controller(within(createSwitch, {
|
|
20
|
+
field
|
|
21
|
+
}), () => ({
|
|
22
|
+
id: local.id ?? generated,
|
|
23
|
+
checked: local.checked,
|
|
24
|
+
defaultChecked: local.defaultChecked,
|
|
25
|
+
disabled: local.disabled,
|
|
26
|
+
readOnly: local.readOnly,
|
|
27
|
+
required: local.required,
|
|
28
|
+
name: local.name,
|
|
29
|
+
value: local.value,
|
|
30
|
+
onCheckedChange: (checked, details) => local.onCheckedChange?.(checked, details)
|
|
31
|
+
}));
|
|
32
|
+
return _$createComponent(Context.Provider, {
|
|
33
|
+
value: made,
|
|
34
|
+
get children() {
|
|
35
|
+
return _$createComponent(Part, _$mergeProps({
|
|
36
|
+
get part() {
|
|
37
|
+
return made.root;
|
|
38
|
+
},
|
|
39
|
+
tag: "span"
|
|
40
|
+
}, rest, {
|
|
41
|
+
get children() {
|
|
42
|
+
return [_$memo(() => local.children), _$createComponent(Part, {
|
|
43
|
+
get part() {
|
|
44
|
+
return made.input;
|
|
45
|
+
},
|
|
46
|
+
tag: "input"
|
|
47
|
+
})];
|
|
48
|
+
}
|
|
49
|
+
}));
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
const Thumb = props => _$createComponent(Part, _$mergeProps({
|
|
54
|
+
get part() {
|
|
55
|
+
return useSwitch().thumb;
|
|
56
|
+
},
|
|
57
|
+
tag: "span"
|
|
58
|
+
}, props));
|
|
59
|
+
export const Switch = {
|
|
60
|
+
Root,
|
|
61
|
+
Thumb
|
|
62
|
+
};
|