@redacto.io/consent-sdk-react 3.5.0 → 3.6.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 (152) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/LICENSE +176 -0
  3. package/dist/index.d.mts +51 -4
  4. package/dist/index.d.ts +51 -4
  5. package/dist/index.js +1891 -243
  6. package/dist/index.mjs +1890 -243
  7. package/dist/privacy-center.d.mts +566 -0
  8. package/dist/privacy-center.d.ts +566 -0
  9. package/dist/privacy-center.js +17174 -0
  10. package/dist/privacy-center.mjs +17136 -0
  11. package/package.json +47 -3
  12. package/src/RedactoNoticeConsent/RedactoNoticeConsent.test.tsx +201 -118
  13. package/src/RedactoNoticeConsent/RedactoNoticeConsent.tsx +1194 -93
  14. package/src/RedactoNoticeConsent/api/index.ts +335 -206
  15. package/src/RedactoNoticeConsent/api/types.ts +140 -16
  16. package/src/RedactoNoticeConsent/components/DigiLockerCallback.tsx +602 -0
  17. package/src/RedactoNoticeConsent/components/index.ts +7 -0
  18. package/src/RedactoNoticeConsent/injectStyles.ts +11 -0
  19. package/src/RedactoNoticeConsent/language-codes.ts +61 -0
  20. package/src/RedactoNoticeConsent/services/storage.ts +122 -0
  21. package/src/RedactoNoticeConsent/types.ts +2 -0
  22. package/src/RedactoPrivacyCenter/PrivacyCenterActivityPage.tsx +19 -0
  23. package/src/RedactoPrivacyCenter/PrivacyCenterConsentManagerPage.tsx +17 -0
  24. package/src/RedactoPrivacyCenter/PrivacyCenterFormPage.tsx +79 -0
  25. package/src/RedactoPrivacyCenter/PrivacyCenterHomePage.tsx +27 -0
  26. package/src/RedactoPrivacyCenter/PrivacyCenterLayout.tsx +142 -0
  27. package/src/RedactoPrivacyCenter/RedactoPrivacyCenter.tsx +51 -0
  28. package/src/RedactoPrivacyCenter/api/actions.ts +444 -0
  29. package/src/RedactoPrivacyCenter/api/client.ts +413 -0
  30. package/src/RedactoPrivacyCenter/api/config.ts +33 -0
  31. package/src/RedactoPrivacyCenter/api/fetcher.ts +181 -0
  32. package/src/RedactoPrivacyCenter/api/upload.ts +93 -0
  33. package/src/RedactoPrivacyCenter/assets/character.svg +31 -0
  34. package/src/RedactoPrivacyCenter/assets/fileAttach.svg +9 -0
  35. package/src/RedactoPrivacyCenter/assets/greenTick.svg +4 -0
  36. package/src/RedactoPrivacyCenter/assets/mail.svg +3 -0
  37. package/src/RedactoPrivacyCenter/assets/poweredByRedacto.svg +9 -0
  38. package/src/RedactoPrivacyCenter/assets/sentImg.svg +9 -0
  39. package/src/RedactoPrivacyCenter/assets/uploadFileIcon.svg +9 -0
  40. package/src/RedactoPrivacyCenter/components/ActivitiesList.tsx +272 -0
  41. package/src/RedactoPrivacyCenter/components/CaseDetailsModal.tsx +468 -0
  42. package/src/RedactoPrivacyCenter/components/CaseHistory.tsx +433 -0
  43. package/src/RedactoPrivacyCenter/components/ConsentManager.tsx +726 -0
  44. package/src/RedactoPrivacyCenter/components/ConsentManagerColumns.tsx +239 -0
  45. package/src/RedactoPrivacyCenter/components/ConsentManagerConstants.ts +7 -0
  46. package/src/RedactoPrivacyCenter/components/ConsentManagerTableSkeleton.tsx +155 -0
  47. package/src/RedactoPrivacyCenter/components/DataRequest/CorrectionDataSection.tsx +189 -0
  48. package/src/RedactoPrivacyCenter/components/DataRequest/GrievanceDataSection.tsx +118 -0
  49. package/src/RedactoPrivacyCenter/components/DataRequest/NominationDataSection.tsx +66 -0
  50. package/src/RedactoPrivacyCenter/components/DataRequest/PurposeSelectionSection.tsx +305 -0
  51. package/src/RedactoPrivacyCenter/components/Form.tsx +1455 -0
  52. package/src/RedactoPrivacyCenter/components/GrievanceTable.tsx +176 -0
  53. package/src/RedactoPrivacyCenter/components/GrievanceTablePagination.tsx +330 -0
  54. package/src/RedactoPrivacyCenter/components/ModifyConsentModal.tsx +329 -0
  55. package/src/RedactoPrivacyCenter/components/Pagination.tsx +140 -0
  56. package/src/RedactoPrivacyCenter/components/PrivacyCenterLayout.tsx +302 -0
  57. package/src/RedactoPrivacyCenter/components/RequestSubmit.tsx +218 -0
  58. package/src/RedactoPrivacyCenter/components/SideMenuBarPC/SideBarPC.tsx +475 -0
  59. package/src/RedactoPrivacyCenter/components/SideMenuBarPC/SideMenuPC.tsx +412 -0
  60. package/src/RedactoPrivacyCenter/components/SideMenuBarPC/constants.tsx +42 -0
  61. package/src/RedactoPrivacyCenter/components/SideMenuBarPC/menuItemsPC.tsx +1 -0
  62. package/src/RedactoPrivacyCenter/components/SideMenuBarPC/types.ts +40 -0
  63. package/src/RedactoPrivacyCenter/components/SideMenuBarPC/utils.ts +38 -0
  64. package/src/RedactoPrivacyCenter/components/ThemeTransitionOverlay.tsx +85 -0
  65. package/src/RedactoPrivacyCenter/components/activitiesColumns.tsx +141 -0
  66. package/src/RedactoPrivacyCenter/components/caseHistoryColumns.tsx +179 -0
  67. package/src/RedactoPrivacyCenter/components/constant.ts +20 -0
  68. package/src/RedactoPrivacyCenter/components/types.ts +68 -0
  69. package/src/RedactoPrivacyCenter/components/utils.tsx +10 -0
  70. package/src/RedactoPrivacyCenter/config/routes.ts +9 -0
  71. package/src/RedactoPrivacyCenter/config/table.ts +25 -0
  72. package/src/RedactoPrivacyCenter/context/AuthContext.tsx +123 -0
  73. package/src/RedactoPrivacyCenter/context/BaseUrlContext.tsx +44 -0
  74. package/src/RedactoPrivacyCenter/context/LocaleContext.tsx +11 -0
  75. package/src/RedactoPrivacyCenter/context/NavigationContext.tsx +64 -0
  76. package/src/RedactoPrivacyCenter/context/OrganizationContext.tsx +30 -0
  77. package/src/RedactoPrivacyCenter/context/PageChromeContext.tsx +60 -0
  78. package/src/RedactoPrivacyCenter/context/theme.tsx +127 -0
  79. package/src/RedactoPrivacyCenter/lib/api.ts +468 -0
  80. package/src/RedactoPrivacyCenter/lib/consent-manager/utils.tsx +63 -0
  81. package/src/RedactoPrivacyCenter/lib/constants.ts +116 -0
  82. package/src/RedactoPrivacyCenter/lib/i18n.ts +81 -0
  83. package/src/RedactoPrivacyCenter/lib/locales.ts +105 -0
  84. package/src/RedactoPrivacyCenter/lib/queries.ts +30 -0
  85. package/src/RedactoPrivacyCenter/lib/types.ts +346 -0
  86. package/src/RedactoPrivacyCenter/lib/useCurrentLanguage.ts +37 -0
  87. package/src/RedactoPrivacyCenter/lib/utils.ts +625 -0
  88. package/src/RedactoPrivacyCenter/locales/as/translation.json +188 -0
  89. package/src/RedactoPrivacyCenter/locales/bho/translation.json +188 -0
  90. package/src/RedactoPrivacyCenter/locales/bn/translation.json +188 -0
  91. package/src/RedactoPrivacyCenter/locales/brx/translation.json +188 -0
  92. package/src/RedactoPrivacyCenter/locales/doi/translation.json +188 -0
  93. package/src/RedactoPrivacyCenter/locales/en/translation.json +188 -0
  94. package/src/RedactoPrivacyCenter/locales/gom/translation.json +188 -0
  95. package/src/RedactoPrivacyCenter/locales/gu/translation.json +188 -0
  96. package/src/RedactoPrivacyCenter/locales/hi/translation.json +188 -0
  97. package/src/RedactoPrivacyCenter/locales/kn/translation.json +188 -0
  98. package/src/RedactoPrivacyCenter/locales/ks/translation.json +188 -0
  99. package/src/RedactoPrivacyCenter/locales/mai/translation.json +188 -0
  100. package/src/RedactoPrivacyCenter/locales/ml/translation.json +188 -0
  101. package/src/RedactoPrivacyCenter/locales/mni-Mtei/translation.json +188 -0
  102. package/src/RedactoPrivacyCenter/locales/mr/translation.json +188 -0
  103. package/src/RedactoPrivacyCenter/locales/ne/translation.json +188 -0
  104. package/src/RedactoPrivacyCenter/locales/or/translation.json +188 -0
  105. package/src/RedactoPrivacyCenter/locales/pa/translation.json +188 -0
  106. package/src/RedactoPrivacyCenter/locales/sa/translation.json +188 -0
  107. package/src/RedactoPrivacyCenter/locales/sat/translation.json +188 -0
  108. package/src/RedactoPrivacyCenter/locales/sd/translation.json +188 -0
  109. package/src/RedactoPrivacyCenter/locales/ta/translation.json +188 -0
  110. package/src/RedactoPrivacyCenter/locales/te/translation.json +188 -0
  111. package/src/RedactoPrivacyCenter/locales/ur/translation.json +188 -0
  112. package/src/RedactoPrivacyCenter/styles/base.css +117 -0
  113. package/src/RedactoPrivacyCenter/styles/injectStyles.ts +1000 -0
  114. package/src/RedactoPrivacyCenter/styles/pcStyles.ts +819 -0
  115. package/src/RedactoPrivacyCenter/styles/responsive.ts +138 -0
  116. package/src/RedactoPrivacyCenter/styles/variables.css +133 -0
  117. package/src/RedactoPrivacyCenter/table/AdvancedTable.tsx +365 -0
  118. package/src/RedactoPrivacyCenter/table/AdvancedTablePagination.tsx +479 -0
  119. package/src/RedactoPrivacyCenter/table/index.ts +2 -0
  120. package/src/RedactoPrivacyCenter/types/images.d.ts +29 -0
  121. package/src/RedactoPrivacyCenter/ui/Footer.tsx +73 -0
  122. package/src/RedactoPrivacyCenter/ui/FormBlockWrapper.tsx +54 -0
  123. package/src/RedactoPrivacyCenter/ui/PCAccordion.tsx +87 -0
  124. package/src/RedactoPrivacyCenter/ui/PCActionIcon.tsx +47 -0
  125. package/src/RedactoPrivacyCenter/ui/PCAvatar.tsx +69 -0
  126. package/src/RedactoPrivacyCenter/ui/PCBadge.tsx +48 -0
  127. package/src/RedactoPrivacyCenter/ui/PCButton.tsx +77 -0
  128. package/src/RedactoPrivacyCenter/ui/PCCheckbox.tsx +55 -0
  129. package/src/RedactoPrivacyCenter/ui/PCCollapse.tsx +97 -0
  130. package/src/RedactoPrivacyCenter/ui/PCEmpty.tsx +35 -0
  131. package/src/RedactoPrivacyCenter/ui/PCInput.tsx +128 -0
  132. package/src/RedactoPrivacyCenter/ui/PCLoader.tsx +30 -0
  133. package/src/RedactoPrivacyCenter/ui/PCModal.tsx +104 -0
  134. package/src/RedactoPrivacyCenter/ui/PCPopover.tsx +175 -0
  135. package/src/RedactoPrivacyCenter/ui/PCSelect.tsx +381 -0
  136. package/src/RedactoPrivacyCenter/ui/PCTable.tsx +137 -0
  137. package/src/RedactoPrivacyCenter/ui/PCText.tsx +39 -0
  138. package/src/RedactoPrivacyCenter/ui/PCTextarea.tsx +43 -0
  139. package/src/RedactoPrivacyCenter/ui/PCTitle.tsx +37 -0
  140. package/src/RedactoPrivacyCenter/ui/PCTooltip.tsx +119 -0
  141. package/src/RedactoPrivacyCenter/ui/SimpleBar.tsx +25 -0
  142. package/src/RedactoPrivacyCenter/ui/StatusBadge.tsx +55 -0
  143. package/src/RedactoPrivacyCenter/ui/ThemeToggle.tsx +70 -0
  144. package/src/RedactoPrivacyCenter/ui/index.ts +18 -0
  145. package/src/RedactoPrivacyCenter/utils/cn.ts +28 -0
  146. package/src/RedactoPrivacyCenter/utils/date.ts +48 -0
  147. package/src/RedactoPrivacyCenter/utils/status.ts +111 -0
  148. package/src/RedactoPrivacyCenter/utils/toast.ts +130 -0
  149. package/src/index.ts +10 -0
  150. package/src/privacy-center.ts +107 -0
  151. package/tsconfig.json +2 -0
  152. package/tsup.config.ts +16 -1
