@tsed/react-formio 3.0.0-alpha.10 → 3.0.0-alpha.12

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 (215) hide show
  1. package/dist/atoms/icon/Icon.js.map +1 -1
  2. package/dist/chunks/index.js +33 -30
  3. package/dist/chunks/index.js.map +1 -1
  4. package/dist/chunks/index.module.js +16 -16
  5. package/dist/chunks/index.module.js.map +1 -1
  6. package/dist/chunks/react-select-animated.esm.js +1204 -1101
  7. package/dist/chunks/react-select-animated.esm.js.map +1 -1
  8. package/dist/hooks/keyboard.constants.d.ts +38 -0
  9. package/dist/hooks/keyboard.constants.js +7 -0
  10. package/dist/hooks/keyboard.constants.js.map +1 -0
  11. package/dist/hooks/useKeyboardControls.d.ts +12 -0
  12. package/dist/hooks/useKeyboardControls.js +35 -0
  13. package/dist/hooks/useKeyboardControls.js.map +1 -0
  14. package/dist/hooks/useTooltip.js.map +1 -1
  15. package/dist/interfaces/Operation.d.ts +12 -2
  16. package/dist/molecules/alert/Alert.js.map +1 -1
  17. package/dist/molecules/button/Button.d.ts +18 -5
  18. package/dist/molecules/button/Button.js +22 -26
  19. package/dist/molecules/button/Button.js.map +1 -1
  20. package/dist/molecules/card/Card.js +7 -5
  21. package/dist/molecules/card/Card.js.map +1 -1
  22. package/dist/molecules/forms/form-control/FormControl.js.map +1 -1
  23. package/dist/molecules/forms/input-tags/InputTags.js +14 -14
  24. package/dist/molecules/forms/input-tags/InputTags.js.map +1 -1
  25. package/dist/molecules/forms/input-tags/components/ChoicesTags.js +26 -26
  26. package/dist/molecules/forms/input-tags/components/ChoicesTags.js.map +1 -1
  27. package/dist/molecules/forms/input-tags/components/ReactTags.js +289 -300
  28. package/dist/molecules/forms/input-tags/components/ReactTags.js.map +1 -1
  29. package/dist/molecules/forms/input-text/InputText.js +3 -3
  30. package/dist/molecules/forms/input-text/InputText.js.map +1 -1
  31. package/dist/molecules/forms/select/Select.js.map +1 -1
  32. package/dist/molecules/forms/select/components/ChoicesSelect.js +71 -73
  33. package/dist/molecules/forms/select/components/ChoicesSelect.js.map +1 -1
  34. package/dist/molecules/forms/select/components/HtmlSelect.js.map +1 -1
  35. package/dist/molecules/forms/select/components/ReactSelect.js +13 -14
  36. package/dist/molecules/forms/select/components/ReactSelect.js.map +1 -1
  37. package/dist/molecules/forms/select/components/choices.template.js +2340 -2257
  38. package/dist/molecules/forms/select/components/choices.template.js.map +1 -1
  39. package/dist/molecules/forms/select/hooks/useOptions.js.map +1 -1
  40. package/dist/molecules/loader/Loader.js.map +1 -1
  41. package/dist/molecules/modal/Modal.js +23 -24
  42. package/dist/molecules/modal/Modal.js.map +1 -1
  43. package/dist/molecules/pagination/Pagination.js +19 -19
  44. package/dist/molecules/pagination/Pagination.js.map +1 -1
  45. package/dist/molecules/pagination/PaginationButton.js.map +1 -1
  46. package/dist/molecules/pagination/utils/getPageNumbers.js.map +1 -1
  47. package/dist/molecules/table/Table.d.ts +11 -3
  48. package/dist/molecules/table/Table.js +31 -32
  49. package/dist/molecules/table/Table.js.map +1 -1
  50. package/dist/molecules/table/components/DefaultArrowSort.js.map +1 -1
  51. package/dist/molecules/table/components/DefaultCell.js.map +1 -1
  52. package/dist/molecules/table/components/DefaultCellFooter.js.map +1 -1
  53. package/dist/molecules/table/components/DefaultCellHeader.js.map +1 -1
  54. package/dist/molecules/table/components/DefaultCellOperations.d.ts +12 -4
  55. package/dist/molecules/table/components/DefaultCellOperations.js +13 -7
  56. package/dist/molecules/table/components/DefaultCellOperations.js.map +1 -1
  57. package/dist/molecules/table/components/DefaultFilter.js.map +1 -1
  58. package/dist/molecules/table/components/DefaultOperationButton.d.ts +12 -4
  59. package/dist/molecules/table/components/DefaultOperationButton.js +1 -1
  60. package/dist/molecules/table/components/DefaultOperationButton.js.map +1 -1
  61. package/dist/molecules/table/filters/RangeFilter.js +23 -24
  62. package/dist/molecules/table/filters/RangeFilter.js.map +1 -1
  63. package/dist/molecules/table/filters/SelectFilter.js +11 -13
  64. package/dist/molecules/table/filters/SelectFilter.js.map +1 -1
  65. package/dist/molecules/table/filters/TextFieldFilter.js.map +1 -1
  66. package/dist/molecules/table/hooks/useTable.d.ts +12 -4
  67. package/dist/molecules/table/hooks/useTable.js +7 -7
  68. package/dist/molecules/table/hooks/useTable.js.map +1 -1
  69. package/dist/molecules/table/hooks/useUniqValues.js.map +1 -1
  70. package/dist/molecules/table/utils/mapFormToColumns.js +20 -21
  71. package/dist/molecules/table/utils/mapFormToColumns.js.map +1 -1
  72. package/dist/molecules/tabs/Tab.d.ts +13 -0
  73. package/dist/molecules/tabs/Tab.js +66 -0
  74. package/dist/molecules/tabs/Tab.js.map +1 -0
  75. package/dist/molecules/tabs/TabList.d.ts +2 -0
  76. package/dist/molecules/tabs/TabList.js +23 -0
  77. package/dist/molecules/tabs/TabList.js.map +1 -0
  78. package/dist/molecules/tabs/TabPanel.d.ts +9 -0
  79. package/dist/molecules/tabs/TabPanel.js +27 -0
  80. package/dist/molecules/tabs/TabPanel.js.map +1 -0
  81. package/dist/molecules/tabs/Tabs.d.ts +4 -16
  82. package/dist/molecules/tabs/Tabs.js +7 -67
  83. package/dist/molecules/tabs/Tabs.js.map +1 -1
  84. package/dist/molecules/tabs/TabsBody.d.ts +1 -0
  85. package/dist/molecules/tabs/TabsBody.js +10 -0
  86. package/dist/molecules/tabs/TabsBody.js.map +1 -0
  87. package/dist/molecules/tabs/TabsLegacy.d.ts +17 -0
  88. package/dist/molecules/tabs/TabsLegacy.js +49 -0
  89. package/dist/molecules/tabs/TabsLegacy.js.map +1 -0
  90. package/dist/molecules/tabs/all.d.ts +5 -0
  91. package/dist/molecules/tabs/all.js +13 -0
  92. package/dist/molecules/tabs/all.js.map +1 -0
  93. package/dist/molecules/tabs/context/TabControl.d.ts +52 -0
  94. package/dist/molecules/tabs/context/TabControl.js +85 -0
  95. package/dist/molecules/tabs/context/TabControl.js.map +1 -0
  96. package/dist/molecules/tabs/hooks/tabControl.d.ts +44 -0
  97. package/dist/molecules/tabs/hooks/tabControl.js +34 -0
  98. package/dist/molecules/tabs/hooks/tabControl.js.map +1 -0
  99. package/dist/organisms/form/Form.js.map +1 -1
  100. package/dist/organisms/form/access/FormAccess.js +41 -41
  101. package/dist/organisms/form/access/FormAccess.js.map +1 -1
  102. package/dist/organisms/form/access/FormAccess.schema.js.map +1 -1
  103. package/dist/organisms/form/access/FormAccess.utils.js +2 -2
  104. package/dist/organisms/form/access/FormAccess.utils.js.map +1 -1
  105. package/dist/organisms/form/{action → actions}/FormAction.js +7 -8
  106. package/dist/organisms/form/actions/FormAction.js.map +1 -0
  107. package/dist/organisms/form/builder/FormBuilder.js.map +1 -1
  108. package/dist/organisms/form/builder/FormEdit.d.ts +3 -1
  109. package/dist/organisms/form/builder/FormEdit.js +38 -35
  110. package/dist/organisms/form/builder/FormEdit.js.map +1 -1
  111. package/dist/organisms/form/builder/FormEdit.reducer.js.map +1 -1
  112. package/dist/organisms/form/builder/FormEditCtas.js +34 -34
  113. package/dist/organisms/form/builder/FormEditCtas.js.map +1 -1
  114. package/dist/organisms/form/builder/FormParameters.js.map +1 -1
  115. package/dist/organisms/form/builder/useFormBuilder.js +41 -38
  116. package/dist/organisms/form/builder/useFormBuilder.js.map +1 -1
  117. package/dist/organisms/form/builder/useFormEdit.js +1 -1
  118. package/dist/organisms/form/builder/useFormEdit.js.map +1 -1
  119. package/dist/organisms/form/exports/FormExport.d.ts +5 -0
  120. package/dist/organisms/form/exports/FormExport.js +55 -0
  121. package/dist/organisms/form/exports/FormExport.js.map +1 -0
  122. package/dist/organisms/form/preview/FormPreview.d.ts +6 -0
  123. package/dist/organisms/form/preview/FormPreview.js +11 -0
  124. package/dist/organisms/form/preview/FormPreview.js.map +1 -0
  125. package/dist/organisms/form/settings/FormSettings.js +24 -24
  126. package/dist/organisms/form/settings/FormSettings.js.map +1 -1
  127. package/dist/organisms/form/settings/FormSettings.schema.js.map +1 -1
  128. package/dist/organisms/form/settings/FormSettings.utils.js.map +1 -1
  129. package/dist/organisms/form/useForm.js +664 -661
  130. package/dist/organisms/form/useForm.js.map +1 -1
  131. package/dist/organisms/modal/RemoveModal.js +16 -17
  132. package/dist/organisms/modal/RemoveModal.js.map +1 -1
  133. package/dist/organisms/table/actions/ActionsTable.js.map +1 -1
  134. package/dist/organisms/table/forms/FormsTable.js.map +1 -1
  135. package/dist/organisms/table/forms/components/FormsCell.js.map +1 -1
  136. package/dist/organisms/table/submissions/SubmissionsTable.d.ts +11 -3
  137. package/dist/organisms/table/submissions/SubmissionsTable.js +4 -1
  138. package/dist/organisms/table/submissions/SubmissionsTable.js.map +1 -1
  139. package/dist/organisms/views/FormViews.d.ts +24 -0
  140. package/dist/organisms/views/FormViews.js +96 -0
  141. package/dist/organisms/views/FormViews.js.map +1 -0
  142. package/dist/registries/components.js.map +1 -1
  143. package/dist/utils/getEventValue.js.map +1 -1
  144. package/dist/utils/iconClass.js.map +1 -1
  145. package/dist/utils/mapPagination.js.map +1 -1
  146. package/dist/utils/stopPropagationWrapper.js.map +1 -1
  147. package/package.json +7 -7
  148. package/src/atoms/icon/Icon.stories.tsx +1 -1
  149. package/src/hooks/keyboard.constants.ts +40 -0
  150. package/src/hooks/useKeyboardControls.spec.tsx +208 -0
  151. package/src/hooks/useKeyboardControls.ts +84 -0
  152. package/src/interfaces/Operation.ts +9 -3
  153. package/src/molecules/button/Button.stories.tsx +1 -1
  154. package/src/molecules/button/Button.tsx +43 -24
  155. package/src/molecules/card/Card.tsx +4 -0
  156. package/src/molecules/forms/form-control/FormControl.stories.tsx +1 -1
  157. package/src/molecules/forms/input-tags/InputTags.tsx +1 -1
  158. package/src/molecules/forms/input-tags/components/ChoicesTags.stories.tsx +1 -1
  159. package/src/molecules/forms/input-tags/components/ReactTags.stories.tsx +1 -1
  160. package/src/molecules/forms/input-text/InputText.stories.tsx +2 -2
  161. package/src/molecules/forms/select/components/ChoicesSelect.stories.tsx +2 -2
  162. package/src/molecules/forms/select/components/HtmlSelect.stories.tsx +2 -2
  163. package/src/molecules/forms/select/components/ReactSelect.stories.tsx +2 -2
  164. package/src/molecules/loader/Loader.stories.tsx +1 -1
  165. package/src/molecules/modal/Modal.stories.tsx +1 -1
  166. package/src/molecules/pagination/Pagination.stories.tsx +1 -8
  167. package/src/molecules/pagination/Pagination.tsx +0 -1
  168. package/src/molecules/table/Table.stories.tsx +36 -3
  169. package/src/molecules/table/Table.tsx +12 -6
  170. package/src/molecules/table/components/DefaultCellOperations.tsx +13 -7
  171. package/src/molecules/table/components/DefaultOperationButton.tsx +5 -4
  172. package/src/molecules/table/filters/SelectFilter.tsx +1 -1
  173. package/src/molecules/table/hooks/useTable.tsx +5 -5
  174. package/src/molecules/tabs/Tab.tsx +106 -0
  175. package/src/molecules/tabs/TabList.tsx +37 -0
  176. package/src/molecules/tabs/TabPanel.tsx +37 -0
  177. package/src/molecules/tabs/Tabs.spec.tsx +126 -73
  178. package/src/molecules/tabs/Tabs.stories.tsx +298 -65
  179. package/src/molecules/tabs/Tabs.tsx +10 -81
  180. package/src/molecules/tabs/TabsBody.tsx +11 -0
  181. package/src/molecules/tabs/TabsLegacy.stories.tsx +103 -0
  182. package/src/molecules/tabs/TabsLegacy.tsx +84 -0
  183. package/src/molecules/tabs/all.ts +5 -0
  184. package/src/molecules/tabs/context/TabControl.tsx +166 -0
  185. package/src/molecules/tabs/hooks/tabControl.spec.tsx +388 -0
  186. package/src/molecules/tabs/hooks/tabControl.ts +52 -0
  187. package/src/organisms/__fixtures__/form-firstname.fixture.json +1 -0
  188. package/src/organisms/__fixtures__/form.fixture.json +1 -0
  189. package/src/organisms/form/Form.stories.tsx +94 -118
  190. package/src/organisms/form/access/FormAccess.stories.tsx +2 -2
  191. package/src/organisms/form/actions/FormAction.stories.tsx +422 -0
  192. package/src/organisms/form/builder/FormBuilder.stories.tsx +4 -1
  193. package/src/organisms/form/builder/FormEdit.stories.tsx +1 -1
  194. package/src/organisms/form/builder/FormEdit.tsx +7 -1
  195. package/src/organisms/form/builder/useFormBuilder.ts +5 -1
  196. package/src/organisms/form/builder/useFormEdit.ts +1 -1
  197. package/src/organisms/form/exports/FormExport.stories.tsx +71 -0
  198. package/src/organisms/form/exports/FormExport.tsx +58 -0
  199. package/src/organisms/form/preview/FormPreview.stories.tsx +61 -0
  200. package/src/organisms/form/preview/FormPreview.tsx +21 -0
  201. package/src/organisms/modal/RemoveModal.stories.tsx +1 -1
  202. package/src/organisms/table/actions/ActionsTable.stories.tsx +38 -36
  203. package/src/organisms/table/submissions/SubmissionsTable.stories.tsx +103 -57
  204. package/src/organisms/table/submissions/SubmissionsTable.tsx +10 -4
  205. package/src/organisms/views/FormViews.stories.tsx +224 -0
  206. package/src/organisms/views/FormViews.tsx +146 -0
  207. package/vite.config.mts +2 -2
  208. package/dist/organisms/form/action/FormAction.js.map +0 -1
  209. package/src/organisms/form/action/FormAction.stories.tsx +0 -364
  210. package/tsconfig.app.json +0 -11
  211. package/tsconfig.json +0 -21
  212. package/tsconfig.node.json +0 -13
  213. package/tsconfig.spec.json +0 -14
  214. /package/dist/organisms/form/{action → actions}/FormAction.d.ts +0 -0
  215. /package/src/organisms/form/{action → actions}/FormAction.tsx +0 -0
