@kirana-ui/solid 0.0.0 → 0.1.1
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/autocomplete.js +2 -0
- package/dom/autosize.js +19 -0
- package/dom/avatar.js +68 -0
- package/dom/button.js +18 -0
- package/dom/calendar.js +141 -0
- package/dom/carousel.js +83 -0
- package/dom/checkbox.js +77 -0
- package/dom/collapsible.js +64 -0
- package/dom/combobox.js +281 -0
- package/dom/command.js +129 -0
- package/dom/context-menu.js +2 -0
- package/dom/date-field.js +86 -0
- package/dom/date-picker.js +103 -0
- package/dom/dialog.js +101 -0
- package/dom/direction-context.js +3 -0
- package/dom/direction.js +27 -0
- package/dom/drawer.js +2 -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 +78 -0
- package/dom/index.js +47 -0
- package/dom/input.js +26 -0
- package/dom/label.js +18 -0
- package/dom/listbox.js +114 -0
- package/dom/menu.js +261 -0
- package/dom/menubar-context.js +3 -0
- package/dom/menubar.js +33 -0
- package/dom/message-scroller.js +56 -0
- package/dom/meter.js +3 -0
- package/dom/navigation-menu.js +150 -0
- package/dom/number-field.js +82 -0
- package/dom/otp.js +95 -0
- package/dom/pagination.js +74 -0
- package/dom/popover.js +70 -0
- package/dom/progress.js +3 -0
- package/dom/qr-code.js +48 -0
- package/dom/radio-group.js +101 -0
- package/dom/resizable.js +65 -0
- package/dom/runtime.js +133 -0
- package/dom/scroll-area.js +99 -0
- package/dom/select.js +213 -0
- package/dom/separator.js +17 -0
- package/dom/slider.js +93 -0
- package/dom/switch.js +63 -0
- package/dom/tabs.js +97 -0
- package/dom/toast.js +113 -0
- package/dom/toggle-group.js +37 -0
- package/dom/toggle.js +28 -0
- package/dom/toolbar-context.js +5 -0
- package/dom/toolbar.js +71 -0
- package/dom/tooltip.js +3 -0
- package/dom/value-bar.js +62 -0
- package/llms.txt +1838 -0
- package/package.json +437 -6
- package/server/accordion.js +106 -0
- package/server/alert-dialog.js +2 -0
- package/server/autocomplete.js +2 -0
- package/server/autosize.js +19 -0
- package/server/avatar.js +68 -0
- package/server/button.js +18 -0
- package/server/calendar.js +140 -0
- package/server/carousel.js +83 -0
- package/server/checkbox.js +77 -0
- package/server/collapsible.js +64 -0
- package/server/combobox.js +281 -0
- package/server/command.js +129 -0
- package/server/context-menu.js +2 -0
- package/server/date-field.js +86 -0
- package/server/date-picker.js +103 -0
- package/server/dialog.js +101 -0
- package/server/direction-context.js +3 -0
- package/server/direction.js +27 -0
- package/server/drawer.js +2 -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 +78 -0
- package/server/index.js +47 -0
- package/server/input.js +26 -0
- package/server/label.js +18 -0
- package/server/listbox.js +114 -0
- package/server/menu.js +261 -0
- package/server/menubar-context.js +3 -0
- package/server/menubar.js +33 -0
- package/server/message-scroller.js +56 -0
- package/server/meter.js +3 -0
- package/server/navigation-menu.js +144 -0
- package/server/number-field.js +81 -0
- package/server/otp.js +94 -0
- package/server/pagination.js +74 -0
- package/server/popover.js +70 -0
- package/server/progress.js +3 -0
- package/server/qr-code.js +48 -0
- package/server/radio-group.js +101 -0
- package/server/resizable.js +65 -0
- package/server/runtime.js +132 -0
- package/server/scroll-area.js +99 -0
- package/server/select.js +213 -0
- package/server/separator.js +17 -0
- package/server/slider.js +92 -0
- package/server/switch.js +62 -0
- package/server/tabs.js +97 -0
- package/server/toast.js +113 -0
- package/server/toggle-group.js +37 -0
- package/server/toggle.js +28 -0
- package/server/toolbar-context.js +5 -0
- package/server/toolbar.js +71 -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/autocomplete.jsx +2 -0
- package/src/autosize.jsx +8 -0
- package/src/avatar.jsx +35 -0
- package/src/button.jsx +9 -0
- package/src/calendar.jsx +104 -0
- package/src/carousel.jsx +51 -0
- package/src/checkbox.jsx +59 -0
- package/src/collapsible.jsx +35 -0
- package/src/combobox.jsx +179 -0
- package/src/command.jsx +81 -0
- package/src/context-menu.js +2 -0
- package/src/date-field.jsx +67 -0
- package/src/date-picker.jsx +72 -0
- package/src/dialog.jsx +67 -0
- package/src/direction-context.js +3 -0
- package/src/direction.jsx +17 -0
- package/src/drawer.js +2 -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 +48 -0
- package/src/index.js +47 -0
- package/src/input.jsx +17 -0
- package/src/label.jsx +9 -0
- package/src/listbox.jsx +81 -0
- package/src/menu.jsx +164 -0
- package/src/menubar-context.js +3 -0
- package/src/menubar.jsx +21 -0
- package/src/message-scroller.jsx +27 -0
- package/src/meter.jsx +3 -0
- package/src/navigation-menu.jsx +95 -0
- package/src/number-field.jsx +75 -0
- package/src/otp.jsx +73 -0
- package/src/pagination.jsx +60 -0
- package/src/popover.jsx +51 -0
- package/src/progress.jsx +3 -0
- package/src/qr-code.jsx +25 -0
- package/src/radio-group.jsx +68 -0
- package/src/resizable.jsx +46 -0
- package/src/runtime.jsx +119 -0
- package/src/scroll-area.jsx +53 -0
- package/src/select.jsx +129 -0
- package/src/separator.jsx +8 -0
- package/src/slider.jsx +76 -0
- package/src/switch.jsx +49 -0
- package/src/tabs.jsx +58 -0
- package/src/toast.jsx +58 -0
- package/src/toggle-group.jsx +32 -0
- package/src/toggle.jsx +24 -0
- package/src/toolbar-context.js +5 -0
- package/src/toolbar.jsx +43 -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/autocomplete.d.ts +1 -0
- package/types/autosize.d.ts +8 -0
- package/types/avatar.d.ts +15 -0
- package/types/button.d.ts +9 -0
- package/types/calendar.d.ts +40 -0
- package/types/carousel.d.ts +26 -0
- package/types/checkbox.d.ts +26 -0
- package/types/collapsible.d.ts +21 -0
- package/types/combobox.d.ts +106 -0
- package/types/command.d.ts +45 -0
- package/types/context-menu.d.ts +1 -0
- package/types/date-field.d.ts +23 -0
- package/types/date-picker.d.ts +49 -0
- package/types/dialog.d.ts +61 -0
- package/types/direction-context.d.ts +3 -0
- package/types/direction.d.ts +14 -0
- package/types/drawer.d.ts +1 -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 +13 -0
- package/types/hover-popup.d.ts +29 -0
- package/types/index.d.ts +50 -0
- package/types/input.d.ts +12 -0
- package/types/label.d.ts +4 -0
- package/types/listbox.d.ts +38 -0
- package/types/menu.d.ts +91 -0
- package/types/menubar-context.d.ts +3 -0
- package/types/menubar.d.ts +10 -0
- package/types/message-scroller.d.ts +16 -0
- package/types/meter.d.ts +9 -0
- package/types/navigation-menu.d.ts +44 -0
- package/types/number-field.d.ts +15 -0
- package/types/otp.d.ts +32 -0
- package/types/pagination.d.ts +23 -0
- package/types/popover.d.ts +31 -0
- package/types/progress.d.ts +9 -0
- package/types/qr-code.d.ts +14 -0
- package/types/radio-group.d.ts +29 -0
- package/types/resizable.d.ts +24 -0
- package/types/runtime.d.ts +49 -0
- package/types/scroll-area.d.ts +20 -0
- package/types/select.d.ts +74 -0
- package/types/separator.d.ts +6 -0
- package/types/slider.d.ts +24 -0
- package/types/switch.d.ts +21 -0
- package/types/tabs.d.ts +32 -0
- package/types/toast.d.ts +33 -0
- package/types/toggle-group.d.ts +14 -0
- package/types/toggle.d.ts +12 -0
- package/types/toolbar-context.d.ts +6 -0
- package/types/toolbar.d.ts +23 -0
- package/types/tooltip.d.ts +13 -0
- package/types/value-bar.d.ts +17 -0
- package/README.md +0 -7
- package/index.js +0 -5
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { createComponent as _$createComponent } from "solid-js/web";
|
|
2
|
+
import { mergeProps as _$mergeProps } from "solid-js/web";
|
|
3
|
+
import { createCommand } from "@kirana-ui/core/command";
|
|
4
|
+
import { Show, createContext, createUniqueId, splitProps, untrack, useContext } from "solid-js";
|
|
5
|
+
import { Part, controller, fromSignal, toSignal } from "./runtime.js";
|
|
6
|
+
const Context = createContext();
|
|
7
|
+
const GroupContext = createContext();
|
|
8
|
+
function useCommand() {
|
|
9
|
+
const made = useContext(Context);
|
|
10
|
+
if (!made) throw new Error("A Command part must be inside <Command.Root>");
|
|
11
|
+
return made;
|
|
12
|
+
}
|
|
13
|
+
function Root(props) {
|
|
14
|
+
const [local, rest] = splitProps(props, ["inputValue", "defaultInputValue", "onInputValueChange", "onSelect", "filter", "loop", "disabled", "id"]);
|
|
15
|
+
const generated = createUniqueId();
|
|
16
|
+
const made = controller(createCommand, () => ({
|
|
17
|
+
id: local.id ?? generated,
|
|
18
|
+
inputValue: local.inputValue,
|
|
19
|
+
defaultInputValue: local.defaultInputValue,
|
|
20
|
+
filter: local.filter,
|
|
21
|
+
loop: local.loop,
|
|
22
|
+
disabled: local.disabled,
|
|
23
|
+
onInputValueChange: (value, details) => local.onInputValueChange?.(value, details),
|
|
24
|
+
onSelect: (value, details) => local.onSelect?.(value, details)
|
|
25
|
+
}));
|
|
26
|
+
return _$createComponent(Context.Provider, {
|
|
27
|
+
value: made,
|
|
28
|
+
get children() {
|
|
29
|
+
return _$createComponent(Part, _$mergeProps({
|
|
30
|
+
get part() {
|
|
31
|
+
return made.root;
|
|
32
|
+
},
|
|
33
|
+
tag: "div"
|
|
34
|
+
}, rest));
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
const Input = props => _$createComponent(Part, _$mergeProps({
|
|
39
|
+
get part() {
|
|
40
|
+
return useCommand().input;
|
|
41
|
+
},
|
|
42
|
+
tag: "input"
|
|
43
|
+
}, props));
|
|
44
|
+
const List = props => _$createComponent(Part, _$mergeProps({
|
|
45
|
+
get part() {
|
|
46
|
+
return useCommand().list;
|
|
47
|
+
},
|
|
48
|
+
tag: "div"
|
|
49
|
+
}, props));
|
|
50
|
+
/** Drawn while no item is shown for what was typed. */
|
|
51
|
+
function Empty(props) {
|
|
52
|
+
const made = useCommand();
|
|
53
|
+
const empty = fromSignal(made.empty);
|
|
54
|
+
return _$createComponent(Show, {
|
|
55
|
+
get when() {
|
|
56
|
+
return empty();
|
|
57
|
+
},
|
|
58
|
+
get children() {
|
|
59
|
+
return _$createComponent(Part, _$mergeProps({
|
|
60
|
+
get part() {
|
|
61
|
+
return made.emptyPart;
|
|
62
|
+
},
|
|
63
|
+
tag: "div"
|
|
64
|
+
}, props));
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
/** Items under a `<Command.GroupHeading>`. Hidden while none of them is shown. */
|
|
69
|
+
function Group(props) {
|
|
70
|
+
const [local, rest] = splitProps(props, ["id"]);
|
|
71
|
+
const generated = createUniqueId();
|
|
72
|
+
const group = useCommand().group(untrack(() => local.id) ?? generated);
|
|
73
|
+
return _$createComponent(GroupContext.Provider, {
|
|
74
|
+
value: group,
|
|
75
|
+
get children() {
|
|
76
|
+
return _$createComponent(Part, _$mergeProps({
|
|
77
|
+
get part() {
|
|
78
|
+
return group.part;
|
|
79
|
+
},
|
|
80
|
+
tag: "div"
|
|
81
|
+
}, rest));
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
function GroupHeading(props) {
|
|
86
|
+
const part = useContext(GroupContext)?.heading ?? useCommand().heading;
|
|
87
|
+
return _$createComponent(Part, _$mergeProps({
|
|
88
|
+
part: part,
|
|
89
|
+
tag: "div"
|
|
90
|
+
}, props));
|
|
91
|
+
}
|
|
92
|
+
/** `label` is what is filtered, the item's text when left out; `keywords` are other words for it. */
|
|
93
|
+
function Item(props) {
|
|
94
|
+
const [local, rest] = splitProps(props, ["value", "disabled", "label", "keywords", "id"]);
|
|
95
|
+
const generated = createUniqueId();
|
|
96
|
+
const options = toSignal(() => ({
|
|
97
|
+
disabled: local.disabled,
|
|
98
|
+
label: local.label,
|
|
99
|
+
keywords: local.keywords,
|
|
100
|
+
id: local.id ?? generated
|
|
101
|
+
}));
|
|
102
|
+
const part = useCommand().item(untrack(() => local.value), () => options.get(), useContext(GroupContext));
|
|
103
|
+
return _$createComponent(Part, _$mergeProps({
|
|
104
|
+
part: part,
|
|
105
|
+
tag: "div"
|
|
106
|
+
}, rest));
|
|
107
|
+
}
|
|
108
|
+
/** A line between groups: gone while something is typed, unless `alwaysRender`. */
|
|
109
|
+
function Separator(props) {
|
|
110
|
+
const [local, rest] = splitProps(props, ["alwaysRender"]);
|
|
111
|
+
const options = toSignal(() => ({
|
|
112
|
+
alwaysRender: local.alwaysRender
|
|
113
|
+
}));
|
|
114
|
+
const part = useCommand().separator(() => options.get().alwaysRender);
|
|
115
|
+
return _$createComponent(Part, _$mergeProps({
|
|
116
|
+
part: part,
|
|
117
|
+
tag: "div"
|
|
118
|
+
}, rest));
|
|
119
|
+
}
|
|
120
|
+
export const Command = {
|
|
121
|
+
Root,
|
|
122
|
+
Input,
|
|
123
|
+
List,
|
|
124
|
+
Empty,
|
|
125
|
+
Group,
|
|
126
|
+
GroupHeading,
|
|
127
|
+
Item,
|
|
128
|
+
Separator
|
|
129
|
+
};
|
|
@@ -0,0 +1,86 @@
|
|
|
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 { createDateField } from "@kirana-ui/core/date-field";
|
|
5
|
+
import { For, createContext, createUniqueId, splitProps, useContext } from "solid-js";
|
|
6
|
+
import { DirectionContext } from "./direction-context.js";
|
|
7
|
+
import { Part, controller, fromSignal } from "./runtime.js";
|
|
8
|
+
const Context = createContext();
|
|
9
|
+
/** For a component made of this one's parts: a date picker. */
|
|
10
|
+
export { Context as DateFieldContext };
|
|
11
|
+
function useDateField() {
|
|
12
|
+
const made = useContext(Context);
|
|
13
|
+
if (!made) throw new Error("A DateField part must be inside <DateField.Root>");
|
|
14
|
+
return made;
|
|
15
|
+
}
|
|
16
|
+
function Root(props) {
|
|
17
|
+
const [local, rest] = splitProps(props, ["value", "defaultValue", "onValueChange", "locale", "min", "max", "placeholders", "disabled", "readOnly", "required", "name", "form", "id"]);
|
|
18
|
+
const generated = createUniqueId();
|
|
19
|
+
const direction = useContext(DirectionContext);
|
|
20
|
+
const made = controller(within(createDateField, {
|
|
21
|
+
direction
|
|
22
|
+
}), () => ({
|
|
23
|
+
id: local.id ?? generated,
|
|
24
|
+
value: local.value,
|
|
25
|
+
defaultValue: local.defaultValue,
|
|
26
|
+
locale: local.locale,
|
|
27
|
+
min: local.min,
|
|
28
|
+
max: local.max,
|
|
29
|
+
placeholders: local.placeholders,
|
|
30
|
+
disabled: local.disabled,
|
|
31
|
+
readOnly: local.readOnly,
|
|
32
|
+
required: local.required,
|
|
33
|
+
name: local.name,
|
|
34
|
+
form: local.form,
|
|
35
|
+
onValueChange: (value, details) => local.onValueChange?.(value, details)
|
|
36
|
+
}));
|
|
37
|
+
return _$createComponent(Context.Provider, {
|
|
38
|
+
value: made,
|
|
39
|
+
get children() {
|
|
40
|
+
return _$createComponent(Part, _$mergeProps({
|
|
41
|
+
get part() {
|
|
42
|
+
return made.root;
|
|
43
|
+
},
|
|
44
|
+
tag: "div"
|
|
45
|
+
}, rest));
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
/** Draws its child once for each piece of the date, in the locale's order. */
|
|
50
|
+
function Segments(props) {
|
|
51
|
+
const segments = fromSignal(useDateField().segments);
|
|
52
|
+
return _$createComponent(For, {
|
|
53
|
+
get each() {
|
|
54
|
+
return segments();
|
|
55
|
+
},
|
|
56
|
+
children: segment => props.children(segment)
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
/** One piece: a part that is typed, or what stands between two. It writes its own text. */
|
|
60
|
+
function Segment(props) {
|
|
61
|
+
const [local, rest] = splitProps(props, ["segment"]);
|
|
62
|
+
const made = useDateField().segment(local.segment);
|
|
63
|
+
const shown = fromSignal(made.text);
|
|
64
|
+
return _$createComponent(Part, _$mergeProps({
|
|
65
|
+
get part() {
|
|
66
|
+
return made.part;
|
|
67
|
+
},
|
|
68
|
+
tag: "span"
|
|
69
|
+
}, rest, {
|
|
70
|
+
get children() {
|
|
71
|
+
return shown();
|
|
72
|
+
}
|
|
73
|
+
}));
|
|
74
|
+
}
|
|
75
|
+
const Input = props => _$createComponent(Part, _$mergeProps({
|
|
76
|
+
get part() {
|
|
77
|
+
return useDateField().input;
|
|
78
|
+
},
|
|
79
|
+
tag: "input"
|
|
80
|
+
}, props));
|
|
81
|
+
export const DateField = {
|
|
82
|
+
Root,
|
|
83
|
+
Segments,
|
|
84
|
+
Segment,
|
|
85
|
+
Input
|
|
86
|
+
};
|
|
@@ -0,0 +1,103 @@
|
|
|
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 { createDatePicker } from "@kirana-ui/core/date-picker";
|
|
5
|
+
import { createContext, createUniqueId, useContext } from "solid-js";
|
|
6
|
+
import { Calendar, CalendarContext } from "./calendar.js";
|
|
7
|
+
import { DateField, DateFieldContext } from "./date-field.js";
|
|
8
|
+
import { DirectionContext } from "./direction-context.js";
|
|
9
|
+
import { Popover, PopoverContext } from "./popover.js";
|
|
10
|
+
import { Part, controller } from "./runtime.js";
|
|
11
|
+
const Context = createContext();
|
|
12
|
+
function useDatePicker() {
|
|
13
|
+
const made = useContext(Context);
|
|
14
|
+
if (!made) throw new Error("A DatePicker part must be inside <DatePicker.Root>");
|
|
15
|
+
return made;
|
|
16
|
+
}
|
|
17
|
+
/** A date field, and a calendar in a popover, with one value between them. It draws nothing. */
|
|
18
|
+
function Root(props) {
|
|
19
|
+
const generated = createUniqueId();
|
|
20
|
+
const made = controller(within(createDatePicker, {
|
|
21
|
+
direction: useContext(DirectionContext)
|
|
22
|
+
}), () => ({
|
|
23
|
+
id: props.id ?? generated,
|
|
24
|
+
value: props.value,
|
|
25
|
+
defaultValue: props.defaultValue,
|
|
26
|
+
open: props.open,
|
|
27
|
+
defaultOpen: props.defaultOpen,
|
|
28
|
+
locale: props.locale,
|
|
29
|
+
min: props.min,
|
|
30
|
+
max: props.max,
|
|
31
|
+
isDateUnavailable: props.isDateUnavailable,
|
|
32
|
+
calendarSystem: props.calendarSystem,
|
|
33
|
+
fixedWeeks: props.fixedWeeks,
|
|
34
|
+
placeholders: props.placeholders,
|
|
35
|
+
disabled: props.disabled,
|
|
36
|
+
readOnly: props.readOnly,
|
|
37
|
+
required: props.required,
|
|
38
|
+
name: props.name,
|
|
39
|
+
form: props.form,
|
|
40
|
+
onValueChange: (value, details) => props.onValueChange?.(value, details),
|
|
41
|
+
onOpenChange: (open, details) => props.onOpenChange?.(open, details)
|
|
42
|
+
}));
|
|
43
|
+
return _$createComponent(Context.Provider, {
|
|
44
|
+
value: made,
|
|
45
|
+
get children() {
|
|
46
|
+
return _$createComponent(DateFieldContext.Provider, {
|
|
47
|
+
get value() {
|
|
48
|
+
return made.field;
|
|
49
|
+
},
|
|
50
|
+
get children() {
|
|
51
|
+
return _$createComponent(PopoverContext.Provider, {
|
|
52
|
+
get value() {
|
|
53
|
+
return made.popover;
|
|
54
|
+
},
|
|
55
|
+
get children() {
|
|
56
|
+
return _$createComponent(CalendarContext.Provider, {
|
|
57
|
+
get value() {
|
|
58
|
+
return made.calendar;
|
|
59
|
+
},
|
|
60
|
+
get children() {
|
|
61
|
+
return props.children;
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
export const DatePicker = {
|
|
72
|
+
Root,
|
|
73
|
+
/** The typed date: what holds its segments and its hidden input. */
|
|
74
|
+
Field: props => _$createComponent(Part, _$mergeProps({
|
|
75
|
+
get part() {
|
|
76
|
+
return useDatePicker().field.root;
|
|
77
|
+
},
|
|
78
|
+
tag: "div"
|
|
79
|
+
}, props)),
|
|
80
|
+
Segments: DateField.Segments,
|
|
81
|
+
Segment: DateField.Segment,
|
|
82
|
+
Input: DateField.Input,
|
|
83
|
+
Trigger: Popover.Trigger,
|
|
84
|
+
Portal: Popover.Portal,
|
|
85
|
+
Positioner: Popover.Positioner,
|
|
86
|
+
Popup: Popover.Popup,
|
|
87
|
+
/** The calendar: what holds its heading, its buttons and its grid. */
|
|
88
|
+
Calendar: props => _$createComponent(Part, _$mergeProps({
|
|
89
|
+
get part() {
|
|
90
|
+
return useDatePicker().calendar.root;
|
|
91
|
+
},
|
|
92
|
+
tag: "div"
|
|
93
|
+
}, props)),
|
|
94
|
+
Heading: Calendar.Heading,
|
|
95
|
+
Previous: Calendar.Previous,
|
|
96
|
+
Next: Calendar.Next,
|
|
97
|
+
Grid: Calendar.Grid,
|
|
98
|
+
Weekdays: Calendar.Weekdays,
|
|
99
|
+
HeadCell: Calendar.HeadCell,
|
|
100
|
+
Weeks: Calendar.Weeks,
|
|
101
|
+
Cell: Calendar.Cell,
|
|
102
|
+
Day: Calendar.Day
|
|
103
|
+
};
|
package/server/dialog.js
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { mergeProps as _$mergeProps } from "solid-js/web";
|
|
2
|
+
import { createComponent as _$createComponent } from "solid-js/web";
|
|
3
|
+
import { createAlertDialog } from "@kirana-ui/core/alert-dialog";
|
|
4
|
+
import { createDialog } from "@kirana-ui/core/dialog";
|
|
5
|
+
import { createDrawer } from "@kirana-ui/core/drawer";
|
|
6
|
+
import { createContext, createUniqueId, useContext } from "solid-js";
|
|
7
|
+
import { Part, Portal as BodyPortal, controller } from "./runtime.js";
|
|
8
|
+
const Context = createContext();
|
|
9
|
+
function useDialog() {
|
|
10
|
+
const made = useContext(Context);
|
|
11
|
+
if (!made) throw new Error("A Dialog part must be inside <Dialog.Root>");
|
|
12
|
+
return made;
|
|
13
|
+
}
|
|
14
|
+
function Root(props) {
|
|
15
|
+
const generated = createUniqueId();
|
|
16
|
+
const made = controller(createDialog, () => ({
|
|
17
|
+
id: props.id ?? generated,
|
|
18
|
+
open: props.open,
|
|
19
|
+
defaultOpen: props.defaultOpen,
|
|
20
|
+
modal: props.modal,
|
|
21
|
+
dismissible: props.dismissible,
|
|
22
|
+
onOpenChange: (open, details) => props.onOpenChange?.(open, details)
|
|
23
|
+
}));
|
|
24
|
+
return _$createComponent(Context.Provider, {
|
|
25
|
+
value: made,
|
|
26
|
+
get children() {
|
|
27
|
+
return props.children;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
const Portal = props => _$createComponent(BodyPortal, {
|
|
32
|
+
get mounted() {
|
|
33
|
+
return useDialog().mounted;
|
|
34
|
+
},
|
|
35
|
+
get children() {
|
|
36
|
+
return props.children;
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
const part = (name, tag) => props => _$createComponent(Part, _$mergeProps({
|
|
40
|
+
get part() {
|
|
41
|
+
return useDialog()[name];
|
|
42
|
+
},
|
|
43
|
+
tag: tag
|
|
44
|
+
}, props));
|
|
45
|
+
function AlertRoot(props) {
|
|
46
|
+
const generated = createUniqueId();
|
|
47
|
+
const made = controller(createAlertDialog, () => ({
|
|
48
|
+
id: props.id ?? generated,
|
|
49
|
+
open: props.open,
|
|
50
|
+
defaultOpen: props.defaultOpen,
|
|
51
|
+
onOpenChange: (open, details) => props.onOpenChange?.(open, details)
|
|
52
|
+
}));
|
|
53
|
+
return _$createComponent(Context.Provider, {
|
|
54
|
+
value: made,
|
|
55
|
+
get children() {
|
|
56
|
+
return props.children;
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
export const Dialog = {
|
|
61
|
+
Root,
|
|
62
|
+
Portal,
|
|
63
|
+
Trigger: part("trigger", "button"),
|
|
64
|
+
Backdrop: part("backdrop", "div"),
|
|
65
|
+
Popup: part("popup", "div"),
|
|
66
|
+
Title: part("title", "h2"),
|
|
67
|
+
Description: part("description", "p"),
|
|
68
|
+
Close: part("close", "button")
|
|
69
|
+
};
|
|
70
|
+
/** A dialog that asks for an answer: a press outside it does not close it. Its parts are a dialog's. */
|
|
71
|
+
export const AlertDialog = {
|
|
72
|
+
...Dialog,
|
|
73
|
+
Root: AlertRoot
|
|
74
|
+
};
|
|
75
|
+
function DrawerRoot(props) {
|
|
76
|
+
const generated = createUniqueId();
|
|
77
|
+
const made = controller(createDrawer, () => ({
|
|
78
|
+
id: props.id ?? generated,
|
|
79
|
+
open: props.open,
|
|
80
|
+
defaultOpen: props.defaultOpen,
|
|
81
|
+
modal: props.modal,
|
|
82
|
+
dismissible: props.dismissible,
|
|
83
|
+
swipeDirection: props.swipeDirection,
|
|
84
|
+
snapPoints: props.snapPoints,
|
|
85
|
+
snapPoint: props.snapPoint,
|
|
86
|
+
defaultSnapPoint: props.defaultSnapPoint,
|
|
87
|
+
onSnapPointChange: (snapPoint, details) => props.onSnapPointChange?.(snapPoint, details),
|
|
88
|
+
onOpenChange: (open, details) => props.onOpenChange?.(open, details)
|
|
89
|
+
}));
|
|
90
|
+
return _$createComponent(Context.Provider, {
|
|
91
|
+
value: made,
|
|
92
|
+
get children() {
|
|
93
|
+
return props.children;
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
/** A dialog that comes from an edge and is dragged back to it. Its parts are a dialog's. */
|
|
98
|
+
export const Drawer = {
|
|
99
|
+
...Dialog,
|
|
100
|
+
Root: DrawerRoot
|
|
101
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { createComponent as _$createComponent } from "solid-js/web";
|
|
2
|
+
import { signal } from "@kirana-ui/core";
|
|
3
|
+
import { createDirection } from "@kirana-ui/core/direction";
|
|
4
|
+
import { useContext } from "solid-js";
|
|
5
|
+
import { DirectionContext } from "./direction-context.js";
|
|
6
|
+
import { controller, fromSignal } from "./runtime.js";
|
|
7
|
+
/**
|
|
8
|
+
* States the reading direction for the components inside. It draws nothing: set the page's own
|
|
9
|
+
* `dir` attribute with it.
|
|
10
|
+
*/
|
|
11
|
+
export function DirectionProvider(props) {
|
|
12
|
+
const made = controller(createDirection, () => ({
|
|
13
|
+
direction: props.direction
|
|
14
|
+
}));
|
|
15
|
+
return _$createComponent(DirectionContext.Provider, {
|
|
16
|
+
get value() {
|
|
17
|
+
return made.direction;
|
|
18
|
+
},
|
|
19
|
+
get children() {
|
|
20
|
+
return props.children;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
/** The direction the nearest provider states; `ltr` outside one. */
|
|
25
|
+
export function useDirection() {
|
|
26
|
+
return fromSignal(useContext(DirectionContext) ?? signal("ltr"));
|
|
27
|
+
}
|
package/server/drawer.js
ADDED
package/server/field.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { createComponent as _$createComponent } from "solid-js/web";
|
|
2
|
+
import { mergeProps as _$mergeProps } from "solid-js/web";
|
|
3
|
+
import { createField } from "@kirana-ui/core/field";
|
|
4
|
+
import { Show, createUniqueId, onCleanup, onMount, splitProps, useContext } from "solid-js";
|
|
5
|
+
import { FieldContext } from "./field-context.js";
|
|
6
|
+
import { FieldsetContext } from "./fieldset.js";
|
|
7
|
+
import { FormContext } from "./form.js";
|
|
8
|
+
import { Part, controller, fromSignal, toSignal } from "./runtime.js";
|
|
9
|
+
function useField() {
|
|
10
|
+
const made = useContext(FieldContext);
|
|
11
|
+
if (!made) throw new Error("A Field part must be inside <Field.Root>");
|
|
12
|
+
return made;
|
|
13
|
+
}
|
|
14
|
+
function Root(props) {
|
|
15
|
+
const [local, rest] = splitProps(props, ["name", "disabled", "invalid", "validate", "validationMode", "validationDebounceTime", "id"]);
|
|
16
|
+
const generated = createUniqueId();
|
|
17
|
+
const around = {
|
|
18
|
+
form: useContext(FormContext),
|
|
19
|
+
fieldset: useContext(FieldsetContext)
|
|
20
|
+
};
|
|
21
|
+
const made = controller(source => createField(source, around), () => ({
|
|
22
|
+
...local,
|
|
23
|
+
id: local.id ?? generated,
|
|
24
|
+
validate: value => local.validate?.(value) ?? null
|
|
25
|
+
}));
|
|
26
|
+
return _$createComponent(FieldContext.Provider, {
|
|
27
|
+
value: made,
|
|
28
|
+
get children() {
|
|
29
|
+
return _$createComponent(Part, _$mergeProps({
|
|
30
|
+
get part() {
|
|
31
|
+
return made.root;
|
|
32
|
+
},
|
|
33
|
+
tag: "div"
|
|
34
|
+
}, rest));
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* What is wrong, or its children in its place. In the page while it applies. `match` is one of
|
|
40
|
+
* the browser's findings (`"valueMissing"`) to show for only that, or `true` to show always.
|
|
41
|
+
*/
|
|
42
|
+
function FieldError(props) {
|
|
43
|
+
const [local, rest] = splitProps(props, ["match", "children"]);
|
|
44
|
+
const options = toSignal(() => ({
|
|
45
|
+
match: local.match
|
|
46
|
+
}));
|
|
47
|
+
const error = useField().error(() => options.get().match);
|
|
48
|
+
onMount(() => onCleanup(error.mount()));
|
|
49
|
+
const mounted = fromSignal(error.mounted);
|
|
50
|
+
const text = fromSignal(error.text);
|
|
51
|
+
return _$createComponent(Show, {
|
|
52
|
+
get when() {
|
|
53
|
+
return mounted();
|
|
54
|
+
},
|
|
55
|
+
get children() {
|
|
56
|
+
return _$createComponent(Part, _$mergeProps({
|
|
57
|
+
get part() {
|
|
58
|
+
return error.part;
|
|
59
|
+
},
|
|
60
|
+
tag: "div"
|
|
61
|
+
}, rest, {
|
|
62
|
+
get children() {
|
|
63
|
+
return local.children ?? text();
|
|
64
|
+
}
|
|
65
|
+
}));
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
/** Draws nothing itself: its child, a function, is given the field's validity. */
|
|
70
|
+
function Validity(props) {
|
|
71
|
+
return props.children(fromSignal(useField().validity));
|
|
72
|
+
}
|
|
73
|
+
const part = (key, tag) => props => _$createComponent(Part, _$mergeProps({
|
|
74
|
+
get part() {
|
|
75
|
+
return useField()[key];
|
|
76
|
+
},
|
|
77
|
+
tag: tag
|
|
78
|
+
}, props));
|
|
79
|
+
export const Field = {
|
|
80
|
+
Root,
|
|
81
|
+
Label: part("label", "label"),
|
|
82
|
+
/** An `<input>`; `as="textarea"` or `as="select"` for another. */
|
|
83
|
+
Control: part("control", "input"),
|
|
84
|
+
Description: part("description", "p"),
|
|
85
|
+
Error: FieldError,
|
|
86
|
+
Validity
|
|
87
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { createComponent as _$createComponent } from "solid-js/web";
|
|
2
|
+
import { mergeProps as _$mergeProps } from "solid-js/web";
|
|
3
|
+
import { createFieldset } from "@kirana-ui/core/fieldset";
|
|
4
|
+
import { createContext, createUniqueId, splitProps, useContext } from "solid-js";
|
|
5
|
+
import { Part, controller } from "./runtime.js";
|
|
6
|
+
/** The fieldset a field is in, if it is in one. */
|
|
7
|
+
export const FieldsetContext = createContext();
|
|
8
|
+
function useFieldset() {
|
|
9
|
+
const made = useContext(FieldsetContext);
|
|
10
|
+
if (!made) throw new Error("A Fieldset part must be inside <Fieldset.Root>");
|
|
11
|
+
return made;
|
|
12
|
+
}
|
|
13
|
+
function Root(props) {
|
|
14
|
+
const [local, rest] = splitProps(props, ["disabled", "id"]);
|
|
15
|
+
const generated = createUniqueId();
|
|
16
|
+
const made = controller(createFieldset, () => ({
|
|
17
|
+
id: local.id ?? generated,
|
|
18
|
+
disabled: local.disabled
|
|
19
|
+
}));
|
|
20
|
+
return _$createComponent(FieldsetContext.Provider, {
|
|
21
|
+
value: made,
|
|
22
|
+
get children() {
|
|
23
|
+
return _$createComponent(Part, _$mergeProps({
|
|
24
|
+
get part() {
|
|
25
|
+
return made.root;
|
|
26
|
+
},
|
|
27
|
+
tag: "fieldset"
|
|
28
|
+
}, rest));
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
const Legend = props => _$createComponent(Part, _$mergeProps({
|
|
33
|
+
get part() {
|
|
34
|
+
return useFieldset().legend;
|
|
35
|
+
},
|
|
36
|
+
tag: "div"
|
|
37
|
+
}, props));
|
|
38
|
+
export const Fieldset = {
|
|
39
|
+
Root,
|
|
40
|
+
Legend
|
|
41
|
+
};
|
package/server/form.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { createComponent as _$createComponent } from "solid-js/web";
|
|
2
|
+
import { mergeProps as _$mergeProps } from "solid-js/web";
|
|
3
|
+
import { createForm } from "@kirana-ui/core/form";
|
|
4
|
+
import { createContext, splitProps } from "solid-js";
|
|
5
|
+
import { Part, controller } from "./runtime.js";
|
|
6
|
+
/** The form a field is in, if it is in one. */
|
|
7
|
+
export const FormContext = createContext();
|
|
8
|
+
/** A `<form>` whose fields say what is wrong; `onFormSubmit` takes the values once all are valid. */
|
|
9
|
+
export function Form(props) {
|
|
10
|
+
const [local, rest] = splitProps(props, ["errors", "onClearErrors", "onFormSubmit", "validationMode"]);
|
|
11
|
+
const made = controller(createForm, () => ({
|
|
12
|
+
errors: local.errors,
|
|
13
|
+
validationMode: local.validationMode,
|
|
14
|
+
// Only when the caller takes the values: without it the form submits as a form does.
|
|
15
|
+
onFormSubmit: local.onFormSubmit ? (values, details) => local.onFormSubmit?.(values, details) : undefined,
|
|
16
|
+
onClearErrors: errors => local.onClearErrors?.(errors)
|
|
17
|
+
}));
|
|
18
|
+
return _$createComponent(FormContext.Provider, {
|
|
19
|
+
value: made,
|
|
20
|
+
get children() {
|
|
21
|
+
return _$createComponent(Part, _$mergeProps({
|
|
22
|
+
get part() {
|
|
23
|
+
return made.root;
|
|
24
|
+
},
|
|
25
|
+
tag: "form"
|
|
26
|
+
}, rest));
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|