@kirana-ui/react 0.2.0 → 0.4.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 (148) hide show
  1. package/CHANGELOG.md +140 -0
  2. package/llms.txt +1800 -187
  3. package/package.json +48 -3
  4. package/skills/kirana-ui-primitives/SKILL.md +53 -12
  5. package/src/accordion.d.ts +2 -2
  6. package/src/accordion.js +3 -2
  7. package/src/accordion.js.map +1 -1
  8. package/src/alert-dialog.d.ts +2 -2
  9. package/src/autocomplete.d.ts +2 -2
  10. package/src/autosize.d.ts +1 -1
  11. package/src/avatar.d.ts +28 -7
  12. package/src/avatar.js +22 -9
  13. package/src/avatar.js.map +1 -1
  14. package/src/button.d.ts +5 -2
  15. package/src/button.js +4 -1
  16. package/src/button.js.map +1 -1
  17. package/src/calendar.d.ts +23 -8
  18. package/src/calendar.js +50 -13
  19. package/src/calendar.js.map +1 -1
  20. package/src/carousel.d.ts +6 -3
  21. package/src/carousel.js +1 -1
  22. package/src/carousel.js.map +1 -1
  23. package/src/checkbox-group-context.d.ts +4 -0
  24. package/src/checkbox-group-context.js +7 -0
  25. package/src/checkbox-group-context.js.map +1 -0
  26. package/src/checkbox-group.d.ts +15 -0
  27. package/src/checkbox-group.js +30 -0
  28. package/src/checkbox-group.js.map +1 -0
  29. package/src/checkbox.d.ts +7 -2
  30. package/src/checkbox.js +9 -3
  31. package/src/checkbox.js.map +1 -1
  32. package/src/collapsible.d.ts +1 -1
  33. package/src/color-picker.d.ts +61 -0
  34. package/src/color-picker.js +119 -0
  35. package/src/color-picker.js.map +1 -0
  36. package/src/combobox.d.ts +54 -5
  37. package/src/combobox.js +49 -8
  38. package/src/combobox.js.map +1 -1
  39. package/src/command.d.ts +4 -4
  40. package/src/command.js +2 -1
  41. package/src/command.js.map +1 -1
  42. package/src/date-field.d.ts +2 -2
  43. package/src/date-field.js +3 -2
  44. package/src/date-field.js.map +1 -1
  45. package/src/date-picker.d.ts +33 -11
  46. package/src/date-picker.js +22 -5
  47. package/src/date-picker.js.map +1 -1
  48. package/src/dialog.d.ts +11 -6
  49. package/src/dialog.js +27 -8
  50. package/src/dialog.js.map +1 -1
  51. package/src/direction.d.ts +1 -1
  52. package/src/direction.js +1 -1
  53. package/src/editable.d.ts +32 -0
  54. package/src/editable.js +63 -0
  55. package/src/editable.js.map +1 -0
  56. package/src/field.d.ts +1 -1
  57. package/src/fieldset.d.ts +1 -1
  58. package/src/file-upload.d.ts +54 -0
  59. package/src/file-upload.js +96 -0
  60. package/src/file-upload.js.map +1 -0
  61. package/src/form.d.ts +1 -1
  62. package/src/hover-popup.d.ts +1 -1
  63. package/src/hover-popup.js +1 -1
  64. package/src/index.d.ts +28 -7
  65. package/src/index.js +12 -1
  66. package/src/input.d.ts +1 -1
  67. package/src/input.js +1 -1
  68. package/src/label.d.ts +1 -1
  69. package/src/listbox.d.ts +1 -1
  70. package/src/listbox.js +1 -1
  71. package/src/menu.d.ts +5 -5
  72. package/src/menu.js +14 -9
  73. package/src/menu.js.map +1 -1
  74. package/src/menubar.d.ts +2 -2
  75. package/src/menubar.js +4 -2
  76. package/src/menubar.js.map +1 -1
  77. package/src/message-scroller.d.ts +1 -1
  78. package/src/navigation-menu.d.ts +5 -5
  79. package/src/navigation-menu.js +14 -4
  80. package/src/navigation-menu.js.map +1 -1
  81. package/src/number-field.d.ts +11 -2
  82. package/src/number-field.js +20 -3
  83. package/src/number-field.js.map +1 -1
  84. package/src/otp.d.ts +3 -2
  85. package/src/otp.js +10 -2
  86. package/src/otp.js.map +1 -1
  87. package/src/pagination.d.ts +1 -1
  88. package/src/password-input.d.ts +23 -0
  89. package/src/password-input.js +40 -0
  90. package/src/password-input.js.map +1 -0
  91. package/src/popover.d.ts +12 -4
  92. package/src/popover.js +14 -1
  93. package/src/popover.js.map +1 -1
  94. package/src/qr-code.d.ts +1 -1
  95. package/src/radio-group.d.ts +4 -2
  96. package/src/radio-group.js +6 -3
  97. package/src/radio-group.js.map +1 -1
  98. package/src/rating.d.ts +28 -0
  99. package/src/rating.js +59 -0
  100. package/src/rating.js.map +1 -0
  101. package/src/resizable.d.ts +1 -1
  102. package/src/resizable.js +1 -1
  103. package/src/runtime.d.ts +18 -8
  104. package/src/runtime.js +24 -5
  105. package/src/runtime.js.map +1 -1
  106. package/src/scroll-area.d.ts +1 -1
  107. package/src/scroll-area.js +1 -1
  108. package/src/select.d.ts +17 -6
  109. package/src/select.js +6 -3
  110. package/src/select.js.map +1 -1
  111. package/src/separator.d.ts +1 -1
  112. package/src/slider.d.ts +2 -2
  113. package/src/slider.js +3 -2
  114. package/src/slider.js.map +1 -1
  115. package/src/steps.d.ts +51 -0
  116. package/src/steps.js +69 -0
  117. package/src/steps.js.map +1 -0
  118. package/src/switch.d.ts +2 -1
  119. package/src/switch.js +1 -1
  120. package/src/switch.js.map +1 -1
  121. package/src/tabs.d.ts +2 -2
  122. package/src/tabs.js +4 -3
  123. package/src/tabs.js.map +1 -1
  124. package/src/tags-input.d.ts +47 -0
  125. package/src/tags-input.js +92 -0
  126. package/src/tags-input.js.map +1 -0
  127. package/src/time-field.d.ts +32 -0
  128. package/src/time-field.js +67 -0
  129. package/src/time-field.js.map +1 -0
  130. package/src/toast.d.ts +1 -1
  131. package/src/toggle-group.d.ts +2 -2
  132. package/src/toggle-group.js +4 -3
  133. package/src/toggle-group.js.map +1 -1
  134. package/src/toggle.d.ts +1 -1
  135. package/src/toggle.js +1 -1
  136. package/src/toolbar.d.ts +14 -6
  137. package/src/toolbar.js +19 -9
  138. package/src/toolbar.js.map +1 -1
  139. package/src/tour.d.ts +61 -0
  140. package/src/tour.js +68 -0
  141. package/src/tour.js.map +1 -0
  142. package/src/tree.d.ts +45 -0
  143. package/src/tree.js +93 -0
  144. package/src/tree.js.map +1 -0
  145. package/src/use-render.d.ts +1 -1
  146. package/src/use-render.js +1 -1
  147. package/src/use-render.js.map +1 -1
  148. package/src/value-bar.d.ts +1 -1
package/src/calendar.js CHANGED
@@ -1,29 +1,39 @@
1
1
  import { DirectionContext } from "./direction-context.js";
2
2
  import { parts, useController, usePart, useSignal } from "./runtime.js";
3
- import { within } from "@kirana-ui/core";
4
3
  import { Fragment, createContext, useContext, useMemo } from "react";
5
- import { createCalendar } from "@kirana-ui/core/calendar";
4
+ import { within } from "@kirana-ui/core";
6
5
  import { Fragment as Fragment$1, jsx } from "react/jsx-runtime";
6
+ import { createCalendar } from "@kirana-ui/core/calendar";
7
7
  // src/calendar.tsx
8
8
  /**
9
9
  * The calendar its parts are inside. Exported for a component that is made of one (a date picker
10
10
  * provides its own to the calendar's parts).
11
11
  */
12
12
  const Context = createContext(null);
13
+ /** The place of the month its parts are drawn in, inside `Calendar.Months`. */
14
+ const MonthContext = createContext(void 0);
15
+ const CellContext = createContext(void 0);
13
16
  function useCalendar(part) {
14
17
  const controller = useContext(Context);
15
18
  if (!controller) throw new Error(`<Calendar.${part}> must be inside <Calendar.Root>`);
16
19
  return controller;
17
20
  }
