@g4rcez/components 4.0.2 → 4.1.2

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 (337) hide show
  1. package/ai/SKILL.md +120 -153
  2. package/ai/docs/Alert.md +47 -48
  3. package/ai/docs/AnimatedList.md +88 -87
  4. package/ai/docs/Autocomplete.md +102 -106
  5. package/ai/docs/Button.md +33 -33
  6. package/ai/docs/Calendar.md +67 -101
  7. package/ai/docs/Card.md +59 -55
  8. package/ai/docs/Checkbox.md +77 -82
  9. package/ai/docs/CommandPalette.md +154 -172
  10. package/ai/docs/DatePicker.md +45 -64
  11. package/ai/docs/Dropdown.md +98 -126
  12. package/ai/docs/Empty.md +41 -44
  13. package/ai/docs/Expand.md +40 -54
  14. package/ai/docs/FileUpload.md +102 -109
  15. package/ai/docs/Form.md +35 -29
  16. package/ai/docs/FormReset.md +37 -37
  17. package/ai/docs/Heading.md +4 -6
  18. package/ai/docs/Input.md +73 -98
  19. package/ai/docs/InputField.md +67 -67
  20. package/ai/docs/List.md +88 -85
  21. package/ai/docs/Menu.md +62 -60
  22. package/ai/docs/Modal.md +129 -136
  23. package/ai/docs/MultiSelect.md +65 -84
  24. package/ai/docs/Notifications.md +96 -96
  25. package/ai/docs/PageCalendar.md +88 -97
  26. package/ai/docs/Polymorph.md +25 -41
  27. package/ai/docs/Progress.md +55 -51
  28. package/ai/docs/Radiobox.md +49 -41
  29. package/ai/docs/RenderOnView.md +26 -32
  30. package/ai/docs/Resizable.md +60 -65
  31. package/ai/docs/Select.md +158 -158
  32. package/ai/docs/Shortcut.md +14 -14
  33. package/ai/docs/Skeleton.md +56 -60
  34. package/ai/docs/Slider.md +26 -49
  35. package/ai/docs/Slot.md +15 -17
  36. package/ai/docs/Spinner.md +17 -15
  37. package/ai/docs/Stats.md +44 -42
  38. package/ai/docs/Step.md +60 -60
  39. package/ai/docs/Switch.md +44 -54
  40. package/ai/docs/Table.md +124 -136
  41. package/ai/docs/Tabs.md +90 -90
  42. package/ai/docs/Tag.md +63 -65
  43. package/ai/docs/TaskList.md +40 -50
  44. package/ai/docs/Textarea.md +47 -70
  45. package/ai/docs/Timeline.md +98 -96
  46. package/ai/docs/Toolbar.md +46 -46
  47. package/ai/docs/Tooltip.md +103 -103
  48. package/ai/docs/Typography.md +55 -55
  49. package/ai/docs/Wizard.md +104 -109
  50. package/ai/docs/index.md +116 -116
  51. package/dist/autocomplete-DcTNOwyg.js +393 -0
  52. package/dist/autocomplete-DcTNOwyg.js.map +1 -0
  53. package/dist/{calendar-B5lSd0ID.js → calendar-BJMHRoy2.js} +104 -105
  54. package/dist/calendar-BJMHRoy2.js.map +1 -0
  55. package/dist/components/core/button.d.ts.map +1 -1
  56. package/dist/components/core/button.js +10 -10
  57. package/dist/components/core/button.js.map +1 -1
  58. package/dist/components/core/button.jsx +79 -0
  59. package/dist/components/core/heading.jsx +4 -0
  60. package/dist/components/core/polymorph.d.ts +1 -1
  61. package/dist/components/core/polymorph.d.ts.map +1 -1
  62. package/dist/components/core/polymorph.jsx +5 -0
  63. package/dist/components/core/render-on-view.jsx +31 -0
  64. package/dist/components/core/resizable.jsx +51 -0
  65. package/dist/components/core/slot.d.ts.map +1 -1
  66. package/dist/components/core/slot.jsx +156 -0
  67. package/dist/components/core/tag.d.ts +1 -1
  68. package/dist/components/core/tag.d.ts.map +1 -1
  69. package/dist/components/core/tag.js +4 -4
  70. package/dist/components/core/tag.js.map +1 -1
  71. package/dist/components/core/tag.jsx +51 -0
  72. package/dist/components/core/typography.jsx +18 -0
  73. package/dist/components/display/alert.d.ts +1 -1
  74. package/dist/components/display/alert.d.ts.map +1 -1
  75. package/dist/components/display/alert.js +48 -46
  76. package/dist/components/display/alert.js.map +1 -1
  77. package/dist/components/display/alert.jsx +61 -0
  78. package/dist/components/display/calendar.js +6 -6
  79. package/dist/components/display/calendar.jsx +299 -0
  80. package/dist/components/display/card.js +2 -2
  81. package/dist/components/display/card.js.map +1 -1
  82. package/dist/components/display/card.jsx +43 -0
  83. package/dist/components/display/empty.jsx +11 -0
  84. package/dist/components/display/list.js +1 -1
  85. package/dist/components/display/list.js.map +1 -1
  86. package/dist/components/display/list.jsx +81 -0
  87. package/dist/components/display/notifications.d.ts +1 -1
  88. package/dist/components/display/notifications.d.ts.map +1 -1
  89. package/dist/components/display/notifications.js +3 -3
  90. package/dist/components/display/notifications.jsx +126 -0
  91. package/dist/components/display/progress.jsx +11 -0
  92. package/dist/components/display/shortcut.jsx +23 -0
  93. package/dist/components/display/skeleton.d.ts.map +1 -1
  94. package/dist/components/display/skeleton.jsx +19 -0
  95. package/dist/components/display/spinner.d.ts.map +1 -1
  96. package/dist/components/display/spinner.jsx +11 -0
  97. package/dist/components/display/stats.js +1 -1
  98. package/dist/components/display/stats.jsx +20 -0
  99. package/dist/components/display/step.jsx +131 -0
  100. package/dist/components/display/tabs.d.ts +1 -1
  101. package/dist/components/display/tabs.d.ts.map +1 -1
  102. package/dist/components/display/tabs.js +2 -2
  103. package/dist/components/display/tabs.jsx +125 -0
  104. package/dist/components/display/timeline.js +1 -1
  105. package/dist/components/display/timeline.jsx +25 -0
  106. package/dist/components/floating/command-palette.d.ts.map +1 -1
  107. package/dist/components/floating/command-palette.jsx +197 -0
  108. package/dist/components/floating/dropdown.d.ts.map +1 -1
  109. package/dist/components/floating/dropdown.js +25 -17
  110. package/dist/components/floating/dropdown.js.map +1 -1
  111. package/dist/components/floating/dropdown.jsx +56 -0
  112. package/dist/components/floating/expand.js +7 -7
  113. package/dist/components/floating/expand.js.map +1 -1
  114. package/dist/components/floating/expand.jsx +44 -0
  115. package/dist/components/floating/menu.js +10 -10
  116. package/dist/components/floating/menu.js.map +1 -1
  117. package/dist/components/floating/menu.jsx +147 -0
  118. package/dist/components/floating/modal.d.ts +4 -4
  119. package/dist/components/floating/modal.d.ts.map +1 -1
  120. package/dist/components/floating/modal.js +106 -102
  121. package/dist/components/floating/modal.js.map +1 -1
  122. package/dist/components/floating/modal.jsx +301 -0
  123. package/dist/components/floating/toolbar.jsx +5 -0
  124. package/dist/components/floating/tooltip.d.ts.map +1 -1
  125. package/dist/components/floating/tooltip.js +14 -14
  126. package/dist/components/floating/tooltip.js.map +1 -1
  127. package/dist/components/floating/tooltip.jsx +58 -0
  128. package/dist/components/floating/wizard.jsx +161 -0
  129. package/dist/components/form/autocomplete.d.ts.map +1 -1
  130. package/dist/components/form/autocomplete.js +6 -6
  131. package/dist/components/form/autocomplete.jsx +278 -0
  132. package/dist/components/form/checkbox.js +1 -1
  133. package/dist/components/form/checkbox.jsx +12 -0
  134. package/dist/components/form/date-picker.d.ts.map +1 -1
  135. package/dist/components/form/date-picker.js +5 -5
  136. package/dist/components/form/date-picker.jsx +115 -0
  137. package/dist/components/form/file-upload.d.ts.map +1 -1
  138. package/dist/components/form/file-upload.js +2 -2
  139. package/dist/components/form/file-upload.jsx +134 -0
  140. package/dist/components/form/form.js.map +1 -1
  141. package/dist/components/form/form.jsx +10 -0
  142. package/dist/components/form/formReset.jsx +17 -0
  143. package/dist/components/form/free-text.d.ts.map +1 -1
  144. package/dist/components/form/free-text.jsx +41 -0
  145. package/dist/components/form/input-field.d.ts +11 -11
  146. package/dist/components/form/input-field.d.ts.map +1 -1
  147. package/dist/components/form/input-field.jsx +58 -0
  148. package/dist/components/form/input.js +1 -1
  149. package/dist/components/form/input.jsx +36 -0
  150. package/dist/components/form/multi-select.d.ts.map +1 -1
  151. package/dist/components/form/multi-select.jsx +336 -0
  152. package/dist/components/form/radiobox.js +1 -1
  153. package/dist/components/form/radiobox.jsx +6 -0
  154. package/dist/components/form/select.js +3 -3
  155. package/dist/components/form/select.jsx +42 -0
  156. package/dist/components/form/slider.jsx +45 -0
  157. package/dist/components/form/switch.js +2 -2
  158. package/dist/components/form/switch.js.map +1 -1
  159. package/dist/components/form/switch.jsx +46 -0
  160. package/dist/components/form/task-list.jsx +26 -0
  161. package/dist/components/form/textarea.jsx +12 -0
  162. package/dist/components/index.d.ts +0 -1
  163. package/dist/components/index.d.ts.map +1 -1
  164. package/dist/components/index.js +44 -0
  165. package/dist/components/page-calendar/calendar-header.jsx +83 -0
  166. package/dist/components/page-calendar/day-view.jsx +94 -0
  167. package/dist/components/page-calendar/event-pill.d.ts.map +1 -1
  168. package/dist/components/page-calendar/event-pill.jsx +25 -0
  169. package/dist/components/page-calendar/index.js +2 -0
  170. package/dist/components/page-calendar/month-view.jsx +46 -0
  171. package/dist/components/page-calendar/page-calendar.jsx +41 -0
  172. package/dist/components/page-calendar/page-calendar.types.js +1 -0
  173. package/dist/components/page-calendar/page-calendar.utils.js +93 -0
  174. package/dist/components/page-calendar/week-view.jsx +71 -0
  175. package/dist/components/table/filter.jsx +141 -0
  176. package/dist/components/table/group.jsx +68 -0
  177. package/dist/components/table/index.d.ts +2 -3
  178. package/dist/components/table/index.d.ts.map +1 -1
  179. package/dist/components/table/index.jsx +60 -0
  180. package/dist/components/table/inner-table.d.ts +2 -3
  181. package/dist/components/table/inner-table.d.ts.map +1 -1
  182. package/dist/components/table/inner-table.jsx +102 -0
  183. package/dist/components/table/metadata.jsx +36 -0
  184. package/dist/components/table/pagination.d.ts +3 -1
  185. package/dist/components/table/pagination.d.ts.map +1 -1
  186. package/dist/components/table/pagination.jsx +74 -0
  187. package/dist/components/table/row.d.ts +4 -5
  188. package/dist/components/table/row.d.ts.map +1 -1
  189. package/dist/components/table/row.jsx +49 -0
  190. package/dist/components/table/sort.d.ts.map +1 -1
  191. package/dist/components/table/sort.jsx +109 -0
  192. package/dist/components/table/table-lib.d.ts +1 -1
  193. package/dist/components/table/table-lib.d.ts.map +1 -1
  194. package/dist/components/table/table-lib.js +83 -0
  195. package/dist/components/table/table.context.jsx +4 -0
  196. package/dist/components/table/table.js +3 -3
  197. package/dist/components/table/thead.jsx +103 -0
  198. package/dist/config/context.js +12 -0
  199. package/dist/config/default-translations.d.ts +4 -0
  200. package/dist/config/default-translations.d.ts.map +1 -1
  201. package/dist/config/default-translations.jsx +87 -0
  202. package/dist/config/default-tweaks.js +4 -0
  203. package/dist/constants.js +2 -0
  204. package/dist/{date-picker-DwNo22lx.js → date-picker-Bnl07nd8.js} +8 -6
  205. package/dist/date-picker-Bnl07nd8.js.map +1 -0
  206. package/dist/{dom-Dl8XH0CK.js → dom-CyQHY7ID.js} +66 -61
  207. package/dist/dom-CyQHY7ID.js.map +1 -0
  208. package/dist/{file-upload-Brf2NkLr.js → file-upload-93d5DR4q.js} +139 -129
  209. package/dist/file-upload-93d5DR4q.js.map +1 -0
  210. package/dist/{floating-ui.react-QNHG9W4N.js → floating-ui.react-M2PGXLDp.js} +8 -8
  211. package/dist/floating-ui.react-M2PGXLDp.js.map +1 -0
  212. package/dist/{fns-D2eyJKd5.js → fns-C7Dt27Qd.js} +2 -2
  213. package/dist/fns-C7Dt27Qd.js.map +1 -0
  214. package/dist/hooks/use-click-outside.js +17 -0
  215. package/dist/hooks/use-color-parser.js +9 -0
  216. package/dist/hooks/use-components-provider.jsx +22 -0
  217. package/dist/hooks/use-debounce.d.ts +3 -3
  218. package/dist/hooks/use-debounce.d.ts.map +1 -1
  219. package/dist/hooks/use-debounce.js +12 -0
  220. package/dist/hooks/use-floating-ref.js +6 -0
  221. package/dist/hooks/use-form.d.ts +14 -13
  222. package/dist/hooks/use-form.d.ts.map +1 -1
  223. package/dist/hooks/use-form.js +563 -0
  224. package/dist/hooks/use-hover.js +18 -0
  225. package/dist/hooks/use-input-id.js +5 -0
  226. package/dist/hooks/use-is-coarse-device.js +12 -0
  227. package/dist/hooks/use-locale.js +10 -0
  228. package/dist/hooks/use-media-query.js +25 -0
  229. package/dist/hooks/use-on-event.js +7 -0
  230. package/dist/hooks/use-parent.js +21 -0
  231. package/dist/hooks/use-preferences.js +23 -0
  232. package/dist/hooks/use-previous.js +9 -0
  233. package/dist/hooks/use-reactive.js +9 -0
  234. package/dist/hooks/use-remove-scroll.d.ts.map +1 -1
  235. package/dist/hooks/use-remove-scroll.js +48 -0
  236. package/dist/hooks/use-resize-observer.js +17 -0
  237. package/dist/hooks/use-stable-ref.js +9 -0
  238. package/dist/hooks/use-swipe.js +17 -0
  239. package/dist/hooks/use-translations.d.ts +4 -0
  240. package/dist/hooks/use-translations.d.ts.map +1 -1
  241. package/dist/hooks/use-translations.js +9 -0
  242. package/dist/hooks/use-tweaks.js +9 -0
  243. package/dist/hooks/use-window-size.js +14 -0
  244. package/dist/index-BJ1ayTam.js +126 -0
  245. package/dist/index-BJ1ayTam.js.map +1 -0
  246. package/dist/index-C-PuFUZi.js.map +1 -1
  247. package/dist/{index-BelDtX5M.js → index-DDeQW0JW.js} +399 -404
  248. package/dist/index-DDeQW0JW.js.map +1 -0
  249. package/dist/index-DE4shK8D.js +215 -0
  250. package/dist/index-DE4shK8D.js.map +1 -0
  251. package/dist/{index-DJSMaZR4.js → index-DlJ_2RBL.js} +2 -2
  252. package/dist/index-DlJ_2RBL.js.map +1 -0
  253. package/dist/index.css +1 -1
  254. package/dist/index.esm-BaIwleSE.js.map +1 -1
  255. package/dist/index.js +20 -8177
  256. package/dist/index.js.map +1 -1
  257. package/dist/{input-CrGrSnUt.js → input-_MVxmIpu.js} +116 -114
  258. package/dist/input-_MVxmIpu.js.map +1 -0
  259. package/dist/{input-field-5vYcz5tT.js → input-field-CDCOODOl.js} +63 -47
  260. package/dist/input-field-CDCOODOl.js.map +1 -0
  261. package/dist/lib/combi-keys.js +60 -0
  262. package/dist/lib/dict.d.ts +1 -4
  263. package/dist/lib/dict.d.ts.map +1 -1
  264. package/dist/lib/dict.js +28 -0
  265. package/dist/lib/dom.d.ts +3 -2
  266. package/dist/lib/dom.d.ts.map +1 -1
  267. package/dist/lib/dom.js +66 -0
  268. package/dist/lib/fns.js +46 -0
  269. package/dist/lib/fzf.d.ts.map +1 -1
  270. package/dist/lib/fzf.js +115 -0
  271. package/dist/lib/keyboard-area.js +14 -0
  272. package/dist/notifications-Dp0ydKJS.js +2576 -0
  273. package/dist/notifications-Dp0ydKJS.js.map +1 -0
  274. package/dist/polymorph-B5n9fs_K.js.map +1 -1
  275. package/dist/preset/plugin.tailwind.d.ts.map +1 -1
  276. package/dist/preset/plugin.tailwind.js +20 -18
  277. package/dist/preset/preset.tailwind.js +24 -25
  278. package/dist/preset/src/styles/common.js +6 -3
  279. package/dist/preset/src/styles/dark.d.ts.map +1 -1
  280. package/dist/preset/src/styles/dark.js +9 -5
  281. package/dist/preset/src/styles/design-tokens.js +68 -89
  282. package/dist/preset/src/styles/light.d.ts.map +1 -1
  283. package/dist/preset/src/styles/light.js +9 -5
  284. package/dist/preset/src/styles/theme.js +7 -4
  285. package/dist/preset/src/styles/theme.types.d.ts +2 -1
  286. package/dist/preset/src/styles/theme.types.d.ts.map +1 -1
  287. package/dist/preset/src/styles/theme.types.js +2 -1
  288. package/dist/skeleton-BjJobYYf.js +24 -0
  289. package/dist/skeleton-BjJobYYf.js.map +1 -0
  290. package/dist/slot-CRyweuj0.js.map +1 -1
  291. package/dist/styles/common.js +6 -3
  292. package/dist/styles/dark.d.ts.map +1 -1
  293. package/dist/styles/dark.js +9 -5
  294. package/dist/styles/design-tokens.js +68 -89
  295. package/dist/styles/light.d.ts.map +1 -1
  296. package/dist/styles/light.js +9 -5
  297. package/dist/styles/theme.js +7 -4
  298. package/dist/styles/theme.types.d.ts +2 -1
  299. package/dist/styles/theme.types.d.ts.map +1 -1
  300. package/dist/styles/theme.types.js +2 -1
  301. package/dist/tabs-B0g7YtQv.js +123 -0
  302. package/dist/tabs-B0g7YtQv.js.map +1 -0
  303. package/dist/tsconfig.lib.tsbuildinfo +1 -0
  304. package/dist/types.d.ts +2 -2
  305. package/dist/types.d.ts.map +1 -1
  306. package/dist/types.js +1 -0
  307. package/dist/{context-BFXNJVn2.js → use-translations-DSltA7H_.js} +38 -30
  308. package/dist/use-translations-DSltA7H_.js.map +1 -0
  309. package/package.json +99 -86
  310. package/ai/docs/TransferList.md +0 -142
  311. package/dist/autocomplete-Cn9Z2hLq.js +0 -375
  312. package/dist/autocomplete-Cn9Z2hLq.js.map +0 -1
  313. package/dist/calendar-B5lSd0ID.js.map +0 -1
  314. package/dist/components/form/transfer-list.d.ts +0 -14
  315. package/dist/components/form/transfer-list.d.ts.map +0 -1
  316. package/dist/components/form/transfer-list.js +0 -55
  317. package/dist/components/form/transfer-list.js.map +0 -1
  318. package/dist/context-BFXNJVn2.js.map +0 -1
  319. package/dist/date-picker-DwNo22lx.js.map +0 -1
  320. package/dist/dom-Dl8XH0CK.js.map +0 -1
  321. package/dist/file-upload-Brf2NkLr.js.map +0 -1
  322. package/dist/floating-ui.react-QNHG9W4N.js.map +0 -1
  323. package/dist/fns-D2eyJKd5.js.map +0 -1
  324. package/dist/index-BelDtX5M.js.map +0 -1
  325. package/dist/index-DJSMaZR4.js.map +0 -1
  326. package/dist/index-Z-fZHxfJ.js +0 -335
  327. package/dist/index-Z-fZHxfJ.js.map +0 -1
  328. package/dist/input-CrGrSnUt.js.map +0 -1
  329. package/dist/input-field-5vYcz5tT.js.map +0 -1
  330. package/dist/notifications-cUdVPs-B.js +0 -2786
  331. package/dist/notifications-cUdVPs-B.js.map +0 -1
  332. package/dist/skeleton-D75GFBV6.js +0 -10
  333. package/dist/skeleton-D75GFBV6.js.map +0 -1
  334. package/dist/tabs-S00a8qq8.js +0 -106
  335. package/dist/tabs-S00a8qq8.js.map +0 -1
  336. package/dist/use-translations-BwLKTrZv.js +0 -10
  337. package/dist/use-translations-BwLKTrZv.js.map +0 -1
