pf-common-components 1.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 (215) hide show
  1. package/components.json +17 -0
  2. package/dist/assets/Arrow.d.ts +7 -0
  3. package/dist/assets/Arrow.js +5 -0
  4. package/dist/assets/CalenderIcon.d.ts +2 -0
  5. package/dist/assets/CalenderIcon.js +5 -0
  6. package/dist/assets/ClearAll.d.ts +2 -0
  7. package/dist/assets/ClearAll.js +5 -0
  8. package/dist/assets/CrossIcon.d.ts +8 -0
  9. package/dist/assets/CrossIcon.js +7 -0
  10. package/dist/assets/DropDown.d.ts +4 -0
  11. package/dist/assets/DropDown.js +5 -0
  12. package/dist/global.css +3213 -0
  13. package/dist/index.d.ts +25 -0
  14. package/dist/index.js +25 -0
  15. package/dist/lib/CommonComponentsUtil.d.ts +7 -0
  16. package/dist/lib/CommonComponentsUtil.js +22 -0
  17. package/dist/lib/utils.d.ts +2 -0
  18. package/dist/lib/utils.js +5 -0
  19. package/dist/ui/BaseTable.d.ts +132 -0
  20. package/dist/ui/BaseTable.js +330 -0
  21. package/dist/ui/DateCalendar.d.ts +10 -0
  22. package/dist/ui/DateCalendar.js +47 -0
  23. package/dist/ui/DateField.d.ts +35 -0
  24. package/dist/ui/DateField.js +37 -0
  25. package/dist/ui/DateOfBirthSelector.d.ts +16 -0
  26. package/dist/ui/DateOfBirthSelector.js +42 -0
  27. package/dist/ui/DateRangePicker.d.ts +8 -0
  28. package/dist/ui/DateRangePicker.js +73 -0
  29. package/dist/ui/DobCalendar.d.ts +17 -0
  30. package/dist/ui/DobCalendar.js +86 -0
  31. package/dist/ui/Formfield.d.ts +12 -0
  32. package/dist/ui/Formfield.js +36 -0
  33. package/dist/ui/GetScrollAlert.d.ts +9 -0
  34. package/dist/ui/GetScrollAlert.js +37 -0
  35. package/dist/ui/RadioGroupContext/RadioGroupContext.d.ts +8 -0
  36. package/dist/ui/RadioGroupContext/RadioGroupContext.js +11 -0
  37. package/dist/ui/SelectCommand.d.ts +69 -0
  38. package/dist/ui/SelectCommand.js +260 -0
  39. package/dist/ui/SlashIcon.d.ts +2 -0
  40. package/dist/ui/SlashIcon.js +5 -0
  41. package/dist/ui/SortingArrows.d.ts +11 -0
  42. package/dist/ui/SortingArrows.js +11 -0
  43. package/dist/ui/TextTags.d.ts +39 -0
  44. package/dist/ui/TextTags.js +73 -0
  45. package/dist/ui/accordion.d.ts +10 -0
  46. package/dist/ui/accordion.js +77 -0
  47. package/dist/ui/alert-dialog.d.ts +20 -0
  48. package/dist/ui/alert-dialog.js +62 -0
  49. package/dist/ui/alert.d.ts +8 -0
  50. package/dist/ui/alert.js +42 -0
  51. package/dist/ui/avatar.d.ts +6 -0
  52. package/dist/ui/avatar.js +32 -0
  53. package/dist/ui/badge.d.ts +10 -0
  54. package/dist/ui/badge.js +58 -0
  55. package/dist/ui/button.d.ts +12 -0
  56. package/dist/ui/button.js +54 -0
  57. package/dist/ui/calendar.d.ts +8 -0
  58. package/dist/ui/calendar.js +45 -0
  59. package/dist/ui/card.d.ts +8 -0
  60. package/dist/ui/card.js +45 -0
  61. package/dist/ui/checkbox.d.ts +12 -0
  62. package/dist/ui/checkbox.js +44 -0
  63. package/dist/ui/command.d.ts +47 -0
  64. package/dist/ui/command.js +67 -0
  65. package/dist/ui/dialog.d.ts +31 -0
  66. package/dist/ui/dialog.js +57 -0
  67. package/dist/ui/dropdown-menu.d.ts +27 -0
  68. package/dist/ui/dropdown-menu.js +72 -0
  69. package/dist/ui/form.d.ts +23 -0
  70. package/dist/ui/form.js +72 -0
  71. package/dist/ui/hover-card.d.ts +7 -0
  72. package/dist/ui/hover-card.js +29 -0
  73. package/dist/ui/input.d.ts +3 -0
  74. package/dist/ui/input.js +20 -0
  75. package/dist/ui/label.d.ts +5 -0
  76. package/dist/ui/label.js +24 -0
  77. package/dist/ui/multi-select.d.ts +44 -0
  78. package/dist/ui/multi-select.js +191 -0
  79. package/dist/ui/navigation-menu.d.ts +11 -0
  80. package/dist/ui/navigation-menu.js +69 -0
  81. package/dist/ui/popover.d.ts +6 -0
  82. package/dist/ui/popover.js +24 -0
  83. package/dist/ui/radio-group.d.ts +7 -0
  84. package/dist/ui/radio-group.js +40 -0
  85. package/dist/ui/radioButtonCard.d.ts +9 -0
  86. package/dist/ui/radioButtonCard.js +23 -0
  87. package/dist/ui/scroll-area.d.ts +5 -0
  88. package/dist/ui/scroll-area.js +29 -0
  89. package/dist/ui/select.d.ts +57 -0
  90. package/dist/ui/select.js +148 -0
  91. package/dist/ui/separator.d.ts +4 -0
  92. package/dist/ui/separator.js +22 -0
  93. package/dist/ui/sheet.d.ts +25 -0
  94. package/dist/ui/sheet.js +65 -0
  95. package/dist/ui/switch.d.ts +10 -0
  96. package/dist/ui/switch.js +47 -0
  97. package/dist/ui/table.d.ts +10 -0
  98. package/dist/ui/table.js +55 -0
  99. package/dist/ui/tabs.d.ts +7 -0
  100. package/dist/ui/tabs.js +33 -0
  101. package/dist/ui/text.d.ts +11 -0
  102. package/dist/ui/text.js +45 -0
  103. package/dist/ui/textarea.d.ts +7 -0
  104. package/dist/ui/textarea.js +21 -0
  105. package/dist/ui/tooltip.d.ts +11 -0
  106. package/dist/ui/tooltip.js +26 -0
  107. package/package.json +123 -0
  108. package/postcss.config.js +6 -0
  109. package/src/assets/Arrow.js +5 -0
  110. package/src/assets/Arrow.tsx +25 -0
  111. package/src/assets/CalenderIcon.js +5 -0
  112. package/src/assets/CalenderIcon.tsx +28 -0
  113. package/src/assets/ClearAll.js +5 -0
  114. package/src/assets/ClearAll.tsx +20 -0
  115. package/src/assets/CrossIcon.js +7 -0
  116. package/src/assets/CrossIcon.tsx +34 -0
  117. package/src/assets/DropDown.js +5 -0
  118. package/src/assets/DropDown.tsx +23 -0
  119. package/src/global.css +560 -0
  120. package/src/index.ts +34 -0
  121. package/src/lib/CommonComponentsUtil.js +22 -0
  122. package/src/lib/CommonComponentsUtil.ts +30 -0
  123. package/src/lib/utils.js +5 -0
  124. package/src/lib/utils.ts +6 -0
  125. package/src/ui/BaseTable.js +330 -0
  126. package/src/ui/BaseTable.tsx +987 -0
  127. package/src/ui/DateCalendar.js +47 -0
  128. package/src/ui/DateCalendar.tsx +111 -0
  129. package/src/ui/DateField.js +37 -0
  130. package/src/ui/DateField.tsx +142 -0
  131. package/src/ui/DateOfBirthSelector.js +42 -0
  132. package/src/ui/DateOfBirthSelector.tsx +114 -0
  133. package/src/ui/DateRangePicker.js +73 -0
  134. package/src/ui/DateRangePicker.tsx +174 -0
  135. package/src/ui/DobCalendar.js +86 -0
  136. package/src/ui/DobCalendar.tsx +172 -0
  137. package/src/ui/Formfield.js +36 -0
  138. package/src/ui/Formfield.tsx +55 -0
  139. package/src/ui/GetScrollAlert.js +37 -0
  140. package/src/ui/GetScrollAlert.tsx +59 -0
  141. package/src/ui/RadioGroupContext/RadioGroupContext.js +11 -0
  142. package/src/ui/RadioGroupContext/RadioGroupContext.tsx +21 -0
  143. package/src/ui/SelectCommand.js +260 -0
  144. package/src/ui/SelectCommand.tsx +587 -0
  145. package/src/ui/SlashIcon.js +5 -0
  146. package/src/ui/SlashIcon.tsx +22 -0
  147. package/src/ui/SortingArrows.js +11 -0
  148. package/src/ui/SortingArrows.tsx +29 -0
  149. package/src/ui/TextTags.js +73 -0
  150. package/src/ui/TextTags.tsx +149 -0
  151. package/src/ui/accordion.js +77 -0
  152. package/src/ui/accordion.tsx +129 -0
  153. package/src/ui/alert-dialog.js +62 -0
  154. package/src/ui/alert-dialog.tsx +141 -0
  155. package/src/ui/alert.js +42 -0
  156. package/src/ui/alert.tsx +59 -0
  157. package/src/ui/avatar.js +32 -0
  158. package/src/ui/avatar.tsx +50 -0
  159. package/src/ui/badge.js +58 -0
  160. package/src/ui/badge.tsx +66 -0
  161. package/src/ui/button.js +54 -0
  162. package/src/ui/button.tsx +89 -0
  163. package/src/ui/calendar.js +45 -0
  164. package/src/ui/calendar.tsx +88 -0
  165. package/src/ui/card.js +45 -0
  166. package/src/ui/card.tsx +83 -0
  167. package/src/ui/checkbox.js +44 -0
  168. package/src/ui/checkbox.tsx +56 -0
  169. package/src/ui/command.js +67 -0
  170. package/src/ui/command.tsx +166 -0
  171. package/src/ui/dialog.js +57 -0
  172. package/src/ui/dialog.tsx +154 -0
  173. package/src/ui/dropdown-menu.js +72 -0
  174. package/src/ui/dropdown-menu.tsx +200 -0
  175. package/src/ui/form.js +72 -0
  176. package/src/ui/form.tsx +177 -0
  177. package/src/ui/hover-card.js +29 -0
  178. package/src/ui/hover-card.tsx +63 -0
  179. package/src/ui/input.js +20 -0
  180. package/src/ui/input.tsx +22 -0
  181. package/src/ui/label.js +24 -0
  182. package/src/ui/label.tsx +26 -0
  183. package/src/ui/multi-select.js +191 -0
  184. package/src/ui/multi-select.tsx +518 -0
  185. package/src/ui/navigation-menu.js +69 -0
  186. package/src/ui/navigation-menu.tsx +139 -0
  187. package/src/ui/popover.js +24 -0
  188. package/src/ui/popover.tsx +31 -0
  189. package/src/ui/radio-group.js +40 -0
  190. package/src/ui/radio-group.tsx +97 -0
  191. package/src/ui/radioButtonCard.js +23 -0
  192. package/src/ui/radioButtonCard.tsx +57 -0
  193. package/src/ui/scroll-area.js +29 -0
  194. package/src/ui/scroll-area.tsx +48 -0
  195. package/src/ui/select.js +148 -0
  196. package/src/ui/select.tsx +343 -0
  197. package/src/ui/separator.js +22 -0
  198. package/src/ui/separator.tsx +31 -0
  199. package/src/ui/sheet.js +65 -0
  200. package/src/ui/sheet.tsx +136 -0
  201. package/src/ui/switch.js +47 -0
  202. package/src/ui/switch.tsx +60 -0
  203. package/src/ui/table.js +55 -0
  204. package/src/ui/table.tsx +112 -0
  205. package/src/ui/tabs.js +33 -0
  206. package/src/ui/tabs.tsx +55 -0
  207. package/src/ui/text.js +45 -0
  208. package/src/ui/text.tsx +49 -0
  209. package/src/ui/textarea.js +21 -0
  210. package/src/ui/textarea.tsx +28 -0
  211. package/src/ui/tooltip.js +26 -0
  212. package/src/ui/tooltip.tsx +54 -0
  213. package/tailwind.config.js +214 -0
  214. package/tsconfig.json +35 -0
  215. package/tsconfig.tsbuildinfo +1 -0
