@addev-be/ui 0.3.2 → 0.3.5
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/icons/arrow-down-1-9.svg +1 -1
- package/assets/icons/arrow-down-a-z.svg +1 -1
- package/assets/icons/arrow-up-z-a.svg +1 -1
- package/assets/icons/check.svg +1 -1
- package/assets/icons/down.svg +1 -1
- package/assets/icons/filter-full.svg +1 -1
- package/assets/icons/filter.svg +1 -1
- package/assets/icons/hashtag.svg +1 -1
- package/assets/icons/image-slash.svg +1 -1
- package/assets/icons/left.svg +1 -1
- package/assets/icons/magnifier.svg +1 -1
- package/assets/icons/phone.svg +1 -1
- package/assets/icons/right.svg +1 -1
- package/assets/icons/sort-calendar-ascending.svg +5 -5
- package/assets/icons/spinner-third.svg +1 -1
- package/assets/icons/table-columns.svg +1 -1
- package/assets/icons/table-footer-slash.svg +4 -4
- package/assets/icons/table-footer.svg +3 -3
- package/assets/icons/up.svg +1 -1
- package/assets/icons/user-tie.svg +1 -1
- package/assets/icons/x-bar.svg +3 -3
- package/dist/Icons.d.ts +43 -0
- package/dist/Icons.js +116 -0
- package/dist/components/data/AdvancedRequestDataGrid/helpers/advancedRequests.d.ts +14 -0
- package/dist/components/data/AdvancedRequestDataGrid/helpers/advancedRequests.js +76 -0
- package/dist/components/data/AdvancedRequestDataGrid/helpers/columns.d.ts +22 -0
- package/dist/components/data/AdvancedRequestDataGrid/helpers/columns.js +156 -0
- package/dist/components/data/AdvancedRequestDataGrid/helpers/index.d.ts +2 -0
- package/dist/components/data/AdvancedRequestDataGrid/helpers/index.js +18 -0
- package/dist/components/data/AdvancedRequestDataGrid/index.d.ts +2 -0
- package/dist/components/data/AdvancedRequestDataGrid/index.js +215 -0
- package/dist/components/data/AdvancedRequestDataGrid/types.d.ts +21 -0
- package/dist/components/data/AdvancedRequestDataGrid/types.js +2 -0
- package/dist/components/data/DataGrid/AdvancedRequestDataGrid.d.ts +10 -0
- package/dist/components/data/DataGrid/AdvancedRequestDataGrid.js +173 -0
- package/dist/components/data/DataGrid/DataGridCell.d.ts +2 -0
- package/dist/components/data/DataGrid/DataGridCell.js +59 -0
- package/dist/components/data/DataGrid/DataGridColumnsModal/helpers.d.ts +2 -0
- package/dist/components/data/DataGrid/DataGridColumnsModal/helpers.js +24 -0
- package/dist/components/data/DataGrid/DataGridColumnsModal/hooks.d.ts +6 -0
- package/dist/components/data/DataGrid/DataGridColumnsModal/hooks.js +38 -0
- package/dist/components/data/DataGrid/DataGridColumnsModal/index.d.ts +15 -0
- package/dist/components/data/DataGrid/DataGridColumnsModal/index.js +111 -0
- package/dist/components/data/DataGrid/DataGridColumnsModal/styles.d.ts +22 -0
- package/dist/components/data/DataGrid/DataGridColumnsModal/styles.js +54 -0
- package/dist/components/data/DataGrid/DataGridEditableCell.d.ts +2 -0
- package/dist/components/data/DataGrid/DataGridEditableCell.js +27 -0
- package/dist/components/data/DataGrid/DataGridFilterMenu/hooks.d.ts +9 -0
- package/dist/components/data/DataGrid/DataGridFilterMenu/hooks.js +52 -0
- package/dist/components/data/DataGrid/DataGridFilterMenu/index.d.ts +9 -0
- package/dist/components/data/DataGrid/DataGridFilterMenu/index.js +220 -0
- package/dist/components/data/DataGrid/DataGridFilterMenu/styles.d.ts +9 -0
- package/dist/components/data/DataGrid/DataGridFilterMenu/styles.js +21 -0
- package/dist/components/data/DataGrid/DataGridFooter.d.ts +4 -0
- package/dist/components/data/DataGrid/DataGridFooter.js +44 -0
- package/dist/components/data/DataGrid/DataGridHeader.d.ts +4 -0
- package/dist/components/data/DataGrid/DataGridHeader.js +119 -0
- package/dist/components/data/DataGrid/DataGridHeaderCell.d.ts +2 -0
- package/dist/components/data/DataGrid/DataGridHeaderCell.js +84 -0
- package/dist/components/data/DataGrid/FilterModalContent/index.d.ts +7 -0
- package/dist/components/data/DataGrid/FilterModalContent/index.js +108 -0
- package/dist/components/data/DataGrid/FilterModalContent/styles.d.ts +3 -0
- package/dist/components/data/DataGrid/FilterModalContent/styles.js +15 -0
- package/dist/components/data/DataGrid/FilterValuesScroller.d.ts +13 -0
- package/dist/components/data/DataGrid/FilterValuesScroller.js +73 -0
- package/dist/components/data/DataGrid/VirtualScroller.d.ts +11 -0
- package/dist/components/data/DataGrid/VirtualScroller.js +41 -0
- package/dist/components/data/DataGrid/helpers/advancedRequests.d.ts +12 -0
- package/dist/components/data/DataGrid/helpers/advancedRequests.js +53 -0
- package/dist/components/data/DataGrid/helpers/columns.d.ts +12 -0
- package/dist/components/data/DataGrid/helpers/columns.js +162 -0
- package/dist/components/data/DataGrid/helpers/filters.d.ts +17 -0
- package/dist/components/data/DataGrid/helpers/filters.js +254 -0
- package/dist/components/data/DataGrid/helpers/index.d.ts +2 -0
- package/dist/components/data/DataGrid/helpers/index.js +18 -0
- package/dist/components/data/DataGrid/helpers.d.ts +28 -0
- package/dist/components/data/DataGrid/helpers.js +436 -0
- package/dist/components/data/DataGrid/hooks/index.d.ts +7 -0
- package/dist/components/data/DataGrid/hooks/index.js +34 -0
- package/dist/components/data/DataGrid/hooks/useDataGrid.d.ts +2 -0
- package/dist/components/data/DataGrid/hooks/useDataGrid.js +246 -0
- package/dist/components/data/DataGrid/hooks/useDataGridCopy.d.ts +4 -0
- package/dist/components/data/DataGrid/hooks/useDataGridCopy.js +171 -0
- package/dist/components/data/DataGrid/hooks/useDataGridSettings.d.ts +16 -0
- package/dist/components/data/DataGrid/hooks/useDataGridSettings.js +43 -0
- package/dist/components/data/DataGrid/index.d.ts +4 -0
- package/dist/components/data/DataGrid/index.js +108 -0
- package/dist/components/data/DataGrid/styles.d.ts +64 -0
- package/dist/components/data/DataGrid/styles.js +134 -0
- package/dist/components/data/DataGrid/types.d.ts +162 -0
- package/dist/components/data/DataGrid/types.js +34 -0
- package/dist/components/data/SqlRequestDataGrid/helpers/columns.d.ts +16 -0
- package/dist/components/data/SqlRequestDataGrid/helpers/columns.js +125 -0
- package/dist/components/data/SqlRequestDataGrid/helpers/index.d.ts +2 -0
- package/dist/components/data/SqlRequestDataGrid/helpers/index.js +18 -0
- package/dist/components/data/SqlRequestDataGrid/helpers/sqlRequests.d.ts +3 -0
- package/dist/components/data/SqlRequestDataGrid/helpers/sqlRequests.js +18 -0
- package/dist/components/data/SqlRequestDataGrid/index.d.ts +2 -0
- package/dist/components/data/SqlRequestDataGrid/index.js +296 -0
- package/dist/components/data/SqlRequestDataGrid/types.d.ts +21 -0
- package/dist/components/data/SqlRequestDataGrid/types.js +2 -0
- package/dist/components/data/index.d.ts +8 -0
- package/dist/components/data/index.js +24 -0
- package/dist/components/forms/Button.d.ts +10 -0
- package/dist/components/forms/Button.js +70 -0
- package/dist/components/forms/IconButton.d.ts +7 -0
- package/dist/components/forms/IconButton.js +64 -0
- package/dist/components/forms/IndeterminateCheckbox.d.ts +8 -0
- package/dist/components/forms/IndeterminateCheckbox.js +41 -0
- package/dist/components/forms/Select.d.ts +10 -0
- package/dist/components/forms/Select.js +49 -0
- package/dist/components/forms/index.d.ts +5 -0
- package/dist/components/forms/index.js +23 -0
- package/dist/components/forms/styles.d.ts +2 -0
- package/dist/components/forms/styles.js +34 -0
- package/dist/components/index.d.ts +3 -0
- package/dist/components/index.js +19 -0
- package/dist/components/layout/Dropdown/index.d.ts +11 -0
- package/dist/components/layout/Dropdown/index.js +85 -0
- package/dist/components/layout/Dropdown/styles.d.ts +11 -0
- package/dist/components/layout/Dropdown/styles.js +45 -0
- package/dist/components/layout/Loading/index.d.ts +6 -0
- package/dist/components/layout/Loading/index.js +42 -0
- package/dist/components/layout/Loading/styles.d.ts +6 -0
- package/dist/components/layout/Loading/styles.js +18 -0
- package/dist/components/layout/Modal/index.d.ts +16 -0
- package/dist/components/layout/Modal/index.js +67 -0
- package/dist/components/layout/Modal/styles.d.ts +32 -0
- package/dist/components/layout/Modal/styles.js +52 -0
- package/dist/components/layout/index.d.ts +3 -0
- package/dist/components/layout/index.js +19 -0
- package/dist/components/ui/ContextMenu/index.d.ts +11 -0
- package/dist/components/ui/ContextMenu/index.js +58 -0
- package/dist/components/ui/ContextMenu/styles.d.ts +18 -0
- package/dist/components/ui/ContextMenu/styles.js +56 -0
- package/dist/config/index.d.ts +10 -0
- package/dist/config/index.js +2 -0
- package/dist/config/types.d.ts +11 -0
- package/dist/config/types.js +2 -0
- package/dist/helpers/dates.d.ts +2 -0
- package/dist/helpers/dates.js +13 -0
- package/dist/helpers/getScrollbarSize.d.ts +1 -0
- package/dist/helpers/getScrollbarSize.js +17 -0
- package/dist/helpers/numbers.d.ts +3 -0
- package/dist/helpers/numbers.js +31 -0
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/index.js +18 -0
- package/dist/hooks/useElementSize.d.ts +4 -0
- package/dist/hooks/useElementSize.js +23 -0
- package/dist/hooks/useWindowSize.d.ts +4 -0
- package/dist/hooks/useWindowSize.js +19 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +21 -0
- package/dist/providers/PortalsProvider/index.d.ts +10 -0
- package/dist/providers/PortalsProvider/index.js +46 -0
- package/dist/providers/PortalsProvider/styles.d.ts +9 -0
- package/dist/providers/PortalsProvider/styles.js +21 -0
- package/dist/providers/SettingsProvider/index.d.ts +8 -0
- package/dist/providers/SettingsProvider/index.js +54 -0
- package/dist/providers/ThemeProvider/ThemeProvider.d.ts +7 -0
- package/dist/providers/ThemeProvider/ThemeProvider.js +51 -0
- package/dist/providers/ThemeProvider/defaultTheme.d.ts +2 -0
- package/dist/providers/ThemeProvider/defaultTheme.js +417 -0
- package/dist/providers/ThemeProvider/index.d.ts +2 -0
- package/dist/providers/ThemeProvider/index.js +5 -0
- package/dist/providers/ThemeProvider/types.d.ts +24 -0
- package/dist/providers/ThemeProvider/types.js +2 -0
- package/dist/providers/UiProviders/index.d.ts +12 -0
- package/dist/providers/UiProviders/index.js +62 -0
- package/dist/providers/UiProviders/styles.d.ts +3 -0
- package/dist/providers/UiProviders/styles.js +13 -0
- package/dist/providers/hooks.d.ts +3 -0
- package/dist/providers/hooks.js +13 -0
- package/dist/providers/index.d.ts +4 -0
- package/dist/providers/index.js +20 -0
- package/dist/services/HttpService.d.ts +10 -0
- package/dist/services/HttpService.js +117 -0
- package/dist/services/WebSocketService.d.ts +24 -0
- package/dist/services/WebSocketService.js +136 -0
- package/dist/services/advancedRequests.d.ts +41 -0
- package/dist/services/advancedRequests.js +13 -0
- package/dist/services/base.d.ts +19 -0
- package/dist/services/base.js +10 -0
- package/dist/services/hooks.d.ts +2 -0
- package/dist/services/hooks.js +18 -0
- package/dist/services/index.d.ts +2 -0
- package/dist/services/index.js +18 -0
- package/dist/services/sqlRequests.d.ts +45 -0
- package/dist/services/sqlRequests.js +11 -0
- package/package.json +2 -1
- package/src/Icons.tsx +108 -108
- package/src/components/data/AdvancedRequestDataGrid/helpers/advancedRequests.ts +93 -93
- package/src/components/data/AdvancedRequestDataGrid/helpers/columns.tsx +262 -262
- package/src/components/data/AdvancedRequestDataGrid/helpers/index.ts +2 -2
- package/src/components/data/AdvancedRequestDataGrid/index.tsx +267 -267
- package/src/components/data/AdvancedRequestDataGrid/types.ts +47 -47
- package/src/components/data/DataGrid/DataGridCell.tsx +73 -73
- package/src/components/data/DataGrid/DataGridColumnsModal/helpers.ts +14 -14
- package/src/components/data/DataGrid/DataGridColumnsModal/hooks.tsx +59 -59
- package/src/components/data/DataGrid/DataGridColumnsModal/index.tsx +181 -181
- package/src/components/data/DataGrid/DataGridColumnsModal/styles.ts +104 -104
- package/src/components/data/DataGrid/DataGridEditableCell.tsx +43 -43
- package/src/components/data/DataGrid/DataGridFilterMenu/FilterValuesScroller.tsx +120 -120
- package/src/components/data/DataGrid/DataGridFilterMenu/hooks.tsx +75 -75
- package/src/components/data/DataGrid/DataGridFilterMenu/index.tsx +360 -360
- package/src/components/data/DataGrid/DataGridFilterMenu/styles.ts +96 -96
- package/src/components/data/DataGrid/DataGridFooter.tsx +42 -42
- package/src/components/data/DataGrid/DataGridHeader.tsx +126 -126
- package/src/components/data/DataGrid/DataGridHeaderCell.tsx +132 -132
- package/src/components/data/DataGrid/FilterModalContent/index.tsx +136 -136
- package/src/components/data/DataGrid/FilterModalContent/styles.ts +22 -22
- package/src/components/data/DataGrid/VirtualScroller.tsx +46 -46
- package/src/components/data/DataGrid/helpers/columns.tsx +295 -295
- package/src/components/data/DataGrid/helpers/filters.ts +287 -287
- package/src/components/data/DataGrid/helpers/index.ts +2 -2
- package/src/components/data/DataGrid/hooks/index.ts +30 -30
- package/src/components/data/DataGrid/hooks/useDataGrid.tsx +306 -306
- package/src/components/data/DataGrid/hooks/useDataGridCopy.ts +175 -175
- package/src/components/data/DataGrid/hooks/useDataGridSettings.ts +48 -48
- package/src/components/data/DataGrid/index.tsx +140 -140
- package/src/components/data/DataGrid/styles.ts +323 -323
- package/src/components/data/DataGrid/types.ts +267 -267
- package/src/components/data/SqlRequestDataGrid/helpers/columns.tsx +277 -277
- package/src/components/data/SqlRequestDataGrid/helpers/index.ts +2 -2
- package/src/components/data/SqlRequestDataGrid/helpers/sqlRequests.ts +16 -16
- package/src/components/data/SqlRequestDataGrid/index.tsx +347 -347
- package/src/components/data/SqlRequestDataGrid/types.ts +47 -47
- package/src/components/data/index.ts +8 -8
- package/src/components/forms/Button.tsx +99 -99
- package/src/components/forms/IconButton.tsx +56 -56
- package/src/components/forms/IndeterminateCheckbox.tsx +46 -46
- package/src/components/forms/Select.tsx +40 -40
- package/src/components/forms/index.ts +5 -5
- package/src/components/forms/styles.ts +20 -20
- package/src/components/index.ts +4 -3
- package/src/components/layout/Dropdown/index.tsx +80 -79
- package/src/components/layout/Dropdown/styles.ts +45 -44
- package/src/components/layout/Loading/index.tsx +29 -29
- package/src/components/layout/Loading/styles.ts +29 -29
- package/src/components/layout/Modal/index.tsx +51 -51
- package/src/components/layout/Modal/styles.ts +110 -110
- package/src/components/layout/index.ts +3 -3
- package/src/components/search/HighlightedText.tsx +30 -0
- package/src/components/search/QuickSearchBar.tsx +78 -0
- package/src/components/search/QuickSearchResults.tsx +86 -0
- package/src/components/search/index.ts +5 -0
- package/src/components/search/styles.ts +60 -0
- package/src/components/search/types.ts +26 -0
- package/src/components/ui/ContextMenu/index.tsx +79 -79
- package/src/components/ui/ContextMenu/styles.ts +119 -119
- package/src/config/index.ts +14 -14
- package/src/helpers/dates.ts +9 -9
- package/src/helpers/getScrollbarSize.ts +14 -14
- package/src/helpers/index.ts +2 -0
- package/src/helpers/numbers.ts +26 -26
- package/src/hooks/index.ts +2 -2
- package/src/hooks/useElementSize.ts +24 -24
- package/src/hooks/useWindowSize.ts +20 -20
- package/src/index.ts +8 -7
- package/src/providers/AuthenticationProvider/index.tsx +199 -143
- package/src/providers/LoadingProvider/index.tsx +47 -47
- package/src/providers/PortalsProvider/index.tsx +54 -54
- package/src/providers/PortalsProvider/styles.ts +27 -27
- package/src/providers/SettingsProvider/index.tsx +70 -70
- package/src/providers/ThemeProvider/ThemeProvider.ts +55 -55
- package/src/providers/ThemeProvider/defaultTheme.ts +444 -444
- package/src/providers/ThemeProvider/index.ts +4 -4
- package/src/providers/ThemeProvider/types.ts +123 -123
- package/src/providers/UiProviders/index.tsx +65 -65
- package/src/providers/UiProviders/styles.ts +10 -10
- package/src/providers/hooks.ts +12 -10
- package/src/providers/index.ts +6 -6
- package/src/services/HttpService.ts +80 -80
- package/src/services/WebSocketService.ts +136 -136
- package/src/services/advancedRequests.ts +101 -101
- package/src/services/base.ts +31 -31
- package/src/services/globalSearch.ts +27 -27
- package/src/services/hooks.ts +40 -40
- package/src/services/index.ts +9 -8
- package/src/services/requests/auth.ts +44 -44
- package/src/services/sqlRequests.ts +110 -110
- package/src/services/types/auth.ts +131 -131
- package/src/services/types/base.ts +10 -10
- package/src/services/types/users.ts +20 -20
- package/src/styles/animations.scss +30 -30
- package/src/styles/index.scss +42 -42
- package/src/typings.d.ts +6 -6
- package/tsconfig.tsbuildinfo +1 -0
|
@@ -1,110 +1,110 @@
|
|
|
1
|
-
import styled, { css } from 'styled-components';
|
|
2
|
-
|
|
3
|
-
export const ModalBackdrop = styled.div.attrs({
|
|
4
|
-
className: 'ModalBackdrop',
|
|
5
|
-
})`
|
|
6
|
-
position: fixed;
|
|
7
|
-
z-index: 1000;
|
|
8
|
-
top: 0;
|
|
9
|
-
left: 0;
|
|
10
|
-
right: 0;
|
|
11
|
-
bottom: 0;
|
|
12
|
-
background-color: rgba(0, 0, 0, 0.5);
|
|
13
|
-
display: flex;
|
|
14
|
-
justify-content: center;
|
|
15
|
-
align-items: center;
|
|
16
|
-
`;
|
|
17
|
-
|
|
18
|
-
export type ModalContainerProps = {
|
|
19
|
-
$width?: number;
|
|
20
|
-
$height?: number;
|
|
21
|
-
$zIndex?: number;
|
|
22
|
-
$fullscreen?: boolean;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export const ModalContainer = styled.div.attrs({
|
|
26
|
-
className: 'ModalContainer',
|
|
27
|
-
})<ModalContainerProps>`
|
|
28
|
-
background: var(--color-neutral-100);
|
|
29
|
-
border-radius: var(--rounded-lg);
|
|
30
|
-
box-shadow: var(--shadow-lg);
|
|
31
|
-
display: flex;
|
|
32
|
-
flex-direction: column;
|
|
33
|
-
max-height: 100vh;
|
|
34
|
-
overflow: hidden;
|
|
35
|
-
|
|
36
|
-
position: fixed;
|
|
37
|
-
z-index: 1001;
|
|
38
|
-
${({ $fullscreen, $width, $height }) =>
|
|
39
|
-
$fullscreen
|
|
40
|
-
? css`
|
|
41
|
-
top: 0;
|
|
42
|
-
left: 0;
|
|
43
|
-
right: 0;
|
|
44
|
-
bottom: 0;
|
|
45
|
-
margin: var(--space-4);
|
|
46
|
-
`
|
|
47
|
-
: css`
|
|
48
|
-
top: 50%;
|
|
49
|
-
left: 50%;
|
|
50
|
-
transform: translate(-50%, -50%);
|
|
51
|
-
width: ${$width ? `${$width}px` : 'auto'};
|
|
52
|
-
height: ${$height ? `${$height}px` : 'auto'};
|
|
53
|
-
`}
|
|
54
|
-
`;
|
|
55
|
-
|
|
56
|
-
export const ModalHeader = styled.div.attrs({ className: 'ModalHeader' })`
|
|
57
|
-
font-weight: bold;
|
|
58
|
-
font-size: var(--text-lg);
|
|
59
|
-
padding: var(--space-2);
|
|
60
|
-
background-color: var(--color-neutral-200);
|
|
61
|
-
padding: var(--space-4);
|
|
62
|
-
`;
|
|
63
|
-
|
|
64
|
-
export const ModalMessage = styled.p.attrs({ className: 'ModalMessage' })`
|
|
65
|
-
margin-bottom: 1rem;
|
|
66
|
-
`;
|
|
67
|
-
|
|
68
|
-
export const ModalContent = styled.div.attrs({ className: 'ModalContent' })`
|
|
69
|
-
display: flex;
|
|
70
|
-
flex-direction: column;
|
|
71
|
-
flex: 1;
|
|
72
|
-
overflow: auto;
|
|
73
|
-
padding: var(--space-4);
|
|
74
|
-
`;
|
|
75
|
-
|
|
76
|
-
export const ModalContentWithIcon = styled.div.attrs({
|
|
77
|
-
className: 'ModalContentWithIcon',
|
|
78
|
-
})`
|
|
79
|
-
display: flex;
|
|
80
|
-
flex-direction: row;
|
|
81
|
-
padding: var(--space-4);
|
|
82
|
-
gap: var(--space-2);
|
|
83
|
-
|
|
84
|
-
& > svg {
|
|
85
|
-
margin: var(--space-2);
|
|
86
|
-
width: var(--space-8);
|
|
87
|
-
height: var(--space-8);
|
|
88
|
-
}
|
|
89
|
-
`;
|
|
90
|
-
|
|
91
|
-
export const ModalFooter = styled.div.attrs({ className: 'ModalFooter' })`
|
|
92
|
-
display: flex;
|
|
93
|
-
flex-direction: row;
|
|
94
|
-
justify-content: space-between;
|
|
95
|
-
padding: var(--space-2);
|
|
96
|
-
background-color: var(--color-neutral-200);
|
|
97
|
-
padding: var(--space-4);
|
|
98
|
-
`;
|
|
99
|
-
|
|
100
|
-
export const ModalButtons = styled(ModalFooter).attrs({
|
|
101
|
-
className: 'ModalButtons',
|
|
102
|
-
})`
|
|
103
|
-
display: flex;
|
|
104
|
-
flex-direction: row;
|
|
105
|
-
gap: var(--space-2);
|
|
106
|
-
|
|
107
|
-
button.right:first-of-type {
|
|
108
|
-
margin-left: auto;
|
|
109
|
-
}
|
|
110
|
-
`;
|
|
1
|
+
import styled, { css } from 'styled-components';
|
|
2
|
+
|
|
3
|
+
export const ModalBackdrop = styled.div.attrs({
|
|
4
|
+
className: 'ModalBackdrop',
|
|
5
|
+
})`
|
|
6
|
+
position: fixed;
|
|
7
|
+
z-index: 1000;
|
|
8
|
+
top: 0;
|
|
9
|
+
left: 0;
|
|
10
|
+
right: 0;
|
|
11
|
+
bottom: 0;
|
|
12
|
+
background-color: rgba(0, 0, 0, 0.5);
|
|
13
|
+
display: flex;
|
|
14
|
+
justify-content: center;
|
|
15
|
+
align-items: center;
|
|
16
|
+
`;
|
|
17
|
+
|
|
18
|
+
export type ModalContainerProps = {
|
|
19
|
+
$width?: number;
|
|
20
|
+
$height?: number;
|
|
21
|
+
$zIndex?: number;
|
|
22
|
+
$fullscreen?: boolean;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const ModalContainer = styled.div.attrs({
|
|
26
|
+
className: 'ModalContainer',
|
|
27
|
+
})<ModalContainerProps>`
|
|
28
|
+
background: var(--color-neutral-100);
|
|
29
|
+
border-radius: var(--rounded-lg);
|
|
30
|
+
box-shadow: var(--shadow-lg);
|
|
31
|
+
display: flex;
|
|
32
|
+
flex-direction: column;
|
|
33
|
+
max-height: 100vh;
|
|
34
|
+
overflow: hidden;
|
|
35
|
+
|
|
36
|
+
position: fixed;
|
|
37
|
+
z-index: 1001;
|
|
38
|
+
${({ $fullscreen, $width, $height }) =>
|
|
39
|
+
$fullscreen
|
|
40
|
+
? css`
|
|
41
|
+
top: 0;
|
|
42
|
+
left: 0;
|
|
43
|
+
right: 0;
|
|
44
|
+
bottom: 0;
|
|
45
|
+
margin: var(--space-4);
|
|
46
|
+
`
|
|
47
|
+
: css`
|
|
48
|
+
top: 50%;
|
|
49
|
+
left: 50%;
|
|
50
|
+
transform: translate(-50%, -50%);
|
|
51
|
+
width: ${$width ? `${$width}px` : 'auto'};
|
|
52
|
+
height: ${$height ? `${$height}px` : 'auto'};
|
|
53
|
+
`}
|
|
54
|
+
`;
|
|
55
|
+
|
|
56
|
+
export const ModalHeader = styled.div.attrs({ className: 'ModalHeader' })`
|
|
57
|
+
font-weight: bold;
|
|
58
|
+
font-size: var(--text-lg);
|
|
59
|
+
padding: var(--space-2);
|
|
60
|
+
background-color: var(--color-neutral-200);
|
|
61
|
+
padding: var(--space-4);
|
|
62
|
+
`;
|
|
63
|
+
|
|
64
|
+
export const ModalMessage = styled.p.attrs({ className: 'ModalMessage' })`
|
|
65
|
+
margin-bottom: 1rem;
|
|
66
|
+
`;
|
|
67
|
+
|
|
68
|
+
export const ModalContent = styled.div.attrs({ className: 'ModalContent' })`
|
|
69
|
+
display: flex;
|
|
70
|
+
flex-direction: column;
|
|
71
|
+
flex: 1;
|
|
72
|
+
overflow: auto;
|
|
73
|
+
padding: var(--space-4);
|
|
74
|
+
`;
|
|
75
|
+
|
|
76
|
+
export const ModalContentWithIcon = styled.div.attrs({
|
|
77
|
+
className: 'ModalContentWithIcon',
|
|
78
|
+
})`
|
|
79
|
+
display: flex;
|
|
80
|
+
flex-direction: row;
|
|
81
|
+
padding: var(--space-4);
|
|
82
|
+
gap: var(--space-2);
|
|
83
|
+
|
|
84
|
+
& > svg {
|
|
85
|
+
margin: var(--space-2);
|
|
86
|
+
width: var(--space-8);
|
|
87
|
+
height: var(--space-8);
|
|
88
|
+
}
|
|
89
|
+
`;
|
|
90
|
+
|
|
91
|
+
export const ModalFooter = styled.div.attrs({ className: 'ModalFooter' })`
|
|
92
|
+
display: flex;
|
|
93
|
+
flex-direction: row;
|
|
94
|
+
justify-content: space-between;
|
|
95
|
+
padding: var(--space-2);
|
|
96
|
+
background-color: var(--color-neutral-200);
|
|
97
|
+
padding: var(--space-4);
|
|
98
|
+
`;
|
|
99
|
+
|
|
100
|
+
export const ModalButtons = styled(ModalFooter).attrs({
|
|
101
|
+
className: 'ModalButtons',
|
|
102
|
+
})`
|
|
103
|
+
display: flex;
|
|
104
|
+
flex-direction: row;
|
|
105
|
+
gap: var(--space-2);
|
|
106
|
+
|
|
107
|
+
button.right:first-of-type {
|
|
108
|
+
margin-left: auto;
|
|
109
|
+
}
|
|
110
|
+
`;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './Dropdown';
|
|
2
|
-
export * from './Modal';
|
|
3
|
-
export * from './Loading';
|
|
1
|
+
export * from './Dropdown';
|
|
2
|
+
export * from './Modal';
|
|
3
|
+
export * from './Loading';
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { FC, HTMLAttributes } from 'react';
|
|
2
|
+
|
|
3
|
+
export const HighlightedText: FC<
|
|
4
|
+
{
|
|
5
|
+
text: string;
|
|
6
|
+
highlight?: string;
|
|
7
|
+
style?: React.CSSProperties;
|
|
8
|
+
} & HTMLAttributes<HTMLSpanElement>
|
|
9
|
+
> = ({ text, highlight, ...props }) => {
|
|
10
|
+
const parts = text?.split(new RegExp(`(${highlight})`, 'gi')) ?? [];
|
|
11
|
+
if (!highlight) return <span {...props}>{text}</span>;
|
|
12
|
+
return (
|
|
13
|
+
<span {...props}>
|
|
14
|
+
{parts
|
|
15
|
+
.filter((part) => !!part)
|
|
16
|
+
.map((part, index) => (
|
|
17
|
+
<span
|
|
18
|
+
key={index}
|
|
19
|
+
style={
|
|
20
|
+
part.toLowerCase() === highlight.toLowerCase()
|
|
21
|
+
? { backgroundColor: 'gold' }
|
|
22
|
+
: {}
|
|
23
|
+
}
|
|
24
|
+
>
|
|
25
|
+
{part}
|
|
26
|
+
</span>
|
|
27
|
+
))}
|
|
28
|
+
</span>
|
|
29
|
+
);
|
|
30
|
+
};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { SearchResults, SearchTypeDefinitions } from './types';
|
|
2
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
3
|
+
|
|
4
|
+
import { Dropdown } from '../layout';
|
|
5
|
+
import { QuickSearchBarInput } from './styles';
|
|
6
|
+
import { QuickSearchResults } from './QuickSearchResults';
|
|
7
|
+
import { useDebounce } from '@uidotdev/usehooks';
|
|
8
|
+
import { useGlobalSearchRequestHandler } from '../../services';
|
|
9
|
+
|
|
10
|
+
type QuickSearchBarProps<R> = {
|
|
11
|
+
definitions: SearchTypeDefinitions<R>;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const QuickSearchBar = <R,>({ definitions }: QuickSearchBarProps<R>) => {
|
|
15
|
+
const [term, setTerm] = useState('');
|
|
16
|
+
const [dropdownVisible, setDropdownVisible] = useState(false);
|
|
17
|
+
const debouncedTerm = useDebounce(term, 300);
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
19
|
+
const [results, setResults] = useState<SearchResults<R> | null>(null);
|
|
20
|
+
|
|
21
|
+
const inputRef = useRef<HTMLInputElement | null>(null);
|
|
22
|
+
const rect = inputRef.current?.getBoundingClientRect() ?? new DOMRect();
|
|
23
|
+
const globalSearch = useGlobalSearchRequestHandler();
|
|
24
|
+
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
if (debouncedTerm) {
|
|
27
|
+
globalSearch({
|
|
28
|
+
types: ['Customer', 'ScanGroup'],
|
|
29
|
+
searchTerm: debouncedTerm,
|
|
30
|
+
limit: 5,
|
|
31
|
+
}).then((response) => {
|
|
32
|
+
setResults(response.data as SearchResults<R>);
|
|
33
|
+
setDropdownVisible(true);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}, [globalSearch, debouncedTerm]);
|
|
37
|
+
|
|
38
|
+
const onFocus = useCallback(() => {
|
|
39
|
+
if (term) {
|
|
40
|
+
setDropdownVisible(true);
|
|
41
|
+
}
|
|
42
|
+
}, [term]);
|
|
43
|
+
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
const input = inputRef.current;
|
|
46
|
+
input?.addEventListener('focus', onFocus);
|
|
47
|
+
return () => {
|
|
48
|
+
input?.removeEventListener('focus', onFocus);
|
|
49
|
+
};
|
|
50
|
+
}, [onFocus]);
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<>
|
|
54
|
+
<QuickSearchBarInput
|
|
55
|
+
type="text"
|
|
56
|
+
value={term}
|
|
57
|
+
onChange={(e) => setTerm(e.target.value)}
|
|
58
|
+
ref={inputRef}
|
|
59
|
+
$opened={dropdownVisible}
|
|
60
|
+
/>
|
|
61
|
+
{results && dropdownVisible && rect && (
|
|
62
|
+
<Dropdown
|
|
63
|
+
$sourceRect={rect}
|
|
64
|
+
onClose={() => setDropdownVisible(false)}
|
|
65
|
+
$width={rect.width}
|
|
66
|
+
$height={[250, 400]}
|
|
67
|
+
$autoPositionY={false}
|
|
68
|
+
>
|
|
69
|
+
<QuickSearchResults
|
|
70
|
+
results={results}
|
|
71
|
+
definitions={definitions}
|
|
72
|
+
term={debouncedTerm}
|
|
73
|
+
/>
|
|
74
|
+
</Dropdown>
|
|
75
|
+
)}
|
|
76
|
+
</>
|
|
77
|
+
);
|
|
78
|
+
};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import * as styles from './styles';
|
|
2
|
+
|
|
3
|
+
import { ReactNode, useMemo, useState } from 'react';
|
|
4
|
+
import { ResultArray, SearchResults, SearchTypeDefinitions } from './types';
|
|
5
|
+
|
|
6
|
+
import { pickBy } from 'lodash';
|
|
7
|
+
|
|
8
|
+
type QuickSearchResultsProps<R> = {
|
|
9
|
+
definitions: SearchTypeDefinitions<R>;
|
|
10
|
+
results: SearchResults<R>;
|
|
11
|
+
term: string;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const QuickSearchResults = <R,>(props: QuickSearchResultsProps<R>) => {
|
|
15
|
+
const { definitions, results: allResults, term } = props;
|
|
16
|
+
const [highlightedIndex, setHighlightedIndex] = useState(-1);
|
|
17
|
+
|
|
18
|
+
const notEmptyResults = pickBy<R[keyof R][]>(
|
|
19
|
+
allResults,
|
|
20
|
+
(results) => results.length > 0
|
|
21
|
+
);
|
|
22
|
+
const resultsArray = useMemo(
|
|
23
|
+
() =>
|
|
24
|
+
Object.keys(notEmptyResults).reduce(
|
|
25
|
+
(acc, type) => [
|
|
26
|
+
...acc,
|
|
27
|
+
...notEmptyResults[type].map((result) => ({
|
|
28
|
+
result,
|
|
29
|
+
type: type as keyof R,
|
|
30
|
+
})),
|
|
31
|
+
],
|
|
32
|
+
[] as ResultArray<R>
|
|
33
|
+
),
|
|
34
|
+
[notEmptyResults]
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
const elements = useMemo(() => {
|
|
38
|
+
const elements: ReactNode[] = [];
|
|
39
|
+
let currentType: keyof R | null = null;
|
|
40
|
+
resultsArray.forEach(({ result, type }, index) => {
|
|
41
|
+
const definition = definitions[type];
|
|
42
|
+
if (currentType !== type) {
|
|
43
|
+
currentType = type;
|
|
44
|
+
elements.push(
|
|
45
|
+
<styles.QuickSearchResultsTitle key={`title-${String(type)}`}>
|
|
46
|
+
{definition.title}
|
|
47
|
+
</styles.QuickSearchResultsTitle>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
elements.push(
|
|
51
|
+
<styles.QuickSearchResultsItem
|
|
52
|
+
key={`result-${index}`}
|
|
53
|
+
onClick={() => definition.onClick?.(result)}
|
|
54
|
+
onMouseEnter={() => setHighlightedIndex(index)}
|
|
55
|
+
className={highlightedIndex === index ? 'highlighted' : ''}
|
|
56
|
+
>
|
|
57
|
+
{definition.quickRenderer(result, term)}
|
|
58
|
+
</styles.QuickSearchResultsItem>
|
|
59
|
+
);
|
|
60
|
+
});
|
|
61
|
+
return elements;
|
|
62
|
+
}, [definitions, highlightedIndex, resultsArray, term]);
|
|
63
|
+
|
|
64
|
+
const highlightedResult = resultsArray[highlightedIndex];
|
|
65
|
+
const highlightedDefinition = highlightedResult
|
|
66
|
+
? definitions[highlightedResult?.type]
|
|
67
|
+
: null;
|
|
68
|
+
|
|
69
|
+
return (
|
|
70
|
+
<styles.QuickSearchResultsContainer>
|
|
71
|
+
<styles.QuickSearchResultsListContainer>
|
|
72
|
+
{elements}
|
|
73
|
+
</styles.QuickSearchResultsListContainer>
|
|
74
|
+
{highlightedDefinition && (
|
|
75
|
+
<styles.QuickSearchResultsDetailsContainer>
|
|
76
|
+
{highlightedDefinition.titleRenderer(highlightedResult.result, term)}
|
|
77
|
+
<styles.QuickSearchResultsDetailsDivider />
|
|
78
|
+
{highlightedDefinition.detailsRenderer(
|
|
79
|
+
highlightedResult.result,
|
|
80
|
+
term
|
|
81
|
+
)}
|
|
82
|
+
</styles.QuickSearchResultsDetailsContainer>
|
|
83
|
+
)}
|
|
84
|
+
</styles.QuickSearchResultsContainer>
|
|
85
|
+
);
|
|
86
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Input } from '../forms';
|
|
2
|
+
import styled from 'styled-components';
|
|
3
|
+
|
|
4
|
+
export const QuickSearchResultsContainer = styled.div`
|
|
5
|
+
display: flex;
|
|
6
|
+
flex-direction: row;
|
|
7
|
+
height: 100%;
|
|
8
|
+
`;
|
|
9
|
+
|
|
10
|
+
export const QuickSearchResultsListContainer = styled.div`
|
|
11
|
+
display: flex;
|
|
12
|
+
flex-direction: column;
|
|
13
|
+
padding: var(--space-2);
|
|
14
|
+
border-right: 1px solid var(--color-gray-200);
|
|
15
|
+
flex: 3;
|
|
16
|
+
overflow: auto;
|
|
17
|
+
`;
|
|
18
|
+
|
|
19
|
+
export const QuickSearchResultsTitle = styled.div`
|
|
20
|
+
margin: 0;
|
|
21
|
+
margin-bottom: var(--space-1);
|
|
22
|
+
&:not(:first-child) {
|
|
23
|
+
margin-top: var(--space-2);
|
|
24
|
+
}
|
|
25
|
+
font-weight: bold;
|
|
26
|
+
font-size: var(--text-lg);
|
|
27
|
+
`;
|
|
28
|
+
|
|
29
|
+
export const QuickSearchResultsItem = styled.div`
|
|
30
|
+
padding: var(--space-2) var(--space-3);
|
|
31
|
+
cursor: pointer;
|
|
32
|
+
border-radius: 4px;
|
|
33
|
+
&:hover {
|
|
34
|
+
background-color: var(--color-gray-100);
|
|
35
|
+
}
|
|
36
|
+
`;
|
|
37
|
+
|
|
38
|
+
export const QuickSearchResultsDetailsContainer = styled.div`
|
|
39
|
+
display: flex;
|
|
40
|
+
flex-direction: column;
|
|
41
|
+
padding: var(--space-2);
|
|
42
|
+
flex: 1;
|
|
43
|
+
`;
|
|
44
|
+
|
|
45
|
+
export const QuickSearchResultsDetailsDivider = styled.hr`
|
|
46
|
+
margin: var(--space-2) 0;
|
|
47
|
+
height: 1px;
|
|
48
|
+
border: none;
|
|
49
|
+
background-color: var(--color-gray-200);
|
|
50
|
+
`;
|
|
51
|
+
|
|
52
|
+
export const QuickSearchResultDetailsTitle = styled.div`
|
|
53
|
+
margin: 0;
|
|
54
|
+
`;
|
|
55
|
+
|
|
56
|
+
export const QuickSearchBarInput = styled(Input)<{ $opened?: boolean }>`
|
|
57
|
+
position: relative;
|
|
58
|
+
width: 100%;
|
|
59
|
+
z-index: ${({ $opened }) => ($opened ? 10000 : 0)};
|
|
60
|
+
`;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { FC, ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
export type SearchTypeDefinition<T> = {
|
|
4
|
+
title: string;
|
|
5
|
+
quickRenderer: (result: T, term: string) => ReactNode;
|
|
6
|
+
titleRenderer: (result: T, term: string) => ReactNode;
|
|
7
|
+
detailsRenderer: (result: T, term: string) => ReactNode;
|
|
8
|
+
onClick?: (result: T) => void;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type SearchTypeDefinitions<R> = {
|
|
12
|
+
[K in keyof R]: SearchTypeDefinition<R[K]>;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export type SearchResults<R> = {
|
|
16
|
+
[K in keyof R]: Array<R[K]>;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export type SearchDetailsFC<T> = FC<{
|
|
20
|
+
searchResult: T;
|
|
21
|
+
}>;
|
|
22
|
+
|
|
23
|
+
export type ResultArray<R> = {
|
|
24
|
+
result: R[keyof R];
|
|
25
|
+
type: keyof R;
|
|
26
|
+
}[];
|
|
@@ -1,79 +1,79 @@
|
|
|
1
|
-
import { Divider, MenuContainer, MenuItemContainer, SubMenu } from './styles';
|
|
2
|
-
import {
|
|
3
|
-
FC,
|
|
4
|
-
HTMLAttributes,
|
|
5
|
-
PropsWithChildren,
|
|
6
|
-
useCallback,
|
|
7
|
-
useRef,
|
|
8
|
-
useState,
|
|
9
|
-
} from 'react';
|
|
10
|
-
|
|
11
|
-
type ContextMenuFC = FC<PropsWithChildren<HTMLAttributes<HTMLDivElement>>> & {
|
|
12
|
-
Item: typeof MenuItemContainer;
|
|
13
|
-
ParentItem: typeof ParentMenuItem;
|
|
14
|
-
Divider: typeof Divider;
|
|
15
|
-
SubMenu: typeof SubMenu;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export const ContextMenu: ContextMenuFC = ({ children }) => {
|
|
19
|
-
return (
|
|
20
|
-
<MenuContainer onClick={(e) => e.stopPropagation()}>
|
|
21
|
-
{children}
|
|
22
|
-
</MenuContainer>
|
|
23
|
-
);
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export const ParentMenuItem: FC<HTMLAttributes<HTMLDivElement>> = ({
|
|
27
|
-
children,
|
|
28
|
-
...props
|
|
29
|
-
}) => {
|
|
30
|
-
const [isOpened, setIsOpened] = useState(false);
|
|
31
|
-
const [isSubMenuLeft, setIsSubMenuLeft] = useState(false);
|
|
32
|
-
const [currentTimeout, setCurrentTimeout] = useState<number | null>(null);
|
|
33
|
-
const containerRef = useRef<HTMLDivElement | null>(null);
|
|
34
|
-
|
|
35
|
-
const stopTimeout = useCallback(() => {
|
|
36
|
-
if (currentTimeout) {
|
|
37
|
-
clearTimeout(currentTimeout);
|
|
38
|
-
}
|
|
39
|
-
setCurrentTimeout(null);
|
|
40
|
-
}, [currentTimeout]);
|
|
41
|
-
|
|
42
|
-
const startTimeout = useCallback(
|
|
43
|
-
(open: boolean) => {
|
|
44
|
-
stopTimeout();
|
|
45
|
-
setCurrentTimeout(
|
|
46
|
-
window.setTimeout(
|
|
47
|
-
() => {
|
|
48
|
-
const rect = containerRef.current?.getBoundingClientRect();
|
|
49
|
-
setIsSubMenuLeft(!!rect && rect.right + 280 > window.innerWidth);
|
|
50
|
-
setIsOpened(open);
|
|
51
|
-
},
|
|
52
|
-
open ? 100 : 300
|
|
53
|
-
)
|
|
54
|
-
);
|
|
55
|
-
},
|
|
56
|
-
[stopTimeout]
|
|
57
|
-
);
|
|
58
|
-
|
|
59
|
-
const open = useCallback(() => startTimeout(true), [startTimeout]);
|
|
60
|
-
const close = useCallback(() => startTimeout(false), [startTimeout]);
|
|
61
|
-
|
|
62
|
-
return (
|
|
63
|
-
<MenuItemContainer
|
|
64
|
-
ref={containerRef}
|
|
65
|
-
{...props}
|
|
66
|
-
className={`${isOpened ? 'opened' : ''} ${isSubMenuLeft ? 'left' : ''}`}
|
|
67
|
-
onMouseEnter={open}
|
|
68
|
-
onMouseLeave={close}
|
|
69
|
-
$withArrow
|
|
70
|
-
>
|
|
71
|
-
{children}
|
|
72
|
-
</MenuItemContainer>
|
|
73
|
-
);
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
ContextMenu.Item = MenuItemContainer;
|
|
77
|
-
ContextMenu.ParentItem = ParentMenuItem;
|
|
78
|
-
ContextMenu.Divider = Divider;
|
|
79
|
-
ContextMenu.SubMenu = SubMenu;
|
|
1
|
+
import { Divider, MenuContainer, MenuItemContainer, SubMenu } from './styles';
|
|
2
|
+
import {
|
|
3
|
+
FC,
|
|
4
|
+
HTMLAttributes,
|
|
5
|
+
PropsWithChildren,
|
|
6
|
+
useCallback,
|
|
7
|
+
useRef,
|
|
8
|
+
useState,
|
|
9
|
+
} from 'react';
|
|
10
|
+
|
|
11
|
+
type ContextMenuFC = FC<PropsWithChildren<HTMLAttributes<HTMLDivElement>>> & {
|
|
12
|
+
Item: typeof MenuItemContainer;
|
|
13
|
+
ParentItem: typeof ParentMenuItem;
|
|
14
|
+
Divider: typeof Divider;
|
|
15
|
+
SubMenu: typeof SubMenu;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const ContextMenu: ContextMenuFC = ({ children }) => {
|
|
19
|
+
return (
|
|
20
|
+
<MenuContainer onClick={(e) => e.stopPropagation()}>
|
|
21
|
+
{children}
|
|
22
|
+
</MenuContainer>
|
|
23
|
+
);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const ParentMenuItem: FC<HTMLAttributes<HTMLDivElement>> = ({
|
|
27
|
+
children,
|
|
28
|
+
...props
|
|
29
|
+
}) => {
|
|
30
|
+
const [isOpened, setIsOpened] = useState(false);
|
|
31
|
+
const [isSubMenuLeft, setIsSubMenuLeft] = useState(false);
|
|
32
|
+
const [currentTimeout, setCurrentTimeout] = useState<number | null>(null);
|
|
33
|
+
const containerRef = useRef<HTMLDivElement | null>(null);
|
|
34
|
+
|
|
35
|
+
const stopTimeout = useCallback(() => {
|
|
36
|
+
if (currentTimeout) {
|
|
37
|
+
clearTimeout(currentTimeout);
|
|
38
|
+
}
|
|
39
|
+
setCurrentTimeout(null);
|
|
40
|
+
}, [currentTimeout]);
|
|
41
|
+
|
|
42
|
+
const startTimeout = useCallback(
|
|
43
|
+
(open: boolean) => {
|
|
44
|
+
stopTimeout();
|
|
45
|
+
setCurrentTimeout(
|
|
46
|
+
window.setTimeout(
|
|
47
|
+
() => {
|
|
48
|
+
const rect = containerRef.current?.getBoundingClientRect();
|
|
49
|
+
setIsSubMenuLeft(!!rect && rect.right + 280 > window.innerWidth);
|
|
50
|
+
setIsOpened(open);
|
|
51
|
+
},
|
|
52
|
+
open ? 100 : 300
|
|
53
|
+
)
|
|
54
|
+
);
|
|
55
|
+
},
|
|
56
|
+
[stopTimeout]
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
const open = useCallback(() => startTimeout(true), [startTimeout]);
|
|
60
|
+
const close = useCallback(() => startTimeout(false), [startTimeout]);
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
<MenuItemContainer
|
|
64
|
+
ref={containerRef}
|
|
65
|
+
{...props}
|
|
66
|
+
className={`${isOpened ? 'opened' : ''} ${isSubMenuLeft ? 'left' : ''}`}
|
|
67
|
+
onMouseEnter={open}
|
|
68
|
+
onMouseLeave={close}
|
|
69
|
+
$withArrow
|
|
70
|
+
>
|
|
71
|
+
{children}
|
|
72
|
+
</MenuItemContainer>
|
|
73
|
+
);
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
ContextMenu.Item = MenuItemContainer;
|
|
77
|
+
ContextMenu.ParentItem = ParentMenuItem;
|
|
78
|
+
ContextMenu.Divider = Divider;
|
|
79
|
+
ContextMenu.SubMenu = SubMenu;
|