@kirana-ui/react 0.1.1 → 0.2.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 (161) hide show
  1. package/llms.txt +1601 -223
  2. package/package.json +14 -2
  3. package/skills/kirana-ui-primitives/SKILL.md +142 -0
  4. package/src/accordion.d.ts +26 -15
  5. package/src/accordion.js +11 -10
  6. package/src/accordion.js.map +1 -1
  7. package/src/agent.d.ts +1 -0
  8. package/src/agent.js +1 -0
  9. package/src/alert-dialog.d.ts +3 -2
  10. package/src/autocomplete.d.ts +3 -2
  11. package/src/autosize.d.ts +5 -2
  12. package/src/autosize.js +2 -2
  13. package/src/autosize.js.map +1 -1
  14. package/src/avatar.d.ts +12 -8
  15. package/src/avatar.js +18 -9
  16. package/src/avatar.js.map +1 -1
  17. package/src/button.d.ts +4 -2
  18. package/src/button.js +3 -3
  19. package/src/button.js.map +1 -1
  20. package/src/calendar.d.ts +49 -28
  21. package/src/calendar.js +7 -3
  22. package/src/calendar.js.map +1 -1
  23. package/src/carousel.d.ts +25 -15
  24. package/src/carousel.js +3 -3
  25. package/src/carousel.js.map +1 -1
  26. package/src/checkbox.d.ts +10 -7
  27. package/src/checkbox.js +18 -12
  28. package/src/checkbox.js.map +1 -1
  29. package/src/collapsible.d.ts +12 -8
  30. package/src/collapsible.js +8 -7
  31. package/src/collapsible.js.map +1 -1
  32. package/src/combobox.d.ts +88 -60
  33. package/src/combobox.js +44 -31
  34. package/src/combobox.js.map +1 -1
  35. package/src/command.d.ts +30 -21
  36. package/src/command.js +14 -7
  37. package/src/command.js.map +1 -1
  38. package/src/context-menu.d.ts +3 -2
  39. package/src/date-field.d.ts +25 -13
  40. package/src/date-field.js +7 -3
  41. package/src/date-field.js.map +1 -1
  42. package/src/date-picker.d.ts +31 -40
  43. package/src/date-picker.js +3 -3
  44. package/src/date-picker.js.map +1 -1
  45. package/src/dialog.d.ts +45 -35
  46. package/src/dialog.js +12 -8
  47. package/src/dialog.js.map +1 -1
  48. package/src/direction.d.ts +1 -0
  49. package/src/direction.js.map +1 -1
  50. package/src/drawer.d.ts +3 -2
  51. package/src/element.d.ts +12 -0
  52. package/src/element.js +20 -0
  53. package/src/element.js.map +1 -0
  54. package/src/field.d.ts +24 -16
  55. package/src/field.js +9 -7
  56. package/src/field.js.map +1 -1
  57. package/src/fieldset.d.ts +10 -5
  58. package/src/fieldset.js +4 -5
  59. package/src/fieldset.js.map +1 -1
  60. package/src/form.d.ts +5 -2
  61. package/src/form.js +6 -6
  62. package/src/form.js.map +1 -1
  63. package/src/hover-card.d.ts +16 -10
  64. package/src/hover-card.js +1 -1
  65. package/src/hover-card.js.map +1 -1
  66. package/src/hover-popup.d.ts +24 -14
  67. package/src/hover-popup.js +5 -13
  68. package/src/hover-popup.js.map +1 -1
  69. package/src/index.d.ts +13 -3
  70. package/src/input.d.ts +4 -2
  71. package/src/input.js +3 -3
  72. package/src/input.js.map +1 -1
  73. package/src/label.d.ts +4 -1
  74. package/src/label.js +3 -3
  75. package/src/label.js.map +1 -1
  76. package/src/listbox.d.ts +23 -15
  77. package/src/listbox.js +4 -5
  78. package/src/listbox.js.map +1 -1
  79. package/src/menu.d.ts +83 -65
  80. package/src/menu.js +10 -18
  81. package/src/menu.js.map +1 -1
  82. package/src/menubar.d.ts +5 -3
  83. package/src/menubar.js +3 -3
  84. package/src/menubar.js.map +1 -1
  85. package/src/message-scroller.d.ts +15 -9
  86. package/src/message-scroller.js +3 -3
  87. package/src/message-scroller.js.map +1 -1
  88. package/src/meter.d.ts +18 -9
  89. package/src/meter.js +1 -1
  90. package/src/meter.js.map +1 -1
  91. package/src/navigation-menu.d.ts +50 -40
  92. package/src/navigation-menu.js +15 -24
  93. package/src/navigation-menu.js.map +1 -1
  94. package/src/number-field.d.ts +19 -12
  95. package/src/number-field.js +6 -10
  96. package/src/number-field.js.map +1 -1
  97. package/src/otp.d.ts +24 -15
  98. package/src/otp.js +7 -13
  99. package/src/otp.js.map +1 -1
  100. package/src/pagination.d.ts +26 -16
  101. package/src/pagination.js +3 -3
  102. package/src/pagination.js.map +1 -1
  103. package/src/popover.d.ts +30 -21
  104. package/src/popover.js +9 -13
  105. package/src/popover.js.map +1 -1
  106. package/src/progress.d.ts +18 -9
  107. package/src/progress.js +1 -1
  108. package/src/progress.js.map +1 -1
  109. package/src/qr-code.d.ts +12 -7
  110. package/src/qr-code.js +3 -3
  111. package/src/qr-code.js.map +1 -1
  112. package/src/radio-group.d.ts +17 -11
  113. package/src/radio-group.js +16 -19
  114. package/src/radio-group.js.map +1 -1
  115. package/src/resizable.d.ts +13 -8
  116. package/src/resizable.js +3 -3
  117. package/src/resizable.js.map +1 -1
  118. package/src/runtime.d.ts +89 -15
  119. package/src/runtime.js +112 -19
  120. package/src/runtime.js.map +1 -1
  121. package/src/scroll-area.d.ts +26 -15
  122. package/src/scroll-area.js +9 -6
  123. package/src/scroll-area.js.map +1 -1
  124. package/src/select.d.ts +65 -45
  125. package/src/select.js +40 -35
  126. package/src/select.js.map +1 -1
  127. package/src/separator.d.ts +4 -2
  128. package/src/separator.js +3 -3
  129. package/src/separator.js.map +1 -1
  130. package/src/slider.d.ts +35 -20
  131. package/src/slider.js +17 -18
  132. package/src/slider.js.map +1 -1
  133. package/src/switch.d.ts +10 -6
  134. package/src/switch.js +11 -9
  135. package/src/switch.js.map +1 -1
  136. package/src/tabs.d.ts +22 -14
  137. package/src/tabs.js +5 -6
  138. package/src/tabs.js.map +1 -1
  139. package/src/testing.d.ts +1 -0
  140. package/src/testing.js +1 -0
  141. package/src/toast.d.ts +59 -23
  142. package/src/toast.js +59 -13
  143. package/src/toast.js.map +1 -1
  144. package/src/toggle-group.d.ts +5 -2
  145. package/src/toggle-group.js +3 -3
  146. package/src/toggle-group.js.map +1 -1
  147. package/src/toggle.d.ts +4 -2
  148. package/src/toggle.js +3 -3
  149. package/src/toggle.js.map +1 -1
  150. package/src/toolbar.d.ts +26 -11
  151. package/src/toolbar.js +23 -13
  152. package/src/toolbar.js.map +1 -1
  153. package/src/tooltip.d.ts +16 -10
  154. package/src/tooltip.js +1 -1
  155. package/src/tooltip.js.map +1 -1
  156. package/src/use-render.d.ts +38 -0
  157. package/src/use-render.js +50 -0
  158. package/src/use-render.js.map +1 -0
  159. package/src/value-bar.d.ts +19 -11
  160. package/src/value-bar.js +8 -5
  161. package/src/value-bar.js.map +1 -1
package/src/date-field.js CHANGED
@@ -1,10 +1,14 @@
1
1
  import { DirectionContext } from "./direction-context.js";
2
- import { useController, usePart, useSignal } from "./runtime.js";
2
+ import { parts, useController, usePart, useSignal } from "./runtime.js";
3
3
  import { within } from "@kirana-ui/core";
4
4
  import { Fragment, createContext, useContext } from "react";
5
5
  import { Fragment as Fragment$1, jsx } from "react/jsx-runtime";
6
6
  import { createDateField } from "@kirana-ui/core/date-field";
7
7
  // src/date-field.tsx
8
+ /**
9
+ * The date field its parts are inside. Exported for a component that is made of one (a date picker
10
+ * provides its own to the date field's parts).
11
+ */
8
12
  const Context = createContext(null);
9
13
  function useDateField(part) {
10
14
  const controller = useContext(Context);
@@ -49,12 +53,12 @@ function Segment({ segment, ...props }) {
49
53
  });
50
54
  }
51
55
  const Input = (props) => usePart(useDateField("Input").input, "input", props);
52
- const DateField = {
56
+ const DateField = /* @__PURE__ */ parts("DateField", {
53
57
  Root,
54
58
  Segments,
55
59
  Segment,
56
60
  Input
57
- };
61
+ });
58
62
  export { DateField, Context as DateFieldContext };
59
63
 
