@addev-be/ui 0.2.5 → 0.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (166) hide show
  1. package/assets/icons/arrow-down-1-9.svg +1 -0
  2. package/assets/icons/arrow-down-a-z.svg +1 -1
  3. package/assets/icons/arrow-down-big-small.svg +1 -0
  4. package/assets/icons/arrow-up-9-1.svg +1 -0
  5. package/assets/icons/arrow-up-big-small.svg +1 -0
  6. package/assets/icons/arrow-up-z-a.svg +1 -1
  7. package/assets/icons/check.svg +1 -1
  8. package/assets/icons/chevron-down.svg +1 -0
  9. package/assets/icons/down.svg +1 -1
  10. package/assets/icons/ellipsis.svg +1 -0
  11. package/assets/icons/filter-full.svg +1 -1
  12. package/assets/icons/filter.svg +1 -1
  13. package/assets/icons/hashtag.svg +1 -1
  14. package/assets/icons/image-slash.svg +1 -1
  15. package/assets/icons/left.svg +1 -1
  16. package/assets/icons/magnifier.svg +1 -1
  17. package/assets/icons/phone.svg +1 -1
  18. package/assets/icons/right.svg +1 -1
  19. package/assets/icons/sigma.svg +1 -0
  20. package/assets/icons/spinner-third.svg +1 -1
  21. package/assets/icons/table-columns.svg +1 -1
  22. package/assets/icons/table-footer-slash.svg +5 -0
  23. package/assets/icons/table-footer.svg +4 -0
  24. package/assets/icons/table.svg +1 -0
  25. package/assets/icons/tally.svg +1 -0
  26. package/assets/icons/up.svg +1 -1
  27. package/assets/icons/user-tie.svg +1 -1
  28. package/assets/icons/x-bar.svg +4 -0
  29. package/dist/Icons.d.ts +13 -1
  30. package/dist/Icons.js +25 -1
  31. package/dist/components/data/AdvancedRequestDataGrid/index.js +3 -3
  32. package/dist/components/data/DataGrid/AdvancedRequestDataGrid.d.ts +1 -2
  33. package/dist/components/data/DataGrid/AdvancedRequestDataGrid.js +3 -5
  34. package/dist/components/data/DataGrid/DataGridCell.d.ts +1 -1
  35. package/dist/components/data/DataGrid/DataGridCell.js +5 -5
  36. package/dist/components/data/DataGrid/DataGridColumnsModal/hooks.js +2 -1
  37. package/dist/components/data/DataGrid/DataGridEditableCell.js +2 -7
  38. package/dist/components/data/DataGrid/DataGridFilterMenu/index.js +90 -10
  39. package/dist/components/data/DataGrid/DataGridFilterMenu/styles.d.ts +3 -9
  40. package/dist/components/data/DataGrid/DataGridFilterMenu/styles.js +10 -37
  41. package/dist/components/data/DataGrid/DataGridFooter.d.ts +1 -1
  42. package/dist/components/data/DataGrid/DataGridFooter.js +35 -22
  43. package/dist/components/data/DataGrid/DataGridHeader.js +1 -3
  44. package/dist/components/data/DataGrid/DataGridHeaderCell.js +8 -23
  45. package/dist/components/data/DataGrid/FilterModalContent/index.d.ts +5 -5
  46. package/dist/components/data/DataGrid/FilterModalContent/index.js +11 -9
  47. package/dist/components/data/DataGrid/FilterValuesScroller.d.ts +8 -7
  48. package/dist/components/data/DataGrid/FilterValuesScroller.js +5 -6
  49. package/dist/components/data/DataGrid/helpers/columns.d.ts +1 -1
  50. package/dist/components/data/DataGrid/helpers/columns.js +72 -20
  51. package/dist/components/data/DataGrid/helpers/filters.d.ts +4 -3
  52. package/dist/components/data/DataGrid/helpers/filters.js +13 -5
  53. package/dist/components/data/DataGrid/hooks/useDataGrid.d.ts +1 -1
  54. package/dist/components/data/DataGrid/hooks/useDataGrid.js +60 -30
  55. package/dist/components/data/DataGrid/hooks/useDataGridCopy.d.ts +2 -2
  56. package/dist/components/data/DataGrid/hooks/useDataGridCopy.js +41 -40
  57. package/dist/components/data/DataGrid/hooks/useDataGridSettings.js +0 -1
  58. package/dist/components/data/DataGrid/index.d.ts +4 -2
  59. package/dist/components/data/DataGrid/index.js +38 -17
  60. package/dist/components/data/DataGrid/styles.d.ts +12 -5
  61. package/dist/components/data/DataGrid/styles.js +31 -18
  62. package/dist/components/data/DataGrid/types.d.ts +28 -16
  63. package/dist/components/data/SqlRequestDataGrid/helpers/columns.d.ts +1 -1
  64. package/dist/components/data/SqlRequestDataGrid/helpers/columns.js +30 -19
  65. package/dist/components/data/SqlRequestDataGrid/index.js +125 -37
  66. package/dist/components/data/SqlRequestDataGrid/types.d.ts +1 -0
  67. package/dist/components/data/index.d.ts +2 -0
  68. package/dist/components/data/index.js +2 -0
  69. package/dist/components/ui/ContextMenu/index.d.ts +11 -0
  70. package/dist/components/ui/ContextMenu/index.js +58 -0
  71. package/dist/components/ui/ContextMenu/styles.d.ts +18 -0
  72. package/dist/components/ui/ContextMenu/styles.js +56 -0
  73. package/dist/helpers/dates.d.ts +2 -0
  74. package/dist/helpers/dates.js +13 -0
  75. package/dist/services/advancedRequests.d.ts +1 -1
  76. package/dist/services/sqlRequests.d.ts +9 -4
  77. package/dist/services/sqlRequests.js +1 -0
  78. package/package.json +1 -1
  79. package/src/Icons.tsx +104 -80
  80. package/src/components/data/AdvancedRequestDataGrid/helpers/advancedRequests.ts +93 -93
  81. package/src/components/data/AdvancedRequestDataGrid/helpers/columns.tsx +262 -262
  82. package/src/components/data/AdvancedRequestDataGrid/helpers/index.ts +2 -2
  83. package/src/components/data/AdvancedRequestDataGrid/index.tsx +267 -269
  84. package/src/components/data/AdvancedRequestDataGrid/types.ts +47 -47
  85. package/src/components/data/DataGrid/DataGridCell.tsx +73 -73
  86. package/src/components/data/DataGrid/DataGridColumnsModal/helpers.ts +14 -14
  87. package/src/components/data/DataGrid/DataGridColumnsModal/hooks.tsx +59 -58
  88. package/src/components/data/DataGrid/DataGridColumnsModal/index.tsx +181 -181
  89. package/src/components/data/DataGrid/DataGridColumnsModal/styles.ts +104 -104
  90. package/src/components/data/DataGrid/DataGridEditableCell.tsx +43 -54
  91. package/src/components/data/DataGrid/DataGridFilterMenu/hooks.tsx +75 -75
  92. package/src/components/data/DataGrid/DataGridFilterMenu/index.tsx +364 -190
  93. package/src/components/data/DataGrid/DataGridFilterMenu/styles.ts +49 -100
  94. package/src/components/data/DataGrid/DataGridFooter.tsx +42 -64
  95. package/src/components/data/DataGrid/DataGridHeader.tsx +126 -126
  96. package/src/components/data/DataGrid/DataGridHeaderCell.tsx +132 -167
  97. package/src/components/data/DataGrid/FilterModalContent/index.tsx +124 -125
  98. package/src/components/data/DataGrid/FilterModalContent/styles.ts +22 -22
  99. package/src/components/data/DataGrid/FilterValuesScroller.tsx +133 -131
  100. package/src/components/data/DataGrid/VirtualScroller.tsx +46 -46
  101. package/src/components/data/DataGrid/helpers/columns.tsx +287 -196
  102. package/src/components/data/DataGrid/helpers/filters.ts +220 -207
  103. package/src/components/data/DataGrid/helpers/index.ts +2 -2
  104. package/src/components/data/DataGrid/hooks/index.ts +30 -30
  105. package/src/components/data/DataGrid/hooks/useDataGrid.tsx +305 -264
  106. package/src/components/data/DataGrid/hooks/useDataGridCopy.ts +170 -165
  107. package/src/components/data/DataGrid/hooks/useDataGridSettings.ts +48 -48
  108. package/src/components/data/DataGrid/index.tsx +139 -132
  109. package/src/components/data/DataGrid/styles.ts +347 -326
  110. package/src/components/data/DataGrid/types.ts +260 -240
  111. package/src/components/data/SqlRequestDataGrid/helpers/columns.tsx +259 -224
  112. package/src/components/data/SqlRequestDataGrid/helpers/index.ts +2 -2
  113. package/src/components/data/SqlRequestDataGrid/helpers/sqlRequests.ts +16 -16
  114. package/src/components/data/SqlRequestDataGrid/index.tsx +347 -252
  115. package/src/components/data/SqlRequestDataGrid/types.ts +47 -47
  116. package/src/components/data/index.ts +8 -8
  117. package/src/components/forms/Button.tsx +99 -99
  118. package/src/components/forms/IconButton.tsx +56 -56
  119. package/src/components/forms/IndeterminateCheckbox.tsx +46 -46
  120. package/src/components/forms/Select.tsx +40 -40
  121. package/src/components/forms/index.ts +5 -5
  122. package/src/components/forms/styles.ts +20 -20
  123. package/src/components/index.ts +3 -3
  124. package/src/components/layout/Dropdown/index.tsx +79 -79
  125. package/src/components/layout/Dropdown/styles.ts +44 -44
  126. package/src/components/layout/Loading/index.tsx +29 -29
  127. package/src/components/layout/Loading/styles.ts +29 -29
  128. package/src/components/layout/Modal/index.tsx +51 -51
  129. package/src/components/layout/Modal/styles.ts +110 -110
  130. package/src/components/layout/index.ts +3 -3
  131. package/src/components/ui/ContextMenu/index.tsx +73 -0
  132. package/src/components/ui/ContextMenu/styles.ts +115 -0
  133. package/src/config/index.ts +14 -14
  134. package/src/helpers/dates.ts +9 -9
  135. package/src/helpers/getScrollbarSize.ts +14 -14
  136. package/src/helpers/numbers.ts +20 -20
  137. package/src/hooks/index.ts +2 -2
  138. package/src/hooks/useElementSize.ts +24 -24
  139. package/src/hooks/useWindowSize.ts +20 -20
  140. package/src/index.ts +7 -7
  141. package/src/providers/PortalsProvider/index.tsx +54 -54
  142. package/src/providers/PortalsProvider/styles.ts +27 -27
  143. package/src/providers/SettingsProvider/index.tsx +70 -70
  144. package/src/providers/ThemeProvider/ThemeProvider.ts +55 -55
  145. package/src/providers/ThemeProvider/defaultTheme.ts +444 -444
  146. package/src/providers/ThemeProvider/index.ts +3 -3
  147. package/src/providers/ThemeProvider/types.ts +123 -123
  148. package/src/providers/UiProviders/index.tsx +65 -65
  149. package/src/providers/UiProviders/styles.ts +10 -10
  150. package/src/providers/hooks.ts +8 -8
  151. package/src/providers/index.ts +5 -5
  152. package/src/services/HttpService.ts +80 -80
  153. package/src/services/WebSocketService.ts +147 -147
  154. package/src/services/advancedRequests.ts +101 -101
  155. package/src/services/base.ts +31 -31
  156. package/src/services/hooks.ts +23 -23
  157. package/src/services/index.ts +2 -2
  158. package/src/services/sqlRequests.ts +110 -99
  159. package/src/styles/animations.scss +30 -30
  160. package/src/styles/index.scss +42 -42
  161. package/src/typings.d.ts +6 -6
  162. package/tsconfig.tsbuildinfo +1 -1
  163. package/dist/components/data/DataGrid/helpers.d.ts +0 -28
  164. package/dist/components/data/DataGrid/helpers.js +0 -436
  165. package/dist/config/types.d.ts +0 -11
  166. package/dist/config/types.js +0 -2