@@ -0,0 +1,138 @@
1
+ /**
2
+ * Responsive Utilities for Privacy Center SDK
3
+ * Provides helper functions for responsive styling
4
+ */
5
+
6
+ export const breakpoints = {
7
+ xs: '0px',
8
+ sm: '640px',
9
+ md: '768px',
10
+ lg: '1024px',
11
+ xl: '1280px',
12
+ '2xl': '1536px',
13
+ } as const;
14
+
15
+ /**
16
+ * Creates a responsive style object that applies different values at different breakpoints
17
+ */
18
+ export const responsive = {
19
+ /**
20
+ * Get responsive padding
21
+ */
22
+ padding: (values: {
23
+ base?: string;
24
+ sm?: string;
25
+ md?: string;
26
+ lg?: string;
27
+ xl?: string;
28
+ }) => {
29
+ const style: React.CSSProperties = {};
30
+ if (values.base) {
31
+ style.padding = values.base;
32
+ }
33
+ // Note: Media queries need to be handled via CSS classes or inline styles with @media
34
+ // For inline styles, we'll use the base value and rely on CSS classes for breakpoints
35
+ return style;
36
+ },
37
+
38
+ /**
39
+ * Get responsive margin
40
+ */
41
+ margin: (values: {
42
+ base?: string;
43
+ sm?: string;
44
+ md?: string;
45
+ lg?: string;
46
+ xl?: string;
47
+ }) => {
48
+ const style: React.CSSProperties = {};
49
+ if (values.base) {
50
+ style.margin = values.base;
51
+ }
52
+ return style;
53
+ },
54
+
55
+ /**
56
+ * Get responsive font size
57
+ */
58
+ fontSize: (values: {
59
+ base?: string;
60
+ sm?: string;
61
+ md?: string;
62
+ lg?: string;
63
+ xl?: string;
64
+ }) => {
65
+ const style: React.CSSProperties = {};
66
+ if (values.base) {
67
+ style.fontSize = values.base;
68
+ }
69
+ return style;
70
+ },
71
+
72
+ /**
73
+ * Get responsive width
74
+ */
75
+ width: (values: {
76
+ base?: string;
77
+ sm?: string;
78
+ md?: string;
79
+ lg?: string;
80
+ xl?: string;
81
+ }) => {
82
+ const style: React.CSSProperties = {};
83
+ if (values.base) {
84
+ style.width = values.base;
85
+ }
86
+ return style;
87
+ },
88
+
89
+ /**
90
+ * Get responsive display (flex/block/none)
91
+ */
92
+ display: (values: {
93
+ base?: 'flex' | 'block' | 'none' | 'grid' | 'inline-flex';
94
+ sm?: 'flex' | 'block' | 'none' | 'grid' | 'inline-flex';
95
+ md?: 'flex' | 'block' | 'none' | 'grid' | 'inline-flex';
96
+ lg?: 'flex' | 'block' | 'none' | 'grid' | 'inline-flex';
97
+ }) => {
98
+ const style: React.CSSProperties = {};
99
+ if (values.base) {
100
+ style.display = values.base;
101
+ }
102
+ return style;
103
+ },
104
+ };
105
+
106
+ /**
107
+ * Common responsive patterns
108
+ */
109
+ export const responsivePatterns = {
110
+ // Container that's full width on mobile, constrained on desktop
111
+ container: {
112
+ width: '100%',
113
+ maxWidth: '100%',
114
+ paddingLeft: '1rem',
115
+ paddingRight: '1rem',
116
+ },
117
+
118
+ // Responsive text sizes
119
+ textResponsive: {
120
+ base: '0.875rem', // sm
121
+ md: '1rem', // base
122
+ lg: '1.125rem', // lg
123
+ },
124
+
125
+ // Responsive spacing
126
+ spacingResponsive: {
127
+ base: '0.75rem', // sm
128
+ md: '1rem', // md
129
+ lg: '1.5rem', // lg
130
+ },
131
+
132
+ // Responsive padding
133
+ paddingResponsive: {
134
+ base: '0.75rem', // sm
135
+ md: '1rem', // md
136
+ lg: '1.5rem', // lg
137
+ },
138
+ };
@@ -0,0 +1,133 @@
1
+ /* CSS Custom Properties for Privacy Center SDK */
2
+ /* These variables are scoped and won't conflict with host app styles */
3
+
4
+ :root,
5
+ [data-theme="light"] {
6
+ /* Colors */
7
+ --pc-primary: #3b82f6;
8
+ --pc-primary-hover: #2563eb;
9
+ --pc-primary-active: #1d4ed8;
10
+ --pc-secondary: #6b7280;
11
+ --pc-secondary-hover: #4b5563;
12
+ --pc-success: #10b981;
13
+ --pc-error: #ef4444;
14
+ --pc-warning: #f59e0b;
15
+ --pc-warning-bg: #fef9c3;
16
+ --pc-warning-border: #fcd34d;
17
+ --pc-warning-text: #92400e;
18
+ --pc-info: #3b82f6;
19
+
20
+ /* Backgrounds */
21
+ --pc-bg-shell: #ffffff;
22
+ --pc-bg-primary: #ffffff;
23
+ --pc-bg-secondary: #f9fafb;
24
+ --pc-bg-tertiary: #f3f4f6;
25
+ --pc-bg-hover: #f9fafb;
26
+ --pc-bg-active: #f3f4f6;
27
+ --pc-bg-overlay: rgba(0, 0, 0, 0.5);
28
+
29
+ /* Text */
30
+ --pc-text-primary: #111827;
31
+ --pc-text-secondary: #6b7280;
32
+ --pc-text-tertiary: #9ca3af;
33
+ --pc-text-inverse: #ffffff;
34
+ --pc-text-disabled: #d1d5db;
35
+
36
+ /* Borders */
37
+ --pc-border-color: #e5e7eb;
38
+ --pc-border-color-hover: #d1d5db;
39
+ --pc-border-color-focus: #3b82f6;
40
+ --pc-border-radius-sm: 0.375rem;
41
+ --pc-border-radius-md: 0.4375rem;
42
+ --pc-border-radius-lg: 0.625rem;
43
+ --pc-border-radius-xl: 0.875rem;
44
+ --pc-border-radius-2xl: 1.25rem;
45
+ --pc-border-radius-3xl: 2rem;
46
+
47
+ /* Shadows */
48
+ --pc-shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
49
+ --pc-shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
50
+ --pc-shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
51
+ --pc-shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
52
+ --pc-sidebar-shadow: 12px 0 28px rgba(15, 23, 42, 0.08), 1px 0 0 rgba(15, 23, 42, 0.04);
53
+
54
+ /* Spacing */
55
+ --pc-spacing-xs: 0.25rem;
56
+ --pc-spacing-sm: 0.5rem;
57
+ --pc-spacing-md: 0.875rem;
58
+ --pc-spacing-lg: 1.25rem;
59
+ --pc-spacing-xl: 1.75rem;
60
+ --pc-spacing-2xl: 2.5rem;
61
+
62
+ /* Typography */
63
+ --pc-font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
64
+ --pc-font-size-xs: 0.75rem;
65
+ --pc-font-size-sm: 0.8125rem;
66
+ --pc-font-size-base: 0.9375rem;
67
+ --pc-font-size-lg: 1.0625rem;
68
+ --pc-font-size-xl: 1.1875rem;
69
+ --pc-font-size-2xl: 1.375rem;
70
+ --pc-font-size-3xl: 1.75rem;
71
+ --pc-font-weight-normal: 400;
72
+ --pc-font-weight-medium: 500;
73
+ --pc-font-weight-semibold: 600;
74
+ --pc-font-weight-bold: 700;
75
+
76
+ /* Transitions */
77
+ --pc-transition-fast: 150ms ease-in-out;
78
+ --pc-transition-base: 200ms ease-in-out;
79
+ --pc-transition-slow: 300ms ease-in-out;
80
+
81
+ /* Z-index */
82
+ --pc-z-dropdown: 1000;
83
+ --pc-z-sticky: 1020;
84
+ --pc-z-fixed: 1030;
85
+ --pc-z-modal-backdrop: 1200;
86
+ --pc-z-modal: 1210;
87
+ --pc-z-popover: 1060;
88
+ --pc-z-tooltip: 1070;
89
+
90
+ /* Icon filters for dark theme */
91
+ --pc-icon-filter: 0;
92
+ }
93
+
94
+ [data-theme="dark"] {
95
+ /* Colors */
96
+ --pc-primary: #60a5fa;
97
+ --pc-primary-hover: #3b82f6;
98
+ --pc-primary-active: #2563eb;
99
+ --pc-secondary: #9ca3af;
100
+ --pc-secondary-hover: #6b7280;
101
+ --pc-success: #34d399;
102
+ --pc-error: #f87171;
103
+ --pc-warning: #fbbf24;
104
+ --pc-warning-bg: #78350f;
105
+ --pc-warning-border: #fbbf24;
106
+ --pc-warning-text: #fef3c7;
107
+ --pc-info: #60a5fa;
108
+
109
+ /* Backgrounds */
110
+ --pc-bg-shell: #111827;
111
+ --pc-bg-primary: #1b2435;
112
+ --pc-bg-secondary: #243044;
113
+ --pc-bg-tertiary: #31405a;
114
+ --pc-bg-hover: #243044;
115
+ --pc-bg-active: #31405a;
116
+ --pc-bg-overlay: rgba(0, 0, 0, 0.7);
117
+
118
+ /* Text */
119
+ --pc-text-primary: #f9fafb;
120
+ --pc-text-secondary: #d1d5db;
121
+ --pc-text-tertiary: #9ca3af;
122
+ --pc-text-inverse: #111827;
123
+ --pc-text-disabled: #6b7280;
124
+
125
+ /* Borders */
126
+ --pc-border-color: rgba(148, 163, 184, 0.18);
127
+ --pc-border-color-hover: rgba(148, 163, 184, 0.28);
128
+ --pc-border-color-focus: #60a5fa;
129
+ --pc-sidebar-shadow: 14px 0 36px rgba(2, 6, 23, 0.42), 1px 0 0 rgba(148, 163, 184, 0.08);
130
+
131
+ /* Icon filters for dark theme */
132
+ --pc-icon-filter: 1;
133
+ }
@@ -0,0 +1,365 @@
1
+ import React from 'react';
2
+ import { useTranslation } from 'react-i18next';
3
+ import { flexRender } from '@tanstack/react-table';
4
+ import { isEmpty } from 'lodash';
5
+ import { PiCaretDownFill, PiCaretUpFill } from 'react-icons/pi';
6
+ import { PCTable, PCLoader, PCEmpty } from '../ui';
7
+ import { pcStyles } from '../styles/pcStyles';
8
+ import type {
9
+ Table as ReactTableType,
10
+ Row,
11
+ Cell,
12
+ HeaderGroup,
13
+ } from '@tanstack/react-table';
14
+
15
+ const getVar = (varName: string): string => `var(${varName})`;
16
+
17
+ export type UniqueIdentifier = string | number;
18
+
19
+ export type TableClassNameProps = {
20
+ container?: string;
21
+ tableClassName?: string;
22
+ headerClassName?: string;
23
+ bodyClassName?: string;
24
+ rowClassName?: string;
25
+ cellClassName?: string;
26
+ headerCellClassName?: string;
27
+ expandedRowClassName?: string;
28
+ expandedCellClassName?: string;
29
+ };
30
+
31
+ export type CustomHeaderCellProps<TData extends Record<string, any>> = {
32
+ columnOrder?: string[];
33
+ headerGroup?: HeaderGroup<TData>;
34
+ isLeftScrollable?: boolean;
35
+ isRightScrollable?: boolean;
36
+ className?: string;
37
+ };
38
+
39
+ export type CustomBodyCellProps<TData extends Record<string, any>> = {
40
+ cell?: Cell<TData, unknown>;
41
+ columnOrder?: string[];
42
+ isLeftScrollable?: boolean;
43
+ isRightScrollable?: boolean;
44
+ className?: string;
45
+ };
46
+
47
+ export type AdvancedTableProps<T extends Record<string, any>> = {
48
+ table: ReactTableType<T>;
49
+ variant?: 'modern' | 'minimal';
50
+ classNames?: TableClassNameProps;
51
+ isLoading?: boolean;
52
+ showLoadingText?: boolean;
53
+ className?: string;
54
+ customLoader?: React.ReactNode;
55
+ expandedComponent?: (row: Row<T>) => React.ReactNode;
56
+ };
57
+
58
+ export default function AdvancedTable<TData extends Record<string, any>>({
59
+ table,
60
+ variant = 'modern',
61
+ classNames,
62
+ isLoading = false,
63
+ showLoadingText = false,
64
+ className,
65
+ customLoader,
66
+ expandedComponent,
67
+ }: AdvancedTableProps<TData>) {
68
+ const { t } = useTranslation();
69
+ if (!table) return null;
70
+
71
+ return (
72
+ <>
73
+ <div
74
+ className={`${classNames?.container || ''} ${className || ''}`}
75
+ style={{
76
+ ...pcStyles.wFull,
77
+ maxWidth: '100%',
78
+ ...pcStyles.overflowXAuto,
79
+ borderRadius: getVar('--pc-border-radius-md'),
80
+ border: `1px solid ${getVar('--pc-border-color')}`,
81
+ backgroundColor: getVar('--pc-bg-primary'),
82
+ transition: 'background-color 0.3s ease, border-color 0.3s ease',
83
+ }}
84
+ >
85
+ <PCTable
86
+ variant={variant}
87
+ className={classNames?.tableClassName}
88
+ style={{
89
+ minWidth: '100%',
90
+ backgroundColor: getVar('--pc-bg-primary'),
91
+ }}
92
+ >
93
+ <PCTable.Header className={classNames?.headerClassName}>
94
+ {table.getHeaderGroups().map((headerGroup) => (
95
+ <PCTable.Row
96
+ key={headerGroup.id}
97
+ className={classNames?.rowClassName}
98
+ >
99
+ <TableHeadBasic
100
+ headerGroup={headerGroup}
101
+ className={classNames?.headerCellClassName}
102
+ />
103
+ </PCTable.Row>
104
+ ))}
105
+ </PCTable.Header>
106
+
107
+ <PCTable.Body className={classNames?.bodyClassName}>
108
+ {table.getRowModel().rows.map((row) => {
109
+ const meta = (table.options.meta as any) || {};
110
+ const onRowClick = meta.onRowClick;
111
+ const handleRowClick = onRowClick
112
+ ? (e: React.MouseEvent) => {
113
+ e.preventDefault();
114
+ onRowClick(row.original);
115
+ }
116
+ : undefined;
117
+
118
+ // Get expandedComponent from prop or meta
119
+ const rowExpandedComponent =
120
+ expandedComponent || meta.expandedComponent;
121
+
122
+ return (
123
+ <React.Fragment key={row.id}>
124
+ <PCTable.Row
125
+ className={classNames?.rowClassName}
126
+ style={onRowClick ? { cursor: 'pointer' } : {}}
127
+ onClick={handleRowClick}
128
+ >
129
+ {row.getVisibleCells().map((cell) => (
130
+ <TableCellBasic
131
+ key={cell.id}
132
+ cell={cell}
133
+ className={classNames?.cellClassName}
134
+ />
135
+ ))}
136
+ </PCTable.Row>
137
+
138
+ {/* Expanded row */}
139
+ {rowExpandedComponent && (
140
+ <PCTable.Row
141
+ className={classNames?.expandedRowClassName}
142
+ style={{
143
+ overflow: 'hidden',
144
+ transition: 'all 0.3s ease-in-out',
145
+ maxHeight: row.getIsExpanded() ? '2000px' : '0',
146
+ opacity: row.getIsExpanded() ? 1 : 0,
147
+ height: row.getIsExpanded() ? 'auto' : '0',
148
+ minHeight: row.getIsExpanded() ? 'auto' : '0',
149
+ }}
150
+ >
151
+ <PCTable.Cell
152
+ colSpan={row.getVisibleCells().length}
153
+ className={classNames?.expandedCellClassName}
154
+ style={{
155
+ padding: row.getIsExpanded() ? undefined : '0',
156
+ transition: 'all 0.3s ease-in-out',
157
+ height: row.getIsExpanded() ? 'auto' : '0',
158
+ paddingTop: row.getIsExpanded() ? undefined : '0',
159
+ paddingBottom: row.getIsExpanded() ? undefined : '0',
160
+ }}
161
+ >
162
+ <div
163
+ style={{
164
+ transition: 'all 0.3s ease-in-out',
165
+ transform: row.getIsExpanded() ? 'translateY(0)' : 'translateY(-8px)',
166
+ opacity: row.getIsExpanded() ? 1 : 0,
167
+ height: row.getIsExpanded() ? 'auto' : '0',
168
+ }}
169
+ >
170
+ {rowExpandedComponent(row)}
171
+ </div>
172
+ </PCTable.Cell>
173
+ </PCTable.Row>
174
+ )}
175
+ </React.Fragment>
176
+ );
177
+ })}
178
+ </PCTable.Body>
179
+ </PCTable>
180
+
181
+ {isLoading && (
182
+ <div style={{
183
+ ...pcStyles.flex,
184
+ ...pcStyles.flexCol,
185
+ ...pcStyles.itemsCenter,
186
+ ...pcStyles.justifyCenter,
187
+ minHeight: '320px',
188
+ height: '100%',
189
+ backgroundColor: getVar('--pc-bg-primary'),
190
+ transition: 'background-color 0.3s ease',
191
+ }}>
192
+ {customLoader ? (
193
+ customLoader
194
+ ) : (
195
+ <div style={{
196
+ ...pcStyles.flex,
197
+ ...pcStyles.flexCol,
198
+ ...pcStyles.itemsCenter,
199
+ ...pcStyles.justifyCenter,
200
+ ...pcStyles.gapMd,
201
+ }}>
202
+ <PCLoader />
203
+ {showLoadingText && (
204
+ <h6 style={{
205
+ ...pcStyles.fontWeightMedium,
206
+ color: getVar('--pc-text-secondary'),
207
+ transition: 'color 0.3s ease',
208
+ }}>Loading...</h6>
209
+ )}
210
+ </div>
211
+ )}
212
+ </div>
213
+ )}
214
+
215
+ {isEmpty(table.getRowModel().rows) && !isLoading && (
216
+ <div style={{
217
+ ...pcStyles.flex,
218
+ ...pcStyles.flexCol,
219
+ ...pcStyles.itemsCenter,
220
+ ...pcStyles.justifyCenter,
221
+ minHeight: '320px',
222
+ padding: getVar('--pc-spacing-2xl'),
223
+ backgroundColor: getVar('--pc-bg-primary'),
224
+ transition: 'background-color 0.3s ease',
225
+ }}>
226
+ <PCEmpty
227
+ icon={
228
+ <svg
229
+ viewBox="0 0 24 24"
230
+ fill="currentColor"
231
+ style={{
232
+ width: '64px',
233
+ height: '64px',
234
+ color: getVar('--pc-text-tertiary'),
235
+ transition: 'color 0.3s ease',
236
+ }}
237
+ >
238
+ <path d="M3 4a1 1 0 011-1h16a1 1 0 011 1v2a1 1 0 01-1 1H4a1 1 0 01-1-1V4zM3 10a1 1 0 011-1h16a1 1 0 011 1v2a1 1 0 01-1 1H4a1 1 0 01-1-1v-2zM3 16a1 1 0 011-1h16a1 1 0 011 1v2a1 1 0 01-1 1H4a1 1 0 01-1-1v-2z" />
239
+ </svg>
240
+ }
241
+ title={t('noData')}
242
+ />
243
+ </div>
244
+ )}
245
+ </div>
246
+ </>
247
+ );
248
+ }
249
+
250
+ // Basic Header component
251
+ export function TableHeadBasic<TData extends Record<string, any>>({
252
+ headerGroup,
253
+ className,
254
+ }: CustomHeaderCellProps<TData>) {
255
+ if (!headerGroup) return null;
256
+
257
+ return (
258
+ <>
259
+ {headerGroup.headers.map((header) => {
260
+ const align = header.column.columnDef.meta?.align || 'left';
261
+ return (
262
+ <PCTable.Head
263
+ key={header.id}
264
+ colSpan={header.colSpan}
265
+ className={className}
266
+ style={{
267
+ position: 'relative',
268
+ textAlign: align,
269
+ }}
270
+ >
271
+ <div style={{
272
+ ...pcStyles.flex,
273
+ ...pcStyles.itemsStart,
274
+ justifyContent: align === 'right' ? 'flex-end' : align === 'center' ? 'center' : 'flex-start',
275
+ }}>
276
+ {header.isPlaceholder
277
+ ? null
278
+ : flexRender(header.column.columnDef.header, header.getContext())}
279
+
280
+ {header.column.getCanSort() && (
281
+ <button
282
+ type="button"
283
+ onClick={header.column.getToggleSortingHandler()}
284
+ style={{
285
+ marginLeft: '0.25rem',
286
+ display: 'inline-block',
287
+ background: 'none',
288
+ border: 'none',
289
+ cursor: 'pointer',
290
+ padding: 0,
291
+ color: getVar('--pc-text-secondary'),
292
+ transition: 'color 0.2s ease',
293
+ }}
294
+ aria-label="Sort by column"
295
+ onMouseEnter={(e) => {
296
+ e.currentTarget.style.color = getVar('--pc-text-primary');
297
+ }}
298
+ onMouseLeave={(e) => {
299
+ e.currentTarget.style.color = getVar('--pc-text-secondary');
300
+ }}
301
+ >
302
+ {{
303
+ asc: <PiCaretUpFill size={14} />,
304
+ desc: <PiCaretDownFill size={14} />,
305
+ }[header.column.getIsSorted() as string] ??
306
+ (header.column.columnDef.header !== '' && (
307
+ <PiCaretDownFill size={14} style={{ opacity: 0.5 }} />
308
+ ))}
309
+ </button>
310
+ )}
311
+ </div>
312
+
313
+ {header.column.getCanResize() && (
314
+ <div
315
+ {...{
316
+ onDoubleClick: () => header.column.resetSize(),
317
+ onMouseDown: header.getResizeHandler(),
318
+ onTouchStart: header.getResizeHandler(),
319
+ }}
320
+ style={{
321
+ position: 'absolute',
322
+ right: 0,
323
+ top: 0,
324
+ height: '100%',
325
+ width: '2px',
326
+ cursor: 'col-resize',
327
+ backgroundColor: getVar('--pc-border-color'),
328
+ display: 'none',
329
+ transition: 'background-color 0.2s ease',
330
+ }}
331
+ onMouseEnter={(e) => {
332
+ e.currentTarget.style.display = 'block';
333
+ e.currentTarget.style.backgroundColor = getVar('--pc-primary');
334
+ }}
335
+ onMouseLeave={(e) => {
336
+ e.currentTarget.style.display = 'none';
337
+ e.currentTarget.style.backgroundColor = getVar('--pc-border-color');
338
+ }}
339
+ />
340
+ )}
341
+ </PCTable.Head>
342
+ );
343
+ })}
344
+ </>
345
+ );
346
+ }
347
+
348
+ // Basic Cell component
349
+ export function TableCellBasic<TData extends Record<string, any>>({
350
+ cell,
351
+ className,
352
+ }: CustomBodyCellProps<TData>) {
353
+ if (!cell) return null;
354
+
355
+ const align = cell.column.columnDef.meta?.align || 'left';
356
+
357
+ return (
358
+ <PCTable.Cell
359
+ className={className}
360
+ style={{ textAlign: align }}
361
+ >
362
+ {flexRender(cell.column.columnDef.cell, cell.getContext())}
363
+ </PCTable.Cell>
364
+ );
365
+ }