@ayasofyazilim/ui 0.0.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 (236) hide show
  1. package/__mocks__/canvas.ts +8 -0
  2. package/components.json +21 -0
  3. package/eslint.config.js +4 -0
  4. package/jest-environment.js +37 -0
  5. package/jest.config.ts +47 -0
  6. package/jest.setup.ts +69 -0
  7. package/package.json +124 -0
  8. package/postcss.config.mjs +6 -0
  9. package/src/aria/index.tsx +1 -0
  10. package/src/aria/number-field.tsx +41 -0
  11. package/src/components/.gitkeep +0 -0
  12. package/src/components/accordion.tsx +66 -0
  13. package/src/components/alert-dialog.tsx +157 -0
  14. package/src/components/alert.tsx +70 -0
  15. package/src/components/aspect-ratio.tsx +11 -0
  16. package/src/components/avatar.tsx +53 -0
  17. package/src/components/badge.tsx +67 -0
  18. package/src/components/breadcrumb.tsx +109 -0
  19. package/src/components/button-group.tsx +83 -0
  20. package/src/components/button.tsx +68 -0
  21. package/src/components/calendar.tsx +219 -0
  22. package/src/components/card.tsx +92 -0
  23. package/src/components/carousel.tsx +241 -0
  24. package/src/components/chart.tsx +363 -0
  25. package/src/components/checkbox.tsx +32 -0
  26. package/src/components/collapsible.tsx +33 -0
  27. package/src/components/command.tsx +184 -0
  28. package/src/components/context-menu.tsx +252 -0
  29. package/src/components/dialog.tsx +144 -0
  30. package/src/components/drawer.tsx +135 -0
  31. package/src/components/dropdown-menu.tsx +258 -0
  32. package/src/components/empty.tsx +100 -0
  33. package/src/components/field.tsx +248 -0
  34. package/src/components/form.tsx +169 -0
  35. package/src/components/hover-card.tsx +44 -0
  36. package/src/components/input-group.tsx +170 -0
  37. package/src/components/input-otp.tsx +77 -0
  38. package/src/components/input.tsx +21 -0
  39. package/src/components/item.tsx +193 -0
  40. package/src/components/kbd.tsx +28 -0
  41. package/src/components/label.tsx +24 -0
  42. package/src/components/menubar.tsx +276 -0
  43. package/src/components/navigation-menu.tsx +168 -0
  44. package/src/components/pagination.tsx +130 -0
  45. package/src/components/popover.tsx +88 -0
  46. package/src/components/progress.tsx +31 -0
  47. package/src/components/radio-group.tsx +45 -0
  48. package/src/components/resizable.tsx +56 -0
  49. package/src/components/scroll-area.tsx +58 -0
  50. package/src/components/select.tsx +189 -0
  51. package/src/components/separator.tsx +28 -0
  52. package/src/components/sheet.tsx +140 -0
  53. package/src/components/sidebar.tsx +862 -0
  54. package/src/components/skeleton.tsx +13 -0
  55. package/src/components/slider.tsx +63 -0
  56. package/src/components/sonner.tsx +40 -0
  57. package/src/components/spinner.tsx +16 -0
  58. package/src/components/stepper.tsx +291 -0
  59. package/src/components/switch.tsx +31 -0
  60. package/src/components/table.tsx +133 -0
  61. package/src/components/tabs.tsx +66 -0
  62. package/src/components/textarea.tsx +18 -0
  63. package/src/components/toggle-group.tsx +83 -0
  64. package/src/components/toggle.tsx +47 -0
  65. package/src/components/tooltip.tsx +66 -0
  66. package/src/custom/action-button.tsx +48 -0
  67. package/src/custom/async-select.tsx +287 -0
  68. package/src/custom/awesome-not-found.tsx +116 -0
  69. package/src/custom/charts/area-chart.tsx +147 -0
  70. package/src/custom/charts/bar-chart.tsx +233 -0
  71. package/src/custom/charts/chart-card.tsx +103 -0
  72. package/src/custom/charts/index.tsx +16 -0
  73. package/src/custom/charts/pie-chart.tsx +168 -0
  74. package/src/custom/charts/radar-chart.tsx +126 -0
  75. package/src/custom/checkbox-tree.tsx +100 -0
  76. package/src/custom/combobox.tsx +296 -0
  77. package/src/custom/confirm-dialog.tsx +102 -0
  78. package/src/custom/country-selector.tsx +204 -0
  79. package/src/custom/date-picker/calendar-rac.tsx +109 -0
  80. package/src/custom/date-picker/datefield-rac.tsx +84 -0
  81. package/src/custom/date-picker/index.tsx +273 -0
  82. package/src/custom/date-picker/types/index.ts +4 -0
  83. package/src/custom/date-picker/utils/index.ts +42 -0
  84. package/src/custom/date-picker-old.tsx +50 -0
  85. package/src/custom/date-tooltip.tsx +98 -0
  86. package/src/custom/document-scanner/consts.ts +5 -0
  87. package/src/custom/document-scanner/corner-adjustment/action-buttons.tsx +33 -0
  88. package/src/custom/document-scanner/corner-adjustment/corner-handle.tsx +43 -0
  89. package/src/custom/document-scanner/corner-adjustment/hooks/use-corner-drag.ts +85 -0
  90. package/src/custom/document-scanner/corner-adjustment/index.tsx +125 -0
  91. package/src/custom/document-scanner/corner-adjustment/types.ts +53 -0
  92. package/src/custom/document-scanner/corner-adjustment/utils/clip-path.ts +22 -0
  93. package/src/custom/document-scanner/corner-adjustment/zoom-magnifier.tsx +115 -0
  94. package/src/custom/document-scanner/hooks/use-document-capture.ts +81 -0
  95. package/src/custom/document-scanner/hooks/use-document-scanner.ts +80 -0
  96. package/src/custom/document-scanner/hooks/use-perspective-crop.ts +38 -0
  97. package/src/custom/document-scanner/index.tsx +255 -0
  98. package/src/custom/document-scanner/lib.ts +407 -0
  99. package/src/custom/document-scanner/types.ts +205 -0
  100. package/src/custom/document-scanner/utils/perspective-correction.ts +139 -0
  101. package/src/custom/document-viewer/controllers.tsx +98 -0
  102. package/src/custom/document-viewer/index.tsx +43 -0
  103. package/src/custom/document-viewer/renderers/image.tsx +37 -0
  104. package/src/custom/document-viewer/renderers/index.tsx +2 -0
  105. package/src/custom/document-viewer/renderers/pdf.tsx +105 -0
  106. package/src/custom/email-input/domains.json +159 -0
  107. package/src/custom/email-input/email.tsx +229 -0
  108. package/src/custom/email-input/index.tsx +4 -0
  109. package/src/custom/email-input/types.ts +104 -0
  110. package/src/custom/file-uploader.tsx +541 -0
  111. package/src/custom/filter-component/fields/async-select.tsx +33 -0
  112. package/src/custom/filter-component/fields/date.tsx +60 -0
  113. package/src/custom/filter-component/fields/multi-select.tsx +30 -0
  114. package/src/custom/filter-component/index.tsx +217 -0
  115. package/src/custom/image-canvas.tsx +260 -0
  116. package/src/custom/json-editor.tsx +22 -0
  117. package/src/custom/master-data-grid/components/dialogs/column-settings-dialog.tsx +100 -0
  118. package/src/custom/master-data-grid/components/dialogs/index.ts +1 -0
  119. package/src/custom/master-data-grid/components/filters/client-filter.tsx +368 -0
  120. package/src/custom/master-data-grid/components/filters/filter-input.tsx +256 -0
  121. package/src/custom/master-data-grid/components/filters/index.ts +3 -0
  122. package/src/custom/master-data-grid/components/filters/inline-column-filter.tsx +233 -0
  123. package/src/custom/master-data-grid/components/filters/multi-filter-dialog.tsx +90 -0
  124. package/src/custom/master-data-grid/components/filters/server-filter.tsx +255 -0
  125. package/src/custom/master-data-grid/components/master-data-grid.tsx +472 -0
  126. package/src/custom/master-data-grid/components/pagination/index.ts +1 -0
  127. package/src/custom/master-data-grid/components/pagination/pagination.tsx +178 -0
  128. package/src/custom/master-data-grid/components/table/cell-renderer.tsx +634 -0
  129. package/src/custom/master-data-grid/components/table/header-cell.tsx +162 -0
  130. package/src/custom/master-data-grid/components/table/index.ts +4 -0
  131. package/src/custom/master-data-grid/components/table/table-body-renderer.tsx +113 -0
  132. package/src/custom/master-data-grid/components/table/virtual-body.tsx +138 -0
  133. package/src/custom/master-data-grid/components/toolbar/index.ts +1 -0
  134. package/src/custom/master-data-grid/components/toolbar/toolbar.tsx +314 -0
  135. package/src/custom/master-data-grid/hooks/index.ts +3 -0
  136. package/src/custom/master-data-grid/hooks/use-columns.tsx +332 -0
  137. package/src/custom/master-data-grid/hooks/use-editing.ts +106 -0
  138. package/src/custom/master-data-grid/hooks/use-table-state-reducer.ts +157 -0
  139. package/src/custom/master-data-grid/hooks/use-table-state.ts +31 -0
  140. package/src/custom/master-data-grid/index.ts +16 -0
  141. package/src/custom/master-data-grid/types.ts +466 -0
  142. package/src/custom/master-data-grid/utils/column-generator.tsx +306 -0
  143. package/src/custom/master-data-grid/utils/export-utils.ts +67 -0
  144. package/src/custom/master-data-grid/utils/filter-fns.ts +290 -0
  145. package/src/custom/master-data-grid/utils/index.ts +8 -0
  146. package/src/custom/master-data-grid/utils/pinning-utils.ts +88 -0
  147. package/src/custom/master-data-grid/utils/translation-utils.ts +42 -0
  148. package/src/custom/multi-select.tsx +432 -0
  149. package/src/custom/password-input.tsx +194 -0
  150. package/src/custom/phone-input.tsx +172 -0
  151. package/src/custom/schema-form/custom/index.tsx +1 -0
  152. package/src/custom/schema-form/custom/label.tsx +53 -0
  153. package/src/custom/schema-form/fields/base-input-field.tsx +82 -0
  154. package/src/custom/schema-form/fields/field.tsx +67 -0
  155. package/src/custom/schema-form/fields/index.tsx +5 -0
  156. package/src/custom/schema-form/fields/object.tsx +12 -0
  157. package/src/custom/schema-form/fields/table-array/array-field-item.tsx +90 -0
  158. package/src/custom/schema-form/fields/table-array/array-field-template.tsx +115 -0
  159. package/src/custom/schema-form/index.tsx +259 -0
  160. package/src/custom/schema-form/templates/description.tsx +20 -0
  161. package/src/custom/schema-form/templates/index.tsx +2 -0
  162. package/src/custom/schema-form/templates/submit.tsx +32 -0
  163. package/src/custom/schema-form/types.ts +64 -0
  164. package/src/custom/schema-form/utils/index.ts +4 -0
  165. package/src/custom/schema-form/utils/schema-dependency.ts +655 -0
  166. package/src/custom/schema-form/utils/schemas.ts +289 -0
  167. package/src/custom/schema-form/utils/validation.ts +23 -0
  168. package/src/custom/schema-form/widgets/boolean.tsx +77 -0
  169. package/src/custom/schema-form/widgets/combobox.tsx +274 -0
  170. package/src/custom/schema-form/widgets/date.tsx +59 -0
  171. package/src/custom/schema-form/widgets/email.tsx +34 -0
  172. package/src/custom/schema-form/widgets/index.tsx +10 -0
  173. package/src/custom/schema-form/widgets/password.tsx +40 -0
  174. package/src/custom/schema-form/widgets/phone.tsx +40 -0
  175. package/src/custom/schema-form/widgets/select.tsx +105 -0
  176. package/src/custom/schema-form/widgets/selectable.tsx +25 -0
  177. package/src/custom/schema-form/widgets/string-array.tsx +296 -0
  178. package/src/custom/schema-form/widgets/url.tsx +56 -0
  179. package/src/custom/section-layout-v2.tsx +212 -0
  180. package/src/custom/select-tabs.tsx +109 -0
  181. package/src/custom/selectable.tsx +316 -0
  182. package/src/custom/stepper.tsx +236 -0
  183. package/src/custom/tab-layout.tsx +213 -0
  184. package/src/custom/tanstack-table/fields/index.tsx +12 -0
  185. package/src/custom/tanstack-table/fields/tanstack-table-action-dialogs.tsx +89 -0
  186. package/src/custom/tanstack-table/fields/tanstack-table-column-header.tsx +66 -0
  187. package/src/custom/tanstack-table/fields/tanstack-table-filter-date.tsx +180 -0
  188. package/src/custom/tanstack-table/fields/tanstack-table-filter-faceted.tsx +158 -0
  189. package/src/custom/tanstack-table/fields/tanstack-table-filter-text.tsx +76 -0
  190. package/src/custom/tanstack-table/fields/tanstack-table-pagination.tsx +136 -0
  191. package/src/custom/tanstack-table/fields/tanstack-table-plain-table.tsx +142 -0
  192. package/src/custom/tanstack-table/fields/tanstack-table-row-actions-confirmation.tsx +77 -0
  193. package/src/custom/tanstack-table/fields/tanstack-table-row-actions-custom-dialog.tsx +87 -0
  194. package/src/custom/tanstack-table/fields/tanstack-table-row-actions.tsx +151 -0
  195. package/src/custom/tanstack-table/fields/tanstack-table-table-actions-custom-dialog.tsx +88 -0
  196. package/src/custom/tanstack-table/fields/tanstack-table-table-actions-schemaform-dialog.tsx +47 -0
  197. package/src/custom/tanstack-table/fields/tanstack-table-toolbar.tsx +143 -0
  198. package/src/custom/tanstack-table/fields/tanstack-table-view-options.tsx +171 -0
  199. package/src/custom/tanstack-table/index.tsx +244 -0
  200. package/src/custom/tanstack-table/types/index.ts +328 -0
  201. package/src/custom/tanstack-table/utils/cell-with-actions.tsx +21 -0
  202. package/src/custom/tanstack-table/utils/column-names.ts +26 -0
  203. package/src/custom/tanstack-table/utils/columns-by-row-data.tsx +312 -0
  204. package/src/custom/tanstack-table/utils/editable-columns-by-row-data.tsx +219 -0
  205. package/src/custom/tanstack-table/utils/faceted-boolean-options.tsx +22 -0
  206. package/src/custom/tanstack-table/utils/index.tsx +10 -0
  207. package/src/custom/tanstack-table/utils/pinning-styles.ts +57 -0
  208. package/src/custom/tanstack-table/utils/table.tsx +83 -0
  209. package/src/custom/tanstack-table/utils/test-conditions.ts +17 -0
  210. package/src/custom/timeline.tsx +208 -0
  211. package/src/custom/tree.tsx +200 -0
  212. package/src/custom/tscanify/browser.ts +66 -0
  213. package/src/custom/tscanify/index.ts +51 -0
  214. package/src/custom/tscanify/tscanify-browser.ts +522 -0
  215. package/src/custom/tscanify/tscanify.ts +262 -0
  216. package/src/custom/tscanify/types.ts +22 -0
  217. package/src/custom/webcam.tsx +737 -0
  218. package/src/hooks/.gitkeep +0 -0
  219. package/src/hooks/use-callback-ref.ts +27 -0
  220. package/src/hooks/use-controllable-state.ts +67 -0
  221. package/src/hooks/use-debounce.ts +19 -0
  222. package/src/hooks/use-is-visible.ts +23 -0
  223. package/src/hooks/use-media-query.ts +21 -0
  224. package/src/hooks/use-mobile.ts +21 -0
  225. package/src/hooks/use-on-window-resize.ts +15 -0
  226. package/src/hooks/use-scroll.tsx +22 -0
  227. package/src/lib/utils.ts +61 -0
  228. package/src/lib/zod.ts +2 -0
  229. package/src/styles/core.css +57 -0
  230. package/src/styles/globals.css +130 -0
  231. package/src/test/email-input.test.tsx +217 -0
  232. package/src/test/password-input.test.tsx +92 -0
  233. package/src/test/select-tabs.test.tsx +302 -0
  234. package/src/test/selectable.test.tsx +1093 -0
  235. package/tsconfig.json +13 -0
  236. package/tsconfig.lint.json +8 -0