60
64
  //# sourceMappingURL=date-field.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"date-field.js","names":[],"sources":["../../../../packages/react/src/date-field.tsx"],"sourcesContent":["import { within } from \"@kirana-ui/core\"\nimport { createDateField } from \"@kirana-ui/core/date-field\"\nimport type {\n DateField as Controller,\n DateFieldProps,\n DateFieldSegment,\n} from \"@kirana-ui/core/date-field\"\nimport { Fragment, createContext, useContext } from \"react\"\nimport type { ReactElement, ReactNode } from \"react\"\n\nimport { DirectionContext } from \"./direction-context.ts\"\nimport { useController, usePart, useSignal } from \"./runtime.tsx\"\nimport type { PartComponentProps } from \"./runtime.tsx\"\n\nconst Context = createContext<Controller | null>(null)\n/** For a component made of this one's parts: a date picker. */\nexport { Context as DateFieldContext }\n\nfunction useDateField(part: string): Controller {\n const controller = useContext(Context)\n if (!controller) throw new Error(`<DateField.${part}> must be inside <DateField.Root>`)\n return controller\n}\n\nexport type RootProps = Omit<DateFieldProps, \"id\"> & { id?: string } & PartComponentProps\n\nfunction Root({\n value,\n defaultValue,\n onValueChange,\n locale,\n min,\n max,\n placeholders,\n disabled,\n readOnly,\n required,\n name,\n form,\n id,\n ...rest\n}: RootProps): ReactElement {\n const direction = useContext(DirectionContext) ?? undefined\n const controller = useController<DateFieldProps, Controller>(\n within(createDateField, { direction }),\n {\n value,\n defaultValue,\n onValueChange,\n locale,\n min,\n max,\n placeholders,\n disabled,\n readOnly,\n required,\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\n/** Draws its child once for each piece of the date, in the locale's order. */\nfunction Segments({ children }: { children: (segment: DateFieldSegment) => ReactNode }) {\n const segments = useSignal(useDateField(\"Segments\").segments)\n return (\n <>\n {segments.map((segment) => (\n <Fragment key={`${segment.index}-${segment.type}`}>{children(segment)}</Fragment>\n ))}\n </>\n )\n}\n\n/** One piece: a part that is typed, or what stands between two. It writes its own text. */\nfunction Segment({\n segment,\n ...props\n}: PartComponentProps & { segment: DateFieldSegment }): ReactElement {\n const { part, text } = useDateField(\"Segment\").segment(segment)\n const shown = useSignal(text)\n // Its text is the field's to write: the browser never edits it, whatever React fears.\n return usePart(part, \"span\", { ...props, suppressContentEditableWarning: true, children: shown })\n}\n\nconst Input = (props: PartComponentProps) => usePart(useDateField(\"Input\").input, \"input\", props)\n\nexport const DateField = { Root, Segments, Segment, Input }\n"],"mappings":";;;;;;;AAcA,MAAM,UAAU,cAAiC,IAAI;AAIrD,SAAS,aAAa,MAA0B;CAC9C,MAAM,aAAa,WAAW,OAAO;CACrC,IAAI,CAAC,YAAY,MAAM,IAAI,MAAM,cAAc,KAAK,kCAAkC;CACtF,OAAO;AACT;AAIA,SAAS,KAAK,EACZ,OACA,cACA,eACA,QACA,KACA,KACA,cACA,UACA,UACA,UACA,MACA,MACA,IACA,GAAG,QACuB;CAC1B,MAAM,YAAY,WAAW,gBAAgB,KAAK,KAAA;CAClD,MAAM,aAAa,cACjB,OAAO,iBAAiB,EAAE,UAAU,CAAC,GACrC;EACE;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;;AAGA,SAAS,SAAS,EAAE,YAAoE;CACtF,MAAM,WAAW,UAAU,aAAa,UAAU,CAAC,CAAC,QAAQ;CAC5D,OACE,oBAAA,YAAA,EAAA,UACG,SAAS,KAAK,YACb,oBAAC,UAAD,EAAA,UAAoD,SAAS,OAAO,EAAY,GAAjE,GAAG,QAAQ,MAAM,GAAG,QAAQ,MAAqC,CACjF,EACD,CAAA;AAEN;;AAGA,SAAS,QAAQ,EACf,SACA,GAAG,SACgE;CACnE,MAAM,EAAE,MAAM,SAAS,aAAa,SAAS,CAAC,CAAC,QAAQ,OAAO;CAC9D,MAAM,QAAQ,UAAU,IAAI;CAE5B,OAAO,QAAQ,MAAM,QAAQ;EAAE,GAAG;EAAO,gCAAgC;EAAM,UAAU;CAAM,CAAC;AAClG;AAEA,MAAM,SAAS,UAA8B,QAAQ,aAAa,OAAO,CAAC,CAAC,OAAO,SAAS,KAAK;AAEhG,MAAa,YAAY;CAAE;CAAM;CAAU;CAAS;AAAM"}
1
+ {"version":3,"file":"date-field.js","names":[],"sources":["../../../../packages/react/src/date-field.tsx"],"sourcesContent":["import { within } from \"@kirana-ui/core\"\nimport type { StateOf } from \"@kirana-ui/core\"\nimport { createDateField } from \"@kirana-ui/core/date-field\"\nimport type {\n DateField as Controller,\n DateFieldProps,\n DateFieldSegment,\n} from \"@kirana-ui/core/date-field\"\nimport type { Vocabulary } from \"@kirana-ui/core/vocabulary\"\nimport { Fragment, createContext, useContext } 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[\"dateField\"]\n\n/**\n * The date field its parts are inside. Exported for a component that is made of one (a date picker\n * provides its own to the date field'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 DateFieldContext }\n\nfunction useDateField(part: string): Controller {\n const controller = useContext(Context)\n if (!controller) throw new Error(`<DateField.${part}> must be inside <DateField.Root>`)\n return controller\n}\n\nexport type RootProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"root\"]>,\n Omit<DateFieldProps, \"id\"> & { id?: string }\n>\n\nfunction Root({\n value,\n defaultValue,\n onValueChange,\n locale,\n min,\n max,\n placeholders,\n disabled,\n readOnly,\n required,\n name,\n form,\n id,\n ...rest\n}: RootProps): ReactElement {\n const direction = useContext(DirectionContext) ?? undefined\n const controller = useController<DateFieldProps, Controller>(\n within(createDateField, { direction }),\n {\n value,\n defaultValue,\n onValueChange,\n locale,\n min,\n max,\n placeholders,\n disabled,\n readOnly,\n required,\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 interface SegmentsProps {\n /** Draws one piece of the date, once for each: a part that is typed, or what stands between two. */\n children: (segment: DateFieldSegment) => ReactNode\n}\n\n/** Draws its child once for each piece of the date, in the locale's order. */\nfunction Segments({ children }: SegmentsProps) {\n const segments = useSignal(useDateField(\"Segments\").segments)\n return (\n <>\n {segments.map((segment) => (\n <Fragment key={`${segment.index}-${segment.type}`}>{children(segment)}</Fragment>\n ))}\n </>\n )\n}\n\nexport type SegmentProps = PartComponentProps<\n \"span\",\n StateOf<Parts[\"segment\"]>,\n {\n /** The piece it is: an entry `DateField.Segments` gave. */\n segment: DateFieldSegment\n }\n>\n\n/** One piece: a part that is typed, or what stands between two. It writes its own text. */\nfunction Segment({ segment, ...props }: SegmentProps): ReactElement {\n const { part, text } = useDateField(\"Segment\").segment(segment)\n const shown = useSignal(text)\n // Its text is the field's to write: the browser never edits it, whatever React fears.\n return usePart(part, \"span\", { ...props, suppressContentEditableWarning: true, children: shown })\n}\n\nexport type InputProps = PartComponentProps<\"input\", StateOf<Parts[\"input\"]>>\n\nconst Input = (props: InputProps) => usePart(useDateField(\"Input\").input, \"input\", props)\n\nexport const DateField = /* @__PURE__ */ parts(\"DateField\", { Root, Segments, Segment, Input })\n"],"mappings":";;;;;;;;;;;AAsBA,MAAM,UAAU,cAAiC,IAAI;AAIrD,SAAS,aAAa,MAA0B;CAC9C,MAAM,aAAa,WAAW,OAAO;CACrC,IAAI,CAAC,YAAY,MAAM,IAAI,MAAM,cAAc,KAAK,kCAAkC;CACtF,OAAO;AACT;AAQA,SAAS,KAAK,EACZ,OACA,cACA,eACA,QACA,KACA,KACA,cACA,UACA,UACA,UACA,MACA,MACA,IACA,GAAG,QACuB;CAC1B,MAAM,YAAY,WAAW,gBAAgB,KAAK,KAAA;CAClD,MAAM,aAAa,cACjB,OAAO,iBAAiB,EAAE,UAAU,CAAC,GACrC;EACE;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;;AAQA,SAAS,SAAS,EAAE,YAA2B;CAC7C,MAAM,WAAW,UAAU,aAAa,UAAU,CAAC,CAAC,QAAQ;CAC5D,OACE,oBAAA,YAAA,EAAA,UACG,SAAS,KAAK,YACb,oBAAC,UAAD,EAAA,UAAoD,SAAS,OAAO,EAAY,GAAjE,GAAG,QAAQ,MAAM,GAAG,QAAQ,MAAqC,CACjF,EACD,CAAA;AAEN;;AAYA,SAAS,QAAQ,EAAE,SAAS,GAAG,SAAqC;CAClE,MAAM,EAAE,MAAM,SAAS,aAAa,SAAS,CAAC,CAAC,QAAQ,OAAO;CAC9D,MAAM,QAAQ,UAAU,IAAI;CAE5B,OAAO,QAAQ,MAAM,QAAQ;EAAE,GAAG;EAAO,gCAAgC;EAAM,UAAU;CAAM,CAAC;AAClG;AAIA,MAAM,SAAS,UAAsB,QAAQ,aAAa,OAAO,CAAC,CAAC,OAAO,SAAS,KAAK;AAExF,MAAa,YAA4B,sBAAM,aAAa;CAAE;CAAM;CAAU;CAAS;AAAM,CAAC"}
@@ -1,53 +1,44 @@
1
- import { PositionerProps } from "./popover.js";
2
- import { PartComponentProps } from "./runtime.js";
1
+ import { InputProps, SegmentProps, SegmentsProps } from "./date-field.js";
2
+ import { PopupProps, PositionerProps, TriggerProps } from "./popover.js";
3
+ import { PartComponentProps, PortalProps } from "./runtime.js";
4
+ import { CellProps, DayProps, GridProps, HeadCellProps, HeadingProps, NextProps, PreviousProps, WeekdaysProps, WeeksProps } from "./calendar.js";
5
+ import { StateOf } from "@kirana-ui/core";
3
6
  import { DatePickerProps } from "@kirana-ui/core/date-picker";
4
7
  import { ReactElement, ReactNode } from "react";
8
+ import { Vocabulary } from "@kirana-ui/core/vocabulary";
9
+ type Parts = Vocabulary["datePicker"];
5
10
  export type RootProps = Omit<DatePickerProps, "id"> & {
6
11
  id?: string;
7
12
  children?: ReactNode;
8
13
  };
9
14
  /** A date field, and a calendar in a popover, with one value between them. It draws nothing. */
10
15
  declare function Root({ children, ...props }: RootProps): ReactElement;
16
+ export type FieldProps = PartComponentProps<"div", StateOf<Parts["field"]>>;
17
+ export type CalendarProps = PartComponentProps<"div", StateOf<Parts["calendar"]>>;
11
18
  /** The typed date: what holds its segments and its hidden input. */
