@kirana-ui/solid 0.2.0 → 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.
Files changed (71) hide show
  1. package/dom/avatar.js +36 -11
  2. package/dom/calendar.js +66 -11
  3. package/dom/checkbox-group-context.js +3 -0
  4. package/dom/checkbox-group.js +38 -0
  5. package/dom/checkbox.js +6 -2
  6. package/dom/combobox.js +53 -3
  7. package/dom/command.js +2 -1
  8. package/dom/date-picker.js +7 -1
  9. package/dom/dialog.js +8 -1
  10. package/dom/index.js +1 -0
  11. package/dom/number-field.js +36 -3
  12. package/dom/otp.js +2 -1
  13. package/dom/popover.js +18 -2
  14. package/dom/primitive.js +92 -0
  15. package/dom/radio-group.js +3 -2
  16. package/dom/select.js +1 -0
  17. package/dom/slider.js +1 -1
  18. package/llms.txt +312 -82
  19. package/package.json +18 -2
  20. package/server/avatar.js +36 -11
  21. package/server/calendar.js +66 -11
  22. package/server/checkbox-group-context.js +3 -0
  23. package/server/checkbox-group.js +38 -0
  24. package/server/checkbox.js +6 -2
  25. package/server/combobox.js +53 -3
  26. package/server/command.js +2 -1
  27. package/server/date-picker.js +7 -1
  28. package/server/dialog.js +8 -1
  29. package/server/index.js +1 -0
  30. package/server/number-field.js +36 -3
  31. package/server/otp.js +2 -1
  32. package/server/popover.js +18 -2
  33. package/server/primitive.js +92 -0
  34. package/server/radio-group.js +3 -2
  35. package/server/select.js +1 -0
  36. package/server/slider.js +1 -1
  37. package/skills/kirana-ui-primitives/SKILL.md +29 -8
  38. package/src/avatar.jsx +16 -9
  39. package/src/calendar.jsx +62 -10
  40. package/src/checkbox-group-context.js +3 -0
  41. package/src/checkbox-group.jsx +33 -0
  42. package/src/checkbox.jsx +5 -1
  43. package/src/combobox.jsx +50 -1
  44. package/src/command.jsx +2 -0
  45. package/src/date-picker.jsx +6 -0
  46. package/src/dialog.jsx +5 -1
  47. package/src/index.js +1 -0
  48. package/src/number-field.jsx +23 -3
  49. package/src/otp.jsx +2 -0
  50. package/src/popover.jsx +15 -1
  51. package/src/primitive.jsx +81 -0
  52. package/src/radio-group.jsx +2 -2
  53. package/src/select.jsx +1 -0
  54. package/src/slider.jsx +1 -0
  55. package/types/alert-dialog.d.ts +1 -1
  56. package/types/autocomplete.d.ts +1 -1
  57. package/types/avatar.d.ts +5 -4
  58. package/types/calendar.d.ts +15 -3
  59. package/types/checkbox-group-context.d.ts +3 -0
  60. package/types/checkbox-group.d.ts +13 -0
  61. package/types/checkbox.d.ts +1 -0
  62. package/types/combobox.d.ts +41 -2
  63. package/types/command.d.ts +2 -0
  64. package/types/date-picker.d.ts +2 -1
  65. package/types/dialog.d.ts +5 -0
  66. package/types/index.d.ts +5 -2
  67. package/types/number-field.d.ts +9 -1
  68. package/types/otp.d.ts +1 -0
  69. package/types/popover.d.ts +17 -3
  70. package/types/primitive.d.ts +50 -0
  71. package/types/radio-group.d.ts +3 -0
