@jcsoftdev/ui 0.3.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 (268) hide show
  1. package/CHANGELOG.md +103 -1
  2. package/README.md +55 -2
  3. package/bin/ui-theme.mjs +13 -2
  4. package/dist/atoms/checkbox/checkbox.js +3 -1
  5. package/dist/atoms/chip/chip.d.ts +11 -3
  6. package/dist/atoms/chip/chip.js +8 -1
  7. package/dist/atoms/chip/index.d.ts +1 -1
  8. package/dist/atoms/chip/index.js +2 -0
  9. package/dist/atoms/due-chip/due-chip.d.ts +31 -0
  10. package/dist/atoms/due-chip/due-chip.js +41 -0
  11. package/dist/atoms/due-chip/index.d.ts +2 -0
  12. package/dist/atoms/due-chip/index.js +6 -0
  13. package/dist/atoms/due-chip/model.d.ts +25 -0
  14. package/dist/atoms/due-chip/model.js +44 -0
  15. package/dist/atoms/icon-button/icon-button.d.ts +22 -0
  16. package/dist/atoms/icon-button/icon-button.js +38 -0
  17. package/dist/atoms/icon-button/index.d.ts +1 -0
  18. package/dist/atoms/icon-button/index.js +8 -0
  19. package/dist/atoms/index.d.ts +5 -0
  20. package/dist/atoms/index.js +5 -0
  21. package/dist/atoms/internal/hit-area.d.ts +6 -0
  22. package/dist/atoms/internal/hit-area.js +4 -0
  23. package/dist/atoms/kbd/index.d.ts +1 -0
  24. package/dist/atoms/kbd/index.js +4 -0
  25. package/dist/atoms/kbd/kbd.d.ts +7 -0
  26. package/dist/atoms/kbd/kbd.js +17 -0
  27. package/dist/atoms/radio-group/radio-group.js +6 -2
  28. package/dist/atoms/seal/index.d.ts +1 -0
  29. package/dist/atoms/seal/index.js +4 -0
  30. package/dist/atoms/seal/seal.d.ts +30 -0
  31. package/dist/atoms/seal/seal.js +71 -0
  32. package/dist/atoms/spinner/index.d.ts +1 -0
  33. package/dist/atoms/spinner/index.js +5 -0
  34. package/dist/atoms/spinner/spinner.d.ts +19 -0
  35. package/dist/atoms/spinner/spinner.js +31 -0
  36. package/dist/atoms/switch/switch.js +3 -1
  37. package/dist/calendar/date-calendar/date-calendar.d.ts +32 -0
  38. package/dist/calendar/date-calendar/date-calendar.js +189 -0
  39. package/dist/calendar/date-calendar/index.d.ts +1 -0
  40. package/dist/calendar/date-calendar/index.js +6 -0
  41. package/dist/calendar/index.d.ts +1 -0
  42. package/dist/calendar/index.js +1 -0
  43. package/dist/calendar/internal/date-utils.d.ts +26 -0
  44. package/dist/calendar/internal/date-utils.js +95 -1
  45. package/dist/containers/aside/aside.d.ts +14 -0
  46. package/dist/containers/aside/aside.js +25 -0
  47. package/dist/containers/aside/index.d.ts +1 -0
  48. package/dist/containers/aside/index.js +5 -0
  49. package/dist/containers/banner/banner.d.ts +4 -1
  50. package/dist/containers/banner/banner.js +9 -1
  51. package/dist/containers/description-list/description-list.d.ts +29 -6
  52. package/dist/containers/description-list/description-list.js +47 -6
  53. package/dist/containers/feed/feed.d.ts +23 -0
  54. package/dist/containers/feed/feed.js +77 -0
  55. package/dist/containers/feed/index.d.ts +2 -0
  56. package/dist/containers/feed/index.js +10 -0
  57. package/dist/containers/feed/model.d.ts +19 -0
  58. package/dist/containers/feed/model.js +38 -0
  59. package/dist/containers/index.d.ts +6 -0
  60. package/dist/containers/index.js +6 -0
  61. package/dist/containers/kpi/kpi.d.ts +50 -8
  62. package/dist/containers/kpi/kpi.js +91 -39
  63. package/dist/containers/list-detail/index.d.ts +1 -0
  64. package/dist/containers/list-detail/index.js +20 -0
  65. package/dist/containers/list-detail/list-detail.d.ts +55 -0
  66. package/dist/containers/list-detail/list-detail.js +221 -0
  67. package/dist/containers/note/index.d.ts +1 -0
  68. package/dist/containers/note/index.js +4 -0
  69. package/dist/containers/note/note.d.ts +13 -0
  70. package/dist/containers/note/note.js +27 -0
  71. package/dist/containers/section/index.d.ts +1 -0
  72. package/dist/containers/section/index.js +6 -0
  73. package/dist/containers/section/section.d.ts +68 -0
  74. package/dist/containers/section/section.js +198 -0
  75. package/dist/containers/shortcuts/index.d.ts +1 -0
  76. package/dist/containers/shortcuts/index.js +8 -0
  77. package/dist/containers/shortcuts/shortcuts.d.ts +18 -0
  78. package/dist/containers/shortcuts/shortcuts.js +50 -0
  79. package/dist/containers/table/selection.d.ts +9 -0
  80. package/dist/containers/table/selection.js +20 -0
  81. package/dist/containers/table/table.d.ts +66 -4
  82. package/dist/containers/table/table.js +128 -7
  83. package/dist/containers/timeline/index.d.ts +1 -1
  84. package/dist/containers/timeline/index.js +4 -2
  85. package/dist/containers/timeline/timeline.d.ts +32 -5
  86. package/dist/containers/timeline/timeline.js +154 -90
  87. package/dist/forms/chip-group/chip-group.d.ts +54 -0
  88. package/dist/forms/chip-group/chip-group.js +114 -0
  89. package/dist/forms/chip-group/index.d.ts +1 -0
  90. package/dist/forms/chip-group/index.js +6 -0
  91. package/dist/forms/combobox/combobox.d.ts +60 -0
  92. package/dist/forms/combobox/combobox.js +281 -0
  93. package/dist/forms/combobox/index.d.ts +1 -0
  94. package/dist/forms/combobox/index.js +6 -0
  95. package/dist/forms/date-picker/date-picker.d.ts +40 -0
  96. package/dist/forms/date-picker/date-picker.js +183 -0
  97. package/dist/forms/date-picker/date-time-picker.d.ts +43 -0
  98. package/dist/forms/date-picker/date-time-picker.js +121 -0
  99. package/dist/forms/date-picker/index.d.ts +2 -0
  100. package/dist/forms/date-picker/index.js +10 -0
  101. package/dist/forms/date-picker/model.d.ts +35 -0
  102. package/dist/forms/date-picker/model.js +83 -0
  103. package/dist/forms/dropzone/dropzone.d.ts +30 -2
  104. package/dist/forms/dropzone/dropzone.js +153 -23
  105. package/dist/forms/field/field.d.ts +16 -10
  106. package/dist/forms/field/field.js +41 -5
  107. package/dist/forms/index.d.ts +4 -0
  108. package/dist/forms/index.js +4 -0
  109. package/dist/forms/input/index.d.ts +1 -1
  110. package/dist/forms/input/index.js +4 -1
  111. package/dist/forms/input/input.d.ts +21 -5
  112. package/dist/forms/input/input.js +74 -9
  113. package/dist/forms/input-icon/input-icon.d.ts +1 -1
  114. package/dist/forms/internal/listbox-items.d.ts +18 -0
  115. package/dist/forms/internal/listbox-items.js +88 -0
  116. package/dist/forms/internal/listbox.d.ts +44 -0
  117. package/dist/forms/internal/listbox.js +74 -0
  118. package/dist/forms/number-stepper/model.d.ts +16 -0
  119. package/dist/forms/number-stepper/model.js +23 -0
  120. package/dist/forms/number-stepper/number-stepper.d.ts +36 -6
  121. package/dist/forms/number-stepper/number-stepper.js +86 -37
  122. package/dist/forms/select-menu/index.d.ts +1 -0
  123. package/dist/forms/select-menu/index.js +6 -0
  124. package/dist/forms/select-menu/select-menu.d.ts +35 -0
  125. package/dist/forms/select-menu/select-menu.js +230 -0
  126. package/dist/i18n/strings.d.ts +89 -0
  127. package/dist/i18n/strings.js +54 -2
  128. package/dist/i18n/ui-strings-provider.d.ts +1 -1
  129. package/dist/i18n/ui-strings-provider.js +6 -2
  130. package/dist/navigation/index.d.ts +1 -0
  131. package/dist/navigation/index.js +1 -0
  132. package/dist/navigation/stepper/index.d.ts +1 -1
  133. package/dist/navigation/stepper/index.js +3 -1
  134. package/dist/navigation/stepper/stepper.d.ts +8 -0
  135. package/dist/navigation/stepper/stepper.js +68 -45
  136. package/dist/navigation/tabs/index.d.ts +1 -0
  137. package/dist/navigation/tabs/index.js +6 -0
  138. package/dist/navigation/tabs/tabs-nav.d.ts +37 -0
  139. package/dist/navigation/tabs/tabs-nav.js +57 -0
  140. package/dist/navigation/wizard/index.d.ts +1 -0
  141. package/dist/navigation/wizard/index.js +6 -0
  142. package/dist/navigation/wizard/model.d.ts +33 -0
  143. package/dist/navigation/wizard/model.js +34 -0
  144. package/dist/navigation/wizard/wizard.d.ts +45 -0
  145. package/dist/navigation/wizard/wizard.js +169 -0
  146. package/dist/overlays/alert-dialog/alert-dialog.d.ts +103 -0
  147. package/dist/overlays/alert-dialog/alert-dialog.js +342 -0
  148. package/dist/overlays/alert-dialog/index.d.ts +1 -0
  149. package/dist/overlays/alert-dialog/index.js +26 -0
  150. package/dist/overlays/dropdown-menu/dropdown-menu.d.ts +17 -1
  151. package/dist/overlays/dropdown-menu/dropdown-menu.js +12 -4
  152. package/dist/overlays/dropdown-menu/index.d.ts +1 -1
  153. package/dist/overlays/dropdown-menu/index.js +8 -2
  154. package/dist/overlays/index.d.ts +2 -0
  155. package/dist/overlays/index.js +2 -0
  156. package/dist/overlays/testing/index.d.ts +5 -0
  157. package/dist/overlays/testing/index.js +4 -0
  158. package/dist/overlays/toaster/index.d.ts +2 -1
  159. package/dist/overlays/toaster/index.js +4 -2
  160. package/dist/overlays/toaster/toast-store.d.ts +6 -2
  161. package/dist/overlays/toaster/toast.d.ts +3 -0
  162. package/dist/overlays/toaster/toast.js +3 -0
  163. package/dist/overlays/toaster/toaster.d.ts +3 -0
  164. package/dist/overlays/toaster/toaster.js +36 -3
  165. package/dist/overlays/tooltip/index.d.ts +1 -0
  166. package/dist/overlays/tooltip/index.js +4 -0
  167. package/dist/overlays/tooltip/model.d.ts +10 -0
  168. package/dist/overlays/tooltip/model.js +13 -0
  169. package/dist/overlays/tooltip/tooltip.d.ts +41 -0
  170. package/dist/overlays/tooltip/tooltip.js +116 -0
  171. package/dist/primitives/use-dismissable-layer.js +1 -1
  172. package/dist/states/error-state/error-state.d.ts +6 -1
  173. package/dist/states/error-state/error-state.js +13 -9
  174. package/dist/states/skeleton/skeleton.d.ts +8 -2
  175. package/dist/states/skeleton/skeleton.js +44 -2
  176. package/package.json +2 -2
  177. package/scripts/build-theme.mjs +12 -1
  178. package/src/atoms/checkbox/checkbox.tsx +3 -1
  179. package/src/atoms/chip/chip.tsx +18 -3
  180. package/src/atoms/chip/index.ts +2 -0
  181. package/src/atoms/due-chip/due-chip.tsx +75 -0
  182. package/src/atoms/due-chip/index.ts +2 -0
  183. package/src/atoms/due-chip/model.ts +67 -0
  184. package/src/atoms/icon-button/icon-button.tsx +58 -0
  185. package/src/atoms/icon-button/index.ts +6 -0
  186. package/src/atoms/index.ts +5 -0
  187. package/src/atoms/internal/hit-area.ts +7 -0
  188. package/src/atoms/kbd/index.ts +1 -0
  189. package/src/atoms/kbd/kbd.tsx +20 -0
  190. package/src/atoms/radio-group/radio-group.tsx +8 -2
  191. package/src/atoms/seal/index.ts +1 -0
  192. package/src/atoms/seal/seal.tsx +107 -0
  193. package/src/atoms/spinner/index.ts +1 -0
  194. package/src/atoms/spinner/spinner.tsx +49 -0
  195. package/src/atoms/switch/switch.tsx +3 -1
  196. package/src/calendar/date-calendar/date-calendar.tsx +230 -0
  197. package/src/calendar/date-calendar/index.ts +5 -0
  198. package/src/calendar/index.ts +1 -0
  199. package/src/calendar/internal/date-utils.ts +115 -0
  200. package/src/containers/aside/aside.tsx +40 -0
  201. package/src/containers/aside/index.ts +1 -0
  202. package/src/containers/banner/banner.tsx +18 -1
  203. package/src/containers/description-list/description-list.tsx +85 -9
  204. package/src/containers/feed/feed.tsx +99 -0
  205. package/src/containers/feed/index.ts +8 -0
  206. package/src/containers/feed/model.ts +54 -0
  207. package/src/containers/index.ts +6 -0
  208. package/src/containers/kpi/kpi.tsx +161 -62
  209. package/src/containers/list-detail/index.ts +15 -0
  210. package/src/containers/list-detail/list-detail.tsx +293 -0
  211. package/src/containers/note/index.ts +1 -0
  212. package/src/containers/note/note.tsx +38 -0
  213. package/src/containers/section/index.ts +11 -0
  214. package/src/containers/section/section.tsx +281 -0
  215. package/src/containers/shortcuts/index.ts +6 -0
  216. package/src/containers/shortcuts/shortcuts.tsx +92 -0
  217. package/src/containers/table/selection.ts +26 -0
  218. package/src/containers/table/table.tsx +215 -13
  219. package/src/containers/timeline/index.ts +3 -0
  220. package/src/containers/timeline/timeline.tsx +204 -93
  221. package/src/forms/chip-group/chip-group.tsx +184 -0
  222. package/src/forms/chip-group/index.ts +8 -0
  223. package/src/forms/combobox/combobox.tsx +359 -0
  224. package/src/forms/combobox/index.ts +7 -0
  225. package/src/forms/date-picker/date-picker.tsx +239 -0
  226. package/src/forms/date-picker/date-time-picker.tsx +178 -0
  227. package/src/forms/date-picker/index.ts +10 -0
  228. package/src/forms/date-picker/model.ts +108 -0
  229. package/src/forms/dropzone/dropzone.tsx +217 -35
  230. package/src/forms/field/field.tsx +72 -7
  231. package/src/forms/index.ts +4 -0
  232. package/src/forms/input/index.ts +8 -1
  233. package/src/forms/input/input.tsx +97 -12
  234. package/src/forms/input-icon/input-icon.tsx +1 -1
  235. package/src/forms/internal/listbox-items.tsx +103 -0
  236. package/src/forms/internal/listbox.ts +124 -0
  237. package/src/forms/number-stepper/model.ts +35 -0
  238. package/src/forms/number-stepper/number-stepper.tsx +132 -42
  239. package/src/forms/select-menu/index.ts +7 -0
  240. package/src/forms/select-menu/select-menu.tsx +280 -0
  241. package/src/i18n/strings.ts +89 -0
  242. package/src/i18n/ui-strings-provider.tsx +15 -4
  243. package/src/navigation/index.ts +1 -0
  244. package/src/navigation/stepper/index.ts +7 -1
  245. package/src/navigation/stepper/stepper.tsx +41 -5
  246. package/src/navigation/tabs/index.ts +7 -0
  247. package/src/navigation/tabs/tabs-nav.tsx +131 -0
  248. package/src/navigation/wizard/index.ts +7 -0
  249. package/src/navigation/wizard/model.ts +61 -0
  250. package/src/navigation/wizard/wizard.tsx +222 -0
  251. package/src/overlays/alert-dialog/alert-dialog.tsx +486 -0
  252. package/src/overlays/alert-dialog/index.ts +19 -0
  253. package/src/overlays/dropdown-menu/dropdown-menu.tsx +29 -4
  254. package/src/overlays/dropdown-menu/index.ts +3 -0
  255. package/src/overlays/index.ts +2 -0
  256. package/src/overlays/testing/index.ts +5 -0
  257. package/src/overlays/toaster/index.ts +2 -0
  258. package/src/overlays/toaster/toast-store.ts +6 -2
  259. package/src/overlays/toaster/toast.ts +6 -0
  260. package/src/overlays/toaster/toaster.tsx +44 -2
  261. package/src/overlays/tooltip/index.ts +1 -0
  262. package/src/overlays/tooltip/model.ts +18 -0
  263. package/src/overlays/tooltip/tooltip.tsx +166 -0
  264. package/src/primitives/use-dismissable-layer.ts +7 -2
  265. package/src/states/error-state/error-state.tsx +19 -8
  266. package/src/states/skeleton/skeleton.tsx +68 -2
  267. package/styles/tailwind.css +33 -30
  268. package/styles/theme.css +33 -30