@@ -0,0 +1,74 @@
1
+ import React, { Fragment, useId, useMemo } from "react";
2
+ import { useTranslations } from "../../hooks/use-translations";
3
+ import { Polymorph } from "../core/polymorph";
4
+ export function createPaginationItems(current, max) {
5
+ if (!current || !max)
6
+ return [];
7
+ const items = [1];
8
+ if (current === 1 && max === 1)
9
+ return items;
10
+ if (current > 4)
11
+ items.push("-");
12
+ const r = 2;
13
+ const r1 = current - r;
14
+ const r2 = current + r;
15
+ for (let i = r1 > 2 ? r1 : 2; i <= Math.min(max, r2); i++)
16
+ items.push(i);
17
+ const p2 = max - 2;
18
+ if (r2 + 1 !== p2) {
19
+ if (r2 + 1 < max)
20
+ items.push("_");
21
+ }
22
+ if (r2 < max) {
23
+ items.push(max - 2);
24
+ items.push(max - 1);
25
+ items.push(max);
26
+ }
27
+ return Array.from(new Set(items));
28
+ }
29
+ export const Pagination = (pagination) => {
30
+ const id = useId();
31
+ const translation = useTranslations();
32
+ const pageNavigation = useMemo(() => createPaginationItems(pagination.current, pagination.pages), [pagination.current, pagination.pages]);
33
+ const hasNext = pagination.current < pagination.pages;
34
+ const Link = pagination.asLink ?? "button";
35
+ return (<footer className="flex flex-wrap items-center justify-center gap-4 border-t-muted p-3 text-sm lg:flex-nowrap lg:justify-between">
36
+ <p>
37
+ <translation.tablePaginationFooter {...pagination} sizes={pagination.sizes} select={pagination.onChangeSize && Array.isArray(pagination.sizes) ? (<Fragment>
38
+ <label htmlFor={id}>{translation.tablePaginationSelectLabel}</label>
39
+ <select id={id} value={pagination.size} className="cursor-pointer bg-transparent" onChange={(e) => {
40
+ pagination.onChangeSize?.(Number(e.target.value));
41
+ }}>
42
+ {pagination.sizes.map((value) => (<option key={`pagination-opt-${value}`} value={value}>
43
+ {value}
44
+ </option>))}
45
+ </select>{" "}
46
+ </Fragment>) : null}/>
47
+ </p>
48
+ <nav>
49
+ <ul className="flex items-center gap-2">
50
+ {pagination.current > 1 ? (<li>
51
+ <Polymorph as={Link} href="previous" className="">
52
+ {translation.tablePaginationPrevious}
53
+ </Polymorph>
54
+ </li>) : null}
55
+ {pageNavigation.map((x) => {
56
+ if (x === null)
57
+ return null;
58
+ return (<Fragment key={`pagination-${x}`}>
59
+ {typeof x === "string" ? (<li>...</li>) : (<li>
60
+ <Polymorph href={x} as={Link} className={`cursor-pointer border-b-2 px-3 py-1 proportional-nums transition-colors hover:border-primary-subtle hover:text-primary-subtle ${x === pagination.current ? "border-primary text-primary" : "border-transparent"}`}>
61
+ {x}
62
+ </Polymorph>
63
+ </li>)}
64
+ </Fragment>);
65
+ })}
66
+ {hasNext ? (<li>
67
+ <Polymorph as={Link} href="next" className="">
68
+ {translation.tablePaginationNext}
69
+ </Polymorph>
70
+ </li>) : null}
71
+ </ul>
72
+ </nav>
73
+ </footer>);
74
+ };
@@ -1,12 +1,11 @@
1
1
  import React from "react";