@@ -0,0 +1,92 @@
1
+ import { mergeProps as _$mergeProps } from "solid-js/web";
2
+ import { memo as _$memo } from "solid-js/web";
3
+ import { createComponent as _$createComponent } from "solid-js/web";
4
+ import { mergeProps as layer, stateAttributes } from "@kirana-ui/core";
5
+ import { Show, children, createMemo, splitProps } from "solid-js";
6
+ import { Dynamic } from "solid-js/web";
7
+ /**
8
+ * A plain element of one's own (a badge, a breadcrumb's link) with the composition a part has:
9
+ * `as` for another tag (a `div` unless said), or `render` for the caller's own element, given the
10
+ * props to spread and the state. `state` is written as `data-*` attributes under the attributes
11
+ * given. Merge the component's own props with its caller's through `mergeProps`, as a part's
12
+ * are merged.
13
+ */
14
+ export function Primitive(props) {
15
+ const [local, rest] = splitProps(props, ["as", "render", "state", "children"]);
16
+ const marks = () => stateAttributes(local.state ?? {});
17
+ return _$createComponent(Show, {
18
+ get when() {
19
+ return local.render;
20
+ },
21
+ get fallback() {
22
+ return _$createComponent(Dynamic, _$mergeProps({
23
+ get component() {
24
+ return local.as ?? "div";
25
+ }
26
+ }, marks, rest, {
27
+ get children() {
28
+ return local.children;
29
+ }
30
+ }));
31
+ },
32
+ children: render => {
33
+ // Resolved once, as a part's are: a change of the props hands the same nodes over again.
34
+ const held = children(() => local.children);
35
+ const handed = createMemo(() => {
36
+ const given = {
37
+ ...marks()
38
+ };
39
+ for (const key of Object.keys(rest)) given[key] = rest[key];
40
+ return {
41
+ ...given,
42
+ children: held()
43
+ };
44
+ });
45
+ return render()(handed, () => local.state ?? {});
46
+ }
47
+ });
48
+ }
49
+ /** One key of several sets, by a part's rule. */
50
+ function mergedValue(sets, key) {
51
+ if (key === "ref") {
52
+ // Solid hands a component a function whatever was written: each set's gets the element.
53
+ const refs = sets.map(set => set?.ref).filter(ref => typeof ref === "function");
54
+ if (refs.length < 2) return refs[0];
55
+ return element => {
56
+ for (const ref of refs) ref(element);
57
+ };
58
+ }
59
+ let merged = {};
60
+ for (const set of sets) if (set && key in set) merged = layer(merged, {
61
+ [key]: set[key]
62
+ });
63
+ return merged[key];
64
+ }
65
+ /**
66
+ * Several sets of props as one, for a component's own props and its caller's: a later set
67
+ * wins an attribute it gives (one it leaves `undefined` stays), classes join, styles are
68
+ * merged property by property, the handlers of an event run in order until one calls
69
+ * `event.preventKiranaHandler()`, which stops those after it, and every `ref` gets the
70
+ * element. It reads its sets when a prop is read, so a component's props stay reactive: spread
71
+ * it (`<Primitive {...mergeProps({ class: "badge" }, props)} />`). Not solid-js's
72
+ * `mergeProps`, where a later class replaces an earlier one: import one under another name
73
+ * where both are used.
74
+ */
75
+ export function mergeProps(...sets) {
76
+ const keys = () => {
77
+ const all = new Set();
78
+ for (const set of sets) if (set) for (const key of Object.keys(set)) all.add(key);
79
+ return [...all];
80
+ };
81
+ const given = sets;
82
+ return new Proxy({}, {
83
+ get: (_, key) => typeof key === "string" ? mergedValue(given, key) : undefined,
84
+ has: (_, key) => typeof key === "string" && keys().includes(key),
85
+ ownKeys: () => keys(),
86
+ getOwnPropertyDescriptor: (_, key) => typeof key === "string" && keys().includes(key) ? {
87
+ configurable: true,
88
+ enumerable: true,
89
+ get: () => mergedValue(given, key)
90
+ } : undefined
91
+ });
92
+ }
@@ -45,11 +45,12 @@ function Root(props) {
45
45
  });
46
46
  }
47
47
  function Item(props) {
48
- const [local, rest] = splitProps(props, ["value", "disabled", "children"]);
48
+ const [local, rest] = splitProps(props, ["value", "disabled", "id", "children"]);
49
49
  // An item is its value for as long as it is in the page.
50
50
  const value = untrack(() => local.value);
51
51
  const options = toSignal(() => ({
52
- disabled: local.disabled
52
+ disabled: local.disabled,
53
+ id: local.id
53
54
  }));
54
55
  const read = () => defined(options.get());
55
56
  const group = useRadioGroup();
package/dom/select.js CHANGED
@@ -26,6 +26,7 @@ function Root(props) {
26
26
  open: props.open,
27
27
  defaultOpen: props.defaultOpen,
28
28
  disabled: props.disabled,
29
+ readOnly: props.readOnly,
29
30
  required: props.required,
30
31
  name: props.name,
31
32
  form: props.form,
package/dom/slider.js CHANGED
@@ -15,7 +15,7 @@ function useSlider() {
15
15
  }
16
16
  // Given neither `value` nor `defaultValue`, a slider has one thumb: its value is a number.
17
17
  function Root(props) {
18
- const [local, rest] = splitProps(props, ["value", "defaultValue", "onValueChange", "onValueCommitted", "min", "max", "step", "largeStep", "minStepsBetweenValues", "thumbAlignment", "orientation", "disabled", "name", "form", "format", "locale", "getAriaValueText", "id"]);
18
+ const [local, rest] = splitProps(props, ["value", "defaultValue", "onValueChange", "onValueCommitted", "min", "max", "step", "largeStep", "minStepsBetweenValues", "thumbAlignment", "orientation", "disabled", "readOnly", "name", "form", "format", "locale", "getAriaValueText", "id"]);
19
19
  const generated = createUniqueId();
20
20
  const field = useContext(FieldContext);
21
21
  const made = controller(within(createSlider, {