@@ -6,6 +6,7 @@ import {
6
6
  useState,
7
7
  useSyncExternalStore
8
8
  } from "react";
9
+ import { statusIcon } from "../../atoms/internal/status-icons.js";
9
10
  import { useUiStrings } from "../../i18n/ui-strings-provider.js";
10
11
  import { Portal } from "../../primitives/portal.js";
11
12
  import { cn } from "../../utils/cn.js";
@@ -19,6 +20,33 @@ import {
19
20
  subscribe
20
21
  } from "./toast-store.js";
21
22
  import { toast } from "./toast.js";
23
+ const toastToneClasses = {
24
+ default: "bg-toast-bg text-toast-ink",
25
+ success: "border border-success/40 bg-success-soft text-ink",
26
+ info: "border border-info/40 bg-info-soft text-ink",
27
+ warning: "border border-warning/40 bg-warning-soft text-ink",
28
+ error: "border border-danger/40 bg-danger-soft text-ink"
29
+ };
30
+ const toneActionClasses = {
31
+ default: "bg-toast-ink/18 text-toast-ink",
32
+ success: "bg-ink/10 text-ink hover:bg-ink/15",
33
+ info: "bg-ink/10 text-ink hover:bg-ink/15",
34
+ warning: "bg-ink/10 text-ink hover:bg-ink/15",
35
+ error: "bg-ink/10 text-ink hover:bg-ink/15"
36
+ };
37
+ const toneGlyph = {
38
+ default: null,
39
+ success: "success",
40
+ info: "info",
41
+ warning: "warning",
42
+ error: "danger"
43
+ };
44
+ const toneGlyphColor = {
45
+ success: "text-success",
46
+ info: "text-info",
47
+ warning: "text-warning",
48
+ danger: "text-danger"
49
+ };
22
50
  const EXIT_MS = 200;