12
- declare const Field: (props: PartComponentProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
19
+ declare const Field: (props: FieldProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
13
20
  /** The calendar: what holds its heading, its buttons and its grid. */
14
- declare const CalendarRoot: (props: PartComponentProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
21
+ declare const CalendarRoot: (props: CalendarProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
15
22
  export declare const DatePicker: {
16
- Root: typeof Root;
17
- Field: typeof Field;
18
- Segments: ({ children }: {
19
- children: (segment: import("@kirana-ui/core/date-field").DateFieldSegment) => ReactNode;
20
- }) => import("react").JSX.Element;
21
- Segment: ({ segment, ...props }: PartComponentProps & {
22
- segment: import("@kirana-ui/core/date-field").DateFieldSegment;
23
- }) => ReactElement;
24
- Input: (props: PartComponentProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
25
- Trigger: (props: PartComponentProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
26
- Portal: ({ children }: {
27
- children?: ReactNode;
28
- }) => ReactElement | null;
29
- Positioner: ({ side, align, sideOffset, alignOffset, collisionPadding, ...props }: PositionerProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
30
- Popup: (props: PartComponentProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
31
- Calendar: typeof CalendarRoot;
32
- Heading: ({ children, ...props }: PartComponentProps) => ReactElement;
33
- Previous: (props: PartComponentProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
34
- Next: (props: PartComponentProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
35
- Grid: (props: PartComponentProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
36
- Weekdays: ({ children }: {
37
- children: (weekday: import("@kirana-ui/core/calendar").CalendarWeekday) => ReactNode;
38
- }) => import("react").JSX.Element;
39
- HeadCell: ({ weekday, ...props }: PartComponentProps & {
40
- weekday: import("@kirana-ui/core/calendar").CalendarWeekday;
41
- }) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
42
- Weeks: ({ children }: {
43
- children: (week: readonly import("@kirana-ui/core/calendar").CalendarDay[]) => ReactNode;
44
- }) => import("react").JSX.Element;
45
- Cell: ({ date, ...props }: PartComponentProps & {
46
- date: string;
47
- }) => ReactElement;
48
- Day: ({ date, ...props }: PartComponentProps & {
49
- date: string;
50
- }) => ReactElement;
23
+ readonly Root: typeof Root;
24
+ readonly Field: typeof Field;
25
+ readonly Segments: ({ children }: SegmentsProps) => import("react").JSX.Element;
26
+ readonly Segment: ({ segment, ...props }: SegmentProps) => ReactElement;
27
+ readonly Input: (props: InputProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
28
+ readonly Trigger: (props: TriggerProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
29
+ readonly Portal: ({ children }: PortalProps) => ReactElement | null;
30
+ readonly Positioner: (props: PositionerProps) => ReactElement;
31
+ readonly Popup: (props: PopupProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
32
+ readonly Calendar: typeof CalendarRoot;
33
+ readonly Heading: ({ children, ...props }: HeadingProps) => ReactElement;
34
+ readonly Previous: (props: PreviousProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
35
+ readonly Next: (props: NextProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
36
+ readonly Grid: (props: GridProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
37
+ readonly Weekdays: ({ children }: WeekdaysProps) => import("react").JSX.Element;
38
+ readonly HeadCell: ({ weekday, ...props }: HeadCellProps) => ReactElement;
39
+ readonly Weeks: ({ children }: WeeksProps) => import("react").JSX.Element;
40
+ readonly Cell: ({ date, ...props }: CellProps) => ReactElement;
41
+ readonly Day: ({ date, ...props }: DayProps) => ReactElement;
51
42
  };
52
- export {};
43
+ export type { CellProps, DayProps, GridProps, HeadCellProps, HeadingProps, InputProps, NextProps, PopupProps, PortalProps, PositionerProps, PreviousProps, SegmentProps, SegmentsProps, TriggerProps, WeekdaysProps, WeeksProps };
53
44
  //# sourceMappingURL=date-picker.d.ts.map
@@ -2,7 +2,7 @@ import { Calendar, CalendarContext as Context$1 } from "./calendar.js";
2
2
  import { DateField, DateFieldContext as Context$2 } from "./date-field.js";
3
3
  import { DirectionContext } from "./direction-context.js";
4
4
  import { Popover, PopoverContext as Context$3 } from "./popover.js";
5
- import { useController, usePart } from "./runtime.js";
5
+ import { parts, useController, usePart } from "./runtime.js";
6
6
  import { within } from "@kirana-ui/core";
7
7
  import { createDatePicker } from "@kirana-ui/core/date-picker";
8
8
  import { createContext, useContext } from "react";
@@ -36,7 +36,7 @@ function Root({ children, ...props }) {
36
36
  const Field = (props) => usePart(useDatePicker("Field").field.root, "div", props);
37
37
  /** The calendar: what holds its heading, its buttons and its grid. */
38
38
  const CalendarRoot = (props) => usePart(useDatePicker("Calendar").calendar.root, "div", props);
39
- const DatePicker = {
39
+ const DatePicker = /* @__PURE__ */ parts("DatePicker", {
40
40
  Root,
41
41
  Field,
42
42
  Segments: DateField.Segments,
@@ -56,7 +56,7 @@ const DatePicker = {
56
56
  Weeks: Calendar.Weeks,
57
57
  Cell: Calendar.Cell,
58
58
  Day: Calendar.Day
59
- };
59
+ });
60
60
  export { DatePicker };
61
61
 
62
62
  //# sourceMappingURL=date-picker.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"date-picker.js","names":["DateFieldContext","PopoverContext","CalendarContext"],"sources":["../../../../packages/react/src/date-picker.tsx"],"sourcesContent":["import { within } from \"@kirana-ui/core\"\nimport { createDatePicker } from \"@kirana-ui/core/date-picker\"\nimport type { DatePicker as Controller, DatePickerProps } from \"@kirana-ui/core/date-picker\"\nimport { createContext, useContext } from \"react\"\nimport type { ReactElement, ReactNode } from \"react\"\n\nimport { Calendar, CalendarContext } from \"./calendar.tsx\"\nimport { DateField, DateFieldContext } from \"./date-field.tsx\"\nimport { DirectionContext } from \"./direction-context.ts\"\nimport { Popover, PopoverContext } from \"./popover.tsx\"\nimport { useController, usePart } from \"./runtime.tsx\"\nimport type { PartComponentProps } from \"./runtime.tsx\"\n\nconst Context = createContext<Controller | null>(null)\n\nfunction useDatePicker(part: string): Controller {\n const controller = useContext(Context)\n if (!controller) throw new Error(`<DatePicker.${part}> must be inside <DatePicker.Root>`)\n return controller\n}\n\nexport type RootProps = Omit<DatePickerProps, \"id\"> & { id?: string; children?: ReactNode }\n\n/** A date field, and a calendar in a popover, with one value between them. It draws nothing. */\nfunction Root({ children, ...props }: RootProps): ReactElement {\n const direction = useContext(DirectionContext) ?? undefined\n const controller = useController<DatePickerProps, Controller>(\n within(createDatePicker, { direction }),\n props\n )\n return (\n <Context.Provider value={controller}>\n <DateFieldContext.Provider value={controller.field}>\n <PopoverContext.Provider value={controller.popover}>\n <CalendarContext.Provider value={controller.calendar}>\n {children}\n </CalendarContext.Provider>\n </PopoverContext.Provider>\n </DateFieldContext.Provider>\n </Context.Provider>\n )\n}\n\n/** The typed date: what holds its segments and its hidden input. */\nconst Field = (props: PartComponentProps) =>\n usePart(useDatePicker(\"Field\").field.root, \"div\", props)\n/** The calendar: what holds its heading, its buttons and its grid. */\nconst CalendarRoot = (props: PartComponentProps) =>\n usePart(useDatePicker(\"Calendar\").calendar.root, \"div\", props)\n\nexport const DatePicker = {\n Root,\n Field,\n Segments: DateField.Segments,\n Segment: DateField.Segment,\n Input: DateField.Input,\n Trigger: Popover.Trigger,\n Portal: Popover.Portal,\n Positioner: Popover.Positioner,\n Popup: Popover.Popup,\n Calendar: CalendarRoot,\n Heading: Calendar.Heading,\n Previous: Calendar.Previous,\n Next: Calendar.Next,\n Grid: Calendar.Grid,\n Weekdays: Calendar.Weekdays,\n HeadCell: Calendar.HeadCell,\n Weeks: Calendar.Weeks,\n Cell: Calendar.Cell,\n Day: Calendar.Day,\n}\n"],"mappings":";;;;;;;;;;AAaA,MAAM,UAAU,cAAiC,IAAI;AAErD,SAAS,cAAc,MAA0B;CAC/C,MAAM,aAAa,WAAW,OAAO;CACrC,IAAI,CAAC,YAAY,MAAM,IAAI,MAAM,eAAe,KAAK,mCAAmC;CACxF,OAAO;AACT;;AAKA,SAAS,KAAK,EAAE,UAAU,GAAG,SAAkC;CAC7D,MAAM,YAAY,WAAW,gBAAgB,KAAK,KAAA;CAClD,MAAM,aAAa,cACjB,OAAO,kBAAkB,EAAE,UAAU,CAAC,GACtC,KACF;CACA,OACE,oBAAC,QAAQ,UAAT;EAAkB,OAAO;EACvB,UAAA,oBAACA,UAAiB,UAAlB;GAA2B,OAAO,WAAW;GAC3C,UAAA,oBAACC,UAAe,UAAhB;IAAyB,OAAO,WAAW;IACzC,UAAA,oBAACC,UAAgB,UAAjB;KAA0B,OAAO,WAAW;KACzC;IACuB,CAAA;GACH,CAAA;EACA,CAAA;CACX,CAAA;AAEtB;;AAGA,MAAM,SAAS,UACb,QAAQ,cAAc,OAAO,CAAC,CAAC,MAAM,MAAM,OAAO,KAAK;;AAEzD,MAAM,gBAAgB,UACpB,QAAQ,cAAc,UAAU,CAAC,CAAC,SAAS,MAAM,OAAO,KAAK;AAE/D,MAAa,aAAa;CACxB;CACA;CACA,UAAU,UAAU;CACpB,SAAS,UAAU;CACnB,OAAO,UAAU;CACjB,SAAS,QAAQ;CACjB,QAAQ,QAAQ;CAChB,YAAY,QAAQ;CACpB,OAAO,QAAQ;CACf,UAAU;CACV,SAAS,SAAS;CAClB,UAAU,SAAS;CACnB,MAAM,SAAS;CACf,MAAM,SAAS;CACf,UAAU,SAAS;CACnB,UAAU,SAAS;CACnB,OAAO,SAAS;CAChB,MAAM,SAAS;CACf,KAAK,SAAS;AAChB"}
1
+ {"version":3,"file":"date-picker.js","names":["DateFieldContext","PopoverContext","CalendarContext"],"sources":["../../../../packages/react/src/date-picker.tsx"],"sourcesContent":["import { within } from \"@kirana-ui/core\"\nimport type { StateOf } from \"@kirana-ui/core\"\nimport { createDatePicker } from \"@kirana-ui/core/date-picker\"\nimport type { DatePicker as Controller, DatePickerProps } from \"@kirana-ui/core/date-picker\"\nimport type { Vocabulary } from \"@kirana-ui/core/vocabulary\"\nimport { createContext, useContext } from \"react\"\nimport type { ReactElement, ReactNode } from \"react\"\n\nimport { Calendar, CalendarContext } from \"./calendar.tsx\"\nimport { DateField, DateFieldContext } from \"./date-field.tsx\"\nimport { DirectionContext } from \"./direction-context.ts\"\nimport { Popover, PopoverContext } from \"./popover.tsx\"\nimport { parts, useController, usePart } from \"./runtime.tsx\"\nimport type { PartComponentProps } from \"./runtime.tsx\"\n\nexport type {\n CellProps,\n DayProps,\n GridProps,\n HeadCellProps,\n HeadingProps,\n NextProps,\n PreviousProps,\n WeekdaysProps,\n WeeksProps,\n} from \"./calendar.tsx\"\nexport type { InputProps, SegmentProps, SegmentsProps } from \"./date-field.tsx\"\nexport type { PopupProps, PortalProps, PositionerProps, TriggerProps } from \"./popover.tsx\"\n\ntype Parts = Vocabulary[\"datePicker\"]\n\nconst Context = createContext<Controller | null>(null)\n\nfunction useDatePicker(part: string): Controller {\n const controller = useContext(Context)\n if (!controller) throw new Error(`<DatePicker.${part}> must be inside <DatePicker.Root>`)\n return controller\n}\n\nexport type RootProps = Omit<DatePickerProps, \"id\"> & { id?: string; children?: ReactNode }\n\n/** A date field, and a calendar in a popover, with one value between them. It draws nothing. */\nfunction Root({ children, ...props }: RootProps): ReactElement {\n const direction = useContext(DirectionContext) ?? undefined\n const controller = useController<DatePickerProps, Controller>(\n within(createDatePicker, { direction }),\n props\n )\n return (\n <Context.Provider value={controller}>\n <DateFieldContext.Provider value={controller.field}>\n <PopoverContext.Provider value={controller.popover}>\n <CalendarContext.Provider value={controller.calendar}>\n {children}\n </CalendarContext.Provider>\n </PopoverContext.Provider>\n </DateFieldContext.Provider>\n </Context.Provider>\n )\n}\n\nexport type FieldProps = PartComponentProps<\"div\", StateOf<Parts[\"field\"]>>\nexport type CalendarProps = PartComponentProps<\"div\", StateOf<Parts[\"calendar\"]>>\n\n/** The typed date: what holds its segments and its hidden input. */\nconst Field = (props: FieldProps) => usePart(useDatePicker(\"Field\").field.root, \"div\", props)\n/** The calendar: what holds its heading, its buttons and its grid. */\nconst CalendarRoot = (props: CalendarProps) =>\n usePart(useDatePicker(\"Calendar\").calendar.root, \"div\", props)\n\nexport const DatePicker = /* @__PURE__ */ parts(\"DatePicker\", {\n Root,\n Field,\n Segments: DateField.Segments,\n Segment: DateField.Segment,\n Input: DateField.Input,\n Trigger: Popover.Trigger,\n Portal: Popover.Portal,\n Positioner: Popover.Positioner,\n Popup: Popover.Popup,\n Calendar: CalendarRoot,\n Heading: Calendar.Heading,\n Previous: Calendar.Previous,\n Next: Calendar.Next,\n Grid: Calendar.Grid,\n Weekdays: Calendar.Weekdays,\n HeadCell: Calendar.HeadCell,\n Weeks: Calendar.Weeks,\n Cell: Calendar.Cell,\n Day: Calendar.Day,\n})\n"],"mappings":";;;;;;;;;;AA+BA,MAAM,UAAU,cAAiC,IAAI;AAErD,SAAS,cAAc,MAA0B;CAC/C,MAAM,aAAa,WAAW,OAAO;CACrC,IAAI,CAAC,YAAY,MAAM,IAAI,MAAM,eAAe,KAAK,mCAAmC;CACxF,OAAO;AACT;;AAKA,SAAS,KAAK,EAAE,UAAU,GAAG,SAAkC;CAC7D,MAAM,YAAY,WAAW,gBAAgB,KAAK,KAAA;CAClD,MAAM,aAAa,cACjB,OAAO,kBAAkB,EAAE,UAAU,CAAC,GACtC,KACF;CACA,OACE,oBAAC,QAAQ,UAAT;EAAkB,OAAO;EACvB,UAAA,oBAACA,UAAiB,UAAlB;GAA2B,OAAO,WAAW;GAC3C,UAAA,oBAACC,UAAe,UAAhB;IAAyB,OAAO,WAAW;IACzC,UAAA,oBAACC,UAAgB,UAAjB;KAA0B,OAAO,WAAW;KACzC;IACuB,CAAA;GACH,CAAA;EACA,CAAA;CACX,CAAA;AAEtB;;AAMA,MAAM,SAAS,UAAsB,QAAQ,cAAc,OAAO,CAAC,CAAC,MAAM,MAAM,OAAO,KAAK;;AAE5F,MAAM,gBAAgB,UACpB,QAAQ,cAAc,UAAU,CAAC,CAAC,SAAS,MAAM,OAAO,KAAK;AAE/D,MAAa,aAA6B,sBAAM,cAAc;CAC5D;CACA;CACA,UAAU,UAAU;CACpB,SAAS,UAAU;CACnB,OAAO,UAAU;CACjB,SAAS,QAAQ;CACjB,QAAQ,QAAQ;CAChB,YAAY,QAAQ;CACpB,OAAO,QAAQ;CACf,UAAU;CACV,SAAS,SAAS;CAClB,UAAU,SAAS;CACnB,MAAM,SAAS;CACf,MAAM,SAAS;CACf,UAAU,SAAS;CACnB,UAAU,SAAS;CACnB,OAAO,SAAS;CAChB,MAAM,SAAS;CACf,KAAK,SAAS;AAChB,CAAC"}
package/src/dialog.d.ts CHANGED
@@ -1,31 +1,38 @@
1
- import { PartComponentProps } from "./runtime.js";
1
+ import { PartComponentProps, PortalProps } from "./runtime.js";
2
+ import { StateOf } from "@kirana-ui/core";
2
3
  import { ReactElement, ReactNode } from "react";
3
4
  import { AlertDialogProps } from "@kirana-ui/core/alert-dialog";
4
5
  import { DialogProps } from "@kirana-ui/core/dialog";
5
6
  import { DrawerProps } from "@kirana-ui/core/drawer";
7
+ import { Vocabulary } from "@kirana-ui/core/vocabulary";
8
+ type Parts = Vocabulary["dialog"];
6
9
  export type RootProps = Omit<DialogProps, "id"> & {
7
10
  id?: string;
8
11
  children?: ReactNode;
9
12
  };
10
13
  declare function Root({ children, ...props }: RootProps): ReactElement;
11
- declare function Portal({ children }: {
12
- children?: ReactNode;
13
- }): ReactElement | null;
14
- declare const Trigger: (props: PartComponentProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
15
- declare const Backdrop: (props: PartComponentProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
16
- declare const Popup: (props: PartComponentProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
17
- declare const Title: (props: PartComponentProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
18
- declare const Description: (props: PartComponentProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
19
- declare const Close: (props: PartComponentProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
14
+ declare function Portal({ children }: PortalProps): ReactElement | null;
15
+ export type TriggerProps = PartComponentProps<"button", StateOf<Parts["trigger"]>>;
16
+ export type BackdropProps = PartComponentProps<"div", StateOf<Parts["backdrop"]>>;
17
+ export type PopupProps = PartComponentProps<"div", StateOf<Parts["popup"]>>;
18
+ export type TitleProps = PartComponentProps<"h2", StateOf<Parts["title"]>>;
19
+ export type DescriptionProps = PartComponentProps<"p", StateOf<Parts["description"]>>;
20
+ export type CloseProps = PartComponentProps<"button", StateOf<Parts["close"]>>;
21
+ declare const Trigger: (props: TriggerProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
22
+ declare const Backdrop: (props: BackdropProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
23
+ declare const Popup: (props: PopupProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
24
+ declare const Title: (props: TitleProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
25
+ declare const Description: (props: DescriptionProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
26
+ declare const Close: (props: CloseProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
20
27
  export declare const Dialog: {
21
- Root: typeof Root;
22
- Trigger: typeof Trigger;
23
- Portal: typeof Portal;
24
- Backdrop: typeof Backdrop;
25
- Popup: typeof Popup;
26
- Title: typeof Title;
27
- Description: typeof Description;
28
- Close: typeof Close;
28
+ readonly Root: typeof Root;
29
+ readonly Trigger: typeof Trigger;
30
+ readonly Portal: typeof Portal;
31
+ readonly Backdrop: typeof Backdrop;
32
+ readonly Popup: typeof Popup;
33
+ readonly Title: typeof Title;
34
+ readonly Description: typeof Description;
35
+ readonly Close: typeof Close;
29
36
  };
30
37
  export type AlertRootProps = Omit<AlertDialogProps, "id"> & {
31
38
  id?: string;
@@ -34,30 +41,33 @@ export type AlertRootProps = Omit<AlertDialogProps, "id"> & {
34
41
  declare function AlertRoot({ children, ...props }: AlertRootProps): ReactElement;
35
42
  /** A dialog that asks for an answer: a press outside it does not close it. Its parts are a dialog's. */
36
43
  export declare const AlertDialog: {
37
- Trigger: typeof Trigger;
38
- Portal: typeof Portal;
39
- Backdrop: typeof Backdrop;
40
- Popup: typeof Popup;
41
- Title: typeof Title;
42
- Description: typeof Description;
43
- Close: typeof Close;
44
- Root: typeof AlertRoot;
44
+ readonly Trigger: typeof Trigger;
45
+ readonly Portal: typeof Portal;
46
+ readonly Backdrop: typeof Backdrop;
47
+ readonly Popup: typeof Popup;
48
+ readonly Title: typeof Title;
49
+ readonly Description: typeof Description;
50
+ readonly Close: typeof Close;
51
+ readonly Root: typeof AlertRoot;
45
52
  };
46
53
  export type DrawerRootProps = Omit<DrawerProps, "id"> & {
47
54
  id?: string;
48
55
  children?: ReactNode;
49
56
  };
50
57
  declare function DrawerRoot({ children, ...props }: DrawerRootProps): ReactElement;
58
+ type DrawerParts = Vocabulary["drawer"];
59
+ export type DrawerBackdropProps = PartComponentProps<"div", StateOf<DrawerParts["backdrop"]>>;
60
+ export type DrawerPopupProps = PartComponentProps<"div", StateOf<DrawerParts["popup"]>>;
51
61
  /** A dialog that comes from an edge and is dragged back to it. Its parts are a dialog's. */
52
62
  export declare const Drawer: {
53
- Trigger: typeof Trigger;
54
- Portal: typeof Portal;
55
- Backdrop: typeof Backdrop;
56
- Popup: typeof Popup;
57
- Title: typeof Title;
58
- Description: typeof Description;
59
- Close: typeof Close;
60
- Root: typeof DrawerRoot;
63
+ readonly Trigger: typeof Trigger;
64
+ readonly Portal: typeof Portal;
65
+ readonly Title: typeof Title;
66
+ readonly Description: typeof Description;
67
+ readonly Close: typeof Close;
68
+ readonly Root: typeof DrawerRoot;
69
+ readonly Backdrop: (props: DrawerBackdropProps) => ReactElement;
70
+ readonly Popup: (props: DrawerPopupProps) => ReactElement;
61
71
  };
62
- export {};
72
+ export type { PortalProps };
63
73
  //# sourceMappingURL=dialog.d.ts.map
package/src/dialog.js CHANGED
@@ -1,4 +1,4 @@
1
- import { Portal as Portal$1, useController, usePart, useSignal } from "./runtime.js";
1
+ import { Portal as Portal$1, parts, useController, usePart, useSignal } from "./runtime.js";
2
2
  import { createContext, useContext } from "react";
3
3
  import { jsx } from "react/jsx-runtime";
4
4
  import { createAlertDialog } from "@kirana-ui/core/alert-dialog";
@@ -27,7 +27,7 @@ const Popup = (props) => usePart(useDialog("Popup").popup, "div", props);
27
27
  const Title = (props) => usePart(useDialog("Title").title, "h2", props);
28
28
  const Description = (props) => usePart(useDialog("Description").description, "p", props);
29
29
  const Close = (props) => usePart(useDialog("Close").close, "button", props);
30
- const Dialog = {
30
+ const Dialog = /* @__PURE__ */ parts("Dialog", {
31
31
  Root,
32
32
  Trigger,
33
33
  Portal,
@@ -36,7 +36,7 @@ const Dialog = {
36
36
  Title,
37
37
  Description,
38
38
  Close
39
- };
39
+ });
40
40
  function AlertRoot({ children, ...props }) {
41
41
  const controller = useController(createAlertDialog, props);
42
42
  return /* @__PURE__ */ jsx(Context.Provider, {
@@ -45,10 +45,10 @@ function AlertRoot({ children, ...props }) {
45
45
  });
46
46
  }
47
47
  /** A dialog that asks for an answer: a press outside it does not close it. Its parts are a dialog's. */
48
- const AlertDialog = {
48
+ const AlertDialog = /* @__PURE__ */ parts("AlertDialog", {
49
49
  ...Dialog,
50
50
  Root: AlertRoot
51
- };
51
+ });
52
52
  function DrawerRoot({ children, ...props }) {
53
53
  const controller = useController(createDrawer, props);
54
54
  return /* @__PURE__ */ jsx(Context.Provider, {
@@ -56,11 +56,15 @@ function DrawerRoot({ children, ...props }) {
56
56
  children
57
57
  });
58
58
  }
59
+ const DrawerBackdrop = Dialog.Backdrop;
60
+ const DrawerPopup = Dialog.Popup;
59
61
  /** A dialog that comes from an edge and is dragged back to it. Its parts are a dialog's. */
60
- const Drawer = {
62
+ const Drawer = /* @__PURE__ */ parts("Drawer", {
61
63
  ...Dialog,
62
- Root: DrawerRoot
63
- };
64
+ Root: DrawerRoot,
65
+ Backdrop: DrawerBackdrop,
66
+ Popup: DrawerPopup
67
+ });
64
68
  export { AlertDialog, Dialog, Drawer };
65
69
 
66
70
  //# sourceMappingURL=dialog.js.map
package/src/dialog.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"dialog.js","names":["BodyPortal"],"sources":["../../../../packages/react/src/dialog.tsx"],"sourcesContent":["import { createAlertDialog } from \"@kirana-ui/core/alert-dialog\"\nimport type { AlertDialogProps } from \"@kirana-ui/core/alert-dialog\"\nimport { createDialog } from \"@kirana-ui/core/dialog\"\nimport { createDrawer } from \"@kirana-ui/core/drawer\"\nimport type { DrawerProps } from \"@kirana-ui/core/drawer\"\nimport type { Dialog as Controller, DialogProps } from \"@kirana-ui/core/dialog\"\nimport { createContext, useContext } from \"react\"\nimport type { ReactElement, ReactNode } from \"react\"\n\nimport { Portal as BodyPortal, useController, usePart, useSignal } from \"./runtime.tsx\"\nimport type { PartComponentProps } from \"./runtime.tsx\"\n\nconst Context = createContext<Controller | null>(null)\n\nfunction useDialog(part: string): Controller {\n const controller = useContext(Context)\n if (!controller) throw new Error(`<Dialog.${part}> must be inside <Dialog.Root>`)\n return controller\n}\n\nexport type RootProps = Omit<DialogProps, \"id\"> & { id?: string; children?: ReactNode }\n\nfunction Root({ children, ...props }: RootProps): ReactElement {\n const controller = useController(createDialog, props)\n return <Context.Provider value={controller}>{children}</Context.Provider>\n}\n\nfunction Portal({ children }: { children?: ReactNode }): ReactElement | null {\n const mounted = useSignal(useDialog(\"Portal\").mounted)\n return mounted ? <BodyPortal>{children}</BodyPortal> : null\n}\n\nconst Trigger = (props: PartComponentProps) =>\n usePart(useDialog(\"Trigger\").trigger, \"button\", props)\nconst Backdrop = (props: PartComponentProps) =>\n usePart(useDialog(\"Backdrop\").backdrop, \"div\", props)\nconst Popup = (props: PartComponentProps) => usePart(useDialog(\"Popup\").popup, \"div\", props)\nconst Title = (props: PartComponentProps) => usePart(useDialog(\"Title\").title, \"h2\", props)\nconst Description = (props: PartComponentProps) =>\n usePart(useDialog(\"Description\").description, \"p\", props)\nconst Close = (props: PartComponentProps) => usePart(useDialog(\"Close\").close, \"button\", props)\n\nexport const Dialog = { Root, Trigger, Portal, Backdrop, Popup, Title, Description, Close }\n\nexport type AlertRootProps = Omit<AlertDialogProps, \"id\"> & { id?: string; children?: ReactNode }\n\nfunction AlertRoot({ children, ...props }: AlertRootProps): ReactElement {\n const controller = useController(createAlertDialog, props)\n return <Context.Provider value={controller}>{children}</Context.Provider>\n}\n\n/** A dialog that asks for an answer: a press outside it does not close it. Its parts are a dialog's. */\nexport const AlertDialog = { ...Dialog, Root: AlertRoot }\n\nexport type DrawerRootProps = Omit<DrawerProps, \"id\"> & { id?: string; children?: ReactNode }\n\nfunction DrawerRoot({ children, ...props }: DrawerRootProps): ReactElement {\n const controller = useController(createDrawer, props)\n return <Context.Provider value={controller}>{children}</Context.Provider>\n}\n\n/** A dialog that comes from an edge and is dragged back to it. Its parts are a dialog's. */\nexport const Drawer = { ...Dialog, Root: DrawerRoot }\n"],"mappings":";;;;;;;AAYA,MAAM,UAAU,cAAiC,IAAI;AAErD,SAAS,UAAU,MAA0B;CAC3C,MAAM,aAAa,WAAW,OAAO;CACrC,IAAI,CAAC,YAAY,MAAM,IAAI,MAAM,WAAW,KAAK,+BAA+B;CAChF,OAAO;AACT;AAIA,SAAS,KAAK,EAAE,UAAU,GAAG,SAAkC;CAC7D,MAAM,aAAa,cAAc,cAAc,KAAK;CACpD,OAAO,oBAAC,QAAQ,UAAT;EAAkB,OAAO;EAAa;CAA2B,CAAA;AAC1E;AAEA,SAAS,OAAO,EAAE,YAA2D;CAE3E,OADgB,UAAU,UAAU,QAAQ,CAAC,CAAC,OACjC,IAAI,oBAACA,UAAD,EAAa,SAAqB,CAAA,IAAI;AACzD;AAEA,MAAM,WAAW,UACf,QAAQ,UAAU,SAAS,CAAC,CAAC,SAAS,UAAU,KAAK;AACvD,MAAM,YAAY,UAChB,QAAQ,UAAU,UAAU,CAAC,CAAC,UAAU,OAAO,KAAK;AACtD,MAAM,SAAS,UAA8B,QAAQ,UAAU,OAAO,CAAC,CAAC,OAAO,OAAO,KAAK;AAC3F,MAAM,SAAS,UAA8B,QAAQ,UAAU,OAAO,CAAC,CAAC,OAAO,MAAM,KAAK;AAC1F,MAAM,eAAe,UACnB,QAAQ,UAAU,aAAa,CAAC,CAAC,aAAa,KAAK,KAAK;AAC1D,MAAM,SAAS,UAA8B,QAAQ,UAAU,OAAO,CAAC,CAAC,OAAO,UAAU,KAAK;AAE9F,MAAa,SAAS;CAAE;CAAM;CAAS;CAAQ;CAAU;CAAO;CAAO;CAAa;AAAM;AAI1F,SAAS,UAAU,EAAE,UAAU,GAAG,SAAuC;CACvE,MAAM,aAAa,cAAc,mBAAmB,KAAK;CACzD,OAAO,oBAAC,QAAQ,UAAT;EAAkB,OAAO;EAAa;CAA2B,CAAA;AAC1E;;AAGA,MAAa,cAAc;CAAE,GAAG;CAAQ,MAAM;AAAU;AAIxD,SAAS,WAAW,EAAE,UAAU,GAAG,SAAwC;CACzE,MAAM,aAAa,cAAc,cAAc,KAAK;CACpD,OAAO,oBAAC,QAAQ,UAAT;EAAkB,OAAO;EAAa;CAA2B,CAAA;AAC1E;;AAGA,MAAa,SAAS;CAAE,GAAG;CAAQ,MAAM;AAAW"}
1
+ {"version":3,"file":"dialog.js","names":["BodyPortal"],"sources":["../../../../packages/react/src/dialog.tsx"],"sourcesContent":["import type { StateOf } from \"@kirana-ui/core\"\nimport { createAlertDialog } from \"@kirana-ui/core/alert-dialog\"\nimport type { AlertDialogProps } from \"@kirana-ui/core/alert-dialog\"\nimport { createDialog } from \"@kirana-ui/core/dialog\"\nimport { createDrawer } from \"@kirana-ui/core/drawer\"\nimport type { DrawerProps } from \"@kirana-ui/core/drawer\"\nimport type { Dialog as Controller, DialogProps } from \"@kirana-ui/core/dialog\"\nimport type { Vocabulary } from \"@kirana-ui/core/vocabulary\"\nimport { createContext, useContext } from \"react\"\nimport type { ReactElement, ReactNode } from \"react\"\n\nimport { Portal as BodyPortal, parts, useController, usePart, useSignal } from \"./runtime.tsx\"\nimport type { PartComponentProps, PortalProps } from \"./runtime.tsx\"\n\nexport type { PortalProps }\n\ntype Parts = Vocabulary[\"dialog\"]\n\nconst Context = createContext<Controller | null>(null)\n\nfunction useDialog(part: string): Controller {\n const controller = useContext(Context)\n if (!controller) throw new Error(`<Dialog.${part}> must be inside <Dialog.Root>`)\n return controller\n}\n\nexport type RootProps = Omit<DialogProps, \"id\"> & { id?: string; children?: ReactNode }\n\nfunction Root({ children, ...props }: RootProps): ReactElement {\n const controller = useController(createDialog, props)\n return <Context.Provider value={controller}>{children}</Context.Provider>\n}\n\nfunction Portal({ children }: PortalProps): ReactElement | null {\n const mounted = useSignal(useDialog(\"Portal\").mounted)\n return mounted ? <BodyPortal>{children}</BodyPortal> : null\n}\n\nexport type TriggerProps = PartComponentProps<\"button\", StateOf<Parts[\"trigger\"]>>\nexport type BackdropProps = PartComponentProps<\"div\", StateOf<Parts[\"backdrop\"]>>\nexport type PopupProps = PartComponentProps<\"div\", StateOf<Parts[\"popup\"]>>\nexport type TitleProps = PartComponentProps<\"h2\", StateOf<Parts[\"title\"]>>\nexport type DescriptionProps = PartComponentProps<\"p\", StateOf<Parts[\"description\"]>>\nexport type CloseProps = PartComponentProps<\"button\", StateOf<Parts[\"close\"]>>\n\nconst Trigger = (props: TriggerProps) => usePart(useDialog(\"Trigger\").trigger, \"button\", props)\nconst Backdrop = (props: BackdropProps) => usePart(useDialog(\"Backdrop\").backdrop, \"div\", props)\nconst Popup = (props: PopupProps) => usePart(useDialog(\"Popup\").popup, \"div\", props)\nconst Title = (props: TitleProps) => usePart(useDialog(\"Title\").title, \"h2\", props)\nconst Description = (props: DescriptionProps) =>\n usePart(useDialog(\"Description\").description, \"p\", props)\nconst Close = (props: CloseProps) => usePart(useDialog(\"Close\").close, \"button\", props)\n\nexport const Dialog = /* @__PURE__ */ parts(\"Dialog\", {\n Root,\n Trigger,\n Portal,\n Backdrop,\n Popup,\n Title,\n Description,\n Close,\n})\n\nexport type AlertRootProps = Omit<AlertDialogProps, \"id\"> & { id?: string; children?: ReactNode }\n\nfunction AlertRoot({ children, ...props }: AlertRootProps): ReactElement {\n const controller = useController(createAlertDialog, props)\n return <Context.Provider value={controller}>{children}</Context.Provider>\n}\n\n/** A dialog that asks for an answer: a press outside it does not close it. Its parts are a dialog's. */\nexport const AlertDialog = /* @__PURE__ */ parts(\"AlertDialog\", { ...Dialog, Root: AlertRoot })\n\nexport type DrawerRootProps = Omit<DrawerProps, \"id\"> & { id?: string; children?: ReactNode }\n\nfunction DrawerRoot({ children, ...props }: DrawerRootProps): ReactElement {\n const controller = useController(createDrawer, props)\n return <Context.Provider value={controller}>{children}</Context.Provider>\n}\n\ntype DrawerParts = Vocabulary[\"drawer\"]\n\nexport type DrawerBackdropProps = PartComponentProps<\"div\", StateOf<DrawerParts[\"backdrop\"]>>\nexport type DrawerPopupProps = PartComponentProps<\"div\", StateOf<DrawerParts[\"popup\"]>>\n\n// A dialog's, which a drawer's controller gives more to say: how far it has been dragged.\nconst DrawerBackdrop: (props: DrawerBackdropProps) => ReactElement = Dialog.Backdrop\nconst DrawerPopup: (props: DrawerPopupProps) => ReactElement = Dialog.Popup\n\n/** A dialog that comes from an edge and is dragged back to it. Its parts are a dialog's. */\nexport const Drawer = /* @__PURE__ */ parts(\"Drawer\", {\n ...Dialog,\n Root: DrawerRoot,\n Backdrop: DrawerBackdrop,\n Popup: DrawerPopup,\n})\n"],"mappings":";;;;;;;AAkBA,MAAM,UAAU,cAAiC,IAAI;AAErD,SAAS,UAAU,MAA0B;CAC3C,MAAM,aAAa,WAAW,OAAO;CACrC,IAAI,CAAC,YAAY,MAAM,IAAI,MAAM,WAAW,KAAK,+BAA+B;CAChF,OAAO;AACT;AAIA,SAAS,KAAK,EAAE,UAAU,GAAG,SAAkC;CAC7D,MAAM,aAAa,cAAc,cAAc,KAAK;CACpD,OAAO,oBAAC,QAAQ,UAAT;EAAkB,OAAO;EAAa;CAA2B,CAAA;AAC1E;AAEA,SAAS,OAAO,EAAE,YAA8C;CAE9D,OADgB,UAAU,UAAU,QAAQ,CAAC,CAAC,OACjC,IAAI,oBAACA,UAAD,EAAa,SAAqB,CAAA,IAAI;AACzD;AASA,MAAM,WAAW,UAAwB,QAAQ,UAAU,SAAS,CAAC,CAAC,SAAS,UAAU,KAAK;AAC9F,MAAM,YAAY,UAAyB,QAAQ,UAAU,UAAU,CAAC,CAAC,UAAU,OAAO,KAAK;AAC/F,MAAM,SAAS,UAAsB,QAAQ,UAAU,OAAO,CAAC,CAAC,OAAO,OAAO,KAAK;AACnF,MAAM,SAAS,UAAsB,QAAQ,UAAU,OAAO,CAAC,CAAC,OAAO,MAAM,KAAK;AAClF,MAAM,eAAe,UACnB,QAAQ,UAAU,aAAa,CAAC,CAAC,aAAa,KAAK,KAAK;AAC1D,MAAM,SAAS,UAAsB,QAAQ,UAAU,OAAO,CAAC,CAAC,OAAO,UAAU,KAAK;AAEtF,MAAa,SAAyB,sBAAM,UAAU;CACpD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAID,SAAS,UAAU,EAAE,UAAU,GAAG,SAAuC;CACvE,MAAM,aAAa,cAAc,mBAAmB,KAAK;CACzD,OAAO,oBAAC,QAAQ,UAAT;EAAkB,OAAO;EAAa;CAA2B,CAAA;AAC1E;;AAGA,MAAa,cAA8B,sBAAM,eAAe;CAAE,GAAG;CAAQ,MAAM;AAAU,CAAC;AAI9F,SAAS,WAAW,EAAE,UAAU,GAAG,SAAwC;CACzE,MAAM,aAAa,cAAc,cAAc,KAAK;CACpD,OAAO,oBAAC,QAAQ,UAAT;EAAkB,OAAO;EAAa;CAA2B,CAAA;AAC1E;AAQA,MAAM,iBAA+D,OAAO;AAC5E,MAAM,cAAyD,OAAO;;AAGtE,MAAa,SAAyB,sBAAM,UAAU;CACpD,GAAG;CACH,MAAM;CACN,UAAU;CACV,OAAO;AACT,CAAC"}
@@ -1,5 +1,6 @@
1
1
  import { Direction } from "@kirana-ui/core";
2
2
  import { ReactElement, ReactNode } from "react";
3
+ /** What `DirectionProvider` takes. */
3
4
  export interface DirectionProviderProps {
4
5
  /** The reading direction of what is inside. `ltr` when left out. */
5
6
  direction?: Direction;
@@ -1 +1 @@
1
- {"version":3,"file":"direction.js","names":[],"sources":["../../../../packages/react/src/direction.tsx"],"sourcesContent":["import { signal } from \"@kirana-ui/core\"\nimport type { Direction } from \"@kirana-ui/core\"\nimport { createDirection } from \"@kirana-ui/core/direction\"\nimport { useContext, useState } from \"react\"\nimport type { ReactElement, ReactNode } from \"react\"\n\nimport { DirectionContext } from \"./direction-context.ts\"\nimport { useController, useSignal } from \"./runtime.tsx\"\n\nexport interface DirectionProviderProps {\n /** The reading direction of what is inside. `ltr` when left out. */\n direction?: Direction\n children?: ReactNode\n}\n\n/**\n * States the reading direction for the components inside. It draws nothing: set the page's own\n * `dir` attribute with it.\n */\nexport function DirectionProvider({ direction, children }: DirectionProviderProps): ReactElement {\n const controller = useController(createDirection, { direction })\n return (\n <DirectionContext.Provider value={controller.direction}>{children}</DirectionContext.Provider>\n )\n}\n\n/** The direction the nearest provider states; `ltr` outside one. */\nexport function useDirection(): Direction {\n const given = useContext(DirectionContext)\n const [fallback] = useState(() => signal<Direction>(\"ltr\"))\n return useSignal(given ?? fallback)\n}\n"],"mappings":";;;;;;;;;;;AAmBA,SAAgB,kBAAkB,EAAE,WAAW,YAAkD;CAC/F,MAAM,aAAa,cAAc,iBAAiB,EAAE,UAAU,CAAC;CAC/D,OACE,oBAAC,iBAAiB,UAAlB;EAA2B,OAAO,WAAW;EAAY;CAAoC,CAAA;AAEjG;;AAGA,SAAgB,eAA0B;CACxC,MAAM,QAAQ,WAAW,gBAAgB;CACzC,MAAM,CAAC,YAAY,eAAe,OAAkB,KAAK,CAAC;CAC1D,OAAO,UAAU,SAAS,QAAQ;AACpC"}
1
+ {"version":3,"file":"direction.js","names":[],"sources":["../../../../packages/react/src/direction.tsx"],"sourcesContent":["import { signal } from \"@kirana-ui/core\"\nimport type { Direction } from \"@kirana-ui/core\"\nimport { createDirection } from \"@kirana-ui/core/direction\"\nimport { useContext, useState } from \"react\"\nimport type { ReactElement, ReactNode } from \"react\"\n\nimport { DirectionContext } from \"./direction-context.ts\"\nimport { useController, useSignal } from \"./runtime.tsx\"\n\n/** What `DirectionProvider` takes. */\nexport interface DirectionProviderProps {\n /** The reading direction of what is inside. `ltr` when left out. */\n direction?: Direction\n children?: ReactNode\n}\n\n/**\n * States the reading direction for the components inside. It draws nothing: set the page's own\n * `dir` attribute with it.\n */\nexport function DirectionProvider({ direction, children }: DirectionProviderProps): ReactElement {\n const controller = useController(createDirection, { direction })\n return (\n <DirectionContext.Provider value={controller.direction}>{children}</DirectionContext.Provider>\n )\n}\n\n/** The direction the nearest provider states; `ltr` outside one. */\nexport function useDirection(): Direction {\n const given = useContext(DirectionContext)\n const [fallback] = useState(() => signal<Direction>(\"ltr\"))\n return useSignal(given ?? fallback)\n}\n"],"mappings":";;;;;;;;;;;AAoBA,SAAgB,kBAAkB,EAAE,WAAW,YAAkD;CAC/F,MAAM,aAAa,cAAc,iBAAiB,EAAE,UAAU,CAAC;CAC/D,OACE,oBAAC,iBAAiB,UAAlB;EAA2B,OAAO,WAAW;EAAY;CAAoC,CAAA;AAEjG;;AAGA,SAAgB,eAA0B;CACxC,MAAM,QAAQ,WAAW,gBAAgB;CACzC,MAAM,CAAC,YAAY,eAAe,OAAkB,KAAK,CAAC;CAC1D,OAAO,UAAU,SAAS,QAAQ;AACpC"}
package/src/drawer.d.ts CHANGED
@@ -1,2 +1,3 @@
1
- import { Drawer } from "./dialog.js";
2
- export { Drawer };
1
+ import { PortalProps } from "./runtime.js";
2
+ import { CloseProps, DescriptionProps, Drawer, DrawerBackdropProps, DrawerPopupProps, DrawerRootProps, TitleProps, TriggerProps } from "./dialog.js";
3
+ export { type DrawerBackdropProps as BackdropProps, type CloseProps, type DescriptionProps, Drawer, type DrawerPopupProps as PopupProps, type PortalProps, type DrawerRootProps as RootProps, type TitleProps, type TriggerProps };
@@ -0,0 +1,12 @@
1
+ import { ReactElement, Ref } from "react";
2
+ /**
3
+ * React 19 keeps a ref among the props, an element's and a component's alike. Before, an
4
+ * element's ref was on the element (reading it there now warns), and a component was given
5
+ * its own only through `forwardRef`.
6
+ */
7
+ export declare const REF_IS_A_PROP: boolean;
8
+ /** The ref a caller put on an element it handed over as `render`. */
9
+ export declare function refOf(element: ReactElement): Ref<HTMLElement> | undefined;
10
+ /** Hands an element to a ref, whichever kind it is. */
11
+ export declare function give(ref: Ref<HTMLElement> | undefined, element: HTMLElement | null): void;
12
+ //# sourceMappingURL=element.d.ts.map
package/src/element.js ADDED
@@ -0,0 +1,20 @@
1
+ import { version } from "react";
2
+ // src/element.ts
3
+ /**
4
+ * React 19 keeps a ref among the props, an element's and a component's alike. Before, an
5
+ * element's ref was on the element (reading it there now warns), and a component was given
6
+ * its own only through `forwardRef`.
7
+ */
8
+ const REF_IS_A_PROP = Number.parseInt(version, 10) >= 19;
9
+ /** The ref a caller put on an element it handed over as `render`. */
10
+ function refOf(element) {
11
+ return REF_IS_A_PROP ? element.props.ref : element.ref;
12
+ }
13
+ /** Hands an element to a ref, whichever kind it is. */
14
+ function give(ref, element) {
15
+ if (typeof ref === "function") ref(element);
16
+ else if (ref) ref.current = element;
17
+ }
18
+ export { REF_IS_A_PROP, give, refOf };
19
+
20
+ //# sourceMappingURL=element.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"element.js","names":[],"sources":["../../../../packages/react/src/element.ts"],"sourcesContent":["import { version } from \"react\"\nimport type { ReactElement, Ref } from \"react\"\n\n/**\n * React 19 keeps a ref among the props, an element's and a component's alike. Before, an\n * element's ref was on the element (reading it there now warns), and a component was given\n * its own only through `forwardRef`.\n */\nexport const REF_IS_A_PROP = Number.parseInt(version, 10) >= 19\n\n/** The ref a caller put on an element it handed over as `render`. */\nexport function refOf(element: ReactElement): Ref<HTMLElement> | undefined {\n return REF_IS_A_PROP\n ? (element.props as { ref?: Ref<HTMLElement> }).ref\n : (element as { ref?: Ref<HTMLElement> }).ref\n}\n\n/** Hands an element to a ref, whichever kind it is. */\nexport function give(ref: Ref<HTMLElement> | undefined, element: HTMLElement | null): void {\n if (typeof ref === \"function\") ref(element)\n else if (ref) (ref as { current: HTMLElement | null }).current = element\n}\n"],"mappings":";;;;;;;AAQA,MAAa,gBAAgB,OAAO,SAAS,SAAS,EAAE,KAAK;;AAG7D,SAAgB,MAAM,SAAqD;CACzE,OAAO,gBACF,QAAQ,MAAqC,MAC7C,QAAuC;AAC9C;;AAGA,SAAgB,KAAK,KAAmC,SAAmC;CACzF,IAAI,OAAO,QAAQ,YAAY,IAAI,OAAO;MACrC,IAAI,KAAK,IAAyC,UAAU;AACnE"}
package/src/field.d.ts CHANGED
@@ -1,31 +1,39 @@
1
1
  import { PartComponentProps } from "./runtime.js";
2
+ import { StateOf } from "@kirana-ui/core";
2
3
  import { ReactElement, ReactNode } from "react";
3
4
  import { FieldProps, FieldValidity, ValidityKey } from "@kirana-ui/core/field";
4
- export type RootProps = Omit<FieldProps, "id"> & {
5
+ import { Vocabulary } from "@kirana-ui/core/vocabulary";
6
+ type Parts = Vocabulary["field"];
7
+ export type RootProps = PartComponentProps<"div", StateOf<Parts["root"]>, Omit<FieldProps, "id"> & {
5
8
  id?: string;
6
- } & PartComponentProps;
9
+ }>;
7
10
  declare function Root({ name, disabled, invalid, validate, validationMode, validationDebounceTime, id, ...rest }: RootProps): ReactElement;
8
- declare const Label: (props: PartComponentProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
11
+ export type LabelProps = PartComponentProps<"label", StateOf<Parts["label"]>>;
12
+ export type ControlProps = PartComponentProps<"input", StateOf<Parts["control"]>>;
13
+ export type DescriptionProps = PartComponentProps<"p", StateOf<Parts["description"]>>;
14
+ declare const Label: (props: LabelProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
9
15
  /** An `<input>`; a `<textarea>` or a `<select>` through `render`. */
10
- declare const Control: (props: PartComponentProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
11
- declare const Description: (props: PartComponentProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
12
- export interface ErrorProps extends PartComponentProps {
16
+ declare const Control: (props: ControlProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
17
+ declare const Description: (props: DescriptionProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
18
+ export type ErrorProps = PartComponentProps<"div", StateOf<Parts["error"]>, {
13
19
  /** One of the browser's findings (`"valueMissing"`) to show for only that; `true` to show always. */
14
20
  match?: ValidityKey | boolean;
15
- }
21
+ }>;
16
22
  /** What is wrong, or `children` in its place. In the page while it applies. */
17
23
  declare function FieldError({ match, children, ...rest }: ErrorProps): ReactElement | null;
18
- /** Draws nothing itself: `children` is given the field's validity. */
19
- declare function Validity({ children }: {
24
+ export interface ValidityProps {
25
+ /** Draws from the field's validity: whether it is valid, what was found wrong, the messages. */
20
26
  children: (validity: FieldValidity) => ReactNode;
21
- }): ReactNode;
27
+ }
28
+ /** Draws nothing itself: `children` is given the field's validity. */
29
+ declare function Validity({ children }: ValidityProps): ReactNode;
22
30
  export declare const Field: {
23
- Root: typeof Root;
24
- Label: typeof Label;
25
- Control: typeof Control;
26
- Description: typeof Description;
27
- Error: typeof FieldError;
28
- Validity: typeof Validity;
31
+ readonly Root: typeof Root;
32
+ readonly Label: typeof Label;
33
+ readonly Control: typeof Control;
34
+ readonly Description: typeof Description;
35
+ readonly Error: typeof FieldError;
36
+ readonly Validity: typeof Validity;
29
37
  };
30
38
  export {};
31
39
  //# sourceMappingURL=field.d.ts.map
package/src/field.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { FieldContext } from "./field-context.js";
2
2
  import { FieldsetContext } from "./fieldset.js";
3
3
  import { FormContext } from "./form.js";
4
- import { useController, useMount, useOptions, usePart, useSignal } from "./runtime.js";
4
+ import { PartElement, parts, useController, useMount, useOptions, usePart, useSignal } from "./runtime.js";
5
5
  import { useContext, useMemo } from "react";
6
6
  import { jsx } from "react/jsx-runtime";
7
7
  import { createField } from "@kirana-ui/core/field";
@@ -29,15 +29,17 @@ function Root({ name, disabled, invalid, validate, validationMode, validationDeb
29
29
  });
30
30
  return /* @__PURE__ */ jsx(FieldContext.Provider, {
31
31
  value: controller,
32
- children: /* @__PURE__ */ jsx(RootElement, { ...rest })
32
+ children: /* @__PURE__ */ jsx(PartElement, {
33
+ of: controller.root,
34
+ tag: "div",
35
+ ...rest
36
+ })
33
37
  });
34
38
  }
35
- const RootElement = (props) => usePart(useField("Root").root, "div", props);
36
39
  const Label = (props) => usePart(useField("Label").label, "label", props);
37
40
  /** An `<input>`; a `<textarea>` or a `<select>` through `render`. */
38
41
  const Control = (props) => usePart(useField("Control").control, "input", props);
39
42
  const Description = (props) => usePart(useField("Description").description, "p", props);
40
- const PartElement = ({ part, tag, ...props }) => usePart(part, tag, props);
41
43
  /** What is wrong, or `children` in its place. In the page while it applies. */
42
44
  function FieldError({ match, children, ...rest }) {
43
45
  const controller = useField("Error");
@@ -48,7 +50,7 @@ function FieldError({ match, children, ...rest }) {
48
50
  const text = useSignal(error.text);
49
51
  if (!mounted) return null;
50
52
  return /* @__PURE__ */ jsx(PartElement, {
51
- part: error.part,
53
+ of: error.part,
52
54
  tag: "div",
53
55
  ...rest,
54
56
  children: children ?? text
@@ -58,14 +60,14 @@ function FieldError({ match, children, ...rest }) {
58
60
  function Validity({ children }) {
59
61
  return children(useSignal(useField("Validity").validity));
60
62
  }
61
- const Field = {
63
+ const Field = /* @__PURE__ */ parts("Field", {
62
64
  Root,
63
65
  Label,
64
66
  Control,
65
67
  Description,
66
68
  Error: FieldError,
67
69
  Validity
68
- };
70
+ });
69
71
  export { Field };
70
72
 
71
73
  //# sourceMappingURL=field.js.map
package/src/field.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"field.js","names":[],"sources":["../../../../packages/react/src/field.tsx"],"sourcesContent":["import type { Part, ReadonlySignal } from \"@kirana-ui/core\"\nimport { createField } from \"@kirana-ui/core/field\"\nimport type {\n Field as Controller,\n FieldProps,\n FieldValidity,\n ValidityKey,\n} from \"@kirana-ui/core/field\"\nimport { useContext, useMemo } from \"react\"\nimport type { ReactElement, ReactNode } from \"react\"\n\nimport { FieldContext } from \"./field-context.ts\"\nimport { FieldsetContext } from \"./fieldset.tsx\"\nimport { FormContext } from \"./form.tsx\"\nimport { useController, useMount, useOptions, usePart, useSignal } from \"./runtime.tsx\"\nimport type { PartComponentProps } from \"./runtime.tsx\"\n\nfunction useField(part: string): Controller {\n const controller = useContext(FieldContext)\n if (!controller) throw new Error(`<Field.${part}> must be inside <Field.Root>`)\n return controller\n}\n\nexport type RootProps = Omit<FieldProps, \"id\"> & { id?: string } & PartComponentProps\n\nfunction Root({\n name,\n disabled,\n invalid,\n validate,\n validationMode,\n validationDebounceTime,\n id,\n ...rest\n}: RootProps): ReactElement {\n const form = useContext(FormContext) ?? undefined\n const fieldset = useContext(FieldsetContext) ?? undefined\n const create = useMemo(\n () => (props: ReadonlySignal<FieldProps>) => createField(props, { form, fieldset }),\n [form, fieldset]\n )\n const controller = useController(create, {\n name,\n disabled,\n invalid,\n validate,\n validationMode,\n validationDebounceTime,\n id,\n })\n return (\n <FieldContext.Provider value={controller}>\n <RootElement {...rest} />\n </FieldContext.Provider>\n )\n}\n\nconst RootElement = (props: PartComponentProps) => usePart(useField(\"Root\").root, \"div\", props)\nconst Label = (props: PartComponentProps) => usePart(useField(\"Label\").label, \"label\", props)\n/** An `<input>`; a `<textarea>` or a `<select>` through `render`. */\nconst Control = (props: PartComponentProps) => usePart(useField(\"Control\").control, \"input\", props)\nconst Description = (props: PartComponentProps) =>\n usePart(useField(\"Description\").description, \"p\", props)\n\nconst PartElement = ({ part, tag, ...props }: PartComponentProps & { part: Part; tag: string }) =>\n usePart(part, tag, props)\n\nexport interface ErrorProps extends PartComponentProps {\n /** One of the browser's findings (`\"valueMissing\"`) to show for only that; `true` to show always. */\n match?: ValidityKey | boolean\n}\n\n/** What is wrong, or `children` in its place. In the page while it applies. */\nfunction FieldError({ match, children, ...rest }: ErrorProps): ReactElement | null {\n const controller = useField(\"Error\")\n const options = useOptions({ match })\n const error = useMemo(() => controller.error(() => options.get().match), [controller, options])\n useMount(error)\n const mounted = useSignal(error.mounted)\n const text = useSignal(error.text)\n if (!mounted) return null\n return (\n <PartElement part={error.part} tag=\"div\" {...rest}>\n {children ?? text}\n </PartElement>\n )\n}\n\n/** Draws nothing itself: `children` is given the field's validity. */\nfunction Validity({ children }: { children: (validity: FieldValidity) => ReactNode }): ReactNode {\n return children(useSignal(useField(\"Validity\").validity))\n}\n\nexport const Field = { Root, Label, Control, Description, Error: FieldError, Validity }\n"],"mappings":";;;;;;;;AAiBA,SAAS,SAAS,MAA0B;CAC1C,MAAM,aAAa,WAAW,YAAY;CAC1C,IAAI,CAAC,YAAY,MAAM,IAAI,MAAM,UAAU,KAAK,8BAA8B;CAC9E,OAAO;AACT;AAIA,SAAS,KAAK,EACZ,MACA,UACA,SACA,UACA,gBACA,wBACA,IACA,GAAG,QACuB;CAC1B,MAAM,OAAO,WAAW,WAAW,KAAK,KAAA;CACxC,MAAM,WAAW,WAAW,eAAe,KAAK,KAAA;CAChD,MAAM,SAAS,eACN,UAAsC,YAAY,OAAO;EAAE;EAAM;CAAS,CAAC,GAClF,CAAC,MAAM,QAAQ,CACjB;CACA,MAAM,aAAa,cAAc,QAAQ;EACvC;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;CACD,OACE,oBAAC,aAAa,UAAd;EAAuB,OAAO;EAC5B,UAAA,oBAAC,aAAD,EAAa,GAAI,KAAO,CAAA;CACH,CAAA;AAE3B;AAEA,MAAM,eAAe,UAA8B,QAAQ,SAAS,MAAM,CAAC,CAAC,MAAM,OAAO,KAAK;AAC9F,MAAM,SAAS,UAA8B,QAAQ,SAAS,OAAO,CAAC,CAAC,OAAO,SAAS,KAAK;;AAE5F,MAAM,WAAW,UAA8B,QAAQ,SAAS,SAAS,CAAC,CAAC,SAAS,SAAS,KAAK;AAClG,MAAM,eAAe,UACnB,QAAQ,SAAS,aAAa,CAAC,CAAC,aAAa,KAAK,KAAK;AAEzD,MAAM,eAAe,EAAE,MAAM,KAAK,GAAG,YACnC,QAAQ,MAAM,KAAK,KAAK;;AAQ1B,SAAS,WAAW,EAAE,OAAO,UAAU,GAAG,QAAyC;CACjF,MAAM,aAAa,SAAS,OAAO;CACnC,MAAM,UAAU,WAAW,EAAE,MAAM,CAAC;CACpC,MAAM,QAAQ,cAAc,WAAW,YAAY,QAAQ,IAAI,CAAC,CAAC,KAAK,GAAG,CAAC,YAAY,OAAO,CAAC;CAC9F,SAAS,KAAK;CACd,MAAM,UAAU,UAAU,MAAM,OAAO;CACvC,MAAM,OAAO,UAAU,MAAM,IAAI;CACjC,IAAI,CAAC,SAAS,OAAO;CACrB,OACE,oBAAC,aAAD;EAAa,MAAM,MAAM;EAAM,KAAI;EAAM,GAAI;EAC1C,UAAA,YAAY;CACF,CAAA;AAEjB;;AAGA,SAAS,SAAS,EAAE,YAA6E;CAC/F,OAAO,SAAS,UAAU,SAAS,UAAU,CAAC,CAAC,QAAQ,CAAC;AAC1D;AAEA,MAAa,QAAQ;CAAE;CAAM;CAAO;CAAS;CAAa,OAAO;CAAY;AAAS"}
1
+ {"version":3,"file":"field.js","names":[],"sources":["../../../../packages/react/src/field.tsx"],"sourcesContent":["import type { ReadonlySignal, StateOf } from \"@kirana-ui/core\"\nimport { createField } from \"@kirana-ui/core/field\"\nimport type {\n Field as Controller,\n FieldProps,\n FieldValidity,\n ValidityKey,\n} from \"@kirana-ui/core/field\"\nimport type { Vocabulary } from \"@kirana-ui/core/vocabulary\"\nimport { useContext, useMemo } from \"react\"\nimport type { ReactElement, ReactNode } from \"react\"\n\nimport { FieldContext } from \"./field-context.ts\"\nimport { FieldsetContext } from \"./fieldset.tsx\"\nimport { FormContext } from \"./form.tsx\"\nimport {\n PartElement,\n parts,\n useController,\n useMount,\n useOptions,\n usePart,\n useSignal,\n} from \"./runtime.tsx\"\nimport type { PartComponentProps } from \"./runtime.tsx\"\n\ntype Parts = Vocabulary[\"field\"]\n\nfunction useField(part: string): Controller {\n const controller = useContext(FieldContext)\n if (!controller) throw new Error(`<Field.${part}> must be inside <Field.Root>`)\n return controller\n}\n\nexport type RootProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"root\"]>,\n Omit<FieldProps, \"id\"> & { id?: string }\n>\n\nfunction Root({\n name,\n disabled,\n invalid,\n validate,\n validationMode,\n validationDebounceTime,\n id,\n ...rest\n}: RootProps): ReactElement {\n const form = useContext(FormContext) ?? undefined\n const fieldset = useContext(FieldsetContext) ?? undefined\n const create = useMemo(\n () => (props: ReadonlySignal<FieldProps>) => createField(props, { form, fieldset }),\n [form, fieldset]\n )\n const controller = useController(create, {\n name,\n disabled,\n invalid,\n validate,\n validationMode,\n validationDebounceTime,\n id,\n })\n return (\n <FieldContext.Provider value={controller}>\n <PartElement of={controller.root} tag=\"div\" {...rest} />\n </FieldContext.Provider>\n )\n}\n\nexport type LabelProps = PartComponentProps<\"label\", StateOf<Parts[\"label\"]>>\nexport type ControlProps = PartComponentProps<\"input\", StateOf<Parts[\"control\"]>>\nexport type DescriptionProps = PartComponentProps<\"p\", StateOf<Parts[\"description\"]>>\n\nconst Label = (props: LabelProps) => usePart(useField(\"Label\").label, \"label\", props)\n/** An `<input>`; a `<textarea>` or a `<select>` through `render`. */\nconst Control = (props: ControlProps) => usePart(useField(\"Control\").control, \"input\", props)\nconst Description = (props: DescriptionProps) =>\n usePart(useField(\"Description\").description, \"p\", props)\n\nexport type ErrorProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"error\"]>,\n {\n /** One of the browser's findings (`\"valueMissing\"`) to show for only that; `true` to show always. */\n match?: ValidityKey | boolean\n }\n>\n\n/** What is wrong, or `children` in its place. In the page while it applies. */\nfunction FieldError({ match, children, ...rest }: ErrorProps): ReactElement | null {\n const controller = useField(\"Error\")\n const options = useOptions({ match })\n const error = useMemo(() => controller.error(() => options.get().match), [controller, options])\n useMount(error)\n const mounted = useSignal(error.mounted)\n const text = useSignal(error.text)\n if (!mounted) return null\n return (\n <PartElement of={error.part} tag=\"div\" {...rest}>\n {children ?? text}\n </PartElement>\n )\n}\n\nexport interface ValidityProps {\n /** Draws from the field's validity: whether it is valid, what was found wrong, the messages. */\n children: (validity: FieldValidity) => ReactNode\n}\n\n/** Draws nothing itself: `children` is given the field's validity. */\nfunction Validity({ children }: ValidityProps): ReactNode {\n return children(useSignal(useField(\"Validity\").validity))\n}\n\nexport const Field = /* @__PURE__ */ parts(\"Field\", {\n Root,\n Label,\n Control,\n Description,\n Error: FieldError,\n Validity,\n})\n"],"mappings":";;;;;;;;AA4BA,SAAS,SAAS,MAA0B;CAC1C,MAAM,aAAa,WAAW,YAAY;CAC1C,IAAI,CAAC,YAAY,MAAM,IAAI,MAAM,UAAU,KAAK,8BAA8B;CAC9E,OAAO;AACT;AAQA,SAAS,KAAK,EACZ,MACA,UACA,SACA,UACA,gBACA,wBACA,IACA,GAAG,QACuB;CAC1B,MAAM,OAAO,WAAW,WAAW,KAAK,KAAA;CACxC,MAAM,WAAW,WAAW,eAAe,KAAK,KAAA;CAChD,MAAM,SAAS,eACN,UAAsC,YAAY,OAAO;EAAE;EAAM;CAAS,CAAC,GAClF,CAAC,MAAM,QAAQ,CACjB;CACA,MAAM,aAAa,cAAc,QAAQ;EACvC;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;CACD,OACE,oBAAC,aAAa,UAAd;EAAuB,OAAO;EAC5B,UAAA,oBAAC,aAAD;GAAa,IAAI,WAAW;GAAM,KAAI;GAAM,GAAI;EAAO,CAAA;CAClC,CAAA;AAE3B;AAMA,MAAM,SAAS,UAAsB,QAAQ,SAAS,OAAO,CAAC,CAAC,OAAO,SAAS,KAAK;;AAEpF,MAAM,WAAW,UAAwB,QAAQ,SAAS,SAAS,CAAC,CAAC,SAAS,SAAS,KAAK;AAC5F,MAAM,eAAe,UACnB,QAAQ,SAAS,aAAa,CAAC,CAAC,aAAa,KAAK,KAAK;;AAYzD,SAAS,WAAW,EAAE,OAAO,UAAU,GAAG,QAAyC;CACjF,MAAM,aAAa,SAAS,OAAO;CACnC,MAAM,UAAU,WAAW,EAAE,MAAM,CAAC;CACpC,MAAM,QAAQ,cAAc,WAAW,YAAY,QAAQ,IAAI,CAAC,CAAC,KAAK,GAAG,CAAC,YAAY,OAAO,CAAC;CAC9F,SAAS,KAAK;CACd,MAAM,UAAU,UAAU,MAAM,OAAO;CACvC,MAAM,OAAO,UAAU,MAAM,IAAI;CACjC,IAAI,CAAC,SAAS,OAAO;CACrB,OACE,oBAAC,aAAD;EAAa,IAAI,MAAM;EAAM,KAAI;EAAM,GAAI;EACxC,UAAA,YAAY;CACF,CAAA;AAEjB;;AAQA,SAAS,SAAS,EAAE,YAAsC;CACxD,OAAO,SAAS,UAAU,SAAS,UAAU,CAAC,CAAC,QAAQ,CAAC;AAC1D;AAEA,MAAa,QAAwB,sBAAM,SAAS;CAClD;CACA;CACA;CACA;CACA,OAAO;CACP;AACF,CAAC"}