@redacto.io/consent-sdk-react 4.0.0 → 5.1.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 (161) hide show
  1. package/CHANGELOG.md +19 -1
  2. package/LICENSE +176 -0
  3. package/README.md +98 -1
  4. package/dist/index.js +231 -96
  5. package/dist/index.mjs +231 -96
  6. package/dist/privacy-center.d.mts +649 -0
  7. package/dist/privacy-center.d.ts +649 -0
  8. package/dist/privacy-center.js +20824 -0
  9. package/dist/privacy-center.mjs +20789 -0
  10. package/package.json +47 -3
  11. package/src/RedactoNoticeConsent/RedactoNoticeConsent.tsx +6 -4
  12. package/src/RedactoNoticeConsent/api/index.ts +2 -0
  13. package/src/RedactoNoticeConsent/api/types.ts +2 -0
  14. package/src/RedactoNoticeConsent/components/DigiLockerCallback.tsx +128 -62
  15. package/src/RedactoNoticeConsent/language-codes.ts +97 -0
  16. package/src/RedactoNoticeConsentInline/RedactoNoticeConsentInline.tsx +0 -3
  17. package/src/RedactoNoticeConsentInline/api/index.ts +0 -1
  18. package/src/RedactoPrivacyCenter/PrivacyCenterActivityPage.tsx +19 -0
  19. package/src/RedactoPrivacyCenter/PrivacyCenterCaseDetailsPage.tsx +154 -0
  20. package/src/RedactoPrivacyCenter/PrivacyCenterConsentManagerPage.tsx +17 -0
  21. package/src/RedactoPrivacyCenter/PrivacyCenterFormPage.tsx +79 -0
  22. package/src/RedactoPrivacyCenter/PrivacyCenterHomePage.tsx +30 -0
  23. package/src/RedactoPrivacyCenter/PrivacyCenterLayout.tsx +173 -0
  24. package/src/RedactoPrivacyCenter/RedactoPrivacyCenter.tsx +55 -0
  25. package/src/RedactoPrivacyCenter/api/actions.ts +476 -0
  26. package/src/RedactoPrivacyCenter/api/client.ts +524 -0
  27. package/src/RedactoPrivacyCenter/api/config.ts +33 -0
  28. package/src/RedactoPrivacyCenter/api/fetcher.ts +181 -0
  29. package/src/RedactoPrivacyCenter/api/upload.ts +93 -0
  30. package/src/RedactoPrivacyCenter/assets/character.svg +31 -0
  31. package/src/RedactoPrivacyCenter/assets/fileAttach.svg +9 -0
  32. package/src/RedactoPrivacyCenter/assets/greenTick.svg +4 -0
  33. package/src/RedactoPrivacyCenter/assets/mail.svg +3 -0
  34. package/src/RedactoPrivacyCenter/assets/poweredByRedacto.svg +9 -0
  35. package/src/RedactoPrivacyCenter/assets/sentImg.svg +9 -0
  36. package/src/RedactoPrivacyCenter/assets/uploadFileIcon.svg +9 -0
  37. package/src/RedactoPrivacyCenter/components/ActivitiesList.tsx +272 -0
  38. package/src/RedactoPrivacyCenter/components/CaseDetails/AttachmentCard.tsx +38 -0
  39. package/src/RedactoPrivacyCenter/components/CaseDetails/ChatBubble.tsx +31 -0
  40. package/src/RedactoPrivacyCenter/components/CaseDetails/DocumentRequestCard.tsx +73 -0
  41. package/src/RedactoPrivacyCenter/components/CaseDetails/MessageComposer.tsx +87 -0
  42. package/src/RedactoPrivacyCenter/components/CaseDetails/MessageItem.tsx +95 -0
  43. package/src/RedactoPrivacyCenter/components/CaseDetails/MessagesTab.tsx +147 -0
  44. package/src/RedactoPrivacyCenter/components/CaseDetails/RequestDetailsTab.tsx +171 -0
  45. package/src/RedactoPrivacyCenter/components/CaseDetails/StatusEvent.tsx +23 -0
  46. package/src/RedactoPrivacyCenter/components/CaseDetails/useFileUpload.ts +116 -0
  47. package/src/RedactoPrivacyCenter/components/CaseDetails/useMessagePolling.ts +36 -0
  48. package/src/RedactoPrivacyCenter/components/CaseDetails/utils.ts +56 -0
  49. package/src/RedactoPrivacyCenter/components/CaseDetailsModal.tsx +469 -0
  50. package/src/RedactoPrivacyCenter/components/CaseHistory.tsx +426 -0
  51. package/src/RedactoPrivacyCenter/components/ConsentManager.tsx +732 -0
  52. package/src/RedactoPrivacyCenter/components/ConsentManagerColumns.tsx +238 -0
  53. package/src/RedactoPrivacyCenter/components/ConsentManagerConstants.ts +7 -0
  54. package/src/RedactoPrivacyCenter/components/ConsentManagerTableSkeleton.tsx +155 -0
  55. package/src/RedactoPrivacyCenter/components/DataRequest/CorrectionDataSection.tsx +189 -0
  56. package/src/RedactoPrivacyCenter/components/DataRequest/GrievanceDataSection.tsx +118 -0
  57. package/src/RedactoPrivacyCenter/components/DataRequest/NominationDataSection.tsx +66 -0
  58. package/src/RedactoPrivacyCenter/components/DataRequest/PurposeSelectionSection.tsx +304 -0
  59. package/src/RedactoPrivacyCenter/components/Form.tsx +1596 -0
  60. package/src/RedactoPrivacyCenter/components/GrievanceTable.tsx +174 -0
  61. package/src/RedactoPrivacyCenter/components/GrievanceTablePagination.tsx +337 -0
  62. package/src/RedactoPrivacyCenter/components/ModifyConsentModal.tsx +330 -0
  63. package/src/RedactoPrivacyCenter/components/Pagination.tsx +140 -0
  64. package/src/RedactoPrivacyCenter/components/PrivacyCenterLayout.tsx +304 -0
  65. package/src/RedactoPrivacyCenter/components/RequestSubmit.tsx +232 -0
  66. package/src/RedactoPrivacyCenter/components/SideMenuBarPC/SideBarPC.tsx +475 -0
  67. package/src/RedactoPrivacyCenter/components/SideMenuBarPC/SideMenuPC.tsx +408 -0
  68. package/src/RedactoPrivacyCenter/components/SideMenuBarPC/constants.tsx +42 -0
  69. package/src/RedactoPrivacyCenter/components/SideMenuBarPC/menuItemsPC.tsx +1 -0
  70. package/src/RedactoPrivacyCenter/components/SideMenuBarPC/types.ts +40 -0
  71. package/src/RedactoPrivacyCenter/components/SideMenuBarPC/utils.ts +38 -0
  72. package/src/RedactoPrivacyCenter/components/ThemeTransitionOverlay.tsx +85 -0
  73. package/src/RedactoPrivacyCenter/components/activitiesColumns.tsx +141 -0
  74. package/src/RedactoPrivacyCenter/components/caseHistoryColumns.tsx +159 -0
  75. package/src/RedactoPrivacyCenter/components/constant.ts +16 -0
  76. package/src/RedactoPrivacyCenter/components/types.ts +76 -0
  77. package/src/RedactoPrivacyCenter/components/utils.tsx +10 -0
  78. package/src/RedactoPrivacyCenter/config/routes.ts +9 -0
  79. package/src/RedactoPrivacyCenter/config/table.ts +25 -0
  80. package/src/RedactoPrivacyCenter/context/AuthContext.tsx +137 -0
  81. package/src/RedactoPrivacyCenter/context/BaseUrlContext.tsx +41 -0
  82. package/src/RedactoPrivacyCenter/context/LocaleContext.tsx +11 -0
  83. package/src/RedactoPrivacyCenter/context/NavigationContext.tsx +96 -0
  84. package/src/RedactoPrivacyCenter/context/OrganizationContext.tsx +30 -0
  85. package/src/RedactoPrivacyCenter/context/PageChromeContext.tsx +60 -0
  86. package/src/RedactoPrivacyCenter/context/theme.tsx +127 -0
  87. package/src/RedactoPrivacyCenter/context/types.ts +14 -0
  88. package/src/RedactoPrivacyCenter/lib/api.ts +566 -0
  89. package/src/RedactoPrivacyCenter/lib/consent-manager/utils.tsx +63 -0
  90. package/src/RedactoPrivacyCenter/lib/constants.ts +161 -0
  91. package/src/RedactoPrivacyCenter/lib/i18n.ts +81 -0
  92. package/src/RedactoPrivacyCenter/lib/locales.ts +105 -0
  93. package/src/RedactoPrivacyCenter/lib/queries.ts +134 -0
  94. package/src/RedactoPrivacyCenter/lib/types.ts +531 -0
  95. package/src/RedactoPrivacyCenter/lib/useCurrentLanguage.ts +37 -0
  96. package/src/RedactoPrivacyCenter/lib/utils.ts +626 -0
  97. package/src/RedactoPrivacyCenter/locales/as/translation.json +280 -0
  98. package/src/RedactoPrivacyCenter/locales/bho/translation.json +280 -0
  99. package/src/RedactoPrivacyCenter/locales/bn/translation.json +280 -0
  100. package/src/RedactoPrivacyCenter/locales/brx/translation.json +280 -0
  101. package/src/RedactoPrivacyCenter/locales/doi/translation.json +280 -0
  102. package/src/RedactoPrivacyCenter/locales/en/translation.json +255 -0
  103. package/src/RedactoPrivacyCenter/locales/gom/translation.json +280 -0
  104. package/src/RedactoPrivacyCenter/locales/gu/translation.json +280 -0
  105. package/src/RedactoPrivacyCenter/locales/hi/translation.json +280 -0
  106. package/src/RedactoPrivacyCenter/locales/kn/translation.json +280 -0
  107. package/src/RedactoPrivacyCenter/locales/ks/translation.json +280 -0
  108. package/src/RedactoPrivacyCenter/locales/mai/translation.json +280 -0
  109. package/src/RedactoPrivacyCenter/locales/ml/translation.json +280 -0
  110. package/src/RedactoPrivacyCenter/locales/mni-Mtei/translation.json +280 -0
  111. package/src/RedactoPrivacyCenter/locales/mr/translation.json +280 -0
  112. package/src/RedactoPrivacyCenter/locales/ne/translation.json +280 -0
  113. package/src/RedactoPrivacyCenter/locales/or/translation.json +280 -0
  114. package/src/RedactoPrivacyCenter/locales/pa/translation.json +280 -0
  115. package/src/RedactoPrivacyCenter/locales/sa/translation.json +280 -0
  116. package/src/RedactoPrivacyCenter/locales/sat/translation.json +280 -0
  117. package/src/RedactoPrivacyCenter/locales/sd/translation.json +280 -0
  118. package/src/RedactoPrivacyCenter/locales/ta/translation.json +280 -0
  119. package/src/RedactoPrivacyCenter/locales/te/translation.json +280 -0
  120. package/src/RedactoPrivacyCenter/locales/ur/translation.json +280 -0
  121. package/src/RedactoPrivacyCenter/styles/base.css +117 -0
  122. package/src/RedactoPrivacyCenter/styles/injectStyles.ts +1725 -0
  123. package/src/RedactoPrivacyCenter/styles/pcStyles.ts +813 -0
  124. package/src/RedactoPrivacyCenter/styles/responsive.ts +138 -0
  125. package/src/RedactoPrivacyCenter/styles/variables.css +133 -0
  126. package/src/RedactoPrivacyCenter/table/AdvancedTable.tsx +367 -0
  127. package/src/RedactoPrivacyCenter/table/AdvancedTablePagination.tsx +476 -0
  128. package/src/RedactoPrivacyCenter/table/index.ts +2 -0
  129. package/src/RedactoPrivacyCenter/types/images.d.ts +29 -0
  130. package/src/RedactoPrivacyCenter/ui/Footer.tsx +75 -0
  131. package/src/RedactoPrivacyCenter/ui/FormBlockWrapper.tsx +54 -0
  132. package/src/RedactoPrivacyCenter/ui/PCAccordion.tsx +93 -0
  133. package/src/RedactoPrivacyCenter/ui/PCActionIcon.tsx +47 -0
  134. package/src/RedactoPrivacyCenter/ui/PCAvatar.tsx +69 -0
  135. package/src/RedactoPrivacyCenter/ui/PCBadge.tsx +48 -0
  136. package/src/RedactoPrivacyCenter/ui/PCButton.tsx +77 -0
  137. package/src/RedactoPrivacyCenter/ui/PCCheckbox.tsx +55 -0
  138. package/src/RedactoPrivacyCenter/ui/PCCollapse.tsx +107 -0
  139. package/src/RedactoPrivacyCenter/ui/PCEmpty.tsx +35 -0
  140. package/src/RedactoPrivacyCenter/ui/PCInput.tsx +132 -0
  141. package/src/RedactoPrivacyCenter/ui/PCLoader.tsx +31 -0
  142. package/src/RedactoPrivacyCenter/ui/PCModal.tsx +106 -0
  143. package/src/RedactoPrivacyCenter/ui/PCPopover.tsx +173 -0
  144. package/src/RedactoPrivacyCenter/ui/PCSelect.tsx +387 -0
  145. package/src/RedactoPrivacyCenter/ui/PCTable.tsx +149 -0
  146. package/src/RedactoPrivacyCenter/ui/PCText.tsx +41 -0
  147. package/src/RedactoPrivacyCenter/ui/PCTextarea.tsx +43 -0
  148. package/src/RedactoPrivacyCenter/ui/PCTitle.tsx +37 -0
  149. package/src/RedactoPrivacyCenter/ui/PCTooltip.tsx +119 -0
  150. package/src/RedactoPrivacyCenter/ui/SimpleBar.tsx +25 -0
  151. package/src/RedactoPrivacyCenter/ui/StatusBadge.tsx +53 -0
  152. package/src/RedactoPrivacyCenter/ui/ThemeToggle.tsx +72 -0
  153. package/src/RedactoPrivacyCenter/ui/index.ts +18 -0
  154. package/src/RedactoPrivacyCenter/utils/cn.ts +28 -0
  155. package/src/RedactoPrivacyCenter/utils/date.ts +48 -0
  156. package/src/RedactoPrivacyCenter/utils/status.ts +111 -0
  157. package/src/RedactoPrivacyCenter/utils/toast.ts +130 -0
  158. package/src/privacy-center.ts +108 -0
  159. package/tsconfig.json +2 -0
  160. package/tsup.config.ts +16 -1
  161. package/.turbo/turbo-build.log +0 -21
