@kirana-ui/solid 0.1.1 → 0.3.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/autosize.js +1 -1
- package/dom/avatar.js +39 -14
- package/dom/button.js +1 -1
- package/dom/calendar.js +78 -19
- package/dom/carousel.js +6 -6
- package/dom/checkbox-group-context.js +3 -0
- package/dom/checkbox-group.js +38 -0
- package/dom/checkbox.js +9 -5
- package/dom/collapsible.js +3 -3
- package/dom/combobox.js +72 -14
- package/dom/command.js +10 -9
- package/dom/date-field.js +7 -3
- package/dom/date-picker.js +9 -3
- package/dom/dialog.js +13 -3
- package/dom/field.js +3 -3
- package/dom/fieldset.js +2 -2
- package/dom/form.js +1 -1
- package/dom/hover-popup.js +3 -3
- package/dom/index.js +1 -0
- package/dom/input.js +1 -1
- package/dom/label.js +1 -1
- package/dom/listbox.js +5 -5
- package/dom/menu.js +11 -11
- package/dom/menubar.js +1 -1
- package/dom/message-scroller.js +4 -4
- package/dom/navigation-menu.js +18 -21
- package/dom/number-field.js +39 -6
- package/dom/otp.js +6 -5
- package/dom/pagination.js +3 -3
- package/dom/popover.js +37 -8
- package/dom/primitive.js +92 -0
- package/dom/qr-code.js +3 -3
- package/dom/radio-group.js +7 -6
- package/dom/resizable.js +3 -3
- package/dom/runtime.js +23 -7
- package/dom/scroll-area.js +5 -5
- package/dom/select.js +26 -13
- package/dom/separator.js +1 -1
- package/dom/slider.js +11 -8
- package/dom/switch.js +3 -3
- package/dom/tabs.js +5 -5
- package/dom/testing.js +3 -0
- package/dom/toast.js +57 -20
- package/dom/toggle-group.js +1 -1
- package/dom/toggle.js +1 -1
- package/dom/toolbar.js +4 -4
- package/dom/value-bar.js +3 -3
- package/llms.txt +1846 -252
- package/package.json +34 -2
- package/server/accordion.js +9 -6
- package/server/agent.js +3 -0
- package/server/autosize.js +1 -1
- package/server/avatar.js +39 -14
- package/server/button.js +1 -1
- package/server/calendar.js +78 -19
- package/server/carousel.js +6 -6
- package/server/checkbox-group-context.js +3 -0
- package/server/checkbox-group.js +38 -0
- package/server/checkbox.js +9 -5
- package/server/collapsible.js +3 -3
- package/server/combobox.js +72 -14
- package/server/command.js +10 -9
- package/server/date-field.js +7 -3
- package/server/date-picker.js +9 -3
- package/server/dialog.js +13 -3
- package/server/field.js +3 -3
- package/server/fieldset.js +2 -2
- package/server/form.js +1 -1
- package/server/hover-popup.js +3 -3
- package/server/index.js +1 -0
- package/server/input.js +1 -1
- package/server/label.js +1 -1
- package/server/listbox.js +5 -5
- package/server/menu.js +11 -11
- package/server/menubar.js +1 -1
- package/server/message-scroller.js +4 -4
- package/server/navigation-menu.js +18 -15
- package/server/number-field.js +39 -6
- package/server/otp.js +6 -5
- package/server/pagination.js +3 -3
- package/server/popover.js +37 -8
- package/server/primitive.js +92 -0
- package/server/qr-code.js +3 -3
- package/server/radio-group.js +7 -6
- package/server/resizable.js +3 -3
- package/server/runtime.js +23 -7
- package/server/scroll-area.js +5 -5
- package/server/select.js +26 -13
- package/server/separator.js +1 -1
- package/server/slider.js +11 -8
- package/server/switch.js +3 -3
- package/server/tabs.js +5 -5
- package/server/testing.js +3 -0
- package/server/toast.js +57 -20
- package/server/toggle-group.js +1 -1
- package/server/toggle.js +1 -1
- package/server/toolbar.js +4 -4
- package/server/value-bar.js +3 -3
- package/skills/kirana-ui-primitives/SKILL.md +163 -0
- package/src/accordion.jsx +10 -7
- package/src/agent.js +3 -0
- package/src/autosize.jsx +1 -1
- package/src/avatar.jsx +17 -10
- package/src/button.jsx +1 -1
- package/src/calendar.jsx +72 -16
- package/src/carousel.jsx +6 -6
- package/src/checkbox-group-context.js +3 -0
- package/src/checkbox-group.jsx +33 -0
- package/src/checkbox.jsx +8 -4
- package/src/collapsible.jsx +3 -3
- package/src/combobox.jsx +70 -13
- package/src/command.jsx +10 -8
- package/src/date-field.jsx +7 -3
- package/src/date-picker.jsx +8 -2
- package/src/dialog.jsx +12 -2
- package/src/field.jsx +3 -3
- package/src/fieldset.jsx +2 -2
- package/src/form.jsx +1 -1
- package/src/hover-popup.jsx +3 -3
- package/src/index.js +1 -0
- package/src/input.jsx +1 -1
- package/src/label.jsx +1 -1
- package/src/listbox.jsx +6 -6
- package/src/menu.jsx +11 -11
- package/src/menubar.jsx +1 -1
- package/src/message-scroller.jsx +4 -4
- package/src/navigation-menu.jsx +14 -13
- package/src/number-field.jsx +26 -6
- package/src/otp.jsx +6 -4
- package/src/pagination.jsx +3 -3
- package/src/popover.jsx +35 -5
- package/src/primitive.jsx +81 -0
- package/src/qr-code.jsx +3 -3
- package/src/radio-group.jsx +7 -7
- package/src/resizable.jsx +3 -3
- package/src/runtime.jsx +21 -7
- package/src/scroll-area.jsx +5 -5
- package/src/select.jsx +29 -14
- package/src/separator.jsx +1 -1
- package/src/slider.jsx +12 -8
- package/src/switch.jsx +3 -3
- package/src/tabs.jsx +6 -6
- package/src/testing.js +3 -0
- package/src/toast.jsx +38 -10
- package/src/toggle-group.jsx +2 -2
- package/src/toggle.jsx +1 -1
- package/src/toolbar.jsx +4 -4
- 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 +1 -0
- package/types/autosize.d.ts +4 -1
- package/types/avatar.d.ts +14 -6
- package/types/button.d.ts +4 -2
- package/types/calendar.d.ts +48 -19
- package/types/carousel.d.ts +18 -10
- package/types/checkbox-group-context.d.ts +3 -0
- package/types/checkbox-group.d.ts +13 -0
- package/types/checkbox.d.ts +10 -6
- package/types/collapsible.d.ts +11 -7
- package/types/combobox.d.ts +102 -64
- package/types/command.d.ts +29 -17
- package/types/context-menu.d.ts +1 -0
- package/types/date-field.d.ts +20 -9
- package/types/date-picker.d.ts +26 -34
- package/types/dialog.d.ts +47 -31
- package/types/direction.d.ts +1 -0
- package/types/drawer.d.ts +1 -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 -10
- package/types/hover-popup.d.ts +23 -13
- package/types/index.d.ts +15 -1
- package/types/input.d.ts +4 -3
- package/types/label.d.ts +4 -1
- package/types/listbox.d.ts +18 -20
- package/types/menu.d.ts +56 -42
- package/types/menubar.d.ts +6 -4
- package/types/message-scroller.d.ts +12 -6
- package/types/meter.d.ts +16 -7
- package/types/navigation-menu.d.ts +35 -29
- package/types/number-field.d.ts +22 -7
- package/types/otp.d.ts +18 -10
- package/types/pagination.d.ts +18 -10
- package/types/popover.d.ts +52 -13
- package/types/primitive.d.ts +50 -0
- package/types/progress.d.ts +16 -7
- package/types/qr-code.d.ts +10 -4
- package/types/radio-group.d.ts +18 -17
- package/types/resizable.d.ts +12 -7
- package/types/runtime.d.ts +36 -12
- package/types/scroll-area.d.ts +17 -9
- package/types/select.d.ts +55 -46
- package/types/separator.d.ts +5 -3
- package/types/slider.d.ts +25 -13
- package/types/switch.d.ts +7 -4
- package/types/tabs.d.ts +20 -16
- package/types/testing.d.ts +1 -0
- package/types/toast.d.ts +40 -16
- package/types/toggle-group.d.ts +6 -11
- package/types/toggle.d.ts +4 -3
- package/types/toolbar.d.ts +19 -14
- package/types/tooltip.d.ts +16 -10
- package/types/value-bar.d.ts +21 -10
package/src/popover.jsx
CHANGED
|
@@ -2,6 +2,10 @@ import { defined } from "@kirana-ui/core";
|
|
|
2
2
|
import { createPopover } from "@kirana-ui/core/popover";
|
|
3
3
|
import { createComputed, createContext, createUniqueId, splitProps, useContext } from "solid-js";
|
|
4
4
|
import { Part, Portal as BodyPortal, controller } from "./runtime.jsx";
|
|
5
|
+
/**
|
|
6
|
+
* The popover its parts are inside. Exported for a component that is made of one (a date picker
|
|
7
|
+
* provides its own to the popover's parts).
|
|
8
|
+
*/
|
|
5
9
|
const Context = createContext();
|
|
6
10
|
/** For a component made of this one's parts: a date picker. */
|
|
7
11
|
export { Context as PopoverContext };
|
|
@@ -16,13 +20,17 @@ function Root(props) {
|
|
|
16
20
|
const made = controller(createPopover, () => ({
|
|
17
21
|
id: props.id ?? generated,
|
|
18
22
|
open: props.open,
|
|
23
|
+
modal: props.modal,
|
|
19
24
|
defaultOpen: props.defaultOpen,
|
|
20
25
|
onOpenChange: (open, details) => props.onOpenChange?.(open, details),
|
|
21
26
|
}));
|
|
22
27
|
return <Context.Provider value={made}>{props.children}</Context.Provider>;
|
|
23
28
|
}
|
|
24
29
|
const Portal = (props) => (<BodyPortal mounted={usePopover().mounted}>{props.children}</BodyPortal>);
|
|
25
|
-
/**
|
|
30
|
+
/**
|
|
31
|
+
* A positioner's own props, written where its placement reads them, before its element
|
|
32
|
+
* attaches: the one place they are named. Gives back what is left, for the part's element.
|
|
33
|
+
*/
|
|
26
34
|
export function positioned(props, positioning) {
|
|
27
35
|
const [local, rest] = splitProps(props, [
|
|
28
36
|
"side",
|
|
@@ -30,21 +38,43 @@ export function positioned(props, positioning) {
|
|
|
30
38
|
"sideOffset",
|
|
31
39
|
"alignOffset",
|
|
32
40
|
"collisionPadding",
|
|
41
|
+
"collisionBoundary",
|
|
42
|
+
"collisionAvoidance",
|
|
43
|
+
"sticky",
|
|
44
|
+
"arrowPadding",
|
|
45
|
+
"positionMethod",
|
|
46
|
+
"anchor",
|
|
33
47
|
]);
|
|
34
|
-
createComputed(() =>
|
|
48
|
+
createComputed(() => {
|
|
49
|
+
const anchor = local.anchor;
|
|
50
|
+
positioning.set(defined({
|
|
51
|
+
...local,
|
|
52
|
+
// A function is asked here, so a change of the signal it reads is followed; and given
|
|
53
|
+
// whole while it has nothing, to be asked again as the popup is placed.
|
|
54
|
+
anchor: typeof anchor === "function" ? (anchor() ?? anchor) : anchor,
|
|
55
|
+
}));
|
|
56
|
+
});
|
|
35
57
|
return rest;
|
|
36
58
|
}
|
|
37
59
|
function Positioner(props) {
|
|
38
60
|
const made = usePopover();
|
|
39
|
-
return <Part
|
|
61
|
+
return <Part of={made.positioner} tag="div" {...positioned(props, made.positioning)}/>;
|
|
62
|
+
}
|
|
63
|
+
const part = (name, tag) => (props) => <Part of={usePopover()[name]} tag={tag} {...props}/>;
|
|
64
|
+
function Trigger(props) {
|
|
65
|
+
const [local, rest] = splitProps(props, ["openOnHover", "delay", "closeDelay"]);
|
|
66
|
+
const made = usePopover();
|
|
67
|
+
createComputed(() => made.hovering.set(defined({ ...local })));
|
|
68
|
+
return <Part of={made.trigger} tag="button" {...rest}/>;
|
|
40
69
|
}
|
|
41
|
-
const part = (name, tag) => (props) => <Part part={usePopover()[name]} tag={tag} {...props}/>;
|
|
42
70
|
export const Popover = {
|
|
43
71
|
Root,
|
|
44
72
|
Portal,
|
|
73
|
+
Backdrop: part("backdrop", "div"),
|
|
45
74
|
Positioner,
|
|
46
|
-
Trigger
|
|
75
|
+
Trigger,
|
|
47
76
|
Popup: part("popup", "div"),
|
|
77
|
+
Arrow: part("arrow", "div"),
|
|
48
78
|
Title: part("title", "h2"),
|
|
49
79
|
Description: part("description", "p"),
|
|
50
80
|
Close: part("close", "button"),
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { mergeProps as layer, stateAttributes } from "@kirana-ui/core";
|
|
2
|
+
import { Show, children, createMemo, splitProps } from "solid-js";
|
|
3
|
+
import { Dynamic } from "solid-js/web";
|
|
4
|
+
/**
|
|
5
|
+
* A plain element of one's own (a badge, a breadcrumb's link) with the composition a part has:
|
|
6
|
+
* `as` for another tag (a `div` unless said), or `render` for the caller's own element, given the
|
|
7
|
+
* props to spread and the state. `state` is written as `data-*` attributes under the attributes
|
|
8
|
+
* given. Merge the component's own props with its caller's through `mergeProps`, as a part's
|
|
9
|
+
* are merged.
|
|
10
|
+
*/
|
|
11
|
+
export function Primitive(props) {
|
|
12
|
+
const [local, rest] = splitProps(props, [
|
|
13
|
+
"as",
|
|
14
|
+
"render",
|
|
15
|
+
"state",
|
|
16
|
+
"children",
|
|
17
|
+
]);
|
|
18
|
+
const marks = () => stateAttributes(local.state ?? {});
|
|
19
|
+
return (<Show when={local.render} fallback={<Dynamic component={local.as ?? "div"} {...marks()} {...rest}>
|
|
20
|
+
{local.children}
|
|
21
|
+
</Dynamic>}>
|
|
22
|
+
{(render) => {
|
|
23
|
+
// Resolved once, as a part's are: a change of the props hands the same nodes over again.
|
|
24
|
+
const held = children(() => local.children);
|
|
25
|
+
const handed = createMemo(() => {
|
|
26
|
+
const given = { ...marks() };
|
|
27
|
+
for (const key of Object.keys(rest))
|
|
28
|
+
given[key] = rest[key];
|
|
29
|
+
return { ...given, children: held() };
|
|
30
|
+
});
|
|
31
|
+
return render()(handed, () => local.state ?? {});
|
|
32
|
+
}}
|
|
33
|
+
</Show>);
|
|
34
|
+
}
|
|
35
|
+
/** One key of several sets, by a part's rule. */
|
|
36
|
+
function mergedValue(sets, key) {
|
|
37
|
+
if (key === "ref") {
|
|
38
|
+
// Solid hands a component a function whatever was written: each set's gets the element.
|
|
39
|
+
const refs = sets.map((set) => set?.ref).filter((ref) => typeof ref === "function");
|
|
40
|
+
if (refs.length < 2)
|
|
41
|
+
return refs[0];
|
|
42
|
+
return (element) => {
|
|
43
|
+
for (const ref of refs)
|
|
44
|
+
ref(element);
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
let merged = {};
|
|
48
|
+
for (const set of sets)
|
|
49
|
+
if (set && key in set)
|
|
50
|
+
merged = layer(merged, { [key]: set[key] });
|
|
51
|
+
return merged[key];
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Several sets of props as one, for a component's own props and its caller's: a later set
|
|
55
|
+
* wins an attribute it gives (one it leaves `undefined` stays), classes join, styles are
|
|
56
|
+
* merged property by property, the handlers of an event run in order until one calls
|
|
57
|
+
* `event.preventKiranaHandler()`, which stops those after it, and every `ref` gets the
|
|
58
|
+
* element. It reads its sets when a prop is read, so a component's props stay reactive: spread
|
|
59
|
+
* it (`<Primitive {...mergeProps({ class: "badge" }, props)} />`). Not solid-js's
|
|
60
|
+
* `mergeProps`, where a later class replaces an earlier one: import one under another name
|
|
61
|
+
* where both are used.
|
|
62
|
+
*/
|
|
63
|
+
export function mergeProps(...sets) {
|
|
64
|
+
const keys = () => {
|
|
65
|
+
const all = new Set();
|
|
66
|
+
for (const set of sets)
|
|
67
|
+
if (set)
|
|
68
|
+
for (const key of Object.keys(set))
|
|
69
|
+
all.add(key);
|
|
70
|
+
return [...all];
|
|
71
|
+
};
|
|
72
|
+
const given = sets;
|
|
73
|
+
return new Proxy({}, {
|
|
74
|
+
get: (_, key) => (typeof key === "string" ? mergedValue(given, key) : undefined),
|
|
75
|
+
has: (_, key) => typeof key === "string" && keys().includes(key),
|
|
76
|
+
ownKeys: () => keys(),
|
|
77
|
+
getOwnPropertyDescriptor: (_, key) => typeof key === "string" && keys().includes(key)
|
|
78
|
+
? { configurable: true, enumerable: true, get: () => mergedValue(given, key) }
|
|
79
|
+
: undefined,
|
|
80
|
+
});
|
|
81
|
+
}
|
package/src/qr-code.jsx
CHANGED
|
@@ -17,9 +17,9 @@ function Root(props) {
|
|
|
17
17
|
correction: local.correction,
|
|
18
18
|
}));
|
|
19
19
|
return (<Context.Provider value={made}>
|
|
20
|
-
<Part
|
|
20
|
+
<Part of={made.root} tag="div" {...rest}/>
|
|
21
21
|
</Context.Provider>);
|
|
22
22
|
}
|
|
23
|
-
const Frame = (props) => <Part
|
|
24
|
-
const Pattern = (props) =>
|
|
23
|
+
const Frame = (props) => <Part of={useQrCode().frame} tag="svg" {...props}/>;
|
|
24
|
+
const Pattern = (props) => <Part of={useQrCode().pattern} tag="path" {...props}/>;
|
|
25
25
|
export const QrCode = { Root, Frame, Pattern };
|
package/src/radio-group.jsx
CHANGED
|
@@ -26,7 +26,7 @@ function Root(props) {
|
|
|
26
26
|
]);
|
|
27
27
|
const generated = createUniqueId();
|
|
28
28
|
const field = useContext(FieldContext);
|
|
29
|
-
const made = controller(within(createRadioGroup, { field, direction: useContext(DirectionContext) }), () => ({
|
|
29
|
+
const made = controller(within((createRadioGroup), { field, direction: useContext(DirectionContext) }), () => ({
|
|
30
30
|
id: local.id ?? generated,
|
|
31
31
|
value: local.value,
|
|
32
32
|
defaultValue: local.defaultValue,
|
|
@@ -38,20 +38,20 @@ function Root(props) {
|
|
|
38
38
|
onValueChange: (value, details) => local.onValueChange?.(value, details),
|
|
39
39
|
}));
|
|
40
40
|
return (<Context.Provider value={made}>
|
|
41
|
-
<Part
|
|
41
|
+
<Part of={made.root} tag="div" {...rest}/>
|
|
42
42
|
</Context.Provider>);
|
|
43
43
|
}
|
|
44
44
|
function Item(props) {
|
|
45
|
-
const [local, rest] = splitProps(props, ["value", "disabled", "children"]);
|
|
45
|
+
const [local, rest] = splitProps(props, ["value", "disabled", "id", "children"]);
|
|
46
46
|
// An item is its value for as long as it is in the page.
|
|
47
47
|
const value = untrack(() => local.value);
|
|
48
|
-
const options = toSignal(() => ({ disabled: local.disabled }));
|
|
48
|
+
const options = toSignal(() => ({ disabled: local.disabled, id: local.id }));
|
|
49
49
|
const read = () => defined(options.get());
|
|
50
50
|
const group = useRadioGroup();
|
|
51
51
|
return (<ItemContext.Provider value={value}>
|
|
52
|
-
<Part
|
|
52
|
+
<Part of={group.item(value, read)} tag="span" {...rest}>
|
|
53
53
|
{local.children}
|
|
54
|
-
<Part
|
|
54
|
+
<Part of={group.itemInput(value, read)} tag="input"/>
|
|
55
55
|
</Part>
|
|
56
56
|
</ItemContext.Provider>);
|
|
57
57
|
}
|
|
@@ -62,7 +62,7 @@ function Indicator(props) {
|
|
|
62
62
|
onMount(() => onCleanup(indicator.mount()));
|
|
63
63
|
const mounted = fromSignal(indicator.mounted);
|
|
64
64
|
return (<Show when={mounted() || local.keepMounted}>
|
|
65
|
-
<Part
|
|
65
|
+
<Part of={indicator.part} tag="span" {...rest}/>
|
|
66
66
|
</Show>);
|
|
67
67
|
}
|
|
68
68
|
export const RadioGroup = { Root, Item, Indicator };
|
package/src/resizable.jsx
CHANGED
|
@@ -28,19 +28,19 @@ function Group(props) {
|
|
|
28
28
|
onSizesChange: (sizes, details) => local.onSizesChange?.(sizes, details),
|
|
29
29
|
}));
|
|
30
30
|
return (<Context.Provider value={made}>
|
|
31
|
-
<Part
|
|
31
|
+
<Part of={made.group} tag="div" {...rest}/>
|
|
32
32
|
</Context.Provider>);
|
|
33
33
|
}
|
|
34
34
|
function Panel(props) {
|
|
35
35
|
const [local, rest] = splitProps(props, ["defaultSize", "minSize", "maxSize"]);
|
|
36
36
|
const options = toSignal(() => ({ ...local }));
|
|
37
37
|
const part = useResizable().panel(() => defined(options.get()));
|
|
38
|
-
return <Part
|
|
38
|
+
return <Part of={part} tag="div" {...rest}/>;
|
|
39
39
|
}
|
|
40
40
|
function Handle(props) {
|
|
41
41
|
const [local, rest] = splitProps(props, ["disabled"]);
|
|
42
42
|
const options = toSignal(() => ({ disabled: local.disabled }));
|
|
43
43
|
const part = useResizable().handle(() => defined(options.get()));
|
|
44
|
-
return <Part
|
|
44
|
+
return <Part of={part} tag="div" {...rest}/>;
|
|
45
45
|
}
|
|
46
46
|
export const Resizable = { Group, Panel, Handle };
|
package/src/runtime.jsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { mergeProps, sameProps, signal } from "@kirana-ui/core";
|
|
1
|
+
import { mergeProps, sameProps, signal, stateOf } from "@kirana-ui/core";
|
|
2
2
|
import { Show, children, createComputed, createContext, createRenderEffect, createMemo, createSignal, getOwner, onCleanup, onMount, runWithOwner, splitProps, untrack, useContext, } from "solid-js";
|
|
3
3
|
import { Dynamic, Portal as SolidPortal, isServer } from "solid-js/web";
|
|
4
4
|
/** A core signal as a Solid accessor: tracked by whatever calls it. */
|
|
@@ -46,12 +46,15 @@ function toSolid(props) {
|
|
|
46
46
|
return out;
|
|
47
47
|
}
|
|
48
48
|
/**
|
|
49
|
-
*
|
|
50
|
-
* part's and the part's DOM work attached once the element is in the page.
|
|
49
|
+
* The element of a part (`of`), or the caller's through `render`, with the caller's props merged under the
|
|
50
|
+
* part's and the part's DOM work attached once the element is in the page. What the part holds
|
|
51
|
+
* is its children here: with `as` they are the element's, and with `render` they are handed to
|
|
52
|
+
* the caller's function as the `children` of its props, so a control drawn as another element
|
|
53
|
+
* keeps the native input a form and a label reach.
|
|
51
54
|
*/
|
|
52
55
|
export function Part(props) {
|
|
53
|
-
const [local, caller] = splitProps(props, ["
|
|
54
|
-
const own = fromSignal(untrack(() => local.
|
|
56
|
+
const [local, caller] = splitProps(props, ["of", "tag", "as", "render", "children"]);
|
|
57
|
+
const own = fromSignal(untrack(() => local.of).props);
|
|
55
58
|
// Solid hands over an element before it is in the page: the part's DOM work (focus, measures,
|
|
56
59
|
// the starting style) waits for the mount that follows. It belongs to this component, not to
|
|
57
60
|
// the effect that spreads the props (which hands the ref over again, and is torn down, each time
|
|
@@ -62,8 +65,12 @@ export function Part(props) {
|
|
|
62
65
|
if (element === attached)
|
|
63
66
|
return;
|
|
64
67
|
attached = element;
|
|
65
|
-
const part = untrack(() => local.
|
|
68
|
+
const part = untrack(() => local.of);
|
|
66
69
|
runWithOwner(owner, () => onMount(() => onCleanup(part.attach(element))));
|
|
70
|
+
// The caller's own `ref` (Solid hands a component a function, whatever was written).
|
|
71
|
+
const theirs = untrack(() => caller.ref);
|
|
72
|
+
if (typeof theirs === "function")
|
|
73
|
+
theirs(element);
|
|
67
74
|
};
|
|
68
75
|
const merged = createMemo(() => {
|
|
69
76
|
const theirs = {};
|
|
@@ -71,10 +78,17 @@ export function Part(props) {
|
|
|
71
78
|
theirs[key] = caller[key];
|
|
72
79
|
return { ...mergeProps(theirs, toSolid(own())), ref: attach };
|
|
73
80
|
});
|
|
81
|
+
const state = () => stateOf(own());
|
|
74
82
|
return (<Show when={local.render} fallback={<Dynamic component={local.as ?? local.tag} {...merged()}>
|
|
75
83
|
{local.children}
|
|
76
84
|
</Dynamic>}>
|
|
77
|
-
{(render) =>
|
|
85
|
+
{(render) => {
|
|
86
|
+
// Resolved once: a change of the part's props hands the same nodes over again, and
|
|
87
|
+
// the element keeps them.
|
|
88
|
+
const held = children(() => local.children);
|
|
89
|
+
const handed = createMemo(() => ({ ...merged(), children: held() }));
|
|
90
|
+
return render()(handed, state);
|
|
91
|
+
}}
|
|
78
92
|
</Show>);
|
|
79
93
|
}
|
|
80
94
|
/**
|
package/src/scroll-area.jsx
CHANGED
|
@@ -15,7 +15,7 @@ function Root(props) {
|
|
|
15
15
|
const direction = useContext(DirectionContext);
|
|
16
16
|
const made = controller(within(createScrollArea, { direction }), () => ({}));
|
|
17
17
|
return (<Context.Provider value={made}>
|
|
18
|
-
<Part
|
|
18
|
+
<Part of={made.root} tag="div" {...props}/>
|
|
19
19
|
</Context.Provider>);
|
|
20
20
|
}
|
|
21
21
|
/** `orientation` is which way it scrolls (`vertical` by default). */
|
|
@@ -25,7 +25,7 @@ function Scrollbar(props) {
|
|
|
25
25
|
const shown = fromSignal(bar.shown);
|
|
26
26
|
return (<ScrollbarContext.Provider value={bar}>
|
|
27
27
|
<Show when={shown() || local.keepMounted}>
|
|
28
|
-
<Part
|
|
28
|
+
<Part of={bar.part} tag="div" {...rest}/>
|
|
29
29
|
</Show>
|
|
30
30
|
</ScrollbarContext.Provider>);
|
|
31
31
|
}
|
|
@@ -33,16 +33,16 @@ function Thumb(props) {
|
|
|
33
33
|
const bar = useContext(ScrollbarContext);
|
|
34
34
|
if (!bar)
|
|
35
35
|
throw new Error("A ScrollArea.Thumb must be inside <ScrollArea.Scrollbar>");
|
|
36
|
-
return <Part
|
|
36
|
+
return <Part of={bar.thumb} tag="div" {...props}/>;
|
|
37
37
|
}
|
|
38
38
|
function Corner(props) {
|
|
39
39
|
const { corner } = useScrollArea();
|
|
40
40
|
const shown = fromSignal(corner.shown);
|
|
41
41
|
return (<Show when={shown()}>
|
|
42
|
-
<Part
|
|
42
|
+
<Part of={corner.part} tag="div" {...props}/>
|
|
43
43
|
</Show>);
|
|
44
44
|
}
|
|
45
|
-
const part = (name) => (props) =>
|
|
45
|
+
const part = (name) => (props) => <Part of={useScrollArea()[name]} tag="div" {...props}/>;
|
|
46
46
|
export const ScrollArea = {
|
|
47
47
|
Root,
|
|
48
48
|
Viewport: part("viewport"),
|
package/src/select.jsx
CHANGED
|
@@ -15,26 +15,31 @@ function useSelect() {
|
|
|
15
15
|
function Root(props) {
|
|
16
16
|
const generated = createUniqueId();
|
|
17
17
|
const field = useContext(FieldContext);
|
|
18
|
-
const made = controller(within(createSelect, { field }), () => ({
|
|
18
|
+
const made = controller(within((createSelect), { field }), () => ({
|
|
19
19
|
id: props.id ?? generated,
|
|
20
20
|
value: props.value,
|
|
21
21
|
defaultValue: props.defaultValue,
|
|
22
22
|
open: props.open,
|
|
23
23
|
defaultOpen: props.defaultOpen,
|
|
24
24
|
disabled: props.disabled,
|
|
25
|
+
readOnly: props.readOnly,
|
|
25
26
|
required: props.required,
|
|
26
27
|
name: props.name,
|
|
27
28
|
form: props.form,
|
|
28
29
|
items: props.items,
|
|
30
|
+
multiple: props.multiple,
|
|
31
|
+
values: props.values,
|
|
32
|
+
defaultValues: props.defaultValues,
|
|
29
33
|
virtualized: props.virtualized,
|
|
30
34
|
onValueChange: (value, details) => props.onValueChange?.(value, details),
|
|
35
|
+
onValuesChange: (values, details) => props.onValuesChange?.(values, details),
|
|
31
36
|
onOpenChange: (open, details) => props.onOpenChange?.(open, details),
|
|
32
37
|
}));
|
|
33
38
|
const named = fromSignal(made.named);
|
|
34
39
|
return (<Context.Provider value={made}>
|
|
35
40
|
{props.children}
|
|
36
41
|
<Show when={named()}>
|
|
37
|
-
<Part
|
|
42
|
+
<Part of={made.input} tag="input"/>
|
|
38
43
|
</Show>
|
|
39
44
|
</Context.Provider>);
|
|
40
45
|
}
|
|
@@ -47,15 +52,25 @@ function Positioner(props) {
|
|
|
47
52
|
const made = useSelect();
|
|
48
53
|
const [local, rest] = splitProps(props, ["alignItemWithTrigger"]);
|
|
49
54
|
createComputed(() => made.alignItemWithTrigger.set(Boolean(local.alignItemWithTrigger)));
|
|
50
|
-
return
|
|
55
|
+
return <Part of={made.positioner} tag="div" {...positioned(rest, made.positioning)}/>;
|
|
51
56
|
}
|
|
52
|
-
/** Shows the chosen value's label, or `placeholder` while nothing is chosen. */
|
|
53
57
|
function Value(props) {
|
|
54
58
|
const [local, rest] = splitProps(props, ["placeholder", "children"]);
|
|
55
59
|
const made = useSelect();
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
60
|
+
const shown = fromSignal(made.shown);
|
|
61
|
+
const drawn = () => {
|
|
62
|
+
const given = local.children;
|
|
63
|
+
// A function that takes nothing is an element of Solid's own, drawn as it is.
|
|
64
|
+
if (typeof given !== "function" || given.length === 0) {
|
|
65
|
+
return given ?? shown().label ?? local.placeholder;
|
|
66
|
+
}
|
|
67
|
+
const draw = given;
|
|
68
|
+
return made.multiple
|
|
69
|
+
? draw(() => shown().values, () => shown().labels)
|
|
70
|
+
: draw(() => shown().value, () => shown().label);
|
|
71
|
+
};
|
|
72
|
+
return (<Part of={made.valuePart} tag="span" {...rest}>
|
|
73
|
+
{drawn()}
|
|
59
74
|
</Part>);
|
|
60
75
|
}
|
|
61
76
|
/** `label` is what typeahead matches and the trigger shows; the item's text when left out. */
|
|
@@ -70,17 +85,17 @@ function Item(props) {
|
|
|
70
85
|
}));
|
|
71
86
|
const part = useSelect().item(value, () => defined(options.get()));
|
|
72
87
|
return (<ItemContext.Provider value={value}>
|
|
73
|
-
<Part
|
|
88
|
+
<Part of={part} tag="div" {...rest}/>
|
|
74
89
|
</ItemContext.Provider>);
|
|
75
90
|
}
|
|
76
|
-
const ItemText = (props) => (<Part
|
|
91
|
+
const ItemText = (props) => (<Part of={useSelect().itemText(useContext(ItemContext))} tag="span" {...props}/>);
|
|
77
92
|
function ItemIndicator(props) {
|
|
78
93
|
const [local, rest] = splitProps(props, ["keepMounted"]);
|
|
79
94
|
const made = useSelect();
|
|
80
95
|
const value = useContext(ItemContext);
|
|
81
96
|
const selected = fromSignal(made.selected(value));
|
|
82
97
|
return (<Show when={selected() || local.keepMounted}>
|
|
83
|
-
<Part
|
|
98
|
+
<Part of={made.itemIndicator(value)} tag="span" {...rest}/>
|
|
84
99
|
</Show>);
|
|
85
100
|
}
|
|
86
101
|
const GroupContext = createContext();
|
|
@@ -90,22 +105,22 @@ function Group(props) {
|
|
|
90
105
|
const generated = createUniqueId();
|
|
91
106
|
const group = useSelect().group(untrack(() => local.id) ?? generated);
|
|
92
107
|
return (<GroupContext.Provider value={group}>
|
|
93
|
-
<Part
|
|
108
|
+
<Part of={group.root} tag="div" {...rest}/>
|
|
94
109
|
</GroupContext.Provider>);
|
|
95
110
|
}
|
|
96
111
|
/** Names the group it is in. With no group around it, it is plain text. */
|
|
97
|
-
const GroupLabel = (props) => (<Part
|
|
112
|
+
const GroupLabel = (props) => (<Part of={useContext(GroupContext)?.label ?? useSelect().groupLabel} tag="div" {...props}/>);
|
|
98
113
|
function scrollArrow(direction) {
|
|
99
114
|
return (props) => {
|
|
100
115
|
const arrow = useSelect().scrollArrow(direction);
|
|
101
116
|
onMount(() => onCleanup(arrow.mount()));
|
|
102
117
|
const mounted = fromSignal(arrow.mounted);
|
|
103
118
|
return (<Show when={mounted()}>
|
|
104
|
-
<Part
|
|
119
|
+
<Part of={arrow.part} tag="div" {...props}/>
|
|
105
120
|
</Show>);
|
|
106
121
|
};
|
|
107
122
|
}
|
|
108
|
-
const part = (name, tag) => (props) => <Part
|
|
123
|
+
const part = (name, tag) => (props) => <Part of={useSelect()[name]} tag={tag} {...props}/>;
|
|
109
124
|
export const Select = {
|
|
110
125
|
Root,
|
|
111
126
|
Portal,
|
package/src/separator.jsx
CHANGED
|
@@ -4,5 +4,5 @@ import { Part, controller } from "./runtime.jsx";
|
|
|
4
4
|
export function Separator(props) {
|
|
5
5
|
const [local, rest] = splitProps(props, ["orientation"]);
|
|
6
6
|
const made = controller(createSeparator, () => ({ orientation: local.orientation }));
|
|
7
|
-
return <Part
|
|
7
|
+
return <Part of={made.root} tag="div" {...rest}/>;
|
|
8
8
|
}
|
package/src/slider.jsx
CHANGED
|
@@ -11,6 +11,7 @@ function useSlider() {
|
|
|
11
11
|
throw new Error("A Slider part must be inside <Slider.Root>");
|
|
12
12
|
return made;
|
|
13
13
|
}
|
|
14
|
+
// Given neither `value` nor `defaultValue`, a slider has one thumb: its value is a number.
|
|
14
15
|
function Root(props) {
|
|
15
16
|
const [local, rest] = splitProps(props, [
|
|
16
17
|
"value",
|
|
@@ -25,6 +26,7 @@ function Root(props) {
|
|
|
25
26
|
"thumbAlignment",
|
|
26
27
|
"orientation",
|
|
27
28
|
"disabled",
|
|
29
|
+
"readOnly",
|
|
28
30
|
"name",
|
|
29
31
|
"form",
|
|
30
32
|
"format",
|
|
@@ -34,25 +36,27 @@ function Root(props) {
|
|
|
34
36
|
]);
|
|
35
37
|
const generated = createUniqueId();
|
|
36
38
|
const field = useContext(FieldContext);
|
|
37
|
-
const made = controller(within(createSlider, { field, direction: useContext(DirectionContext) }), () => ({
|
|
39
|
+
const made = controller(within((createSlider), { field, direction: useContext(DirectionContext) }), () => ({
|
|
38
40
|
...local,
|
|
39
41
|
id: local.id ?? generated,
|
|
40
42
|
onValueChange: (value, details) => local.onValueChange?.(value, details),
|
|
41
43
|
onValueCommitted: (value, details) => local.onValueCommitted?.(value, details),
|
|
42
44
|
}));
|
|
43
45
|
return (<Context.Provider value={made}>
|
|
44
|
-
<Part
|
|
46
|
+
<Part of={made.root} tag="div" {...rest}/>
|
|
45
47
|
</Context.Provider>);
|
|
46
48
|
}
|
|
47
49
|
/** `index` is which value of a range the thumb is, from 0. */
|
|
48
50
|
function Thumb(props) {
|
|
49
51
|
const [local, rest] = splitProps(props, ["index", "children"]);
|
|
50
|
-
// A thumb is its index for as long as it is in the page.
|
|
51
|
-
|
|
52
|
+
// A thumb is its index for as long as it is in the page. Given none, it takes its place
|
|
53
|
+
// among the slider's thumbs, in the order they are written.
|
|
54
|
+
const generated = createUniqueId();
|
|
55
|
+
const index = untrack(() => local.index ?? generated);
|
|
52
56
|
const slider = useSlider();
|
|
53
|
-
return (<Part
|
|
57
|
+
return (<Part of={slider.thumb(index)} tag="div" {...rest}>
|
|
54
58
|
{local.children}
|
|
55
|
-
<Part
|
|
59
|
+
<Part of={slider.thumbInput(index)} tag="input"/>
|
|
56
60
|
</Part>);
|
|
57
61
|
}
|
|
58
62
|
/** The written value, or what its child, a function, makes of it and of the values. */
|
|
@@ -61,11 +65,11 @@ function Value(props) {
|
|
|
61
65
|
const made = useSlider();
|
|
62
66
|
const text = fromSignal(made.text);
|
|
63
67
|
const values = fromSignal(made.values);
|
|
64
|
-
return (<Part
|
|
68
|
+
return (<Part of={made.value} tag="output" {...rest}>
|
|
65
69
|
{local.children ? local.children(text, values) : text()}
|
|
66
70
|
</Part>);
|
|
67
71
|
}
|
|
68
|
-
const part = (key) => (props) =>
|
|
72
|
+
const part = (key) => (props) => <Part of={useSlider()[key]} tag="div" {...props}/>;
|
|
69
73
|
export const Slider = {
|
|
70
74
|
Root,
|
|
71
75
|
Value,
|
package/src/switch.jsx
CHANGED
|
@@ -39,11 +39,11 @@ function Root(props) {
|
|
|
39
39
|
onCheckedChange: (checked, details) => local.onCheckedChange?.(checked, details),
|
|
40
40
|
}));
|
|
41
41
|
return (<Context.Provider value={made}>
|
|
42
|
-
<Part
|
|
42
|
+
<Part of={made.root} tag="span" {...rest}>
|
|
43
43
|
{local.children}
|
|
44
|
-
<Part
|
|
44
|
+
<Part of={made.input} tag="input"/>
|
|
45
45
|
</Part>
|
|
46
46
|
</Context.Provider>);
|
|
47
47
|
}
|
|
48
|
-
const Thumb = (props) => <Part
|
|
48
|
+
const Thumb = (props) => <Part of={useSwitch().thumb} tag="span" {...props}/>;
|
|
49
49
|
export const Switch = { Root, Thumb };
|
package/src/tabs.jsx
CHANGED
|
@@ -20,7 +20,7 @@ function Root(props) {
|
|
|
20
20
|
]);
|
|
21
21
|
const generated = createUniqueId();
|
|
22
22
|
const direction = useContext(DirectionContext);
|
|
23
|
-
const made = controller(within(createTabs, { direction }), () => ({
|
|
23
|
+
const made = controller(within((createTabs), { direction }), () => ({
|
|
24
24
|
id: local.id ?? generated,
|
|
25
25
|
value: local.value,
|
|
26
26
|
defaultValue: local.defaultValue,
|
|
@@ -28,23 +28,23 @@ function Root(props) {
|
|
|
28
28
|
onValueChange: (value, details) => local.onValueChange?.(value, details),
|
|
29
29
|
}));
|
|
30
30
|
return (<Context.Provider value={made}>
|
|
31
|
-
<Part
|
|
31
|
+
<Part of={made.root} tag="div" {...rest}/>
|
|
32
32
|
</Context.Provider>);
|
|
33
33
|
}
|
|
34
34
|
function List(props) {
|
|
35
35
|
const [local, rest] = splitProps(props, ["activateOnFocus", "loop"]);
|
|
36
36
|
const made = useTabs();
|
|
37
37
|
createComputed(() => made.listOptions.set(defined({ ...local })));
|
|
38
|
-
return <Part
|
|
38
|
+
return <Part of={made.list} tag="div" {...rest}/>;
|
|
39
39
|
}
|
|
40
40
|
function Tab(props) {
|
|
41
41
|
const [local, rest] = splitProps(props, ["value", "disabled"]);
|
|
42
42
|
const options = toSignal(() => ({ disabled: local.disabled }));
|
|
43
43
|
// A tab is its value for as long as it is in the page.
|
|
44
44
|
const part = useTabs().tab(untrack(() => local.value), () => defined(options.get()));
|
|
45
|
-
return <Part
|
|
45
|
+
return <Part of={part} tag="button" {...rest}/>;
|
|
46
46
|
}
|
|
47
|
-
const Indicator = (props) =>
|
|
47
|
+
const Indicator = (props) => <Part of={useTabs().indicator} tag="span" {...props}/>;
|
|
48
48
|
/** `keepMounted` keeps the panel in the page, `hidden`, while its tab is not the active one. */
|
|
49
49
|
function Panel(props) {
|
|
50
50
|
const [local, rest] = splitProps(props, ["value", "keepMounted"]);
|
|
@@ -52,7 +52,7 @@ function Panel(props) {
|
|
|
52
52
|
onMount(() => onCleanup(panel.mount()));
|
|
53
53
|
const mounted = fromSignal(panel.mounted);
|
|
54
54
|
return (<Show when={mounted() || local.keepMounted}>
|
|
55
|
-
<Part
|
|
55
|
+
<Part of={panel.part} tag="div" {...rest}/>
|
|
56
56
|
</Show>);
|
|
57
57
|
}
|
|
58
58
|
export const Tabs = { Root, List, Tab, Indicator, Panel };
|
package/src/testing.js
ADDED