@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,167 +1,132 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
- /* eslint-disable @typescript-eslint/no-unnecessary-type-constraint */
3
-
4
- import * as styles from './styles';
5
-
6
- import {
7
- ArrowDownAZIcon,
8
- ArrowUpZAIcon,
9
- ArrowsUpDownIcon,
10
- FilterFullIcon,
11
- FilterIcon,
12
- } from '../../../Icons';
13
- import { MouseEvent, useCallback, useMemo, useRef, useState } from 'react';
14
-
15
- import { DataGridFilterMenu } from './DataGridFilterMenu';
16
- import { DataGridHeaderCellProps } from './types';
17
- import { Dropdown } from '../../layout';
18
- import { IconButton } from '../../forms/IconButton';
19
- import { useDataGridContext } from './hooks';
20
- import { useUi } from '../../../providers';
21
-
22
- export const DataGridHeaderCell = <R,>({
23
- columnKey,
24
- columnIndex,
25
- column,
26
- context,
27
- }: DataGridHeaderCellProps<R>) => {
28
- const { getElementScreenRect } = useUi();
29
- const contextValue = useDataGridContext(context);
30
- const {
31
- filters = {},
32
- sorts = {},
33
- setSorts,
34
- setColumnWidth,
35
- saveSettings,
36
- headerColor,
37
- } = contextValue;
38
- const filterButtonRef = useRef<HTMLButtonElement | null>(null);
39
-
40
- /** SORTING */
41
- const SortIcon = sorts[columnKey]
42
- ? sorts[columnKey] === 'desc'
43
- ? ArrowUpZAIcon
44
- : ArrowDownAZIcon
45
- : ArrowsUpDownIcon;
46
-
47
- const onSortButtonClicked = useCallback(
48
- (columnKey: string) => {
49
- const sort = sorts[columnKey];
50
- if (!sort || sort === 'desc') {
51
- setSorts({ [columnKey]: 'asc' });
52
- } else {
53
- setSorts({ [columnKey]: 'desc' });
54
- }
55
- },
56
- [setSorts, sorts]
57
- );
58
-
59
- /** RESIZING */
60
-
61
- const [isResizing, setIsResizing] = useState(false);
62
- const resizingOffset = useRef(0);
63
-
64
- const onResizeStart = useCallback(
65
- (e: MouseEvent) => {
66
- resizingOffset.current = e.screenX - (column.width || 150);
67
- setIsResizing(true);
68
- },
69
- [column.width]
70
- );
71
-
72
- const onResizeMove = useCallback(
73
- (e: MouseEvent) => {
74
- if (isResizing) {
75
- const newWidth = Math.max(86, e.screenX - resizingOffset.current);
76
- setColumnWidth(columnKey, newWidth);
77
- }
78
- },
79
- [columnKey, isResizing, setColumnWidth]
80
- );
81
-
82
- const onResizeEnd = useCallback(() => {
83
- setIsResizing(false);
84
- saveSettings();
85
- }, [saveSettings]);
86
-
87
- const [isFilterDropdownVisible, setIsFilterDropdownVisible] = useState(false);
88
- const filterDropdown = useMemo(() => {
89
- if (!isFilterDropdownVisible || !filterButtonRef.current || !columnKey) {
90
- return null;
91
- }
92
- const filterButtonRect = getElementScreenRect(filterButtonRef.current);
93
- filterButtonRect.x += window.scrollX;
94
- filterButtonRect.y += window.scrollY;
95
- return (
96
- <Dropdown
97
- $sourceRect={filterButtonRect}
98
- onClose={() => setIsFilterDropdownVisible(false)}
99
- $width={320}
100
- $height={[200, 320]}
101
- $autoPositionX
102
- >
103
- <DataGridFilterMenu
104
- columnKey={columnKey}
105
- columnIndex={columnIndex}
106
- context={context}
107
- onClose={() => setIsFilterDropdownVisible(false)}
108
- />
109
- </Dropdown>
110
- );
111
- }, [
112
- columnIndex,
113
- columnKey,
114
- context,
115
- getElementScreenRect,
116
- isFilterDropdownVisible,
117
- ]);
118
-
119
- const onFilterButtonClicked = useCallback(() => {
120
- setIsFilterDropdownVisible(true);
121
- }, []);
122
-
123
- const hasFilters = filters[columnKey]?.values.length > 0;
124
-
125
- return (
126
- <styles.DataGridHeaderCellContainer
127
- $headerColor={headerColor}
128
- $isResizing={isResizing}
129
- >
130
- {filterDropdown}
131
- <span>{column.name}</span>
132
- {!!column.sortGetter && (
133
- <IconButton
134
- color={headerColor}
135
- size="small"
136
- icon={SortIcon}
137
- onClick={() => onSortButtonClicked?.(columnKey)}
138
- />
139
- )}
140
- {!!column.filter && (
141
- <IconButton
142
- size="small"
143
- className={hasFilters ? 'danger' : ''}
144
- ref={filterButtonRef}
145
- icon={hasFilters ? FilterFullIcon : FilterIcon}
146
- color={hasFilters ? 'danger' : headerColor}
147
- onClick={onFilterButtonClicked}
148
- />
149
- )}
150
- {column.resizable !== false && (
151
- <>
152
- <styles.DataGridResizeGrip
153
- className={isResizing ? 'active' : ''}
154
- $headerColor={headerColor}
155
- onMouseDown={onResizeStart}
156
- />
157
- {isResizing && (
158
- <styles.ResizeBackdrop
159
- onMouseMove={onResizeMove}
160
- onMouseUp={onResizeEnd}
161
- />
162
- )}
163
- </>
164
- )}
165
- </styles.DataGridHeaderCellContainer>
166
- );
167
- };
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ /* eslint-disable @typescript-eslint/no-unnecessary-type-constraint */
3
+
4
+ import * as styles from './styles';
5
+
6
+ import { MouseEvent, useCallback, useMemo, useRef, useState } from 'react';
7
+
8
+ import { ChevronDownIcon } from '../../../Icons';
9
+ import { DataGridFilterMenu } from './DataGridFilterMenu';
10
+ import { DataGridHeaderCellProps } from './types';
11
+ import { Dropdown } from '../../layout';
12
+ import { IconButton } from '../../forms/IconButton';
13
+ import { useDataGridContext } from './hooks';
14
+ import { useUi } from '../../../providers';
15
+
16
+ export const DataGridHeaderCell = <R,>({
17
+ columnKey,
18
+ columnIndex,
19
+ column,
20
+ context,
21
+ }: DataGridHeaderCellProps<R>) => {
22
+ const { getElementScreenRect } = useUi();
23
+ const contextValue = useDataGridContext(context);
24
+ const {
25
+ filters = {},
26
+ setColumnWidth,
27
+ saveSettings,
28
+ headerColor,
29
+ } = contextValue;
30
+ const filterButtonRef = useRef<HTMLButtonElement | null>(null);
31
+
32
+ /** RESIZING */
33
+
34
+ const [isResizing, setIsResizing] = useState(false);
35
+ const resizingOffset = useRef(0);
36
+
37
+ const onResizeStart = useCallback(
38
+ (e: MouseEvent) => {
39
+ resizingOffset.current = e.screenX - (column.width || 150);
40
+ setIsResizing(true);
41
+ },
42
+ [column.width]
43
+ );
44
+
45
+ const onResizeMove = useCallback(
46
+ (e: MouseEvent) => {
47
+ if (isResizing) {
48
+ const newWidth = Math.max(86, e.screenX - resizingOffset.current);
49
+ setColumnWidth(columnKey, newWidth);
50
+ }
51
+ },
52
+ [columnKey, isResizing, setColumnWidth]
53
+ );
54
+
55
+ const onResizeEnd = useCallback(() => {
56
+ setIsResizing(false);
57
+ saveSettings();
58
+ }, [saveSettings]);
59
+
60
+ const [isFilterDropdownVisible, setIsFilterDropdownVisible] = useState(false);
61
+ const filterDropdown = useMemo(() => {
62
+ if (!isFilterDropdownVisible || !filterButtonRef.current || !columnKey) {
63
+ return null;
64
+ }
65
+ const filterButtonRect = getElementScreenRect(filterButtonRef.current);
66
+ filterButtonRect.x += window.scrollX;
67
+ filterButtonRect.y += window.scrollY;
68
+ return (
69
+ <Dropdown
70
+ $sourceRect={filterButtonRect}
71
+ onClose={() => setIsFilterDropdownVisible(false)}
72
+ $width={320}
73
+ $height={[250, 400]}
74
+ $autoPositionX
75
+ >
76
+ <DataGridFilterMenu
77
+ columnKey={columnKey}
78
+ columnIndex={columnIndex}
79
+ context={context}
80
+ onClose={() => setIsFilterDropdownVisible(false)}
81
+ />
82
+ </Dropdown>
83
+ );
84
+ }, [
85
+ columnIndex,
86
+ columnKey,
87
+ context,
88
+ getElementScreenRect,
89
+ isFilterDropdownVisible,
90
+ ]);
91
+
92
+ const onFilterButtonClicked = useCallback(() => {
93
+ setIsFilterDropdownVisible(true);
94
+ }, []);
95
+
96
+ const hasFilters = filters[columnKey]?.values.length > 0;
97
+
98
+ return (
99
+ <styles.DataGridHeaderCellContainer
100
+ $headerColor={headerColor}
101
+ $isResizing={isResizing}
102
+ >
103
+ {filterDropdown}
104
+ <span>{column.name}</span>
105
+ {!!column.filter && (
106
+ <IconButton
107
+ size="small"
108
+ className={hasFilters ? 'danger' : ''}
109
+ ref={filterButtonRef}
110
+ icon={ChevronDownIcon}
111
+ color={hasFilters ? 'danger' : headerColor}
112
+ onClick={onFilterButtonClicked}
113
+ />
114
+ )}
115
+ {column.resizable !== false && (
116
+ <>
117
+ <styles.DataGridResizeGrip
118
+ className={isResizing ? 'active' : ''}
119
+ $headerColor={headerColor}
120
+ onMouseDown={onResizeStart}
121
+ />
122
+ {isResizing && (
123
+ <styles.ResizeBackdrop
124
+ onMouseMove={onResizeMove}
125
+ onMouseUp={onResizeEnd}
126
+ />
127
+ )}
128
+ </>
129
+ )}
130
+ </styles.DataGridHeaderCellContainer>
131
+ );
132
+ };
@@ -1,125 +1,124 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
- /* eslint-disable @typescript-eslint/no-unnecessary-type-constraint */
3
-
4
- import * as styles from './styles';
5
-
6
- import {
7
- DataGridFilter,
8
- DataGridFilterOperator,
9
- DataGridFilterType,
10
- } from '../types';
11
- import { Input, Select } from '../../../forms';
12
- import { useEffect, useRef } from 'react';
13
-
14
- // import { Select } from '../../Select';
15
- // import clx from 'classnames';
16
-
17
- const filterOperators: {
18
- [K in DataGridFilterType]: Partial<{
19
- [K2 in DataGridFilterOperator<K>]: string;
20
- }>;
21
- } = {
22
- number: {
23
- equals: 'Égal à',
24
- notEquals: 'Différent de',
25
- greaterThan: 'Supérieur à',
26
- greaterThanOrEqual: 'Supérieur ou égal à',
27
- lessThan: 'Inférieur à',
28
- lessThanOrEqual: 'Inférieur ou égal à',
29
- inRange: "Dans l'intervalle",
30
- },
31
- text: {
32
- equals: 'Égal à',
33
- notEquals: 'Différent de',
34
- contains: 'Contient',
35
- notContains: 'Ne contient pas',
36
- startsWith: 'Commence par',
37
- endsWith: 'Finit par',
38
- },
39
- };
40
-
41
- type FilterModalContentProps<
42
- R,
43
- T extends DataGridFilterType = DataGridFilterType
44
- > = {
45
- filter: DataGridFilter<R, T>;
46
- onFilterChanged: (filter: DataGridFilter<R, T>) => void;
47
- };
48
-
49
- export const FilterModalContent = <
50
- R,
51
- T extends DataGridFilterType = DataGridFilterType
52
- >({
53
- filter,
54
- onFilterChanged,
55
- }: FilterModalContentProps<R, T>) => {
56
- const value1Ref = useRef<HTMLInputElement>(null);
57
- useEffect(() => {
58
- setTimeout(() => value1Ref.current?.focus(), 100);
59
- }, []);
60
-
61
- if (!filter) return null;
62
-
63
- const { operator, type, values } = filter;
64
- return (
65
- <styles.FilterModalContentContainer>
66
- <label htmlFor="filterOperator">
67
- <span>Opérateur :</span>
68
- <Select
69
- name="filterOperator"
70
- items={Object.entries(filterOperators[filter.type])}
71
- itemKey={0}
72
- itemLabel={1}
73
- value={String(operator)}
74
- className="text-sm"
75
- onChange={(e) =>
76
- onFilterChanged({ ...filter, operator: e.target.value as any })
77
- }
78
- />
79
- </label>
80
- <label htmlFor="filterValue1">
81
- <span>{operator === 'inRange' ? 'Entre' : 'Valeur'} :</span>
82
- <Input
83
- ref={value1Ref}
84
- name="filterValue1"
85
- type={filter.type}
86
- value={values[0] ?? ''}
87
- // className={(type === 'number' ? 'w-24 ' : '') + 'text-sm'}
88
- onChange={(e) => {
89
- const newValues = [...values];
90
- newValues[0] =
91
- type === 'number'
92
- ? Number(e.target.value)
93
- : (String(e.target.value) as any);
94
- onFilterChanged({
95
- ...filter,
96
- values: newValues,
97
- });
98
- }}
99
- />
100
- </label>
101
- {operator === 'inRange' && (
102
- <label htmlFor="filterValue2">
103
- <span>et</span>
104
- <input
105
- name="filterValue2"
106
- type={filter.type}
107
- value={values[1] ?? ''}
108
- // className="text-sm w-24"
109
- onChange={(e) => {
110
- const newValues = [...values];
111
- newValues[0] =
112
- type === 'number'
113
- ? Number(e.target.value)
114
- : (String(e.target.value) as any);
115
- onFilterChanged({
116
- ...filter,
117
- values: newValues,
118
- });
119
- }}
120
- />
121
- </label>
122
- )}
123
- </styles.FilterModalContentContainer>
124
- );
125
- };
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ /* eslint-disable @typescript-eslint/no-unnecessary-type-constraint */
3
+
4
+ import * as styles from './styles';
5
+
6
+ import {
7
+ DataGridFilter,
8
+ DataGridFilterOperator,
9
+ DataGridFilterType,
10
+ } from '../types';
11
+ import { Input, Select } from '../../../forms';
12
+ import { useEffect, useRef } from 'react';
13
+
14
+ // import { Select } from '../../Select';
15
+ // import clx from 'classnames';
16
+
17
+ const filterOperators: {
18
+ [K in DataGridFilterType]: Partial<{
19
+ [K2 in DataGridFilterOperator<K>]: string;
20
+ }>;
21
+ } = {
22
+ number: {
23
+ equals: 'Égal à',
24
+ notEquals: 'Différent de',
25
+ greaterThan: 'Supérieur à',
26
+ greaterThanOrEqual: 'Supérieur ou égal à',
27
+ lessThan: 'Inférieur à',
28
+ lessThanOrEqual: 'Inférieur ou égal à',
29
+ inRange: "Dans l'intervalle",
30
+ },
31
+ text: {
32
+ equals: 'Égal à',
33
+ notEquals: 'Différent de',
34
+ contains: 'Contient',
35
+ notContains: 'Ne contient pas',
36
+ startsWith: 'Commence par',
37
+ endsWith: 'Finit par',
38
+ },
39
+ };
40
+
41
+ type FilterModalContentProps = {
42
+ filter: DataGridFilter;
43
+ onFilterChanged: (filter: DataGridFilter) => void;
44
+ };
45
+
46
+ export const FilterModalContent = ({
47
+ filter,
48
+ onFilterChanged,
49
+ }: FilterModalContentProps) => {
50
+ const value1Ref = useRef<HTMLInputElement>(null);
51
+ useEffect(() => {
52
+ setTimeout(() => value1Ref.current?.focus(), 100);
53
+ }, []);
54
+
55
+ if (!filter) return null;
56
+
57
+ const { operator, type, values } = filter;
58
+ return (
59
+ <styles.FilterModalContentContainer>
60
+ <label htmlFor="filterOperator">
61
+ <span>Opérateur :</span>
62
+ <Select
63
+ name="filterOperator"
64
+ items={Object.entries(filterOperators[filter.type])}
65
+ itemKey={0}
66
+ itemLabel={1}
67
+ value={String(operator)}
68
+ className="text-sm"
69
+ onChange={(e) =>
70
+ onFilterChanged({ ...filter, operator: e.target.value as any })
71
+ }
72
+ />
73
+ </label>
74
+ <label htmlFor="filterValue1">
75
+ <span>{operator === 'inRange' ? 'Entre' : 'Valeur'} :</span>
76
+ <Input
77
+ ref={value1Ref}
78
+ name="filterValue1"
79
+ type={filter.type}
80
+ value={values[0] ?? ''}
81
+ onChange={(e) => {
82
+ if (type === 'number') {
83
+ const newValues = [...values];
84
+ newValues[0] = Number(e.target.value);
85
+ onFilterChanged({
86
+ ...filter,
87
+ values: newValues,
88
+ });
89
+ } else {
90
+ const newValues = [...values];
91
+ newValues[0] = String(e.target.value) as any;
92
+ onFilterChanged({
93
+ ...filter,
94
+ values: newValues,
95
+ });
96
+ }
97
+ }}
98
+ />
99
+ </label>
100
+ {operator === 'inRange' && (
101
+ <label htmlFor="filterValue2">
102
+ <span>et</span>
103
+ <input
104
+ name="filterValue2"
105
+ type={filter.type}
106
+ value={values[1] ?? ''}
107
+ // className="text-sm w-24"
108
+ onChange={(e) => {
109
+ const newValues = [...values];
110
+ newValues[0] =
111
+ type === 'number'
112
+ ? Number(e.target.value)
113
+ : (String(e.target.value) as any);
114
+ onFilterChanged({
115
+ ...filter,
116
+ values: newValues,
117
+ });
118
+ }}
119
+ />
120
+ </label>
121
+ )}
122
+ </styles.FilterModalContentContainer>
123
+ );
124
+ };
@@ -1,22 +1,22 @@
1
- import styled from 'styled-components';
2
-
3
- export const FilterModalContentContainer = styled.div.attrs({
4
- className: 'FilterModalContentContainer',
5
- })`
6
- display: flex;
7
- flex-direction: column;
8
- font-size: var(--text-base);
9
- gap: var(--space-1);
10
-
11
- & > label {
12
- display: flex;
13
- flex-direction: row;
14
- gap: var(--space-1);
15
- align-items: center;
16
-
17
- & > span {
18
- font-weight: bold;
19
- width: var(--space-32);
20
- }
21
- }
22
- `;
1
+ import styled from 'styled-components';
2
+
3
+ export const FilterModalContentContainer = styled.div.attrs({
4
+ className: 'FilterModalContentContainer',
5
+ })`
6
+ display: flex;
7
+ flex-direction: column;
8
+ font-size: var(--text-base);
9
+ gap: var(--space-1);
10
+
11
+ & > label {
12
+ display: flex;
13
+ flex-direction: row;
14
+ gap: var(--space-1);
15
+ align-items: center;
16
+
17
+ & > span {
18
+ font-weight: bold;
19
+ width: var(--space-32);
20
+ }
21
+ }
22
+ `;