@pezeshk-book/modules 0.2.5 → 0.2.7

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 (278) hide show
  1. package/.eslintrc.json +133 -0
  2. package/calendar/calendar.props.ts +25 -0
  3. package/calendar/calendar.tsx +185 -0
  4. package/calendar/config/chunk.ts +42 -0
  5. package/calendar/config/create-date-range.ts +14 -0
  6. package/calendar/config/days-in-month.en.ts +47 -0
  7. package/calendar/config/days-in-month.fa.ts +37 -0
  8. package/calendar/config/index.ts +16 -0
  9. package/calendar/config/months.ts +29 -0
  10. package/calendar/config/week-day.ts +19 -0
  11. package/calendar/icons/arrow-left-icon.tsx +14 -0
  12. package/calendar/icons/arrow-right-icon.tsx +14 -0
  13. package/calendar/icons/index.ts +7 -0
  14. package/calendar/index.ts +3 -0
  15. package/calendar/shared/formatDate.tsx +12 -0
  16. package/calendar/sub-components/day/day.props.ts +27 -0
  17. package/calendar/sub-components/day/day.tsx +31 -0
  18. package/calendar/sub-components/days/days.props.ts +51 -0
  19. package/calendar/sub-components/days/days.tsx +142 -0
  20. package/calendar/sub-components/days-head/days-head.props.ts +27 -0
  21. package/calendar/sub-components/days-head/days-head.tsx +122 -0
  22. package/countdown-timer/countdown.props.ts +18 -0
  23. package/countdown-timer/countdown.tsx +79 -0
  24. package/countdown-timer/index.ts +3 -0
  25. package/data-table/data-table.props.ts +7 -0
  26. package/data-table/data-table.tsx +17 -0
  27. package/data-table/default/default-data-table.props.ts +47 -0
  28. package/data-table/default/default-data-table.tsx +427 -0
  29. package/data-table/default/index.ts +3 -0
  30. package/data-table/hooks/use-window-dimensions.tsx +33 -0
  31. package/data-table/icons/add.tsx +10 -0
  32. package/data-table/icons/arrow-down.tsx +11 -0
  33. package/data-table/icons/index.ts +9 -0
  34. package/data-table/icons/sort.tsx +16 -0
  35. package/data-table/index.ts +3 -0
  36. package/data-table/simple/index.ts +3 -0
  37. package/data-table/simple/simple-data-table.props.ts +23 -0
  38. package/data-table/simple/simple-data-table.tsx +258 -0
  39. package/dist/{modules/calendar → calendar}/calendar.js +1 -0
  40. package/dist/calendar/calendar.js.map +1 -0
  41. package/dist/calendar/calendar.props.js.map +1 -0
  42. package/dist/calendar/config/chunk.js.map +1 -0
  43. package/dist/calendar/config/create-date-range.js.map +1 -0
  44. package/dist/calendar/config/days-in-month.en.js.map +1 -0
  45. package/dist/calendar/config/days-in-month.fa.js.map +1 -0
  46. package/dist/calendar/config/index.js.map +1 -0
  47. package/dist/calendar/config/months.js.map +1 -0
  48. package/dist/calendar/config/week-day.js.map +1 -0
  49. package/dist/calendar/icons/arrow-left-icon.js.map +1 -0
  50. package/dist/calendar/icons/arrow-right-icon.js.map +1 -0
  51. package/dist/calendar/icons/index.js.map +1 -0
  52. package/dist/calendar/index.js.map +1 -0
  53. package/dist/calendar/shared/formatDate.js.map +1 -0
  54. package/dist/{modules/calendar → calendar}/sub-components/day/day.js +1 -1
  55. package/dist/calendar/sub-components/day/day.js.map +1 -0
  56. package/dist/calendar/sub-components/day/day.props.js.map +1 -0
  57. package/dist/calendar/sub-components/days/days.js.map +1 -0
  58. package/dist/calendar/sub-components/days/days.props.js.map +1 -0
  59. package/dist/{modules/calendar → calendar}/sub-components/days-head/days-head.js +2 -2
  60. package/dist/calendar/sub-components/days-head/days-head.js.map +1 -0
  61. package/dist/calendar/sub-components/days-head/days-head.props.js.map +1 -0
  62. package/dist/countdown-timer/countdown.js.map +1 -0
  63. package/dist/countdown-timer/countdown.props.js.map +1 -0
  64. package/dist/countdown-timer/index.js.map +1 -0
  65. package/dist/{modules/data-table → data-table}/data-table.js +1 -0
  66. package/dist/data-table/data-table.js.map +1 -0
  67. package/dist/data-table/data-table.props.js.map +1 -0
  68. package/dist/data-table/default/default-data-table.js.map +1 -0
  69. package/dist/data-table/default/default-data-table.props.js.map +1 -0
  70. package/dist/data-table/default/index.js.map +1 -0
  71. package/dist/data-table/hooks/use-window-dimensions.js.map +1 -0
  72. package/dist/data-table/icons/add.js.map +1 -0
  73. package/dist/data-table/icons/arrow-down.js.map +1 -0
  74. package/dist/data-table/icons/index.js.map +1 -0
  75. package/dist/data-table/icons/sort.js.map +1 -0
  76. package/dist/data-table/index.js.map +1 -0
  77. package/dist/data-table/simple/index.js.map +1 -0
  78. package/dist/data-table/simple/simple-data-table.js.map +1 -0
  79. package/dist/data-table/simple/simple-data-table.props.js.map +1 -0
  80. package/dist/index.d.ts +5 -5
  81. package/dist/index.js +5 -5
  82. package/dist/index.js.map +1 -1
  83. package/dist/pagination/icons/arrow-Right.js.map +1 -0
  84. package/dist/pagination/icons/arrow-left.js.map +1 -0
  85. package/dist/pagination/icons/index.js.map +1 -0
  86. package/dist/pagination/index.js.map +1 -0
  87. package/dist/{modules/pagination → pagination}/pagination.js +1 -0
  88. package/dist/pagination/pagination.js.map +1 -0
  89. package/dist/pagination/pagination.props.js.map +1 -0
  90. package/dist/pagination/use-pagination.js.map +1 -0
  91. package/dist/slider/index.js.map +1 -0
  92. package/dist/{modules/slider → slider}/slider.js +2 -1
  93. package/dist/slider/slider.js.map +1 -0
  94. package/dist/slider/slider.props.js.map +1 -0
  95. package/dist/stories/calendar/calendar.d.ts +1 -1
  96. package/dist/stories/calendar/calendar.js +1 -1
  97. package/dist/stories/calendar/calendar.js.map +1 -1
  98. package/dist/stories/count-down/count-down.d.ts +1 -1
  99. package/dist/stories/count-down/count-down.js +1 -1
  100. package/dist/stories/count-down/count-down.js.map +1 -1
  101. package/dist/stories/data-table/default-data-table.d.ts +1 -1
  102. package/dist/stories/data-table/default-data-table.js +1 -1
  103. package/dist/stories/data-table/default-data-table.js.map +1 -1
  104. package/dist/stories/data-table/simple-data-table.d.ts +1 -1
  105. package/dist/stories/data-table/simple-data-table.js +1 -1
  106. package/dist/stories/data-table/simple-data-table.js.map +1 -1
  107. package/dist/stories/pagination/pagination.d.ts +1 -1
  108. package/dist/stories/pagination/pagination.js +1 -1
  109. package/dist/stories/pagination/pagination.js.map +1 -1
  110. package/dist/stories/slider/slider.d.ts +1 -1
  111. package/dist/stories/slider/slider.js +1 -1
  112. package/dist/stories/slider/slider.js.map +1 -1
  113. package/index.ts +13 -0
  114. package/package.json +5 -10
  115. package/pagination/icons/arrow-Right.tsx +22 -0
  116. package/pagination/icons/arrow-left.tsx +22 -0
  117. package/pagination/icons/index.ts +7 -0
  118. package/pagination/index.ts +3 -0
  119. package/pagination/pagination.props.ts +33 -0
  120. package/pagination/pagination.tsx +135 -0
  121. package/pagination/use-pagination.ts +49 -0
  122. package/react-app-env.d.ts +1 -0
  123. package/slider/index.ts +3 -0
  124. package/slider/slider.props.ts +39 -0
  125. package/slider/slider.tsx +292 -0
  126. package/stories/calendar/calendar.stories.tsx +25 -0
  127. package/stories/calendar/calendar.tsx +11 -0
  128. package/stories/count-down/count-down.stories.tsx +19 -0
  129. package/stories/count-down/count-down.tsx +11 -0
  130. package/stories/data-table/data-table-columns.tsx +70 -0
  131. package/stories/data-table/default-data-table.stories.tsx +22 -0
  132. package/stories/data-table/default-data-table.tsx +18 -0
  133. package/stories/data-table/dummy-data.ts +204 -0
  134. package/stories/data-table/simple-data-table.stories.tsx +22 -0
  135. package/stories/data-table/simple-data-table.tsx +18 -0
  136. package/stories/pagination/pagination.stories.tsx +35 -0
  137. package/stories/pagination/pagination.tsx +11 -0
  138. package/stories/slider/slider.stories.tsx +19 -0
  139. package/stories/slider/slider.tsx +45 -0
  140. package/stories/wrapper.tsx +11 -0
  141. package/styles.css +28 -0
  142. package/utils/class-names.ts +5 -0
  143. package/utils/persian-to-english-number.ts +4 -0
  144. package/dist/modules/calendar/calendar.js.map +0 -1
  145. package/dist/modules/calendar/calendar.props.js.map +0 -1
  146. package/dist/modules/calendar/config/chunk.js.map +0 -1
  147. package/dist/modules/calendar/config/create-date-range.js.map +0 -1
  148. package/dist/modules/calendar/config/days-in-month.en.js.map +0 -1
  149. package/dist/modules/calendar/config/days-in-month.fa.js.map +0 -1
  150. package/dist/modules/calendar/config/index.js.map +0 -1
  151. package/dist/modules/calendar/config/months.js.map +0 -1
  152. package/dist/modules/calendar/config/week-day.js.map +0 -1
  153. package/dist/modules/calendar/icons/arrow-left-icon.js.map +0 -1
  154. package/dist/modules/calendar/icons/arrow-right-icon.js.map +0 -1
  155. package/dist/modules/calendar/icons/index.js.map +0 -1
  156. package/dist/modules/calendar/index.js.map +0 -1
  157. package/dist/modules/calendar/shared/formatDate.js.map +0 -1
  158. package/dist/modules/calendar/sub-components/day/day.js.map +0 -1
  159. package/dist/modules/calendar/sub-components/day/day.props.js.map +0 -1
  160. package/dist/modules/calendar/sub-components/days/days.js.map +0 -1
  161. package/dist/modules/calendar/sub-components/days/days.props.js.map +0 -1
  162. package/dist/modules/calendar/sub-components/days-head/days-head.js.map +0 -1
  163. package/dist/modules/calendar/sub-components/days-head/days-head.props.js.map +0 -1
  164. package/dist/modules/countdown-timer/countdown.js.map +0 -1
  165. package/dist/modules/countdown-timer/countdown.props.js.map +0 -1
  166. package/dist/modules/countdown-timer/index.js.map +0 -1
  167. package/dist/modules/data-table/data-table.js.map +0 -1
  168. package/dist/modules/data-table/data-table.props.js.map +0 -1
  169. package/dist/modules/data-table/default/default-data-table.js.map +0 -1
  170. package/dist/modules/data-table/default/default-data-table.props.js.map +0 -1
  171. package/dist/modules/data-table/default/index.js.map +0 -1
  172. package/dist/modules/data-table/hooks/use-window-dimensions.js.map +0 -1
  173. package/dist/modules/data-table/icons/add.js.map +0 -1
  174. package/dist/modules/data-table/icons/arrow-down.js.map +0 -1
  175. package/dist/modules/data-table/icons/index.js.map +0 -1
  176. package/dist/modules/data-table/icons/sort.js.map +0 -1
  177. package/dist/modules/data-table/index.js.map +0 -1
  178. package/dist/modules/data-table/simple/index.js.map +0 -1
  179. package/dist/modules/data-table/simple/simple-data-table.js.map +0 -1
  180. package/dist/modules/data-table/simple/simple-data-table.props.js.map +0 -1
  181. package/dist/modules/pagination/icons/arrow-Right.js.map +0 -1
  182. package/dist/modules/pagination/icons/arrow-left.js.map +0 -1
  183. package/dist/modules/pagination/icons/index.js.map +0 -1
  184. package/dist/modules/pagination/index.js.map +0 -1
  185. package/dist/modules/pagination/pagination.js.map +0 -1
  186. package/dist/modules/pagination/pagination.props.js.map +0 -1
  187. package/dist/modules/pagination/use-pagination.js.map +0 -1
  188. package/dist/modules/slider/index.js.map +0 -1
  189. package/dist/modules/slider/slider.js.map +0 -1
  190. package/dist/modules/slider/slider.props.js.map +0 -1
  191. /package/dist/{modules/calendar → calendar}/calendar.d.ts +0 -0
  192. /package/dist/{modules/calendar → calendar}/calendar.props.d.ts +0 -0
  193. /package/dist/{modules/calendar → calendar}/calendar.props.js +0 -0
  194. /package/dist/{modules/calendar → calendar}/config/chunk.d.ts +0 -0
  195. /package/dist/{modules/calendar → calendar}/config/chunk.js +0 -0
  196. /package/dist/{modules/calendar → calendar}/config/create-date-range.d.ts +0 -0
  197. /package/dist/{modules/calendar → calendar}/config/create-date-range.js +0 -0
  198. /package/dist/{modules/calendar → calendar}/config/days-in-month.en.d.ts +0 -0
  199. /package/dist/{modules/calendar → calendar}/config/days-in-month.en.js +0 -0
  200. /package/dist/{modules/calendar → calendar}/config/days-in-month.fa.d.ts +0 -0
  201. /package/dist/{modules/calendar → calendar}/config/days-in-month.fa.js +0 -0
  202. /package/dist/{modules/calendar → calendar}/config/index.d.ts +0 -0
  203. /package/dist/{modules/calendar → calendar}/config/index.js +0 -0
  204. /package/dist/{modules/calendar → calendar}/config/months.d.ts +0 -0
  205. /package/dist/{modules/calendar → calendar}/config/months.js +0 -0
  206. /package/dist/{modules/calendar → calendar}/config/week-day.d.ts +0 -0
  207. /package/dist/{modules/calendar → calendar}/config/week-day.js +0 -0
  208. /package/dist/{modules/calendar → calendar}/icons/arrow-left-icon.d.ts +0 -0
  209. /package/dist/{modules/calendar → calendar}/icons/arrow-left-icon.js +0 -0
  210. /package/dist/{modules/calendar → calendar}/icons/arrow-right-icon.d.ts +0 -0
  211. /package/dist/{modules/calendar → calendar}/icons/arrow-right-icon.js +0 -0
  212. /package/dist/{modules/calendar → calendar}/icons/index.d.ts +0 -0
  213. /package/dist/{modules/calendar → calendar}/icons/index.js +0 -0
  214. /package/dist/{modules/calendar → calendar}/index.d.ts +0 -0
  215. /package/dist/{modules/calendar → calendar}/index.js +0 -0
  216. /package/dist/{modules/calendar → calendar}/shared/formatDate.d.ts +0 -0
  217. /package/dist/{modules/calendar → calendar}/shared/formatDate.js +0 -0
  218. /package/dist/{modules/calendar → calendar}/sub-components/day/day.d.ts +0 -0
  219. /package/dist/{modules/calendar → calendar}/sub-components/day/day.props.d.ts +0 -0
  220. /package/dist/{modules/calendar → calendar}/sub-components/day/day.props.js +0 -0
  221. /package/dist/{modules/calendar → calendar}/sub-components/days/days.d.ts +0 -0
  222. /package/dist/{modules/calendar → calendar}/sub-components/days/days.js +0 -0
  223. /package/dist/{modules/calendar → calendar}/sub-components/days/days.props.d.ts +0 -0
  224. /package/dist/{modules/calendar → calendar}/sub-components/days/days.props.js +0 -0
  225. /package/dist/{modules/calendar → calendar}/sub-components/days-head/days-head.d.ts +0 -0
  226. /package/dist/{modules/calendar → calendar}/sub-components/days-head/days-head.props.d.ts +0 -0
  227. /package/dist/{modules/calendar → calendar}/sub-components/days-head/days-head.props.js +0 -0
  228. /package/dist/{modules/countdown-timer → countdown-timer}/countdown.d.ts +0 -0
  229. /package/dist/{modules/countdown-timer → countdown-timer}/countdown.js +0 -0
  230. /package/dist/{modules/countdown-timer → countdown-timer}/countdown.props.d.ts +0 -0
  231. /package/dist/{modules/countdown-timer → countdown-timer}/countdown.props.js +0 -0
  232. /package/dist/{modules/countdown-timer → countdown-timer}/index.d.ts +0 -0
  233. /package/dist/{modules/countdown-timer → countdown-timer}/index.js +0 -0
  234. /package/dist/{modules/data-table → data-table}/data-table.d.ts +0 -0
  235. /package/dist/{modules/data-table → data-table}/data-table.props.d.ts +0 -0
  236. /package/dist/{modules/data-table → data-table}/data-table.props.js +0 -0
  237. /package/dist/{modules/data-table → data-table}/default/default-data-table.d.ts +0 -0
  238. /package/dist/{modules/data-table → data-table}/default/default-data-table.js +0 -0
  239. /package/dist/{modules/data-table → data-table}/default/default-data-table.props.d.ts +0 -0
  240. /package/dist/{modules/data-table → data-table}/default/default-data-table.props.js +0 -0
  241. /package/dist/{modules/data-table → data-table}/default/index.d.ts +0 -0
  242. /package/dist/{modules/data-table → data-table}/default/index.js +0 -0
  243. /package/dist/{modules/data-table → data-table}/hooks/use-window-dimensions.d.ts +0 -0
  244. /package/dist/{modules/data-table → data-table}/hooks/use-window-dimensions.js +0 -0
  245. /package/dist/{modules/data-table → data-table}/icons/add.d.ts +0 -0
  246. /package/dist/{modules/data-table → data-table}/icons/add.js +0 -0
  247. /package/dist/{modules/data-table → data-table}/icons/arrow-down.d.ts +0 -0
  248. /package/dist/{modules/data-table → data-table}/icons/arrow-down.js +0 -0
  249. /package/dist/{modules/data-table → data-table}/icons/index.d.ts +0 -0
  250. /package/dist/{modules/data-table → data-table}/icons/index.js +0 -0
  251. /package/dist/{modules/data-table → data-table}/icons/sort.d.ts +0 -0
  252. /package/dist/{modules/data-table → data-table}/icons/sort.js +0 -0
  253. /package/dist/{modules/data-table → data-table}/index.d.ts +0 -0
  254. /package/dist/{modules/data-table → data-table}/index.js +0 -0
  255. /package/dist/{modules/data-table → data-table}/simple/index.d.ts +0 -0
  256. /package/dist/{modules/data-table → data-table}/simple/index.js +0 -0
  257. /package/dist/{modules/data-table → data-table}/simple/simple-data-table.d.ts +0 -0
  258. /package/dist/{modules/data-table → data-table}/simple/simple-data-table.js +0 -0
  259. /package/dist/{modules/data-table → data-table}/simple/simple-data-table.props.d.ts +0 -0
  260. /package/dist/{modules/data-table → data-table}/simple/simple-data-table.props.js +0 -0
  261. /package/dist/{modules/pagination → pagination}/icons/arrow-Right.d.ts +0 -0
  262. /package/dist/{modules/pagination → pagination}/icons/arrow-Right.js +0 -0
  263. /package/dist/{modules/pagination → pagination}/icons/arrow-left.d.ts +0 -0
  264. /package/dist/{modules/pagination → pagination}/icons/arrow-left.js +0 -0
  265. /package/dist/{modules/pagination → pagination}/icons/index.d.ts +0 -0
  266. /package/dist/{modules/pagination → pagination}/icons/index.js +0 -0
  267. /package/dist/{modules/pagination → pagination}/index.d.ts +0 -0
  268. /package/dist/{modules/pagination → pagination}/index.js +0 -0
  269. /package/dist/{modules/pagination → pagination}/pagination.d.ts +0 -0
  270. /package/dist/{modules/pagination → pagination}/pagination.props.d.ts +0 -0
  271. /package/dist/{modules/pagination → pagination}/pagination.props.js +0 -0
  272. /package/dist/{modules/pagination → pagination}/use-pagination.d.ts +0 -0
  273. /package/dist/{modules/pagination → pagination}/use-pagination.js +0 -0
  274. /package/dist/{modules/slider → slider}/index.d.ts +0 -0
  275. /package/dist/{modules/slider → slider}/index.js +0 -0
  276. /package/dist/{modules/slider → slider}/slider.d.ts +0 -0
  277. /package/dist/{modules/slider → slider}/slider.props.d.ts +0 -0
  278. /package/dist/{modules/slider → slider}/slider.props.js +0 -0