@@ -0,0 +1,330 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ import { flexRender, getCoreRowModel, useReactTable, } from "@tanstack/react-table";
4
+ import { Text } from '../ui/text';
5
+ import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "../ui/table";
6
+ import ClearAll from "../../public/assets/ClearAll";
7
+ import { ChevronLeft, ChevronRight } from "lucide-react";
8
+ import React, { useEffect, useRef, useState } from "react";
9
+ import { Button } from "../ui/button";
10
+ import { Checkbox } from "../ui/checkbox";
11
+ import { DropdownMenu, DropdownMenuContent, DropdownMenuTrigger, } from "../ui/dropdown-menu";
12
+ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "../ui/select";
13
+ import DropDown from "../../public/assets/DropDown";
14
+ import { useTranslation } from "next-i18next";
15
+ import { debounce } from "lodash";
16
+ export function BaseTable({ columns, data, tableStyles, current, setCurrent = () => { }, pageCount, total = 0, setPageSize = () => { }, pageSize = 0, pagination = false, checkboxSelection, columnPinning = false, defaultColumns = [], rowSelection, setRowSelection, columnSelector, sorting, setSorting, noRecordsPlaceholder = "No results", isFiltering = false, noScroll, actionComponent, userColumnPreferences, tableContainerId = "base-table-container", handleUserColumnPreferences, tableId = "", }) {
17
+ var _a, _b, _c, _d, _e, _f, _g;
18
+ // Initial visibility state for column selector
19
+ const initialColumnVisibilityChanges = columns.reduce((acc, { accessorKey, enableHiding }) => {
20
+ if (accessorKey) {
21
+ // Determine initial visibility for the current column
22
+ acc[accessorKey] =
23
+ // If the defaultColumns array is empty or includes the current column's accessorKey, set visibility to true
24
+ defaultColumns.length === 0 || defaultColumns.includes(accessorKey)
25
+ ? true
26
+ : // If enableHiding is true for the current column, set visibility to false, otherwise set it to true
27
+ enableHiding
28
+ ? false
29
+ : true;
30
+ }
31
+ return acc;
32
+ }, {});
33
+ const [columnVisibility, setColumnVisibility] = React.useState(userColumnPreferences
34
+ ? userColumnPreferences
35
+ : initialColumnVisibilityChanges);
36
+ //Local state for column selector to apply chnages when we click on apply button
37
+ const [columnVisibilityChanges, setColumnVisibilityChanges] = useState(userColumnPreferences
38
+ ? userColumnPreferences
39
+ : initialColumnVisibilityChanges);
40
+ // whenever userColumnPreferences get changed we need to update the values of those columns
41
+ useEffect(() => {
42
+ if (userColumnPreferences) {
43
+ setColumnVisibility(userColumnPreferences);
44
+ setColumnVisibilityChanges(userColumnPreferences);
45
+ }
46
+ }, [userColumnPreferences]);
47
+ //initial state for select all checkbox
48
+ const initialSelectAll = Object.keys(columnVisibilityChanges).length > 0 &&
49
+ Object.values(columnVisibilityChanges).every(Boolean);
50
+ const [selectAll, setSelectAll] = useState(initialSelectAll);
51
+ /**
52
+ * @function getRowId
53
+ * @description this function return id if the row have the id else it will return the index as id
54
+ * @param originalRow
55
+ * @param index
56
+ * @returns index in string format
57
+ */
58
+ const getRowId = (originalRow, index) => {
59
+ if (checkboxSelection) {
60
+ return originalRow.id.toString();
61
+ }
62
+ else {
63
+ return index.toString();
64
+ }
65
+ };
66
+ // table hook
67
+ const table = useReactTable({
68
+ data,
69
+ columns: columns,
70
+ enableSortingRemoval: true,
71
+ sortDescFirst: false,
72
+ getCoreRowModel: getCoreRowModel(),
73
+ // getPaginationRowModel: getPaginationRowModel(),
74
+ manualPagination: true,
75
+ onColumnVisibilityChange: setColumnVisibility,
76
+ onRowSelectionChange: setRowSelection,
77
+ getRowId,
78
+ manualSorting: true,
79
+ state: {
80
+ columnVisibility,
81
+ rowSelection,
82
+ sorting,
83
+ },
84
+ onSortingChange: setSorting,
85
+ });
86
+ /**
87
+ * Function to handle the select all checkbox changes
88
+ */
89
+ const handleSelectAllChange = (checked) => {
90
+ setSelectAll(checked);
91
+ const newColumnVisibilityChanges = {};
92
+ //Logic for not uncheck the columns which cannot be hidden they should be always true
93
+ Object.keys(columnVisibilityChanges).forEach((columnId) => {
94
+ const column = columns === null || columns === void 0 ? void 0 : columns.find((column) => column.accessorKey === columnId);
95
+ const canHide = column === null || column === void 0 ? void 0 : column.enableHiding;
96
+ newColumnVisibilityChanges[columnId] = canHide === false ? true : checked;
97
+ });
98
+ setColumnVisibilityChanges(newColumnVisibilityChanges);
99
+ };
100
+ /**
101
+ * function to handle the columns in column selector
102
+ */
103
+ const handleColumnVisibilityChange = (columnId, isVisible) => {
104
+ setColumnVisibilityChanges((prevState) => (Object.assign(Object.assign({}, prevState), { [columnId]: isVisible })));
105
+ // when i uncheck the individual check box we need to see if all checkboxes or checked or not and we have to update the select all
106
+ const allChecked = Object.values(Object.assign(Object.assign({}, columnVisibilityChanges), { [columnId]: isVisible })).every(Boolean);
107
+ setSelectAll(allChecked);
108
+ };
109
+ /**
110
+ * function to handle the columns in column selector
111
+ */
112
+ const applyColumnVisibilityChanges = () => {
113
+ table.setColumnVisibility(columnVisibilityChanges);
114
+ handleUserColumnPreferences === null || handleUserColumnPreferences === void 0 ? void 0 : handleUserColumnPreferences(columnVisibilityChanges);
115
+ setOpen(false);
116
+ requestAnimationFrame(() => {
117
+ handleScroll(); // Recalculate scroll position after layout change
118
+ });
119
+ };
120
+ /**
121
+ * functions to clear the columns in column selector
122
+ */
123
+ const clearColumnVisibilityChanges = () => {
124
+ const finalColumnVisibilityChanges = columns.reduce((acc, column) => {
125
+ //When clearing we need to make sure that columns which are not been hidden need to be true always
126
+ if (column.accessorKey) {
127
+ if (column.enableHiding == false) {
128
+ acc[column.accessorKey] = true;
129
+ }
130
+ else {
131
+ acc[column.accessorKey] = false;
132
+ }
133
+ }
134
+ return acc;
135
+ }, {});
136
+ setColumnVisibilityChanges(finalColumnVisibilityChanges);
137
+ setColumnVisibility(finalColumnVisibilityChanges);
138
+ handleUserColumnPreferences === null || handleUserColumnPreferences === void 0 ? void 0 : handleUserColumnPreferences(finalColumnVisibilityChanges);
139
+ setSelectAll(false);
140
+ requestAnimationFrame(() => {
141
+ handleScroll(); // Recalculate scroll position after layout change
142
+ });
143
+ };
144
+ const [scrollLeft, setScrollLeft] = useState(0);
145
+ const tableRef = useRef(null);
146
+ /**
147
+ * function to move the scroll bar to left using controls in action
148
+ */
149
+ const handlePrevButtonClick = () => {
150
+ if (tableRef.current) {
151
+ tableRef.current.scrollLeft -= 250;
152
+ setScrollLeft(tableRef.current.scrollLeft);
153
+ }
154
+ };
155
+ /**
156
+ * function to move the scroll bar to right using controls in action
157
+ */
158
+ const handleNextButtonClick = () => {
159
+ if (tableRef.current) {
160
+ tableRef.current.scrollLeft += 250;
161
+ setScrollLeft(tableRef.current.scrollWidth - tableRef.current.clientWidth);
162
+ }
163
+ };
164
+ //state variable to control the opening and closing of the column selector
165
+ const [open, setOpen] = useState(false);
166
+ const { t } = useTranslation(["common", "course.find_course", "bx_v1"]);
167
+ /**
168
+ * This function will set the drop down to open or close
169
+ * ColumnVisibilityChange is the columns selected in the dropdown
170
+ * While triggering the dropdown we are updated the ColumnVisibilityChange with ColumnVisibility
171
+ * Where ColumnVisibility is the columns selected after the changes are applied
172
+ */
173
+ const handleColumnDropdownChange = () => {
174
+ setOpen(!open);
175
+ setColumnVisibilityChanges(Object.assign({}, columnVisibility));
176
+ //If all checkboxes are checked or not and Based on that we have to update the select all
177
+ const allChecked = Object.values(Object.assign({}, columnVisibility)).every(Boolean);
178
+ setSelectAll(allChecked);
179
+ };
180
+ /**
181
+ *This component manages the scroll state of a scrollable element (referred to as `tableRef`).
182
+ * It tracks whether the element is scrolled to the start (leftmost position) or the end (rightmost position).
183
+ * The `isAtStart` state is true when the scroll position is at the left edge of the element,
184
+ * and the `isAtEnd` state is true when the scroll position is at or beyond the right edge of the element.
185
+ */
186
+ const [isAtStart, setIsAtStart] = useState(true);
187
+ const [isAtEnd, setIsAtEnd] = useState(false);
188
+ const handleScroll = () => {
189
+ if (tableRef.current) {
190
+ const { scrollLeft, clientWidth, scrollWidth } = tableRef.current;
191
+ const roundedScrollLeft = Math.round(scrollLeft);
192
+ const roundedClientWidth = Math.round(clientWidth);
193
+ const roundedScrollWidth = Math.round(scrollWidth);
194
+ // Add tolerance for floating-point inaccuracies
195
+ const tolerance = 1;
196
+ setIsAtStart(roundedScrollLeft <= tolerance);
197
+ setIsAtEnd(roundedScrollLeft + roundedClientWidth >= roundedScrollWidth - tolerance);
198
+ }
199
+ };
200
+ const handleResize = debounce(() => {
201
+ handleScroll();
202
+ }, 100);
203
+ useEffect(() => {
204
+ const tableElement = tableRef.current;
205
+ if (tableElement) {
206
+ tableElement.addEventListener("scroll", handleScroll, { passive: true });
207
+ window.addEventListener("resize", handleResize);
208
+ handleScroll(); // Initial scroll state check
209
+ }
210
+ if (isFiltering && tableRef.current) {
211
+ tableRef.current.scrollLeft = 0;
212
+ }
213
+ return () => {
214
+ if (tableElement) {
215
+ tableElement.removeEventListener("scroll", handleScroll);
216
+ }
217
+ window.removeEventListener("resize", handleResize);
218
+ };
219
+ }, [tableRef.current, isFiltering]);
220
+ return (_jsxs("div", Object.assign({ className: "flex flex-col gap-4" }, { children: [_jsxs("div", Object.assign({ className: "flex max-h-[50px] flex-row items-center justify-between" }, { children: [_jsxs("div", Object.assign({ className: "flex flex-row items-center gap-4" }, { children: [columnSelector && (_jsx("div", { children: _jsxs(DropdownMenu, Object.assign({ open: open, onOpenChange: handleColumnDropdownChange }, { children: [_jsx(DropdownMenuTrigger, Object.assign({ asChild: true }, { children: _jsxs(Button, Object.assign({ onClick: () => setOpen(true), variant: "outline", className: "flex h-10 w-[192px] flex-row justify-between rounded-xl hover:border hover:border-solid hover:border-primary", id: "base-table-column-selector-button" }, { children: [t("course.find_course:columns"), _jsx(DropDown, {})] })) })), _jsx(DropdownMenuContent, Object.assign({ className: "w-[192px] rounded-xl pl-3 pt-2.5", align: "start" }, { children: _jsxs("div", { children: [_jsxs("div", Object.assign({ className: "scrollbar column-selector-responsive-container flex flex-col gap-4 overflow-y-auto text-grey" }, { children: [_jsxs("div", Object.assign({ className: "flex flex-row items-center gap-4" }, { children: [_jsx(Checkbox, { checked: selectAll, onCheckedChange: handleSelectAllChange, id: "base-table-column-selector-select-all-checkbox" }), _jsx(Text, Object.assign({ className: "text-sm font-bold" }, { children: t("course.find_course:select_all") }))] })), table
221
+ .getAllColumns()
222
+ .filter((column) => column === null || column === void 0 ? void 0 : column.accessorFn)
223
+ // Here we are filtering the columns which have accessorKey
224
+ .map((column, index) => {
225
+ var _a, _b;
226
+ if (!column.getCanHide()) {
227
+ //display the disabled options
228
+ return (_jsxs("div", Object.assign({ className: "flex flex-row items-center gap-4" }, { children: [_jsx(Checkbox, { disabled: !column.getCanHide(),
229
+ //Disabling the checkbox if the column cannot be hidden
230
+ checked: columnVisibilityChanges[column.id], onCheckedChange: (value) => {
231
+ handleColumnVisibilityChange(column.id, value);
232
+ }, id: `column-${(_a = column === null || column === void 0 ? void 0 : column.columnDef) === null || _a === void 0 ? void 0 : _a.column_name}` }, column.id), (_b = column === null || column === void 0 ? void 0 : column.columnDef) === null || _b === void 0 ? void 0 : _b.column_name] }), index));
233
+ }
234
+ }), table
235
+ .getAllColumns()
236
+ .filter((column) => (column === null || column === void 0 ? void 0 : column.accessorFn) && column.getCanHide())
237
+ // Here we are filtering the columns which have accessorKey
238
+ .map((column) => {
239
+ var _a;
240
+ // display the enabled options
241
+ return (_jsxs("div", Object.assign({ className: "flex flex-row items-center gap-4" }, { children: [_jsx(Checkbox, { checked: columnVisibilityChanges[column.id], onCheckedChange: (value) => {
242
+ handleColumnVisibilityChange(column.id, value);
243
+ } }, column.id), (_a = column === null || column === void 0 ? void 0 : column.columnDef) === null || _a === void 0 ? void 0 : _a.column_name] })));
244
+ })] })), _jsxs("div", Object.assign({ className: "thin-scrollbar relative flex w-full flex-row items-center gap-4 overflow-auto pb-2.5 pt-2" }, { children: [_jsx("div", Object.assign({ onClick: clearColumnVisibilityChanges, className: "cursor-pointer rounded-xl border border-primary p-2 hover:border-solid" }, { children: _jsx(ClearAll, {}) })), _jsx(Button, Object.assign({ size: "sm", variant: "primary", onClick: applyColumnVisibilityChanges, id: "base-table-column-selector-apply-button" }, { children: t("apply_button") }))] }))] }) }))] })) })), actionComponent && actionComponent] })), _jsx("div", { children: !isFiltering && pagination && total > pageSize && (_jsx(DataPagination, { setCurrent: setCurrent, current: current, pageCount: pageCount, total: total })) })] })), _jsxs("div", { children: [_jsx("div", Object.assign({ className: "h-full overflow-hidden rounded-xl border" }, { children: _jsx("div", Object.assign({ ref: tableRef, className: `w-full ${tableStyles === null || tableStyles === void 0 ? void 0 : tableStyles.tableContainer} scrollbar ${isFiltering
245
+ ? "overflow-x-hidden"
246
+ : "overflow-x-auto overflow-y-hidden"} relative overflow-x-auto overflow-y-hidden` }, { children: _jsxs(Table, Object.assign({ id: tableId, className: `${tableStyles === null || tableStyles === void 0 ? void 0 : tableStyles.table}` }, { children: [_jsx(TableHeader, Object.assign({ className: `w-full bg-primary-light ${tableStyles === null || tableStyles === void 0 ? void 0 : tableStyles.tableHeader}` }, { children: table &&
247
+ ((_a = table === null || table === void 0 ? void 0 : table.getHeaderGroups()) === null || _a === void 0 ? void 0 : _a.map((headerGroup) => {
248
+ var _a;
249
+ return (_jsxs(TableRow, Object.assign({ className: "w-full border-none text-base font-bold" }, { children: [checkboxSelection && (_jsx(TableHead, Object.assign({ className: `${columnPinning && "sticky left-0 bg-primary-light"}` }, { children: _jsx(Checkbox, { checked: table.getIsAllPageRowsSelected(), onCheckedChange: (value) => {
250
+ table.toggleAllPageRowsSelected(value);
251
+ }, "aria-label": "Select all", id: "base-table-select-all-checkbox" }) }))), (_a = headerGroup === null || headerGroup === void 0 ? void 0 : headerGroup.headers) === null || _a === void 0 ? void 0 : _a.map((header, index) => {
252
+ var _a, _b;
253
+ return (_jsxs(TableHead
254
+ //If we have column pinning true then we have to make the first and last column sticky
255
+ , Object.assign({
256
+ //If we have column pinning true then we have to make the first and last column sticky
257
+ className: `${columnPinning &&
258
+ index === 0 &&
259
+ `sticky ${checkboxSelection ? "left-12" : "left-0"} bg-primary-light drop-shadow-right`} ${!noScroll &&
260
+ columnPinning &&
261
+ index === headerGroup.headers.length - 1 &&
262
+ `sticky right-0 w-[50px] bg-primary-light drop-shadow-left`} ${(tableStyles === null || tableStyles === void 0 ? void 0 : tableStyles.tableHeaderCell) ? tableStyles === null || tableStyles === void 0 ? void 0 : tableStyles.tableHeaderCell : ""} text-grey` }, { children: [(header === null || header === void 0 ? void 0 : header.isPlaceholder)
263
+ ? null
264
+ : flexRender((_b = (_a = header === null || header === void 0 ? void 0 : header.column) === null || _a === void 0 ? void 0 : _a.columnDef) === null || _b === void 0 ? void 0 : _b.header, header === null || header === void 0 ? void 0 : header.getContext()), !noScroll &&
265
+ index === headerGroup.headers.length - 1 &&
266
+ columnPinning && (_jsxs("div", Object.assign({ className: "flex flex-row gap-2" }, { children: [_jsx(ChevronLeft, { onClick: handlePrevButtonClick, className: `mr-1 size-6 cursor-pointer rounded-full ${isAtStart
267
+ ? "bg-white text-primary"
268
+ : "bg-primary text-white"}` }), _jsx(ChevronRight, { onClick: handleNextButtonClick, className: `size-6 cursor-pointer rounded-full ${isAtEnd
269
+ ? "bg-white text-primary"
270
+ : "bg-primary text-white"}`, id: "base-table-columns-right-button" })] })))] }), header === null || header === void 0 ? void 0 : header.id));
271
+ })] }), headerGroup === null || headerGroup === void 0 ? void 0 : headerGroup.id));
272
+ })) })), _jsx(TableBody, { children: isFiltering ? (_jsx(TableRow, { children: _jsx(TableCell, Object.assign({ colSpan: columns === null || columns === void 0 ? void 0 : columns.length, className: "h-24 text-center" }, { children: _jsx("div", Object.assign({ className: "flex w-screen items-center justify-center" }, { children: _jsx("div", { className: "loader" }) })) })) })) : table && ((_c = (_b = table === null || table === void 0 ? void 0 : table.getRowModel()) === null || _b === void 0 ? void 0 : _b.rows) === null || _c === void 0 ? void 0 : _c.length) ? (_jsxs(_Fragment, { children: [(_e = (_d = table === null || table === void 0 ? void 0 : table.getRowModel()) === null || _d === void 0 ? void 0 : _d.rows) === null || _e === void 0 ? void 0 : _e.map((row) => (_jsxs(TableRow, Object.assign({ className: `{${tableStyles === null || tableStyles === void 0 ? void 0 : tableStyles.rowStyles}` }, { children: [checkboxSelection && (_jsx(TableCell, Object.assign({ className: `${columnPinning && "sticky left-0 bg-white"}` }, { children: _jsx(Checkbox, { checked: row === null || row === void 0 ? void 0 : row.getIsSelected(), onCheckedChange: (value) => row === null || row === void 0 ? void 0 : row.toggleSelected(!!value), "aria-label": "Select row" }) }))), row === null || row === void 0 ? void 0 : row.getVisibleCells().map((cell, index) => {
273
+ var _a, _b;
274
+ return (
275
+ //If we have column pinning true then we have to make the first and last column sticky
276
+ _jsx(TableCell, Object.assign({ className: ` ${columnPinning &&
277
+ index === 0 &&
278
+ `sticky ${checkboxSelection ? "left-12" : "left-0"} top-0 bg-white drop-shadow-right`} ${!noScroll &&
279
+ columnPinning &&
280
+ index === row.getVisibleCells().length - 1 &&
281
+ `sticky right-0 top-0 w-[50px] bg-white drop-shadow-left`} ${(tableStyles === null || tableStyles === void 0 ? void 0 : tableStyles.tableBodyCell) ? tableStyles === null || tableStyles === void 0 ? void 0 : tableStyles.tableBodyCell : ""} text-grey` }, { children: flexRender((_b = (_a = cell === null || cell === void 0 ? void 0 : cell.column) === null || _a === void 0 ? void 0 : _a.columnDef) === null || _b === void 0 ? void 0 : _b.cell, cell === null || cell === void 0 ? void 0 : cell.getContext()) }), cell.id));
282
+ })] }), row === null || row === void 0 ? void 0 : row.id))), ((_f = table === null || table === void 0 ? void 0 : table.getFooterGroups()) === null || _f === void 0 ? void 0 : _f.some((group) => group.headers.some((header) => header.column.columnDef.footer))) &&
283
+ ((_g = table === null || table === void 0 ? void 0 : table.getFooterGroups()) === null || _g === void 0 ? void 0 : _g.map((row) => {
284
+ var _a;
285
+ return (_jsx(TableRow, Object.assign({ className: "bg-primary-light" }, { children: (_a = row === null || row === void 0 ? void 0 : row.headers) === null || _a === void 0 ? void 0 : _a.map((cell, index) => {
286
+ var _a, _b;
287
+ return (_jsx(TableCell, Object.assign({ className: `${columnPinning && index === 0
288
+ ? "sticky left-0 bg-primary-light drop-shadow-right"
289
+ : ""} ${!noScroll &&
290
+ columnPinning &&
291
+ index === row.headers.length - 1
292
+ ? "sticky right-0 bg-white drop-shadow-left"
293
+ : ""} ${(tableStyles === null || tableStyles === void 0 ? void 0 : tableStyles.tableBodyCell) ? tableStyles === null || tableStyles === void 0 ? void 0 : tableStyles.tableBodyCell : ""} text-grey` }, { children: flexRender((_b = (_a = cell === null || cell === void 0 ? void 0 : cell.column) === null || _a === void 0 ? void 0 : _a.columnDef) === null || _b === void 0 ? void 0 : _b.footer, cell === null || cell === void 0 ? void 0 : cell.getContext()) }), cell.id));
294
+ }) }), row.id));
295
+ }))] })) : (_jsx(TableRow, { children: _jsx(TableCell, Object.assign({ colSpan: columns === null || columns === void 0 ? void 0 : columns.length, className: "h-24 text-left" }, { children: noRecordsPlaceholder })) })) })] })) })) })), !isFiltering && pagination && (_jsxs("div", Object.assign({ className: "my-6 flex justify-center" }, { children: [_jsx("div", { className: "w-1/3" }), _jsx("div", Object.assign({ className: "flex w-1/3 items-center justify-center" }, { children: total > pageSize && (_jsx(DataPagination, { setCurrent: setCurrent, current: current, pageCount: pageCount, total: total, pageSize: pageSize })) })), total >= 10 && (_jsxs("div", Object.assign({ className: "flex w-1/3 items-center justify-end space-x-2", id: "base-table-pagination-dropdown" }, { children: [_jsxs(Select, Object.assign({ value: pageSize, onValueChange: (value) => {
296
+ setCurrent(1);
297
+ setPageSize(Number(value));
298
+ table === null || table === void 0 ? void 0 : table.setPageSize(Number(value));
299
+ } }, { children: [_jsxs(SelectTrigger, Object.assign({ className: "h-8 w-[131px]", id: "base-table-page-size" }, { children: [_jsx(Text, Object.assign({ className: "text-grey1" }, { children: t("course.find_course:showing") })), _jsx(SelectValue, {})] })), _jsx(SelectContent, Object.assign({ side: "top" }, { children: [10, 25, 50, 100].map((pageSize // Till now there is no limit will change after confirming TODO
300
+ ) => (_jsx(SelectItem, Object.assign({ value: `${pageSize}`, id: `base-table-${pageSize}` }, { children: pageSize }), pageSize))) }))] })), _jsxs(Text, Object.assign({ className: "text-sm font-normal" }, { children: [t("course.find_course:of"), " ", total] }))] })))] })))] })] })));
301
+ }
302
+ const DataPagination = ({ setCurrent = () => { }, total = 0, current = 1, pageCount = 1, pageSize = 0, }) => {
303
+ const PagesArray = [];
304
+ const DOTS = ". . .";
305
+ if (pageCount <= 4) {
306
+ // If there are 4 or fewer pages, show all pages without ellipses
307
+ for (let i = 1; i <= pageCount; i++) {
308
+ PagesArray.push(i);
309
+ }
310
+ }
311
+ else {
312
+ if (current <= 3) {
313
+ // If current page is 4 or less, show pages 1 to 4, then ellipses, then last page
314
+ PagesArray.push(1, 2, 3, 4, DOTS, pageCount);
315
+ }
316
+ else if (current >= pageCount - 2) {
317
+ // If current page is near the end, show first page, ellipses, and last 4 pages
318
+ PagesArray.push(1, DOTS, pageCount - 3, pageCount - 2, pageCount - 1, pageCount);
319
+ }
320
+ else {
321
+ // Otherwise,first page , ellipses, current page, ellipses, and last page
322
+ PagesArray.push(1, DOTS, current - 1, current, current + 1, DOTS, pageCount);
323
+ }
324
+ }
325
+ const { t } = useTranslation(["common", "bx_v1"]);
326
+ return (_jsxs("div", Object.assign({ className: "flex flex-row items-center space-x-2 self-center p-2 text-xs" }, { children: [pageCount > 1 && (_jsx(Button, Object.assign({ variant: "outline", className: `h-8 min-w-8 rounded-sm border-none p-0 text-xs !font-semibold ${current <= 1 ? "text-grey2-light-active" : " "}`, onClick: () => setCurrent(current - 1), disabled: current <= 1, id: "base-table-pagination-prev-button" }, { children: t("bx_v1:cm_prev") }))), total > pageSize &&
327
+ PagesArray.map((page, index) => (_jsx("div", { children: page === DOTS ? (_jsx("span", Object.assign({ className: "p-2 text-xs" }, { children: DOTS }))) : (_jsx(Button, Object.assign({ variant: page === current ? "primary" : "outline", onClick: () => {
328
+ setCurrent(page);
329
+ }, className: "size-8 rounded-lg p-3 text-xs", id: `base-table-pagination-page-${page}-button` }, { children: page }))) }, index))), pageCount > 1 && (_jsx(Button, Object.assign({ variant: "outline", className: `h-8 min-w-8 rounded-sm border-none p-0 text-xs !font-semibold ${current >= pageCount ? "text-grey2-light-active" : " "}`, onClick: () => setCurrent(current + 1), disabled: current >= pageCount, id: "base-table-pagination-next-button" }, { children: t("next") })))] })));
330
+ };