@zesty-io/material 0.1.0 → 0.1.3
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/es/ConfirmDialog/ConfirmDialog.stories.d.ts +6 -0
- package/es/ConfirmDialog/ConfirmDialog.stories.js +24 -0
- package/es/ConfirmDialog/index.d.ts +18 -0
- package/es/ConfirmDialog/index.js +11 -0
- package/es/CopyButton/index.js +3 -3
- package/es/FieldTypeColor/index.d.ts +1 -1
- package/es/FieldTypeColor/index.js +12 -16
- package/es/FieldTypeDate/FieldTypeDate.stories.js +1 -4
- package/es/FieldTypeDate/index.d.ts +4 -6
- package/es/FieldTypeDate/index.js +4 -8
- package/es/FieldTypeDateTime/FieldTypeDateTime.stories.js +1 -4
- package/es/FieldTypeDateTime/index.d.ts +4 -6
- package/es/FieldTypeDateTime/index.js +4 -8
- package/es/FieldTypeDropdown/FieldTypeDropwdon.stories.js +2 -1
- package/es/FieldTypeDropdown/index.d.ts +1 -1
- package/es/FieldTypeDropdown/index.js +5 -10
- package/es/FieldTypeNumber/FieldTypeNumber.stories.js +1 -0
- package/es/FieldTypeNumber/index.d.ts +1 -1
- package/es/FieldTypeNumber/index.js +4 -7
- package/es/FieldTypeOneToMany/FieldTypeOneToMany.stories.d.ts +5 -0
- package/es/FieldTypeOneToMany/FieldTypeOneToMany.stories.js +28 -0
- package/es/FieldTypeOneToMany/index.d.ts +32 -0
- package/es/FieldTypeOneToMany/index.js +29 -0
- package/es/FieldTypeOneToOne/FieldTypeOneToOne.stories.d.ts +5 -0
- package/es/FieldTypeOneToOne/FieldTypeOneToOne.stories.js +28 -0
- package/es/FieldTypeOneToOne/index.d.ts +34 -0
- package/es/FieldTypeOneToOne/index.js +33 -0
- package/es/FieldTypeSort/FieldTypeSort.stories.js +1 -0
- package/es/FieldTypeSort/index.d.ts +1 -1
- package/es/FieldTypeSort/index.js +17 -27
- package/es/FieldTypeText/FieldTypeText.stories.js +4 -2
- package/es/FieldTypeText/index.d.ts +1 -1
- package/es/FieldTypeText/index.js +4 -12
- package/es/FieldTypeUrl/index.d.ts +1 -1
- package/es/FieldTypeUrl/index.js +8 -16
- package/es/index.d.ts +3 -1
- package/es/index.js +3 -1
- package/es/theme/index.js +10 -0
- package/es/utils/virtualization.d.ts +2 -0
- package/es/utils/virtualization.js +63 -0
- package/package.json +5 -3
- package/src/{ConfirmModal/ConfirmModal.stories.tsx → ConfirmDialog/ConfirmDialog.stories.tsx} +0 -0
- package/src/{ConfirmModal → ConfirmDialog}/index.tsx +0 -0
- package/src/CopyButton/index.tsx +6 -6
- package/src/FieldTypeColor/index.tsx +5 -7
- package/src/FieldTypeDate/FieldTypeDate.stories.tsx +1 -4
- package/src/FieldTypeDate/index.tsx +22 -25
- package/src/FieldTypeDateTime/FieldTypeDateTime.stories.tsx +1 -4
- package/src/FieldTypeDateTime/index.tsx +23 -25
- package/src/FieldTypeDropdown/FieldTypeDropwdon.stories.tsx +2 -1
- package/src/FieldTypeDropdown/index.tsx +5 -7
- package/src/FieldTypeNumber/FieldTypeNumber.stories.tsx +1 -0
- package/src/FieldTypeNumber/index.tsx +5 -6
- package/src/FieldTypeOneToMany/FieldTypeOneToMany.stories.tsx +47 -0
- package/src/FieldTypeOneToMany/index.tsx +90 -0
- package/src/FieldTypeOneToOne/FieldTypeOneToOne.stories.tsx +46 -0
- package/src/FieldTypeOneToOne/index.tsx +96 -0
- package/src/FieldTypeSort/FieldTypeSort.stories.tsx +1 -0
- package/src/FieldTypeSort/index.tsx +9 -18
- package/src/FieldTypeText/FieldTypeText.stories.tsx +9 -5
- package/src/FieldTypeText/index.tsx +11 -18
- package/src/FieldTypeUrl/index.tsx +11 -18
- package/src/index.ts +3 -1
- package/src/theme/index.ts +10 -0
- package/src/utils/virtualization.tsx +107 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ReactNode, SyntheticEvent, useState } from 'react';
|
|
2
|
+
import { Story, Meta } from '@storybook/react/types-6-0';
|
|
3
|
+
import FieldTypeOneToOne, { FieldTypeOneToOneProps } from './';
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
title: 'FieldTypeOneToOne',
|
|
7
|
+
component: FieldTypeOneToOne,
|
|
8
|
+
argType: {},
|
|
9
|
+
} as Meta;
|
|
10
|
+
|
|
11
|
+
const Template: Story<FieldTypeOneToOneProps> = (args) => {
|
|
12
|
+
const [value, setValue] = useState<{component: string | ReactNode, value: string, inputLabel: string}>({component: '- None -', value: '0', inputLabel: '- None -'});
|
|
13
|
+
|
|
14
|
+
const [options, setOptions] = useState<{component: string | ReactNode, value: string, inputLabel: string}[]>([]);
|
|
15
|
+
|
|
16
|
+
const handleOnOpen = async () => {
|
|
17
|
+
const largeArr = new Array(1000).fill(null);
|
|
18
|
+
await new Promise((resolve) => setTimeout(resolve, 3000))
|
|
19
|
+
const data = largeArr.map((_, idx) => ({component: <div>{`Test ${idx}`}</div>, value: String(Math.random()), inputLabel: `Test ${idx}`}));
|
|
20
|
+
setOptions(data);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const handleOnChange = (e: SyntheticEvent<Element, Event>, option: {component: string | ReactNode, value: string, inputLabel: string}) => {
|
|
24
|
+
setValue(option);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<FieldTypeOneToOne
|
|
29
|
+
{...args}
|
|
30
|
+
value={value}
|
|
31
|
+
onChange={handleOnChange}
|
|
32
|
+
options={options}
|
|
33
|
+
onOpen={handleOnOpen}
|
|
34
|
+
/>
|
|
35
|
+
);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export const Default = Template.bind({});
|
|
39
|
+
Default.args = {
|
|
40
|
+
label: 'OneToOne label',
|
|
41
|
+
helperText: 'OneToOne helperText',
|
|
42
|
+
placeholder: 'OneToOne placeholder'
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { ReactNode, useState } from 'react';
|
|
2
|
+
import { AutocompleteProps, Popper, styled, TextField, FormLabel, FormControl, InputAdornment } from '@mui/material';
|
|
3
|
+
import Autocomplete, { autocompleteClasses } from '@mui/material/Autocomplete';
|
|
4
|
+
import { ListboxComponent } from '../utils/virtualization';
|
|
5
|
+
|
|
6
|
+
export interface FieldTypeOneToOneProps extends Omit<AutocompleteProps<any, false, false, false>, 'onOpen' | 'renderInput'> {
|
|
7
|
+
label?: string;
|
|
8
|
+
helperText?: string;
|
|
9
|
+
placeholder?: string;
|
|
10
|
+
error?: boolean;
|
|
11
|
+
required?: boolean;
|
|
12
|
+
startAdornment?: ReactNode;
|
|
13
|
+
endAdornment?: ReactNode;
|
|
14
|
+
/**
|
|
15
|
+
* Callback to be fired upon opening the dropdown
|
|
16
|
+
*/
|
|
17
|
+
onOpen?: () => Promise<any>;
|
|
18
|
+
/**
|
|
19
|
+
* Structure for option
|
|
20
|
+
*/
|
|
21
|
+
options: {
|
|
22
|
+
/**
|
|
23
|
+
* Component to be rendered in the dropdown
|
|
24
|
+
*/
|
|
25
|
+
component: ReactNode | string;
|
|
26
|
+
/**
|
|
27
|
+
* Value of option
|
|
28
|
+
*/
|
|
29
|
+
value: string;
|
|
30
|
+
/**
|
|
31
|
+
* Label that should display in the input when selected
|
|
32
|
+
*/
|
|
33
|
+
inputLabel: string;
|
|
34
|
+
}[]
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const FieldTypeOneToOne = ({label, helperText, placeholder, error, onOpen, options, required, startAdornment, endAdornment, ...props }: FieldTypeOneToOneProps) => {
|
|
38
|
+
const [loaded, setLoaded] = useState(false);
|
|
39
|
+
const [loading, setLoading] = useState(false);
|
|
40
|
+
|
|
41
|
+
const handleOpen = () => {
|
|
42
|
+
if (!loaded && onOpen) {
|
|
43
|
+
onOpen().then(() => {
|
|
44
|
+
setLoading(false);
|
|
45
|
+
});
|
|
46
|
+
setLoading(true);
|
|
47
|
+
setLoaded(true);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<FormControl fullWidth required={required}>
|
|
53
|
+
<FormLabel>{label}</FormLabel>
|
|
54
|
+
<Autocomplete
|
|
55
|
+
onOpen={handleOpen}
|
|
56
|
+
loading={loading}
|
|
57
|
+
fullWidth
|
|
58
|
+
disableListWrap
|
|
59
|
+
disableClearable
|
|
60
|
+
disablePortal
|
|
61
|
+
size='small'
|
|
62
|
+
PopperComponent={StyledPopper}
|
|
63
|
+
ListboxComponent={ListboxComponent}
|
|
64
|
+
renderInput={(params) => (
|
|
65
|
+
<TextField
|
|
66
|
+
{...params}
|
|
67
|
+
helperText={helperText}
|
|
68
|
+
error={error}
|
|
69
|
+
placeholder={placeholder}
|
|
70
|
+
InputProps={{
|
|
71
|
+
...params.InputProps,
|
|
72
|
+
startAdornment: <InputAdornment position='end'>{startAdornment}</InputAdornment>,
|
|
73
|
+
endAdornment: <>{params.InputProps.endAdornment}<InputAdornment sx={{ position: 'relative', right: '40px'}} position='end'>{endAdornment}</InputAdornment></>
|
|
74
|
+
}}
|
|
75
|
+
/>
|
|
76
|
+
)}
|
|
77
|
+
options={loading ? [] : options}
|
|
78
|
+
getOptionLabel={(option) => option.inputLabel}
|
|
79
|
+
renderOption={(props, option) => [props, option.component]}
|
|
80
|
+
{...props}
|
|
81
|
+
/>
|
|
82
|
+
</FormControl>
|
|
83
|
+
);
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export default FieldTypeOneToOne;
|
|
87
|
+
|
|
88
|
+
const StyledPopper = styled(Popper)({
|
|
89
|
+
[`& .${autocompleteClasses.listbox}`]: {
|
|
90
|
+
boxSizing: 'border-box',
|
|
91
|
+
'& ul': {
|
|
92
|
+
padding: 0,
|
|
93
|
+
margin: 0,
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import MuiTextField, { OutlinedTextFieldProps } from '@mui/material/TextField';
|
|
2
|
-
import { Button, InputAdornment } from '@mui/material';
|
|
2
|
+
import { Button, FormControl, FormLabel, InputAdornment } from '@mui/material';
|
|
3
3
|
import AddIcon from '@mui/icons-material/Add';
|
|
4
4
|
import RemoveIcon from '@mui/icons-material/Remove';
|
|
5
5
|
|
|
@@ -7,18 +7,15 @@ export interface FieldTypeSortProps extends Omit<OutlinedTextFieldProps, 'varian
|
|
|
7
7
|
value: string;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
const FieldTypeSort = ({value, InputProps,
|
|
10
|
+
const FieldTypeSort = ({label, value, InputProps, required, ...props }: FieldTypeSortProps) => {
|
|
11
11
|
return (
|
|
12
|
+
<FormControl fullWidth required={required}>
|
|
13
|
+
<FormLabel>{label}</FormLabel>
|
|
12
14
|
<MuiTextField
|
|
13
15
|
size="small"
|
|
14
16
|
variant='outlined'
|
|
15
17
|
type='number'
|
|
16
18
|
value={value}
|
|
17
|
-
sx={{
|
|
18
|
-
width: 165,
|
|
19
|
-
// Spread props at the end to allow sx prop overrides
|
|
20
|
-
...sx
|
|
21
|
-
}}
|
|
22
19
|
InputProps={{
|
|
23
20
|
startAdornment: (
|
|
24
21
|
<InputAdornment position="start">
|
|
@@ -28,9 +25,8 @@ const FieldTypeSort = ({value, InputProps, InputLabelProps, sx, ...props }: Fiel
|
|
|
28
25
|
onClick={(e) => {
|
|
29
26
|
// References input via event in order to modify its value
|
|
30
27
|
const input = e.currentTarget?.parentElement?.parentElement?.childNodes?.[1] as HTMLInputElement;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}}><AddIcon fontSize='small' />
|
|
28
|
+
input.value = String(+input.value - 1)
|
|
29
|
+
}}><RemoveIcon fontSize='small' />
|
|
34
30
|
</Button>
|
|
35
31
|
</InputAdornment>
|
|
36
32
|
),
|
|
@@ -42,23 +38,18 @@ const FieldTypeSort = ({value, InputProps, InputLabelProps, sx, ...props }: Fiel
|
|
|
42
38
|
onClick={(e) => {
|
|
43
39
|
// References input via event in order to modify its value
|
|
44
40
|
const input = e.currentTarget?.parentElement?.parentElement?.childNodes?.[1] as HTMLInputElement;
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}}><RemoveIcon fontSize='small' />
|
|
41
|
+
input.value = String(+input.value + 1)
|
|
42
|
+
}}><AddIcon fontSize='small' />
|
|
48
43
|
</Button>
|
|
49
44
|
</InputAdornment>
|
|
50
45
|
),
|
|
51
46
|
// Spread props at the end to allow Input prop overrides
|
|
52
47
|
...InputProps,
|
|
53
48
|
}}
|
|
54
|
-
InputLabelProps={{
|
|
55
|
-
shrink: true,
|
|
56
|
-
// Spread props at the end to allow InputLabel prop overrides
|
|
57
|
-
...InputLabelProps,
|
|
58
|
-
}}
|
|
59
49
|
// Spread props at the end to allow prop overrides
|
|
60
50
|
{...props}
|
|
61
51
|
/>
|
|
52
|
+
</FormControl>
|
|
62
53
|
);
|
|
63
54
|
};
|
|
64
55
|
|
|
@@ -16,11 +16,13 @@ const Template: Story<FieldTypeTextProps> = (args) => {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
return (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
<>
|
|
20
|
+
<FieldTypeText
|
|
21
|
+
{...args}
|
|
22
|
+
value={value}
|
|
23
|
+
onChange={handleOnChange}
|
|
24
|
+
/>
|
|
25
|
+
</>
|
|
24
26
|
);
|
|
25
27
|
};
|
|
26
28
|
|
|
@@ -28,6 +30,7 @@ export const Default = Template.bind({});
|
|
|
28
30
|
Default.args = {
|
|
29
31
|
placeholder: 'Placeholder Text...',
|
|
30
32
|
label: 'Text label',
|
|
33
|
+
helperText: 'Text helper text',
|
|
31
34
|
};
|
|
32
35
|
|
|
33
36
|
export const TextArea = Template.bind({});
|
|
@@ -36,6 +39,7 @@ TextArea.args = {
|
|
|
36
39
|
rows: 4,
|
|
37
40
|
placeholder: 'Placeholder Text...',
|
|
38
41
|
label: 'Text Label',
|
|
42
|
+
helperText: 'Text helper text',
|
|
39
43
|
};
|
|
40
44
|
|
|
41
45
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import MuiTextField, { OutlinedTextFieldProps } from '@mui/material/TextField';
|
|
2
|
-
import {
|
|
2
|
+
import { FormControl, FormLabel, Box } from '@mui/material';
|
|
3
3
|
|
|
4
4
|
export interface FieldTypeTextProps extends Omit<OutlinedTextFieldProps, 'variant'> {
|
|
5
5
|
/**
|
|
@@ -10,32 +10,25 @@ export interface FieldTypeTextProps extends Omit<OutlinedTextFieldProps, 'varian
|
|
|
10
10
|
value: string;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
const FieldTypeText = ({maxLength = 150, value, helperText,
|
|
13
|
+
const FieldTypeText = ({label, maxLength = 150, value, helperText, required, ...props }: FieldTypeTextProps) => {
|
|
14
14
|
|
|
15
15
|
return (
|
|
16
|
+
<FormControl fullWidth required={required}>
|
|
17
|
+
{/* Sets flex order to make appended required asterisk properly positioned */}
|
|
18
|
+
<FormLabel sx={{display: 'flex', justifyContent: 'space-between', '& .MuiFormLabel-asterisk': {order: 2}}}>
|
|
19
|
+
<Box sx={{ order: 1}}>{label}</Box>
|
|
20
|
+
<Box sx={{ order: 3, flex: 1, textAlign: 'right'}}>{value?.length}/{maxLength}</Box>
|
|
21
|
+
</FormLabel>
|
|
16
22
|
<MuiTextField
|
|
17
23
|
size="small"
|
|
18
24
|
variant='outlined'
|
|
19
25
|
value={value}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
<InputAdornment position="end">
|
|
23
|
-
<>{value.length}/{maxLength}</>
|
|
24
|
-
</InputAdornment>
|
|
25
|
-
),
|
|
26
|
-
// Spread props at the end to allow Input prop overrides
|
|
27
|
-
...InputProps,
|
|
28
|
-
}}
|
|
29
|
-
InputLabelProps={{
|
|
30
|
-
shrink: true,
|
|
31
|
-
// Spread props at the end to allow InputLabel prop overrides
|
|
32
|
-
...InputLabelProps,
|
|
33
|
-
}}
|
|
34
|
-
error={value.length > maxLength}
|
|
35
|
-
helperText={value.length > maxLength ? 'Your input is over the specified limit' : helperText}
|
|
26
|
+
error={value?.length > maxLength}
|
|
27
|
+
helperText={value?.length > maxLength ? 'Your input is over the specified limit' : helperText}
|
|
36
28
|
// Spread props at the end to allow prop overrides
|
|
37
29
|
{...props}
|
|
38
30
|
/>
|
|
31
|
+
</FormControl>
|
|
39
32
|
);
|
|
40
33
|
};
|
|
41
34
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useRef } from 'react';
|
|
2
2
|
import MuiTextField, { OutlinedTextFieldProps } from '@mui/material/TextField';
|
|
3
|
-
import {
|
|
3
|
+
import { FormControl, FormLabel, Box } from '@mui/material';
|
|
4
4
|
|
|
5
5
|
export interface FieldTypeUrlProps extends Omit<OutlinedTextFieldProps, 'variant'> {
|
|
6
6
|
/**
|
|
@@ -11,39 +11,32 @@ export interface FieldTypeUrlProps extends Omit<OutlinedTextFieldProps, 'variant
|
|
|
11
11
|
value: string;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
const FieldTypeUrl = ({maxLength = 2000, value, helperText,
|
|
14
|
+
const FieldTypeUrl = ({label, maxLength = 2000, value, helperText, required, inputProps, ...props }: FieldTypeUrlProps) => {
|
|
15
15
|
const inputRef = useRef<HTMLInputElement>(null);
|
|
16
16
|
|
|
17
17
|
return (
|
|
18
|
+
<FormControl fullWidth required={required}>
|
|
19
|
+
{/* Sets flex order to make appended required asterisk properly positioned */}
|
|
20
|
+
<FormLabel sx={{display: 'flex', justifyContent: 'space-between', '& .MuiFormLabel-asterisk': {order: 2}}}>
|
|
21
|
+
<Box sx={{ order: 1}}>{label}</Box>
|
|
22
|
+
<Box sx={{ order: 3, flex: 1, textAlign: 'right'}}>{value?.length}/{maxLength}</Box>
|
|
23
|
+
</FormLabel>
|
|
18
24
|
<MuiTextField
|
|
19
25
|
size="small"
|
|
20
26
|
type='url'
|
|
21
27
|
variant='outlined'
|
|
22
28
|
value={value}
|
|
23
|
-
InputProps={{
|
|
24
|
-
endAdornment: (
|
|
25
|
-
<InputAdornment position="end">
|
|
26
|
-
<>{value.length}/{maxLength}</>
|
|
27
|
-
</InputAdornment>
|
|
28
|
-
),
|
|
29
|
-
// Spread props at the end to allow Input prop overrides
|
|
30
|
-
...InputProps,
|
|
31
|
-
}}
|
|
32
|
-
InputLabelProps={{
|
|
33
|
-
shrink: true,
|
|
34
|
-
// Spread props at the end to allow InputLabel prop overrides
|
|
35
|
-
...InputLabelProps,
|
|
36
|
-
}}
|
|
37
29
|
inputProps={{
|
|
38
30
|
ref: inputRef,
|
|
39
31
|
// Spread props at the end to allow inputProps prop overrides
|
|
40
32
|
...inputProps,
|
|
41
33
|
}}
|
|
42
|
-
error={(value && !inputRef.current?.validity.valid) || value
|
|
43
|
-
helperText={value
|
|
34
|
+
error={(value && !inputRef.current?.validity.valid) || value?.length > maxLength}
|
|
35
|
+
helperText={value?.length > maxLength ? 'Your input is over the specified limit' : (value && !inputRef.current?.validity.valid) ? 'Your input is not a valid url' : helperText}
|
|
44
36
|
// Spread props at the end to allow prop overrides
|
|
45
37
|
{...props}
|
|
46
38
|
/>
|
|
39
|
+
</FormControl>
|
|
47
40
|
);
|
|
48
41
|
};
|
|
49
42
|
|
package/src/index.ts
CHANGED
|
@@ -7,5 +7,7 @@ export { default as FieldTypeDateTime } from './FieldTypeDateTime';
|
|
|
7
7
|
export { default as FieldTypeColor } from './FieldTypeColor';
|
|
8
8
|
export { default as FieldTypeNumber } from './FieldTypeNumber';
|
|
9
9
|
export { default as FieldTypeDropdown } from './FieldTypeDropdown';
|
|
10
|
+
export { default as FieldTypeOneToOne} from './FieldTypeOneToOne';
|
|
11
|
+
export { default as FieldTypeOneToMany} from './FieldTypeOneToMany';
|
|
10
12
|
export { default as CopyButton } from './CopyButton';
|
|
11
|
-
export { default as
|
|
13
|
+
export { default as ConfirmDialog } from './ConfirmDialog';
|
package/src/theme/index.ts
CHANGED
|
@@ -41,6 +41,16 @@ theme = createTheme(theme, {
|
|
|
41
41
|
root: {
|
|
42
42
|
color: theme.palette.primary.dark,
|
|
43
43
|
},
|
|
44
|
+
asterisk: {
|
|
45
|
+
color: theme.palette.error.main,
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
MuiCardHeader: {
|
|
50
|
+
styleOverrides: {
|
|
51
|
+
root: {
|
|
52
|
+
backgroundColor: '#e4e9f1',
|
|
53
|
+
},
|
|
44
54
|
},
|
|
45
55
|
},
|
|
46
56
|
MuiToggleButton: {
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import useMediaQuery from '@mui/material/useMediaQuery';
|
|
3
|
+
import ListSubheader from '@mui/material/ListSubheader';
|
|
4
|
+
import { useTheme } from '@mui/material/styles';
|
|
5
|
+
import { VariableSizeList, ListChildComponentProps } from 'react-window';
|
|
6
|
+
import Typography from '@mui/material/Typography';
|
|
7
|
+
|
|
8
|
+
const LISTBOX_PADDING = 8; // px
|
|
9
|
+
|
|
10
|
+
function renderRow(props: ListChildComponentProps) {
|
|
11
|
+
const { data, index, style } = props;
|
|
12
|
+
const dataSet = data[index];
|
|
13
|
+
const inlineStyle = {
|
|
14
|
+
...style,
|
|
15
|
+
top: (style.top as number) + LISTBOX_PADDING,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
if (dataSet.hasOwnProperty('group')) {
|
|
19
|
+
return (
|
|
20
|
+
<ListSubheader key={dataSet.key} component="div" style={inlineStyle}>
|
|
21
|
+
{dataSet.group}
|
|
22
|
+
</ListSubheader>
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<Typography component="li" {...dataSet[0]} noWrap style={inlineStyle}>
|
|
28
|
+
{dataSet[1]}
|
|
29
|
+
</Typography>
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const OuterElementContext = React.createContext({});
|
|
34
|
+
|
|
35
|
+
const OuterElementType = React.forwardRef<HTMLDivElement>((props, ref) => {
|
|
36
|
+
const outerProps = React.useContext(OuterElementContext);
|
|
37
|
+
return <div ref={ref} {...props} {...outerProps} />;
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
function useResetCache(data: any) {
|
|
41
|
+
const ref = React.useRef<VariableSizeList>(null);
|
|
42
|
+
React.useEffect(() => {
|
|
43
|
+
if (ref.current != null) {
|
|
44
|
+
ref.current.resetAfterIndex(0, true);
|
|
45
|
+
}
|
|
46
|
+
}, [data]);
|
|
47
|
+
return ref;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Adapter for react-window
|
|
51
|
+
export const ListboxComponent = React.forwardRef<
|
|
52
|
+
HTMLDivElement,
|
|
53
|
+
React.HTMLAttributes<HTMLElement>
|
|
54
|
+
>(function ListboxComponent(props, ref) {
|
|
55
|
+
const { children, ...other } = props;
|
|
56
|
+
const itemData: React.ReactChild[] = [];
|
|
57
|
+
(children as React.ReactChild[]).forEach(
|
|
58
|
+
(item: React.ReactChild & { children?: React.ReactChild[] }) => {
|
|
59
|
+
itemData.push(item);
|
|
60
|
+
itemData.push(...(item.children || []));
|
|
61
|
+
},
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
const theme = useTheme();
|
|
65
|
+
const smUp = useMediaQuery(theme.breakpoints.up('sm'), {
|
|
66
|
+
noSsr: true,
|
|
67
|
+
});
|
|
68
|
+
const itemCount = itemData.length;
|
|
69
|
+
const itemSize = smUp ? 36 : 48;
|
|
70
|
+
|
|
71
|
+
const getChildSize = (child: React.ReactChild) => {
|
|
72
|
+
if (child.hasOwnProperty('group')) {
|
|
73
|
+
return 48;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return itemSize;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const getHeight = () => {
|
|
80
|
+
if (itemCount > 8) {
|
|
81
|
+
return 8 * itemSize;
|
|
82
|
+
}
|
|
83
|
+
return itemData.map(getChildSize).reduce((a, b) => a + b, 0);
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const gridRef = useResetCache(itemCount);
|
|
87
|
+
|
|
88
|
+
return (
|
|
89
|
+
<div ref={ref}>
|
|
90
|
+
<OuterElementContext.Provider value={other}>
|
|
91
|
+
<VariableSizeList
|
|
92
|
+
itemData={itemData}
|
|
93
|
+
height={getHeight() + 2 * LISTBOX_PADDING}
|
|
94
|
+
width="100%"
|
|
95
|
+
ref={gridRef}
|
|
96
|
+
outerElementType={OuterElementType}
|
|
97
|
+
innerElementType="ul"
|
|
98
|
+
itemSize={(index: any) => getChildSize(itemData[index])}
|
|
99
|
+
overscanCount={5}
|
|
100
|
+
itemCount={itemCount}
|
|
101
|
+
>
|
|
102
|
+
{renderRow}
|
|
103
|
+
</VariableSizeList>
|
|
104
|
+
</OuterElementContext.Provider>
|
|
105
|
+
</div>
|
|
106
|
+
);
|
|
107
|
+
});
|