@@ -0,0 +1,427 @@
1
+ import { Fragment, useEffect, useState } from 'react';
2
+ import { Button, Checkbox, classNames, Div, FormControlLabel, LoadingIndicator, Skeleton, Text } from '@pezeshk-book/ui-kit';
3
+ import Pagination from '../../pagination';
4
+ import { DefaultDataTableProps } from './default-data-table.props';
5
+ import {
6
+ ColumnDef,
7
+ flexRender,
8
+ getCoreRowModel,
9
+ getExpandedRowModel,
10
+ getSortedRowModel,
11
+ RowData,
12
+ SortingState,
13
+ useReactTable,
14
+ } from '@tanstack/react-table';
15
+ import useWindowDimensions from '../hooks/use-window-dimensions';
16
+ import { ArrowDownIcon, AddIcon, SortIcon } from '../icons';
17
+ import { AnimatePresence, motion } from 'motion/react';
18
+
19
+ declare module '@tanstack/react-table' {
20
+ // eslint-disable-next-line no-unused-vars
21
+ interface TableMeta<TData extends RowData> {
22
+ updateData: (value: string, info?: string | object) => void
23
+ }
24
+ }
25
+
26
+ const fillArray = (n: number) => Array.from({ length: n + 1 }, (_, i) => i);
27
+
28
+ const DefaultDataTable = (
29
+ {
30
+ header,
31
+ data,
32
+ column,
33
+ mobileColumns,
34
+ expandable = false,
35
+ expandedComponent,
36
+ serverSideSorting,
37
+ isLoading = false,
38
+ getCurrentPage,
39
+ lastPage,
40
+ perPage,
41
+ currentPage,
42
+ total,
43
+ previousPage,
44
+ nextPage,
45
+ getLimit,
46
+ columnOrder = false,
47
+ updateData,
48
+ select,
49
+ selectedRows,
50
+ expandAll = false,
51
+ visitedRows = [],
52
+ }: DefaultDataTableProps) => {
53
+ const [rowSelection, setRowSelection] = useState({});
54
+ const [sorting, setSorting] = useState<SortingState>([]);
55
+ const [scrollPosition, setScrollPosition] = useState(0);
56
+ const [showGoTop, setShowGoTop] = useState(false);
57
+ const [columnVisibility, setColumnVisibility] = useState<any>({});
58
+ const [rowExpander, setRowExpander] = useState<Array<any>>([]);
59
+
60
+ const dimensions = useWindowDimensions();
61
+
62
+ const handleMobileExpander = (row: { index: number }) => {
63
+ if (rowExpander.indexOf(row.index) === -1) {
64
+ setRowExpander([...rowExpander, row.index]);
65
+ } else {
66
+ setRowExpander(value => value.filter(item => item !== row.index));
67
+ }
68
+ };
69
+ const columns: ColumnDef<any>[] = [
70
+ {
71
+ id: 'mobileExpander',
72
+ accessorKey: 'mobileExpander',
73
+ header: () => null,
74
+ cell: ({ row }) => {
75
+ return (
76
+ <Button
77
+ onClick={() => handleMobileExpander(row)}
78
+ startAdornment={
79
+ <AddIcon
80
+ className={classNames(
81
+ 'absolute transition-all duration-500',
82
+ rowExpander.indexOf(row.index) !== -1 ? 'rotate-[225deg]' : '',
83
+ )}
84
+ />
85
+ }
86
+ variant={'text'}
87
+ size={'tiny'}
88
+ className={'!p-0'}
89
+ />
90
+ );
91
+ },
92
+ enableSorting: false,
93
+ },
94
+ {
95
+ id: 'select',
96
+ accessorKey: 'select',
97
+ header: ({ table }) => {
98
+ return select ? (
99
+ <Checkbox
100
+ size={'small'}
101
+ indeterminate={table.getIsSomeRowsSelected()}
102
+ checked={table.getIsAllRowsSelected()}
103
+ onChange={table.getToggleAllRowsSelectedHandler()}
104
+ />
105
+ ) : null;
106
+ },
107
+ cell: ({ row }) => {
108
+ return row.getCanSelect() && select ? (
109
+ <Checkbox
110
+ size={'small'}
111
+ onChange={row.getToggleSelectedHandler()}
112
+ checked={row.getIsSelected()}
113
+ />
114
+ ) : null;
115
+ },
116
+ enableSorting: false,
117
+ },
118
+ ...column,
119
+ {
120
+ id: 'expander',
121
+ accessorKey: 'expander',
122
+ header: () => null,
123
+ cell: ({ row }) => {
124
+ return row.getCanExpand() ? (
125
+ <Button
126
+ className={'!p-0'}
127
+ variant={'text'}
128
+ size={'tiny'}
129
+ {...{
130
+ onClick: row.getToggleExpandedHandler(),
131
+ style: { cursor: 'pointer' },
132
+ }}
133
+ >
134
+ <ArrowDownIcon
135
+ className={classNames(
136
+ 'transition-all duration-300',
137
+ row.getIsExpanded() ? 'rotate-180' : '')}
138
+ />
139
+ </Button>
140
+ ) : null;
141
+ },
142
+ enableSorting: false,
143
+ },
144
+ ];
145
+ const table = useReactTable({
146
+ data,
147
+ columns,
148
+ getCoreRowModel: getCoreRowModel(),
149
+ getSortedRowModel: getSortedRowModel(),
150
+ getRowCanExpand: () => true,
151
+ getExpandedRowModel: getExpandedRowModel(),
152
+ state: {
153
+ columnVisibility,
154
+ rowSelection,
155
+ sorting,
156
+ },
157
+ onColumnVisibilityChange: setColumnVisibility,
158
+ onRowSelectionChange: setRowSelection,
159
+ onSortingChange: setSorting,
160
+ manualSorting: !!serverSideSorting,
161
+ meta: {
162
+ updateData: (value, info) => {
163
+ if (updateData) {
164
+ updateData(value, info);
165
+ }
166
+ },
167
+ },
168
+ });
169
+
170
+ useEffect(() => {
171
+ if (selectedRows) {
172
+ selectedRows(table.getSelectedRowModel().rows.map((row) => {
173
+ return row.original;
174
+ }));
175
+ }
176
+ }, [rowSelection]);
177
+
178
+ useEffect(() => {
179
+ window.addEventListener('scroll', handleVisibleButton);
180
+ });
181
+
182
+ useEffect(() => {
183
+ if (serverSideSorting && sorting.length > 0) {
184
+ serverSideSorting(sorting);
185
+ }
186
+ }, [sorting]);
187
+
188
+ useEffect(() => {
189
+ const obj: any = {};
190
+ if (dimensions.width < 640) {
191
+ columns.forEach((value) => {
192
+ if (value.id) {
193
+ obj[value.id] = mobileColumns?.includes(value.id);
194
+ }
195
+ });
196
+ setColumnVisibility({ ...obj, mobileExpander: true, expander: expandable, select: select });
197
+ } else {
198
+ columns.forEach((value) => {
199
+ if (value.id) {
200
+ obj[value.id] = true;
201
+ }
202
+ });
203
+ setColumnVisibility({ ...obj, mobileExpander: false, expander: expandable, select: select });
204
+ }
205
+ }, [dimensions.width]);
206
+
207
+ useEffect(() => {
208
+ if (expandAll && dimensions.width < 640) {
209
+ setRowExpander(fillArray(perPage));
210
+ }
211
+ if (expandAll && dimensions.width >= 640) {
212
+ setRowExpander([]);
213
+ }
214
+ }, [expandAll, perPage, currentPage, dimensions.width]);
215
+
216
+ const handleVisibleButton = () => {
217
+ const position = window.scrollY;
218
+ setScrollPosition(position);
219
+
220
+ if (scrollPosition > 150) {
221
+ return setShowGoTop(true);
222
+ } else if (scrollPosition < 150) {
223
+ return setShowGoTop(false);
224
+ }
225
+ };
226
+
227
+ const handleScrollUp = () => {
228
+ window.scrollTo({ behavior: 'smooth', top: 0 });
229
+ };
230
+
231
+ return (
232
+ <Div className={'w-full flex-col relative'}>
233
+ {isLoading && data.length > 0 ? (
234
+ <Div className={'absolute bg-control bg-opacity-25 w-full h-full items-center justify-center z-50 rounded-xl'}>
235
+ <LoadingIndicator size={'huge'} color={'control'}/>
236
+ </Div>
237
+ ) : null}
238
+ <Div className={'gap-0 md:gap-4 flex-col md:flex-row'}>
239
+ {columnOrder && table.getAllLeafColumns().map(column => {
240
+ if (column.id === 'mobileExpander' || column.id === 'expander') {
241
+ return null;
242
+ }
243
+ return (
244
+ <FormControlLabel key={column.id} className={'p-2'} label={header[column.id]}>
245
+ <Checkbox checked={column.getIsVisible()} onChange={column.getToggleVisibilityHandler()}/>
246
+ </FormControlLabel>
247
+ );
248
+ })}
249
+ </Div>
250
+ <Div className={'bg-white md:border w-full border-control-300 border-opacity-50 p-2 rounded-xl max-w-full flex-col relative'}>
251
+ <table className={'w-full table-auto'}>
252
+ <thead className={'bg-control-50 h-14 sticky top-0 z-[9]'}>
253
+ {table.getHeaderGroups().map(headerGroup => (
254
+ <tr key={headerGroup.id}>
255
+ {headerGroup.headers.map(header => (
256
+ <th
257
+ className={'hover:cursor-pointer'}
258
+ onClick={header.column.getToggleSortingHandler()}
259
+ key={header.id}>
260
+ <Div className={'justify-center items-center gap-1'}>
261
+ {header.column.getCanSort() ? (
262
+ <Div className={'text-control-800'}>
263
+ <SortIcon direction={header.column.getIsSorted() as string}/>
264
+ </Div>
265
+ ) : null}
266
+ <Text color={header.column.getIsSorted() ? 'primary' : 'grey.800'} typography={'sm'} type={'bold'}>
267
+ {header.isPlaceholder
268
+ ? null
269
+ : flexRender(
270
+ header.column.columnDef.header,
271
+ header.getContext(),
272
+ )}
273
+ </Text>
274
+ </Div>
275
+ </th>
276
+ ))}
277
+ </tr>
278
+ ))}
279
+ </thead>
280
+ {isLoading && !data.length ? (
281
+ <tbody>
282
+ {[...new Array(15)].map((_, index) => (
283
+ <tr key={`loadingItem_${index}`} className={'h-16'}>
284
+ {table.getFlatHeaders().map(cell => {
285
+ return (
286
+ <td className={'px-1'} key={cell.id}>
287
+ <Skeleton color={'control'} className={'!max-w-full !min-w-full'}/>
288
+ </td>
289
+ );
290
+ })}
291
+ </tr>
292
+ ))}
293
+ </tbody>
294
+ ) : !isLoading && !data.length ? (
295
+ <tbody>
296
+ <tr className={'h-48'}>
297
+ <td colSpan={table.getFlatHeaders().length}>
298
+ <Text typography={'lg'} type={'bold'}>اطلاعاتی برای نمایش وجود ندارد!</Text>
299
+ </td>
300
+ </tr>
301
+ </tbody>
302
+ ) : (
303
+ <tbody>
304
+ {table.getRowModel().rows.map((row, index) => {
305
+ return (
306
+ <Fragment key={row.id}>
307
+ {/* @ts-ignore */}
308
+ <AnimatePresence mode="wait">
309
+ <motion.tr
310
+ key={row ? row.id : 'empty'}
311
+ initial={{ y: 100, opacity: 0 }}
312
+ animate={{ y: 0, opacity: 1 }}
313
+ exit={{ y: -100, opacity: 0 }}
314
+ transition={{ duration: 0.5, delay: index * 0.01 }}
315
+ className={classNames('h-16 hover:bg-primary-50',
316
+ row.getIsSelected() && 'bg-slate-200',
317
+ visitedRows?.indexOf(row.index) !== -1 ? 'bg-slate-100' : '')}>
318
+ {row.getVisibleCells().map(cell => {
319
+ return (
320
+ <td className={'px-1'} key={cell.id}>
321
+ <Div className={'flex-col items-center'}>
322
+ {
323
+ flexRender(
324
+ cell.column.columnDef.cell,
325
+ cell.getContext(),
326
+ )
327
+ }
328
+ </Div>
329
+ </td>
330
+ );
331
+ })}
332
+ </motion.tr>
333
+ </AnimatePresence>
334
+ {/* @ts-ignore */}
335
+ <AnimatePresence>
336
+ {row.getIsExpanded() && (
337
+ <motion.tr
338
+ initial={{ height: 0, opacity: 0 }}
339
+ animate={{ height: 'auto', opacity: 1 }}
340
+ exit={{ height: 0, opacity: 0 }}
341
+ transition={{ duration: 0.5, ease: 'easeInOut' }}
342
+ >
343
+ <td colSpan={row.getVisibleCells().length}>
344
+ <motion.div
345
+ initial={{ height: 0, opacity: 0 }}
346
+ animate={{ height: row.getIsExpanded() ? 'auto' : 0, opacity: 1 }}
347
+ exit={{ height: 0, opacity: 0 }}
348
+ transition={{ duration: 0.5, ease: 'easeInOut' }}
349
+ className={'flex flex-col overflow-hidden'}>
350
+ {expandedComponent(row.original)}
351
+ </motion.div>
352
+ </td>
353
+ </motion.tr>
354
+ )}
355
+ </AnimatePresence>
356
+ {/* @ts-ignore */}
357
+ <AnimatePresence>
358
+ {rowExpander.indexOf(row.index) !== -1 && (
359
+ <motion.tr
360
+ initial={{ height: 0, opacity: 0 }}
361
+ animate={{ height: 'auto', opacity: 1 }}
362
+ exit={{ height: 0, opacity: 0 }}
363
+ transition={{ duration: 0.5, ease: 'easeInOut' }}
364
+ className={classNames('bg-primary-50')}>
365
+ <td colSpan={row.getVisibleCells().length}>
366
+ <motion.div
367
+ initial={{ height: 0, opacity: 0 }}
368
+ animate={{ height: row.getVisibleCells().length ? 'auto' : 0, opacity: 1 }}
369
+ exit={{ height: 0, opacity: 0 }}
370
+ transition={{ duration: 0.5, ease: 'easeInOut' }}
371
+ className={'flex flex-col overflow-hidden'}>
372
+ {row.getAllCells().map((mobileCell) => {
373
+ if (!mobileCell.column.getIsVisible() && mobileCell.column.id !== 'expander') {
374
+ return (
375
+ <Div
376
+ key={mobileCell.id}
377
+ className={'gap-2 p-2 items-start'}>
378
+ {/*@ts-ignore*/}
379
+ <Text typography={'sm'} type={'bold'}>{header[mobileCell.column.id]}:</Text>
380
+ {flexRender(
381
+ mobileCell.column.columnDef.cell,
382
+ mobileCell.getContext(),
383
+ )}
384
+ </Div>
385
+ );
386
+ }
387
+ return null;
388
+ })}
389
+ </motion.div>
390
+ </td>
391
+ </motion.tr>
392
+ )}
393
+ </AnimatePresence>
394
+ </Fragment>
395
+ );
396
+ })}
397
+ </tbody>
398
+ )}
399
+ </table>
400
+ <Button onClick={handleScrollUp} shape={'square'} rounded={'full'} className={classNames('rotate-180 sticky !p-0 bottom-1 self-center duration-500 transition',
401
+ showGoTop ? 'opacity-100 translate-y-0 !h-auto !min-h-12' : 'translate-y-full opacity-0 !h-0 !min-h-[0px]',
402
+ )}>
403
+ <ArrowDownIcon/>
404
+ </Button>
405
+ {!isLoading && data.length ? (
406
+ <Div className={'mt-4 bg-control-50 md:h-14 py-2 md:py-0 justify-center items-center rounded-b-xl flex-col'}>
407
+ <Pagination
408
+ color={'primary'}
409
+ variant={'filled'}
410
+ getCurrentPage={getCurrentPage}
411
+ isLoading={isLoading}
412
+ lastPage={lastPage}
413
+ perPage={perPage}
414
+ currentPage={currentPage}
415
+ total={total}
416
+ nextPage={nextPage}
417
+ previousPage={previousPage}
418
+ getLimit={getLimit}
419
+ />
420
+ </Div>
421
+ ) : null}
422
+ </Div>
423
+ </Div>
424
+ );
425
+ };
426
+ export default DefaultDataTable;
427
+
@@ -0,0 +1,3 @@
1
+ import DefaultDataTable from './default-data-table';
2
+
3
+ export default DefaultDataTable;
@@ -0,0 +1,33 @@
1
+ 'use clients';
2
+ import { useState, useEffect } from 'react';
3
+ import { useDebouncedCallback } from 'use-debounce';
4
+ const useWindowDimensions = () => {
5
+ const [windowDimensions, setWindowDimensions] = useState({
6
+ width: window.innerWidth,
7
+ height: window.innerHeight,
8
+ });
9
+
10
+ useEffect(() => {
11
+ setWindowDimensions({
12
+ width: window.innerWidth,
13
+ height: window.innerHeight,
14
+ });
15
+ }, []);
16
+
17
+ const handleResize = useDebouncedCallback(() => {
18
+ setWindowDimensions({
19
+ width: window.innerWidth,
20
+ height: window.innerHeight,
21
+ });
22
+ }, 500);
23
+
24
+ useEffect(() => {
25
+ window.addEventListener('resize', handleResize);
26
+
27
+ return () => window.removeEventListener('resize', handleResize);
28
+ }, []);
29
+
30
+ return windowDimensions;
31
+ };
32
+
33
+ export default useWindowDimensions;
@@ -0,0 +1,10 @@
1
+ const AddIcon = ({ className }: {className?: string}) => {
2
+ return (
3
+ <svg className={className} width='24' height='24' viewBox='0 0 24 24' fill='none' xmlns='http://www.w3.org/2000/svg'>
4
+ <path d='M8 12H16' stroke='currentColor' strokeWidth='1.5' strokeLinecap='round' strokeLinejoin='round' />
5
+ <path d='M12 16V8' stroke='currentColor' strokeWidth='1.5' strokeLinecap='round' strokeLinejoin='round' />
6
+ </svg>
7
+ );
8
+ };
9
+
10
+ export default AddIcon;
@@ -0,0 +1,11 @@
1
+ const ArrowDownIcon = ({ fill = 'none', className = 'h-6 w-6' }: any) => {
2
+ return (
3
+ <svg width="20" height="20" viewBox="0 0 20 20" fill={fill} className={className} xmlns="http://www.w3.org/2000/svg">
4
+ <path fillRule="evenodd" clipRule="evenodd"
5
+ d="M4.4107 6.91073C4.73614 6.5853 5.26378 6.5853 5.58922 6.91073L9.99996 11.3215L14.4107 6.91074C14.7361 6.5853 15.2638 6.5853 15.5892 6.91074C15.9147 7.23617 15.9147 7.76381 15.5892 8.08925L10.5892 13.0892C10.2638 13.4147 9.73614 13.4147 9.4107 13.0892L4.4107 8.08925C4.08527 7.76381 4.08527 7.23617 4.4107 6.91073Z"
6
+ fill="currentColor"/>
7
+ </svg>
8
+ );
9
+ };
10
+
11
+ export default ArrowDownIcon;
@@ -0,0 +1,9 @@
1
+ import AddIcon from './add';
2
+ import SortIcon from './sort';
3
+ import ArrowDownIcon from './arrow-down';
4
+
5
+ export {
6
+ AddIcon,
7
+ ArrowDownIcon,
8
+ SortIcon,
9
+ };
@@ -0,0 +1,16 @@
1
+ const SortIcon = ({ direction } : { direction: string }) => {
2
+ return (
3
+ <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
4
+ <g>
5
+ <g>
6
+ <path d="M9.00999 20.5L3.98999 15.49" stroke={direction === 'desc' ? 'currentColor' : '#A8A8A8'} strokeWidth="1.5" strokeMiterlimit="10" strokeLinecap="round" strokeLinejoin="round"/>
7
+ <path d="M9.01001 3.5V20.5" stroke={direction === 'desc' ? 'currentColor' : '#A8A8A8'} strokeWidth="1.5" strokeMiterlimit="10" strokeLinecap="round" strokeLinejoin="round"/>
8
+ <path d="M14.99 3.5L20.01 8.51" stroke={direction === 'asc' ? 'currentColor' : '#A8A8A8'} strokeWidth="1.5" strokeMiterlimit="10" strokeLinecap="round" strokeLinejoin="round"/>
9
+ <path d="M14.99 20.5V3.5" stroke={direction === 'asc' ? 'currentColor' : '#A8A8A8'} strokeWidth="1.5" strokeMiterlimit="10" strokeLinecap="round" strokeLinejoin="round"/>
10
+ </g>
11
+ </g>
12
+ </svg>
13
+ );
14
+ };
15
+
16
+ export default SortIcon;
@@ -0,0 +1,3 @@
1
+ import DataTable from './data-table';
2
+
3
+ export default DataTable;
@@ -0,0 +1,3 @@
1
+ import SimpleDataTable from './simple-data-table';
2
+
3
+ export default SimpleDataTable;
@@ -0,0 +1,23 @@
1
+ import { ColumnDef } from '@tanstack/react-table';
2
+
3
+ export interface SimpleDataTableProps {
4
+ data: Array<any>
5
+
6
+ header: any
7
+
8
+ column: Array<ColumnDef<any>>
9
+
10
+ mobileColumns?: Array<string>
11
+
12
+ isLoading?: boolean
13
+
14
+ updateData?: (value: string, info?: string | object) => void
15
+
16
+ select?: boolean
17
+
18
+ selectedRows?: (rows: Array<ColumnDef<any>>) => void
19
+
20
+ expandAll?: boolean
21
+
22
+ visitedRows?: Array<number>
23
+ }