@zesty-io/material 0.2.4 → 0.3.0
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/cjs/ConfirmDialog/ConfirmDialog.stories.d.ts +6 -0
- package/cjs/ConfirmDialog/ConfirmDialog.stories.js +27 -0
- package/cjs/ConfirmDialog/index.d.ts +18 -0
- package/cjs/ConfirmDialog/index.js +13 -0
- package/cjs/CopyButton/CopyButton.stories.d.ts +5 -0
- package/cjs/CopyButton/CopyButton.stories.js +17 -0
- package/cjs/CopyButton/index.d.ts +10 -0
- package/cjs/CopyButton/index.js +28 -0
- package/cjs/FieldTypeColor/FieldTypeColor.stories.d.ts +5 -0
- package/cjs/FieldTypeColor/FieldTypeColor.stories.js +24 -0
- package/cjs/FieldTypeColor/index.d.ts +6 -0
- package/cjs/FieldTypeColor/index.js +18 -0
- package/cjs/FieldTypeDate/FieldTypeDate.stories.d.ts +5 -0
- package/cjs/FieldTypeDate/FieldTypeDate.stories.js +20 -0
- package/cjs/FieldTypeDate/index.d.ts +9 -0
- package/cjs/FieldTypeDate/index.js +12 -0
- package/cjs/FieldTypeDateTime/FieldTypeDateTime.stories.d.ts +5 -0
- package/cjs/FieldTypeDateTime/FieldTypeDateTime.stories.js +20 -0
- package/cjs/FieldTypeDateTime/index.d.ts +9 -0
- package/cjs/FieldTypeDateTime/index.js +12 -0
- package/cjs/FieldTypeNumber/FieldTypeNumber.stories.d.ts +5 -0
- package/cjs/FieldTypeNumber/FieldTypeNumber.stories.js +24 -0
- package/cjs/FieldTypeNumber/index.d.ts +6 -0
- package/cjs/FieldTypeNumber/index.js +9 -0
- package/cjs/FieldTypeOneToMany/FieldTypeOneToMany.stories.d.ts +5 -0
- package/cjs/FieldTypeOneToMany/FieldTypeOneToMany.stories.js +31 -0
- package/cjs/FieldTypeOneToMany/index.d.ts +32 -0
- package/cjs/FieldTypeOneToMany/index.js +31 -0
- package/cjs/FieldTypeOneToOne/FieldTypeOneToOne.stories.d.ts +5 -0
- package/cjs/FieldTypeOneToOne/FieldTypeOneToOne.stories.js +31 -0
- package/cjs/FieldTypeOneToOne/index.d.ts +34 -0
- package/cjs/FieldTypeOneToOne/index.js +35 -0
- package/cjs/FieldTypeSort/FieldTypeSort.stories.d.ts +5 -0
- package/cjs/FieldTypeSort/FieldTypeSort.stories.js +25 -0
- package/cjs/FieldTypeSort/index.d.ts +7 -0
- package/cjs/FieldTypeSort/index.js +36 -0
- package/cjs/FieldTypeText/FieldTypeText.stories.d.ts +6 -0
- package/cjs/FieldTypeText/FieldTypeText.stories.js +32 -0
- package/cjs/FieldTypeText/index.d.ts +12 -0
- package/cjs/FieldTypeText/index.js +9 -0
- package/cjs/FieldTypeUrl/FieldTypeUrl.stories.d.ts +5 -0
- package/cjs/FieldTypeUrl/FieldTypeUrl.stories.js +24 -0
- package/cjs/FieldTypeUrl/index.d.ts +12 -0
- package/cjs/FieldTypeUrl/index.js +16 -0
- package/cjs/LegacyTheme/index.d.ts +3 -0
- package/cjs/LegacyTheme/index.js +83 -0
- package/cjs/LegacyTheme/palette.d.ts +3 -0
- package/cjs/LegacyTheme/palette.js +25 -0
- package/{src/LegacyTheme/typography.ts → cjs/LegacyTheme/typography.d.ts} +1 -5
- package/cjs/LegacyTheme/typography.js +6 -0
- package/cjs/VitualizedAutocomplete/VirtualizedAutocomplete.stories.d.ts +5 -0
- package/cjs/VitualizedAutocomplete/VirtualizedAutocomplete.stories.js +30 -0
- package/cjs/VitualizedAutocomplete/index.d.ts +28 -0
- package/cjs/VitualizedAutocomplete/index.js +23 -0
- package/{src/index.ts → cjs/index.d.ts} +3 -3
- package/cjs/index.js +31 -0
- package/cjs/theme/Theme.stories.d.ts +4 -0
- package/cjs/theme/Theme.stories.js +13 -0
- package/cjs/theme/index.d.ts +3 -0
- package/cjs/theme/index.js +52 -0
- package/cjs/theme/palette.d.ts +15 -0
- package/cjs/theme/palette.js +138 -0
- package/cjs/theme/typography.d.ts +9 -0
- package/cjs/theme/typography.js +59 -0
- package/cjs/utils/virtualization.d.ts +2 -0
- package/cjs/utils/virtualization.js +66 -0
- package/es/LegacyTheme/index.js +2 -0
- package/es/TextField.stories.d.ts +5 -0
- package/es/TextField.stories.js +18 -0
- package/es/icons/FolderGlobal.d.ts +3 -0
- package/es/icons/FolderGlobal.js +3 -0
- package/es/icons/index.d.ts +1 -0
- package/es/icons/index.js +1 -0
- package/es/index.d.ts +1 -0
- package/es/index.js +1 -0
- package/es/theme/index.d.ts +8 -0
- package/es/theme/index.js +95 -2
- package/es/theme/palette.d.ts +1 -0
- package/es/theme/palette.js +3 -1
- package/package.json +11 -7
- package/.storybook/main.js +0 -25
- package/.storybook/preview-head.html +0 -1
- package/.storybook/preview.js +0 -15
- package/src/ConfirmDialog/ConfirmDialog.stories.tsx +0 -35
- package/src/ConfirmDialog/index.tsx +0 -50
- package/src/CopyButton/CopyButton.stories.tsx +0 -20
- package/src/CopyButton/index.tsx +0 -55
- package/src/FieldTypeColor/FieldTypeColor.stories.tsx +0 -35
- package/src/FieldTypeColor/index.tsx +0 -43
- package/src/FieldTypeDate/FieldTypeDate.stories.tsx +0 -23
- package/src/FieldTypeDate/index.tsx +0 -35
- package/src/FieldTypeDateTime/FieldTypeDateTime.stories.tsx +0 -23
- package/src/FieldTypeDateTime/index.tsx +0 -36
- package/src/FieldTypeNumber/FieldTypeNumber.stories.tsx +0 -35
- package/src/FieldTypeNumber/index.tsx +0 -22
- package/src/FieldTypeOneToMany/FieldTypeOneToMany.stories.tsx +0 -47
- package/src/FieldTypeOneToMany/index.tsx +0 -90
- package/src/FieldTypeOneToOne/FieldTypeOneToOne.stories.tsx +0 -46
- package/src/FieldTypeOneToOne/index.tsx +0 -96
- package/src/FieldTypeSort/FieldTypeSort.stories.tsx +0 -36
- package/src/FieldTypeSort/index.tsx +0 -70
- package/src/FieldTypeText/FieldTypeText.stories.tsx +0 -45
- package/src/FieldTypeText/index.tsx +0 -35
- package/src/FieldTypeUrl/FieldTypeUrl.stories.tsx +0 -33
- package/src/FieldTypeUrl/index.tsx +0 -44
- package/src/LegacyTheme/index.ts +0 -88
- package/src/LegacyTheme/palette.ts +0 -25
- package/src/VitualizedAutocomplete/VirtualizedAutocomplete.stories.tsx +0 -45
- package/src/VitualizedAutocomplete/index.tsx +0 -69
- package/src/theme/Theme.stories.tsx +0 -16
- package/src/theme/index.ts +0 -53
- package/src/theme/palette.ts +0 -153
- package/src/theme/typography.ts +0 -69
- package/src/utils/virtualization.tsx +0 -107
- package/tsconfig.json +0 -22
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
2
|
-
import Dialog, { DialogProps } from '@mui/material/Dialog';
|
|
3
|
-
import DialogActions from '@mui/material/DialogActions';
|
|
4
|
-
import DialogContent from '@mui/material/DialogContent';
|
|
5
|
-
import DialogContentText from '@mui/material/DialogContentText';
|
|
6
|
-
import DialogTitle from '@mui/material/DialogTitle';
|
|
7
|
-
import { Button } from '@mui/material';
|
|
8
|
-
|
|
9
|
-
export interface ConfirmDialogProps extends Omit<DialogProps, 'title'> {
|
|
10
|
-
/**
|
|
11
|
-
* Title of confirm dialog
|
|
12
|
-
*/
|
|
13
|
-
title: string | ReactNode ;
|
|
14
|
-
/**
|
|
15
|
-
* Content of confirm dialog
|
|
16
|
-
*/
|
|
17
|
-
content: string | ReactNode ;
|
|
18
|
-
/**
|
|
19
|
-
* Callback of confirm dialog
|
|
20
|
-
*/
|
|
21
|
-
callback: (confirmed: boolean) => void ;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const ConfirmDialog = ({title, content, onClose, children, callback, ...props }: ConfirmDialogProps) => {
|
|
25
|
-
|
|
26
|
-
return (
|
|
27
|
-
<Dialog
|
|
28
|
-
{...props}
|
|
29
|
-
>
|
|
30
|
-
<DialogTitle>
|
|
31
|
-
{title}
|
|
32
|
-
</DialogTitle>
|
|
33
|
-
<DialogContent>
|
|
34
|
-
<DialogContentText>
|
|
35
|
-
{content}
|
|
36
|
-
</DialogContentText>
|
|
37
|
-
</DialogContent>
|
|
38
|
-
{children ? <DialogActions>{children}</DialogActions> : (
|
|
39
|
-
<DialogActions>
|
|
40
|
-
<Button variant="contained" onClick={() => callback(false)}>No</Button>
|
|
41
|
-
<Button variant="contained" onClick={() => callback(true)} autoFocus>
|
|
42
|
-
Yes
|
|
43
|
-
</Button>
|
|
44
|
-
</DialogActions>
|
|
45
|
-
)}
|
|
46
|
-
</Dialog>
|
|
47
|
-
);
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
export default ConfirmDialog;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { Story, Meta } from '@storybook/react/types-6-0';
|
|
2
|
-
import CopyButton, { CopyButtonProps } from '.';
|
|
3
|
-
|
|
4
|
-
export default {
|
|
5
|
-
title: 'CopyButton',
|
|
6
|
-
component: CopyButton,
|
|
7
|
-
argType: {},
|
|
8
|
-
} as Meta;
|
|
9
|
-
|
|
10
|
-
const Template: Story<CopyButtonProps> = (args) => {
|
|
11
|
-
|
|
12
|
-
return (
|
|
13
|
-
<CopyButton {...args} />
|
|
14
|
-
);
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export const Default = Template.bind({});
|
|
18
|
-
Default.args = {
|
|
19
|
-
value: 'Copy Me!'
|
|
20
|
-
};
|
package/src/CopyButton/index.tsx
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { useCallback, useState, useEffect } from 'react';
|
|
2
|
-
import Button, { ButtonProps } from '@mui/material/Button';
|
|
3
|
-
import ContentCopyIcon from '@mui/icons-material/ContentCopy';
|
|
4
|
-
import CheckIcon from '@mui/icons-material/Check';
|
|
5
|
-
|
|
6
|
-
export interface CopyButtonProps extends ButtonProps {
|
|
7
|
-
/**
|
|
8
|
-
* Value to be copied to clipboard
|
|
9
|
-
*/
|
|
10
|
-
value: string ;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const CopyButton = ({value, sx, ...props }: CopyButtonProps) => {
|
|
14
|
-
const [copied, setCopied] = useState(false);
|
|
15
|
-
|
|
16
|
-
const copyValue = useCallback(() => {
|
|
17
|
-
navigator?.clipboard.writeText(value);
|
|
18
|
-
setCopied(true);
|
|
19
|
-
}, [value]);
|
|
20
|
-
|
|
21
|
-
useEffect(() => {
|
|
22
|
-
const iconTimer = setTimeout(() => {
|
|
23
|
-
setCopied(false);
|
|
24
|
-
}, 500);
|
|
25
|
-
|
|
26
|
-
return () => {
|
|
27
|
-
clearTimeout(iconTimer);
|
|
28
|
-
};
|
|
29
|
-
}, [copied]);
|
|
30
|
-
|
|
31
|
-
return (
|
|
32
|
-
<Button
|
|
33
|
-
variant='outlined'
|
|
34
|
-
onClick={copyValue}
|
|
35
|
-
size="small"
|
|
36
|
-
title={props.children ? `Copy ${props.children}` : `Copy ${value}`}
|
|
37
|
-
sx={{
|
|
38
|
-
textTransform: 'unset',
|
|
39
|
-
// Spread sx prop at the end to allow sx prop overrides
|
|
40
|
-
...sx,
|
|
41
|
-
}}
|
|
42
|
-
startIcon={copied ? (
|
|
43
|
-
<CheckIcon color='success' fontSize='small' />
|
|
44
|
-
) : (
|
|
45
|
-
<ContentCopyIcon fontSize='small' />
|
|
46
|
-
)}
|
|
47
|
-
// Spread props at the end to allow prop overrides
|
|
48
|
-
{...props}
|
|
49
|
-
>
|
|
50
|
-
{props.children ? props.children : value}
|
|
51
|
-
</Button>
|
|
52
|
-
);
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
export default CopyButton;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { ChangeEvent, useState } from 'react';
|
|
2
|
-
import { Story, Meta } from '@storybook/react/types-6-0';
|
|
3
|
-
import FieldTypeColor, { FieldTypeColorProps } from './';
|
|
4
|
-
|
|
5
|
-
export default {
|
|
6
|
-
title: 'FieldTypeColor',
|
|
7
|
-
component: FieldTypeColor,
|
|
8
|
-
argType: {},
|
|
9
|
-
} as Meta;
|
|
10
|
-
|
|
11
|
-
const Template: Story<FieldTypeColorProps> = (args) => {
|
|
12
|
-
const [value, setValue] = useState('');
|
|
13
|
-
|
|
14
|
-
const handleOnChange = (e: ChangeEvent<HTMLInputElement>) => {
|
|
15
|
-
setValue(e.target.value);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
return (
|
|
19
|
-
<FieldTypeColor
|
|
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: 'Color label',
|
|
31
|
-
helperText: 'Color helper text',
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { useRef } from 'react';
|
|
2
|
-
import MuiTextField, { OutlinedTextFieldProps } from '@mui/material/TextField';
|
|
3
|
-
import { Button, FormControl, FormHelperText, FormLabel, InputAdornment } from '@mui/material';
|
|
4
|
-
import BrushIcon from '@mui/icons-material/Brush';
|
|
5
|
-
|
|
6
|
-
export interface FieldTypeColorProps extends Omit<OutlinedTextFieldProps, 'variant'> {}
|
|
7
|
-
|
|
8
|
-
const FieldTypeColor = ({InputProps, label, required, ...props }: FieldTypeColorProps) => {
|
|
9
|
-
|
|
10
|
-
return (
|
|
11
|
-
<FormControl fullWidth required={required}>
|
|
12
|
-
<FormLabel>{label}</FormLabel>
|
|
13
|
-
<MuiTextField
|
|
14
|
-
size="small"
|
|
15
|
-
variant='outlined'
|
|
16
|
-
type='color'
|
|
17
|
-
InputProps={{
|
|
18
|
-
endAdornment: (
|
|
19
|
-
<InputAdornment position="end">
|
|
20
|
-
<Button
|
|
21
|
-
size="small"
|
|
22
|
-
variant="contained"
|
|
23
|
-
onClick={(e) => {
|
|
24
|
-
// References color input via event in order to open color picker
|
|
25
|
-
const input = e.currentTarget?.parentElement?.parentElement?.firstElementChild as HTMLInputElement;
|
|
26
|
-
input?.click()
|
|
27
|
-
}}
|
|
28
|
-
>
|
|
29
|
-
<BrushIcon fontSize='small' />
|
|
30
|
-
</Button>
|
|
31
|
-
</InputAdornment>
|
|
32
|
-
),
|
|
33
|
-
// Spread props at the end to allow Input prop overrides
|
|
34
|
-
...InputProps,
|
|
35
|
-
}}
|
|
36
|
-
// Spread props at the end to allow prop overrides
|
|
37
|
-
{...props}
|
|
38
|
-
/>
|
|
39
|
-
</FormControl>
|
|
40
|
-
);
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
export default FieldTypeColor;
|
|
@@ -1,23 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { AdapterDateFns } from '@mui/x-date-pickers/AdapterDateFns';
|
|
2
|
-
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
|
|
3
|
-
import { DesktopDatePicker, DesktopDatePickerProps } from '@mui/x-date-pickers';
|
|
4
|
-
import { FormControl, FormLabel, TextField } from '@mui/material';
|
|
5
|
-
|
|
6
|
-
export interface FieldTypeDateProps extends Omit<DesktopDatePickerProps<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
|
-
<DesktopDatePicker
|
|
18
|
-
data-testid="zds-date-picker"
|
|
19
|
-
renderInput={(params) =>
|
|
20
|
-
<TextField
|
|
21
|
-
{...params}
|
|
22
|
-
helperText={helperText}
|
|
23
|
-
error={error}
|
|
24
|
-
size="small"
|
|
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 FieldTypeDate;
|
|
@@ -1,23 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { AdapterDateFns } from '@mui/x-date-pickers/AdapterDateFns';
|
|
2
|
-
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
|
|
3
|
-
import { DesktopDateTimePicker, DesktopDateTimePickerProps } from '@mui/x-date-pickers';
|
|
4
|
-
import { TextField, FormControl, FormLabel } from '@mui/material';
|
|
5
|
-
|
|
6
|
-
export interface FieldTypeDateTimeProps extends Omit<DesktopDateTimePickerProps<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
|
-
<DesktopDateTimePicker
|
|
18
|
-
data-testid="zds-date-time-picker"
|
|
19
|
-
renderInput={(params) =>
|
|
20
|
-
<TextField
|
|
21
|
-
|
|
22
|
-
{...params}
|
|
23
|
-
helperText={helperText}
|
|
24
|
-
error={error}
|
|
25
|
-
size="small"
|
|
26
|
-
/>
|
|
27
|
-
}
|
|
28
|
-
// Spread props at the end to allow prop overrides
|
|
29
|
-
{...props}
|
|
30
|
-
/>
|
|
31
|
-
</LocalizationProvider>
|
|
32
|
-
</FormControl>
|
|
33
|
-
);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export default FieldTypeDateTime;
|
|
@@ -1,35 +0,0 @@
|
|
|
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
|
-
|
|
@@ -1,22 +0,0 @@
|
|
|
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;
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { ReactNode, SyntheticEvent, useState } from 'react';
|
|
2
|
-
import { Story, Meta } from '@storybook/react/types-6-0';
|
|
3
|
-
import FieldTypeOneToMany, { FieldTypeOneToManyProps } from '.';
|
|
4
|
-
|
|
5
|
-
export default {
|
|
6
|
-
title: 'FieldTypeOneToMany',
|
|
7
|
-
component: FieldTypeOneToMany,
|
|
8
|
-
argType: {},
|
|
9
|
-
} as Meta;
|
|
10
|
-
|
|
11
|
-
const Template: Story<FieldTypeOneToManyProps> = (args) => {
|
|
12
|
-
const [value, setValue] = useState<{component: string | ReactNode, value: string, inputLabel: string}[]>([]);
|
|
13
|
-
|
|
14
|
-
const [options, setOptions] = useState<{component: string | ReactNode, value: string, inputLabel: string}[]>([]);
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const handleOnOpen = async () => {
|
|
18
|
-
const largeArr = new Array(1000).fill(null);
|
|
19
|
-
await new Promise((resolve) => setTimeout(resolve, 3000))
|
|
20
|
-
const data = largeArr.map((_, idx) => ({component: <div>{`Test ${idx}`}</div>, value: String(Math.random()), inputLabel: `Test ${idx}`}));
|
|
21
|
-
setOptions(data);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const handleOnChange = (e: SyntheticEvent<Element, Event>, values: {component: string | ReactNode, value: string, inputLabel: string}[]) => {
|
|
25
|
-
setValue(values);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return (
|
|
29
|
-
<FieldTypeOneToMany
|
|
30
|
-
{...args}
|
|
31
|
-
value={value}
|
|
32
|
-
onChange={handleOnChange}
|
|
33
|
-
options={options}
|
|
34
|
-
onOpen={handleOnOpen}
|
|
35
|
-
/>
|
|
36
|
-
);
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
export const Default = Template.bind({});
|
|
40
|
-
Default.args = {
|
|
41
|
-
placeholder: 'Placeholder Text...',
|
|
42
|
-
label: 'OneToMany label',
|
|
43
|
-
helperText: 'OneToMany helperText',
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { ReactNode, useState } from 'react';
|
|
2
|
-
import { AutocompleteProps, FormControl, FormLabel, 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
|
-
label?: string;
|
|
8
|
-
helperText?: string;
|
|
9
|
-
placeholder?: string;
|
|
10
|
-
error?: boolean;
|
|
11
|
-
required?: boolean;
|
|
12
|
-
/**
|
|
13
|
-
* Callback to be fired upon opening the dropdown
|
|
14
|
-
*/
|
|
15
|
-
onOpen: () => Promise<any>;
|
|
16
|
-
/**
|
|
17
|
-
* Structure for option
|
|
18
|
-
*/
|
|
19
|
-
options: {
|
|
20
|
-
/**
|
|
21
|
-
* Component to be rendered in the dropdown
|
|
22
|
-
*/
|
|
23
|
-
component: ReactNode | string;
|
|
24
|
-
/**
|
|
25
|
-
* Value of option
|
|
26
|
-
*/
|
|
27
|
-
value: string;
|
|
28
|
-
/**
|
|
29
|
-
* Label that should display in the input when selected
|
|
30
|
-
*/
|
|
31
|
-
inputLabel: string;
|
|
32
|
-
}[]
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const FieldTypeOneToMany = ({label, helperText, placeholder, error, onOpen, options, required, ...props }: FieldTypeOneToManyProps) => {
|
|
36
|
-
const [loaded, setLoaded] = useState(false);
|
|
37
|
-
const [loading, setLoading] = useState(false);
|
|
38
|
-
|
|
39
|
-
const handleOpen = () => {
|
|
40
|
-
if (!loaded && onOpen) {
|
|
41
|
-
onOpen().then(() => {
|
|
42
|
-
setLoading(false);
|
|
43
|
-
});
|
|
44
|
-
setLoading(true);
|
|
45
|
-
setLoaded(true);
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
return (
|
|
50
|
-
<FormControl fullWidth required={required}>
|
|
51
|
-
<FormLabel>{label}</FormLabel>
|
|
52
|
-
<Autocomplete
|
|
53
|
-
onOpen={handleOpen}
|
|
54
|
-
loading={loading}
|
|
55
|
-
fullWidth
|
|
56
|
-
multiple
|
|
57
|
-
disableListWrap
|
|
58
|
-
disableClearable
|
|
59
|
-
disablePortal
|
|
60
|
-
size='small'
|
|
61
|
-
PopperComponent={StyledPopper}
|
|
62
|
-
ListboxComponent={ListboxComponent}
|
|
63
|
-
renderInput={(params) => (
|
|
64
|
-
<TextField
|
|
65
|
-
{...params}
|
|
66
|
-
helperText={helperText}
|
|
67
|
-
error={error}
|
|
68
|
-
placeholder={placeholder}
|
|
69
|
-
/>
|
|
70
|
-
)}
|
|
71
|
-
options={loading ? [] : options}
|
|
72
|
-
getOptionLabel={(option) => option.inputLabel}
|
|
73
|
-
renderOption={(props, option) => [props, option.component]}
|
|
74
|
-
{...props}
|
|
75
|
-
/>
|
|
76
|
-
</FormControl>
|
|
77
|
-
);
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
export default FieldTypeOneToMany;
|
|
81
|
-
|
|
82
|
-
const StyledPopper = styled(Popper)({
|
|
83
|
-
[`& .${autocompleteClasses.listbox}`]: {
|
|
84
|
-
boxSizing: 'border-box',
|
|
85
|
-
'& ul': {
|
|
86
|
-
padding: 0,
|
|
87
|
-
margin: 0,
|
|
88
|
-
},
|
|
89
|
-
},
|
|
90
|
-
});
|
|
@@ -1,46 +0,0 @@
|
|
|
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
|
-
|
|
@@ -1,96 +0,0 @@
|
|
|
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
|
-
});
|