@kirana-ui/solid 0.0.0 → 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 +1 -1
- 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 +219 -6
- 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 -7
- package/index.js +0 -5
|
@@ -0,0 +1,98 @@
|
|
|
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
|
+
get children() {
|
|
93
|
+
return props.children;
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
}
|
package/server/select.js
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { memo as _$memo } from "solid-js/web";
|
|
2
|
+
import { mergeProps as _$mergeProps } from "solid-js/web";
|
|
3
|
+
import { createComponent as _$createComponent } 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 [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
|
+
};
|
|
@@ -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/server/slider.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { createComponent as _$createComponent } from "solid-js/web";
|
|
2
|
+
import { mergeProps as _$mergeProps } from "solid-js/web";
|
|
3
|
+
import { within } from "@kirana-ui/core";
|
|
4
|
+
import { createSlider } from "@kirana-ui/core/slider";
|
|
5
|
+
import { createContext, createUniqueId, splitProps, untrack, useContext } from "solid-js";
|
|
6
|
+
import { DirectionContext } from "./direction-context.js";
|
|
7
|
+
import { FieldContext } from "./field-context.js";
|
|
8
|
+
import { Part, controller, fromSignal } from "./runtime.js";
|
|
9
|
+
const Context = createContext();
|
|
10
|
+
function useSlider() {
|
|
11
|
+
const made = useContext(Context);
|
|
12
|
+
if (!made) throw new Error("A Slider part must be inside <Slider.Root>");
|
|
13
|
+
return made;
|
|
14
|
+
}
|
|
15
|
+
function Root(props) {
|
|
16
|
+
const [local, rest] = splitProps(props, ["value", "defaultValue", "onValueChange", "onValueCommitted", "min", "max", "step", "largeStep", "minStepsBetweenValues", "orientation", "disabled", "name", "format", "locale", "getAriaValueText", "id"]);
|
|
17
|
+
const generated = createUniqueId();
|
|
18
|
+
const field = useContext(FieldContext);
|
|
19
|
+
const made = controller(within(createSlider, {
|
|
20
|
+
field,
|
|
21
|
+
direction: useContext(DirectionContext)
|
|
22
|
+
}), () => ({
|
|
23
|
+
...local,
|
|
24
|
+
id: local.id ?? generated,
|
|
25
|
+
onValueChange: (value, details) => local.onValueChange?.(value, details),
|
|
26
|
+
onValueCommitted: (value, details) => local.onValueCommitted?.(value, details)
|
|
27
|
+
}));
|
|
28
|
+
return _$createComponent(Context.Provider, {
|
|
29
|
+
value: made,
|
|
30
|
+
get children() {
|
|
31
|
+
return _$createComponent(Part, _$mergeProps({
|
|
32
|
+
get part() {
|
|
33
|
+
return made.root;
|
|
34
|
+
},
|
|
35
|
+
tag: "div"
|
|
36
|
+
}, rest));
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
/** `index` is which value of a range the thumb is, from 0. */
|
|
41
|
+
function Thumb(props) {
|
|
42
|
+
const [local, rest] = splitProps(props, ["index", "children"]);
|
|
43
|
+
// A thumb is its index for as long as it is in the page.
|
|
44
|
+
const index = untrack(() => local.index ?? 0);
|
|
45
|
+
const slider = useSlider();
|
|
46
|
+
return _$createComponent(Part, _$mergeProps({
|
|
47
|
+
get part() {
|
|
48
|
+
return slider.thumb(index);
|
|
49
|
+
},
|
|
50
|
+
tag: "div"
|
|
51
|
+
}, rest, {
|
|
52
|
+
get children() {
|
|
53
|
+
return [local.children, _$createComponent(Part, {
|
|
54
|
+
get part() {
|
|
55
|
+
return slider.thumbInput(index);
|
|
56
|
+
},
|
|
57
|
+
tag: "input"
|
|
58
|
+
})];
|
|
59
|
+
}
|
|
60
|
+
}));
|
|
61
|
+
}
|
|
62
|
+
/** The written value, or what its child, a function, makes of it and of the values. */
|
|
63
|
+
function Value(props) {
|
|
64
|
+
const [local, rest] = splitProps(props, ["children"]);
|
|
65
|
+
const made = useSlider();
|
|
66
|
+
const text = fromSignal(made.text);
|
|
67
|
+
const values = fromSignal(made.values);
|
|
68
|
+
return _$createComponent(Part, _$mergeProps({
|
|
69
|
+
get part() {
|
|
70
|
+
return made.value;
|
|
71
|
+
},
|
|
72
|
+
tag: "output"
|
|
73
|
+
}, rest, {
|
|
74
|
+
get children() {
|
|
75
|
+
return local.children ? local.children(text, values) : text();
|
|
76
|
+
}
|
|
77
|
+
}));
|
|
78
|
+
}
|
|
79
|
+
const part = key => props => _$createComponent(Part, _$mergeProps({
|
|
80
|
+
get part() {
|
|
81
|
+
return useSlider()[key];
|
|
82
|
+
},
|
|
83
|
+
tag: "div"
|
|
84
|
+
}, props));
|
|
85
|
+
export const Slider = {
|
|
86
|
+
Root,
|
|
87
|
+
Value,
|
|
88
|
+
Control: part("control"),
|
|
89
|
+
Track: part("track"),
|
|
90
|
+
Indicator: part("indicator"),
|
|
91
|
+
Thumb
|
|
92
|
+
};
|
package/server/switch.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { mergeProps as _$mergeProps } from "solid-js/web";
|
|
2
|
+
import { createComponent as _$createComponent } from "solid-js/web";
|
|
3
|
+
import { within } from "@kirana-ui/core";
|
|
4
|
+
import { createSwitch } from "@kirana-ui/core/switch";
|
|
5
|
+
import { createContext, createUniqueId, splitProps, useContext } from "solid-js";
|
|
6
|
+
import { FieldContext } from "./field-context.js";
|
|
7
|
+
import { Part, controller } from "./runtime.js";
|
|
8
|
+
const Context = createContext();
|
|
9
|
+
function useSwitch() {
|
|
10
|
+
const made = useContext(Context);
|
|
11
|
+
if (!made) throw new Error("A Switch part must be inside <Switch.Root>");
|
|
12
|
+
return made;
|
|
13
|
+
}
|
|
14
|
+
function Root(props) {
|
|
15
|
+
const [local, rest] = splitProps(props, ["checked", "defaultChecked", "onCheckedChange", "disabled", "readOnly", "required", "name", "value", "id", "children"]);
|
|
16
|
+
const generated = createUniqueId();
|
|
17
|
+
const field = useContext(FieldContext);
|
|
18
|
+
const made = controller(within(createSwitch, {
|
|
19
|
+
field
|
|
20
|
+
}), () => ({
|
|
21
|
+
id: local.id ?? generated,
|
|
22
|
+
checked: local.checked,
|
|
23
|
+
defaultChecked: local.defaultChecked,
|
|
24
|
+
disabled: local.disabled,
|
|
25
|
+
readOnly: local.readOnly,
|
|
26
|
+
required: local.required,
|
|
27
|
+
name: local.name,
|
|
28
|
+
value: local.value,
|
|
29
|
+
onCheckedChange: (checked, details) => local.onCheckedChange?.(checked, details)
|
|
30
|
+
}));
|
|
31
|
+
return _$createComponent(Context.Provider, {
|
|
32
|
+
value: made,
|
|
33
|
+
get children() {
|
|
34
|
+
return _$createComponent(Part, _$mergeProps({
|
|
35
|
+
get part() {
|
|
36
|
+
return made.root;
|
|
37
|
+
},
|
|
38
|
+
tag: "span"
|
|
39
|
+
}, rest, {
|
|
40
|
+
get children() {
|
|
41
|
+
return [local.children, _$createComponent(Part, {
|
|
42
|
+
get part() {
|
|
43
|
+
return made.input;
|
|
44
|
+
},
|
|
45
|
+
tag: "input"
|
|
46
|
+
})];
|
|
47
|
+
}
|
|
48
|
+
}));
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
const Thumb = props => _$createComponent(Part, _$mergeProps({
|
|
53
|
+
get part() {
|
|
54
|
+
return useSwitch().thumb;
|
|
55
|
+
},
|
|
56
|
+
tag: "span"
|
|
57
|
+
}, props));
|
|
58
|
+
export const Switch = {
|
|
59
|
+
Root,
|
|
60
|
+
Thumb
|
|
61
|
+
};
|
package/server/tabs.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
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 { createTabs } from "@kirana-ui/core/tabs";
|
|
6
|
+
import { Show, createComputed, createContext, createUniqueId, onCleanup, onMount, splitProps, untrack, useContext } from "solid-js";
|
|
7
|
+
import { DirectionContext } from "./direction-context.js";
|
|
8
|
+
import { Part, controller, fromSignal, toSignal } from "./runtime.js";
|
|
9
|
+
const Context = createContext();
|
|
10
|
+
function useTabs() {
|
|
11
|
+
const made = useContext(Context);
|
|
12
|
+
if (!made) throw new Error("A Tabs part must be inside <Tabs.Root>");
|
|
13
|
+
return made;
|
|
14
|
+
}
|
|
15
|
+
function Root(props) {
|
|
16
|
+
const [local, rest] = splitProps(props, ["value", "defaultValue", "onValueChange", "orientation", "id"]);
|
|
17
|
+
const generated = createUniqueId();
|
|
18
|
+
const direction = useContext(DirectionContext);
|
|
19
|
+
const made = controller(within(createTabs, {
|
|
20
|
+
direction
|
|
21
|
+
}), () => ({
|
|
22
|
+
id: local.id ?? generated,
|
|
23
|
+
value: local.value,
|
|
24
|
+
defaultValue: local.defaultValue,
|
|
25
|
+
orientation: local.orientation,
|
|
26
|
+
onValueChange: (value, details) => local.onValueChange?.(value, details)
|
|
27
|
+
}));
|
|
28
|
+
return _$createComponent(Context.Provider, {
|
|
29
|
+
value: made,
|
|
30
|
+
get children() {
|
|
31
|
+
return _$createComponent(Part, _$mergeProps({
|
|
32
|
+
get part() {
|
|
33
|
+
return made.root;
|
|
34
|
+
},
|
|
35
|
+
tag: "div"
|
|
36
|
+
}, rest));
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
function List(props) {
|
|
41
|
+
const [local, rest] = splitProps(props, ["activateOnFocus", "loop"]);
|
|
42
|
+
const made = useTabs();
|
|
43
|
+
createComputed(() => made.listOptions.set(defined({
|
|
44
|
+
...local
|
|
45
|
+
})));
|
|
46
|
+
return _$createComponent(Part, _$mergeProps({
|
|
47
|
+
get part() {
|
|
48
|
+
return made.list;
|
|
49
|
+
},
|
|
50
|
+
tag: "div"
|
|
51
|
+
}, rest));
|
|
52
|
+
}
|
|
53
|
+
function Tab(props) {
|
|
54
|
+
const [local, rest] = splitProps(props, ["value", "disabled"]);
|
|
55
|
+
const options = toSignal(() => ({
|
|
56
|
+
disabled: local.disabled
|
|
57
|
+
}));
|
|
58
|
+
// A tab is its value for as long as it is in the page.
|
|
59
|
+
const part = useTabs().tab(untrack(() => local.value), () => defined(options.get()));
|
|
60
|
+
return _$createComponent(Part, _$mergeProps({
|
|
61
|
+
part: part,
|
|
62
|
+
tag: "button"
|
|
63
|
+
}, rest));
|
|
64
|
+
}
|
|
65
|
+
const Indicator = props => _$createComponent(Part, _$mergeProps({
|
|
66
|
+
get part() {
|
|
67
|
+
return useTabs().indicator;
|
|
68
|
+
},
|
|
69
|
+
tag: "span"
|
|
70
|
+
}, props));
|
|
71
|
+
/** `keepMounted` keeps the panel in the page, `hidden`, while its tab is not the active one. */
|
|
72
|
+
function Panel(props) {
|
|
73
|
+
const [local, rest] = splitProps(props, ["value", "keepMounted"]);
|
|
74
|
+
const panel = useTabs().panel(untrack(() => local.value));
|
|
75
|
+
onMount(() => onCleanup(panel.mount()));
|
|
76
|
+
const mounted = fromSignal(panel.mounted);
|
|
77
|
+
return _$createComponent(Show, {
|
|
78
|
+
get when() {
|
|
79
|
+
return mounted() || local.keepMounted;
|
|
80
|
+
},
|
|
81
|
+
get children() {
|
|
82
|
+
return _$createComponent(Part, _$mergeProps({
|
|
83
|
+
get part() {
|
|
84
|
+
return panel.part;
|
|
85
|
+
},
|
|
86
|
+
tag: "div"
|
|
87
|
+
}, rest));
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
export const Tabs = {
|
|
92
|
+
Root,
|
|
93
|
+
List,
|
|
94
|
+
Tab,
|
|
95
|
+
Indicator,
|
|
96
|
+
Panel
|
|
97
|
+
};
|
package/server/toggle.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { createComponent as _$createComponent } from "solid-js/web";
|
|
2
|
+
import { mergeProps as _$mergeProps } from "solid-js/web";
|
|
3
|
+
import { createToggle } from "@kirana-ui/core/toggle";
|
|
4
|
+
import { splitProps } from "solid-js";
|
|
5
|
+
import { Part, controller } from "./runtime.js";
|
|
6
|
+
export function Toggle(props) {
|
|
7
|
+
const [local, rest] = splitProps(props, ["pressed", "defaultPressed", "onPressedChange", "disabled"]);
|
|
8
|
+
const made = controller(createToggle, () => ({
|
|
9
|
+
pressed: local.pressed,
|
|
10
|
+
defaultPressed: local.defaultPressed,
|
|
11
|
+
disabled: local.disabled,
|
|
12
|
+
onPressedChange: (pressed, details) => local.onPressedChange?.(pressed, details)
|
|
13
|
+
}));
|
|
14
|
+
return _$createComponent(Part, _$mergeProps({
|
|
15
|
+
get part() {
|
|
16
|
+
return made.root;
|
|
17
|
+
},
|
|
18
|
+
tag: "button"
|
|
19
|
+
}, rest));
|
|
20
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { createComponent as _$createComponent } from "solid-js/web";
|
|
2
|
+
import { mergeProps as _$mergeProps } from "solid-js/web";
|
|
3
|
+
import { createContext, createUniqueId, splitProps, useContext } from "solid-js";
|
|
4
|
+
import { Part, controller, fromSignal } from "./runtime.js";
|
|
5
|
+
/** The parts of a value drawn as a filled track: a progress bar's, a meter's. */
|
|
6
|
+
export function valueBar(name, create) {
|
|
7
|
+
const Context = createContext();
|
|
8
|
+
function use() {
|
|
9
|
+
const made = useContext(Context);
|
|
10
|
+
if (!made) throw new Error(`A ${name} part must be inside <${name}.Root>`);
|
|
11
|
+
return made;
|
|
12
|
+
}
|
|
13
|
+
function Root(props) {
|
|
14
|
+
const [local, rest] = splitProps(props, ["value", "min", "max", "format", "locale", "getAriaValueText", "id"]);
|
|
15
|
+
const generated = createUniqueId();
|
|
16
|
+
const made = controller(create, () => ({
|
|
17
|
+
...local,
|
|
18
|
+
id: local.id ?? generated
|
|
19
|
+
}));
|
|
20
|
+
return _$createComponent(Context.Provider, {
|
|
21
|
+
value: made,
|
|
22
|
+
get children() {
|
|
23
|
+
return _$createComponent(Part, _$mergeProps({
|
|
24
|
+
get part() {
|
|
25
|
+
return made.root;
|
|
26
|
+
},
|
|
27
|
+
tag: "div"
|
|
28
|
+
}, rest));
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
/** The written value, or what its child, a function, makes of it. */
|
|
33
|
+
function Value(props) {
|
|
34
|
+
const [local, rest] = splitProps(props, ["children"]);
|
|
35
|
+
const made = use();
|
|
36
|
+
const text = fromSignal(made.text);
|
|
37
|
+
return _$createComponent(Part, _$mergeProps({
|
|
38
|
+
get part() {
|
|
39
|
+
return made.value;
|
|
40
|
+
},
|
|
41
|
+
tag: "span"
|
|
42
|
+
}, rest, {
|
|
43
|
+
get children() {
|
|
44
|
+
return local.children ? local.children(text) : text();
|
|
45
|
+
}
|
|
46
|
+
}));
|
|
47
|
+
}
|
|
48
|
+
const part = (key, tag) => props => _$createComponent(Part, _$mergeProps({
|
|
49
|
+
get part() {
|
|
50
|
+
return use()[key];
|
|
51
|
+
},
|
|
52
|
+
tag: tag
|
|
53
|
+
}, props));
|
|
54
|
+
return {
|
|
55
|
+
Root,
|
|
56
|
+
Value,
|
|
57
|
+
Track: part("track", "div"),
|
|
58
|
+
Indicator: part("indicator", "div"),
|
|
59
|
+
Label: part("label", "span")
|
|
60
|
+
};
|
|
61
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { defined, within } from "@kirana-ui/core";
|
|
2
|
+
import { createAccordion } from "@kirana-ui/core/accordion";
|
|
3
|
+
import { Show, createContext, createUniqueId, onCleanup, onMount, splitProps, untrack, useContext, } from "solid-js";
|
|
4
|
+
import { DirectionContext } from "./direction-context.js";
|
|
5
|
+
import { Part, controller, fromSignal, toSignal } from "./runtime.jsx";
|
|
6
|
+
const Context = createContext();
|
|
7
|
+
const ItemContext = createContext();
|
|
8
|
+
function useAccordion() {
|
|
9
|
+
const made = useContext(Context);
|
|
10
|
+
if (!made)
|
|
11
|
+
throw new Error("An Accordion part must be inside <Accordion.Root>");
|
|
12
|
+
return made;
|
|
13
|
+
}
|
|
14
|
+
function useItem() {
|
|
15
|
+
const item = useContext(ItemContext);
|
|
16
|
+
if (!item)
|
|
17
|
+
throw new Error("An Accordion part must be inside <Accordion.Item>");
|
|
18
|
+
return item;
|
|
19
|
+
}
|
|
20
|
+
function Root(props) {
|
|
21
|
+
const [local, rest] = splitProps(props, [
|
|
22
|
+
"value",
|
|
23
|
+
"defaultValue",
|
|
24
|
+
"onValueChange",
|
|
25
|
+
"multiple",
|
|
26
|
+
"disabled",
|
|
27
|
+
"orientation",
|
|
28
|
+
"loop",
|
|
29
|
+
"id",
|
|
30
|
+
]);
|
|
31
|
+
const generated = createUniqueId();
|
|
32
|
+
const direction = useContext(DirectionContext);
|
|
33
|
+
const made = controller(within(createAccordion, { direction }), () => ({
|
|
34
|
+
id: local.id ?? generated,
|
|
35
|
+
value: local.value,
|
|
36
|
+
defaultValue: local.defaultValue,
|
|
37
|
+
multiple: local.multiple,
|
|
38
|
+
disabled: local.disabled,
|
|
39
|
+
orientation: local.orientation,
|
|
40
|
+
loop: local.loop,
|
|
41
|
+
onValueChange: (value, details) => local.onValueChange?.(value, details),
|
|
42
|
+
}));
|
|
43
|
+
return (<Context.Provider value={made}>
|
|
44
|
+
<Part part={made.root} tag="div" {...rest}/>
|
|
45
|
+
</Context.Provider>);
|
|
46
|
+
}
|
|
47
|
+
function Item(props) {
|
|
48
|
+
const [local, rest] = splitProps(props, ["value", "disabled"]);
|
|
49
|
+
const options = toSignal(() => ({ disabled: local.disabled }));
|
|
50
|
+
// An item is its value for as long as it is in the page.
|
|
51
|
+
const item = useAccordion().item(untrack(() => local.value), () => defined(options.get()));
|
|
52
|
+
onMount(() => onCleanup(item.mount()));
|
|
53
|
+
return (<ItemContext.Provider value={item}>
|
|
54
|
+
<Part part={item.root} tag="div" {...rest}/>
|
|
55
|
+
</ItemContext.Provider>);
|
|
56
|
+
}
|
|
57
|
+
const Header = (props) => <Part part={useItem().header} tag="h3" {...props}/>;
|
|
58
|
+
const Trigger = (props) => (<Part part={useItem().trigger} tag="button" {...props}/>);
|
|
59
|
+
/** `keepMounted` keeps the closed panel in the page, `hidden`. */
|
|
60
|
+
function Panel(props) {
|
|
61
|
+
const [local, rest] = splitProps(props, ["keepMounted"]);
|
|
62
|
+
const item = useItem();
|
|
63
|
+
const mounted = fromSignal(item.mounted);
|
|
64
|
+
return (<Show when={mounted() || local.keepMounted}>
|
|
65
|
+
<Part part={item.panel} tag="div" {...rest}/>
|
|
66
|
+
</Show>);
|
|
67
|
+
}
|
|
68
|
+
export const Accordion = { Root, Item, Header, Trigger, Panel };
|