@@ -0,0 +1,171 @@
1
+ "use client";
2
+
3
+ import { DropdownMenuTrigger } from "@radix-ui/react-dropdown-menu";
4
+ import { Table } from "@tanstack/react-table";
5
+
6
+ import { ChevronDownIcon } from "lucide-react";
7
+ import { Button } from "@repo/ayasofyazilim-ui/components/button";
8
+ import {
9
+ DropdownMenu,
10
+ DropdownMenuContent,
11
+ DropdownMenuItem,
12
+ } from "@repo/ayasofyazilim-ui/components/dropdown-menu";
13
+ import {
14
+ TanstackTableSelectedRowActionType,
15
+ TanstackTableTableActionsType,
16
+ } from "../types";
17
+
18
+ interface TanstackTableViewOptionsProps<TData> {
19
+ editable?: boolean;
20
+ selectedRowAction?: TanstackTableSelectedRowActionType<TData>;
21
+ setTableAction: (actions: TanstackTableTableActionsType<TData>) => void;
22
+ table: Table<TData>;
23
+ tableActions?: TanstackTableTableActionsType<TData>[];
24
+ tableData: TData[];
25
+ }
26
+
27
+ function TablePrimaryActionButton<TData>({
28
+ table,
29
+ action,
30
+ setRowAction,
31
+ }: {
32
+ action: TanstackTableTableActionsType<TData>;
33
+ setRowAction: (actions: TanstackTableTableActionsType<TData>) => void;
34
+ table: Table<TData>;
35
+ }) {
36
+ return (
37
+ <Button
38
+ variant="outline"
39
+ size="sm"
40
+ type="button"
41
+ onClick={() => handleActionOnClick(table, action, setRowAction)}
42
+ >
43
+ {action?.icon && <action.icon className="mr-2 h-4 w-4" />}
44
+ {action.cta?.toString()}
45
+ </Button>
46
+ );
47
+ }
48
+ function handleActionOnClick<TData>(
49
+ table: Table<TData>,
50
+ action: TanstackTableTableActionsType<TData>,
51
+ setRowAction: (actions: TanstackTableTableActionsType<TData>) => void
52
+ ) {
53
+ if (action.type === "simple") {
54
+ action.onClick();
55
+ return;
56
+ }
57
+ if (action.type === "create-row") {
58
+ table.options.meta?.addRow(-1, "", null);
59
+ action?.onClick?.();
60
+ return;
61
+ }
62
+ setRowAction(action);
63
+ }
64
+
65
+ export function TanstackTableViewOptions<TData>(
66
+ props: TanstackTableViewOptionsProps<TData>
67
+ ) {
68
+ const {
69
+ table,
70
+ tableActions,
71
+ selectedRowAction,
72
+ setTableAction: setRowAction,
73
+ tableData,
74
+ editable,
75
+ } = props;
76
+
77
+ // Filter actions based on condition, keeping backward compatibility
78
+ const filteredActions =
79
+ tableActions?.filter(
80
+ (action) => !action.condition || action.condition(tableData)
81
+ ) ?? [];
82
+
83
+ const primaryAction = filteredActions[0];
84
+ const secondaryAction = filteredActions[1];
85
+ const otherActions = filteredActions.slice(2);
86
+ const selectedRowCount = Object.keys(table.getState().rowSelection).length;
87
+
88
+ return (
89
+ <>
90
+ {selectedRowAction && selectedRowCount > 0 && (
91
+ <div
92
+ className={
93
+ primaryAction &&
94
+ ((primaryAction.condition &&
95
+ primaryAction.condition?.(tableData)) ||
96
+ true) &&
97
+ otherActions &&
98
+ "mr-2"
99
+ }
100
+ >
101
+ <Button
102
+ variant="outline"
103
+ size="sm"
104
+ type="button"
105
+ className="ml-2"
106
+ onClick={() => {
107
+ const selectedRowIds = table.getState().rowSelection;
108
+ selectedRowAction.onClick(Object.keys(selectedRowIds), tableData);
109
+ }}
110
+ >
111
+ {selectedRowAction?.icon && (
112
+ <selectedRowAction.icon className="mr-2 h-4 w-4" />
113
+ )}
114
+ {`${selectedRowAction.cta?.toString()} (${selectedRowCount})`}
115
+ </Button>
116
+ </div>
117
+ )}
118
+
119
+ {editable && null}
120
+
121
+ <div className="space-x-2">
122
+ {primaryAction && (
123
+ <TablePrimaryActionButton
124
+ table={table}
125
+ action={primaryAction}
126
+ setRowAction={setRowAction}
127
+ />
128
+ )}
129
+ {secondaryAction && (
130
+ <TablePrimaryActionButton
131
+ table={table}
132
+ action={secondaryAction}
133
+ setRowAction={setRowAction}
134
+ />
135
+ )}
136
+ {otherActions && otherActions.length > 0 && (
137
+ <DropdownMenu>
138
+ <DropdownMenuTrigger asChild>
139
+ <Button
140
+ size="sm"
141
+ type="button"
142
+ variant="outline"
143
+ className="px-2"
144
+ >
145
+ <ChevronDownIcon className="size-4" />
146
+ </Button>
147
+ </DropdownMenuTrigger>
148
+ <DropdownMenuContent align="end" className="w-40">
149
+ {otherActions?.map((action) => (
150
+ <DropdownMenuItem key={action.cta}>
151
+ <Button
152
+ variant="ghost"
153
+ type="button"
154
+ size="sm"
155
+ className="justify-start w-full"
156
+ onClick={() =>
157
+ handleActionOnClick(table, action, setRowAction)
158
+ }
159
+ >
160
+ {action.icon && <action.icon className="w-4 h-4" />}
161
+ <span className="ml-2">{action.cta}</span>
162
+ </Button>
163
+ </DropdownMenuItem>
164
+ ))}
165
+ </DropdownMenuContent>
166
+ </DropdownMenu>
167
+ )}
168
+ </div>
169
+ </>
170
+ );
171
+ }
@@ -0,0 +1,244 @@
1
+ "use client";
2
+ "use no memo";
3
+ import {
4
+ getCoreRowModel,
5
+ getExpandedRowModel,
6
+ getPaginationRowModel,
7
+ getSortedRowModel,
8
+ RowData,
9
+ SortingState,
10
+ useReactTable,
11
+ VisibilityState,
12
+ } from "@tanstack/react-table";
13
+ import { useCallback, useMemo, useState } from "react";
14
+
15
+ import {
16
+ TanstackTableActionDialogs,
17
+ TanstackTablePagination,
18
+ TanstackTablePlainTable,
19
+ TanstackTableToolbar,
20
+ } from "./fields";
21
+
22
+ import {
23
+ TanstackBaseProps,
24
+ TanstackTablePropsType,
25
+ TanstackTableRowActionsType,
26
+ TanstackTableTableActionsType,
27
+ } from "./types";
28
+ import {
29
+ CellWithActions,
30
+ EditableTanstackTable,
31
+ NonEditableTanstackTable,
32
+ } from "./utils";
33
+
34
+ declare module "@tanstack/react-table" {
35
+ // eslint-disaxxble-next-line @typescript-eslint/no-unused-vars
36
+ interface TableMeta<TData extends RowData> {
37
+ addRow: (rowIndex: number, columnId: string, value: unknown) => void;
38
+ removeRow: (rowIndex: number, columnId: string, value: unknown) => void;
39
+ updateData: (rowIndex: number, columnId: string, value: unknown) => void;
40
+ duplicateRow: (rowIndex: number, value: TData) => void;
41
+ orderRow: (newIndex: number, oldIndex: number) => void;
42
+ }
43
+ }
44
+
45
+ export default function TanstackTable<TData, TValue>({
46
+ data,
47
+ rowCount,
48
+ columns,
49
+ columnOrder,
50
+ columnVisibility,
51
+ pinColumns,
52
+ rowActions,
53
+ tableActions,
54
+ selectedRowAction,
55
+ expandedRowComponent,
56
+ fillerColumn,
57
+ editable,
58
+ excludeColumns,
59
+ onTableDataChange,
60
+ filters,
61
+ title,
62
+ resizeable = true,
63
+ showPagination = true,
64
+ }: TanstackTablePropsType<TData, TValue>) {
65
+ const commonProps = {
66
+ pinColumns,
67
+ columnOrder,
68
+ columnVisibility,
69
+ rowActions,
70
+ tableActions,
71
+ selectedRowAction,
72
+ excludeColumns,
73
+ expandedRowComponent,
74
+ title,
75
+ resizeable,
76
+ };
77
+ if (editable) {
78
+ return (
79
+ <TanstackBase<TData, TValue>
80
+ {...commonProps}
81
+ {...EditableTanstackTable({ initialData: data, onTableDataChange })}
82
+ columns={columns}
83
+ editable
84
+ fillerColumn={fillerColumn}
85
+ />
86
+ );
87
+ }
88
+ return (
89
+ <TanstackBase<TData, TValue>
90
+ {...commonProps}
91
+ {...NonEditableTanstackTable(data, rowCount || 0)}
92
+ columns={columns}
93
+ editable={false}
94
+ filters={filters}
95
+ fillerColumn={fillerColumn}
96
+ showPagination={showPagination}
97
+ />
98
+ );
99
+ }
100
+
101
+ function TanstackBase<TData, TValue>(props: TanstackBaseProps<TData, TValue>) {
102
+ const {
103
+ data,
104
+ columns,
105
+ columnOrder,
106
+ rowCount,
107
+ columnVisibility,
108
+ pinColumns,
109
+ rowActions,
110
+ tableActions,
111
+ selectedRowAction,
112
+ expandedRowComponent,
113
+ fillerColumn,
114
+ editable,
115
+ excludeColumns,
116
+ onPaginationChange,
117
+ onColumnFiltersChange,
118
+ columnFilters,
119
+ pagination,
120
+ filters,
121
+ meta,
122
+ showPagination,
123
+ title,
124
+ resizeable,
125
+ } = props;
126
+ const [sorting, setSorting] = useState<SortingState>([]);
127
+ const [colVisibility, setColumnVisibility] = useState<VisibilityState>(
128
+ columnVisibility
129
+ ? Object.fromEntries(
130
+ columns.map((col) => [
131
+ col.id || "",
132
+
133
+ columnVisibility?.columns.includes(
134
+ (col.id || "") as keyof TData
135
+ ) ===
136
+ (columnVisibility.type === "show"),
137
+ ])
138
+ )
139
+ : {}
140
+ );
141
+ const [rowAction, setRowAction] = useState<
142
+ (TanstackTableRowActionsType<TData> & { row: TData }) | null
143
+ >(null);
144
+ const [tableAction, setTableAction] =
145
+ useState<TanstackTableTableActionsType<TData> | null>(null);
146
+
147
+ const tableColumns = useMemo(() => {
148
+ const _columns = [...columns].filter(
149
+ (col) => !excludeColumns?.includes(col.id as keyof TData)
150
+ );
151
+
152
+ if (rowActions) {
153
+ _columns.push({
154
+ id: "actions",
155
+ cell: ({ row }) =>
156
+ CellWithActions(table, row, rowActions, setRowAction),
157
+ });
158
+ }
159
+ if (!resizeable) return _columns;
160
+ return _columns.map((col) => ({
161
+ ...col,
162
+ minSize: fillerColumn === col.id ? 600 : undefined,
163
+ }));
164
+ }, [columns, rowActions]);
165
+
166
+ const getRowId = useCallback(
167
+ (row: TData, index: number) =>
168
+ editable ? index.toString() : (row as TData & { id: string }).id,
169
+ []
170
+ );
171
+
172
+ const table = useReactTable({
173
+ data,
174
+ columns: tableColumns,
175
+ getRowId,
176
+ columnResizeMode: "onChange",
177
+ columnResizeDirection: "ltr",
178
+ state: {
179
+ sorting,
180
+ columnVisibility: colVisibility,
181
+ columnFilters,
182
+ pagination,
183
+ },
184
+ initialState: {
185
+ columnOrder: columnOrder as string[],
186
+ columnPinning: {
187
+ left: [
188
+ "expanded-content",
189
+ "select",
190
+ ...((pinColumns as string[]) ?? []),
191
+ ],
192
+ right: ["actions"],
193
+ },
194
+ },
195
+ enableRowSelection: true,
196
+ enableColumnResizing: true,
197
+ enableColumnPinning: true,
198
+ manualPagination: true,
199
+ getRowCanExpand: () => !!expandedRowComponent,
200
+ getCoreRowModel: getCoreRowModel(),
201
+ onSortingChange: setSorting,
202
+ getSortedRowModel: getSortedRowModel(),
203
+ onColumnVisibilityChange: setColumnVisibility,
204
+ getPaginationRowModel: getPaginationRowModel(),
205
+ getExpandedRowModel: getExpandedRowModel(),
206
+ onPaginationChange,
207
+ onColumnFiltersChange,
208
+ rowCount,
209
+ meta,
210
+ });
211
+ return (
212
+ <div className="flex flex-col gap-2 overflow-hidden">
213
+ <TanstackTableToolbar<TData>
214
+ title={title}
215
+ table={table}
216
+ filters={filters}
217
+ selectedRowAction={selectedRowAction}
218
+ tableActions={tableActions}
219
+ tableData={data}
220
+ setTableAction={setTableAction}
221
+ editable={editable}
222
+ />
223
+ <div className="rounded-md border overflow-auto flex-1 h-0 max-h-max">
224
+ <TanstackTablePlainTable
225
+ resizeable={resizeable}
226
+ table={table}
227
+ columns={tableColumns}
228
+ editable={editable}
229
+ expandedRowComponent={expandedRowComponent}
230
+ fillerColumn={fillerColumn}
231
+ />
232
+ </div>
233
+ {pagination && showPagination && (
234
+ <TanstackTablePagination table={table} pagination={pagination} />
235
+ )}
236
+ <TanstackTableActionDialogs
237
+ tableAction={tableAction}
238
+ setTableAction={setTableAction}
239
+ rowAction={rowAction}
240
+ setRowAction={setRowAction}
241
+ />
242
+ </div>
243
+ );
244
+ }