@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
package/src/avatar.jsx
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { createAvatar } from "@kirana-ui/core/avatar";
|
|
2
|
+
import { Show, createComputed, createContext, splitProps, useContext } from "solid-js";
|
|
3
|
+
import { Part, controller, fromSignal } from "./runtime.jsx";
|
|
4
|
+
const Context = createContext();
|
|
5
|
+
function useAvatar() {
|
|
6
|
+
const made = useContext(Context);
|
|
7
|
+
if (!made)
|
|
8
|
+
throw new Error("An Avatar part must be inside <Avatar.Root>");
|
|
9
|
+
return made;
|
|
10
|
+
}
|
|
11
|
+
function Root(props) {
|
|
12
|
+
const made = controller(createAvatar, () => ({}));
|
|
13
|
+
return (<Context.Provider value={made}>
|
|
14
|
+
<Part part={made.root} tag="span" {...props}/>
|
|
15
|
+
</Context.Provider>);
|
|
16
|
+
}
|
|
17
|
+
/** The picture: in the page once `src` has loaded. */
|
|
18
|
+
function Image(props) {
|
|
19
|
+
const [local, rest] = splitProps(props, ["src"]);
|
|
20
|
+
const made = useAvatar();
|
|
21
|
+
createComputed(() => made.source.set(local.src));
|
|
22
|
+
const status = fromSignal(made.status);
|
|
23
|
+
return (<Show when={status() === "loaded"}>
|
|
24
|
+
<Part part={made.image} tag="img" {...rest}/>
|
|
25
|
+
</Show>);
|
|
26
|
+
}
|
|
27
|
+
/** What shows until the picture has loaded, or when it cannot. */
|
|
28
|
+
function Fallback(props) {
|
|
29
|
+
const made = useAvatar();
|
|
30
|
+
const status = fromSignal(made.status);
|
|
31
|
+
return (<Show when={status() !== "loaded"}>
|
|
32
|
+
<Part part={made.fallback} tag="span" {...props}/>
|
|
33
|
+
</Show>);
|
|
34
|
+
}
|
|
35
|
+
export const Avatar = { Root, Image, Fallback };
|
package/src/button.jsx
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { createButton } from "@kirana-ui/core/button";
|
|
2
|
+
import { splitProps } from "solid-js";
|
|
3
|
+
import { Part, controller } from "./runtime.jsx";
|
|
4
|
+
/** A `<button>`, or with `as` and `nativeButton={false}` another element that acts as one. */
|
|
5
|
+
export function Button(props) {
|
|
6
|
+
const [local, rest] = splitProps(props, ["disabled", "focusableWhenDisabled", "nativeButton"]);
|
|
7
|
+
const made = controller(createButton, () => ({ ...local }));
|
|
8
|
+
return <Part part={made.root} tag="button" {...rest}/>;
|
|
9
|
+
}
|
package/src/checkbox.jsx
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { within } from "@kirana-ui/core";
|
|
2
|
+
import { createCheckbox } from "@kirana-ui/core/checkbox";
|
|
3
|
+
import { Show, createContext, createUniqueId, splitProps, useContext } from "solid-js";
|
|
4
|
+
import { FieldContext } from "./field-context.js";
|
|
5
|
+
import { Part, controller, fromSignal } from "./runtime.jsx";
|
|
6
|
+
const Context = createContext();
|
|
7
|
+
function useCheckbox() {
|
|
8
|
+
const made = useContext(Context);
|
|
9
|
+
if (!made)
|
|
10
|
+
throw new Error("A Checkbox part must be inside <Checkbox.Root>");
|
|
11
|
+
return made;
|
|
12
|
+
}
|
|
13
|
+
function Root(props) {
|
|
14
|
+
const [local, rest] = splitProps(props, [
|
|
15
|
+
"checked",
|
|
16
|
+
"defaultChecked",
|
|
17
|
+
"onCheckedChange",
|
|
18
|
+
"indeterminate",
|
|
19
|
+
"disabled",
|
|
20
|
+
"readOnly",
|
|
21
|
+
"required",
|
|
22
|
+
"name",
|
|
23
|
+
"value",
|
|
24
|
+
"id",
|
|
25
|
+
"children",
|
|
26
|
+
]);
|
|
27
|
+
const generated = createUniqueId();
|
|
28
|
+
const field = useContext(FieldContext);
|
|
29
|
+
const made = controller(within(createCheckbox, { field }), () => ({
|
|
30
|
+
id: local.id ?? generated,
|
|
31
|
+
checked: local.checked,
|
|
32
|
+
defaultChecked: local.defaultChecked,
|
|
33
|
+
indeterminate: local.indeterminate,
|
|
34
|
+
disabled: local.disabled,
|
|
35
|
+
readOnly: local.readOnly,
|
|
36
|
+
required: local.required,
|
|
37
|
+
name: local.name,
|
|
38
|
+
value: local.value,
|
|
39
|
+
onCheckedChange: (checked, details) => local.onCheckedChange?.(checked, details),
|
|
40
|
+
}));
|
|
41
|
+
return (<Context.Provider value={made}>
|
|
42
|
+
<Part part={made.root} tag="span" {...rest}>
|
|
43
|
+
{local.children}
|
|
44
|
+
<Part part={made.input} tag="input"/>
|
|
45
|
+
</Part>
|
|
46
|
+
</Context.Provider>);
|
|
47
|
+
}
|
|
48
|
+
/** `keepMounted` keeps the mark in the page while the box is unchecked. */
|
|
49
|
+
function Indicator(props) {
|
|
50
|
+
const [local, rest] = splitProps(props, ["keepMounted"]);
|
|
51
|
+
const made = useCheckbox();
|
|
52
|
+
const mounted = fromSignal(made.indicatorMounted);
|
|
53
|
+
return (<Show when={mounted() || local.keepMounted}>
|
|
54
|
+
<Part part={made.indicator} tag="span" {...rest}/>
|
|
55
|
+
</Show>);
|
|
56
|
+
}
|
|
57
|
+
export const Checkbox = { Root, Indicator };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { createCollapsible } from "@kirana-ui/core/collapsible";
|
|
2
|
+
import { Show, createContext, createUniqueId, splitProps, useContext } from "solid-js";
|
|
3
|
+
import { Part, controller, fromSignal } from "./runtime.jsx";
|
|
4
|
+
const Context = createContext();
|
|
5
|
+
function useCollapsible() {
|
|
6
|
+
const made = useContext(Context);
|
|
7
|
+
if (!made)
|
|
8
|
+
throw new Error("A Collapsible part must be inside <Collapsible.Root>");
|
|
9
|
+
return made;
|
|
10
|
+
}
|
|
11
|
+
function Root(props) {
|
|
12
|
+
const [local, rest] = splitProps(props, ["open", "defaultOpen", "onOpenChange", "disabled", "id"]);
|
|
13
|
+
const generated = createUniqueId();
|
|
14
|
+
const made = controller(createCollapsible, () => ({
|
|
15
|
+
id: local.id ?? generated,
|
|
16
|
+
open: local.open,
|
|
17
|
+
defaultOpen: local.defaultOpen,
|
|
18
|
+
disabled: local.disabled,
|
|
19
|
+
onOpenChange: (open, details) => local.onOpenChange?.(open, details),
|
|
20
|
+
}));
|
|
21
|
+
return (<Context.Provider value={made}>
|
|
22
|
+
<Part part={made.root} tag="div" {...rest}/>
|
|
23
|
+
</Context.Provider>);
|
|
24
|
+
}
|
|
25
|
+
const Trigger = (props) => (<Part part={useCollapsible().trigger} tag="button" {...props}/>);
|
|
26
|
+
/** `keepMounted` keeps the closed panel in the page, `hidden`. */
|
|
27
|
+
function Panel(props) {
|
|
28
|
+
const [local, rest] = splitProps(props, ["keepMounted"]);
|
|
29
|
+
const made = useCollapsible();
|
|
30
|
+
const mounted = fromSignal(made.mounted);
|
|
31
|
+
return (<Show when={mounted() || local.keepMounted}>
|
|
32
|
+
<Part part={made.panel} tag="div" {...rest}/>
|
|
33
|
+
</Show>);
|
|
34
|
+
}
|
|
35
|
+
export const Collapsible = { Root, Trigger, Panel };
|
package/src/dialog.jsx
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { createAlertDialog } from "@kirana-ui/core/alert-dialog";
|
|
2
|
+
import { createDialog } from "@kirana-ui/core/dialog";
|
|
3
|
+
import { createContext, createUniqueId, useContext } from "solid-js";
|
|
4
|
+
import { Part, Portal as BodyPortal, controller } from "./runtime.jsx";
|
|
5
|
+
const Context = createContext();
|
|
6
|
+
function useDialog() {
|
|
7
|
+
const made = useContext(Context);
|
|
8
|
+
if (!made)
|
|
9
|
+
throw new Error("A Dialog part must be inside <Dialog.Root>");
|
|
10
|
+
return made;
|
|
11
|
+
}
|
|
12
|
+
function Root(props) {
|
|
13
|
+
const generated = createUniqueId();
|
|
14
|
+
const made = controller(createDialog, () => ({
|
|
15
|
+
id: props.id ?? generated,
|
|
16
|
+
open: props.open,
|
|
17
|
+
defaultOpen: props.defaultOpen,
|
|
18
|
+
modal: props.modal,
|
|
19
|
+
dismissible: props.dismissible,
|
|
20
|
+
onOpenChange: (open, details) => props.onOpenChange?.(open, details),
|
|
21
|
+
}));
|
|
22
|
+
return <Context.Provider value={made}>{props.children}</Context.Provider>;
|
|
23
|
+
}
|
|
24
|
+
const Portal = (props) => (<BodyPortal mounted={useDialog().mounted}>{props.children}</BodyPortal>);
|
|
25
|
+
const part = (name, tag) => (props) => <Part part={useDialog()[name]} tag={tag} {...props}/>;
|
|
26
|
+
function AlertRoot(props) {
|
|
27
|
+
const generated = createUniqueId();
|
|
28
|
+
const made = controller(createAlertDialog, () => ({
|
|
29
|
+
id: props.id ?? generated,
|
|
30
|
+
open: props.open,
|
|
31
|
+
defaultOpen: props.defaultOpen,
|
|
32
|
+
onOpenChange: (open, details) => props.onOpenChange?.(open, details),
|
|
33
|
+
}));
|
|
34
|
+
return <Context.Provider value={made}>{props.children}</Context.Provider>;
|
|
35
|
+
}
|
|
36
|
+
export const Dialog = {
|
|
37
|
+
Root,
|
|
38
|
+
Portal,
|
|
39
|
+
Trigger: part("trigger", "button"),
|
|
40
|
+
Backdrop: part("backdrop", "div"),
|
|
41
|
+
Popup: part("popup", "div"),
|
|
42
|
+
Title: part("title", "h2"),
|
|
43
|
+
Description: part("description", "p"),
|
|
44
|
+
Close: part("close", "button"),
|
|
45
|
+
};
|
|
46
|
+
/** A dialog that asks for an answer: a press outside it does not close it. Its parts are a dialog's. */
|
|
47
|
+
export const AlertDialog = { ...Dialog, Root: AlertRoot };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { signal } from "@kirana-ui/core";
|
|
2
|
+
import { createDirection } from "@kirana-ui/core/direction";
|
|
3
|
+
import { useContext } from "solid-js";
|
|
4
|
+
import { DirectionContext } from "./direction-context.js";
|
|
5
|
+
import { controller, fromSignal } from "./runtime.jsx";
|
|
6
|
+
/**
|
|
7
|
+
* States the reading direction for the components inside. It draws nothing: set the page's own
|
|
8
|
+
* `dir` attribute with it.
|
|
9
|
+
*/
|
|
10
|
+
export function DirectionProvider(props) {
|
|
11
|
+
const made = controller(createDirection, () => ({ direction: props.direction }));
|
|
12
|
+
return (<DirectionContext.Provider value={made.direction}>{props.children}</DirectionContext.Provider>);
|
|
13
|
+
}
|
|
14
|
+
/** The direction the nearest provider states; `ltr` outside one. */
|
|
15
|
+
export function useDirection() {
|
|
16
|
+
return fromSignal(useContext(DirectionContext) ?? signal("ltr"));
|
|
17
|
+
}
|
package/src/field.jsx
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { createField } from "@kirana-ui/core/field";
|
|
2
|
+
import { Show, createUniqueId, onCleanup, onMount, splitProps, useContext } from "solid-js";
|
|
3
|
+
import { FieldContext } from "./field-context.js";
|
|
4
|
+
import { FieldsetContext } from "./fieldset.jsx";
|
|
5
|
+
import { FormContext } from "./form.jsx";
|
|
6
|
+
import { Part, controller, fromSignal, toSignal } from "./runtime.jsx";
|
|
7
|
+
function useField() {
|
|
8
|
+
const made = useContext(FieldContext);
|
|
9
|
+
if (!made)
|
|
10
|
+
throw new Error("A Field part must be inside <Field.Root>");
|
|
11
|
+
return made;
|
|
12
|
+
}
|
|
13
|
+
function Root(props) {
|
|
14
|
+
const [local, rest] = splitProps(props, [
|
|
15
|
+
"name",
|
|
16
|
+
"disabled",
|
|
17
|
+
"invalid",
|
|
18
|
+
"validate",
|
|
19
|
+
"validationMode",
|
|
20
|
+
"validationDebounceTime",
|
|
21
|
+
"id",
|
|
22
|
+
]);
|
|
23
|
+
const generated = createUniqueId();
|
|
24
|
+
const around = { form: useContext(FormContext), fieldset: useContext(FieldsetContext) };
|
|
25
|
+
const made = controller((source) => createField(source, around), () => ({
|
|
26
|
+
...local,
|
|
27
|
+
id: local.id ?? generated,
|
|
28
|
+
validate: (value) => local.validate?.(value) ?? null,
|
|
29
|
+
}));
|
|
30
|
+
return (<FieldContext.Provider value={made}>
|
|
31
|
+
<Part part={made.root} tag="div" {...rest}/>
|
|
32
|
+
</FieldContext.Provider>);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* What is wrong, or its children in its place. In the page while it applies. `match` is one of
|
|
36
|
+
* the browser's findings (`"valueMissing"`) to show for only that, or `true` to show always.
|
|
37
|
+
*/
|
|
38
|
+
function FieldError(props) {
|
|
39
|
+
const [local, rest] = splitProps(props, ["match", "children"]);
|
|
40
|
+
const options = toSignal(() => ({ match: local.match }));
|
|
41
|
+
const error = useField().error(() => options.get().match);
|
|
42
|
+
onMount(() => onCleanup(error.mount()));
|
|
43
|
+
const mounted = fromSignal(error.mounted);
|
|
44
|
+
const text = fromSignal(error.text);
|
|
45
|
+
return (<Show when={mounted()}>
|
|
46
|
+
<Part part={error.part} tag="div" {...rest}>
|
|
47
|
+
{local.children ?? text()}
|
|
48
|
+
</Part>
|
|
49
|
+
</Show>);
|
|
50
|
+
}
|
|
51
|
+
/** Draws nothing itself: its child, a function, is given the field's validity. */
|
|
52
|
+
function Validity(props) {
|
|
53
|
+
return props.children(fromSignal(useField().validity));
|
|
54
|
+
}
|
|
55
|
+
const part = (key, tag) => (props) => (<Part part={useField()[key]} tag={tag} {...props}/>);
|
|
56
|
+
export const Field = {
|
|
57
|
+
Root,
|
|
58
|
+
Label: part("label", "label"),
|
|
59
|
+
/** An `<input>`; `as="textarea"` or `as="select"` for another. */
|
|
60
|
+
Control: part("control", "input"),
|
|
61
|
+
Description: part("description", "p"),
|
|
62
|
+
Error: FieldError,
|
|
63
|
+
Validity,
|
|
64
|
+
};
|
package/src/fieldset.jsx
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { createFieldset } from "@kirana-ui/core/fieldset";
|
|
2
|
+
import { createContext, createUniqueId, splitProps, useContext } from "solid-js";
|
|
3
|
+
import { Part, controller } from "./runtime.jsx";
|
|
4
|
+
/** The fieldset a field is in, if it is in one. */
|
|
5
|
+
export const FieldsetContext = createContext();
|
|
6
|
+
function useFieldset() {
|
|
7
|
+
const made = useContext(FieldsetContext);
|
|
8
|
+
if (!made)
|
|
9
|
+
throw new Error("A Fieldset part must be inside <Fieldset.Root>");
|
|
10
|
+
return made;
|
|
11
|
+
}
|
|
12
|
+
function Root(props) {
|
|
13
|
+
const [local, rest] = splitProps(props, ["disabled", "id"]);
|
|
14
|
+
const generated = createUniqueId();
|
|
15
|
+
const made = controller(createFieldset, () => ({
|
|
16
|
+
id: local.id ?? generated,
|
|
17
|
+
disabled: local.disabled,
|
|
18
|
+
}));
|
|
19
|
+
return (<FieldsetContext.Provider value={made}>
|
|
20
|
+
<Part part={made.root} tag="fieldset" {...rest}/>
|
|
21
|
+
</FieldsetContext.Provider>);
|
|
22
|
+
}
|
|
23
|
+
const Legend = (props) => (<Part part={useFieldset().legend} tag="div" {...props}/>);
|
|
24
|
+
export const Fieldset = { Root, Legend };
|
package/src/form.jsx
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { createForm } from "@kirana-ui/core/form";
|
|
2
|
+
import { createContext, splitProps } from "solid-js";
|
|
3
|
+
import { Part, controller } from "./runtime.jsx";
|
|
4
|
+
/** The form a field is in, if it is in one. */
|
|
5
|
+
export const FormContext = createContext();
|
|
6
|
+
/** A `<form>` whose fields say what is wrong; `onFormSubmit` takes the values once all are valid. */
|
|
7
|
+
export function Form(props) {
|
|
8
|
+
const [local, rest] = splitProps(props, [
|
|
9
|
+
"errors",
|
|
10
|
+
"onClearErrors",
|
|
11
|
+
"onFormSubmit",
|
|
12
|
+
"validationMode",
|
|
13
|
+
]);
|
|
14
|
+
const made = controller(createForm, () => ({
|
|
15
|
+
errors: local.errors,
|
|
16
|
+
validationMode: local.validationMode,
|
|
17
|
+
// Only when the caller takes the values: without it the form submits as a form does.
|
|
18
|
+
onFormSubmit: local.onFormSubmit
|
|
19
|
+
? (values, details) => local.onFormSubmit?.(values, details)
|
|
20
|
+
: undefined,
|
|
21
|
+
onClearErrors: (errors) => local.onClearErrors?.(errors),
|
|
22
|
+
}));
|
|
23
|
+
return (<FormContext.Provider value={made}>
|
|
24
|
+
<Part part={made.root} tag="form" {...rest}/>
|
|
25
|
+
</FormContext.Provider>);
|
|
26
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { createContext, createUniqueId, useContext } from "solid-js";
|
|
2
|
+
import { positioned } from "./popover.jsx";
|
|
3
|
+
import { Part, Portal as BodyPortal, controller } from "./runtime.jsx";
|
|
4
|
+
/** The parts of a popup the pointer opens: a tooltip's, a hover card's. */
|
|
5
|
+
export function hoverPopup(name, create, triggerTag) {
|
|
6
|
+
const Context = createContext();
|
|
7
|
+
function use() {
|
|
8
|
+
const made = useContext(Context);
|
|
9
|
+
if (!made)
|
|
10
|
+
throw new Error(`A ${name} part must be inside <${name}.Root>`);
|
|
11
|
+
return made;
|
|
12
|
+
}
|
|
13
|
+
function Root(props) {
|
|
14
|
+
const generated = createUniqueId();
|
|
15
|
+
const made = controller(create, () => ({
|
|
16
|
+
id: props.id ?? generated,
|
|
17
|
+
open: props.open,
|
|
18
|
+
defaultOpen: props.defaultOpen,
|
|
19
|
+
delay: props.delay,
|
|
20
|
+
closeDelay: props.closeDelay,
|
|
21
|
+
disabled: props.disabled,
|
|
22
|
+
onOpenChange: (open, details) => props.onOpenChange?.(open, details),
|
|
23
|
+
}));
|
|
24
|
+
return <Context.Provider value={made}>{props.children}</Context.Provider>;
|
|
25
|
+
}
|
|
26
|
+
const Portal = (props) => (<BodyPortal mounted={use().mounted}>{props.children}</BodyPortal>);
|
|
27
|
+
function Positioner(props) {
|
|
28
|
+
const made = use();
|
|
29
|
+
return <Part part={made.positioner} tag="div" {...positioned(props, made.positioning)}/>;
|
|
30
|
+
}
|
|
31
|
+
const part = (key, tag) => (props) => (<Part part={use()[key]} tag={tag} {...props}/>);
|
|
32
|
+
return {
|
|
33
|
+
Root,
|
|
34
|
+
Portal,
|
|
35
|
+
Positioner,
|
|
36
|
+
Trigger: part("trigger", triggerTag),
|
|
37
|
+
Popup: part("popup", "div"),
|
|
38
|
+
Arrow: part("arrow", "div"),
|
|
39
|
+
};
|
|
40
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export { Accordion } from "./accordion.jsx";
|
|
2
|
+
export { Checkbox } from "./checkbox.jsx";
|
|
3
|
+
export { Collapsible } from "./collapsible.jsx";
|
|
4
|
+
export { AlertDialog, Dialog } from "./dialog.jsx";
|
|
5
|
+
export { HoverCard } from "./hover-card.jsx";
|
|
6
|
+
export { Popover } from "./popover.jsx";
|
|
7
|
+
export { RadioGroup } from "./radio-group.jsx";
|
|
8
|
+
export { Select } from "./select.jsx";
|
|
9
|
+
export { Switch } from "./switch.jsx";
|
|
10
|
+
export { Tabs } from "./tabs.jsx";
|
|
11
|
+
export { Tooltip } from "./tooltip.jsx";
|
|
12
|
+
export { Avatar } from "./avatar.jsx";
|
|
13
|
+
export { Button } from "./button.jsx";
|
|
14
|
+
export { Meter } from "./meter.jsx";
|
|
15
|
+
export { Progress } from "./progress.jsx";
|
|
16
|
+
export { Separator } from "./separator.jsx";
|
|
17
|
+
export { Toggle } from "./toggle.jsx";
|
|
18
|
+
export { Slider } from "./slider.jsx";
|
|
19
|
+
export { Field } from "./field.jsx";
|
|
20
|
+
export { Fieldset } from "./fieldset.jsx";
|
|
21
|
+
export { Form } from "./form.jsx";
|
|
22
|
+
export { DirectionProvider, useDirection } from "./direction.jsx";
|
package/src/meter.jsx
ADDED
package/src/popover.jsx
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { defined } from "@kirana-ui/core";
|
|
2
|
+
import { createPopover } from "@kirana-ui/core/popover";
|
|
3
|
+
import { createComputed, createContext, createUniqueId, splitProps, useContext } from "solid-js";
|
|
4
|
+
import { Part, Portal as BodyPortal, controller } from "./runtime.jsx";
|
|
5
|
+
const Context = createContext();
|
|
6
|
+
function usePopover() {
|
|
7
|
+
const made = useContext(Context);
|
|
8
|
+
if (!made)
|
|
9
|
+
throw new Error("A Popover part must be inside <Popover.Root>");
|
|
10
|
+
return made;
|
|
11
|
+
}
|
|
12
|
+
function Root(props) {
|
|
13
|
+
const generated = createUniqueId();
|
|
14
|
+
const made = controller(createPopover, () => ({
|
|
15
|
+
id: props.id ?? generated,
|
|
16
|
+
open: props.open,
|
|
17
|
+
defaultOpen: props.defaultOpen,
|
|
18
|
+
onOpenChange: (open, details) => props.onOpenChange?.(open, details),
|
|
19
|
+
}));
|
|
20
|
+
return <Context.Provider value={made}>{props.children}</Context.Provider>;
|
|
21
|
+
}
|
|
22
|
+
const Portal = (props) => (<BodyPortal mounted={usePopover().mounted}>{props.children}</BodyPortal>);
|
|
23
|
+
/** A positioner's own props, written where its placement reads them, before its element attaches. */
|
|
24
|
+
export function positioned(props, positioning) {
|
|
25
|
+
const [local, rest] = splitProps(props, [
|
|
26
|
+
"side",
|
|
27
|
+
"align",
|
|
28
|
+
"sideOffset",
|
|
29
|
+
"alignOffset",
|
|
30
|
+
"collisionPadding",
|
|
31
|
+
]);
|
|
32
|
+
createComputed(() => positioning.set(defined({ ...local })));
|
|
33
|
+
return rest;
|
|
34
|
+
}
|
|
35
|
+
function Positioner(props) {
|
|
36
|
+
const made = usePopover();
|
|
37
|
+
return <Part part={made.positioner} tag="div" {...positioned(props, made.positioning)}/>;
|
|
38
|
+
}
|
|
39
|
+
const part = (name, tag) => (props) => <Part part={usePopover()[name]} tag={tag} {...props}/>;
|
|
40
|
+
export const Popover = {
|
|
41
|
+
Root,
|
|
42
|
+
Portal,
|
|
43
|
+
Positioner,
|
|
44
|
+
Trigger: part("trigger", "button"),
|
|
45
|
+
Popup: part("popup", "div"),
|
|
46
|
+
Title: part("title", "h2"),
|
|
47
|
+
Description: part("description", "p"),
|
|
48
|
+
Close: part("close", "button"),
|
|
49
|
+
};
|
package/src/progress.jsx
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { defined, within } from "@kirana-ui/core";
|
|
2
|
+
import { createRadioGroup } from "@kirana-ui/core/radio-group";
|
|
3
|
+
import { Show, createContext, createUniqueId, onCleanup, onMount, splitProps, untrack, useContext, } from "solid-js";
|
|
4
|
+
import { DirectionContext } from "./direction-context.js";
|
|
5
|
+
import { FieldContext } from "./field-context.js";
|
|
6
|
+
import { Part, controller, fromSignal, toSignal } from "./runtime.jsx";
|
|
7
|
+
const Context = createContext();
|
|
8
|
+
const ItemContext = createContext();
|
|
9
|
+
function useRadioGroup() {
|
|
10
|
+
const made = useContext(Context);
|
|
11
|
+
if (!made)
|
|
12
|
+
throw new Error("A RadioGroup part must be inside <RadioGroup.Root>");
|
|
13
|
+
return made;
|
|
14
|
+
}
|
|
15
|
+
function Root(props) {
|
|
16
|
+
const [local, rest] = splitProps(props, [
|
|
17
|
+
"value",
|
|
18
|
+
"defaultValue",
|
|
19
|
+
"onValueChange",
|
|
20
|
+
"disabled",
|
|
21
|
+
"readOnly",
|
|
22
|
+
"required",
|
|
23
|
+
"name",
|
|
24
|
+
"id",
|
|
25
|
+
]);
|
|
26
|
+
const generated = createUniqueId();
|
|
27
|
+
const field = useContext(FieldContext);
|
|
28
|
+
const made = controller(within(createRadioGroup, { field, direction: useContext(DirectionContext) }), () => ({
|
|
29
|
+
id: local.id ?? generated,
|
|
30
|
+
value: local.value,
|
|
31
|
+
defaultValue: local.defaultValue,
|
|
32
|
+
disabled: local.disabled,
|
|
33
|
+
readOnly: local.readOnly,
|
|
34
|
+
required: local.required,
|
|
35
|
+
name: local.name,
|
|
36
|
+
onValueChange: (value, details) => local.onValueChange?.(value, details),
|
|
37
|
+
}));
|
|
38
|
+
return (<Context.Provider value={made}>
|
|
39
|
+
<Part part={made.root} tag="div" {...rest}/>
|
|
40
|
+
</Context.Provider>);
|
|
41
|
+
}
|
|
42
|
+
function Item(props) {
|
|
43
|
+
const [local, rest] = splitProps(props, ["value", "disabled", "children"]);
|
|
44
|
+
// An item is its value for as long as it is in the page.
|
|
45
|
+
const value = untrack(() => local.value);
|
|
46
|
+
const options = toSignal(() => ({ disabled: local.disabled }));
|
|
47
|
+
const read = () => defined(options.get());
|
|
48
|
+
const group = useRadioGroup();
|
|
49
|
+
return (<ItemContext.Provider value={value}>
|
|
50
|
+
<Part part={group.item(value, read)} tag="span" {...rest}>
|
|
51
|
+
{local.children}
|
|
52
|
+
<Part part={group.itemInput(value, read)} tag="input"/>
|
|
53
|
+
</Part>
|
|
54
|
+
</ItemContext.Provider>);
|
|
55
|
+
}
|
|
56
|
+
/** `keepMounted` keeps the mark in the page while its item is not the chosen one. */
|
|
57
|
+
function Indicator(props) {
|
|
58
|
+
const [local, rest] = splitProps(props, ["keepMounted"]);
|
|
59
|
+
const indicator = useRadioGroup().indicator(useContext(ItemContext));
|
|
60
|
+
onMount(() => onCleanup(indicator.mount()));
|
|
61
|
+
const mounted = fromSignal(indicator.mounted);
|
|
62
|
+
return (<Show when={mounted() || local.keepMounted}>
|
|
63
|
+
<Part part={indicator.part} tag="span" {...rest}/>
|
|
64
|
+
</Show>);
|
|
65
|
+
}
|
|
66
|
+
export const RadioGroup = { Root, Item, Indicator };
|
package/src/runtime.jsx
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { mergeProps, sameProps, signal } from "@kirana-ui/core";
|
|
2
|
+
import { Show, createComputed, createMemo, createSignal, getOwner, onCleanup, onMount, runWithOwner, splitProps, untrack, } from "solid-js";
|
|
3
|
+
import { Dynamic, Portal as SolidPortal, isServer } from "solid-js/web";
|
|
4
|
+
/** A core signal as a Solid accessor: tracked by whatever calls it. */
|
|
5
|
+
export function fromSignal(source) {
|
|
6
|
+
const [read, write] = createSignal(source.peek(), { equals: false });
|
|
7
|
+
if (!isServer)
|
|
8
|
+
onCleanup(source.subscribe(() => write(() => source.peek())));
|
|
9
|
+
return read;
|
|
10
|
+
}
|
|
11
|
+
/** A core signal that follows Solid state: the core hears a changed prop before anything renders. */
|
|
12
|
+
export function toSignal(read) {
|
|
13
|
+
const source = signal(untrack(read), sameProps);
|
|
14
|
+
createComputed(() => source.set(read()));
|
|
15
|
+
return source;
|
|
16
|
+
}
|
|
17
|
+
/** A component's controller, made once, following its props. */
|
|
18
|
+
export function controller(create, read) {
|
|
19
|
+
const made = create(toSignal(read));
|
|
20
|
+
onMount(() => onCleanup(made.mount()));
|
|
21
|
+
return made;
|
|
22
|
+
}
|
|
23
|
+
// HTML's boolean attributes, which Solid sets as properties: a part's `""` means "present".
|
|
24
|
+
const BOOLEAN = new Set([
|
|
25
|
+
"hidden",
|
|
26
|
+
"disabled",
|
|
27
|
+
"inert",
|
|
28
|
+
"required",
|
|
29
|
+
"readonly",
|
|
30
|
+
"multiple",
|
|
31
|
+
"checked",
|
|
32
|
+
"novalidate",
|
|
33
|
+
]);
|
|
34
|
+
function toSolid(props) {
|
|
35
|
+
const out = {};
|
|
36
|
+
for (const key in props) {
|
|
37
|
+
const value = props[key];
|
|
38
|
+
// Solid's `onFocus` and `onBlur` do not bubble; the core's are the ones that do.
|
|
39
|
+
if (key === "onFocus")
|
|
40
|
+
out.onFocusIn = value;
|
|
41
|
+
else if (key === "onBlur")
|
|
42
|
+
out.onFocusOut = value;
|
|
43
|
+
else
|
|
44
|
+
out[key] = BOOLEAN.has(key) ? value === "" || value === true : value;
|
|
45
|
+
}
|
|
46
|
+
return out;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* A part's element (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.
|
|
51
|
+
*/
|
|
52
|
+
export function Part(props) {
|
|
53
|
+
const [local, caller] = splitProps(props, ["part", "tag", "as", "render", "children"]);
|
|
54
|
+
const own = fromSignal(untrack(() => local.part).props);
|
|
55
|
+
// Solid hands over an element before it is in the page: the part's DOM work (focus, measures,
|
|
56
|
+
// the starting style) waits for the mount that follows. It belongs to this component, not to
|
|
57
|
+
// the effect that spreads the props (which hands the ref over again, and is torn down, each time
|
|
58
|
+
// they change): attached once per element, detached when the component goes.
|
|
59
|
+
const owner = getOwner();
|
|
60
|
+
let attached;
|
|
61
|
+
const attach = (element) => {
|
|
62
|
+
if (element === attached)
|
|
63
|
+
return;
|
|
64
|
+
attached = element;
|
|
65
|
+
const part = untrack(() => local.part);
|
|
66
|
+
runWithOwner(owner, () => onMount(() => onCleanup(part.attach(element))));
|
|
67
|
+
};
|
|
68
|
+
const merged = createMemo(() => {
|
|
69
|
+
const theirs = {};
|
|
70
|
+
for (const key of Object.keys(caller))
|
|
71
|
+
theirs[key] = caller[key];
|
|
72
|
+
return { ...mergeProps(theirs, toSolid(own())), ref: attach };
|
|
73
|
+
});
|
|
74
|
+
return (<Show when={local.render} fallback={<Dynamic component={local.as ?? local.tag} {...merged()}>
|
|
75
|
+
{local.children}
|
|
76
|
+
</Dynamic>}>
|
|
77
|
+
{(render) => render()(merged)}
|
|
78
|
+
</Show>);
|
|
79
|
+
}
|
|
80
|
+
/** Its children in a container at the end of the page, while `mounted`. */
|
|
81
|
+
export function Portal(props) {
|
|
82
|
+
const shown = fromSignal(untrack(() => props.mounted));
|
|
83
|
+
return (<Show when={shown()}>
|
|
84
|
+
<SolidPortal ref={(container) => container.setAttribute("data-kirana-portal", "")}>
|
|
85
|
+
{props.children}
|
|
86
|
+
</SolidPortal>
|
|
87
|
+
</Show>);
|
|
88
|
+
}
|