@@ -1,5 +1,5 @@
1
1
  import cx from "classnames";
2
- import { type ButtonHTMLAttributes, forwardRef, type LegacyRef, type PropsWithChildren } from "react";
2
+ import { type ButtonHTMLAttributes, forwardRef, type PropsWithChildren } from "react";
3
3
 
4
4
  import { registerComponent } from "../../registries/components";
5
5
 
@@ -24,31 +24,50 @@ export const BUTTON_VARIANTS = [
24
24
  "outline-link"
25
25
  ];
26
26
 
27
- export interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
27
+ interface BaseButtonProps<T extends HTMLElement> extends ButtonHTMLAttributes<T> {
28
+ tag?: "button" | "a" | "input" | "div";
28
29
  variant?: (typeof BUTTON_VARIANTS)[keyof typeof BUTTON_VARIANTS] | string;
29
30
  }
30
31
 
31
- export const Button = forwardRef(
32
- ({ variant, className, children, ...props }: PropsWithChildren<ButtonProps>, ref: LegacyRef<HTMLButtonElement>) => {
33
- return (
34
- <button
35
- {...props}
36
- ref={ref}
37
- className={cx(
38
- "btn flex gap-1",
39
- {
40
- disabled: props.disabled
41
- },
42
- `btn-${variant}`,
43
- className
44
- )}
45
- disabled={props.disabled}
46
- onClick={(evt) => !props.disabled && props.onClick?.(evt)}
47
- >
48
- {children}
49
- </button>
50
- );
51
- }
52
- );
32
+ interface HTMLAnchorProps extends BaseButtonProps<HTMLAnchorElement> {
33
+ tag: "a";
34
+ }
35
+
36
+ interface HTMLButtonProps extends BaseButtonProps<HTMLButtonElement> {
37
+ tag?: "button";
38
+ }
39
+
40
+ interface HTMLInputProps extends BaseButtonProps<HTMLInputElement> {
41
+ tag: "input";
42
+ }
43
+
44
+ interface HTMLDivProps extends BaseButtonProps<HTMLDivElement> {
45
+ tag: "div";
46
+ }
47
+
48
+ export type ButtonProps = HTMLAnchorProps | HTMLButtonProps | HTMLInputProps | HTMLDivProps;
49
+
50
+ export const Button = forwardRef(({ tag: Tag = "button", variant, className, children, ...props }: PropsWithChildren<ButtonProps>, ref) => {
51
+ return (
52
+ <Tag
53
+ {...(props as any)}
54
+ ref={ref as any}
55
+ className={cx(
56
+ "btn flex gap-1",
57
+ {
58
+ disabled: props.disabled
59
+ },
60
+ `btn-${variant}`,
61
+ className
62
+ )}
63
+ disabled={props.disabled}
64
+ onClick={(evt) => !props.disabled && props.onClick?.(evt as any)}
65
+ >
66
+ {children}
67
+ </Tag>
68
+ );
69
+ });
70
+
71
+ Button.displayName = "Button";
53
72
 