@@ -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,367 @@
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
+ import type { TableColumnMeta } from '../components/types';
15
+
16
+ const getVar = (varName: string): string => `var(${varName})`;
17
+
18
+ export type UniqueIdentifier = string | number;
19
+
20
+ export type TableClassNameProps = {
21
+ container?: string;
22
+ tableClassName?: string;
23
+ headerClassName?: string;
24
+ bodyClassName?: string;
25
+ rowClassName?: string;
26
+ cellClassName?: string;
27
+ headerCellClassName?: string;
28
+ expandedRowClassName?: string;
29
+ expandedCellClassName?: string;
30
+ };
31
+
32
+ export type CustomHeaderCellProps<TData extends Record<string, any>> = {
33
+ columnOrder?: string[];
34
+ headerGroup?: HeaderGroup<TData>;
35
+ isLeftScrollable?: boolean;
36
+ isRightScrollable?: boolean;
37
+ className?: string;
38
+ };
39
+
40
+ export type CustomBodyCellProps<TData extends Record<string, any>> = {
41
+ cell?: Cell<TData, unknown>;
42
+ columnOrder?: string[];
43
+ isLeftScrollable?: boolean;
44
+ isRightScrollable?: boolean;
45
+ className?: string;
46
+ };
47
+
48
+ export type AdvancedTableProps<T extends Record<string, any>> = {
49
+ table: ReactTableType<T>;
50
+ variant?: 'modern' | 'minimal';
51
+ classNames?: TableClassNameProps;
52
+ isLoading?: boolean;
53
+ showLoadingText?: boolean;
54
+ className?: string;
55
+ customLoader?: React.ReactNode;
56
+ expandedComponent?: (row: Row<T>) => React.ReactNode;
57
+ };
58
+
59
+ export default function AdvancedTable<TData extends Record<string, any>>({
60
+ table,
61
+ variant = 'modern',
62
+ classNames,
63
+ isLoading = false,
64
+ showLoadingText = false,
65
+ className,
66
+ customLoader,
67
+ expandedComponent,
68
+ }: AdvancedTableProps<TData>) {
69
+ const { t } = useTranslation();
70
+ if (!table) return null;
71
+
72
+ return (
73
+ <>
74
+ <div
75
+ className={`${classNames?.container || ''} ${className || ''}`}
76
+ style={{
77
+ ...pcStyles.wFull,
78
+ maxWidth: '100%',
79
+ ...pcStyles.overflowXAuto,
80
+ borderRadius: getVar('--pc-border-radius-md'),
81
+ border: `1px solid ${getVar('--pc-border-color')}`,
82
+ backgroundColor: getVar('--pc-bg-primary'),
83
+ transition: 'background-color 0.3s ease, border-color 0.3s ease',
84
+ }}
85
+ >
86
+ <PCTable
87
+ variant={variant}
88
+ className={classNames?.tableClassName}
89
+ style={{
90
+ minWidth: '100%',
91
+ backgroundColor: getVar('--pc-bg-primary'),
92
+ }}
93
+ >
94
+ <PCTable.Header className={classNames?.headerClassName}>
95
+ {table.getHeaderGroups().map((headerGroup) => (
96
+ <PCTable.Row
97
+ key={headerGroup.id}
98
+ className={classNames?.rowClassName}
99
+ >
100
+ <TableHeadBasic
101
+ headerGroup={headerGroup}
102
+ className={classNames?.headerCellClassName}
103
+ />
104
+ </PCTable.Row>
105
+ ))}
106
+ </PCTable.Header>
107
+
108
+ <PCTable.Body className={classNames?.bodyClassName}>
109
+ {table.getRowModel().rows.map((row) => {
110
+ const meta = (table.options.meta as any) || {};
111
+ const onRowClick = meta.onRowClick;
112
+ const handleRowClick = onRowClick
113
+ ? (e: React.MouseEvent) => {
114
+ e.preventDefault();
115
+ onRowClick(row.original);
116
+ }
117
+ : undefined;
118
+
119
+ // Get expandedComponent from prop or meta
120
+ const rowExpandedComponent =
121
+ expandedComponent || meta.expandedComponent;
122
+
123
+ return (
124
+ <React.Fragment key={row.id}>
125
+ <PCTable.Row
126
+ className={classNames?.rowClassName}
127
+ style={onRowClick ? { cursor: 'pointer' } : {}}
128
+ onClick={handleRowClick}
129
+ >
130
+ {row.getVisibleCells().map((cell) => (
131
+ <TableCellBasic
132
+ key={cell.id}
133
+ cell={cell}
134
+ className={classNames?.cellClassName}
135
+ />
136
+ ))}
137
+ </PCTable.Row>
138
+
139
+ {/* Expanded row */}
140
+ {rowExpandedComponent && (
141
+ <PCTable.Row
142
+ className={classNames?.expandedRowClassName}
143
+ style={{
144
+ overflow: 'hidden',
145
+ transition: 'all 0.3s ease-in-out',
146
+ maxHeight: row.getIsExpanded() ? '2000px' : '0',
147
+ opacity: row.getIsExpanded() ? 1 : 0,
148
+ height: row.getIsExpanded() ? 'auto' : '0',
149
+ minHeight: row.getIsExpanded() ? 'auto' : '0',
150
+ }}
151
+ >
152
+ <PCTable.Cell
153
+ colSpan={row.getVisibleCells().length}
154
+ className={classNames?.expandedCellClassName}
155
+ style={{
156
+ padding: row.getIsExpanded() ? undefined : '0',
157
+ transition: 'all 0.3s ease-in-out',
158
+ height: row.getIsExpanded() ? 'auto' : '0',
159
+ paddingTop: row.getIsExpanded() ? undefined : '0',
160
+ paddingBottom: row.getIsExpanded() ? undefined : '0',
161
+ }}
162
+ >
163
+ <div
164
+ style={{
165
+ transition: 'all 0.3s ease-in-out',
166
+ transform: row.getIsExpanded() ? 'translateY(0)' : 'translateY(-8px)',
167
+ opacity: row.getIsExpanded() ? 1 : 0,
168
+ height: row.getIsExpanded() ? 'auto' : '0',
169
+ }}
170
+ >
171
+ {rowExpandedComponent(row)}
172
+ </div>
173
+ </PCTable.Cell>
174
+ </PCTable.Row>
175
+ )}
176
+ </React.Fragment>
177
+ );
178
+ })}
179
+ </PCTable.Body>
180
+ </PCTable>
181
+
182
+ {isLoading && (
183
+ <div style={{
184
+ ...pcStyles.flex,
185
+ ...pcStyles.flexCol,
186
+ ...pcStyles.itemsCenter,
187
+ ...pcStyles.justifyCenter,
188
+ minHeight: '320px',
189
+ height: '100%',
190
+ backgroundColor: getVar('--pc-bg-primary'),
191
+ transition: 'background-color 0.3s ease',
192
+ }}>
193
+ {customLoader ? (
194
+ customLoader
195
+ ) : (
196
+ <div style={{
197
+ ...pcStyles.flex,
198
+ ...pcStyles.flexCol,
199
+ ...pcStyles.itemsCenter,
200
+ ...pcStyles.justifyCenter,
201
+ ...pcStyles.gapMd,
202
+ }}>
203
+ <PCLoader />
204
+ {showLoadingText && (
205
+ <h6 style={{
206
+ ...pcStyles.fontWeightMedium,
207
+ color: getVar('--pc-text-secondary'),
208
+ transition: 'color 0.3s ease',
209
+ }}>Loading...</h6>
210
+ )}
211
+ </div>
212
+ )}
213
+ </div>
214
+ )}
215
+
216
+ {isEmpty(table.getRowModel().rows) && !isLoading && (
217
+ <div style={{
218
+ ...pcStyles.flex,
219
+ ...pcStyles.flexCol,
220
+ ...pcStyles.itemsCenter,
221
+ ...pcStyles.justifyCenter,
222
+ minHeight: '320px',
223
+ padding: getVar('--pc-spacing-2xl'),
224
+ backgroundColor: getVar('--pc-bg-primary'),
225
+ transition: 'background-color 0.3s ease',
226
+ }}>
227
+ <PCEmpty
228
+ icon={
229
+ <svg
230
+ viewBox="0 0 24 24"
231
+ fill="currentColor"
232
+ style={{
233
+ width: '64px',
234
+ height: '64px',
235
+ color: getVar('--pc-text-tertiary'),
236
+ transition: 'color 0.3s ease',
237
+ }}
238
+ >
239
+ <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" />
240
+ </svg>
241
+ }
242
+ title={t('noData')}
243
+ />
244
+ </div>
245
+ )}
246
+ </div>
247
+ </>
248
+ );
249
+ }
250
+
251
+ // Basic Header component
252
+ export function TableHeadBasic<TData extends Record<string, any>>({
253
+ headerGroup,
254
+ className,
255
+ }: CustomHeaderCellProps<TData>) {
256
+ const { t } = useTranslation();
257
+ if (!headerGroup) return null;
258
+
259
+ return (
260
+ <>
261
+ {headerGroup.headers.map((header) => {
262
+ const align = (header.column.columnDef.meta as TableColumnMeta | undefined)?.align || 'left';
263
+ return (
264
+ <PCTable.Head
265
+ key={header.id}
266
+ colSpan={header.colSpan}
267
+ className={className}
268
+ style={{
269
+ position: 'relative',
270
+ textAlign: align,
271
+ }}
272
+ >
273
+ <div style={{
274
+ ...pcStyles.flex,
275
+ ...pcStyles.itemsStart,
276
+ justifyContent: align === 'right' ? 'flex-end' : align === 'center' ? 'center' : 'flex-start',
277
+ }}>
278
+ {header.isPlaceholder
279
+ ? null
280
+ : flexRender(header.column.columnDef.header, header.getContext())}
281
+
282
+ {header.column.getCanSort() && (
283
+ <button
284
+ type="button"
285
+ onClick={header.column.getToggleSortingHandler()}
286
+ style={{
287
+ marginLeft: '0.25rem',
288
+ display: 'inline-block',
289
+ background: 'none',
290
+ border: 'none',
291
+ cursor: 'pointer',
292
+ padding: 0,
293
+ color: getVar('--pc-text-secondary'),
294
+ transition: 'color 0.2s ease',
295
+ }}
296
+ aria-label={t('sortByColumn')}
297
+ onMouseEnter={(e) => {
298
+ e.currentTarget.style.color = getVar('--pc-text-primary');
299
+ }}
300
+ onMouseLeave={(e) => {
301
+ e.currentTarget.style.color = getVar('--pc-text-secondary');
302
+ }}
303
+ >
304
+ {{
305
+ asc: <PiCaretUpFill size={14} />,
306
+ desc: <PiCaretDownFill size={14} />,
307
+ }[header.column.getIsSorted() as string] ??
308
+ (header.column.columnDef.header !== '' && (
309
+ <PiCaretDownFill size={14} style={{ opacity: 0.5 }} />
310
+ ))}
311
+ </button>
312
+ )}
313
+ </div>
314
+
315
+ {header.column.getCanResize() && (
316
+ <div
317
+ {...{
318
+ onDoubleClick: () => header.column.resetSize(),
319
+ onMouseDown: header.getResizeHandler(),
320
+ onTouchStart: header.getResizeHandler(),
321
+ }}
322
+ style={{
323
+ position: 'absolute',
324
+ right: 0,
325
+ top: 0,
326
+ height: '100%',
327
+ width: '2px',
328
+ cursor: 'col-resize',
329
+ backgroundColor: getVar('--pc-border-color'),
330
+ display: 'none',
331
+ transition: 'background-color 0.2s ease',
332
+ }}
333
+ onMouseEnter={(e) => {
334
+ e.currentTarget.style.display = 'block';
335
+ e.currentTarget.style.backgroundColor = getVar('--pc-primary');
336
+ }}
337
+ onMouseLeave={(e) => {
338
+ e.currentTarget.style.display = 'none';
339
+ e.currentTarget.style.backgroundColor = getVar('--pc-border-color');
340
+ }}
341
+ />
342
+ )}
343
+ </PCTable.Head>
344
+ );
345
+ })}
346
+ </>
347
+ );
348
+ }
349
+
350
+ // Basic Cell component
351
+ export function TableCellBasic<TData extends Record<string, any>>({
352
+ cell,
353
+ className,
354
+ }: CustomBodyCellProps<TData>) {
355
+ if (!cell) return null;
356
+
357
+ const align = (cell.column.columnDef.meta as TableColumnMeta | undefined)?.align || 'left';
358
+
359
+ return (
360
+ <PCTable.Cell
361
+ className={className}
362
+ style={{ textAlign: align }}
363
+ >
364
+ {flexRender(cell.column.columnDef.cell, cell.getContext())}
365
+ </PCTable.Cell>
366
+ );
367
+ }