2
- import { Any } from "../../types";
3
2
  import { CellAsideElement, Col } from "./table-lib";
4
- type ItemContentContext = {
5
- cols: Col<Any>[];
3
+ type ItemContentContext<T extends Record<string, unknown>> = {
4
+ cols: Col<T>[];
6
5
  loading?: boolean;
7
6
  loadingMore?: boolean;
8
- Aside?: React.FC<CellAsideElement<any>>;
7
+ Aside?: React.FC<CellAsideElement<T>>;
9
8
  };
10
- export declare const Row: (index: number, row: any, context: ItemContentContext) => React.JSX.Element;
9
+ export declare const Row: <T extends Record<string, unknown>>(index: number, row: T, context: ItemContentContext<T>) => React.JSX.Element;
11
10
  export {};
12
11
  //# sourceMappingURL=row.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"row.d.ts","sourceRoot":"","sources":["../../../src/components/table/row.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmE,MAAM,OAAO,CAAC;AAGxF,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAElC,OAAO,EAAE,gBAAgB,EAAoB,GAAG,EAAa,MAAM,aAAa,CAAC;AAEjF,KAAK,kBAAkB,GAAG;IACtB,IAAI,EAAE,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,KAAK,CAAC,EAAE,KAAK,CAAC,EAAE,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAAC;CAC3C,CAAC;AA6CF,eAAO,MAAM,GAAG,GAAI,OAAO,MAAM,EAAE,KAAK,GAAG,EAAE,SAAS,kBAAkB,sBA0CvE,CAAC"}
1
+ {"version":3,"file":"row.d.ts","sourceRoot":"","sources":["../../../src/components/table/row.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAwD,MAAM,OAAO,CAAC;AAI7E,OAAO,EAAE,gBAAgB,EAAoB,GAAG,EAAa,MAAM,aAAa,CAAC;AAEjF,KAAK,kBAAkB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI;IACzD,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;IACf,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,KAAK,CAAC,EAAE,KAAK,CAAC,EAAE,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC;CACzC,CAAC;AAoCF,eAAO,MAAM,GAAG,GAAI,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,MAAM,EAAE,KAAK,CAAC,EAAE,SAAS,kBAAkB,CAAC,CAAC,CAAC,sBAgD3G,CAAC"}
@@ -0,0 +1,49 @@
1
+ import React, { Fragment, useRef, useState } from "react";
2
+ import { Is } from "sidekicker";
3
+ import { path } from "../../lib/fns";
4
+ import { SkeletonCell } from "../display/skeleton";
5
+ const RowAside = (props) => {
6
+ const parentRef = useRef(null);
7
+ const ref = useRef(null);
8
+ const [className, setClassName] = useState("opacity-0");
9
+ const ariaHidden = className === "opacity-0";
10
+ const onLeave = () => setClassName("opacity-0");
11
+ const onEnter = () => {
12
+ const child = ref.current;
13
+ const parent = parentRef.current;
14
+ if (child !== null && parent !== null) {
15
+ parent.style.left = `-${child.getBoundingClientRect().width + 4}px`;
16
+ }
17
+ setClassName("opacity-100");
18
+ };
19
+ return (<div ref={parentRef} onMouseEnter={onEnter} onMouseLeave={onLeave} data-component="cell-aside" inert={ariaHidden ? true : undefined} tabIndex={ariaHidden ? -1 : undefined} className={`group-table-cell-aside absolute inset-0 top-0 flex h-full w-full items-stretch transition-opacity duration-300 ease-in-out ${className}`}>
20
+ <div ref={ref} className="isolate block">
21
+ {props.children}
22
+ </div>
23
+ </div>);
24
+ };
25
+ export const Row = (index, row, context) => {
26
+ const cols = context.cols;
27
+ const loading = context.loading;
28
+ return (<Fragment>
29
+ {cols.map((col, colIndex) => {
30
+ const matrix = `${colIndex},${index}`;
31
+ const value = path(row, col.id);
32
+ const Component = col.Element;
33
+ const className = col.cellProps?.className || "";
34
+ const exposeAside = colIndex === 0 && context.Aside && loading === false;
35
+ const Aside = context.Aside;
36
+ return (<td {...col.cellProps} role="cell" data-matrix={matrix} key={`accessor-${index}-${colIndex}`} className={`typography group-table-cell flex border-collapse flex-col whitespace-pre-wrap border border-y border-b border-table-border p-[var(--table-cell-padding)] md:table-cell md:border-b-0 md:border-r md:border-l-transparent md:last:border-r-transparent ${className}`}>
37
+ {exposeAside ? (<RowAside>
38
+ <Aside col={col} row={row} rowIndex={index}/>
39
+ </RowAside>) : null}
40
+ <span className="block text-sm font-bold leading-tight md:hidden">{col.thead}</span>
41
+ <span className="relative">
42
+ {loading ? (SkeletonCell) : Component ? (<Fragment>
43
+ <Component row={row} matrix={matrix} col={col} rowIndex={index} value={value}/>
44
+ </Fragment>) : (<Fragment>{Is.nil(value) ? "" : value}</Fragment>)}
45
+ </span>
46
+ </td>);
47
+ })}
48
+ </Fragment>);
49
+ };
@@ -1 +1 @@
1
- {"version":3,"file":"sort.d.ts","sourceRoot":"","sources":["../../../src/components/table/sort.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAwC,MAAM,OAAO,CAAC;AAG7D,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAGzC,OAAO,EAAE,GAAG,EAAY,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAErF,KAAK,KAAK,CAAC,CAAC,SAAS,GAAG,IAAI,MAAM,CAAC,SAAS,MAAM,CAAC,SAAS,MAAM,GAAG,CAAC,GAAG,KAAK,CAAC;AAE/E,aAAK,KAAK;IACN,GAAG,QAAQ;IACX,IAAI,SAAS;IACb,SAAS,cAAc;CAC1B;AAED,MAAM,MAAM,MA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AAC,CAAC,CAAC,sBAkClE,CAAC"}
@@ -0,0 +1,109 @@
1
+ "use client";
2
+ import { SortAscendingIcon, SortDescendingIcon, CaretUpDownIcon, PlusIcon, TrashIcon } from "@phosphor-icons/react";
3
+ import React, { Fragment, useState } from "react";
4
+ import { useTranslations } from "../../hooks/use-translations";
5
+ import { uuid } from "../../lib/fns";
6
+ import { Dropdown } from "../floating/dropdown";
7
+ import { Select } from "../form/select";
8
+ import { getLabel } from "./table-lib";
9
+ var Order;
10
+ (function (Order) {
11
+ Order["Asc"] = "asc";
12
+ Order["Desc"] = "desc";
13
+ Order["Undefined"] = "undefined";
14
+ })(Order || (Order = {}));
15
+ const createSorterFn = (fields) => (a, b) => fields.reduce((acc, x) => {
16
+ const reverse = x.type === "desc" ? -1 : 1;
17
+ const property = x.value;
18
+ const p = a[property] > b[property] ? reverse : a[property] < b[property] ? -reverse : 0;
19
+ return acc !== 0 ? acc : p;
20
+ }, 0);
21
+ export const multiSort = (array, fields) => {
22
+ array.sort(createSorterFn(fields));
23
+ return array;
24
+ };
25
+ const createSorter = (col, label, order) => ({
26
+ label,
27
+ id: uuid(),
28
+ type: order,
29
+ value: col.id,
30
+ });
31
+ export const Sort = (props) => {
32
+ const translation = useTranslations();
33
+ const orders = {
34
+ asc: { label: translation.tableSortAsc, value: Order.Asc },
35
+ desc: { label: translation.tableSortDesc, value: Order.Desc },
36
+ };
37
+ const orderOptions = [orders.asc, orders.desc];
38
+ const onAddSorter = () => {
39
+ const col = props.cols[0];
40
+ if (col)
41
+ props.set((prev) => [...prev, createSorter(col, orders.asc.label, orders.asc.value)]);
42
+ };
43
+ const onSetSorter = (id) => (e) => {
44
+ const value = e.target.value;
45
+ props.set((prev) => prev.map((x) => (x.id === id ? { ...x, value: value } : x)));
46
+ };
47
+ const onSortOrderType = (id) => (e) => {
48
+ const type = e.target.value;
49
+ props.set((prev) => prev.map((x) => (x.id === id ? { ...x, type: type } : x)));
50
+ };
51
+ const onDelete = (e) => {
52
+ const id = e.currentTarget.dataset.id || "";
53
+ props.set((prev) => prev.filter((x) => x.id !== id));
54
+ };
55
+ return (<Fragment>
56
+ <Dropdown title={translation.tableSortDropdownTitle} trigger={<span className="flex items-center gap-1 proportional-nums">
57
+ <CaretUpDownIcon size={14}/>
58
+ {translation.tableSortOrderByLabel} {props.sorters.length === 0 ? "" : ` (${props.sorters.length})`}
59
+ </span>}>
60
+ <ul className="mt-4 space-y-2">
61
+ {props.sorters.map((sorter) => {
62
+ return (<li key={`sorter-select-${sorter.id}`} className="flex flex-nowrap gap-3">
63
+ <Select options={props.options} value={sorter.value} onChange={onSetSorter(sorter.id)} title={translation.tableSortOrderInputTitle} placeholder={translation.tableSortOrderInputPlaceholder}/>
64
+ <Select onChange={onSortOrderType(sorter.id)} value={sorter.type} options={orderOptions} title={translation.tableSortTypeInputTitle} placeholder={translation.tableSortTypeInputPlaceholder}/>
65
+ <button className="mt-4" data-id={sorter.id} onClick={onDelete}>
66
+ <TrashIcon className="text-danger" size={14}/>
67
+ </button>
68
+ </li>);
69
+ })}
70
+ <li>
71
+ <button type="button" onClick={onAddSorter} className="flex items-center gap-1 text-primary">
72
+ <PlusIcon size={14}/> {translation.tableSortAddButton}
73
+ </button>
74
+ </li>
75
+ </ul>
76
+ </Dropdown>
77
+ </Fragment>);
78
+ };
79
+ export const SorterHead = (props) => {
80
+ const translations = useTranslations();
81
+ const [status, setStatus] = useState(() => {
82
+ const sorter = props.sorters.find((sort) => sort.value === props.col.id);
83
+ return sorter ? sorter.type : Order.Undefined;
84
+ });
85
+ const onClick = () => {
86
+ const next = status === Order.Undefined ? Order.Asc : status === Order.Asc ? Order.Desc : Order.Undefined;
87
+ setStatus(next);
88
+ props.setSorters((prev) => {
89
+ if (next === Order.Undefined)
90
+ return prev.filter((x) => x.value !== props.col.id);
91
+ const findIndex = prev.findIndex((p) => p.value === props.col.id);
92
+ const sorter = createSorter(props.col, next, next);
93
+ if (findIndex === -1)
94
+ return [...prev, sorter];
95
+ prev[findIndex] = sorter;
96
+ return [...prev];
97
+ });
98
+ };
99
+ const labelId = `${props.col.id}-sorter-id`;
100
+ const label = getLabel(props.col);
101
+ return (<button aria-labelledby={labelId} className="isolate flex items-center" onClick={onClick} type="button">
102
+ <span id={labelId} className="sr-only">
103
+ {translations.tableSortDropdownTitle} {label}
104
+ </span>
105
+ {status === Order.Asc ? <SortAscendingIcon size={14}/> : null}
106
+ {status === Order.Desc ? <SortDescendingIcon size={14}/> : null}
107
+ {status === Order.Undefined ? <CaretUpDownIcon size={14}/> : null}
108
+ </button>);
109
+ };
@@ -79,7 +79,7 @@ export type TablePagination = {
79
79
  className: string;
80
80
  }>>;
81
81
  };
82
- type TableGetters<T extends POJO> = {
82
+ export type TableGetters<T extends POJO> = {
83
83
  rows: T[];
84
84
  cols: Col<T>[];
85
85
  sorters: Sorter<T>[];
@@ -1 +1 @@
1
- {"version":3,"file":"table-lib.d.ts","sourceRoot":"","sources":["../../../src/components/table/table-lib.ts"],"names":[],"mappings":"AACA,OAAO,KAA8B,MAAM,OAAO,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAKtC,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,eAAO,MAAM,QAAQ,GAAI,CAAC,SAAS,IAAI,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC,sUAAuD,CAAC;AAE5G,MAAM,MAAM,kBAAkB,CAAC,CAAC,SAAS,IAAI,EAAE,CAAC,SAAS,IAAI,GAAG,GAAG,IAAI,CAAC,GAAG;IACvE,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;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;IAClC,SAAS,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IACpC,UAAU,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;CAC3C,CAAC;AAEF,MAAM,MAAM,mBAAmB,CAAC,CAAC,SAAS,IAAI,IAAI,kBAAkB,CAChE,CAAC,EACD,YAAY,CAAC,CAAC,CAAC,GACX,YAAY,CAAC,CAAC,CAAC,GAAG;IACd,GAAG,CAAC,EAAE,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;CACtC,GAAG;IACA,YAAY,EAAE,OAAO,CAAC;IACtB,YAAY,EAAE,OAAO,CAAC;CACzB,CACR,CAAC;AAEF,eAAO,MAAM,aAAa,GAAI,CAAC,SAAS,IAAI,EAAE,UAAU,CAAC,CAAC,EAAE,cAAc,CAAC,CAAC,CAAC,KAAK,IAAI;;;;;;;;;;GAQrF,CAAC;AA0BF,eAAO,MAAM,mBAAmB,GAAI,CAAC,SAAS,IAAI,EAAE,MAAM,MAAM,EAAE,MAAM,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,UAAS,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAQ;;;;;;;;;;;;;;;;;gBAvD1G,eAAe,GAAG,IAAI;CA+ErC,CAAC;AAEF,eAAO,MAAM,eAAe,GAAI,CAAC,SAAS,MAAM,EAAE,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,KAAK,IAAI,mEAIjE,GAAG,CAAC,CAAC,CAAC,EAAE,UAWtB,CAAC;AAEF,eAAO,MAAM,mBAAmB,+BAAyG,CAAC"}
@@ -0,0 +1,83 @@
1
+ "use client";
2
+ import { useCallback, useRef } from "react";
3
+ import { LocalStorage } from "storage-manager-js";
4
+ import { useReducer } from "use-typed-reducer";
5
+ import { useStableRef } from "../../hooks/use-stable-ref";
6
+ import { isSsr } from "../../lib/fns";
7
+ export const getLabel = (col) => col.headerLabel ?? col.thead ?? col.id;
8
+ export const createOptionCols = (cols) => cols.map((opt) => ({
9
+ value: opt.id,
10
+ label: (opt.thead ?? opt.headerLabel ?? opt.id),
11
+ }));
12
+ export var ColType;
13
+ (function (ColType) {
14
+ ColType["Boolean"] = "boolean";
15
+ ColType["Number"] = "number";
16
+ ColType["Select"] = "select";
17
+ ColType["Text"] = "text";
18
+ })(ColType || (ColType = {}));
19
+ export const valueFromType = (input) => (input.type === "number" ? input.valueAsNumber : input.value);
20
+ const cols = () => (id, thead, options) => ({ ...options, id, thead });
21
+ export const createColumns = (callback) => {
22
+ let items = [];
23
+ const add = (id, thead, options) => items.push({ ...options, id, thead });
24
+ const remove = (id) => (items = items.filter((x) => x.id !== id));
25
+ const getAll = () => Array.from(items);
26
+ const filter = (c) => (items = Array.from(items.filter(c)));
27
+ callback({ add, remove, getAll, filter });
28
+ return items;
29
+ };
30
+ const noop = {};
31
+ const mergeCols = (cols, saved) => {
32
+ if (!Array.isArray(saved))
33
+ return cols;
34
+ const savedSet = new Set(saved.map((x) => x.id));
35
+ if (!cols.every((x) => savedSet.has(x.id))) {
36
+ return cols;
37
+ }
38
+ const map = new Map(cols.map((x) => [x.id, x]));
39
+ return saved.map((mock, index) => {
40
+ const original = map.get(mock.id);
41
+ if (original === undefined)
42
+ return cols[index];
43
+ return original;
44
+ });
45
+ };
46
+ export const useTablePreferences = (name, cols, options = noop) => {
47
+ const init = isSsr() ? null : LocalStorage.get(`@components/table-${name}`) || null;
48
+ const [state, dispatch] = useReducer({
49
+ name,
50
+ groups: options.groups || init?.groups || [],
51
+ sorters: options.sorters || init?.sorters || [],
52
+ filters: options.filters || init?.filters || [],
53
+ cols: mergeCols(cols, init?.cols),
54
+ }, (get) => {
55
+ const intercept = (partial) => {
56
+ const prev = get.state();
57
+ const result = { ...prev, ...partial };
58
+ if (!isSsr())
59
+ LocalStorage.set(`@components/table-${prev.name}`, result);
60
+ return result;
61
+ };
62
+ intercept(get.state());
63
+ return {
64
+ set: (getters) => intercept(getters),
65
+ };
66
+ });
67
+ return { ...state, ...dispatch, name };
68
+ };
69
+ export const useWidthControl = (reorder) => {
70
+ const stableRef = useStableRef(reorder);
71
+ const ref = useRef(null);
72
+ const onChange = useCallback((cols) => {
73
+ stableRef.current(cols);
74
+ cols.forEach((x) => {
75
+ const c = ref.current.querySelector(`th[data-tableheader="${x.id}"]`);
76
+ if (!c)
77
+ return;
78
+ c.style.width = "auto";
79
+ });
80
+ }, [stableRef]);
81
+ return [ref, onChange];
82
+ };
83
+ export const getModalScrollerRef = () => (isSsr() ? undefined : document.querySelector(`[data-component="modal-body"]`));
@@ -0,0 +1,4 @@
1
+ import { createContext, useContext } from "react";
2
+ const TableContext = createContext({});
3
+ export const TableProvider = TableContext.Provider;
4
+ export const useTable = () => useContext(TableContext);
@@ -1,8 +1,8 @@
1
1
  import "react/jsx-runtime";
2
2
  import "react";
3
- import "../../index-Z-fZHxfJ.js";
4
- import "../../input-field-5vYcz5tT.js";
5
- import { T as e } from "../../index-BelDtX5M.js";
3
+ import "../../index-BJ1ayTam.js";
4
+ import "../../input-field-CDCOODOl.js";
5
+ import { T as e } from "../../index-DDeQW0JW.js";
6
6
  import "../../proxy-BZcQiBrp.js";
7
7
  export {
8
8
  e as Table
@@ -0,0 +1,103 @@
1
+ "use client";
2
+ import { AnimatePresence, motion, Reorder } from "motion/react";
3
+ import { Order } from "linq-arrays";
4
+ import { PlusIcon, MagnifyingGlassIcon, MagnifyingGlassMinusIcon } from "@phosphor-icons/react";
5
+ import React, { Fragment, useCallback, useRef } from "react";
6
+ import { useTranslations } from "../../hooks/use-translations";
7
+ import { useTweaks } from "../../hooks/use-tweaks";
8
+ import { Dropdown } from "../floating/dropdown";
9
+ import { ColumnHeaderFilter, createFilterFromCol, useOperators } from "./filter";
10
+ import { SorterHead } from "./sort";
11
+ import { getLabel, useWidthControl } from "./table-lib";
12
+ const dragConstraints = { top: 0, left: 0, right: 0, bottom: -1 };
13
+ const HeaderChild = (props) => {
14
+ const tweaks = useTweaks();
15
+ const translation = useTranslations();
16
+ const ownFilters = props.filters.filter((x) => x.name === props.header.id);
17
+ const hasFilters = ownFilters.length > 0;
18
+ const defaultAllowSort = props.header.allowSort ?? tweaks.table.sorters ?? true;
19
+ const defaultAllowFilter = props.header.allowFilter ?? tweaks.table.filters ?? true;
20
+ const operators = useOperators();
21
+ const FilterIcon = hasFilters ? MagnifyingGlassIcon : MagnifyingGlassMinusIcon;
22
+ const th = useRef(null);
23
+ const onDelete = (e) => {
24
+ const id = e.currentTarget.dataset.id || "";
25
+ return props.setFilters((prev) => prev.filter((x) => x.id !== id));
26
+ };
27
+ const dragRef = useCallback((dom) => {
28
+ if (dom === null)
29
+ return;
30
+ th.current = dom;
31
+ const controller = new AbortController();
32
+ dom.addEventListener("pointerdown", (e) => {
33
+ const target = e.target;
34
+ if (target.dataset.type === "resizer") {
35
+ e.stopPropagation();
36
+ return e.stopImmediatePropagation();
37
+ }
38
+ }, { signal: controller.signal });
39
+ return () => controller.abort();
40
+ }, []);
41
+ const ownSorter = props.sorters.find((x) => props.header.id === x.value);
42
+ const ariaSort = !ownSorter?.type ? "none" : ownSorter.type === Order.Asc ? "ascending" : "descending";
43
+ const label = getLabel(props.header);
44
+ return (<Reorder.Item {...props.header.thProps} as="th" ref={dragRef} initial={false} dragSnapToOrigin dragDirectionLock role="columnheader" aria-sort={ariaSort} value={props.header} aria-busy={props.loading} data-tableheader={props.header.id} whileDrag={{ cursor: "grabbing" }} className={`typography relative min-w-0 cursor-grab overflow-clip border-r-[1px] border-table-border bg-table-header font-medium first:rounded-tl-lg last:rounded-tr-lg last:border-r-transparent md:h-14 ${props.header.thProps?.className ?? ""}`}>
45
+ <span className={`flex h-full items-center justify-between bg-table-header p-[var(--table-cell-padding)] ${props.isLast ? "rounded-tr-lg" : ""} ${props.index === 0 ? "rounded-tl-lg" : ""}`}>
46
+ <span className="flex items-center gap-1">
47
+ {props.inlineFilter && defaultAllowFilter ? (<Dropdown arrow trigger={<span>
48
+ <span id={`${props.header.id}-filter-dropdown-button`} className="sr-only">
49
+ {translation.tableFilterDropdownTitleUnique} {label}
50
+ </span>
51
+ <FilterIcon aria-labelledby={`${props.header.id}-filter-dropdown-button`} size={14}/>
52
+ </span>} title={<span className="text-lg">
53
+ {translation.tableFilterDropdownTitleUnique} <span className="font-medium">{label}</span>
54
+ </span>}>
55
+ <ul className="font-medium">
56
+ {ownFilters.length === 0 ? null : (<Fragment>
57
+ {ownFilters.map((filter) => (<li key={`thead-filter-${filter.id}`} className="my-1">
58
+ <ColumnHeaderFilter onDelete={onDelete} filter={filter} set={props.setFilters}/>
59
+ </li>))}
60
+ </Fragment>)}
61
+ <li>
62
+ <button type="button" className="flex items-center gap-1 text-primary" onClick={() => props.setFilters((prev) => prev.concat(createFilterFromCol(props.header, operators.options, operators.operations)))}>
63
+ <PlusIcon size={14}/> {translation.tableFilterNewFilter}
64
+ </button>
65
+ </li>
66
+ </ul>
67
+ </Dropdown>) : null}
68
+ <span className="pointer-events-auto text-balance text-base">{props.header.thead}</span>
69
+ {props.inlineSorter && defaultAllowSort ? (<SorterHead col={props.header} setSorters={props.setSorters} sorters={props.sorters}/>) : null}
70
+ </span>
71
+ </span>
72
+ {props.isLast ? null : (<motion.button drag="x" draggable dragListener dragMomentum type="button" animate={false} dragElastic={0} dragPropagation initial={false} dragSnapToOrigin dragDirectionLock data-type="resizer" title={props.header.id} dragConstraints={dragConstraints} className="absolute -right-[0.5px] top-0 z-calendar block h-full w-[1px] cursor-col-resize bg-transparent hover:w-1.5 hover:bg-primary active:w-1.5 active:bg-primary" onClick={(e) => void e.currentTarget.focus()} onKeyDown={(e) => {
73
+ if (e.key === "ArrowLeft" || e.key === "ArrowRight") {
74
+ if (th.current === null)
75
+ return;
76
+ th.current.setAttribute("data-resized", "true");
77
+ const v = th.current.getBoundingClientRect().width;
78
+ const move = e.shiftKey ? 50 : 10;
79
+ const delta = move * (e.key === "ArrowLeft" ? -1 : 1);
80
+ th.current.style.width = `${Math.abs(v + delta)}px`;
81
+ }
82
+ }} onDoubleClick={() => {
83
+ if (th.current === null)
84
+ return;
85
+ th.current.style.width = "auto";
86
+ }} onDrag={(_, info) => {
87
+ if (th.current === null)
88
+ return;
89
+ th.current.setAttribute("data-resized", "true");
90
+ const v = th.current.getBoundingClientRect().width;
91
+ const delta = info.delta.x;
92
+ th.current.style.width = `${Math.abs(v + delta)}px`;
93
+ }}/>)}
94
+ </Reorder.Item>);
95
+ };
96
+ export const TableHeader = (props) => {
97
+ const [ref, onChange] = useWidthControl(props.setCols);
98
+ return (<Reorder.Group layout as="tr" axis="x" drag="x" ref={ref} layoutRoot role="row" layoutScroll onReorder={onChange} values={props.headers}>
99
+ <AnimatePresence>
100
+ {props.headers.map((header, index) => (<HeaderChild index={index} header={header} filters={props.filters} loading={props.loading} sorters={props.sorters} setFilters={props.setFilters} setSorters={props.setSorters} inlineFilter={props.inlineFilter} inlineSorter={props.inlineSorter} isLast={index === props.headers.length - 1} key={`header-child-item-${header.id}`}/>))}
101
+ </AnimatePresence>
102
+ </Reorder.Group>);
103
+ };
@@ -0,0 +1,12 @@
1
+ "use client";
2
+ import { createContext } from "react";
3
+ import { parsers } from "../styles/design-tokens";
4
+ import { defaultTranslations } from "./default-translations";
5
+ import { defaultTweaks } from "./default-tweaks";
6
+ export const Context = createContext({
7
+ parser: parsers.hsla,
8
+ tweaks: defaultTweaks,
9
+ floatingRef: undefined,
10
+ map: defaultTranslations,
11
+ locale: undefined,
12
+ });
@@ -85,6 +85,10 @@ export declare const defaultTranslations: {
85
85
  }) => string;
86
86
  uploadDialogTitle: string;
87
87
  datepickerPlaceholder: (_: string) => string;
88
+ spinnerLoading: string;
89
+ skeletonLoading: string;
90
+ closeButton: string;
91
+ fileUploadZoneLabel: string;
88
92
  };
89
93
  export type Translations = typeof defaultTranslations;
90
94
  //# sourceMappingURL=default-translations.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"default-translations.d.ts","sourceRoot":"","sources":["../../src/config/default-translations.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AAExC,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;+BAgBD,MAAM;;gCAEL,MAAM;;;;;;gCAMN,MAAM;iCACL,MAAM,QAAQ,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wCAmCb;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,KAAK,CAAC,SAAS,CAAA;KAAE;;;;;;;;;;;;;;;4BAqB7G;QAAE,CAAC,EAAE,MAAM,CAAA;KAAE;;+BAGV,MAAM;CACpC,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG,OAAO,mBAAmB,CAAC"}
1
+ {"version":3,"file":"default-translations.d.ts","sourceRoot":"","sources":["../../src/config/default-translations.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AAExC,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;+BAgBD,MAAM;;gCAEL,MAAM;;;;;;gCAMN,MAAM;iCACL,MAAM,QAAQ,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wCAmCb;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,KAAK,CAAC,SAAS,CAAA;KAAE;;;;;;;;;;;;;;;4BAqB7G;QAAE,CAAC,EAAE,MAAM,CAAA;KAAE;;+BAGV,MAAM;;;;;CAKpC,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG,OAAO,mBAAmB,CAAC"}
@@ -0,0 +1,87 @@
1
+ import React, { Fragment } from "react";
2
+ export const defaultTranslations = {
3
+ autocompleteEmpty: "Nothing here...",
4
+ calendarBackMonth: "Back month",
5
+ calendarFromDate: "From",
6
+ calendarMonthLabel: "Month",
7
+ calendarNextMonth: "Next month",
8
+ calendarDatetimeTitle: "Time",
9
+ calendarToDate: "To",
10
+ calendarToday: "Today",
11
+ pageCalendarMonthView: "Month view",
12
+ pageCalendarWeekView: "Week view",
13
+ pageCalendarDayView: "Day view",
14
+ pageCalendarPrevious: "Previous",
15
+ pageCalendarNext: "Next",
16
+ pageCalendarToday: "Today",
17
+ pageCalendarAddEvent: "Add event",
18
+ pageCalendarWeekLabel: (n) => `Week ${n}`,
19
+ pageCalendarFilter: "Filter:",
20
+ pageCalendarMoreEvents: (n) => `+${n} more...`,
21
+ pageCalendarLabel: "Calendar",
22
+ pageCalendarNavigation: "Calendar navigation",
23
+ pageCalendarMonthGrid: "Calendar month",
24
+ pageCalendarFilterEnabled: "enabled",
25
+ pageCalendarFilterDisabled: "disabled",
26
+ pageCalendarEventCount: (n) => (n === 1 ? "1 event" : `${n} events`),
27
+ pageCalendarEventAt: (title, time) => `${title} at ${time}`,
28
+ commandPaletteEmpty: "Nothing here...",
29
+ commandPaletteLoading: "Loading...",
30
+ datePickerCalendarButtonLabel: "Click to open a date picker",
31
+ emptyDataMessage: "No data",
32
+ inputCaretDown: "Click to see all options",
33
+ inputCloseValue: "Click to clear the value",
34
+ inputOptionalLabel: "Optional",
35
+ wizardNext: "Next",
36
+ wizardPrev: "Previous",
37
+ wizardFinish: "Finish",
38
+ wizardSkip: "Skip",
39
+ multiSelectInnerPlaceholder: "Search...",
40
+ multiSelectSelectedLabel: "Selected",
41
+ tableColumnResizer: "Resize column",
42
+ tableFilterColumnPlaceholder: "Filter by",
43
+ tableFilterColumnTitle: "Filter by",
44
+ tableFilterDropdownTitle: "Filters",
45
+ tableFilterDropdownTitleUnique: "Filter by",
46
+ tableFilterLabel: "Filters",
47
+ tableFilterNewFilter: "New filter",
48
+ tableFilterOperatorPlaceholder: "Equals to...",
49
+ tableFilterOperatorTitle: "Operation",
50
+ tableFilterTypeContains: "Contains",
51
+ tableFilterTypeEndsWith: "Ends with",
52
+ tableFilterTypeGreaterThan: "Greater than",
53
+ tableFilterTypeIs: "Is",
54
+ tableFilterTypeIsNot: "Is not",
55
+ tableFilterTypeLessThan: "Less than",
56
+ tableFilterTypeNotContains: "Not contains",
57
+ tableFilterTypeStartsWith: "Starts with",
58
+ tableFilterValuePlaceholder: "Something...",
59
+ tableFilterValueTitle: "Value",
60
+ tableGroupLabel: "Group",
61
+ tableGroupLabelWithCount: "Group",
62
+ tablePaginationFooter: (pagination) => (<Fragment>
63
+ {pagination.current} to {pagination.pages} of {pagination.totalItems} items.{Array.isArray(pagination.sizes) ? pagination.select : null}{" "}
64
+ per page.
65
+ </Fragment>),
66
+ tablePaginationNext: "Next",
67
+ tablePaginationPrevious: "Previous",
68
+ tablePaginationSelectLabel: "Select the size of page",
69
+ tableSortAddButton: "Add sort",
70
+ tableSortAsc: "Ascending",
71
+ tableSortDesc: "Descending",
72
+ tableSortDropdownTitle: "Order by",
73
+ tableSortOrderByLabel: "Order by",
74
+ tableSortOrderInputPlaceholder: "Order by",
75
+ tableSortOrderInputTitle: "Order by",
76
+ tableSortTypeInputPlaceholder: "Ascending",
77
+ tableSortTypeInputTitle: "Sort type",
78
+ uploadIdle: "You can drag your files here",
79
+ uploadIdleButton: "Choose your files",
80
+ uploadDragging: (props) => `Dragging ${props.n} ${props.n > 0 ? "files" : "file"}`,
81
+ uploadDialogTitle: "Details of your file",
82
+ datepickerPlaceholder: (_) => "day/month/year",
83
+ spinnerLoading: "Loading",
84
+ skeletonLoading: "Loading content",
85
+ closeButton: "Close",
86
+ fileUploadZoneLabel: "File upload area. Drag files here or press Enter to browse.",
87
+ };
@@ -0,0 +1,4 @@
1
+ export const defaultTweaks = {
2
+ input: { iconFeedback: true },
3
+ table: { operations: true, sorters: true, filters: true, sticky: undefined },
4
+ };
@@ -0,0 +1,2 @@
1
+ export const FLOATING_DELAY = 200;
2
+ export const TYPEAHEAD_RESET_DELAY = 500;