54
73
  registerComponent("Button", Button);
@@ -1,6 +1,8 @@
1
1
  import classnames from "classnames";
2
2
  import { PropsWithChildren } from "react";
3
3
 
4
+ import { registerComponent } from "../../registries/components.js";
5
+
4
6
  export interface CardProps {
5
7
  label: string;
6
8
  className?: string;
@@ -18,3 +20,5 @@ export function Card({ children, label, className }: PropsWithChildren<CardProps
18
20
  </div>
19
21
  );
20
22
  }
23
+
24
+ registerComponent("Card", Card);
@@ -1,4 +1,4 @@
1
- import { Meta, StoryObj } from "@storybook/react";
1
+ import { Meta, StoryObj } from "@storybook/react-vite";
2
2
 
3
3
  import { iconClass } from "../../../utils/iconClass";
4
4
  import { FormControl } from "./FormControl";
@@ -9,7 +9,7 @@ export function InputTags<Data = string>(props: InputTagsProps) {
9
9
 
10
10
  const FormControl = getComponent<typeof DefaultFormControl>("FormControl");
11
11
  const Component = getComponent<ComponentType<InputTagsProps<Data>>>([`InputTags.${layout}`, "Input"]);
12
- console.log("VALUE", props.value);
12
+
13
13
  return (
14
14
  <FormControl
15
15
  id={id}
@@ -1,6 +1,6 @@
1
1
  import "../all";
2
2
 
3
- import type { Meta, StoryObj } from "@storybook/react";
3
+ import type { Meta, StoryObj } from "@storybook/react-vite";
4
4
 
5
5
  import { iconClass } from "../../../../utils/iconClass";
6
6
  import { useValue } from "../../../__fixtures__/useValue.hook";
@@ -1,6 +1,6 @@
1
1
  import "../all";
2
2
 
3
- import type { Meta, StoryObj } from "@storybook/react";
3
+ import type { Meta, StoryObj } from "@storybook/react-vite";
4
4
  import { type CreatableProps } from "react-select/creatable";
5
5
 
6
6
  import { iconClass } from "../../../../utils/iconClass";
@@ -1,5 +1,5 @@
1
- import type { Meta, StoryObj } from "@storybook/react";
2
- import { expect, userEvent, within } from "@storybook/test";
1
+ import type { Meta, StoryObj } from "@storybook/react-vite";
2
+ import { expect, userEvent, within } from "storybook/test";
3
3
 
4
4
  import { iconClass } from "../../../utils/iconClass";
5
5
  import { useValue } from "../../__fixtures__/useValue.hook";
@@ -1,7 +1,7 @@
1
1
  import "./ChoicesSelect";
2
2
 
3
- import { Meta, StoryObj } from "@storybook/react";
4
- import { fn } from "@storybook/test";
3
+ import { Meta, StoryObj } from "@storybook/react-vite";
4
+ import { fn } from "storybook/test";
5
5
 
6
6
  import { iconClass } from "../../../../utils/iconClass";
7
7
  import { useValue } from "../../../__fixtures__/useValue.hook";
@@ -1,7 +1,7 @@
1
1
  import "./HtmlSelect";
2
2
 
3
- import { Meta, StoryObj } from "@storybook/react";
4
- import { expect, fn, userEvent, within } from "@storybook/test";
3
+ import { Meta, StoryObj } from "@storybook/react-vite";
4
+ import { expect, fn, userEvent, within } from "storybook/test";
5
5
 
6
6
  import { iconClass } from "../../../../utils/iconClass";
7
7
  import { useValue } from "../../../__fixtures__/useValue.hook";
@@ -1,7 +1,7 @@
1
1
  import "../all";
2
2
 
3
- import { Meta, StoryObj } from "@storybook/react";
4
- import { fn } from "@storybook/test";
3
+ import { Meta, StoryObj } from "@storybook/react-vite";
4
+ import { fn } from "storybook/test";
5
5
 
6
6
  import { iconClass } from "../../../../utils/iconClass";
7
7
  import { useValue } from "../../../__fixtures__/useValue.hook";
@@ -1,4 +1,4 @@
1
- import type { Meta, StoryObj } from "@storybook/react";
1
+ import type { Meta, StoryObj } from "@storybook/react-vite";
2
2
  import tailwind from "@tsed/tailwind-formio";
3
3
 
4
4
  import { Loader } from "./Loader";
@@ -1,4 +1,4 @@
1
- import { Meta, StoryObj } from "@storybook/react";
1
+ import { Meta, StoryObj } from "@storybook/react-vite";
2
2
 
3
3
  import { Modal, ModalProps, useModal } from "./Modal";
4
4
 
@@ -1,6 +1,6 @@
1
1
  import "../forms/select/all";
2
2
 
3
- import { Meta, StoryObj } from "@storybook/react";
3
+ import { Meta, StoryObj } from "@storybook/react-vite";
4
4
  import { useEffect, useState } from "react";
5
5
 
6
6
  import { Pagination } from "./all";
@@ -12,18 +12,11 @@ import { Pagination } from "./all";
12
12
  *
13
13
  * ```tsx
14
14
  * import {Pagination} from "@tsed/react-formio/molecules/pagination/all"
15
- * import {Pagination} from "@tsed/react-formio/molecules/form/select/Select/all"
16
15
  *
17
16
  * or
18
17
  *
19
18
  * import {Pagination} from "@tsed/react-formio/molecules/pagination/Pagination";
20
19
  * import "@tsed/react-formio/molecules/pagination/PaginationButton";
21
- *
22
- * or
23
- *
24
- * import {Pagination} from "@tsed/react-formio/molecules/pagination/Pagination";
25
- *
26
- * registerComponent("PaginationButton", MyPaginationButton);
27
20
  * ```
28
21
  *
29
22
  * Pagination component support DI container and can be used with custom PaginationButton component.
@@ -95,7 +95,6 @@ export function Pagination(props: PaginationProps) {
95
95
  multiple={false}
96
96
  layout={props.layout}
97
97
  onChange={(_, value) => {
98
- console.log("On page change", value);
99
98
  onPageSizeChange(+value);
100
99
  }}
101
100
  />
@@ -1,7 +1,7 @@
1
1
  import "./all";
2
2
 
3
- import type { Meta, StoryObj } from "@storybook/react";
4
- import { expect, fn, userEvent, waitFor, within } from "@storybook/test";
3
+ import type { Meta, StoryObj } from "@storybook/react-vite";
4
+ import { expect, fn, userEvent, waitFor, within } from "storybook/test";
5
5
 
6
6
  import { SubmissionType } from "../../interfaces";
7
7
  import FormType from "../__fixtures__/form-schema.json";
@@ -19,7 +19,40 @@ type ProductSubmission = SubmissionType<{
19
19
  price?: number;
20
20
  currency?: string;
21
21
  }>;
22
-
22
+ /**
23
+ * Table component.
24
+ *
25
+ * You can import this component and use it like:
26
+ *
27
+ * ```tsx
28
+ * import {Table} from "@tsed/react-formio/molecules/table/all"
29
+ *
30
+ * or
31
+ *
32
+ * import {Table} from "@tsed/react-formio/molecules/table/Table";
33
+ * ```
34
+ *
35
+ * Table component support DI container and can be used with custom component. Here is the list of components that you can override:
36
+ *
37
+ * - DefaultFilter
38
+ * - DefaultArrowSort
39
+ * - DefaultCell
40
+ * - DefaultCellOperations
41
+ * - DefaultOperationButton
42
+ * - DefaultCellHeader
43
+ * - DefaultCellFooter
44
+ * - TextFieldFilter
45
+ * - SelectFilter
46
+ * - RangeFilter
47
+ *
48
+ * ```tsx
49
+ * function CustomDefaultFilter() {
50
+ *
51
+ * }
52
+ *
53
+ * registerComponent("DefaultFilter", DefaultFilter);
54
+ * ```
55
+ */
23
56
  export default {
24
57
  title: "Table",
25
58
  component: Table,
@@ -1,14 +1,15 @@
1
- import { flexRender, RowData } from "@tanstack/react-table";
1
+ import { flexRender } from "@tanstack/react-table";
2
2
  import cx from "classnames";
3
3
  import { PropsWithChildren } from "react";
4
4
 
5
+ import type { JSON } from "../../interfaces/index.js";
5
6
  import { getComponent } from "../../registries/components";
6
7
  import type { Pagination as DefaultPagination } from "../pagination/Pagination";
7
8
  import type { DefaultCellFooter } from "./components/DefaultCellFooter";
8
9
  import type { DefaultCellHeader } from "./components/DefaultCellHeader";
9
10
  import { useTable, UseTableProps } from "./hooks/useTable";
10
11
 
11
- export interface TableProps<Data extends RowData = any> extends UseTableProps<Data> {
12
+ export interface TableProps<Data extends { [key: string]: JSON } = { [key: string]: JSON }> extends UseTableProps<Data> {
12
13
  className?: string;
13
14
 
14
15
  enableFooter?: boolean;
@@ -16,8 +17,13 @@ export interface TableProps<Data extends RowData = any> extends UseTableProps<Da
16
17
  pageSizes?: number[];
17
18
  }
18
19
 
19
- export function Table<Data extends RowData = any>({ className, enableFooter, children, ...props }: PropsWithChildren<TableProps<Data>>) {
20
- const { tableInstance, i18n } = useTable(props);
20
+ export function Table<Data extends { [key: string]: JSON } = { [key: string]: JSON }>({
21
+ className,
22
+ enableFooter,
23
+ children,
24
+ ...props
25
+ }: PropsWithChildren<TableProps<Data>>) {
26
+ const { tableInstance, i18n } = useTable<Data>(props);
21
27
  const CellHeader = getComponent<typeof DefaultCellHeader>("CellHeader");
22
28
  const CellFooter = getComponent<typeof DefaultCellFooter>("CellFooter");
23
29
  const Pagination = getComponent<typeof DefaultPagination>("Pagination");
@@ -76,7 +82,7 @@ export function Table<Data extends RowData = any>({ className, enableFooter, chi
76
82
  )}
77
83
  </table>
78
84
  <div className={"overflow-hidden flex flex-wrap"}>
79
- {props.data.length && pagination && (
85
+ {props.data.length && pagination ? (
80
86
  <Pagination
81
87
  className={"flex-1"}
82
88
  canNextPage={tableInstance.getCanNextPage()}
@@ -92,7 +98,7 @@ export function Table<Data extends RowData = any>({ className, enableFooter, chi
92
98
  onClickNextPage={() => tableInstance.nextPage()}
93
99
  onPageSizeChange={(pageSize) => tableInstance.setPageSize(pageSize)}
94
100
  />
95
- )}
101
+ ) : null}
96
102
  <div>{children}</div>
97
103
  </div>
98
104
  </div>
@@ -1,24 +1,30 @@
1
1
  import type { CellContext } from "@tanstack/react-table";
2
2
 
3
- import type { Operation } from "../../../interfaces";
3
+ import type { CellMetadata, JSON, Operation } from "../../../interfaces";
4
4
  import { getComponent, registerComponent } from "../../../registries/components";
5
5
  import type { DefaultOperationButton } from "./DefaultOperationButton";
6
6
 
7
- export interface DefaultCellOperationsProps<Data = any> {
7
+ export interface DefaultCellOperationsProps<Data extends { [key: string]: JSON } = { [key: string]: JSON }> {
8
8
  info: CellContext<Data, unknown>;
9
9
  operations: Operation<Data>[];
10
- metadata?: Record<string, unknown>;
10
+ metadata?: CellMetadata;
11
11
  i18n: (i18n: string) => string;
12
12
  onClick?: (data: any, operation: Operation<Data>) => void;
13
13
  }
14
14
 
15
- export function DefaultCellOperations({ info, metadata, operations, i18n, onClick }: DefaultCellOperationsProps) {
16
- const Button = getComponent<typeof DefaultOperationButton>("OperationButton");
15
+ export function DefaultCellOperations<Data extends { [key: string]: JSON } = { [key: string]: JSON }>({
16
+ info,
17
+ metadata,
18
+ operations,
19
+ i18n,
20
+ onClick
21
+ }: DefaultCellOperationsProps<Data>) {
22
+ const Button = getComponent<typeof DefaultOperationButton<Data>>("OperationButton");
17
23
  return (
18
24
  <div className='btn-group'>
19
25
  {operations
20
- .filter(({ permissionsResolver }) => {
21
- return !permissionsResolver || permissionsResolver(info.row.original, metadata);
26
+ .filter(({ permissionsResolver, ...operation }) => {
27
+ return !permissionsResolver || permissionsResolver(info.row.original, metadata || {}, operation);
22
28
  })
23
29
  .map((operation) => {
24
30
  return (
@@ -2,20 +2,21 @@ import { CellContext } from "@tanstack/react-table";
2
2
  import cx from "classnames";
3
3
  import { HTMLAttributes } from "react";
4
4
 
5
- import { Operation } from "../../../interfaces";
5
+ import { type CellMetadata, type JSON, Operation } from "../../../interfaces";
6
6
  import { registerComponent } from "../../../registries/components";
7
7
  import { iconClass } from "../../../utils/iconClass";
8
8
  import { stopPropagationWrapper } from "../../../utils/stopPropagationWrapper";
9
9
 
10
- export interface OperationButtonProps<Data = any> extends Omit<HTMLAttributes<HTMLButtonElement>, "onClick"> {
10
+ export interface OperationButtonProps<Data extends { [key: string]: JSON } = { [key: string]: JSON }>
11
+ extends Omit<HTMLAttributes<HTMLButtonElement>, "onClick"> {
11
12
  operation: Operation<Data>;
12
13
  info: CellContext<Data, unknown>;
13
- metadata?: Record<string, unknown>;
14
+ metadata?: CellMetadata;
14
15
  onClick: () => void;
15
16
  i18n?: (i18n: string) => string;
16
17
  }
17
18
 
18
- export function DefaultOperationButton(props: OperationButtonProps) {
19
+ export function DefaultOperationButton<Data extends { [key: string]: JSON } = { [key: string]: JSON }>(props: OperationButtonProps<Data>) {
19
20
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
20
21
  const { i18n = (f: string) => f, onClick, operation, info, ...extraProps } = props;
21
22
  const { className = "btn", buttonSize = "xs", buttonType = "primary", buttonOutline, action, title = "", icon = "" } = operation;
@@ -9,7 +9,7 @@ export function SelectFilter<Data = any>({ header, options }: FilterProps<Data,
9
9
  const Select = getComponent<typeof DefaultSelect>("Select");
10
10
  const columnFilterValue = header.column.getFilterValue();
11
11
  const uniqValues = useUniqValues<Data>({ header, filterVariant: "text" });
12
- console.log(uniqValues);
12
+
13
13
  const opts =
14
14
  options.layout === "choicesjs"
15
15
  ? {
@@ -6,18 +6,18 @@ import {
6
6
  getFilteredRowModel,
7
7
  getPaginationRowModel,
8
8
  getSortedRowModel,
9
- type RowData,
10
9
  type TableOptions,
11
10
  type TableState,
12
11
  useReactTable
13
12
  } from "@tanstack/react-table";
14
13
  import { useEffect } from "react";
15
14
 
16
- import { Operation } from "../../../interfaces";
15
+ import { type JSON, Operation } from "../../../interfaces";
17
16
  import { getComponent } from "../../../registries/components";
18
17
  import type { DefaultCellOperations } from "../components/DefaultCellOperations";
19
18
 
20
- export interface UseTableProps<Data extends RowData> extends TableOptions<Data> {
19
+ export interface UseTableProps<Data extends { [key: string]: JSON } = { [key: string]: JSON }>
20
+ extends Omit<TableOptions<Data>, "getCoreRowModel" | "onClick"> {
21
21
  operations: Operation<Data>[];
22
22
  metadata?: Record<string, unknown>;
23
23
  i18n?: (i18n: string) => string;
@@ -27,8 +27,8 @@ export interface UseTableProps<Data extends RowData> extends TableOptions<Data>
27
27
  pageSizes?: number[];
28
28
  }
29
29
 
30
- export function useTable<Data extends RowData>(props: UseTableProps<Data>) {
31
- const Operations = getComponent<typeof DefaultCellOperations>("CellOperations");
30
+ export function useTable<Data extends { [key: string]: JSON } = { [key: string]: JSON }>(props: UseTableProps<Data>) {
31
+ const Operations = getComponent<typeof DefaultCellOperations<Data>>("CellOperations");
32
32
  const i18n = props.i18n || ((f: string) => f);
33
33
 
34
34
  // const [pagination, setPagination] = useState({
@@ -0,0 +1,106 @@
1
+ import classnames from "classnames";
2
+ import { PropsWithChildren, useCallback, useEffect, useRef } from "react";
3
+
4
+ import { useKeyboardControls } from "../../hooks/useKeyboardControls.js";
5
+ import { registerComponent } from "../../registries/components.js";
6
+ import { iconClass } from "../../utils/iconClass.js";
7
+ import { useActiveTab, useRegisterTabControl, useTabsUid } from "./hooks/tabControl.js";
8
+
9
+ export interface TabProps {
10
+ icon?: string;
11
+ isActive?: boolean;
12
+ className?: string;
13
+ after?: React.ReactNode;
14
+ value: number;
15
+ /**
16
+ * on tab select handler
17
+ */
18
+ onClick?: (value: number) => void;
19
+ }
20
+
21
+ export function Tab({ onClick, icon, value, children, className, after }: PropsWithChildren<TabProps>) {
22
+ const uid = useTabsUid();
23
+ const ref = useRef<HTMLButtonElement>(null);
24
+ const activeTab = useActiveTab();
25
+ const dispatch = useRegisterTabControl({ value, ref });
26
+ const previousActiveTab = useRef(activeTab);
27
+
28
+ const isActive = useRef(activeTab === value);
29
+ isActive.current = activeTab === value;
30
+
31
+ useEffect(() => {
32
+ if (previousActiveTab.current !== activeTab && value === activeTab) {
33
+ ref.current?.focus();
34
+ onClick?.(value);
35
+ }
36
+ if (previousActiveTab.current !== activeTab) {
37
+ previousActiveTab.current = activeTab;
38
+ }
39
+ }, [value, onClick, activeTab]);
40
+
41
+ const start = useCallback(() => {
42
+ dispatch({ type: "start" });
43
+ }, [dispatch]);
44
+
45
+ const end = useCallback(() => {
46
+ dispatch({ type: "end" });
47
+ }, [dispatch]);
48
+
49
+ const up = useCallback(() => {
50
+ dispatch({ type: "previous" });
51
+ }, [dispatch]);
52
+
53
+ const down = useCallback(() => {
54
+ dispatch({ type: "next" });
55
+ }, [dispatch]);
56
+
57
+ const left = useCallback(() => {
58
+ const isRTL = document.documentElement.dir === "rtl";
59
+
60
+ dispatch({ type: isRTL ? "next" : "previous" });
61
+ }, [dispatch]);
62
+
63
+ const right = useCallback(() => {
64
+ const isRTL = document.documentElement.dir === "rtl";
65
+
66
+ dispatch({ type: isRTL ? "previous" : "next" });
67
+ }, [dispatch]);
68
+
69
+ const handleKeyDown = useKeyboardControls({
70
+ start,
71
+ end,
72
+ up,
73
+ down,
74
+ left,
75
+ right
76
+ });
77
+
78
+ const handleClick = useCallback(() => {
79
+ dispatch({ type: "update", payload: value });
80
+ }, [dispatch, value]);
81
+
82
+ return (
83
+ <div title={"button-wrapper"} className={classnames("tw-tabs__button-wrapper", className, { "-active": isActive.current }, className)}>
84
+ <button
85
+ ref={ref}
86
+ id={`Tab_${value}_${uid}`}
87
+ data-name='Tab'
88
+ title='button-tab'
89
+ role='tab'
90
+ aria-selected={isActive.current}
91
+ aria-controls={`TabPanel_${value}_${uid}`}
92
+ tabIndex={isActive.current ? 0 : -1}
93
+ className={"tw-tabs__button"}
94
+ onClick={handleClick}
95
+ onKeyDown={handleKeyDown}
96
+ >
97
+ {icon && <i className={classnames(iconClass(undefined, icon), "tw-tabs__button-icon")} />}
98
+ <span className={"tw-tabs__button-label"}>{children}</span>
99
+ {after}
100
+ </button>
101
+ <div className='tw-tabs__button-border' />
102
+ </div>
103
+ );
104
+ }
105
+
106
+ registerComponent("Tab", Tab);
@@ -0,0 +1,37 @@
1
+ import { Children, isValidElement, PropsWithChildren, ReactNode } from "react";
2
+
3
+ import { registerComponent } from "../../registries/components.js";
4
+
5
+ export function TabList(props: PropsWithChildren<{}>) {
6
+ const before: ReactNode[] = [];
7
+ const after: ReactNode[] = [];
8
+ const items: ReactNode[] = [];
9
+
10
+ Children.forEach(props.children, (child) => {
11
+ if (isValidElement(child)) {
12
+ if ((child.type as any)?.name === "Tab") {
13
+ items.push(child);
14
+ return;
15
+ }
16
+ }
17
+
18
+ if (items.length > 0) {
19
+ after.push(child);
20
+ } else {
21
+ before.push(child);
22
+ }
23
+ });
24
+
25
+ return (
26
+ <nav className='tw-tabs__header'>
27
+ <div className='tw-tabs__header-wrapper'>
28
+ <div className='tw-tabs__header-border' />
29
+ {before}
30
+ <div role='tablist'>{items}</div>
31
+ {after}
32
+ </div>
33
+ </nav>
34
+ );
35
+ }
36
+
37
+ registerComponent("TabList", TabList);
@@ -0,0 +1,37 @@
1
+ import classnames from "classnames";
2
+
3
+ import { registerComponent } from "../../registries/components.js";
4
+ import { useActiveTab, useTabsUid } from "./hooks/tabControl.js";
5
+
6
+ export interface TabPanelProps {
7
+ className?: string;
8
+ /**
9
+ * Tab panel index<br/>
10
+ * _Can be **0** or **1** indexed_
11
+ */
12
+ value: number;
13
+ }
14
+
15
+ export function TabPanel({ value, className, children }: React.PropsWithChildren<TabPanelProps>) {
16
+ const tabSelected = useActiveTab();
17
+ const uid = useTabsUid();
18
+ const isActive = tabSelected === value;
19
+
20
+ return (
21
+ <div
22
+ id={`TabPanel_${value}_${uid}`}
23
+ data-name={`TabPanel_${value}`}
24
+ role='tabpanel'
25
+ aria-hidden={!isActive}
26
+ aria-labelledby={`Tab_${value}_${uid}`}
27
+ tabIndex={isActive ? 0 : -1}
28
+ className={classnames("tw-tabs__panel", className, {
29
+ "-active": isActive
30
+ })}
31
+ >
32
+ {children}
33
+ </div>
34
+ );
35
+ }
36
+
37
+ registerComponent("TabPanel", TabPanel);