18
- function Root({ value, defaultValue, onValueChange, mode, defaultFocusedValue, onMonthChange, locale, calendarSystem, min, max, isDateUnavailable, disabled, readOnly, fixedWeeks, id, ...rest }) {
21
+ function Root({ value, defaultValue, onValueChange, mode, required, minDays, maxDays, months, pagedNavigation, month, defaultMonth, onMonthChange, defaultFocusedValue, locale, calendarSystem, min, max, isDateUnavailable, disabled, readOnly, fixedWeeks, name, form, id, ...rest }) {
19
22
  const direction = useContext(DirectionContext) ?? void 0;
20
23
  const controller = useController(within(createCalendar, { direction }), {
21
24
  value,
22
25
  defaultValue,
23
26
  onValueChange,
24
27
  mode,
25
- defaultFocusedValue,
28
+ required,
29
+ minDays,
30
+ maxDays,
31
+ months,
32
+ pagedNavigation,
33
+ month,
34
+ defaultMonth,
26
35
  onMonthChange,
36
+ defaultFocusedValue,
27
37
  locale,
28
38
  calendarSystem,
29
39
  min,
@@ -32,6 +42,8 @@ function Root({ value, defaultValue, onValueChange, mode, defaultFocusedValue, o
32
42
  disabled,
33
43
  readOnly,
34
44
  fixedWeeks,
45
+ name,
46
+ form,
35
47
  id
36
48
  });
37
49
  return /* @__PURE__ */ jsx(Context.Provider, {
@@ -39,18 +51,31 @@ function Root({ value, defaultValue, onValueChange, mode, defaultFocusedValue, o
39
51
  children: usePart(controller.root, "div", rest)
40
52
  });
41
53
  }
54
+ /** The month a part is drawn in: the one `Calendar.Months` gave, or the first. */
55
+ const useMonth = (part) => useCalendar(part).monthAt(useContext(MonthContext) ?? 0);
42
56
  /** Names the month shown, unless it is given something else to say. */
43
57
  function Heading({ children, ...props }) {
44
- const controller = useCalendar("Heading");
45
- const title = useSignal(controller.title);
46
- return usePart(controller.heading, "div", {
58
+ const month = useMonth("Heading");
59
+ const title = useSignal(month.title);
60
+ return usePart(month.heading, "div", {
47
61
  ...props,
48
62
  children: children ?? title
49
63
  });
50
64
  }
51
65
  const Previous = (props) => usePart(useCalendar("Previous").previous, "button", props);
52
66
  const Next = (props) => usePart(useCalendar("Next").next, "button", props);
53
- const Grid = (props) => usePart(useCalendar("Grid").grid, "table", props);
67
+ const Grid = (props) => usePart(useMonth("Grid").grid, "table", props);
68
+ /**
69
+ * Draws its child once for each month shown (`months` on the root), side by side: the parts
70
+ * inside each are that month's. Left out for one month.
71
+ */
72
+ function Months({ children }) {
73
+ const months = useSignal(useCalendar("Months").months);
74
+ return /* @__PURE__ */ jsx(Fragment$1, { children: months.map((month) => /* @__PURE__ */ jsx(MonthContext.Provider, {
75
+ value: month.index,
76
+ children: children(month)
77
+ }, month.index)) });
78
+ }
54
79
  /** Draws its child once for each day of the week, in the locale's order. */
55
80
  function Weekdays({ children }) {
56
81
  const weekdays = useSignal(useCalendar("Weekdays").weekdays);
@@ -58,7 +83,7 @@ function Weekdays({ children }) {
58
83
  }
59
84
  /** Draws its child once for each week of the month shown. */
60
85
  function Weeks({ children }) {
61
- const weeks = useSignal(useCalendar("Weeks").weeks);
86
+ const weeks = useSignal(useMonth("Weeks").weeks);
62
87
  return /* @__PURE__ */ jsx(Fragment$1, { children: weeks.map((week) => /* @__PURE__ */ jsx(Fragment, { children: children(week) }, week[0].date)) });
63
88
  }
64
89
  function HeadCell({ weekday, ...props }) {
@@ -67,22 +92,34 @@ function HeadCell({ weekday, ...props }) {
67
92
  return usePart(part, "th", props);
68
93
  }
69
94
  function Cell({ date, ...props }) {
70
- return usePart(useCalendar("Cell").cell(date), "td", props);
95
+ const index = useContext(MonthContext);
96
+ return /* @__PURE__ */ jsx(CellContext.Provider, {
97
+ value: date,
98
+ children: usePart(useCalendar("Cell").cell(date, index), "td", props)
99
+ });
71
100
  }
72
- function Day({ date, ...props }) {
73
- return usePart(useCalendar("Day").day(date), "button", props);
101
+ function Day({ date: given, ...props }) {
102
+ const index = useContext(MonthContext);
103
+ const cell = useContext(CellContext);
104
+ const date = given ?? cell;
105
+ if (date === void 0) throw new Error("<Calendar.Day> needs a date or a <Calendar.Cell> around it");
106
+ return usePart(useCalendar("Day").day(date, index), "button", props);
74
107
  }
108
+ /** The hidden input the value is submitted by, when the root has a `name`. */
109
+ const Input = (props) => usePart(useCalendar("Input").input, "input", props);
75
110
  const Calendar = /* @__PURE__ */ parts("Calendar", {
76
111
  Root,
77
112
  Heading,
78
113
  Previous,
79
114
  Next,
115
+ Months,
80
116
  Grid,
81
117
  Weekdays,
82
118
  HeadCell,
83
119
  Weeks,
84
120
  Cell,
85
- Day
121
+ Day,
122
+ Input
86
123
  });
87
124
  export { Calendar, Context as CalendarContext };
88
125
 
@@ -1 +1 @@
1
- {"version":3,"file":"calendar.js","names":[],"sources":["../../../../packages/react/src/calendar.tsx"],"sourcesContent":["import { within } from \"@kirana-ui/core\"\nimport type { StateOf } from \"@kirana-ui/core\"\nimport { createCalendar } from \"@kirana-ui/core/calendar\"\nimport type {\n Calendar as Controller,\n CalendarDay,\n CalendarProps,\n CalendarWeekday,\n} from \"@kirana-ui/core/calendar\"\nimport type { Vocabulary } from \"@kirana-ui/core/vocabulary\"\nimport { Fragment, createContext, useContext, useMemo } from \"react\"\nimport type { ReactElement, ReactNode } from \"react\"\n\nimport { DirectionContext } from \"./direction-context.ts\"\nimport { parts, useController, usePart, useSignal } from \"./runtime.tsx\"\nimport type { PartComponentProps } from \"./runtime.tsx\"\n\ntype Parts = Vocabulary[\"calendar\"]\n\n/**\n * The calendar its parts are inside. Exported for a component that is made of one (a date picker\n * provides its own to the calendar's parts).\n */\nconst Context = createContext<Controller | null>(null)\n/** For a component made of this one's parts: a date picker. */\nexport { Context as CalendarContext }\n\nfunction useCalendar(part: string): Controller {\n const controller = useContext(Context)\n if (!controller) throw new Error(`<Calendar.${part}> must be inside <Calendar.Root>`)\n return controller\n}\n\nexport type RootProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"root\"]>,\n Omit<CalendarProps, \"id\"> & { id?: string }\n>\n\nfunction Root({\n value,\n defaultValue,\n onValueChange,\n mode,\n defaultFocusedValue,\n onMonthChange,\n locale,\n calendarSystem,\n min,\n max,\n isDateUnavailable,\n disabled,\n readOnly,\n fixedWeeks,\n id,\n ...rest\n}: RootProps): ReactElement {\n const direction = useContext(DirectionContext) ?? undefined\n const controller = useController<CalendarProps, Controller>(\n within(createCalendar, { direction }),\n {\n value,\n defaultValue,\n onValueChange,\n mode,\n defaultFocusedValue,\n onMonthChange,\n locale,\n calendarSystem,\n min,\n max,\n isDateUnavailable,\n disabled,\n readOnly,\n fixedWeeks,\n id,\n }\n )\n return (\n <Context.Provider value={controller}>{usePart(controller.root, \"div\", rest)}</Context.Provider>\n )\n}\n\nexport type HeadingProps = PartComponentProps<\"div\", StateOf<Parts[\"heading\"]>>\n\n/** Names the month shown, unless it is given something else to say. */\nfunction Heading({ children, ...props }: HeadingProps): ReactElement {\n const controller = useCalendar(\"Heading\")\n const title = useSignal(controller.title)\n return usePart(controller.heading, \"div\", { ...props, children: children ?? title })\n}\n\nexport type PreviousProps = PartComponentProps<\"button\", StateOf<Parts[\"previous\"]>>\n\nconst Previous = (props: PreviousProps) =>\n usePart(useCalendar(\"Previous\").previous, \"button\", props)\nexport type NextProps = PartComponentProps<\"button\", StateOf<Parts[\"next\"]>>\n\nconst Next = (props: NextProps) => usePart(useCalendar(\"Next\").next, \"button\", props)\nexport type GridProps = PartComponentProps<\"table\", StateOf<Parts[\"grid\"]>>\n\nconst Grid = (props: GridProps) => usePart(useCalendar(\"Grid\").grid, \"table\", props)\n\nexport interface WeekdaysProps {\n /** Draws one day of the week, once for each: its heading cell. */\n children: (weekday: CalendarWeekday) => ReactNode\n}\n\n/** Draws its child once for each day of the week, in the locale's order. */\nfunction Weekdays({ children }: WeekdaysProps) {\n const weekdays = useSignal(useCalendar(\"Weekdays\").weekdays)\n return (\n <>\n {weekdays.map((weekday) => (\n <Fragment key={weekday.index}>{children(weekday)}</Fragment>\n ))}\n </>\n )\n}\n\nexport interface WeeksProps {\n /** Draws one week, once for each of the month shown: a row of its days. */\n children: (week: readonly CalendarDay[]) => ReactNode\n}\n\n/** Draws its child once for each week of the month shown. */\nfunction Weeks({ children }: WeeksProps) {\n const weeks = useSignal(useCalendar(\"Weeks\").weeks)\n return (\n <>\n {weeks.map((week) => (\n <Fragment key={week[0]!.date}>{children(week)}</Fragment>\n ))}\n </>\n )\n}\n\nexport type HeadCellProps = PartComponentProps<\n \"th\",\n StateOf<Parts[\"headCell\"]>,\n {\n /** The day of the week it heads: an entry `Calendar.Weekdays` gave. */\n weekday: CalendarWeekday\n }\n>\n\nfunction HeadCell({ weekday, ...props }: HeadCellProps): ReactElement {\n const controller = useCalendar(\"HeadCell\")\n const part = useMemo(() => controller.headCell(weekday), [controller, weekday])\n return usePart(part, \"th\", props)\n}\n\nexport type CellProps = PartComponentProps<\n \"td\",\n StateOf<Parts[\"cell\"]>,\n {\n /** The day it holds, as `Calendar.Weeks` gave it: `day.date`. */\n date: string\n }\n>\n\nfunction Cell({ date, ...props }: CellProps): ReactElement {\n return usePart(useCalendar(\"Cell\").cell(date), \"td\", props)\n}\n\nexport type DayProps = PartComponentProps<\n \"button\",\n StateOf<Parts[\"day\"]>,\n {\n /** The day it is the button of, as `Calendar.Weeks` gave it: `day.date`. */\n date: string\n }\n>\n\nfunction Day({ date, ...props }: DayProps): ReactElement {\n return usePart(useCalendar(\"Day\").day(date), \"button\", props)\n}\n\nexport const Calendar = /* @__PURE__ */ parts(\"Calendar\", {\n Root,\n Heading,\n Previous,\n Next,\n Grid,\n Weekdays,\n HeadCell,\n Weeks,\n Cell,\n Day,\n})\n"],"mappings":";;;;;;;;;;;AAuBA,MAAM,UAAU,cAAiC,IAAI;AAIrD,SAAS,YAAY,MAA0B;CAC7C,MAAM,aAAa,WAAW,OAAO;CACrC,IAAI,CAAC,YAAY,MAAM,IAAI,MAAM,aAAa,KAAK,iCAAiC;CACpF,OAAO;AACT;AAQA,SAAS,KAAK,EACZ,OACA,cACA,eACA,MACA,qBACA,eACA,QACA,gBACA,KACA,KACA,mBACA,UACA,UACA,YACA,IACA,GAAG,QACuB;CAC1B,MAAM,YAAY,WAAW,gBAAgB,KAAK,KAAA;CAClD,MAAM,aAAa,cACjB,OAAO,gBAAgB,EAAE,UAAU,CAAC,GACpC;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CACF;CACA,OACE,oBAAC,QAAQ,UAAT;EAAkB,OAAO;EAAa,UAAA,QAAQ,WAAW,MAAM,OAAO,IAAI;CAAoB,CAAA;AAElG;;AAKA,SAAS,QAAQ,EAAE,UAAU,GAAG,SAAqC;CACnE,MAAM,aAAa,YAAY,SAAS;CACxC,MAAM,QAAQ,UAAU,WAAW,KAAK;CACxC,OAAO,QAAQ,WAAW,SAAS,OAAO;EAAE,GAAG;EAAO,UAAU,YAAY;CAAM,CAAC;AACrF;AAIA,MAAM,YAAY,UAChB,QAAQ,YAAY,UAAU,CAAC,CAAC,UAAU,UAAU,KAAK;AAG3D,MAAM,QAAQ,UAAqB,QAAQ,YAAY,MAAM,CAAC,CAAC,MAAM,UAAU,KAAK;AAGpF,MAAM,QAAQ,UAAqB,QAAQ,YAAY,MAAM,CAAC,CAAC,MAAM,SAAS,KAAK;;AAQnF,SAAS,SAAS,EAAE,YAA2B;CAC7C,MAAM,WAAW,UAAU,YAAY,UAAU,CAAC,CAAC,QAAQ;CAC3D,OACE,oBAAA,YAAA,EAAA,UACG,SAAS,KAAK,YACb,oBAAC,UAAD,EAAA,UAA+B,SAAS,OAAO,EAAY,GAA5C,QAAQ,KAAoC,CAC5D,EACD,CAAA;AAEN;;AAQA,SAAS,MAAM,EAAE,YAAwB;CACvC,MAAM,QAAQ,UAAU,YAAY,OAAO,CAAC,CAAC,KAAK;CAClD,OACE,oBAAA,YAAA,EAAA,UACG,MAAM,KAAK,SACV,oBAAC,UAAD,EAAA,UAA+B,SAAS,IAAI,EAAY,GAAzC,KAAK,EAAE,CAAE,IAAgC,CACzD,EACD,CAAA;AAEN;AAWA,SAAS,SAAS,EAAE,SAAS,GAAG,SAAsC;CACpE,MAAM,aAAa,YAAY,UAAU;CACzC,MAAM,OAAO,cAAc,WAAW,SAAS,OAAO,GAAG,CAAC,YAAY,OAAO,CAAC;CAC9E,OAAO,QAAQ,MAAM,MAAM,KAAK;AAClC;AAWA,SAAS,KAAK,EAAE,MAAM,GAAG,SAAkC;CACzD,OAAO,QAAQ,YAAY,MAAM,CAAC,CAAC,KAAK,IAAI,GAAG,MAAM,KAAK;AAC5D;AAWA,SAAS,IAAI,EAAE,MAAM,GAAG,SAAiC;CACvD,OAAO,QAAQ,YAAY,KAAK,CAAC,CAAC,IAAI,IAAI,GAAG,UAAU,KAAK;AAC9D;AAEA,MAAa,WAA2B,sBAAM,YAAY;CACxD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC"}
1
+ {"version":3,"file":"calendar.js","names":[],"sources":["../../../../packages/react/src/calendar.tsx"],"sourcesContent":["import { within } from \"@kirana-ui/core\"\nimport type { StateOf } from \"@kirana-ui/core\"\nimport { createCalendar } from \"@kirana-ui/core/calendar\"\nimport type {\n Calendar as Controller,\n CalendarDay,\n CalendarMode,\n CalendarMonth,\n CalendarProps,\n CalendarValue,\n CalendarWeekday,\n} from \"@kirana-ui/core/calendar\"\nimport type { Vocabulary } from \"@kirana-ui/core/vocabulary\"\nimport { Fragment, createContext, useContext, useMemo } from \"react\"\nimport type { ReactElement, ReactNode } from \"react\"\n\nimport { DirectionContext } from \"./direction-context.ts\"\nimport { parts, useController, usePart, useSignal } from \"./runtime.tsx\"\nimport type { PartComponentProps } from \"./runtime.tsx\"\n\ntype Parts = Vocabulary[\"calendar\"]\n\n/**\n * The calendar its parts are inside. Exported for a component that is made of one (a date picker\n * provides its own to the calendar's parts).\n */\nconst Context = createContext<Controller | null>(null)\n/** For a component made of this one's parts: a date picker. */\nexport { Context as CalendarContext }\n\n/** The place of the month its parts are drawn in, inside `Calendar.Months`. */\nconst MonthContext = createContext<number | undefined>(undefined)\n// The day a cell holds, for the day button inside it.\nconst CellContext = createContext<string | undefined>(undefined)\n\nfunction useCalendar(part: string): Controller {\n const controller = useContext(Context)\n if (!controller) throw new Error(`<Calendar.${part}> must be inside <Calendar.Root>`)\n return controller\n}\n\n/** `value` and `onValueChange` are typed by `mode`: a day, a range, or a list of days. */\nexport type RootProps<Mode extends CalendarMode = \"single\"> = PartComponentProps<\n \"div\",\n StateOf<Parts[\"root\"]>,\n Omit<CalendarProps<Mode>, \"id\"> & { id?: string }\n>\n\nfunction Root<Mode extends CalendarMode = \"single\">({\n value,\n defaultValue,\n onValueChange,\n mode,\n required,\n minDays,\n maxDays,\n months,\n pagedNavigation,\n month,\n defaultMonth,\n onMonthChange,\n defaultFocusedValue,\n locale,\n calendarSystem,\n min,\n max,\n isDateUnavailable,\n disabled,\n readOnly,\n fixedWeeks,\n name,\n form,\n id,\n ...rest\n}: RootProps<Mode>): ReactElement {\n const direction = useContext(DirectionContext) ?? undefined\n const controller = useController<CalendarProps, Controller>(\n within(createCalendar, { direction }),\n {\n // The core holds any mode's value; the caller's is its mode's.\n value: value as CalendarValue | undefined,\n defaultValue: defaultValue as CalendarValue | undefined,\n onValueChange: onValueChange as CalendarProps[\"onValueChange\"],\n mode,\n required,\n minDays,\n maxDays,\n months,\n pagedNavigation,\n month,\n defaultMonth,\n onMonthChange,\n defaultFocusedValue,\n locale,\n calendarSystem,\n min,\n max,\n isDateUnavailable,\n disabled,\n readOnly,\n fixedWeeks,\n name,\n form,\n id,\n }\n )\n return (\n <Context.Provider value={controller}>{usePart(controller.root, \"div\", rest)}</Context.Provider>\n )\n}\n\nexport type HeadingProps = PartComponentProps<\"div\", StateOf<Parts[\"heading\"]>>\n\n/** The month a part is drawn in: the one `Calendar.Months` gave, or the first. */\nconst useMonth = (part: string) => useCalendar(part).monthAt(useContext(MonthContext) ?? 0)\n\n/** Names the month shown, unless it is given something else to say. */\nfunction Heading({ children, ...props }: HeadingProps): ReactElement {\n const month = useMonth(\"Heading\")\n const title = useSignal(month.title)\n return usePart(month.heading, \"div\", { ...props, children: children ?? title })\n}\n\nexport type PreviousProps = PartComponentProps<\"button\", StateOf<Parts[\"previous\"]>>\n\nconst Previous = (props: PreviousProps) =>\n usePart(useCalendar(\"Previous\").previous, \"button\", props)\nexport type NextProps = PartComponentProps<\"button\", StateOf<Parts[\"next\"]>>\n\nconst Next = (props: NextProps) => usePart(useCalendar(\"Next\").next, \"button\", props)\nexport type GridProps = PartComponentProps<\"table\", StateOf<Parts[\"grid\"]>>\n\nconst Grid = (props: GridProps) => usePart(useMonth(\"Grid\").grid, \"table\", props)\n\nexport interface MonthsProps {\n /** Draws one month, once for each shown: its heading and its grid. */\n children: (month: CalendarMonth) => ReactNode\n}\n\n/**\n * Draws its child once for each month shown (`months` on the root), side by side: the parts\n * inside each are that month's. Left out for one month.\n */\nfunction Months({ children }: MonthsProps) {\n const months = useSignal(useCalendar(\"Months\").months)\n return (\n <>\n {months.map((month) => (\n <MonthContext.Provider key={month.index} value={month.index}>\n {children(month)}\n </MonthContext.Provider>\n ))}\n </>\n )\n}\n\nexport interface WeekdaysProps {\n /** Draws one day of the week, once for each: its heading cell. */\n children: (weekday: CalendarWeekday) => ReactNode\n}\n\n/** Draws its child once for each day of the week, in the locale's order. */\nfunction Weekdays({ children }: WeekdaysProps) {\n const weekdays = useSignal(useCalendar(\"Weekdays\").weekdays)\n return (\n <>\n {weekdays.map((weekday) => (\n <Fragment key={weekday.index}>{children(weekday)}</Fragment>\n ))}\n </>\n )\n}\n\nexport interface WeeksProps {\n /** Draws one week, once for each of the month shown: a row of its days. */\n children: (week: readonly CalendarDay[]) => ReactNode\n}\n\n/** Draws its child once for each week of the month shown. */\nfunction Weeks({ children }: WeeksProps) {\n const weeks = useSignal(useMonth(\"Weeks\").weeks)\n return (\n <>\n {weeks.map((week) => (\n <Fragment key={week[0]!.date}>{children(week)}</Fragment>\n ))}\n </>\n )\n}\n\nexport type HeadCellProps = PartComponentProps<\n \"th\",\n StateOf<Parts[\"headCell\"]>,\n {\n /** The day of the week it heads: an entry `Calendar.Weekdays` gave. */\n weekday: CalendarWeekday\n }\n>\n\nfunction HeadCell({ weekday, ...props }: HeadCellProps): ReactElement {\n const controller = useCalendar(\"HeadCell\")\n const part = useMemo(() => controller.headCell(weekday), [controller, weekday])\n return usePart(part, \"th\", props)\n}\n\nexport type CellProps = PartComponentProps<\n \"td\",\n StateOf<Parts[\"cell\"]>,\n {\n /** The day it holds, as `Calendar.Weeks` gave it: `day.date`. A `Day` inside takes it too. */\n date: string\n }\n>\n\nfunction Cell({ date, ...props }: CellProps): ReactElement {\n const index = useContext(MonthContext)\n return (\n <CellContext.Provider value={date}>\n {usePart(useCalendar(\"Cell\").cell(date, index), \"td\", props)}\n </CellContext.Provider>\n )\n}\n\nexport type DayProps = PartComponentProps<\n \"button\",\n StateOf<Parts[\"day\"]>,\n {\n /** The day it is the button of. Left out, the `Calendar.Cell`'s it is inside. */\n date?: string\n }\n>\n\nfunction Day({ date: given, ...props }: DayProps): ReactElement {\n const index = useContext(MonthContext)\n const cell = useContext(CellContext)\n const date = given ?? cell\n if (date === undefined)\n throw new Error(\"<Calendar.Day> needs a date or a <Calendar.Cell> around it\")\n return usePart(useCalendar(\"Day\").day(date, index), \"button\", props)\n}\n\nexport type InputProps = PartComponentProps<\"input\", StateOf<Parts[\"input\"]>>\n\n/** The hidden input the value is submitted by, when the root has a `name`. */\nconst Input = (props: InputProps) => usePart(useCalendar(\"Input\").input, \"input\", props)\n\nexport const Calendar = /* @__PURE__ */ parts(\"Calendar\", {\n Root,\n Heading,\n Previous,\n Next,\n Months,\n Grid,\n Weekdays,\n HeadCell,\n Weeks,\n Cell,\n Day,\n Input,\n})\n"],"mappings":";;;;;;;;;;;AA0BA,MAAM,UAAU,cAAiC,IAAI;;AAKrD,MAAM,eAAe,cAAkC,KAAA,CAAS;AAEhE,MAAM,cAAc,cAAkC,KAAA,CAAS;AAE/D,SAAS,YAAY,MAA0B;CAC7C,MAAM,aAAa,WAAW,OAAO;CACrC,IAAI,CAAC,YAAY,MAAM,IAAI,MAAM,aAAa,KAAK,iCAAiC;CACpF,OAAO;AACT;AASA,SAAS,KAA2C,EAClD,OACA,cACA,eACA,MACA,UACA,SACA,SACA,QACA,iBACA,OACA,cACA,eACA,qBACA,QACA,gBACA,KACA,KACA,mBACA,UACA,UACA,YACA,MACA,MACA,IACA,GAAG,QAC6B;CAChC,MAAM,YAAY,WAAW,gBAAgB,KAAK,KAAA;CAClD,MAAM,aAAa,cACjB,OAAO,gBAAgB,EAAE,UAAU,CAAC,GACpC;EAES;EACO;EACC;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CACF;CACA,OACE,oBAAC,QAAQ,UAAT;EAAkB,OAAO;EAAa,UAAA,QAAQ,WAAW,MAAM,OAAO,IAAI;CAAoB,CAAA;AAElG;;AAKA,MAAM,YAAY,SAAiB,YAAY,IAAI,CAAC,CAAC,QAAQ,WAAW,YAAY,KAAK,CAAC;;AAG1F,SAAS,QAAQ,EAAE,UAAU,GAAG,SAAqC;CACnE,MAAM,QAAQ,SAAS,SAAS;CAChC,MAAM,QAAQ,UAAU,MAAM,KAAK;CACnC,OAAO,QAAQ,MAAM,SAAS,OAAO;EAAE,GAAG;EAAO,UAAU,YAAY;CAAM,CAAC;AAChF;AAIA,MAAM,YAAY,UAChB,QAAQ,YAAY,UAAU,CAAC,CAAC,UAAU,UAAU,KAAK;AAG3D,MAAM,QAAQ,UAAqB,QAAQ,YAAY,MAAM,CAAC,CAAC,MAAM,UAAU,KAAK;AAGpF,MAAM,QAAQ,UAAqB,QAAQ,SAAS,MAAM,CAAC,CAAC,MAAM,SAAS,KAAK;;;;;AAWhF,SAAS,OAAO,EAAE,YAAyB;CACzC,MAAM,SAAS,UAAU,YAAY,QAAQ,CAAC,CAAC,MAAM;CACrD,OACE,oBAAA,YAAA,EAAA,UACG,OAAO,KAAK,UACX,oBAAC,aAAa,UAAd;EAAyC,OAAO,MAAM;EACnD,UAAA,SAAS,KAAK;CACM,GAFK,MAAM,KAEX,CACxB,EACD,CAAA;AAEN;;AAQA,SAAS,SAAS,EAAE,YAA2B;CAC7C,MAAM,WAAW,UAAU,YAAY,UAAU,CAAC,CAAC,QAAQ;CAC3D,OACE,oBAAA,YAAA,EAAA,UACG,SAAS,KAAK,YACb,oBAAC,UAAD,EAAA,UAA+B,SAAS,OAAO,EAAY,GAA5C,QAAQ,KAAoC,CAC5D,EACD,CAAA;AAEN;;AAQA,SAAS,MAAM,EAAE,YAAwB;CACvC,MAAM,QAAQ,UAAU,SAAS,OAAO,CAAC,CAAC,KAAK;CAC/C,OACE,oBAAA,YAAA,EAAA,UACG,MAAM,KAAK,SACV,oBAAC,UAAD,EAAA,UAA+B,SAAS,IAAI,EAAY,GAAzC,KAAK,EAAE,CAAE,IAAgC,CACzD,EACD,CAAA;AAEN;AAWA,SAAS,SAAS,EAAE,SAAS,GAAG,SAAsC;CACpE,MAAM,aAAa,YAAY,UAAU;CACzC,MAAM,OAAO,cAAc,WAAW,SAAS,OAAO,GAAG,CAAC,YAAY,OAAO,CAAC;CAC9E,OAAO,QAAQ,MAAM,MAAM,KAAK;AAClC;AAWA,SAAS,KAAK,EAAE,MAAM,GAAG,SAAkC;CACzD,MAAM,QAAQ,WAAW,YAAY;CACrC,OACE,oBAAC,YAAY,UAAb;EAAsB,OAAO;EAC1B,UAAA,QAAQ,YAAY,MAAM,CAAC,CAAC,KAAK,MAAM,KAAK,GAAG,MAAM,KAAK;CACvC,CAAA;AAE1B;AAWA,SAAS,IAAI,EAAE,MAAM,OAAO,GAAG,SAAiC;CAC9D,MAAM,QAAQ,WAAW,YAAY;CACrC,MAAM,OAAO,WAAW,WAAW;CACnC,MAAM,OAAO,SAAS;CACtB,IAAI,SAAS,KAAA,GACX,MAAM,IAAI,MAAM,4DAA4D;CAC9E,OAAO,QAAQ,YAAY,KAAK,CAAC,CAAC,IAAI,MAAM,KAAK,GAAG,UAAU,KAAK;AACrE;;AAKA,MAAM,SAAS,UAAsB,QAAQ,YAAY,OAAO,CAAC,CAAC,OAAO,SAAS,KAAK;AAEvF,MAAa,WAA2B,sBAAM,YAAY;CACxD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC"}
package/src/carousel.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { PartComponentProps } from "./runtime.js";
2
- import { StateOf } from "@kirana-ui/core";
3
2
  import { ReactElement } from "react";
3
+ import { StateOf } from "@kirana-ui/core";
4
4
  import { CarouselProps } from "@kirana-ui/core/carousel";
5
5
  import { Vocabulary } from "@kirana-ui/core/vocabulary";
6
6
  type Parts = Vocabulary["carousel"];
@@ -11,8 +11,11 @@ declare function Root({ index, defaultIndex, onIndexChange, orientation, loop, i
11
11
  export type ViewportProps = PartComponentProps<"div", StateOf<Parts["viewport"]>>;
12
12
  declare const Viewport: (props: ViewportProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
13
13
  export type ItemProps = PartComponentProps<"div", StateOf<Parts["item"]>, {
14
- /** Its place among the slides, from 0. */
15
- index: number;
14
+ /**
15
+ * Its place among the slides, from 0. Left out, its place in the page, once it is there:
16
+ * give it on a page a server draws, which cannot count them.
17
+ */
18
+ index?: number;
16
19
  }>;
17
20
  declare function Item({ index, ...props }: ItemProps): ReactElement;
18
21
  export type PreviousProps = PartComponentProps<"button", StateOf<Parts["previous"]>>;
package/src/carousel.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { DirectionContext } from "./direction-context.js";
2
2
  import { parts, useController, usePart } from "./runtime.js";
3
- import { within } from "@kirana-ui/core";
4
3
  import { createContext, useContext, useMemo } from "react";
4
+ import { within } from "@kirana-ui/core";
5
5
  import { jsx } from "react/jsx-runtime";
6
6
  import { createCarousel } from "@kirana-ui/core/carousel";
7
7
  // src/carousel.tsx
@@ -1 +1 @@
1
- {"version":3,"file":"carousel.js","names":[],"sources":["../../../../packages/react/src/carousel.tsx"],"sourcesContent":["import { within } from \"@kirana-ui/core\"\nimport type { StateOf } from \"@kirana-ui/core\"\nimport { createCarousel } from \"@kirana-ui/core/carousel\"\nimport type { Carousel as Controller, CarouselProps } from \"@kirana-ui/core/carousel\"\nimport type { Vocabulary } from \"@kirana-ui/core/vocabulary\"\nimport { createContext, useContext, useMemo } from \"react\"\nimport type { ReactElement } from \"react\"\n\nimport { DirectionContext } from \"./direction-context.ts\"\nimport { parts, useController, usePart } from \"./runtime.tsx\"\nimport type { PartComponentProps } from \"./runtime.tsx\"\n\ntype Parts = Vocabulary[\"carousel\"]\n\nconst Context = createContext<Controller | null>(null)\n\nfunction useCarousel(part: string): Controller {\n const controller = useContext(Context)\n if (!controller) throw new Error(`<Carousel.${part}> must be inside <Carousel.Root>`)\n return controller\n}\n\nexport type RootProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"root\"]>,\n Omit<CarouselProps, \"id\"> & { id?: string }\n>\n\nfunction Root({\n index,\n defaultIndex,\n onIndexChange,\n orientation,\n loop,\n id,\n ...rest\n}: RootProps): ReactElement {\n const direction = useContext(DirectionContext) ?? undefined\n const controller = useController<CarouselProps, Controller>(\n within(createCarousel, { direction }),\n { index, defaultIndex, onIndexChange, orientation, loop, id }\n )\n return (\n <Context.Provider value={controller}>{usePart(controller.root, \"div\", rest)}</Context.Provider>\n )\n}\n\nexport type ViewportProps = PartComponentProps<\"div\", StateOf<Parts[\"viewport\"]>>\n\nconst Viewport = (props: ViewportProps) => usePart(useCarousel(\"Viewport\").viewport, \"div\", props)\n\nexport type ItemProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"item\"]>,\n {\n /** Its place among the slides, from 0. */\n index: number\n }\n>\n\nfunction Item({ index, ...props }: ItemProps): ReactElement {\n const controller = useCarousel(\"Item\")\n const part = useMemo(() => controller.item(index), [controller, index])\n return usePart(part, \"div\", props)\n}\n\nexport type PreviousProps = PartComponentProps<\"button\", StateOf<Parts[\"previous\"]>>\n\nconst Previous = (props: PreviousProps) =>\n usePart(useCarousel(\"Previous\").previous, \"button\", props)\nexport type NextProps = PartComponentProps<\"button\", StateOf<Parts[\"next\"]>>\n\nconst Next = (props: NextProps) => usePart(useCarousel(\"Next\").next, \"button\", props)\n\nexport type IndicatorProps = PartComponentProps<\n \"button\",\n StateOf<Parts[\"indicator\"]>,\n {\n /** The slide it goes to, from 0. */\n index: number\n }\n>\n\nfunction Indicator({ index, ...props }: IndicatorProps): ReactElement {\n const controller = useCarousel(\"Indicator\")\n const part = useMemo(() => controller.indicator(index), [controller, index])\n return usePart(part, \"button\", props)\n}\n\nexport const Carousel = /* @__PURE__ */ parts(\"Carousel\", {\n Root,\n Viewport,\n Item,\n Previous,\n Next,\n Indicator,\n})\n"],"mappings":";;;;;;;AAcA,MAAM,UAAU,cAAiC,IAAI;AAErD,SAAS,YAAY,MAA0B;CAC7C,MAAM,aAAa,WAAW,OAAO;CACrC,IAAI,CAAC,YAAY,MAAM,IAAI,MAAM,aAAa,KAAK,iCAAiC;CACpF,OAAO;AACT;AAQA,SAAS,KAAK,EACZ,OACA,cACA,eACA,aACA,MACA,IACA,GAAG,QACuB;CAC1B,MAAM,YAAY,WAAW,gBAAgB,KAAK,KAAA;CAClD,MAAM,aAAa,cACjB,OAAO,gBAAgB,EAAE,UAAU,CAAC,GACpC;EAAE;EAAO;EAAc;EAAe;EAAa;EAAM;CAAG,CAC9D;CACA,OACE,oBAAC,QAAQ,UAAT;EAAkB,OAAO;EAAa,UAAA,QAAQ,WAAW,MAAM,OAAO,IAAI;CAAoB,CAAA;AAElG;AAIA,MAAM,YAAY,UAAyB,QAAQ,YAAY,UAAU,CAAC,CAAC,UAAU,OAAO,KAAK;AAWjG,SAAS,KAAK,EAAE,OAAO,GAAG,SAAkC;CAC1D,MAAM,aAAa,YAAY,MAAM;CACrC,MAAM,OAAO,cAAc,WAAW,KAAK,KAAK,GAAG,CAAC,YAAY,KAAK,CAAC;CACtE,OAAO,QAAQ,MAAM,OAAO,KAAK;AACnC;AAIA,MAAM,YAAY,UAChB,QAAQ,YAAY,UAAU,CAAC,CAAC,UAAU,UAAU,KAAK;AAG3D,MAAM,QAAQ,UAAqB,QAAQ,YAAY,MAAM,CAAC,CAAC,MAAM,UAAU,KAAK;AAWpF,SAAS,UAAU,EAAE,OAAO,GAAG,SAAuC;CACpE,MAAM,aAAa,YAAY,WAAW;CAC1C,MAAM,OAAO,cAAc,WAAW,UAAU,KAAK,GAAG,CAAC,YAAY,KAAK,CAAC;CAC3E,OAAO,QAAQ,MAAM,UAAU,KAAK;AACtC;AAEA,MAAa,WAA2B,sBAAM,YAAY;CACxD;CACA;CACA;CACA;CACA;CACA;AACF,CAAC"}
1
+ {"version":3,"file":"carousel.js","names":[],"sources":["../../../../packages/react/src/carousel.tsx"],"sourcesContent":["import { within } from \"@kirana-ui/core\"\nimport type { StateOf } from \"@kirana-ui/core\"\nimport { createCarousel } from \"@kirana-ui/core/carousel\"\nimport type { Carousel as Controller, CarouselProps } from \"@kirana-ui/core/carousel\"\nimport type { Vocabulary } from \"@kirana-ui/core/vocabulary\"\nimport { createContext, useContext, useMemo } from \"react\"\nimport type { ReactElement } from \"react\"\n\nimport { DirectionContext } from \"./direction-context.ts\"\nimport { parts, useController, usePart } from \"./runtime.tsx\"\nimport type { PartComponentProps } from \"./runtime.tsx\"\n\ntype Parts = Vocabulary[\"carousel\"]\n\nconst Context = createContext<Controller | null>(null)\n\nfunction useCarousel(part: string): Controller {\n const controller = useContext(Context)\n if (!controller) throw new Error(`<Carousel.${part}> must be inside <Carousel.Root>`)\n return controller\n}\n\nexport type RootProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"root\"]>,\n Omit<CarouselProps, \"id\"> & { id?: string }\n>\n\nfunction Root({\n index,\n defaultIndex,\n onIndexChange,\n orientation,\n loop,\n id,\n ...rest\n}: RootProps): ReactElement {\n const direction = useContext(DirectionContext) ?? undefined\n const controller = useController<CarouselProps, Controller>(\n within(createCarousel, { direction }),\n { index, defaultIndex, onIndexChange, orientation, loop, id }\n )\n return (\n <Context.Provider value={controller}>{usePart(controller.root, \"div\", rest)}</Context.Provider>\n )\n}\n\nexport type ViewportProps = PartComponentProps<\"div\", StateOf<Parts[\"viewport\"]>>\n\nconst Viewport = (props: ViewportProps) => usePart(useCarousel(\"Viewport\").viewport, \"div\", props)\n\nexport type ItemProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"item\"]>,\n {\n /**\n * Its place among the slides, from 0. Left out, its place in the page, once it is there:\n * give it on a page a server draws, which cannot count them.\n */\n index?: number\n }\n>\n\nfunction Item({ index, ...props }: ItemProps): ReactElement {\n const controller = useCarousel(\"Item\")\n const part = useMemo(() => controller.item(index), [controller, index])\n return usePart(part, \"div\", props)\n}\n\nexport type PreviousProps = PartComponentProps<\"button\", StateOf<Parts[\"previous\"]>>\n\nconst Previous = (props: PreviousProps) =>\n usePart(useCarousel(\"Previous\").previous, \"button\", props)\nexport type NextProps = PartComponentProps<\"button\", StateOf<Parts[\"next\"]>>\n\nconst Next = (props: NextProps) => usePart(useCarousel(\"Next\").next, \"button\", props)\n\nexport type IndicatorProps = PartComponentProps<\n \"button\",\n StateOf<Parts[\"indicator\"]>,\n {\n /** The slide it goes to, from 0. */\n index: number\n }\n>\n\nfunction Indicator({ index, ...props }: IndicatorProps): ReactElement {\n const controller = useCarousel(\"Indicator\")\n const part = useMemo(() => controller.indicator(index), [controller, index])\n return usePart(part, \"button\", props)\n}\n\nexport const Carousel = /* @__PURE__ */ parts(\"Carousel\", {\n Root,\n Viewport,\n Item,\n Previous,\n Next,\n Indicator,\n})\n"],"mappings":";;;;;;;AAcA,MAAM,UAAU,cAAiC,IAAI;AAErD,SAAS,YAAY,MAA0B;CAC7C,MAAM,aAAa,WAAW,OAAO;CACrC,IAAI,CAAC,YAAY,MAAM,IAAI,MAAM,aAAa,KAAK,iCAAiC;CACpF,OAAO;AACT;AAQA,SAAS,KAAK,EACZ,OACA,cACA,eACA,aACA,MACA,IACA,GAAG,QACuB;CAC1B,MAAM,YAAY,WAAW,gBAAgB,KAAK,KAAA;CAClD,MAAM,aAAa,cACjB,OAAO,gBAAgB,EAAE,UAAU,CAAC,GACpC;EAAE;EAAO;EAAc;EAAe;EAAa;EAAM;CAAG,CAC9D;CACA,OACE,oBAAC,QAAQ,UAAT;EAAkB,OAAO;EAAa,UAAA,QAAQ,WAAW,MAAM,OAAO,IAAI;CAAoB,CAAA;AAElG;AAIA,MAAM,YAAY,UAAyB,QAAQ,YAAY,UAAU,CAAC,CAAC,UAAU,OAAO,KAAK;AAcjG,SAAS,KAAK,EAAE,OAAO,GAAG,SAAkC;CAC1D,MAAM,aAAa,YAAY,MAAM;CACrC,MAAM,OAAO,cAAc,WAAW,KAAK,KAAK,GAAG,CAAC,YAAY,KAAK,CAAC;CACtE,OAAO,QAAQ,MAAM,OAAO,KAAK;AACnC;AAIA,MAAM,YAAY,UAChB,QAAQ,YAAY,UAAU,CAAC,CAAC,UAAU,UAAU,KAAK;AAG3D,MAAM,QAAQ,UAAqB,QAAQ,YAAY,MAAM,CAAC,CAAC,MAAM,UAAU,KAAK;AAWpF,SAAS,UAAU,EAAE,OAAO,GAAG,SAAuC;CACpE,MAAM,aAAa,YAAY,WAAW;CAC1C,MAAM,OAAO,cAAc,WAAW,UAAU,KAAK,GAAG,CAAC,YAAY,KAAK,CAAC;CAC3E,OAAO,QAAQ,MAAM,UAAU,KAAK;AACtC;AAEA,MAAa,WAA2B,sBAAM,YAAY;CACxD;CACA;CACA;CACA;CACA;CACA;AACF,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { CheckboxGroup } from "@kirana-ui/core/checkbox-group";
2
+ /** The group a checkbox is one of the boxes of, if it is in one. */
3
+ export declare const CheckboxGroupContext: import("react").Context<CheckboxGroup | null>;
4
+ //# sourceMappingURL=checkbox-group-context.d.ts.map
@@ -0,0 +1,7 @@
1
+ import { createContext } from "react";
2
+ // src/checkbox-group-context.ts
3
+ /** The group a checkbox is one of the boxes of, if it is in one. */
4
+ const CheckboxGroupContext = createContext(null);
5
+ export { CheckboxGroupContext };
6
+
7
+ //# sourceMappingURL=checkbox-group-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checkbox-group-context.js","names":[],"sources":["../../../../packages/react/src/checkbox-group-context.ts"],"sourcesContent":["import type { CheckboxGroup } from \"@kirana-ui/core/checkbox-group\"\nimport { createContext } from \"react\"\n\n/** The group a checkbox is one of the boxes of, if it is in one. */\nexport const CheckboxGroupContext = createContext<CheckboxGroup | null>(null)\n"],"mappings":";;;AAIA,MAAa,uBAAuB,cAAoC,IAAI"}
@@ -0,0 +1,15 @@
1
+ import { PartComponentProps } from "./runtime.js";
2
+ import { ReactElement } from "react";
3
+ import { StateOf } from "@kirana-ui/core";
4
+ import { CheckboxGroupProps as CheckboxGroupProps$1 } from "@kirana-ui/core/checkbox-group";
5
+ import { Vocabulary } from "@kirana-ui/core/vocabulary";
6
+ export type CheckboxGroupProps = PartComponentProps<"div", StateOf<Vocabulary["checkboxGroup"]["root"]>, Omit<CheckboxGroupProps$1, "id"> & {
7
+ /** The group's own id, and what its boxes' elements are named from (`<id>-0`, `<id>-1` …, by their place in `allValues`), which a parent box's `aria-controls` names. Inside a `Field`, the group takes the field's id instead. */
8
+ id?: string;
9
+ }>;
10
+ /**
11
+ * Checkboxes that hold one list of values. Each `<Checkbox.Root value>` inside it is checked
12
+ * while the list has its value; with `allValues`, a `<Checkbox.Root parent>` stands for them all.
13
+ */
14
+ export declare const CheckboxGroup: ({ value, defaultValue, onValueChange, allValues, disabled, id, ...rest }: CheckboxGroupProps) => ReactElement;
15
+ //# sourceMappingURL=checkbox-group.d.ts.map
@@ -0,0 +1,30 @@
1
+ import { CheckboxGroupContext } from "./checkbox-group-context.js";
2
+ import { FieldContext } from "./field-context.js";
3
+ import { component, useController, usePart } from "./runtime.js";
4
+ import { useContext } from "react";
5
+ import { within } from "@kirana-ui/core";
6
+ import { jsx } from "react/jsx-runtime";
7
+ import { createCheckboxGroup } from "@kirana-ui/core/checkbox-group";
8
+ // src/checkbox-group.tsx
9
+ /**
10
+ * Checkboxes that hold one list of values. Each `<Checkbox.Root value>` inside it is checked
11
+ * while the list has its value; with `allValues`, a `<Checkbox.Root parent>` stands for them all.
12
+ */
13
+ const CheckboxGroup = /* @__PURE__ */ component("CheckboxGroup", function CheckboxGroup({ value, defaultValue, onValueChange, allValues, disabled, id, ...rest }) {
14
+ const field = useContext(FieldContext) ?? void 0;
15
+ const controller = useController(within(createCheckboxGroup, { field }), {
16
+ value,
17
+ defaultValue,
18
+ onValueChange,
19
+ allValues,
20
+ disabled,
21
+ id
22
+ });
23
+ return /* @__PURE__ */ jsx(CheckboxGroupContext.Provider, {
24
+ value: controller,
25
+ children: usePart(controller.root, "div", rest)
26
+ });
27
+ });
28
+ export { CheckboxGroup };
29
+
30
+ //# sourceMappingURL=checkbox-group.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checkbox-group.js","names":[],"sources":["../../../../packages/react/src/checkbox-group.tsx"],"sourcesContent":["import { within } from \"@kirana-ui/core\"\nimport type { StateOf } from \"@kirana-ui/core\"\nimport { createCheckboxGroup } from \"@kirana-ui/core/checkbox-group\"\nimport type {\n CheckboxGroup as Controller,\n CheckboxGroupProps as CoreProps,\n} from \"@kirana-ui/core/checkbox-group\"\nimport type { Vocabulary } from \"@kirana-ui/core/vocabulary\"\nimport { useContext } from \"react\"\nimport type { ReactElement } from \"react\"\n\nimport { CheckboxGroupContext } from \"./checkbox-group-context.ts\"\nimport { FieldContext } from \"./field-context.ts\"\nimport { component, useController, usePart } from \"./runtime.tsx\"\nimport type { PartComponentProps } from \"./runtime.tsx\"\n\nexport type CheckboxGroupProps = PartComponentProps<\n \"div\",\n StateOf<Vocabulary[\"checkboxGroup\"][\"root\"]>,\n Omit<CoreProps, \"id\"> & {\n /** The group's own id, and what its boxes' elements are named from (`<id>-0`, `<id>-1` …, by their place in `allValues`), which a parent box's `aria-controls` names. Inside a `Field`, the group takes the field's id instead. */\n id?: string\n }\n>\n\n/**\n * Checkboxes that hold one list of values. Each `<Checkbox.Root value>` inside it is checked\n * while the list has its value; with `allValues`, a `<Checkbox.Root parent>` stands for them all.\n */\nexport const CheckboxGroup = /* @__PURE__ */ component(\n \"CheckboxGroup\",\n function CheckboxGroup({\n value,\n defaultValue,\n onValueChange,\n allValues,\n disabled,\n id,\n ...rest\n }: CheckboxGroupProps): ReactElement {\n const field = useContext(FieldContext) ?? undefined\n const controller = useController<CoreProps, Controller>(\n within(createCheckboxGroup, { field }),\n {\n value,\n defaultValue,\n onValueChange,\n allValues,\n disabled,\n id,\n }\n )\n return (\n <CheckboxGroupContext.Provider value={controller}>\n {usePart(controller.root, \"div\", rest)}\n </CheckboxGroupContext.Provider>\n )\n }\n)\n"],"mappings":";;;;;;;;;;;;AA6BA,MAAa,gBAAgC,0BAC3C,iBACA,SAAS,cAAc,EACrB,OACA,cACA,eACA,WACA,UACA,IACA,GAAG,QACgC;CACnC,MAAM,QAAQ,WAAW,YAAY,KAAK,KAAA;CAC1C,MAAM,aAAa,cACjB,OAAO,qBAAqB,EAAE,MAAM,CAAC,GACrC;EACE;EACA;EACA;EACA;EACA;EACA;CACF,CACF;CACA,OACE,oBAAC,qBAAqB,UAAtB;EAA+B,OAAO;EACnC,UAAA,QAAQ,WAAW,MAAM,OAAO,IAAI;CACR,CAAA;AAEnC,CACF"}
package/src/checkbox.d.ts CHANGED
@@ -1,13 +1,18 @@
1
1
  import { PartComponentProps } from "./runtime.js";
2
- import { StateOf } from "@kirana-ui/core";
3
2
  import { ReactElement } from "react";
3
+ import { StateOf } from "@kirana-ui/core";
4
4
  import { CheckboxProps } from "@kirana-ui/core/checkbox";
5
5
  import { Vocabulary } from "@kirana-ui/core/vocabulary";
6
6
  type Parts = Vocabulary["checkbox"];
7
7
  export type RootProps = PartComponentProps<"span", StateOf<Parts["root"]>, Omit<CheckboxProps, "id"> & {
8
+ /** The id of the box's hidden native checkbox, not of the box: a `<label for>` names it. Inside a `Field`, that input takes the field's id instead. */
8
9
  id?: string;
9
10
  }>;
10
- declare function Root({ checked, defaultChecked, onCheckedChange, indeterminate, disabled, readOnly, required, name, form, value, id, ...rest }: RootProps): ReactElement;
11
+ declare function Root({ checked, defaultChecked, onCheckedChange, indeterminate, parent, disabled, readOnly, required, name, form, value, id, ...rest }: RootProps): ReactElement;
12
+ /**
13
+ * A dash while mixed and a tick while checked, from the part's state: `<Checkbox.Indicator
14
+ * render={(props, state) => <span {...props}>{state.indeterminate ? "–" : "✓"}</span>} />`.
15
+ */
11
16
  export type IndicatorProps = PartComponentProps<"span", StateOf<Parts["indicator"]>, {
12
17
  /** Keeps the mark in the page while the box is unchecked. */
13
18
  keepMounted?: boolean;
package/src/checkbox.js CHANGED
@@ -1,7 +1,8 @@
1
+ import { CheckboxGroupContext } from "./checkbox-group-context.js";
1
2
  import { FieldContext } from "./field-context.js";
2
3
  import { PartElement, parts, useController, usePart, useSignal } from "./runtime.js";
3
- import { within } from "@kirana-ui/core";
4
4
  import { createContext, useContext } from "react";
5
+ import { within } from "@kirana-ui/core";
5
6
  import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
6
7
  import { createCheckbox } from "@kirana-ui/core/checkbox";
7
8
  // src/checkbox.tsx
@@ -11,14 +12,19 @@ function useCheckbox(part) {
11
12
  if (!controller) throw new Error(`<Checkbox.${part}> must be inside <Checkbox.Root>`);
12
13
  return controller;
13
14
  }
14
- function Root({ checked, defaultChecked, onCheckedChange, indeterminate, disabled, readOnly, required, name, form, value, id, ...rest }) {
15
+ function Root({ checked, defaultChecked, onCheckedChange, indeterminate, parent, disabled, readOnly, required, name, form, value, id, ...rest }) {
15
16
  const field = useContext(FieldContext) ?? void 0;
16
- const create = within(createCheckbox, { field });
17
+ const group = useContext(CheckboxGroupContext) ?? void 0;
18
+ const create = within(createCheckbox, {
19
+ field,
20
+ group
21
+ });
17
22
  const controller = useController(create, {
18
23
  checked,
19
24
  defaultChecked,
20
25
  onCheckedChange,
21
26
  indeterminate,
27
+ parent,
22
28
  disabled,
23
29
  readOnly,
24
30
  required,
@@ -1 +1 @@
1
- {"version":3,"file":"checkbox.js","names":[],"sources":["../../../../packages/react/src/checkbox.tsx"],"sourcesContent":["import { within } from \"@kirana-ui/core\"\nimport type { StateOf } from \"@kirana-ui/core\"\nimport { createCheckbox } from \"@kirana-ui/core/checkbox\"\nimport type { Checkbox as Controller, CheckboxProps } from \"@kirana-ui/core/checkbox\"\nimport type { Vocabulary } from \"@kirana-ui/core/vocabulary\"\nimport { createContext, useContext } from \"react\"\nimport type { ReactElement, ReactNode } from \"react\"\n\nimport { FieldContext } from \"./field-context.ts\"\nimport { PartElement, parts, useController, usePart, useSignal } from \"./runtime.tsx\"\nimport type { PartComponentProps } from \"./runtime.tsx\"\n\ntype Parts = Vocabulary[\"checkbox\"]\n\nconst Context = createContext<Controller | null>(null)\n\nfunction useCheckbox(part: string): Controller {\n const controller = useContext(Context)\n if (!controller) throw new Error(`<Checkbox.${part}> must be inside <Checkbox.Root>`)\n return controller\n}\n\nexport type RootProps = PartComponentProps<\n \"span\",\n StateOf<Parts[\"root\"]>,\n Omit<CheckboxProps, \"id\"> & { id?: string }\n>\n\nfunction Root({\n checked,\n defaultChecked,\n onCheckedChange,\n indeterminate,\n disabled,\n readOnly,\n required,\n name,\n form,\n value,\n id,\n ...rest\n}: RootProps): ReactElement {\n const field = useContext(FieldContext) ?? undefined\n const create = within(createCheckbox, { field })\n const controller = useController(create, {\n checked,\n defaultChecked,\n onCheckedChange,\n indeterminate,\n disabled,\n readOnly,\n required,\n name,\n form,\n value,\n id,\n })\n return (\n <Context.Provider value={controller}>\n <PartElement of={controller.root} tag=\"span\" hold={withInput} {...rest} />\n </Context.Provider>\n )\n}\n\n// Its native input is the element's last child, whatever element the caller asked for.\nconst withInput = (content: ReactNode) => (\n <>\n {content}\n <Input />\n </>\n)\n\nconst Input = () => usePart(useCheckbox(\"Root\").input, \"input\", {})\n\nexport type IndicatorProps = PartComponentProps<\n \"span\",\n StateOf<Parts[\"indicator\"]>,\n {\n /** Keeps the mark in the page while the box is unchecked. */\n keepMounted?: boolean\n }\n>\n\nfunction Indicator({ keepMounted, ...props }: IndicatorProps): ReactElement | null {\n const controller = useCheckbox(\"Indicator\")\n const mounted = useSignal(controller.indicatorMounted)\n if (!mounted && !keepMounted) return null\n return <PartElement of={controller.indicator} tag=\"span\" {...props} />\n}\n\nexport const Checkbox = /* @__PURE__ */ parts(\"Checkbox\", { Root, Indicator })\n"],"mappings":";;;;;;;AAcA,MAAM,UAAU,cAAiC,IAAI;AAErD,SAAS,YAAY,MAA0B;CAC7C,MAAM,aAAa,WAAW,OAAO;CACrC,IAAI,CAAC,YAAY,MAAM,IAAI,MAAM,aAAa,KAAK,iCAAiC;CACpF,OAAO;AACT;AAQA,SAAS,KAAK,EACZ,SACA,gBACA,iBACA,eACA,UACA,UACA,UACA,MACA,MACA,OACA,IACA,GAAG,QACuB;CAC1B,MAAM,QAAQ,WAAW,YAAY,KAAK,KAAA;CAC1C,MAAM,SAAS,OAAO,gBAAgB,EAAE,MAAM,CAAC;CAC/C,MAAM,aAAa,cAAc,QAAQ;EACvC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;CACD,OACE,oBAAC,QAAQ,UAAT;EAAkB,OAAO;EACvB,UAAA,oBAAC,aAAD;GAAa,IAAI,WAAW;GAAM,KAAI;GAAO,MAAM;GAAW,GAAI;EAAO,CAAA;CACzD,CAAA;AAEtB;AAGA,MAAM,aAAa,YACjB,qBAAA,YAAA,EAAA,UAAA,CACG,SACD,oBAAC,OAAD,CAAQ,CAAA,CACR,EAAA,CAAA;AAGJ,MAAM,cAAc,QAAQ,YAAY,MAAM,CAAC,CAAC,OAAO,SAAS,CAAC,CAAC;AAWlE,SAAS,UAAU,EAAE,aAAa,GAAG,SAA8C;CACjF,MAAM,aAAa,YAAY,WAAW;CAE1C,IAAI,CADY,UAAU,WAAW,gBAC1B,KAAK,CAAC,aAAa,OAAO;CACrC,OAAO,oBAAC,aAAD;EAAa,IAAI,WAAW;EAAW,KAAI;EAAO,GAAI;CAAQ,CAAA;AACvE;AAEA,MAAa,WAA2B,sBAAM,YAAY;CAAE;CAAM;AAAU,CAAC"}
1
+ {"version":3,"file":"checkbox.js","names":[],"sources":["../../../../packages/react/src/checkbox.tsx"],"sourcesContent":["import { within } from \"@kirana-ui/core\"\nimport type { StateOf } from \"@kirana-ui/core\"\nimport { createCheckbox } from \"@kirana-ui/core/checkbox\"\nimport type { Checkbox as Controller, CheckboxProps } from \"@kirana-ui/core/checkbox\"\nimport type { Vocabulary } from \"@kirana-ui/core/vocabulary\"\nimport { createContext, useContext } from \"react\"\nimport type { ReactElement, ReactNode } from \"react\"\n\nimport { CheckboxGroupContext } from \"./checkbox-group-context.ts\"\nimport { FieldContext } from \"./field-context.ts\"\nimport { PartElement, parts, useController, usePart, useSignal } from \"./runtime.tsx\"\nimport type { PartComponentProps } from \"./runtime.tsx\"\n\ntype Parts = Vocabulary[\"checkbox\"]\n\nconst Context = createContext<Controller | null>(null)\n\nfunction useCheckbox(part: string): Controller {\n const controller = useContext(Context)\n if (!controller) throw new Error(`<Checkbox.${part}> must be inside <Checkbox.Root>`)\n return controller\n}\n\nexport type RootProps = PartComponentProps<\n \"span\",\n StateOf<Parts[\"root\"]>,\n Omit<CheckboxProps, \"id\"> & {\n /** The id of the box's hidden native checkbox, not of the box: a `<label for>` names it. Inside a `Field`, that input takes the field's id instead. */\n id?: string\n }\n>\n\nfunction Root({\n checked,\n defaultChecked,\n onCheckedChange,\n indeterminate,\n parent,\n disabled,\n readOnly,\n required,\n name,\n form,\n value,\n id,\n ...rest\n}: RootProps): ReactElement {\n const field = useContext(FieldContext) ?? undefined\n const group = useContext(CheckboxGroupContext) ?? undefined\n const create = within(createCheckbox, { field, group })\n const controller = useController(create, {\n checked,\n defaultChecked,\n onCheckedChange,\n indeterminate,\n parent,\n disabled,\n readOnly,\n required,\n name,\n form,\n value,\n id,\n })\n return (\n <Context.Provider value={controller}>\n <PartElement of={controller.root} tag=\"span\" hold={withInput} {...rest} />\n </Context.Provider>\n )\n}\n\n// Its native input is the element's last child, whatever element the caller asked for.\nconst withInput = (content: ReactNode) => (\n <>\n {content}\n <Input />\n </>\n)\n\nconst Input = () => usePart(useCheckbox(\"Root\").input, \"input\", {})\n\n/**\n * A dash while mixed and a tick while checked, from the part's state: `<Checkbox.Indicator\n * render={(props, state) => <span {...props}>{state.indeterminate ? \"–\" : \"✓\"}</span>} />`.\n */\nexport type IndicatorProps = PartComponentProps<\n \"span\",\n StateOf<Parts[\"indicator\"]>,\n {\n /** Keeps the mark in the page while the box is unchecked. */\n keepMounted?: boolean\n }\n>\n\nfunction Indicator({ keepMounted, ...props }: IndicatorProps): ReactElement | null {\n const controller = useCheckbox(\"Indicator\")\n const mounted = useSignal(controller.indicatorMounted)\n if (!mounted && !keepMounted) return null\n return <PartElement of={controller.indicator} tag=\"span\" {...props} />\n}\n\nexport const Checkbox = /* @__PURE__ */ parts(\"Checkbox\", { Root, Indicator })\n"],"mappings":";;;;;;;;AAeA,MAAM,UAAU,cAAiC,IAAI;AAErD,SAAS,YAAY,MAA0B;CAC7C,MAAM,aAAa,WAAW,OAAO;CACrC,IAAI,CAAC,YAAY,MAAM,IAAI,MAAM,aAAa,KAAK,iCAAiC;CACpF,OAAO;AACT;AAWA,SAAS,KAAK,EACZ,SACA,gBACA,iBACA,eACA,QACA,UACA,UACA,UACA,MACA,MACA,OACA,IACA,GAAG,QACuB;CAC1B,MAAM,QAAQ,WAAW,YAAY,KAAK,KAAA;CAC1C,MAAM,QAAQ,WAAW,oBAAoB,KAAK,KAAA;CAClD,MAAM,SAAS,OAAO,gBAAgB;EAAE;EAAO;CAAM,CAAC;CACtD,MAAM,aAAa,cAAc,QAAQ;EACvC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;CACD,OACE,oBAAC,QAAQ,UAAT;EAAkB,OAAO;EACvB,UAAA,oBAAC,aAAD;GAAa,IAAI,WAAW;GAAM,KAAI;GAAO,MAAM;GAAW,GAAI;EAAO,CAAA;CACzD,CAAA;AAEtB;AAGA,MAAM,aAAa,YACjB,qBAAA,YAAA,EAAA,UAAA,CACG,SACD,oBAAC,OAAD,CAAQ,CAAA,CACR,EAAA,CAAA;AAGJ,MAAM,cAAc,QAAQ,YAAY,MAAM,CAAC,CAAC,OAAO,SAAS,CAAC,CAAC;AAelE,SAAS,UAAU,EAAE,aAAa,GAAG,SAA8C;CACjF,MAAM,aAAa,YAAY,WAAW;CAE1C,IAAI,CADY,UAAU,WAAW,gBAC1B,KAAK,CAAC,aAAa,OAAO;CACrC,OAAO,oBAAC,aAAD;EAAa,IAAI,WAAW;EAAW,KAAI;EAAO,GAAI;CAAQ,CAAA;AACvE;AAEA,MAAa,WAA2B,sBAAM,YAAY;CAAE;CAAM;AAAU,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import { PartComponentProps } from "./runtime.js";
2
- import { StateOf } from "@kirana-ui/core";
3
2
  import { ReactElement } from "react";
3
+ import { StateOf } from "@kirana-ui/core";
4
4
  import { CollapsibleProps } from "@kirana-ui/core/collapsible";
5
5
  import { Vocabulary } from "@kirana-ui/core/vocabulary";
6
6
  type Parts = Vocabulary["collapsible"];
@@ -0,0 +1,61 @@
1
+ import { PartComponentProps } from "./runtime.js";
2
+ import { ReactElement } from "react";
3
+ import { Orientation, StateOf } from "@kirana-ui/core";
4
+ import { ColorPickerInputChannel, ColorPickerProps, ColorPickerSliderChannel } from "@kirana-ui/core/color-picker";
5
+ import { Vocabulary } from "@kirana-ui/core/vocabulary";
6
+ type Parts = Vocabulary["colorPicker"];
7
+ export type RootProps = PartComponentProps<"div", StateOf<Parts["root"]>, Omit<ColorPickerProps, "id"> & {
8
+ id?: string;
9
+ }>;
10
+ declare function Root({ value, defaultValue, onValueChange, onValueCommitted, format, defaultFormat, onFormatChange, alpha, thumbAlignment, disabled, readOnly, required, name, form, getAriaValueText, id, ...rest }: RootProps): ReactElement;
11
+ export type AreaProps = PartComponentProps<"div", StateOf<Parts["area"]>>;
12
+ export type AreaThumbProps = PartComponentProps<"div", StateOf<Parts["areaThumb"]>>;
13
+ declare const Area: (props: AreaProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
14
+ declare const AreaThumb: (props: AreaThumbProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
15
+ export type ChannelSliderProps = PartComponentProps<"div", StateOf<Parts["channelSlider"]>, {
16
+ /** The channel it moves: the hue, or the alpha. */
17
+ channel: ColorPickerSliderChannel;
18
+ /** The way its track runs. Default `horizontal`. */
19
+ orientation?: Orientation;
20
+ }>;
21
+ declare function ChannelSlider({ channel, orientation, ...props }: ChannelSliderProps): ReactElement;
22
+ export type ChannelSliderTrackProps = PartComponentProps<"div", StateOf<Parts["channelSliderTrack"]>>;
23
+ export type ChannelSliderThumbProps = PartComponentProps<"div", StateOf<Parts["channelSliderThumb"]>>;
24
+ declare function ChannelSliderTrack(props: ChannelSliderTrackProps): ReactElement;
25
+ declare function ChannelSliderThumb(props: ChannelSliderThumbProps): ReactElement;
26
+ export type ChannelInputProps = PartComponentProps<"input", StateOf<Parts["channelInput"]>, {
27
+ /** The channel it is typed in, or `hex` for the whole colour. */
28
+ channel: ColorPickerInputChannel;
29
+ }>;
30
+ declare function ChannelInput({ channel, ...props }: ChannelInputProps): ReactElement;
31
+ export type SwatchProps = PartComponentProps<"div", StateOf<Parts["swatch"]>>;
32
+ declare const Swatch: (props: SwatchProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
33
+ export type SwatchTriggerProps = PartComponentProps<"button", StateOf<Parts["swatchTrigger"]>, {
34
+ /** The preset's colour, in any format: pressed, the colour is this one. */
35
+ value: string;
36
+ }>;
37
+ declare function SwatchTrigger({ value, ...props }: SwatchTriggerProps): ReactElement;
38
+ export type EyeDropperTriggerProps = PartComponentProps<"button", StateOf<Parts["eyeDropperTrigger"]>>;
39
+ declare const EyeDropperTrigger: (props: EyeDropperTriggerProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
40
+ export type ValueTextProps = PartComponentProps<"span", StateOf<Parts["valueText"]>>;
41
+ /** Says the colour in its format unless it is given children. */
42
+ declare function ValueText(props: ValueTextProps): ReactElement;
43
+ export type FormatTriggerProps = PartComponentProps<"button", StateOf<Parts["formatTrigger"]>>;
44
+ /** Says the format the colour is written in unless it is given children. */
45
+ declare function FormatTrigger(props: FormatTriggerProps): ReactElement;
46
+ export declare const ColorPicker: {
47
+ readonly Root: typeof Root;
48
+ readonly Area: typeof Area;
49
+ readonly AreaThumb: typeof AreaThumb;
50
+ readonly ChannelSlider: typeof ChannelSlider;
51
+ readonly ChannelSliderTrack: typeof ChannelSliderTrack;
52
+ readonly ChannelSliderThumb: typeof ChannelSliderThumb;
53
+ readonly ChannelInput: typeof ChannelInput;
54
+ readonly Swatch: typeof Swatch;
55
+ readonly SwatchTrigger: typeof SwatchTrigger;
56
+ readonly EyeDropperTrigger: typeof EyeDropperTrigger;
57
+ readonly ValueText: typeof ValueText;
58
+ readonly FormatTrigger: typeof FormatTrigger;
59
+ };
60
+ export {};
61
+ //# sourceMappingURL=color-picker.d.ts.map
@@ -0,0 +1,119 @@
1
+ import { DirectionContext } from "./direction-context.js";
2
+ import { FieldContext } from "./field-context.js";
3
+ import { PartElement, parts, useController, useOwnText, usePart, useSignal } from "./runtime.js";
4
+ import { createContext, useContext } from "react";
5
+ import { within } from "@kirana-ui/core";
6
+ import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
7
+ import { createColorPicker } from "@kirana-ui/core/color-picker";
8
+ // src/color-picker.tsx
9
+ const Context = createContext(null);
10
+ const SliderContext = createContext(null);
11
+ function useColorPicker(part) {
12
+ const controller = useContext(Context);
13
+ if (!controller) throw new Error(`<ColorPicker.${part}> must be inside <ColorPicker.Root>`);
14
+ return controller;
15
+ }
16
+ function useSliderOf(part) {
17
+ const slider = useContext(SliderContext);
18
+ if (!slider) throw new Error(`<ColorPicker.${part}> must be inside <ColorPicker.ChannelSlider>`);
19
+ return slider;
20
+ }
21
+ function Root({ value, defaultValue, onValueChange, onValueCommitted, format, defaultFormat, onFormatChange, alpha, thumbAlignment, disabled, readOnly, required, name, form, getAriaValueText, id, ...rest }) {
22
+ const field = useContext(FieldContext) ?? void 0;
23
+ const direction = useContext(DirectionContext) ?? void 0;
24
+ const create = within(createColorPicker, {
25
+ field,
26
+ direction
27
+ });
28
+ const controller = useController(create, {
29
+ value,
30
+ defaultValue,
31
+ onValueChange,
32
+ onValueCommitted,
33
+ format,
34
+ defaultFormat,
35
+ onFormatChange,
36
+ alpha,
37
+ thumbAlignment,
38
+ disabled,
39
+ readOnly,
40
+ required,
41
+ name,
42
+ form,
43
+ getAriaValueText,
44
+ id
45
+ });
46
+ return /* @__PURE__ */ jsx(Context.Provider, {
47
+ value: controller,
48
+ children: usePart(controller.root, "div", rest, void 0, (content) => /* @__PURE__ */ jsxs(Fragment$1, { children: [content, /* @__PURE__ */ jsx(PartElement, {
49
+ of: controller.input,
50
+ tag: "input"
51
+ })] }))
52
+ });
53
+ }
54
+ const Area = (props) => usePart(useColorPicker("Area").area, "div", props);
55
+ const AreaThumb = (props) => usePart(useColorPicker("AreaThumb").areaThumb, "div", props);
56
+ function ChannelSlider({ channel, orientation = "horizontal", ...props }) {
57
+ const controller = useColorPicker("ChannelSlider");
58
+ return /* @__PURE__ */ jsx(SliderContext.Provider, {
59
+ value: {
60
+ channel,
61
+ orientation
62
+ },
63
+ children: usePart(controller.channelSlider(channel, orientation), "div", props)
64
+ });
65
+ }
66
+ function ChannelSliderTrack(props) {
67
+ const { channel, orientation } = useSliderOf("ChannelSliderTrack");
68
+ const controller = useColorPicker("ChannelSliderTrack");
69
+ return usePart(controller.channelSliderTrack(channel, orientation), "div", props);
70
+ }
71
+ function ChannelSliderThumb(props) {
72
+ const { channel, orientation } = useSliderOf("ChannelSliderThumb");
73
+ const controller = useColorPicker("ChannelSliderThumb");
74
+ return usePart(controller.channelSliderThumb(channel, orientation), "div", props);
75
+ }
76
+ function ChannelInput({ channel, ...props }) {
77
+ const controller = useColorPicker("ChannelInput");
78
+ return usePart(useOwnText(controller.channelInput(channel)), "input", props);
79
+ }
80
+ const Swatch = (props) => usePart(useColorPicker("Swatch").swatch, "div", props);
81
+ function SwatchTrigger({ value, ...props }) {
82
+ return usePart(useColorPicker("SwatchTrigger").swatchTrigger(value), "button", props);
83
+ }
84
+ const EyeDropperTrigger = (props) => usePart(useColorPicker("EyeDropperTrigger").eyeDropperTrigger, "button", props);
85
+ /** Says the colour in its format unless it is given children. */
86
+ function ValueText(props) {
87
+ const controller = useColorPicker("ValueText");
88
+ const text = useSignal(controller.text);
89
+ return usePart(controller.valueText, "span", {
90
+ ...props,
91
+ children: props.children ?? text
92
+ });
93
+ }
94
+ /** Says the format the colour is written in unless it is given children. */
95
+ function FormatTrigger(props) {
96
+ const controller = useColorPicker("FormatTrigger");
97
+ const format = useSignal(controller.format);
98
+ return usePart(controller.formatTrigger, "button", {
99
+ ...props,
100
+ children: props.children ?? format
101
+ });
102
+ }
103
+ const ColorPicker = /* @__PURE__ */ parts("ColorPicker", {
104
+ Root,
105
+ Area,
106
+ AreaThumb,
107
+ ChannelSlider,
108
+ ChannelSliderTrack,
109
+ ChannelSliderThumb,
110
+ ChannelInput,
111
+ Swatch,
112
+ SwatchTrigger,
113
+ EyeDropperTrigger,
114
+ ValueText,
115
+ FormatTrigger
116
+ });
117
+ export { ColorPicker };
118
+
119
+ //# sourceMappingURL=color-picker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"color-picker.js","names":[],"sources":["../../../../packages/react/src/color-picker.tsx"],"sourcesContent":["import { within } from \"@kirana-ui/core\"\nimport type { Orientation, StateOf } from \"@kirana-ui/core\"\nimport { createColorPicker } from \"@kirana-ui/core/color-picker\"\nimport type {\n ColorPicker as Controller,\n ColorPickerInputChannel,\n ColorPickerProps,\n ColorPickerSliderChannel,\n} from \"@kirana-ui/core/color-picker\"\nimport type { Vocabulary } from \"@kirana-ui/core/vocabulary\"\nimport { createContext, useContext } from \"react\"\nimport type { ReactElement } from \"react\"\n\nimport { DirectionContext } from \"./direction-context.ts\"\nimport { FieldContext } from \"./field-context.ts\"\nimport { PartElement, parts, useController, useOwnText, usePart, useSignal } from \"./runtime.tsx\"\nimport type { PartComponentProps } from \"./runtime.tsx\"\n\ntype Parts = Vocabulary[\"colorPicker\"]\n\nconst Context = createContext<Controller | null>(null)\n\n/** The channel a slider moves and the way it runs, for its track and its thumb. */\ninterface SliderOf {\n channel: ColorPickerSliderChannel\n orientation: Orientation\n}\nconst SliderContext = createContext<SliderOf | null>(null)\n\nfunction useColorPicker(part: string): Controller {\n const controller = useContext(Context)\n if (!controller) throw new Error(`<ColorPicker.${part}> must be inside <ColorPicker.Root>`)\n return controller\n}\n\nfunction useSliderOf(part: string): SliderOf {\n const slider = useContext(SliderContext)\n if (!slider) throw new Error(`<ColorPicker.${part}> must be inside <ColorPicker.ChannelSlider>`)\n return slider\n}\n\nexport type RootProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"root\"]>,\n Omit<ColorPickerProps, \"id\"> & { id?: string }\n>\n\nfunction Root({\n value,\n defaultValue,\n onValueChange,\n onValueCommitted,\n format,\n defaultFormat,\n onFormatChange,\n alpha,\n thumbAlignment,\n disabled,\n readOnly,\n required,\n name,\n form,\n getAriaValueText,\n id,\n ...rest\n}: RootProps): ReactElement {\n const field = useContext(FieldContext) ?? undefined\n const direction = useContext(DirectionContext) ?? undefined\n const create = within(createColorPicker, { field, direction })\n const controller: Controller = useController(create, {\n value,\n defaultValue,\n onValueChange,\n onValueCommitted,\n format,\n defaultFormat,\n onFormatChange,\n alpha,\n thumbAlignment,\n disabled,\n readOnly,\n required,\n name,\n form,\n getAriaValueText,\n id,\n })\n return (\n <Context.Provider value={controller}>\n {usePart(controller.root, \"div\", rest, undefined, (content) => (\n // The input a form reads is the element's last child, whatever element the caller asked for.\n <>\n {content}\n <PartElement of={controller.input} tag=\"input\" />\n </>\n ))}\n </Context.Provider>\n )\n}\n\nexport type AreaProps = PartComponentProps<\"div\", StateOf<Parts[\"area\"]>>\nexport type AreaThumbProps = PartComponentProps<\"div\", StateOf<Parts[\"areaThumb\"]>>\n\nconst Area = (props: AreaProps) => usePart(useColorPicker(\"Area\").area, \"div\", props)\nconst AreaThumb = (props: AreaThumbProps) =>\n usePart(useColorPicker(\"AreaThumb\").areaThumb, \"div\", props)\n\nexport type ChannelSliderProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"channelSlider\"]>,\n {\n /** The channel it moves: the hue, or the alpha. */\n channel: ColorPickerSliderChannel\n /** The way its track runs. Default `horizontal`. */\n orientation?: Orientation\n }\n>\n\nfunction ChannelSlider({\n channel,\n orientation = \"horizontal\",\n ...props\n}: ChannelSliderProps): ReactElement {\n const controller = useColorPicker(\"ChannelSlider\")\n return (\n <SliderContext.Provider value={{ channel, orientation }}>\n {usePart(controller.channelSlider(channel, orientation), \"div\", props)}\n </SliderContext.Provider>\n )\n}\n\nexport type ChannelSliderTrackProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"channelSliderTrack\"]>\n>\nexport type ChannelSliderThumbProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"channelSliderThumb\"]>\n>\n\nfunction ChannelSliderTrack(props: ChannelSliderTrackProps): ReactElement {\n const { channel, orientation } = useSliderOf(\"ChannelSliderTrack\")\n const controller = useColorPicker(\"ChannelSliderTrack\")\n return usePart(controller.channelSliderTrack(channel, orientation), \"div\", props)\n}\n\nfunction ChannelSliderThumb(props: ChannelSliderThumbProps): ReactElement {\n const { channel, orientation } = useSliderOf(\"ChannelSliderThumb\")\n const controller = useColorPicker(\"ChannelSliderThumb\")\n return usePart(controller.channelSliderThumb(channel, orientation), \"div\", props)\n}\n\nexport type ChannelInputProps = PartComponentProps<\n \"input\",\n StateOf<Parts[\"channelInput\"]>,\n {\n /** The channel it is typed in, or `hex` for the whole colour. */\n channel: ColorPickerInputChannel\n }\n>\n\n// Its text is the core's own, written as the colour changes: given to React as a default.\nfunction ChannelInput({ channel, ...props }: ChannelInputProps): ReactElement {\n const controller = useColorPicker(\"ChannelInput\")\n return usePart(useOwnText(controller.channelInput(channel)), \"input\", props)\n}\n\nexport type SwatchProps = PartComponentProps<\"div\", StateOf<Parts[\"swatch\"]>>\n\nconst Swatch = (props: SwatchProps) => usePart(useColorPicker(\"Swatch\").swatch, \"div\", props)\n\nexport type SwatchTriggerProps = PartComponentProps<\n \"button\",\n StateOf<Parts[\"swatchTrigger\"]>,\n {\n /** The preset's colour, in any format: pressed, the colour is this one. */\n value: string\n }\n>\n\nfunction SwatchTrigger({ value, ...props }: SwatchTriggerProps): ReactElement {\n return usePart(useColorPicker(\"SwatchTrigger\").swatchTrigger(value), \"button\", props)\n}\n\nexport type EyeDropperTriggerProps = PartComponentProps<\n \"button\",\n StateOf<Parts[\"eyeDropperTrigger\"]>\n>\n\nconst EyeDropperTrigger = (props: EyeDropperTriggerProps) =>\n usePart(useColorPicker(\"EyeDropperTrigger\").eyeDropperTrigger, \"button\", props)\n\nexport type ValueTextProps = PartComponentProps<\"span\", StateOf<Parts[\"valueText\"]>>\n\n/** Says the colour in its format unless it is given children. */\nfunction ValueText(props: ValueTextProps): ReactElement {\n const controller = useColorPicker(\"ValueText\")\n const text = useSignal(controller.text)\n return usePart(controller.valueText, \"span\", { ...props, children: props.children ?? text })\n}\n\nexport type FormatTriggerProps = PartComponentProps<\"button\", StateOf<Parts[\"formatTrigger\"]>>\n\n/** Says the format the colour is written in unless it is given children. */\nfunction FormatTrigger(props: FormatTriggerProps): ReactElement {\n const controller = useColorPicker(\"FormatTrigger\")\n const format = useSignal(controller.format)\n return usePart(controller.formatTrigger, \"button\", {\n ...props,\n children: props.children ?? format,\n })\n}\n\nexport const ColorPicker = /* @__PURE__ */ parts(\"ColorPicker\", {\n Root,\n Area,\n AreaThumb,\n ChannelSlider,\n ChannelSliderTrack,\n ChannelSliderThumb,\n ChannelInput,\n Swatch,\n SwatchTrigger,\n EyeDropperTrigger,\n ValueText,\n FormatTrigger,\n})\n"],"mappings":"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"}