@addev-be/ui 0.1.18
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.
- package/assets/fonts/montserrat-200.woff2 +0 -0
- package/assets/fonts/montserrat-400.woff2 +0 -0
- package/assets/fonts/montserrat-500.woff2 +0 -0
- package/assets/fonts/montserrat-700.woff2 +0 -0
- package/assets/icons/arrow-down-a-z.svg +1 -0
- package/assets/icons/arrow-up-z-a.svg +1 -0
- package/assets/icons/arrows-rotate.svg +1 -0
- package/assets/icons/arrows-up-down.svg +1 -0
- package/assets/icons/check.svg +1 -0
- package/assets/icons/copy.svg +1 -0
- package/assets/icons/down.svg +1 -0
- package/assets/icons/filter-full.svg +1 -0
- package/assets/icons/filter-slash.svg +1 -0
- package/assets/icons/filter.svg +1 -0
- package/assets/icons/hashtag.svg +1 -0
- package/assets/icons/image-slash.svg +1 -0
- package/assets/icons/left.svg +1 -0
- package/assets/icons/magnifier.svg +1 -0
- package/assets/icons/phone.svg +1 -0
- package/assets/icons/plus.svg +1 -0
- package/assets/icons/right.svg +1 -0
- package/assets/icons/spinner-third.svg +1 -0
- package/assets/icons/table-columns.svg +1 -0
- package/assets/icons/up.svg +1 -0
- package/assets/icons/user-tie.svg +1 -0
- package/eslint.config.js +28 -0
- package/package.json +49 -0
- package/src/Icons.tsx +80 -0
- package/src/components/data/DataGrid/AdvancedRequestDataGrid.tsx +236 -0
- package/src/components/data/DataGrid/DataGridCell.tsx +78 -0
- package/src/components/data/DataGrid/DataGridColumnsModal/helpers.ts +14 -0
- package/src/components/data/DataGrid/DataGridColumnsModal/hooks.tsx +58 -0
- package/src/components/data/DataGrid/DataGridColumnsModal/index.tsx +181 -0
- package/src/components/data/DataGrid/DataGridColumnsModal/styles.ts +104 -0
- package/src/components/data/DataGrid/DataGridEditableCell.tsx +54 -0
- package/src/components/data/DataGrid/DataGridFilterMenu/hooks.tsx +75 -0
- package/src/components/data/DataGrid/DataGridFilterMenu/index.tsx +190 -0
- package/src/components/data/DataGrid/DataGridFilterMenu/styles.ts +100 -0
- package/src/components/data/DataGrid/DataGridFooter.tsx +64 -0
- package/src/components/data/DataGrid/DataGridHeader.tsx +129 -0
- package/src/components/data/DataGrid/DataGridHeaderCell.tsx +166 -0
- package/src/components/data/DataGrid/FilterModalContent/index.tsx +125 -0
- package/src/components/data/DataGrid/FilterModalContent/styles.ts +22 -0
- package/src/components/data/DataGrid/FilterValuesScroller.tsx +131 -0
- package/src/components/data/DataGrid/VirtualScroller.tsx +51 -0
- package/src/components/data/DataGrid/helpers/advancedRequests.tsx +61 -0
- package/src/components/data/DataGrid/helpers/columns.tsx +259 -0
- package/src/components/data/DataGrid/helpers/filters.ts +219 -0
- package/src/components/data/DataGrid/helpers/index.ts +3 -0
- package/src/components/data/DataGrid/hooks/index.ts +30 -0
- package/src/components/data/DataGrid/hooks/useDataGrid.tsx +225 -0
- package/src/components/data/DataGrid/hooks/useDataGridCopy.ts +166 -0
- package/src/components/data/DataGrid/hooks/useDataGridSettings.ts +49 -0
- package/src/components/data/DataGrid/index.tsx +145 -0
- package/src/components/data/DataGrid/styles.ts +284 -0
- package/src/components/data/DataGrid/types.ts +232 -0
- package/src/components/data/index.ts +3 -0
- package/src/components/forms/Button.tsx +99 -0
- package/src/components/forms/IconButton.tsx +57 -0
- package/src/components/forms/IndeterminateCheckbox.tsx +46 -0
- package/src/components/forms/Select.tsx +40 -0
- package/src/components/forms/index.ts +5 -0
- package/src/components/forms/styles.ts +20 -0
- package/src/components/index.ts +3 -0
- package/src/components/layout/Dropdown/index.tsx +79 -0
- package/src/components/layout/Dropdown/styles.ts +44 -0
- package/src/components/layout/Loading/index.tsx +28 -0
- package/src/components/layout/Loading/styles.ts +29 -0
- package/src/components/layout/Modal/index.tsx +51 -0
- package/src/components/layout/Modal/styles.ts +110 -0
- package/src/components/layout/index.ts +3 -0
- package/src/config/index.ts +14 -0
- package/src/helpers/getScrollbarSize.ts +14 -0
- package/src/helpers/numbers.ts +20 -0
- package/src/hooks/index.ts +2 -0
- package/src/hooks/useElementSize.ts +24 -0
- package/src/hooks/useWindowSize.ts +20 -0
- package/src/index.ts +7 -0
- package/src/providers/PortalsProvider/index.tsx +54 -0
- package/src/providers/PortalsProvider/styles.ts +27 -0
- package/src/providers/SettingsProvider/index.tsx +70 -0
- package/src/providers/ThemeProvider/ThemeProvider.ts +55 -0
- package/src/providers/ThemeProvider/defaultTheme.ts +444 -0
- package/src/providers/ThemeProvider/index.ts +3 -0
- package/src/providers/ThemeProvider/types.ts +123 -0
- package/src/providers/UiProviders/index.tsx +65 -0
- package/src/providers/UiProviders/styles.ts +10 -0
- package/src/providers/hooks.ts +8 -0
- package/src/providers/index.ts +5 -0
- package/src/services/WebSocketService.ts +147 -0
- package/src/services/advancedRequests.ts +100 -0
- package/src/services/base.ts +31 -0
- package/src/services/hooks.ts +13 -0
- package/src/services/index.ts +2 -0
- package/src/styles/animations.scss +30 -0
- package/src/styles/index.scss +42 -0
- package/src/typings.d.ts +6 -0
- package/tsconfig.json +18 -0
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
import styled, { css } from 'styled-components';
|
|
2
|
+
|
|
3
|
+
import { ThemeColor } from '../../../providers/ThemeProvider/types';
|
|
4
|
+
|
|
5
|
+
export const VIRTUAL_SCROLL_TOLERANCE = 20;
|
|
6
|
+
export const TOOLBAR_HEIGHT = 40;
|
|
7
|
+
export const DEFAULT_HEADER_ROW_HEIGHT = 40;
|
|
8
|
+
export const DEFAULT_ROW_HEIGHT = 32;
|
|
9
|
+
export const DEFAULT_FILTER_ROW_HEIGHT = 24;
|
|
10
|
+
|
|
11
|
+
export const TopPaddingRow = styled.div``;
|
|
12
|
+
export const BottomPaddingRow = styled.div``;
|
|
13
|
+
|
|
14
|
+
export const VirtualScrollerContainer = styled.div<{
|
|
15
|
+
$height: number;
|
|
16
|
+
}>`
|
|
17
|
+
position: relative;
|
|
18
|
+
overflow: visible;
|
|
19
|
+
height: ${({ $height }) => `${$height}px`};
|
|
20
|
+
`;
|
|
21
|
+
export const VirtualScrollerRowsContainer = styled.div.attrs<{
|
|
22
|
+
$gridTemplateColumns: string;
|
|
23
|
+
$topPadding: number;
|
|
24
|
+
$rowHeight?: number;
|
|
25
|
+
}>(({ $gridTemplateColumns, $topPadding, $rowHeight = DEFAULT_ROW_HEIGHT }) => {
|
|
26
|
+
const rowHeightValue = `${$rowHeight}px`;
|
|
27
|
+
return {
|
|
28
|
+
style: {
|
|
29
|
+
top: `${$topPadding}px`,
|
|
30
|
+
gridTemplateColumns: $gridTemplateColumns,
|
|
31
|
+
gridAutoRows: rowHeightValue,
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
})`
|
|
35
|
+
display: grid;
|
|
36
|
+
position: absolute;
|
|
37
|
+
|
|
38
|
+
${TopPaddingRow} {
|
|
39
|
+
grid-column-start: 1;
|
|
40
|
+
grid-column-end: -1;
|
|
41
|
+
grid-row: 1;
|
|
42
|
+
}
|
|
43
|
+
${BottomPaddingRow} {
|
|
44
|
+
grid-column-start: 1;
|
|
45
|
+
grid-column-end: -1;
|
|
46
|
+
grid-row: -1;
|
|
47
|
+
}
|
|
48
|
+
`;
|
|
49
|
+
|
|
50
|
+
export const DataGridResizeGrip = styled.div<{ $headerColor?: ThemeColor }>`
|
|
51
|
+
position: absolute;
|
|
52
|
+
top: 0;
|
|
53
|
+
right: 0;
|
|
54
|
+
width: var(--space-1);
|
|
55
|
+
height: 100%;
|
|
56
|
+
|
|
57
|
+
${({ $headerColor }) =>
|
|
58
|
+
$headerColor
|
|
59
|
+
? css`
|
|
60
|
+
background-color: var(--color-${$headerColor}-400);
|
|
61
|
+
&:hover,
|
|
62
|
+
&.active {
|
|
63
|
+
background-color: var(--color-${$headerColor}-500);
|
|
64
|
+
}
|
|
65
|
+
`
|
|
66
|
+
: css`
|
|
67
|
+
background-color: var(--color-neutral-400);
|
|
68
|
+
&:hover,
|
|
69
|
+
&.active {
|
|
70
|
+
background-color: var(--color-neutral-500);
|
|
71
|
+
}
|
|
72
|
+
`}
|
|
73
|
+
|
|
74
|
+
cursor: col-resize;
|
|
75
|
+
display: none;
|
|
76
|
+
`;
|
|
77
|
+
|
|
78
|
+
type DataGridHeaderCellContainerProps = {
|
|
79
|
+
$isResizing: boolean;
|
|
80
|
+
$headerColor?: ThemeColor;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export const DataGridHeaderCellContainer = styled.div<DataGridHeaderCellContainerProps>`
|
|
84
|
+
position: relative;
|
|
85
|
+
display: flex;
|
|
86
|
+
align-items: center;
|
|
87
|
+
flex-wrap: nowrap;
|
|
88
|
+
gap: var(--space-1);
|
|
89
|
+
padding: 0 0.75rem;
|
|
90
|
+
height: 100%;
|
|
91
|
+
font-weight: var(--font-bold);
|
|
92
|
+
line-height: 1.5rem;
|
|
93
|
+
z-index: ${({ $isResizing }) => ($isResizing ? 1 : 0)};
|
|
94
|
+
|
|
95
|
+
${({ $headerColor }) =>
|
|
96
|
+
$headerColor
|
|
97
|
+
? css`
|
|
98
|
+
background-color: var(--color-${$headerColor}-200);
|
|
99
|
+
color: var(--color-${$headerColor}-900);
|
|
100
|
+
&:hover {
|
|
101
|
+
background-color: var(--color-${$headerColor}-300);
|
|
102
|
+
}
|
|
103
|
+
`
|
|
104
|
+
: css`
|
|
105
|
+
background-color: var(--color-neutral-200);
|
|
106
|
+
color: var(--color-neutral-900);
|
|
107
|
+
&:hover {
|
|
108
|
+
background-color: var(--color-neutral-300);
|
|
109
|
+
}
|
|
110
|
+
`}
|
|
111
|
+
|
|
112
|
+
&:hover {
|
|
113
|
+
${DataGridResizeGrip} {
|
|
114
|
+
display: block;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
& > span {
|
|
119
|
+
display: inline-block;
|
|
120
|
+
text-overflow: ellipsis;
|
|
121
|
+
overflow: hidden;
|
|
122
|
+
white-space: nowrap;
|
|
123
|
+
flex: 1;
|
|
124
|
+
}
|
|
125
|
+
`;
|
|
126
|
+
DataGridHeaderCellContainer.displayName = 'DataGridHeaderCellContainer';
|
|
127
|
+
|
|
128
|
+
export const DataGridCell = styled.div`
|
|
129
|
+
padding: 0 var(--space-3);
|
|
130
|
+
overflow: hidden;
|
|
131
|
+
text-overflow: ellipsis;
|
|
132
|
+
white-space: nowrap;
|
|
133
|
+
border-right: 1px solid var(--color-neutral-200);
|
|
134
|
+
border-bottom: 1px solid var(--color-neutral-200);
|
|
135
|
+
`;
|
|
136
|
+
DataGridCell.displayName = 'DataGridCell';
|
|
137
|
+
|
|
138
|
+
export const DataGridToolsRow = styled.div`
|
|
139
|
+
grid-column-start: 1;
|
|
140
|
+
grid-column-end: -1;
|
|
141
|
+
grid-row: 1;
|
|
142
|
+
display: flex;
|
|
143
|
+
gap: var(--space-1);
|
|
144
|
+
padding: 0 var(--space-1);
|
|
145
|
+
align-items: center;
|
|
146
|
+
background-color: var(--color-neutral-200);
|
|
147
|
+
position: sticky;
|
|
148
|
+
top: 0;
|
|
149
|
+
left: 0;
|
|
150
|
+
z-index: 10;
|
|
151
|
+
`;
|
|
152
|
+
DataGridToolsRow.displayName = 'DataGridToolsRow';
|
|
153
|
+
|
|
154
|
+
export const DataGridContainer = styled.div<{
|
|
155
|
+
$headerRowHeight?: number;
|
|
156
|
+
$rowHeight?: number;
|
|
157
|
+
$rowsCount: number;
|
|
158
|
+
$showToolsHeader?: boolean;
|
|
159
|
+
}>`
|
|
160
|
+
display: grid;
|
|
161
|
+
width: 100%;
|
|
162
|
+
height: 100%;
|
|
163
|
+
background-color: var(--color-neutral-50);
|
|
164
|
+
font-size: var(--text-base);
|
|
165
|
+
overflow: scroll;
|
|
166
|
+
grid-template-rows: ${({ $headerRowHeight = DEFAULT_HEADER_ROW_HEIGHT }) =>
|
|
167
|
+
`${TOOLBAR_HEIGHT}px ${$headerRowHeight}px auto`};
|
|
168
|
+
|
|
169
|
+
${DataGridToolsRow} {
|
|
170
|
+
height: ${TOOLBAR_HEIGHT}px;
|
|
171
|
+
}
|
|
172
|
+
${DataGridHeaderCellContainer} {
|
|
173
|
+
position: sticky;
|
|
174
|
+
top: ${({ $headerRowHeight = DEFAULT_HEADER_ROW_HEIGHT }) =>
|
|
175
|
+
`${$headerRowHeight}px`};
|
|
176
|
+
height: ${({ $headerRowHeight = DEFAULT_HEADER_ROW_HEIGHT }) =>
|
|
177
|
+
`${$headerRowHeight}px`};
|
|
178
|
+
}
|
|
179
|
+
${DataGridCell} {
|
|
180
|
+
height: ${({ $rowHeight = DEFAULT_ROW_HEIGHT }) => `${$rowHeight}px`};
|
|
181
|
+
line-height: ${({ $rowHeight = DEFAULT_ROW_HEIGHT }) => `${$rowHeight}px`};
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
${VirtualScrollerContainer} {
|
|
185
|
+
grid-column-start: 1;
|
|
186
|
+
grid-column-end: -1;
|
|
187
|
+
grid-row: 3;
|
|
188
|
+
}
|
|
189
|
+
`;
|
|
190
|
+
DataGridContainer.displayName = 'DataGridContainer';
|
|
191
|
+
|
|
192
|
+
export const DataGridHeaderRow = styled.div.attrs<{
|
|
193
|
+
$headerRowHeight?: number;
|
|
194
|
+
$headerColor?: ThemeColor;
|
|
195
|
+
$gridTemplateColumns: string;
|
|
196
|
+
}>(({ $gridTemplateColumns }) => ({
|
|
197
|
+
style: {
|
|
198
|
+
gridTemplateColumns: $gridTemplateColumns,
|
|
199
|
+
},
|
|
200
|
+
}))`
|
|
201
|
+
display: grid;
|
|
202
|
+
grid-template-rows: ${({ $headerRowHeight = DEFAULT_HEADER_ROW_HEIGHT }) =>
|
|
203
|
+
`${$headerRowHeight}px`};
|
|
204
|
+
z-index: 10;
|
|
205
|
+
position: sticky;
|
|
206
|
+
top: ${TOOLBAR_HEIGHT}px;
|
|
207
|
+
|
|
208
|
+
${({ $headerColor }) =>
|
|
209
|
+
$headerColor
|
|
210
|
+
? css`
|
|
211
|
+
background-color: var(--color-${$headerColor}-100);
|
|
212
|
+
color: var(--color-${$headerColor}-900);
|
|
213
|
+
`
|
|
214
|
+
: css`
|
|
215
|
+
background-color: var(--color-neutral-200);
|
|
216
|
+
color: var(--color-neutral-900);
|
|
217
|
+
`}
|
|
218
|
+
`;
|
|
219
|
+
DataGridHeaderRow.displayName = 'DataGridHeaderRow';
|
|
220
|
+
|
|
221
|
+
export const DataGridRow = styled.div`
|
|
222
|
+
display: contents;
|
|
223
|
+
`;
|
|
224
|
+
DataGridRow.displayName = 'DataGridRow';
|
|
225
|
+
|
|
226
|
+
export const LoadingCell = styled(DataGridCell)`
|
|
227
|
+
padding: var(--space-2);
|
|
228
|
+
`;
|
|
229
|
+
LoadingCell.displayName = 'LoadingCell';
|
|
230
|
+
|
|
231
|
+
export const SelectionCell = styled.div`
|
|
232
|
+
/* inline-flex items-center justify-center w-12 select-none text-center whitespace-nowrap */
|
|
233
|
+
& > input[type='checkbox'] {
|
|
234
|
+
height: 1rem;
|
|
235
|
+
width: 1rem;
|
|
236
|
+
border-radius: 0.25rem;
|
|
237
|
+
border: 1px solid var(--color-neutral-300);
|
|
238
|
+
color: var(--color-sky-600);
|
|
239
|
+
}
|
|
240
|
+
`;
|
|
241
|
+
SelectionCell.displayName = 'SelectionCell';
|
|
242
|
+
|
|
243
|
+
export const ResizeBackdrop = styled.div.attrs({
|
|
244
|
+
className: 'ResizeBackdrop',
|
|
245
|
+
})`
|
|
246
|
+
position: fixed;
|
|
247
|
+
top: 0;
|
|
248
|
+
left: 0;
|
|
249
|
+
right: 0;
|
|
250
|
+
bottom: 0;
|
|
251
|
+
background-color: rgba(0, 0, 0, 0);
|
|
252
|
+
cursor: col-resize;
|
|
253
|
+
`;
|
|
254
|
+
ResizeBackdrop.displayName = 'ResizeBackdrop';
|
|
255
|
+
|
|
256
|
+
export const FilterValuesScrollerContainer = styled.div.attrs({
|
|
257
|
+
className: 'FilterValuesScrollerContainer',
|
|
258
|
+
})<{
|
|
259
|
+
$rowHeight?: number;
|
|
260
|
+
}>`
|
|
261
|
+
display: block;
|
|
262
|
+
font-size: var(--text-base);
|
|
263
|
+
background-color: var(--color-neutral-0);
|
|
264
|
+
overflow-y: scroll;
|
|
265
|
+
overflow-x: hidden;
|
|
266
|
+
height: 100%;
|
|
267
|
+
|
|
268
|
+
& > div {
|
|
269
|
+
position: relative;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
& .checkbox {
|
|
273
|
+
position: absolute;
|
|
274
|
+
display: flex;
|
|
275
|
+
flex-direction: row;
|
|
276
|
+
align-items: center;
|
|
277
|
+
height: ${({ $rowHeight = DEFAULT_FILTER_ROW_HEIGHT }) =>
|
|
278
|
+
`${$rowHeight}px`};
|
|
279
|
+
|
|
280
|
+
input[type='checkbox'] {
|
|
281
|
+
margin-right: var(--space-1);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
`;
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
|
|
3
|
+
import * as t from 'io-ts';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
CSSProperties,
|
|
7
|
+
Context,
|
|
8
|
+
Dispatch,
|
|
9
|
+
MouseEvent,
|
|
10
|
+
ReactNode,
|
|
11
|
+
SetStateAction,
|
|
12
|
+
} from 'react';
|
|
13
|
+
|
|
14
|
+
import { FieldDTO } from '../../../services/advancedRequests';
|
|
15
|
+
import { SettingsContextProps } from '../../../providers/SettingsProvider';
|
|
16
|
+
import { ThemeColor } from '../../../providers/ThemeProvider/types';
|
|
17
|
+
|
|
18
|
+
export type DataGridColumn<
|
|
19
|
+
R,
|
|
20
|
+
T extends DataGridFilterType | undefined = DataGridFilterType
|
|
21
|
+
> = {
|
|
22
|
+
bodyClassName?: string;
|
|
23
|
+
className?: string;
|
|
24
|
+
editable?: boolean;
|
|
25
|
+
excelFormatter?: (value: any) => string;
|
|
26
|
+
excelValue?: (value: any) => string;
|
|
27
|
+
field?: FieldDTO;
|
|
28
|
+
filter?: T extends undefined ? never : AnyDataGridFilter<R>;
|
|
29
|
+
footer?: (allRows: R[], filteredRows: R[], selectedRows: R[]) => ReactNode;
|
|
30
|
+
footerClassName?: string;
|
|
31
|
+
getter?: (row: R) => string | number;
|
|
32
|
+
headerClassName?: string;
|
|
33
|
+
name: string;
|
|
34
|
+
order?: number;
|
|
35
|
+
propertyName?: keyof R;
|
|
36
|
+
render?: (column: DataGridColumn<R, T>, row: R) => ReactNode | string;
|
|
37
|
+
resizable?: boolean;
|
|
38
|
+
sortGetter?: (row: R) => string | number;
|
|
39
|
+
type?: 'text' | 'number' | 'date';
|
|
40
|
+
width?: number;
|
|
41
|
+
settingsContext?: Context<SettingsContextProps>;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export type DataGridColumns<R> = Record<
|
|
45
|
+
string,
|
|
46
|
+
DataGridColumn<R, DataGridFilterType | undefined>
|
|
47
|
+
>;
|
|
48
|
+
|
|
49
|
+
export type DataGridFilters<R> = Record<
|
|
50
|
+
string,
|
|
51
|
+
DataGridFilter<R, DataGridFilterType>
|
|
52
|
+
>;
|
|
53
|
+
|
|
54
|
+
export type DataGridProps<R> = {
|
|
55
|
+
name?: string;
|
|
56
|
+
className?: string;
|
|
57
|
+
rows: R[];
|
|
58
|
+
columns: DataGridColumns<R>;
|
|
59
|
+
rowKey: keyof R | ((row: R) => string);
|
|
60
|
+
selectable?: boolean;
|
|
61
|
+
editable?: boolean;
|
|
62
|
+
onRowDoubleClick?: (row: R, e: MouseEvent) => void;
|
|
63
|
+
onSelectionChange?: (selectedRows: R[]) => void;
|
|
64
|
+
onFiltersChanged?: (filters: DataGridFilters<R>) => void;
|
|
65
|
+
onSortsChanged?: (sorts: Record<string, DataGridSort>) => void;
|
|
66
|
+
onVisibleRowsChange?: (startIndex: number, length: number) => void;
|
|
67
|
+
onCellEdited?: (row: R, columnKey: string, value: any) => void;
|
|
68
|
+
rowClassNameGetter?: (row: R | null) => {
|
|
69
|
+
className?: string;
|
|
70
|
+
style?: CSSProperties;
|
|
71
|
+
};
|
|
72
|
+
headerRowHeight?: number;
|
|
73
|
+
rowHeight?: number;
|
|
74
|
+
filter?: boolean;
|
|
75
|
+
sort?: boolean;
|
|
76
|
+
filterValuesLoader?: (
|
|
77
|
+
columnKey: string
|
|
78
|
+
) => Promise<(string | number | null)[]>;
|
|
79
|
+
// copyTableHandler?: (
|
|
80
|
+
// includeHeaders?: boolean,
|
|
81
|
+
// includeFooters?: boolean
|
|
82
|
+
// ) => Promise<void>;
|
|
83
|
+
loadCopyRows?: () => Promise<R[]>;
|
|
84
|
+
refresh?: () => void;
|
|
85
|
+
headerColor?: ThemeColor;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export type DataGridContextProps<R> = DataGridProps<R> & {
|
|
89
|
+
editingCell?: [number, number];
|
|
90
|
+
setEditingCell: Dispatch<SetStateAction<[number, number]>>;
|
|
91
|
+
sortedRows: R[];
|
|
92
|
+
selectedRows: R[];
|
|
93
|
+
setSelectedRows: (selection: R[]) => void;
|
|
94
|
+
sorts?: Record<string, DataGridSort>;
|
|
95
|
+
setSorts: (sorts: Record<string, DataGridSort>) => void;
|
|
96
|
+
filters?: DataGridFilters<R>;
|
|
97
|
+
setFilters: Dispatch<SetStateAction<DataGridFilters<R>>>;
|
|
98
|
+
visibleColumns: DataGridColumnKeyValuePair<R>[];
|
|
99
|
+
copyTable: (
|
|
100
|
+
includeHeaders?: boolean,
|
|
101
|
+
includeFooters?: boolean
|
|
102
|
+
) => Promise<void>;
|
|
103
|
+
setColumnWidth: (key: string, width: number) => void;
|
|
104
|
+
saveSettings: (newSettings?: DataGridSettings) => void;
|
|
105
|
+
settings: DataGridSettings;
|
|
106
|
+
setSettings: Dispatch<SetStateAction<DataGridSettings>>;
|
|
107
|
+
visibleRows: R[];
|
|
108
|
+
scrollableRef: React.RefObject<HTMLDivElement>;
|
|
109
|
+
onScroll: (e: React.UIEvent<HTMLDivElement>) => void;
|
|
110
|
+
index: number;
|
|
111
|
+
length: number;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
export type DataGridContext<R> = Context<DataGridContextProps<R>>;
|
|
115
|
+
|
|
116
|
+
export const dataGridSettingCodec = t.partial(
|
|
117
|
+
{
|
|
118
|
+
width: t.number,
|
|
119
|
+
order: t.number,
|
|
120
|
+
},
|
|
121
|
+
'DataGridSetting'
|
|
122
|
+
);
|
|
123
|
+
export const dataGridSettingsCodec = t.record(
|
|
124
|
+
t.string,
|
|
125
|
+
dataGridSettingCodec,
|
|
126
|
+
'DataGridSettings'
|
|
127
|
+
);
|
|
128
|
+
export const dataGridSettingsByNameCodec = t.record(
|
|
129
|
+
t.string,
|
|
130
|
+
dataGridSettingsCodec,
|
|
131
|
+
'DataGridSettingsByName'
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
export type DataGridSetting = t.TypeOf<typeof dataGridSettingCodec>;
|
|
135
|
+
export type DataGridSettings = t.TypeOf<typeof dataGridSettingsCodec>;
|
|
136
|
+
export type DataGridSettingsByName = t.TypeOf<
|
|
137
|
+
typeof dataGridSettingsByNameCodec
|
|
138
|
+
>;
|
|
139
|
+
export type DataGridSettingsTuple = [string, DataGridSetting];
|
|
140
|
+
export type DataGridSettingsArray = DataGridSettingsTuple[];
|
|
141
|
+
export type DataGridColumnKeyValuePair<R> = [string, DataGridColumn<R, any>];
|
|
142
|
+
|
|
143
|
+
export type DataGridCellProps<R> = {
|
|
144
|
+
row: R;
|
|
145
|
+
rowIndex: number;
|
|
146
|
+
columnKey: string;
|
|
147
|
+
columnIndex: number;
|
|
148
|
+
column: DataGridColumn<R>;
|
|
149
|
+
context: DataGridContext<R>;
|
|
150
|
+
className?: string;
|
|
151
|
+
style?: CSSProperties;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
export type DataGridHeaderCellProps<R> = {
|
|
155
|
+
columnKey: string;
|
|
156
|
+
columnIndex: number;
|
|
157
|
+
column: DataGridColumn<R>;
|
|
158
|
+
context: DataGridContext<R>;
|
|
159
|
+
onFilterButtonClicked?: (columnKey: string) => void;
|
|
160
|
+
isFilterOpen?: boolean;
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
export type DataGridSort = 'asc' | 'desc';
|
|
164
|
+
|
|
165
|
+
export type DataGridFilterType = 'text' | 'number';
|
|
166
|
+
export type DataGridFilterDataType<T extends DataGridFilterType> =
|
|
167
|
+
T extends 'text' ? string : number;
|
|
168
|
+
|
|
169
|
+
export type DataGridFilterPredicate<T> = (valueToVerify: T) => boolean;
|
|
170
|
+
export type DataGridFilterPredicateBuilder<T> = (
|
|
171
|
+
row: any,
|
|
172
|
+
...filterValues: T[]
|
|
173
|
+
) => DataGridFilterPredicate<T>;
|
|
174
|
+
|
|
175
|
+
export type DataGridFilterGetter<R, T extends DataGridFilterType> = (
|
|
176
|
+
row: R
|
|
177
|
+
) => DataGridFilterDataType<T> | null;
|
|
178
|
+
export type DataGridFilterFormatter = (
|
|
179
|
+
value: string | number | null
|
|
180
|
+
) => string | null;
|
|
181
|
+
|
|
182
|
+
export type DataGridFilterPredicates = {
|
|
183
|
+
text: {
|
|
184
|
+
contains: DataGridFilterPredicateBuilder<string>;
|
|
185
|
+
notContains: DataGridFilterPredicateBuilder<string>;
|
|
186
|
+
equals: DataGridFilterPredicateBuilder<string>;
|
|
187
|
+
notEquals: DataGridFilterPredicateBuilder<string>;
|
|
188
|
+
startsWith: DataGridFilterPredicateBuilder<string>;
|
|
189
|
+
endsWith: DataGridFilterPredicateBuilder<string>;
|
|
190
|
+
inArray: DataGridFilterPredicateBuilder<string>;
|
|
191
|
+
};
|
|
192
|
+
number: {
|
|
193
|
+
equals: DataGridFilterPredicateBuilder<number>;
|
|
194
|
+
notEquals: DataGridFilterPredicateBuilder<number>;
|
|
195
|
+
lessThan: DataGridFilterPredicateBuilder<number>;
|
|
196
|
+
lessThanOrEqual: DataGridFilterPredicateBuilder<number>;
|
|
197
|
+
greaterThan: DataGridFilterPredicateBuilder<number>;
|
|
198
|
+
greaterThanOrEqual: DataGridFilterPredicateBuilder<number>;
|
|
199
|
+
inRange: DataGridFilterPredicateBuilder<number>;
|
|
200
|
+
inArray: DataGridFilterPredicateBuilder<number>;
|
|
201
|
+
};
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
export type DataGridFilterOperator<T extends DataGridFilterType> =
|
|
205
|
+
keyof DataGridFilterPredicates[T];
|
|
206
|
+
|
|
207
|
+
export type DataGridFilter<
|
|
208
|
+
R,
|
|
209
|
+
T extends DataGridFilterType = DataGridFilterType
|
|
210
|
+
> = {
|
|
211
|
+
type: T;
|
|
212
|
+
operator: keyof DataGridFilterPredicates[T];
|
|
213
|
+
getter: DataGridFilterGetter<R, T>;
|
|
214
|
+
formatter?: DataGridFilterFormatter;
|
|
215
|
+
values: (DataGridFilterDataType<T> | null)[];
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
export type AnyDataGridFilter<R> =
|
|
219
|
+
| DataGridFilter<R, 'text'>
|
|
220
|
+
| DataGridFilter<R, 'number'>;
|
|
221
|
+
|
|
222
|
+
export type DataGridFilterGroup<R> = {
|
|
223
|
+
name: string;
|
|
224
|
+
values?: R[];
|
|
225
|
+
groups?: DataGridFilterGroup<R>[];
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
export type DataGridFilterCheckbox<R extends string | number | null> = {
|
|
229
|
+
displayValue: string | null;
|
|
230
|
+
values: R[];
|
|
231
|
+
level: number;
|
|
232
|
+
};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { ComponentProps, forwardRef } from 'react';
|
|
2
|
+
import styled, { css } from 'styled-components';
|
|
3
|
+
|
|
4
|
+
import { IconFC } from '../../Icons';
|
|
5
|
+
import { ThemeColor } from '../../providers/ThemeProvider/types';
|
|
6
|
+
|
|
7
|
+
export const StyledButton = styled.button.withConfig({
|
|
8
|
+
shouldForwardProp: () => true,
|
|
9
|
+
})<ButtonProps>`
|
|
10
|
+
display: inline-flex;
|
|
11
|
+
vertical-align: middle;
|
|
12
|
+
align-items: center;
|
|
13
|
+
justify-content: center;
|
|
14
|
+
box-shadow: var(--shadow-sm);
|
|
15
|
+
/* font-weight: bold; */
|
|
16
|
+
border-radius: var(--rounded-md);
|
|
17
|
+
font-family: var(--font-sans);
|
|
18
|
+
cursor: pointer;
|
|
19
|
+
|
|
20
|
+
${({ color }) =>
|
|
21
|
+
color
|
|
22
|
+
? css`
|
|
23
|
+
background-color: var(--color-${color}-400);
|
|
24
|
+
border: 1px solid var(--color-${color}-500);
|
|
25
|
+
&:hover {
|
|
26
|
+
background-color: var(--color-${color}-300);
|
|
27
|
+
border: 1px solid var(--color-${color}-400);
|
|
28
|
+
}
|
|
29
|
+
color: var(--color-${color}-950);
|
|
30
|
+
svg {
|
|
31
|
+
fill: var(--color-${color}-950);
|
|
32
|
+
}
|
|
33
|
+
`
|
|
34
|
+
: css`
|
|
35
|
+
background-color: var(--color-neutral-100);
|
|
36
|
+
border: 1px solid var(--color-neutral-300);
|
|
37
|
+
&:hover {
|
|
38
|
+
background-color: var(--color-neutral-200);
|
|
39
|
+
border: 1px solid var(--color-neutral-400);
|
|
40
|
+
}
|
|
41
|
+
color: var(--color-neutral-900);
|
|
42
|
+
svg {
|
|
43
|
+
fill: var(--color-neutral-900);
|
|
44
|
+
}
|
|
45
|
+
`}
|
|
46
|
+
|
|
47
|
+
${({ rounded }) => rounded && 'border-radius: var(--rounded-full);'}
|
|
48
|
+
|
|
49
|
+
&.small {
|
|
50
|
+
padding: var(--space-1) var(--space-1_5);
|
|
51
|
+
font-size: var(--text-sm);
|
|
52
|
+
height: var(--space-6);
|
|
53
|
+
box-shadow: var(--shadow-sm);
|
|
54
|
+
svg {
|
|
55
|
+
margin-right: var(--space-1);
|
|
56
|
+
width: var(--space-3);
|
|
57
|
+
height: var(--space-3);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
&.medium {
|
|
61
|
+
padding: var(--space-2) var(--space-3);
|
|
62
|
+
font-size: var(--text-base);
|
|
63
|
+
height: var(--space-8);
|
|
64
|
+
box-shadow: var(--shadow-sm);
|
|
65
|
+
svg {
|
|
66
|
+
margin-right: var(--space-1);
|
|
67
|
+
width: var(--space-4);
|
|
68
|
+
height: var(--space-4);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
&.large {
|
|
72
|
+
padding: var(--space-3) var(--space-4);
|
|
73
|
+
font-size: var(--text-lg);
|
|
74
|
+
height: var(--space-10);
|
|
75
|
+
box-shadow: var(--shadow-sm);
|
|
76
|
+
svg {
|
|
77
|
+
margin-right: var(--space-1);
|
|
78
|
+
width: var(--space-5);
|
|
79
|
+
height: var(--space-5);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
`;
|
|
83
|
+
|
|
84
|
+
export type ButtonProps = {
|
|
85
|
+
color?: ThemeColor;
|
|
86
|
+
size?: 'small' | 'medium' | 'large';
|
|
87
|
+
icon?: IconFC;
|
|
88
|
+
rounded?: boolean;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
export const Button = forwardRef<
|
|
92
|
+
HTMLButtonElement,
|
|
93
|
+
ComponentProps<typeof StyledButton> & ButtonProps
|
|
94
|
+
>(({ children, size = 'medium', icon: Icon, className, ...props }, ref) => (
|
|
95
|
+
<StyledButton ref={ref} className={`${size} ${className}`} {...props}>
|
|
96
|
+
{Icon && <Icon />}
|
|
97
|
+
{children}
|
|
98
|
+
</StyledButton>
|
|
99
|
+
));
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Button, ButtonProps } from './Button';
|
|
2
|
+
import { ButtonHTMLAttributes, forwardRef } from 'react';
|
|
3
|
+
|
|
4
|
+
import { IconFC } from '../../Icons';
|
|
5
|
+
import styled from 'styled-components';
|
|
6
|
+
|
|
7
|
+
type IconButtonProps = ButtonProps & {
|
|
8
|
+
icon: IconFC;
|
|
9
|
+
$iconSize?: string;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const styles = {
|
|
13
|
+
IconButton: styled(Button).attrs({
|
|
14
|
+
className: 'IconButton',
|
|
15
|
+
})<Omit<IconButtonProps, 'icon'>>`
|
|
16
|
+
border-radius: 100%;
|
|
17
|
+
&.small {
|
|
18
|
+
padding: var(--space-1);
|
|
19
|
+
height: var(--space-6);
|
|
20
|
+
width: var(--space-6);
|
|
21
|
+
svg {
|
|
22
|
+
margin-right: 0;
|
|
23
|
+
width: ${({ $iconSize = 'var(--space-4)' }) => $iconSize};
|
|
24
|
+
height: ${({ $iconSize = 'var(--space-4)' }) => $iconSize};
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
&.medium {
|
|
28
|
+
padding: var(--space-2);
|
|
29
|
+
height: var(--space-8);
|
|
30
|
+
width: var(--space-8);
|
|
31
|
+
svg {
|
|
32
|
+
margin-right: 0;
|
|
33
|
+
width: ${({ $iconSize = 'var(--space-5)' }) => $iconSize};
|
|
34
|
+
height: ${({ $iconSize = 'var(--space-5)' }) => $iconSize};
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
&.large {
|
|
38
|
+
padding: var(--space-3);
|
|
39
|
+
height: var(--space-10);
|
|
40
|
+
width: var(--space-10);
|
|
41
|
+
svg {
|
|
42
|
+
margin-right: 0;
|
|
43
|
+
width: ${({ $iconSize = 'var(--space-6)' }) => $iconSize};
|
|
44
|
+
height: ${({ $iconSize = 'var(--space-6)' }) => $iconSize};
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
`,
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export const IconButton = forwardRef<
|
|
51
|
+
HTMLButtonElement,
|
|
52
|
+
IconButtonProps & ButtonHTMLAttributes<HTMLButtonElement>
|
|
53
|
+
>(({ icon: Icon, ...props }, ref) => (
|
|
54
|
+
<styles.IconButton ref={ref} {...props}>
|
|
55
|
+
<Icon className="iconbutton-icon" />
|
|
56
|
+
</styles.IconButton>
|
|
57
|
+
));
|