@zesty-io/material 0.0.3 → 0.1.1
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/.storybook/main.js +15 -2
- package/.storybook/preview-head.html +1 -0
- package/.storybook/preview.js +14 -8
- package/es/ConfirmModal/ConfirmModal.stories.d.ts +6 -0
- package/es/ConfirmModal/ConfirmModal.stories.js +24 -0
- package/es/ConfirmModal/index.d.ts +18 -0
- package/es/ConfirmModal/index.js +11 -0
- package/es/CopyButton/CopyButton.stories.d.ts +5 -0
- package/es/CopyButton/CopyButton.stories.js +14 -0
- package/es/CopyButton/index.d.ts +10 -0
- package/es/CopyButton/index.js +26 -0
- package/es/FieldTypeColor/FieldTypeColor.stories.d.ts +5 -0
- package/es/FieldTypeColor/FieldTypeColor.stories.js +21 -0
- package/es/FieldTypeColor/index.d.ts +6 -0
- package/es/FieldTypeColor/index.js +16 -0
- package/es/FieldTypeDate/FieldTypeDate.stories.d.ts +5 -0
- package/es/FieldTypeDate/FieldTypeDate.stories.js +17 -0
- package/es/FieldTypeDate/index.d.ts +9 -0
- package/es/FieldTypeDate/index.js +10 -0
- package/es/FieldTypeDateTime/FieldTypeDateTime.stories.d.ts +5 -0
- package/es/FieldTypeDateTime/FieldTypeDateTime.stories.js +17 -0
- package/es/FieldTypeDateTime/index.d.ts +9 -0
- package/es/FieldTypeDateTime/index.js +10 -0
- package/es/FieldTypeDropdown/FieldTypeDropwdon.stories.d.ts +5 -0
- package/es/FieldTypeDropdown/FieldTypeDropwdon.stories.js +35 -0
- package/es/FieldTypeDropdown/index.d.ts +11 -0
- package/es/FieldTypeDropdown/index.js +10 -0
- package/es/FieldTypeNumber/FieldTypeNumber.stories.d.ts +5 -0
- package/es/FieldTypeNumber/FieldTypeNumber.stories.js +21 -0
- package/es/FieldTypeNumber/index.d.ts +6 -0
- package/es/FieldTypeNumber/index.js +7 -0
- package/es/FieldTypeOneToMany/FieldTypeOneToMany.stories.d.ts +5 -0
- package/es/FieldTypeOneToMany/FieldTypeOneToMany.stories.js +29 -0
- package/es/FieldTypeOneToMany/index.d.ts +14 -0
- package/es/FieldTypeOneToMany/index.js +30 -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.d.ts +5 -0
- package/es/FieldTypeSort/FieldTypeSort.stories.js +22 -0
- package/es/FieldTypeSort/index.d.ts +7 -0
- package/es/FieldTypeSort/index.js +22 -0
- package/es/FieldTypeText/FieldTypeText.stories.d.ts +6 -0
- package/es/FieldTypeText/FieldTypeText.stories.js +29 -0
- package/es/FieldTypeText/index.d.ts +12 -0
- package/es/FieldTypeText/index.js +7 -0
- package/es/FieldTypeUrl/FieldTypeUrl.stories.d.ts +5 -0
- package/es/FieldTypeUrl/FieldTypeUrl.stories.js +21 -0
- package/es/FieldTypeUrl/index.d.ts +12 -0
- package/es/FieldTypeUrl/index.js +13 -0
- package/es/index.d.ts +12 -0
- package/es/index.js +12 -0
- package/es/theme/Theme.stories.d.ts +4 -0
- package/es/theme/Theme.stories.js +10 -0
- package/es/theme/index.js +36 -8
- package/es/utils/virtualization.d.ts +3 -0
- package/es/utils/virtualization.js +74 -0
- package/package.json +8 -3
- package/src/ConfirmModal/ConfirmModal.stories.tsx +35 -0
- package/src/ConfirmModal/index.tsx +50 -0
- package/src/CopyButton/CopyButton.stories.tsx +20 -0
- package/src/CopyButton/index.tsx +55 -0
- package/src/FieldTypeColor/FieldTypeColor.stories.tsx +35 -0
- package/src/FieldTypeColor/index.tsx +43 -0
- package/src/FieldTypeDate/FieldTypeDate.stories.tsx +23 -0
- package/src/FieldTypeDate/index.tsx +34 -0
- package/src/FieldTypeDateTime/FieldTypeDateTime.stories.tsx +23 -0
- package/src/FieldTypeDateTime/index.tsx +35 -0
- package/src/FieldTypeDropdown/FieldTypeDropwdon.stories.tsx +52 -0
- package/src/FieldTypeDropdown/index.tsx +41 -0
- package/src/FieldTypeNumber/FieldTypeNumber.stories.tsx +35 -0
- package/src/FieldTypeNumber/index.tsx +22 -0
- package/src/FieldTypeOneToMany/FieldTypeOneToMany.stories.tsx +47 -0
- package/src/FieldTypeOneToMany/index.tsx +65 -0
- package/src/FieldTypeOneToOne/FieldTypeOneToOne.stories.tsx +46 -0
- package/src/FieldTypeOneToOne/index.tsx +97 -0
- package/src/FieldTypeSort/FieldTypeSort.stories.tsx +36 -0
- package/src/FieldTypeSort/index.tsx +56 -0
- package/src/FieldTypeText/FieldTypeText.stories.tsx +45 -0
- package/src/FieldTypeText/index.tsx +35 -0
- package/src/FieldTypeUrl/FieldTypeUrl.stories.tsx +33 -0
- package/src/FieldTypeUrl/index.tsx +43 -0
- package/src/index.ts +12 -0
- package/src/{stories → theme}/Theme.stories.tsx +1 -1
- package/src/theme/index.ts +41 -9
- package/src/utils/virtualization.tsx +125 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import {useState} from 'react';
|
|
2
|
+
import { Story, Meta } from '@storybook/react/types-6-0';
|
|
3
|
+
import FieldTypeDate, { FieldTypeDateProps } from '.';
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
title: 'FieldTypeDate',
|
|
7
|
+
component: FieldTypeDate,
|
|
8
|
+
argType: {},
|
|
9
|
+
} as Meta;
|
|
10
|
+
|
|
11
|
+
const Template: Story<FieldTypeDateProps> = (args) => {
|
|
12
|
+
const [value, setValue] = useState<Date | null>(null);
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
<FieldTypeDate {...args} value={value} onChange={(value) => setValue(value)}/>
|
|
16
|
+
);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const Default = Template.bind({});
|
|
20
|
+
Default.args = {
|
|
21
|
+
label: 'Date label',
|
|
22
|
+
helperText: 'Date helper text',
|
|
23
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { AdapterDateFns } from '@mui/x-date-pickers/AdapterDateFns';
|
|
2
|
+
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
|
|
3
|
+
import { DatePicker, DatePickerProps} from '@mui/x-date-pickers/DatePicker';
|
|
4
|
+
import { FormControl, FormLabel, TextField } from '@mui/material';
|
|
5
|
+
|
|
6
|
+
export interface FieldTypeDateProps extends Omit<DatePickerProps<Date, Date>, 'renderInput'> {
|
|
7
|
+
helperText?: string;
|
|
8
|
+
error?: boolean;
|
|
9
|
+
required?: boolean;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const FieldTypeDate = ({label, helperText, error, required, ...props}: FieldTypeDateProps) => {
|
|
13
|
+
return (
|
|
14
|
+
<FormControl fullWidth required={required}>
|
|
15
|
+
<FormLabel>{label}</FormLabel>
|
|
16
|
+
<LocalizationProvider dateAdapter={AdapterDateFns}>
|
|
17
|
+
<DatePicker
|
|
18
|
+
data-testid="zds-date-picker"
|
|
19
|
+
renderInput={(params) =>
|
|
20
|
+
<TextField
|
|
21
|
+
{...params}
|
|
22
|
+
helperText={helperText}
|
|
23
|
+
error={error}
|
|
24
|
+
/>
|
|
25
|
+
}
|
|
26
|
+
// Spread props at the end to allow prop overrides
|
|
27
|
+
{...props}
|
|
28
|
+
/>
|
|
29
|
+
</LocalizationProvider>
|
|
30
|
+
</FormControl>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export default FieldTypeDate;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import {useState} from 'react';
|
|
2
|
+
import { Story, Meta } from '@storybook/react/types-6-0';
|
|
3
|
+
import FieldTypeDateTime, { FieldTypeDateTimeProps } from '.';
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
title: 'FieldTypeDateTime',
|
|
7
|
+
component: FieldTypeDateTime,
|
|
8
|
+
argType: {},
|
|
9
|
+
} as Meta;
|
|
10
|
+
|
|
11
|
+
const Template: Story<FieldTypeDateTimeProps> = (args) => {
|
|
12
|
+
const [value, setValue] = useState<Date | null>(null);
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
<FieldTypeDateTime {...args} value={value} onChange={(value) => setValue(value)}/>
|
|
16
|
+
);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const Default = Template.bind({});
|
|
20
|
+
Default.args = {
|
|
21
|
+
label: 'Date label',
|
|
22
|
+
helperText: 'Date helper text',
|
|
23
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { AdapterDateFns } from '@mui/x-date-pickers/AdapterDateFns';
|
|
2
|
+
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
|
|
3
|
+
import { DateTimePicker, DateTimePickerProps} from '@mui/x-date-pickers/DateTimePicker';
|
|
4
|
+
import { TextField, FormControl, FormLabel } from '@mui/material';
|
|
5
|
+
|
|
6
|
+
export interface FieldTypeDateTimeProps extends Omit<DateTimePickerProps<Date, Date>, 'renderInput'> {
|
|
7
|
+
helperText?: string;
|
|
8
|
+
error?: boolean;
|
|
9
|
+
required?: boolean;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const FieldTypeDateTime = ({label, helperText, error, required, ...props}: FieldTypeDateTimeProps) => {
|
|
13
|
+
return (
|
|
14
|
+
<FormControl fullWidth required={required}>
|
|
15
|
+
<FormLabel>{label}</FormLabel>
|
|
16
|
+
<LocalizationProvider dateAdapter={AdapterDateFns}>
|
|
17
|
+
<DateTimePicker
|
|
18
|
+
data-testid="zds-date-picker"
|
|
19
|
+
renderInput={(params) =>
|
|
20
|
+
<TextField
|
|
21
|
+
|
|
22
|
+
{...params}
|
|
23
|
+
helperText={helperText}
|
|
24
|
+
error={error}
|
|
25
|
+
/>
|
|
26
|
+
}
|
|
27
|
+
// Spread props at the end to allow prop overrides
|
|
28
|
+
{...props}
|
|
29
|
+
/>
|
|
30
|
+
</LocalizationProvider>
|
|
31
|
+
</FormControl>
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export default FieldTypeDateTime;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { ChangeEvent, useState } from 'react';
|
|
2
|
+
import { Story, Meta } from '@storybook/react/types-6-0';
|
|
3
|
+
import FieldTypeDropdown, { FieldTypeDropdownProps } from './';
|
|
4
|
+
import { MenuItem } from '@mui/material';
|
|
5
|
+
|
|
6
|
+
export default {
|
|
7
|
+
title: 'FieldTypeDropdown',
|
|
8
|
+
component: FieldTypeDropdown,
|
|
9
|
+
argType: {},
|
|
10
|
+
} as Meta;
|
|
11
|
+
|
|
12
|
+
const options = [
|
|
13
|
+
{
|
|
14
|
+
value: 'option1',
|
|
15
|
+
label: 'Option 1',
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
value: 'option2',
|
|
19
|
+
label: 'Option 2',
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
value: 'option3',
|
|
23
|
+
label: 'Option 3',
|
|
24
|
+
},
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
const Template: Story<FieldTypeDropdownProps> = (args) => {
|
|
28
|
+
const [value, setValue] = useState('');
|
|
29
|
+
|
|
30
|
+
const handleOnChange = (e: ChangeEvent<HTMLInputElement>) => {
|
|
31
|
+
setValue(e.target.value);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<FieldTypeDropdown
|
|
36
|
+
{...args}
|
|
37
|
+
value={value}
|
|
38
|
+
onChange={handleOnChange}
|
|
39
|
+
options={options}
|
|
40
|
+
/>
|
|
41
|
+
);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export const Default = Template.bind({});
|
|
45
|
+
Default.args = {
|
|
46
|
+
placeholder: 'Placeholder Text...',
|
|
47
|
+
label: 'Dropdown label',
|
|
48
|
+
helperText: 'Dropdown helper text',
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { MenuItem } from '@mui/material';
|
|
2
|
+
import MuiTextField, { OutlinedTextFieldProps } from '@mui/material/TextField';
|
|
3
|
+
import { FormControl, FormLabel } from '@mui/material';
|
|
4
|
+
|
|
5
|
+
interface Option {
|
|
6
|
+
label: string;
|
|
7
|
+
value: any;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface FieldTypeDropdownProps extends Omit<OutlinedTextFieldProps, 'variant'> {
|
|
11
|
+
options: Option[];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const FieldTypeDropdown = ({label, options, required, ...props }: FieldTypeDropdownProps) => {
|
|
15
|
+
|
|
16
|
+
return (
|
|
17
|
+
<FormControl fullWidth required={required}>
|
|
18
|
+
<FormLabel>{label}</FormLabel>
|
|
19
|
+
<MuiTextField
|
|
20
|
+
size="small"
|
|
21
|
+
variant='outlined'
|
|
22
|
+
select
|
|
23
|
+
SelectProps={{
|
|
24
|
+
displayEmpty: true,
|
|
25
|
+
}}
|
|
26
|
+
{...props}
|
|
27
|
+
>
|
|
28
|
+
<MenuItem key={''} value={''}>
|
|
29
|
+
- None -
|
|
30
|
+
</MenuItem>
|
|
31
|
+
{options.map((option) => (
|
|
32
|
+
<MenuItem key={option.value} value={option.value}>
|
|
33
|
+
{option.label}
|
|
34
|
+
</MenuItem>
|
|
35
|
+
))}
|
|
36
|
+
</MuiTextField>
|
|
37
|
+
</FormControl>
|
|
38
|
+
);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export default FieldTypeDropdown;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ChangeEvent, useState } from 'react';
|
|
2
|
+
import { Story, Meta } from '@storybook/react/types-6-0';
|
|
3
|
+
import FieldTypeNumber, { FieldTypeNumberProps } from './';
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
title: 'FieldTypeNumber',
|
|
7
|
+
component: FieldTypeNumber,
|
|
8
|
+
argType: {},
|
|
9
|
+
} as Meta;
|
|
10
|
+
|
|
11
|
+
const Template: Story<FieldTypeNumberProps> = (args) => {
|
|
12
|
+
const [value, setValue] = useState('0');
|
|
13
|
+
|
|
14
|
+
const handleOnChange = (e: ChangeEvent<HTMLInputElement>) => {
|
|
15
|
+
setValue(e.target.value);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<FieldTypeNumber
|
|
20
|
+
{...args}
|
|
21
|
+
value={value}
|
|
22
|
+
onChange={handleOnChange}
|
|
23
|
+
/>
|
|
24
|
+
);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const Default = Template.bind({});
|
|
28
|
+
Default.args = {
|
|
29
|
+
placeholder: 'Placeholder Text...',
|
|
30
|
+
label: 'Number label',
|
|
31
|
+
helperText: 'Number helper text',
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { FormControl, FormLabel } from '@mui/material';
|
|
2
|
+
import MuiTextField, { OutlinedTextFieldProps } from '@mui/material/TextField';
|
|
3
|
+
|
|
4
|
+
export interface FieldTypeNumberProps extends Omit<OutlinedTextFieldProps, 'variant'> {}
|
|
5
|
+
|
|
6
|
+
const FieldTypeText = ({label, required, ...props }: FieldTypeNumberProps) => {
|
|
7
|
+
|
|
8
|
+
return (
|
|
9
|
+
<FormControl fullWidth required={required}>
|
|
10
|
+
<FormLabel>{label}</FormLabel>
|
|
11
|
+
<MuiTextField
|
|
12
|
+
size="small"
|
|
13
|
+
variant='outlined'
|
|
14
|
+
type='number'
|
|
15
|
+
// Spread props at the end to allow prop overrides
|
|
16
|
+
{...props}
|
|
17
|
+
/>
|
|
18
|
+
</FormControl>
|
|
19
|
+
);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export default FieldTypeText;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { SyntheticEvent, useState } from 'react';
|
|
2
|
+
import { Story, Meta } from '@storybook/react/types-6-0';
|
|
3
|
+
import FieldTypeOneToMany, { FieldTypeOneToManyProps } from '.';
|
|
4
|
+
import { randomOptions } from '../utils/virtualization';
|
|
5
|
+
|
|
6
|
+
export default {
|
|
7
|
+
title: 'FieldTypeOneToMany',
|
|
8
|
+
component: FieldTypeOneToMany,
|
|
9
|
+
argType: {},
|
|
10
|
+
} as Meta;
|
|
11
|
+
|
|
12
|
+
const Template: Story<FieldTypeOneToManyProps> = (args) => {
|
|
13
|
+
const [value, setValue] = useState<string[]>([]);
|
|
14
|
+
|
|
15
|
+
const [options, setOptions] = useState<string[]>([]);
|
|
16
|
+
|
|
17
|
+
const handleOnOpen = async () => {
|
|
18
|
+
await new Promise((resolve) => setTimeout(resolve, 3000))
|
|
19
|
+
setOptions(randomOptions);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const handleOnChange = (e: SyntheticEvent<Element, Event>, values: string[]) => {
|
|
23
|
+
setValue(values);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<FieldTypeOneToMany
|
|
28
|
+
{...args}
|
|
29
|
+
value={value}
|
|
30
|
+
onChange={handleOnChange}
|
|
31
|
+
options={options}
|
|
32
|
+
onOpen={handleOnOpen}
|
|
33
|
+
/>
|
|
34
|
+
);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export const Default = Template.bind({});
|
|
38
|
+
Default.args = {
|
|
39
|
+
textFieldProps: {
|
|
40
|
+
placeholder: 'Placeholder Text...',
|
|
41
|
+
label: 'OneToOne label',
|
|
42
|
+
helperText: 'OneToOne helperText',
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import { AutocompleteProps, Popper, styled, TextField, TextFieldProps } from '@mui/material';
|
|
3
|
+
import Autocomplete, { autocompleteClasses } from '@mui/material/Autocomplete';
|
|
4
|
+
import { ListboxComponent } from '../utils/virtualization';
|
|
5
|
+
|
|
6
|
+
export interface FieldTypeOneToManyProps extends Omit<AutocompleteProps<any, false, false, false>, 'onOpen' | 'renderInput'> {
|
|
7
|
+
/**
|
|
8
|
+
* Props passed to TextField component
|
|
9
|
+
*/
|
|
10
|
+
textFieldProps?: TextFieldProps;
|
|
11
|
+
/**
|
|
12
|
+
* Callback to be fired upon opening the dropdown
|
|
13
|
+
*/
|
|
14
|
+
onOpen: () => Promise<any>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const FieldTypeOneToMany = ({textFieldProps, onOpen, ...props }: FieldTypeOneToManyProps) => {
|
|
18
|
+
const [loaded, setLoaded] = useState(false);
|
|
19
|
+
const [loading, setLoading] = useState(true);
|
|
20
|
+
|
|
21
|
+
const handleOpen = () => {
|
|
22
|
+
if (!loaded && onOpen) {
|
|
23
|
+
onOpen().then(() => {
|
|
24
|
+
setLoading(false);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
setLoaded(true);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<Autocomplete
|
|
33
|
+
onOpen={handleOpen}
|
|
34
|
+
loading={loading}
|
|
35
|
+
fullWidth
|
|
36
|
+
multiple
|
|
37
|
+
disableListWrap
|
|
38
|
+
PopperComponent={StyledPopper}
|
|
39
|
+
ListboxComponent={ListboxComponent}
|
|
40
|
+
renderInput={(params) => (
|
|
41
|
+
<TextField
|
|
42
|
+
{...params}
|
|
43
|
+
{...textFieldProps}
|
|
44
|
+
InputLabelProps={{
|
|
45
|
+
shrink: true,
|
|
46
|
+
}}
|
|
47
|
+
/>
|
|
48
|
+
)}
|
|
49
|
+
renderOption={(props, option) => [props, option]}
|
|
50
|
+
{...props}
|
|
51
|
+
/>
|
|
52
|
+
);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export default FieldTypeOneToMany;
|
|
56
|
+
|
|
57
|
+
const StyledPopper = styled(Popper)({
|
|
58
|
+
[`& .${autocompleteClasses.listbox}`]: {
|
|
59
|
+
boxSizing: 'border-box',
|
|
60
|
+
'& ul': {
|
|
61
|
+
padding: 0,
|
|
62
|
+
margin: 0,
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
});
|
|
@@ -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,97 @@
|
|
|
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
|
+
// getOptionLabel={(option) => option.label}
|
|
81
|
+
{...props}
|
|
82
|
+
/>
|
|
83
|
+
</FormControl>
|
|
84
|
+
);
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export default FieldTypeOneToOne;
|
|
88
|
+
|
|
89
|
+
const StyledPopper = styled(Popper)({
|
|
90
|
+
[`& .${autocompleteClasses.listbox}`]: {
|
|
91
|
+
boxSizing: 'border-box',
|
|
92
|
+
'& ul': {
|
|
93
|
+
padding: 0,
|
|
94
|
+
margin: 0,
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ChangeEvent, useState } from 'react';
|
|
2
|
+
import { Story, Meta } from '@storybook/react/types-6-0';
|
|
3
|
+
import FieldTypeSort, { FieldTypeSortProps } from './';
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
title: 'FieldTypeSort',
|
|
7
|
+
component: FieldTypeSort,
|
|
8
|
+
argType: {},
|
|
9
|
+
} as Meta;
|
|
10
|
+
|
|
11
|
+
const Template: Story<FieldTypeSortProps> = (args) => {
|
|
12
|
+
const [value, setValue] = useState('3');
|
|
13
|
+
|
|
14
|
+
const handleOnChange = (e: ChangeEvent<HTMLInputElement>) => {
|
|
15
|
+
setValue(e.target.value);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<FieldTypeSort
|
|
20
|
+
{...args}
|
|
21
|
+
value={value}
|
|
22
|
+
onChange={handleOnChange}
|
|
23
|
+
/>
|
|
24
|
+
);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const Default = Template.bind({});
|
|
28
|
+
Default.args = {
|
|
29
|
+
placeholder: 'Placeholder Text...',
|
|
30
|
+
label: 'Sort label',
|
|
31
|
+
helperText: 'Sort helper text',
|
|
32
|
+
error: false,
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import MuiTextField, { OutlinedTextFieldProps } from '@mui/material/TextField';
|
|
2
|
+
import { Button, FormControl, FormLabel, InputAdornment } from '@mui/material';
|
|
3
|
+
import AddIcon from '@mui/icons-material/Add';
|
|
4
|
+
import RemoveIcon from '@mui/icons-material/Remove';
|
|
5
|
+
|
|
6
|
+
export interface FieldTypeSortProps extends Omit<OutlinedTextFieldProps, 'variant'> {
|
|
7
|
+
value: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const FieldTypeSort = ({label, value, InputProps, required, ...props }: FieldTypeSortProps) => {
|
|
11
|
+
return (
|
|
12
|
+
<FormControl fullWidth required={required}>
|
|
13
|
+
<FormLabel>{label}</FormLabel>
|
|
14
|
+
<MuiTextField
|
|
15
|
+
size="small"
|
|
16
|
+
variant='outlined'
|
|
17
|
+
type='number'
|
|
18
|
+
value={value}
|
|
19
|
+
InputProps={{
|
|
20
|
+
startAdornment: (
|
|
21
|
+
<InputAdornment position="start">
|
|
22
|
+
<Button
|
|
23
|
+
size="small"
|
|
24
|
+
variant="contained"
|
|
25
|
+
onClick={(e) => {
|
|
26
|
+
// References input via event in order to modify its value
|
|
27
|
+
const input = e.currentTarget?.parentElement?.parentElement?.childNodes?.[1] as HTMLInputElement;
|
|
28
|
+
input.value = String(+input.value - 1)
|
|
29
|
+
}}><RemoveIcon fontSize='small' />
|
|
30
|
+
</Button>
|
|
31
|
+
</InputAdornment>
|
|
32
|
+
),
|
|
33
|
+
endAdornment: (
|
|
34
|
+
<InputAdornment position="end">
|
|
35
|
+
<Button
|
|
36
|
+
size="small"
|
|
37
|
+
variant="contained"
|
|
38
|
+
onClick={(e) => {
|
|
39
|
+
// References input via event in order to modify its value
|
|
40
|
+
const input = e.currentTarget?.parentElement?.parentElement?.childNodes?.[1] as HTMLInputElement;
|
|
41
|
+
input.value = String(+input.value + 1)
|
|
42
|
+
}}><AddIcon fontSize='small' />
|
|
43
|
+
</Button>
|
|
44
|
+
</InputAdornment>
|
|
45
|
+
),
|
|
46
|
+
// Spread props at the end to allow Input prop overrides
|
|
47
|
+
...InputProps,
|
|
48
|
+
}}
|
|
49
|
+
// Spread props at the end to allow prop overrides
|
|
50
|
+
{...props}
|
|
51
|
+
/>
|
|
52
|
+
</FormControl>
|
|
53
|
+
);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export default FieldTypeSort;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { ChangeEvent, useState } from 'react';
|
|
2
|
+
import { Story, Meta } from '@storybook/react/types-6-0';
|
|
3
|
+
import FieldTypeText, { FieldTypeTextProps } from './';
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
title: 'FieldTypeText',
|
|
7
|
+
component: FieldTypeText,
|
|
8
|
+
argType: {},
|
|
9
|
+
} as Meta;
|
|
10
|
+
|
|
11
|
+
const Template: Story<FieldTypeTextProps> = (args) => {
|
|
12
|
+
const [value, setValue] = useState('');
|
|
13
|
+
|
|
14
|
+
const handleOnChange = (e: ChangeEvent<HTMLInputElement>) => {
|
|
15
|
+
setValue(e.target.value);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<>
|
|
20
|
+
<FieldTypeText
|
|
21
|
+
{...args}
|
|
22
|
+
value={value}
|
|
23
|
+
onChange={handleOnChange}
|
|
24
|
+
/>
|
|
25
|
+
</>
|
|
26
|
+
);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const Default = Template.bind({});
|
|
30
|
+
Default.args = {
|
|
31
|
+
placeholder: 'Placeholder Text...',
|
|
32
|
+
label: 'Text label',
|
|
33
|
+
helperText: 'Text helper text',
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export const TextArea = Template.bind({});
|
|
37
|
+
TextArea.args = {
|
|
38
|
+
multiline: true,
|
|
39
|
+
rows: 4,
|
|
40
|
+
placeholder: 'Placeholder Text...',
|
|
41
|
+
label: 'Text Label',
|
|
42
|
+
helperText: 'Text helper text',
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
|