23
51
  const SWIPE_THRESHOLD = 60;
24
52
  const POSITION = {
@@ -107,6 +135,7 @@ function ToastItem({ record, duration, reducedMotion, classNames }) {
107
135
  if (Math.abs(dx) >= SWIPE_THRESHOLD) dismiss(id);
108
136
  };
109
137
  const isError = tone === "error";
138
+ const glyph = toneGlyph[tone];
110
139
  const closed = state === "closed";
111
140
  const swiping = dragX !== 0;
112
141
  return (
@@ -133,7 +162,8 @@ function ToastItem({ record, duration, reducedMotion, classNames }) {
133
162
  onPointerCancel: endDrag,
134
163
  style: swiping ? { transform: `translateX(${dragX}px)`, opacity: 1 - Math.abs(dragX) / 200 } : void 0,
135
164
  className: cn(
136
- "pointer-events-auto flex min-h-11 w-max max-w-[min(92vw,26rem)] touch-pan-y items-center gap-3 rounded-button bg-toast-bg py-1.5 pr-2 pl-4 text-control text-toast-ink shadow-overlay",
165
+ "pointer-events-auto flex min-h-11 w-max max-w-[min(92vw,26rem)] touch-pan-y items-center gap-3 rounded-button py-1.5 pr-2 pl-4 text-control shadow-overlay",
166
+ toastToneClasses[tone],
137
167
  "transition-[opacity,transform] duration-200 ease-out motion-reduce:transition-none",
138
168
  !entered && "opacity-0 data-[state=open]:translate-y-2",
139
169
  closed && "opacity-0",
@@ -141,6 +171,7 @@ function ToastItem({ record, duration, reducedMotion, classNames }) {
141
171
  classNames?.toast
142
172
  ),
143
173
  children: [
174
+ glyph ? /* @__PURE__ */ jsx("span", { "data-slot": "glyph", className: cn("shrink-0", toneGlyphColor[glyph]), children: statusIcon(glyph, "size-4") }) : null,
144
175
  /* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1", children: [
145
176
  /* @__PURE__ */ jsx("div", { className: classNames?.title, children: record.message }),
146
177
  record.description ? /* @__PURE__ */ jsx("div", { className: cn("opacity-70", classNames?.description), children: record.description }) : null
@@ -150,7 +181,8 @@ function ToastItem({ record, duration, reducedMotion, classNames }) {
150
181
  {
151
182
  type: "button",
152
183
  className: cn(
153
- "h-8 shrink-0 rounded-button bg-toast-ink/18 px-3 font-bold text-toast-ink focus-ring",
184
+ "h-8 shrink-0 rounded-button px-3 font-bold focus-ring",
185
+ toneActionClasses[tone],
154
186
  classNames?.action
155
187
  ),
156
188
  onClick: (event) => {
@@ -228,5 +260,6 @@ function Toaster({
228
260
  }
229
261
  export {
230
262
  Toaster,
231
- toast
263
+ toast,
264
+ toastToneClasses
232
265
  };
@@ -0,0 +1 @@
1
+ export { Tooltip, type TooltipPart, type TooltipProps } from "./tooltip.js";
@@ -0,0 +1,4 @@
1
+ import { Tooltip } from "./tooltip.js";
2
+ export {
3
+ Tooltip
4
+ };
@@ -0,0 +1,10 @@
1
+ /** Hover opens a tooltip for a mouse or pen, never for a finger: a tap must reach the control. */
2
+ export declare function opensOnHover(pointerType: string): boolean;
3
+ /**
4
+ * Focus opens a tooltip only when it came from the keyboard (`:focus-visible`) and not from a
5
+ * press that has just closed it, so clicking a button never makes its tooltip flicker back.
6
+ */
7
+ export declare function opensOnFocus({ pressed, focusVisible, }: {
8
+ pressed: boolean;
9
+ focusVisible: boolean;
10
+ }): boolean;
@@ -0,0 +1,13 @@
1
+ function opensOnHover(pointerType) {
2
+ return pointerType !== "touch";
3
+ }
4
+ function opensOnFocus({
5
+ pressed,
6
+ focusVisible
7
+ }) {
8
+ return focusVisible && !pressed;
9
+ }
10
+ export {
11
+ opensOnFocus,
12
+ opensOnHover
13
+ };
@@ -0,0 +1,41 @@
1
+ import { type ReactElement, type ReactNode } from "react";
2
+ import type { Align, Side } from "../../primitives/popper/geometry.js";
3
+ import type { ClassNames } from "../../utils/class-names.js";
4
+ import { type Material } from "../../utils/material.js";
5
+ export type TooltipPart = "content" | "shortcut";
6
+ export interface TooltipProps {
7
+ /** The hint. It repeats or complements the trigger's name; never put information only here. */
8
+ content: ReactNode;
9
+ /** Keyboard shortcut shown next to the hint, rendered as a `Kbd`. */
10
+ shortcut?: ReactNode;
11
+ side?: Side;
12
+ align?: Align;
13
+ /** Gap between the trigger and the tooltip, in px. */
14
+ sideOffset?: number;
15
+ /** ms the pointer must rest on the trigger before the tooltip opens. Keyboard focus opens at once. */
16
+ openDelay?: number;
17
+ /** ms before closing after the pointer leaves, so it can travel onto the tooltip (WCAG 1.4.13). */
18
+ closeDelay?: number;
19
+ /** Controlled open state. */
20
+ open?: boolean;
21
+ defaultOpen?: boolean;
22
+ onOpenChange?: (open: boolean) => void;
23
+ /** Never show the tooltip, e.g. when the label is already visible. */
24
+ disabled?: boolean;
25
+ /** Portal target. Defaults to `document.body`; pass an element to keep a scoped `data-style`. */
26
+ container?: HTMLElement | null;
27
+ /** Surface material; see `PopoverContent`. */
28
+ material?: Material;
29
+ className?: string;
30
+ /** Per-part classes merged with `cn`; consumer classes win. `className` still targets the content and is merged last. */
31
+ classNames?: ClassNames<TooltipPart>;
32
+ /** The element that gets the tooltip. It receives `aria-describedby` while the tooltip is open. */
33
+ children: ReactElement;
34
+ }
35
+ /**
36
+ * Short, non-interactive hint for a control. Opens on hover (after `openDelay`) and on keyboard
37
+ * focus, closes on Escape, blur, press and pointer leave. Touch never opens it by hover, so a tap
38
+ * always reaches the control. The trigger is described by it (`aria-describedby`), and the
39
+ * tooltip never takes focus.
40
+ */
41
+ export declare function Tooltip({ content, shortcut, side, align, sideOffset, openDelay, closeDelay, open: openProp, defaultOpen, onOpenChange, disabled, container, material, className, classNames, children, }: TooltipProps): import("react").JSX.Element;
@@ -0,0 +1,116 @@
1
+ "use client";
2
+ import { jsx, jsxs } from "react/jsx-runtime";
3
+ import {
4
+ useCallback,
5
+ useEffect,
6
+ useId,
7
+ useRef
8
+ } from "react";
9
+ import { Kbd } from "../../atoms/kbd/kbd.js";
10
+ import * as PopoverPrimitive from "../../primitives/popover/popover.js";
11
+ import { cn } from "../../utils/cn.js";
12
+ import { materialClass } from "../../utils/material.js";
13
+ import { Slot } from "../../utils/slot.js";
14
+ import { useControllableState } from "../../utils/use-controllable-state.js";
15
+ import { opensOnFocus, opensOnHover } from "./model.js";
16
+ function focusIsVisible(element) {
17
+ try {
18
+ return element.matches(":focus-visible");
19
+ } catch {
20
+ return true;
21
+ }
22
+ }
23
+ function Tooltip({
24
+ content,
25
+ shortcut,
26
+ side = "top",
27
+ align = "center",
28
+ sideOffset = 6,
29
+ openDelay = 300,
30
+ closeDelay = 100,
31
+ open: openProp,
32
+ defaultOpen = false,
33
+ onOpenChange,
34
+ disabled = false,
35
+ container,
36
+ material,
37
+ className,
38
+ classNames,
39
+ children
40
+ }) {
41
+ const [openState, setOpen] = useControllableState({
42
+ prop: openProp,
43
+ defaultProp: defaultOpen,
44
+ onChange: onOpenChange
45
+ });
46
+ const open = openState && !disabled;
47
+ const contentId = useId();
48
+ const timer = useRef(void 0);
49
+ const pressed = useRef(false);
50
+ const schedule = useCallback(
51
+ (next, delay) => {
52
+ window.clearTimeout(timer.current);
53
+ if (delay <= 0) setOpen(next);
54
+ else timer.current = window.setTimeout(() => setOpen(next), delay);
55
+ },
56
+ [setOpen]
57
+ );
58
+ useEffect(() => () => window.clearTimeout(timer.current), []);
59
+ const trigger = /* @__PURE__ */ jsx(
60
+ Slot,
61
+ {
62
+ "aria-describedby": open ? contentId : void 0,
63
+ onPointerEnter: (event) => {
64
+ if (opensOnHover(event.pointerType)) schedule(true, openDelay);
65
+ },
66
+ onPointerLeave: (event) => {
67
+ if (opensOnHover(event.pointerType)) schedule(false, closeDelay);
68
+ },
69
+ onPointerDown: () => {
70
+ pressed.current = true;
71
+ schedule(false, 0);
72
+ },
73
+ onFocus: (event) => {
74
+ if (opensOnFocus({ pressed: pressed.current, focusVisible: focusIsVisible(event.target) })) {
75
+ schedule(true, 0);
76
+ }
77
+ },
78
+ onBlur: () => {
79
+ pressed.current = false;
80
+ schedule(false, 0);
81
+ },
82
+ children
83
+ }
84
+ );
85
+ return /* @__PURE__ */ jsxs(PopoverPrimitive.Root, { open, onOpenChange: setOpen, children: [
86
+ /* @__PURE__ */ jsx(PopoverPrimitive.Anchor, { asChild: true, children: trigger }),
87
+ /* @__PURE__ */ jsx(PopoverPrimitive.Portal, { container, children: /* @__PURE__ */ jsxs(
88
+ PopoverPrimitive.Content,
89
+ {
90
+ id: contentId,
91
+ role: "tooltip",
92
+ side,
93
+ align,
94
+ sideOffset,
95
+ collisionPadding: 8,
96
+ onOpenAutoFocus: (event) => event.preventDefault(),
97
+ onCloseAutoFocus: (event) => event.preventDefault(),
98
+ onMouseEnter: () => schedule(true, 0),
99
+ onMouseLeave: () => schedule(false, closeDelay),
100
+ className: cn(
101
+ "z-85 flex w-max max-w-[min(16rem,var(--ui-popper-available-width))] items-center gap-2 rounded-popover surface-overlay px-2.5 py-1.5 text-meta text-ink shadow-overlay",
102
+ materialClass(material, "surface-solid"),
103
+ classNames?.content,
104
+ className
105
+ ),
106
+ children: [
107
+ /* @__PURE__ */ jsx("span", { className: "min-w-0 break-words", children: content }),
108
+ shortcut === void 0 ? null : /* @__PURE__ */ jsx(Kbd, { className: classNames?.shortcut, children: shortcut })
109
+ ]
110
+ }
111
+ ) })
112
+ ] });
113
+ }
114
+ export {
115
+ Tooltip
116
+ };
@@ -5,7 +5,7 @@ import {
5
5
  useRef
6
6
  } from "react";
7
7
  import { useEnabledPointerEvents } from "./pointer-events-lock.js";
8
- const FOREIGN_LAYER = "[role=listbox][data-state=open], [role=combobox][aria-expanded=true]";
8
+ const FOREIGN_LAYER = "[role=listbox][data-state=open]:not([data-ui-layer]), [role=combobox][aria-expanded=true]:not([data-ui-layer])";
9
9
  const LAYER_BRANCH_ATTRIBUTE = "data-ui-layer-branch";
10
10
  const LAYER_BRANCH = `[${LAYER_BRANCH_ATTRIBUTE}]`;
11
11
  const ESCAPE_CLAIM = "[data-ui-escape-claim]";
@@ -12,8 +12,13 @@ export interface ErrorStateProps {
12
12
  correlationLabel?: string;
13
13
  onRetry?: () => void;
14
14
  retryLabel?: string;
15
+ /**
16
+ * Extra actions (buttons or links) in the same row as the retry button, under the message.
17
+ * Use it for "Go back" or "Contact support"; `onRetry` stays the shortcut for a plain retry.
18
+ */
19
+ actions?: ReactNode;
15
20
  /** `outlined` draws a danger border around the state. */
16
21
  variant?: "plain" | "outlined";
17
22
  className?: string;
18
23
  }
19
- export declare function ErrorState({ title, description, message, correlationId, correlationLabel, onRetry, retryLabel, variant, className, }: ErrorStateProps): import("react").JSX.Element;
24
+ export declare function ErrorState({ title, description, message, correlationId, correlationLabel, onRetry, retryLabel, actions, variant, className, }: ErrorStateProps): import("react").JSX.Element;
@@ -11,6 +11,7 @@ function ErrorState({
11
11
  correlationLabel,
12
12
  onRetry,
13
13
  retryLabel,
14
+ actions,
14
15
  variant = "plain",
15
16
  className
16
17
  }) {
@@ -34,15 +35,18 @@ function ErrorState({
34
35
  " ",
35
36
  correlationId
36
37
  ] }) : null,
37
- onRetry ? /* @__PURE__ */ jsx(
38
- "button",
39
- {
40
- type: "button",
41
- onClick: onRetry,
42
- className: "mt-2 inline-flex h-control-sm cursor-pointer items-center rounded-input border-control bg-surface-control px-3 font-semibold text-fs-130 text-ink hover:bg-surface-2",
43
- children: retryLabel ?? strings.retry
44
- }
45
- ) : null
38
+ onRetry || displayable(actions) !== void 0 ? /* @__PURE__ */ jsxs("div", { className: "mt-2 flex flex-wrap items-center justify-center gap-2", children: [
39
+ onRetry ? /* @__PURE__ */ jsx(
40
+ "button",
41
+ {
42
+ type: "button",
43
+ onClick: onRetry,
44
+ className: "inline-flex h-control-sm cursor-pointer items-center rounded-input border-control bg-surface-control px-3 font-semibold text-fs-130 text-ink hover:bg-surface-2",
45
+ children: retryLabel ?? strings.retry
46
+ }
47
+ ) : null,
48
+ displayable(actions)
49
+ ] }) : null
46
50
  ]
47
51
  }
48
52
  );
@@ -1,12 +1,18 @@
1
- export type SkeletonVariant = "lines" | "table" | "card";
1
+ export type SkeletonVariant = "lines" | "table" | "card" | "list" | "kpis" | "key-value" | "bar";
2
2
  export interface SkeletonProps {
3
3
  variant?: SkeletonVariant;
4
4
  /** Number of lines for the `lines` variant. */
5
5
  lines?: number;
6
6
  /** Number of rows for the `table` variant. */
7
7
  rows?: number;
8
+ /** Number of items for the `list`, `kpis` and `key-value` variants. Defaults to 4, at most 12. */
9
+ count?: number;
8
10
  /** Text announced to screen readers while loading. */
9
11
  label?: string;
12
+ /**
13
+ * Classes on the root. The `bar` variant is one block sized by them (`h-8 w-32`), 12px tall and
14
+ * full width otherwise.
15
+ */
10
16
  className?: string;
11
17
  }
12
- export declare function Skeleton({ variant, lines, rows, label, className, }: SkeletonProps): import("react").JSX.Element;
18
+ export declare function Skeleton({ variant, lines, rows, count, label, className, }: SkeletonProps): import("react").JSX.Element;
@@ -3,10 +3,17 @@ import { jsx, jsxs } from "react/jsx-runtime";
3
3
  import { useUiStrings } from "../../i18n/index.js";
4
4
  import { cn } from "../../utils/cn.js";
5
5
  const PLACEHOLDER_IDS = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l"];
6
+ function Bar({ className }) {
7
+ return /* @__PURE__ */ jsx("span", { "aria-hidden": "true", className: cn("block h-3 rounded-xs bg-surface-2", className) });
8
+ }
9
+ function items(count, render) {
10
+ return PLACEHOLDER_IDS.slice(0, Math.max(0, count)).map((id, index) => render(id, index));
11
+ }
6
12
  function Skeleton({
7
13
  variant = "lines",
8
14
  lines = 3,
9
15
  rows = 4,
16
+ count = 4,
10
17
  label,
11
18
  className
12
19
  }) {
@@ -17,7 +24,11 @@ function Skeleton({
17
24
  role: "status",
18
25
  "aria-busy": "true",
19
26
  "aria-label": label ?? strings.loading,
20
- className: cn("animate-pulse", className),
27
+ className: cn(
28
+ "animate-pulse",
29
+ variant === "bar" && "block h-3 w-full rounded-xs bg-surface-2",
30
+ className
31
+ ),
21
32
  children: [
22
33
  variant === "lines" ? /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: PLACEHOLDER_IDS.slice(0, lines).map((id, index) => /* @__PURE__ */ jsx(
23
34
  "div",
@@ -28,11 +39,42 @@ function Skeleton({
28
39
  id
29
40
  )) }) : null,
30
41
  variant === "table" ? /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: PLACEHOLDER_IDS.slice(0, rows).map((id) => /* @__PURE__ */ jsx("div", { className: "h-9 rounded-xs bg-surface-2" }, id)) }) : null,
31
- variant === "card" ? /* @__PURE__ */ jsx("div", { className: "h-40 rounded-card bg-surface-2" }) : null
42
+ variant === "card" ? /* @__PURE__ */ jsx("div", { className: "h-40 rounded-card bg-surface-2" }) : null,
43
+ variant === "list" ? /* @__PURE__ */ jsx("div", { className: "flex flex-col", children: items(count, (id, index) => /* @__PURE__ */ jsxs(
44
+ "div",
45
+ {
46
+ className: "grid min-h-11 grid-cols-[minmax(0,1fr)_auto] items-center gap-3 border-b-divider py-2.5 in-data-[density=touch]:min-h-14",
47
+ children: [
48
+ /* @__PURE__ */ jsxs("span", { className: "flex flex-col gap-1.5", children: [
49
+ /* @__PURE__ */ jsx(Bar, { className: index % 2 === 0 ? "w-2/5" : "w-1/2" }),
50
+ /* @__PURE__ */ jsx(Bar, { className: "h-2.5 w-1/4" })
51
+ ] }),
52
+ /* @__PURE__ */ jsx(Bar, { className: "w-14" })
53
+ ]
54
+ },
55
+ id
56
+ )) }) : null,
57
+ variant === "kpis" ? /* @__PURE__ */ jsx("div", { className: "grid gap-3 [grid-template-columns:repeat(auto-fit,minmax(min(168px,100%),1fr))]", children: items(count, (id) => /* @__PURE__ */ jsxs(
58
+ "div",
59
+ {
60
+ className: "flex flex-col gap-2.5 rounded-card border-card bg-surface px-4 py-3.5",
61
+ children: [
62
+ /* @__PURE__ */ jsx(Bar, { className: "w-1/2" }),
63
+ /* @__PURE__ */ jsx(Bar, { className: "h-6.5 w-2/3" }),
64
+ /* @__PURE__ */ jsx(Bar, { className: "w-1/3" })
65
+ ]
66
+ },
67
+ id
68
+ )) }) : null,
69
+ variant === "key-value" ? /* @__PURE__ */ jsx("div", { className: "grid gap-x-4 gap-y-2.5 py-3 [grid-template-columns:minmax(min(6.5rem,40%),10rem)_minmax(0,1fr)]", children: items(count, (id, index) => /* @__PURE__ */ jsxs("div", { className: "contents", children: [
70
+ /* @__PURE__ */ jsx(Bar, { className: "w-3/4" }),
71
+ /* @__PURE__ */ jsx(Bar, { className: KEY_VALUE_WIDTHS[index % KEY_VALUE_WIDTHS.length] })
72
+ ] }, id)) }) : null
32
73
  ]
33
74
  }
34
75
  );
35
76
  }
77
+ const KEY_VALUE_WIDTHS = ["w-11/12", "w-3/4", "w-5/6", "w-2/3"];
36
78
  export {
37
79
  Skeleton
38
80
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jcsoftdev/ui",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Token-driven React component library: React 19, Tailwind v4.",
5
5
  "author": "jcsoftdev",
6
6
  "license": "MIT",
@@ -102,7 +102,7 @@
102
102
  "typescript": "^5.5.4",
103
103
  "vite": "7.3.6",
104
104
  "vitest": "4.1.11",
105
- "@jcsoftdev/ui-tokens": "^0.3.0"
105
+ "@jcsoftdev/ui-tokens": "^0.4.0"
106
106
  },
107
107
  "publishConfig": {
108
108
  "access": "public"
@@ -336,7 +336,18 @@ export function buildThemeCss(tokens) {
336
336
  cssRule(`@utility ${name}`, body),
337
337
  );
338
338
  const tail = utilities.length ? `\n${utilities.join("\n\n")}\n` : "";
339
- return `/* Generated by ui-theme from "${tokens.name}". Do not edit. */\n@theme inline {\n${lines.join("\n")}\n}\n${tail}`;
339
+ // A token whose utility name equals its raw variable (`--radius-input: var(--radius-input)`) would
340
+ // be emitted into Tailwind's theme layer as a cycle, which resolves to nothing for any consumer that
341
+ // loads tokens.css below that layer. `reference` keeps the utilities and drops the declaration;
342
+ // the utilities read the raw variable directly because the block is also `inline`.
343
+ const selfReference = (l) => {
344
+ const m = /^\s*(--[\w-]+): var\((--[\w-]+)\);$/.exec(l);
345
+ return m !== null && m[1] === m[2];
346
+ };
347
+ const mapped = lines.filter((l) => !selfReference(l));
348
+ const same = lines.filter(selfReference);
349
+ const reference = same.length ? `\n@theme reference inline {\n${same.join("\n")}\n}\n` : "";
350
+ return `/* Generated by ui-theme from "${tokens.name}". Do not edit. */\n@theme inline {\n${mapped.join("\n")}\n}\n${reference}${tail}`;
340
351
  }
341
352
 
342
353
  export function buildFontsCss(tokens) {
@@ -7,6 +7,7 @@ import { cn } from "../../utils/cn.js";
7
7
  import { composeHandlers, useComposedRefs } from "../../utils/compose.js";
8
8
  import { BubbleInput, useFormBubble, useFormReset } from "../../utils/form-bubble.js";
9
9
  import { useControllableState } from "../../utils/use-controllable-state.js";
10
+ import { touchHitArea } from "../internal/hit-area.js";
10
11
 
11
12
  export type CheckedState = boolean | "indeterminate";
12
13
 
@@ -86,7 +87,8 @@ export function Checkbox({
86
87
  {...props}
87
88
  ref={composedRef}
88
89
  className={cn(
89
- "group inline-flex size-10 shrink-0 items-center justify-center in-data-[density=touch]:size-11 disabled:cursor-not-allowed disabled:opacity-50",
90
+ touchHitArea,
91
+ "group inline-flex size-10 shrink-0 items-center justify-center disabled:cursor-not-allowed disabled:opacity-50",
90
92
  classNames?.root,
91
93
  className,
92
94
  )}
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
 
3
- import type { ComponentPropsWithoutRef, ReactNode } from "react";
3
+ import type { ComponentPropsWithRef, ReactNode } from "react";
4
4
  import { useUiStrings } from "../../i18n/index.js";
5
5
  import { X } from "../../icons/index.js";
6
6
  import { cn } from "../../utils/cn.js";
@@ -32,8 +32,21 @@ export const chipToneClasses: Readonly<Record<ChipBuiltinTone, string>> = {
32
32
  outline: "bg-transparent text-ink-2 shadow-[inset_0_0_0_1px_var(--line-strong)]",
33
33
  };
34
34
 
35
- export interface ChipProps extends ComponentPropsWithoutRef<"span"> {
35
+ export type ChipSize = "sm" | "md";
36
+
37
+ /** Class map behind each `size`; exported like `chipToneClasses`. */
38
+ export const chipSizeClasses: Readonly<Record<ChipSize, string>> = {
39
+ md: "h-6 px-2.5 font-[650] text-fs-120",
40
+ sm: "h-auto min-h-5 px-1.5 py-px font-medium text-fs-115 tabular-nums",
41
+ };
42
+
43
+ export interface ChipProps extends ComponentPropsWithRef<"span"> {
36
44
  tone?: ChipTone;
45
+ /**
46
+ * `sm` is the compact tag: it grows with its content, tightens the padding and uses tabular
47
+ * numerals, so codes, counts and ids line up. Pair it with `square` and a neutral tone for a tag.
48
+ */
49
+ size?: ChipSize;
37
50
  /** Use the smaller chip radius instead of a full pill. */
38
51
  square?: boolean;
39
52
  /** Leading decorative icon; wins over `statusIcon`. */
@@ -51,6 +64,7 @@ const builtinTones = new Set<string>(Object.keys(chipToneClasses));
51
64
 
52
65
  export function Chip({
53
66
  tone = "neutral",
67
+ size = "md",
54
68
  square,
55
69
  icon,
56
70
  statusIcon: withStatusIcon,
@@ -70,7 +84,8 @@ export function Chip({
70
84
  return (
71
85
  <span
72
86
  className={cn(
73
- "inline-flex h-6 max-w-full items-center gap-1.5 overflow-hidden whitespace-nowrap px-2.5 font-[650] text-fs-120 leading-none [&_svg]:size-3",
87
+ "inline-flex max-w-full items-center gap-1.5 overflow-hidden whitespace-nowrap leading-none [&_svg]:size-3",
88
+ chipSizeClasses[size],
74
89
  square ? "rounded-chip" : "rounded-badge",
75
90
  custom
76
91
  ? "bg-(--tone-c-soft) text-(--tone-c-ink)"
@@ -2,6 +2,8 @@ export {
2
2
  Chip,
3
3
  type ChipBuiltinTone,
4
4
  type ChipProps,
5
+ type ChipSize,
5
6
  type ChipTone,
7
+ chipSizeClasses,
6
8
  chipToneClasses,
7
9
  } from "./chip.js";
@@ -0,0 +1,75 @@
1
+ "use client";
2
+
3
+ import type { ReactNode } from "react";
4
+ import { todayIso } from "../../calendar/internal/date-utils.js";
5
+ import { useUiStrings } from "../../i18n/index.js";
6
+ import { Chip, type ChipProps } from "../chip/chip.js";
7
+ import { type DueState, dueCalendarDate, dueStatus, formatDueDay } from "./model.js";
8
+
9
+ export type { DueState } from "./model.js";
10
+
11
+ const toneFor: Record<DueState, "danger" | "warning" | "neutral"> = {
12
+ overdue: "danger",
13
+ soon: "warning",
14
+ ok: "neutral",
15
+ };
16
+
17
+ export interface DueChipProps
18
+ extends Omit<ChipProps, "tone" | "children" | "onRemove" | "statusIcon"> {
19
+ /** Due date: "2026-03-04", a naive date-time "2026-03-04T17:00", or an ISO instant (read in the viewer's zone). */
20
+ date: string;
21
+ /**
22
+ * Reference day ("YYYY-MM-DD") the state is measured from. Defaults to the viewer's today;
23
+ * pass it for deterministic output (server render, tests, "as of" views).
24
+ */
25
+ today?: string | undefined;
26
+ /** Days ahead (inclusive of today) that count as `soon`. Defaults to 3. */
27
+ soonDays?: number | undefined;
28
+ /**
29
+ * Forces the state regardless of the date, for a status the date alone cannot tell (a
30
+ * payment that is late by policy, a hold). `done` is the neutral finished look. Wins over `done`.
31
+ */
32
+ state?: DueState | "done" | undefined;
33
+ /** A finished item is never overdue or soon: the chip stays neutral. */
34
+ done?: boolean | undefined;
35
+ /** Replaces the formatted date text. */
36
+ children?: ReactNode;
37
+ locale?: string | undefined;
38
+ }
39
+
40
+ /**
41
+ * A due date as a chip: neutral while it is far off, warning from `soonDays` before, danger once
42
+ * past. The tone is never the only signal: overdue and soon chips carry a status glyph and a
43
+ * screen-reader state. Renders `<time datetime>`; an unreadable date is shown as given.
44
+ */
45
+ export function DueChip({
46
+ date,
47
+ today,
48
+ soonDays,
49
+ done = false,
50
+ state: forced,
51
+ locale,
52
+ children,
53
+ ...props
54
+ }: DueChipProps) {
55
+ const strings = useUiStrings();
56
+ const reference = today ?? todayIso();
57
+ const day = dueCalendarDate(date);
58
+ const status = day ? dueStatus(date, { today: reference, soonDays }) : null;
59
+ if (!day || !status) return <Chip {...props}>{children ?? date}</Chip>;
60
+
61
+ const resolved: DueState | "done" = forced ?? (done ? "done" : status.state);
62
+ const state: DueState = resolved === "done" ? "ok" : resolved;
63
+ const tone = toneFor[state];
64
+ const stateText =
65
+ state === "overdue" ? strings.overdue : state === "soon" ? strings.dueSoon : null;
66
+ return (
67
+ <Chip tone={tone} statusIcon data-state={resolved} {...props}>
68
+ <time dateTime={date}>
69
+ {children ??
70
+ formatDueDay(day, dueCalendarDate(reference) ?? reference, locale ?? strings.locale)}
71
+ </time>
72
+ {stateText ? <span className="sr-only">, {stateText}</span> : null}
73
+ </Chip>
74
+ );
75
+ }
@@ -0,0 +1,2 @@
1
+ export { DueChip, type DueChipProps, type DueState } from "./due-chip.js";
2
+ export { dueStatus } from "./model.js";