@@ -1,196 +1,287 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
-
3
- import { DataGridColumn, DataGridColumns, DataGridSettings } from '../types';
4
- import {
5
- formatMoney,
6
- formatNumber,
7
- formatPercentage,
8
- } from '../../../../helpers/numbers';
9
- import { numberFilter, textFilter } from './filters';
10
-
11
- import moment from 'moment';
12
-
13
- export const isColumnVisible = <R,>(
14
- obj: DataGridColumn<R> | DataGridSettings
15
- ): boolean => obj?.order !== -1;
16
-
17
- export const textColumn = <R extends Record<string, any>>(
18
- key: string,
19
- title: string,
20
- options?: Partial<DataGridColumn<R>>
21
- ): DataGridColumns<R> => ({
22
- [key]: {
23
- name: title,
24
- render: (row) => row[key] ?? '',
25
- getter: (row) => row[key] ?? '',
26
- sortGetter: (row) => row[key] ?? '',
27
- filter: textFilter(key),
28
- ...options,
29
- },
30
- });
31
-
32
- export const mailColumn = <R extends Record<string, any>>(
33
- key: string,
34
- title: string,
35
- options?: Partial<DataGridColumn<R>>
36
- ): DataGridColumns<R> => ({
37
- [key]: {
38
- name: title,
39
- render: (row) => (
40
- <a
41
- // className="text-blue-500 hover:text-blue-700"
42
- href={`mailto:${row[key]}`}
43
- >
44
- {row[key] ?? ''}
45
- </a>
46
- ),
47
- getter: (row) => row[key] ?? '',
48
- sortGetter: (row) => row[key] ?? '',
49
- filter: textFilter(key),
50
- ...options,
51
- },
52
- });
53
-
54
- export const phoneColumn = <R extends Record<string, any>>(
55
- key: string,
56
- title: string,
57
- options?: Partial<DataGridColumn<R>>
58
- ): DataGridColumns<R> => ({
59
- [key]: {
60
- name: title,
61
- render: (row) => (
62
- <a
63
- // className="text-blue-500 hover:text-blue-700"
64
- href={`tel:${row[key]}`}
65
- >
66
- {row[key] ?? ''}
67
- </a>
68
- ),
69
- getter: (row) => row[key] ?? '',
70
- sortGetter: (row) => row[key] ?? '',
71
- filter: textFilter(key),
72
- ...options,
73
- },
74
- });
75
-
76
- export const dateColumn = <R extends Record<string, any>>(
77
- key: string,
78
- title: string,
79
- options?: Partial<DataGridColumn<R>>
80
- ): DataGridColumns<R> => ({
81
- [key]: {
82
- name: title,
83
- render: (row) => moment(row[key]).format('DD/MM/YYYY') ?? '',
84
- getter: (row) => row[key] ?? '',
85
- sortGetter: (row) => row[key] ?? '',
86
- filter: textFilter(key),
87
- ...options,
88
- },
89
- });
90
-
91
- export const monthColumn = <R extends Record<string, any>>(
92
- key: string,
93
- title: string,
94
- options?: Partial<DataGridColumn<R>>
95
- ): DataGridColumns<R> => ({
96
- [key]: {
97
- name: title,
98
- render: (row) => (row[key] ? `${row[key]} mois ` : ''),
99
- getter: (row) => row[key] ?? '',
100
- sortGetter: (row) => row[key] ?? '',
101
- filter: textFilter(key),
102
- ...options,
103
- },
104
- });
105
-
106
- export const numberColumn = <R extends Record<string, any>>(
107
- key: string,
108
- title: string,
109
- decimals = 2,
110
- options?: Partial<DataGridColumn<R>>
111
- ): DataGridColumns<R> => ({
112
- [key]: {
113
- name: title,
114
- render: (row) => formatNumber(row[key], decimals) ?? '',
115
- excelFormatter: () => '#',
116
- getter: (row) => row[key] ?? '',
117
- sortGetter: (row) => row[key] ?? '',
118
- filter: {
119
- type: 'number',
120
- operator: 'equals',
121
- values: [0],
122
- getter: (value) => value ?? 0,
123
- },
124
- ...options,
125
- },
126
- });
127
-
128
- export const moneyColumn = <R extends Record<string, any>>(
129
- key: string,
130
- title: string,
131
- decimals = 2,
132
- options?: Partial<DataGridColumn<R>>
133
- ): DataGridColumns<R> => ({
134
- [key]: {
135
- name: title,
136
- render: (row) => formatMoney(row[key], decimals) ?? '',
137
- excelFormatter: () => '#0.00',
138
- getter: (row) => row[key] ?? '',
139
- sortGetter: (row) => row[key] ?? '',
140
- filter: numberFilter(key),
141
- ...options,
142
- },
143
- });
144
-
145
- export const percentageColumn = <R extends Record<string, any>>(
146
- key: string,
147
- title: string,
148
- options?: Partial<DataGridColumn<R>>
149
- ): DataGridColumns<R> => ({
150
- [key]: {
151
- name: title,
152
- render: (row) => formatPercentage(row[key]) ?? '',
153
- excelFormatter: () => '#0.00',
154
- getter: (row) => row[key] ?? '',
155
- sortGetter: (row) => row[key] ?? '',
156
- filter: numberFilter(key),
157
- ...options,
158
- },
159
- });
160
-
161
- export const checkboxColumn = <R extends Record<string, any>>(
162
- key: string,
163
- title: string,
164
- options?: Partial<DataGridColumn<R>>
165
- ): DataGridColumns<R> => ({
166
- [key]: {
167
- name: title,
168
- render: (row) => (
169
- <>
170
- <input type="checkbox" checked={row[key]} />
171
- <span>{row[key] ? ' Oui' : ' Non'}</span>
172
- </>
173
- ),
174
- getter: (row) => row[key] ?? '',
175
- sortGetter: (row) => row[key] ?? '',
176
- filter: numberFilter(key),
177
- ...options,
178
- },
179
- });
180
-
181
- export const colorColumn = <R extends Record<string, any>>(
182
- key: string,
183
- title: string,
184
- options?: Partial<DataGridColumn<R>>
185
- ): DataGridColumns<R> => ({
186
- [key]: {
187
- name: title,
188
- render: (row) => (
189
- <div style={{ backgroundColor: row[key] }}>{row[key] ?? ''}</div>
190
- ),
191
- getter: (row) => row[key] ?? '',
192
- sortGetter: (row) => row[key] ?? '',
193
- filter: textFilter(key),
194
- ...options,
195
- },
196
- });
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+
3
+ import { DataGridColumn, DataGridColumns, DataGridSettings } from '../types';
4
+ import {
5
+ formatMoney,
6
+ formatNumber,
7
+ formatPercentage,
8
+ } from '../../../../helpers/numbers';
9
+ import { numberFilter, textFilter } from './filters';
10
+
11
+ import moment from 'moment';
12
+ import { repeat } from 'lodash';
13
+
14
+ export const isColumnVisible = <R,>(
15
+ obj: DataGridColumn<R> | DataGridSettings
16
+ ): boolean => obj?.order !== -1;
17
+
18
+ const buildExcelFormat = (decimals = 2, suffix = '') =>
19
+ `#0${decimals > 0 ? `.${repeat('0', decimals)}` : ''}${suffix}`;
20
+
21
+ export const textColumn = <R extends Record<string, any>>(
22
+ key: string,
23
+ title: string,
24
+ options?: Partial<DataGridColumn<R>>
25
+ ): DataGridColumns<R> => ({
26
+ [key]: {
27
+ name: title,
28
+ render: (row) => row[key] ?? '',
29
+ getter: (row) => row[key] ?? '',
30
+ sortGetter: (row) => row[key] ?? '',
31
+ footer: (_, filteredRows) => `${filteredRows.length} éléments`,
32
+ filter: textFilter(key),
33
+ ...options,
34
+ },
35
+ });
36
+
37
+ export const mailColumn = <R extends Record<string, any>>(
38
+ key: string,
39
+ title: string,
40
+ options?: Partial<DataGridColumn<R>>
41
+ ): DataGridColumns<R> => ({
42
+ [key]: {
43
+ name: title,
44
+ render: (row) => (
45
+ <a
46
+ // className="text-blue-500 hover:text-blue-700"
47
+ href={`mailto:${row[key]}`}
48
+ >
49
+ {row[key] ?? ''}
50
+ </a>
51
+ ),
52
+ getter: (row) => row[key] ?? '',
53
+ sortGetter: (row) => row[key] ?? '',
54
+ footer: (_, filteredRows) => `${filteredRows.length} éléments`,
55
+ filter: textFilter(key),
56
+ ...options,
57
+ },
58
+ });
59
+
60
+ export const phoneColumn = <R extends Record<string, any>>(
61
+ key: string,
62
+ title: string,
63
+ options?: Partial<DataGridColumn<R>>
64
+ ): DataGridColumns<R> => ({
65
+ [key]: {
66
+ name: title,
67
+ render: (row) => (
68
+ <a
69
+ // className="text-blue-500 hover:text-blue-700"
70
+ href={`tel:${row[key]}`}
71
+ >
72
+ {row[key] ?? ''}
73
+ </a>
74
+ ),
75
+ getter: (row) => row[key] ?? '',
76
+ sortGetter: (row) => row[key] ?? '',
77
+ footer: (_, filteredRows) => `${filteredRows.length} éléments`,
78
+ filter: textFilter(key),
79
+ ...options,
80
+ },
81
+ });
82
+
83
+ export const dateColumn = <R extends Record<string, any>>(
84
+ key: string,
85
+ title: string,
86
+ options?: Partial<DataGridColumn<R>>
87
+ ): DataGridColumns<R> => ({
88
+ [key]: {
89
+ name: title,
90
+ render: (row) => moment(row[key]).format('DD/MM/YYYY') ?? '',
91
+ getter: (row) => row[key] ?? '',
92
+ sortGetter: (row) => row[key] ?? '',
93
+ footer: (_, filteredRows) => `${filteredRows.length} éléments`,
94
+ filter: textFilter(key),
95
+ ...options,
96
+ },
97
+ });
98
+
99
+ export const monthColumn = <R extends Record<string, any>>(
100
+ key: string,
101
+ title: string,
102
+ options?: Partial<DataGridColumn<R>>
103
+ ): DataGridColumns<R> => ({
104
+ [key]: {
105
+ name: title,
106
+ render: (row) => (row[key] ? `${row[key]} mois ` : ''),
107
+ getter: (row) => row[key] ?? '',
108
+ sortGetter: (row) => row[key] ?? '',
109
+ footer: (_, filteredRows) => `${filteredRows.length} éléments`,
110
+ filter: textFilter(key),
111
+ ...options,
112
+ },
113
+ });
114
+
115
+ export const numberColumn = <R extends Record<string, any>>(
116
+ key: string,
117
+ title: string,
118
+ decimals = 2,
119
+ options?: Partial<DataGridColumn<R>>
120
+ ): DataGridColumns<R> => ({
121
+ [key]: {
122
+ name: title,
123
+ render: (row) => formatNumber(row[key], decimals) ?? '',
124
+ excelFormatter: () => '#',
125
+ getter: (row) => row[key] ?? '',
126
+ sortGetter: (row) => row[key] ?? '',
127
+ footer: {
128
+ sum: (_, filteredRows) =>
129
+ formatNumber(
130
+ filteredRows.reduce((acc, row) => acc + (row[key] ?? 0), 0),
131
+ decimals
132
+ ),
133
+ average: (_, filteredRows) =>
134
+ formatNumber(
135
+ filteredRows.reduce((acc, row) => acc + (row[key] ?? 0), 0) /
136
+ (filteredRows.length || 1),
137
+ decimals
138
+ ),
139
+ count: (_, filteredRows) => `${filteredRows.length} éléments`,
140
+ max: (_, filteredRows) =>
141
+ formatNumber(
142
+ Math.max(...filteredRows.map((row) => row[key] ?? 0)),
143
+ decimals
144
+ ),
145
+ min: (_, filteredRows) =>
146
+ formatNumber(
147
+ Math.min(...filteredRows.map((row) => row[key] ?? 0)),
148
+ decimals
149
+ ),
150
+ },
151
+ filter: {
152
+ ...numberFilter(key),
153
+ renderer: (value) => formatNumber(value, decimals) ?? '',
154
+ },
155
+ ...options,
156
+ },
157
+ });
158
+
159
+ export const moneyColumn = <R extends Record<string, any>>(
160
+ key: string,
161
+ title: string,
162
+ decimals = 2,
163
+ options?: Partial<DataGridColumn<R>>
164
+ ): DataGridColumns<R> => ({
165
+ [key]: {
166
+ name: title,
167
+ render: (row) => formatMoney(row[key], decimals) ?? '',
168
+ excelFormatter: () => buildExcelFormat(decimals, ' €'),
169
+ getter: (row) => row[key] ?? '',
170
+ sortGetter: (row) => row[key] ?? '',
171
+ filter: {
172
+ ...numberFilter(key),
173
+ renderer: (value) => formatMoney(value, decimals) ?? '',
174
+ },
175
+ footer: {
176
+ sum: (_, filteredRows) =>
177
+ formatMoney(
178
+ filteredRows.reduce((acc, row) => acc + (row[key] ?? 0), 0),
179
+ decimals
180
+ ),
181
+ average: (_, filteredRows) =>
182
+ formatMoney(
183
+ filteredRows.reduce((acc, row) => acc + (row[key] ?? 0), 0) /
184
+ (filteredRows.length || 1),
185
+ decimals
186
+ ),
187
+ count: (_, filteredRows) => `${filteredRows.length} éléments`,
188
+ max: (_, filteredRows) =>
189
+ formatMoney(
190
+ Math.max(...filteredRows.map((row) => row[key] ?? 0)),
191
+ decimals
192
+ ),
193
+ min: (_, filteredRows) =>
194
+ formatMoney(
195
+ Math.min(...filteredRows.map((row) => row[key] ?? 0)),
196
+ decimals
197
+ ),
198
+ },
199
+ ...options,
200
+ },
201
+ });
202
+
203
+ export const percentageColumn = <R extends Record<string, any>>(
204
+ key: string,
205
+ title: string,
206
+ decimals = 2,
207
+ options?: Partial<DataGridColumn<R>>
208
+ ): DataGridColumns<R> => ({
209
+ [key]: {
210
+ name: title,
211
+ render: (row) => formatPercentage(row[key]) ?? '',
212
+ excelFormatter: () => buildExcelFormat(decimals),
213
+ getter: (row) => row[key] ?? '',
214
+ sortGetter: (row) => row[key] ?? '',
215
+ filter: numberFilter(key),
216
+ footer: {
217
+ average: (_, filteredRows) =>
218
+ formatNumber(
219
+ filteredRows.reduce((acc, row) => acc + (row[key] ?? 0), 0) /
220
+ (filteredRows.length || 1),
221
+ decimals
222
+ ),
223
+ count: (_, filteredRows) => `${filteredRows.length} éléments`,
224
+ max: (_, filteredRows) =>
225
+ formatNumber(
226
+ Math.max(...filteredRows.map((row) => row[key] ?? 0)),
227
+ decimals
228
+ ),
229
+ min: (_, filteredRows) =>
230
+ formatNumber(
231
+ Math.min(...filteredRows.map((row) => row[key] ?? 0)),
232
+ decimals
233
+ ),
234
+ sum: (_, filteredRows) =>
235
+ formatNumber(
236
+ filteredRows.reduce((acc, row) => acc + (row[key] ?? 0), 0),
237
+ decimals
238
+ ),
239
+ },
240
+ ...options,
241
+ },
242
+ });
243
+
244
+ export const checkboxColumn = <R extends Record<string, any>>(
245
+ key: string,
246
+ title: string,
247
+ options?: Partial<DataGridColumn<R>>
248
+ ): DataGridColumns<R> => ({
249
+ [key]: {
250
+ name: title,
251
+ render: (row) => (
252
+ <>
253
+ <input type="checkbox" checked={row[key]} />
254
+ <span>{row[key] ? ' Oui' : ' Non'}</span>
255
+ </>
256
+ ),
257
+ getter: (row) => row[key] ?? '',
258
+ sortGetter: (row) => row[key] ?? '',
259
+ filter: numberFilter(key),
260
+ footer: {
261
+ count: (_, filteredRows) => `${filteredRows.length} éléments`,
262
+ checked: (_, filteredRows) =>
263
+ `${filteredRows.filter((row) => !!row[key]).length} cochés`,
264
+ unchecked: (_, filteredRows) =>
265
+ `${filteredRows.filter((row) => !row[key]).length} décochés`,
266
+ },
267
+ ...options,
268
+ },
269
+ });
270
+
271
+ export const colorColumn = <R extends Record<string, any>>(
272
+ key: string,
273
+ title: string,
274
+ options?: Partial<DataGridColumn<R>>
275
+ ): DataGridColumns<R> => ({
276
+ [key]: {
277
+ name: title,
278
+ render: (row) => (
279
+ <div style={{ backgroundColor: row[key] }}>{row[key] ?? ''}</div>
280
+ ),
281
+ getter: (row) => row[key] ?? '',
282
+ sortGetter: (row) => row[key] ?? '',
283
+ filter: textFilter(key),
284
+ footer: (rows) => `${rows.length} éléments`,
285
+ ...options,
286
+ },
287
+ });