@addev-be/ui 0.2.5 → 0.2.6

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 (133) hide show
  1. package/assets/icons/arrow-down-a-z.svg +1 -1
  2. package/assets/icons/arrow-up-z-a.svg +1 -1
  3. package/assets/icons/check.svg +1 -1
  4. package/assets/icons/down.svg +1 -1
  5. package/assets/icons/filter-full.svg +1 -1
  6. package/assets/icons/filter.svg +1 -1
  7. package/assets/icons/hashtag.svg +1 -1
  8. package/assets/icons/image-slash.svg +1 -1
  9. package/assets/icons/left.svg +1 -1
  10. package/assets/icons/magnifier.svg +1 -1
  11. package/assets/icons/phone.svg +1 -1
  12. package/assets/icons/right.svg +1 -1
  13. package/assets/icons/spinner-third.svg +1 -1
  14. package/assets/icons/table-columns.svg +1 -1
  15. package/assets/icons/up.svg +1 -1
  16. package/assets/icons/user-tie.svg +1 -1
  17. package/dist/components/data/DataGrid/AdvancedRequestDataGrid.d.ts +1 -2
  18. package/dist/components/data/DataGrid/AdvancedRequestDataGrid.js +3 -5
  19. package/dist/components/data/DataGrid/DataGridCell.d.ts +1 -1
  20. package/dist/components/data/DataGrid/DataGridCell.js +5 -5
  21. package/dist/components/data/DataGrid/DataGridEditableCell.js +2 -7
  22. package/dist/components/data/DataGrid/DataGridFilterMenu/index.js +10 -8
  23. package/dist/components/data/DataGrid/DataGridFooter.js +4 -14
  24. package/dist/components/data/DataGrid/DataGridHeader.js +1 -3
  25. package/dist/components/data/DataGrid/DataGridHeaderCell.js +6 -5
  26. package/dist/components/data/DataGrid/FilterModalContent/index.d.ts +5 -5
  27. package/dist/components/data/DataGrid/FilterModalContent/index.js +11 -9
  28. package/dist/components/data/DataGrid/FilterValuesScroller.d.ts +8 -7
  29. package/dist/components/data/DataGrid/FilterValuesScroller.js +5 -6
  30. package/dist/components/data/DataGrid/helpers/columns.js +1 -4
  31. package/dist/components/data/DataGrid/helpers/filters.d.ts +4 -3
  32. package/dist/components/data/DataGrid/helpers/filters.js +13 -5
  33. package/dist/components/data/DataGrid/hooks/useDataGrid.js +2 -2
  34. package/dist/components/data/DataGrid/hooks/useDataGridCopy.js +0 -1
  35. package/dist/components/data/DataGrid/hooks/useDataGridSettings.js +0 -1
  36. package/dist/components/data/DataGrid/index.js +16 -5
  37. package/dist/components/data/DataGrid/styles.d.ts +4 -1
  38. package/dist/components/data/DataGrid/styles.js +11 -8
  39. package/dist/components/data/DataGrid/types.d.ts +20 -15
  40. package/dist/components/data/SqlRequestDataGrid/helpers/columns.js +7 -9
  41. package/dist/components/data/SqlRequestDataGrid/index.js +34 -18
  42. package/dist/components/data/SqlRequestDataGrid/types.d.ts +1 -0
  43. package/dist/components/data/index.d.ts +2 -0
  44. package/dist/components/data/index.js +2 -0
  45. package/dist/helpers/dates.d.ts +2 -0
  46. package/dist/helpers/dates.js +13 -0
  47. package/package.json +1 -1
  48. package/src/Icons.tsx +80 -80
  49. package/src/components/data/AdvancedRequestDataGrid/helpers/advancedRequests.ts +93 -93
  50. package/src/components/data/AdvancedRequestDataGrid/helpers/columns.tsx +262 -262
  51. package/src/components/data/AdvancedRequestDataGrid/helpers/index.ts +2 -2
  52. package/src/components/data/AdvancedRequestDataGrid/index.tsx +269 -269
  53. package/src/components/data/AdvancedRequestDataGrid/types.ts +47 -47
  54. package/src/components/data/DataGrid/DataGridCell.tsx +73 -73
  55. package/src/components/data/DataGrid/DataGridColumnsModal/helpers.ts +14 -14
  56. package/src/components/data/DataGrid/DataGridColumnsModal/hooks.tsx +58 -58
  57. package/src/components/data/DataGrid/DataGridColumnsModal/index.tsx +181 -181
  58. package/src/components/data/DataGrid/DataGridColumnsModal/styles.ts +104 -104
  59. package/src/components/data/DataGrid/DataGridEditableCell.tsx +43 -54
  60. package/src/components/data/DataGrid/DataGridFilterMenu/hooks.tsx +75 -75
  61. package/src/components/data/DataGrid/DataGridFilterMenu/index.tsx +200 -190
  62. package/src/components/data/DataGrid/DataGridFilterMenu/styles.ts +100 -100
  63. package/src/components/data/DataGrid/DataGridFooter.tsx +44 -64
  64. package/src/components/data/DataGrid/DataGridHeader.tsx +126 -126
  65. package/src/components/data/DataGrid/DataGridHeaderCell.tsx +167 -167
  66. package/src/components/data/DataGrid/FilterModalContent/index.tsx +124 -125
  67. package/src/components/data/DataGrid/FilterModalContent/styles.ts +22 -22
  68. package/src/components/data/DataGrid/FilterValuesScroller.tsx +133 -131
  69. package/src/components/data/DataGrid/VirtualScroller.tsx +46 -46
  70. package/src/components/data/DataGrid/helpers/columns.tsx +196 -196
  71. package/src/components/data/DataGrid/helpers/filters.ts +220 -207
  72. package/src/components/data/DataGrid/helpers/index.ts +2 -2
  73. package/src/components/data/DataGrid/hooks/index.ts +30 -30
  74. package/src/components/data/DataGrid/hooks/useDataGrid.tsx +264 -264
  75. package/src/components/data/DataGrid/hooks/useDataGridCopy.ts +165 -165
  76. package/src/components/data/DataGrid/hooks/useDataGridSettings.ts +48 -48
  77. package/src/components/data/DataGrid/index.tsx +132 -132
  78. package/src/components/data/DataGrid/styles.ts +326 -326
  79. package/src/components/data/DataGrid/types.ts +241 -240
  80. package/src/components/data/SqlRequestDataGrid/helpers/columns.tsx +224 -224
  81. package/src/components/data/SqlRequestDataGrid/helpers/index.ts +2 -2
  82. package/src/components/data/SqlRequestDataGrid/helpers/sqlRequests.ts +16 -16
  83. package/src/components/data/SqlRequestDataGrid/index.tsx +252 -252
  84. package/src/components/data/SqlRequestDataGrid/types.ts +47 -47
  85. package/src/components/data/index.ts +8 -8
  86. package/src/components/forms/Button.tsx +99 -99
  87. package/src/components/forms/IconButton.tsx +56 -56
  88. package/src/components/forms/IndeterminateCheckbox.tsx +46 -46
  89. package/src/components/forms/Select.tsx +40 -40
  90. package/src/components/forms/index.ts +5 -5
  91. package/src/components/forms/styles.ts +20 -20
  92. package/src/components/index.ts +3 -3
  93. package/src/components/layout/Dropdown/index.tsx +79 -79
  94. package/src/components/layout/Dropdown/styles.ts +44 -44
  95. package/src/components/layout/Loading/index.tsx +29 -29
  96. package/src/components/layout/Loading/styles.ts +29 -29
  97. package/src/components/layout/Modal/index.tsx +51 -51
  98. package/src/components/layout/Modal/styles.ts +110 -110
  99. package/src/components/layout/index.ts +3 -3
  100. package/src/config/index.ts +14 -14
  101. package/src/helpers/dates.ts +9 -9
  102. package/src/helpers/getScrollbarSize.ts +14 -14
  103. package/src/helpers/numbers.ts +20 -20
  104. package/src/hooks/index.ts +2 -2
  105. package/src/hooks/useElementSize.ts +24 -24
  106. package/src/hooks/useWindowSize.ts +20 -20
  107. package/src/index.ts +7 -7
  108. package/src/providers/PortalsProvider/index.tsx +54 -54
  109. package/src/providers/PortalsProvider/styles.ts +27 -27
  110. package/src/providers/SettingsProvider/index.tsx +70 -70
  111. package/src/providers/ThemeProvider/ThemeProvider.ts +55 -55
  112. package/src/providers/ThemeProvider/defaultTheme.ts +444 -444
  113. package/src/providers/ThemeProvider/index.ts +3 -3
  114. package/src/providers/ThemeProvider/types.ts +123 -123
  115. package/src/providers/UiProviders/index.tsx +65 -65
  116. package/src/providers/UiProviders/styles.ts +10 -10
  117. package/src/providers/hooks.ts +8 -8
  118. package/src/providers/index.ts +5 -5
  119. package/src/services/HttpService.ts +80 -80
  120. package/src/services/WebSocketService.ts +147 -147
  121. package/src/services/advancedRequests.ts +101 -101
  122. package/src/services/base.ts +31 -31
  123. package/src/services/hooks.ts +23 -23
  124. package/src/services/index.ts +2 -2
  125. package/src/services/sqlRequests.ts +99 -99
  126. package/src/styles/animations.scss +30 -30
  127. package/src/styles/index.scss +42 -42
  128. package/src/typings.d.ts +6 -6
  129. package/tsconfig.tsbuildinfo +1 -1
  130. package/dist/components/data/DataGrid/helpers.d.ts +0 -28
  131. package/dist/components/data/DataGrid/helpers.js +0 -436
  132. package/dist/config/types.d.ts +0 -11
  133. package/dist/config/types.js +0 -2
@@ -1,167 +1,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 {
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 {
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,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
+ `;