@zesty-io/material 0.0.2 → 0.1.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/.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 +20 -0
- package/es/FieldTypeDate/FieldTypeDate.stories.d.ts +5 -0
- package/es/FieldTypeDate/FieldTypeDate.stories.js +20 -0
- package/es/FieldTypeDate/index.d.ts +11 -0
- package/es/FieldTypeDate/index.js +14 -0
- package/es/FieldTypeDateTime/FieldTypeDateTime.stories.d.ts +5 -0
- package/es/FieldTypeDateTime/FieldTypeDateTime.stories.js +20 -0
- package/es/FieldTypeDateTime/index.d.ts +11 -0
- package/es/FieldTypeDateTime/index.js +14 -0
- package/es/FieldTypeDropdown/FieldTypeDropwdon.stories.d.ts +5 -0
- package/es/FieldTypeDropdown/FieldTypeDropwdon.stories.js +34 -0
- package/es/FieldTypeDropdown/index.d.ts +11 -0
- package/es/FieldTypeDropdown/index.js +15 -0
- package/es/FieldTypeNumber/FieldTypeNumber.stories.d.ts +5 -0
- package/es/FieldTypeNumber/FieldTypeNumber.stories.js +20 -0
- package/es/FieldTypeNumber/index.d.ts +6 -0
- package/es/FieldTypeNumber/index.js +10 -0
- package/es/FieldTypeSort/FieldTypeSort.stories.d.ts +5 -0
- package/es/FieldTypeSort/FieldTypeSort.stories.js +21 -0
- package/es/FieldTypeSort/index.d.ts +7 -0
- package/es/FieldTypeSort/index.js +32 -0
- package/es/FieldTypeText/FieldTypeText.stories.d.ts +6 -0
- package/es/FieldTypeText/FieldTypeText.stories.js +27 -0
- package/es/FieldTypeText/index.d.ts +12 -0
- package/es/FieldTypeText/index.js +15 -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 +21 -0
- package/es/index.d.ts +10 -0
- package/es/index.js +10 -0
- package/es/theme/Theme.stories.d.ts +4 -0
- package/es/theme/Theme.stories.js +10 -0
- package/es/theme/index.js +46 -12
- package/package.json +5 -2
- 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 +45 -0
- package/src/FieldTypeDate/FieldTypeDate.stories.tsx +26 -0
- package/src/FieldTypeDate/index.tsx +37 -0
- package/src/FieldTypeDateTime/FieldTypeDateTime.stories.tsx +26 -0
- package/src/FieldTypeDateTime/index.tsx +37 -0
- package/src/FieldTypeDropdown/FieldTypeDropwdon.stories.tsx +51 -0
- package/src/FieldTypeDropdown/index.tsx +43 -0
- package/src/FieldTypeNumber/FieldTypeNumber.stories.tsx +34 -0
- package/src/FieldTypeNumber/index.tsx +23 -0
- package/src/FieldTypeSort/FieldTypeSort.stories.tsx +35 -0
- package/src/FieldTypeSort/index.tsx +65 -0
- package/src/FieldTypeText/FieldTypeText.stories.tsx +41 -0
- package/src/FieldTypeText/index.tsx +42 -0
- package/src/FieldTypeUrl/FieldTypeUrl.stories.tsx +33 -0
- package/src/FieldTypeUrl/index.tsx +50 -0
- package/src/index.ts +10 -0
- package/src/{stories → theme}/Theme.stories.tsx +1 -1
- package/src/theme/index.ts +52 -13
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { OutlinedTextFieldProps } from '@mui/material/TextField';
|
|
3
|
+
export interface FieldTypeUrlProps extends Omit<OutlinedTextFieldProps, 'variant'> {
|
|
4
|
+
/**
|
|
5
|
+
* Max length of the field
|
|
6
|
+
* @default 2000
|
|
7
|
+
*/
|
|
8
|
+
maxLength?: number;
|
|
9
|
+
value: string;
|
|
10
|
+
}
|
|
11
|
+
declare const FieldTypeUrl: ({ maxLength, value, helperText, InputProps, InputLabelProps, inputProps, ...props }: FieldTypeUrlProps) => JSX.Element;
|
|
12
|
+
export default FieldTypeUrl;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useRef } from 'react';
|
|
3
|
+
import MuiTextField from '@mui/material/TextField';
|
|
4
|
+
import { InputAdornment } from '@mui/material';
|
|
5
|
+
const FieldTypeUrl = ({ maxLength = 2000, value, helperText, InputProps, InputLabelProps, inputProps, ...props }) => {
|
|
6
|
+
const inputRef = useRef(null);
|
|
7
|
+
return (_jsx(MuiTextField, { size: "small", type: 'url', variant: 'outlined', value: value, InputProps: {
|
|
8
|
+
endAdornment: (_jsx(InputAdornment, { position: "end", children: _jsxs(_Fragment, { children: [value.length, "/", maxLength] }) })),
|
|
9
|
+
// Spread props at the end to allow Input prop overrides
|
|
10
|
+
...InputProps,
|
|
11
|
+
}, InputLabelProps: {
|
|
12
|
+
shrink: true,
|
|
13
|
+
// Spread props at the end to allow InputLabel prop overrides
|
|
14
|
+
...InputLabelProps,
|
|
15
|
+
}, inputProps: {
|
|
16
|
+
ref: inputRef,
|
|
17
|
+
// Spread props at the end to allow inputProps prop overrides
|
|
18
|
+
...inputProps,
|
|
19
|
+
}, error: (value && !inputRef.current?.validity.valid) || value.length > maxLength, helperText: value.length > maxLength ? 'Your input is over the specified limit' : (value && !inputRef.current?.validity.valid) ? 'Your input is not a valid url' : helperText, ...props }));
|
|
20
|
+
};
|
|
21
|
+
export default FieldTypeUrl;
|
package/es/index.d.ts
CHANGED
|
@@ -1 +1,11 @@
|
|
|
1
1
|
export { default as theme } from './theme';
|
|
2
|
+
export { default as FieldTypeText } from './FieldTypeText';
|
|
3
|
+
export { default as FieldTypeSort } from './FieldTypeSort';
|
|
4
|
+
export { default as FieldTypeUrl } from './FieldTypeUrl';
|
|
5
|
+
export { default as FieldTypeDate } from './FieldTypeDate';
|
|
6
|
+
export { default as FieldTypeDateTime } from './FieldTypeDateTime';
|
|
7
|
+
export { default as FieldTypeColor } from './FieldTypeColor';
|
|
8
|
+
export { default as FieldTypeNumber } from './FieldTypeNumber';
|
|
9
|
+
export { default as FieldTypeDropdown } from './FieldTypeDropdown';
|
|
10
|
+
export { default as CopyButton } from './CopyButton';
|
|
11
|
+
export { default as ConfirmModal } from './ConfirmModal';
|
package/es/index.js
CHANGED
|
@@ -1 +1,11 @@
|
|
|
1
1
|
export { default as theme } from './theme';
|
|
2
|
+
export { default as FieldTypeText } from './FieldTypeText';
|
|
3
|
+
export { default as FieldTypeSort } from './FieldTypeSort';
|
|
4
|
+
export { default as FieldTypeUrl } from './FieldTypeUrl';
|
|
5
|
+
export { default as FieldTypeDate } from './FieldTypeDate';
|
|
6
|
+
export { default as FieldTypeDateTime } from './FieldTypeDateTime';
|
|
7
|
+
export { default as FieldTypeColor } from './FieldTypeColor';
|
|
8
|
+
export { default as FieldTypeNumber } from './FieldTypeNumber';
|
|
9
|
+
export { default as FieldTypeDropdown } from './FieldTypeDropdown';
|
|
10
|
+
export { default as CopyButton } from './CopyButton';
|
|
11
|
+
export { default as ConfirmModal } from './ConfirmModal';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import ReactJson from 'react-json-view';
|
|
3
|
+
import theme from '.';
|
|
4
|
+
export default {
|
|
5
|
+
title: 'Theme',
|
|
6
|
+
};
|
|
7
|
+
const Template = (args) => {
|
|
8
|
+
return (_jsx(ReactJson, { src: theme }));
|
|
9
|
+
};
|
|
10
|
+
export const Default = Template.bind({});
|
package/es/theme/index.js
CHANGED
|
@@ -6,18 +6,52 @@ let theme = createTheme({
|
|
|
6
6
|
typography,
|
|
7
7
|
});
|
|
8
8
|
theme = createTheme(theme, {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
lineHeight: "20px",
|
|
9
|
+
components: {
|
|
10
|
+
MuiButton: {
|
|
11
|
+
styleOverrides: {
|
|
12
|
+
root: {
|
|
13
|
+
minWidth: 'auto',
|
|
14
|
+
},
|
|
16
15
|
},
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
},
|
|
17
|
+
MuiTooltip: {
|
|
18
|
+
styleOverrides: {
|
|
19
|
+
tooltip: {
|
|
20
|
+
color: theme.palette.primary.contrastText,
|
|
21
|
+
backgroundColor: theme.palette.primary.main,
|
|
22
|
+
fontSize: '14px',
|
|
23
|
+
lineHeight: '20px',
|
|
24
|
+
},
|
|
25
|
+
arrow: {
|
|
26
|
+
color: theme.palette.primary.main,
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
MuiInputBase: {
|
|
31
|
+
styleOverrides: {
|
|
32
|
+
root: {
|
|
33
|
+
backgroundColor: theme.palette.primary.contrastText,
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
MuiFormLabel: {
|
|
38
|
+
styleOverrides: {
|
|
39
|
+
root: {
|
|
40
|
+
color: theme.palette.primary.dark,
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
MuiToggleButton: {
|
|
45
|
+
styleOverrides: {
|
|
46
|
+
root: ({ ownerState, theme }) => ({
|
|
47
|
+
backgroundColor: `${theme.palette[ownerState.color].contrastText} !important`,
|
|
48
|
+
...(ownerState.selected && {
|
|
49
|
+
color: `${theme.palette[ownerState.color].contrastText} !important`,
|
|
50
|
+
backgroundColor: `${theme.palette[ownerState.color].main} !important`,
|
|
51
|
+
}),
|
|
52
|
+
}),
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
},
|
|
22
56
|
});
|
|
23
57
|
export default theme;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zesty-io/material",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "Contains custom components which are in addition to the @mui design-system",
|
|
5
5
|
"author": "Zesty.io",
|
|
6
6
|
"license": "MIT",
|
|
@@ -30,7 +30,9 @@
|
|
|
30
30
|
"@emotion/react": "^11.9.0",
|
|
31
31
|
"@emotion/styled": "^11.8.1",
|
|
32
32
|
"@mui/icons-material": "^5.6.2",
|
|
33
|
-
"@mui/material": "^5.6.4"
|
|
33
|
+
"@mui/material": "^5.6.4",
|
|
34
|
+
"@mui/x-date-pickers": "^5.0.0-alpha.5",
|
|
35
|
+
"date-fns": "^2.28.0"
|
|
34
36
|
},
|
|
35
37
|
"devDependencies": {
|
|
36
38
|
"@babel/core": "^7.17.10",
|
|
@@ -43,6 +45,7 @@
|
|
|
43
45
|
"babel-loader": "^8.2.5",
|
|
44
46
|
"gh-pages": "^3.2.3",
|
|
45
47
|
"react": "^18.1.0",
|
|
48
|
+
"react-docgen-typescript": "^2.2.2",
|
|
46
49
|
"react-dom": "^18.1.0",
|
|
47
50
|
"react-json-view": "^1.21.3",
|
|
48
51
|
"typescript": "^4.6.3"
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import { Story, Meta } from '@storybook/react/types-6-0';
|
|
3
|
+
import { Button, Stack } from '@mui/material';
|
|
4
|
+
import ConfirmDialog, { ConfirmDialogProps } from '.';
|
|
5
|
+
|
|
6
|
+
export default {
|
|
7
|
+
title: 'ConfirmDialog',
|
|
8
|
+
component: ConfirmDialog,
|
|
9
|
+
argType: {},
|
|
10
|
+
} as Meta;
|
|
11
|
+
|
|
12
|
+
const Template: Story<ConfirmDialogProps> = (args) => {
|
|
13
|
+
const [open, setOpen] = useState(false);
|
|
14
|
+
|
|
15
|
+
return (
|
|
16
|
+
<>
|
|
17
|
+
<Button variant="contained" onClick={() => setOpen(true)}>Click me to open</Button>
|
|
18
|
+
<ConfirmDialog {...args} open={open} callback={(confirmed) => setOpen(false) } />
|
|
19
|
+
</>
|
|
20
|
+
);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const Default = Template.bind({});
|
|
24
|
+
Default.args = {
|
|
25
|
+
title: 'Confirm modal title',
|
|
26
|
+
content: 'Confirm modal content',
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const CustomChildren = Template.bind({});
|
|
30
|
+
CustomChildren.args = {
|
|
31
|
+
title: 'Confirm modal title',
|
|
32
|
+
content: 'Confirm modal content',
|
|
33
|
+
children: <><Button color="error" variant="contained">Custom 1</Button><Button color="success" variant="contained">Custom 2</Button></>
|
|
34
|
+
};
|
|
35
|
+
|
|
@@ -0,0 +1,50 @@
|
|
|
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;
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
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
|
+
// Spread props at the end to allow prop overrides
|
|
43
|
+
{...props}
|
|
44
|
+
>
|
|
45
|
+
{copied ? (
|
|
46
|
+
<CheckIcon color='success' fontSize='small' />
|
|
47
|
+
) : (
|
|
48
|
+
<ContentCopyIcon fontSize='small' />
|
|
49
|
+
)}
|
|
50
|
+
{props.children ? props.children : value}
|
|
51
|
+
</Button>
|
|
52
|
+
);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export default CopyButton;
|
|
@@ -0,0 +1,35 @@
|
|
|
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
|
+
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { useRef } from 'react';
|
|
2
|
+
import MuiTextField, { OutlinedTextFieldProps } from '@mui/material/TextField';
|
|
3
|
+
import { Button, 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, InputLabelProps, ...props }: FieldTypeColorProps) => {
|
|
9
|
+
|
|
10
|
+
return (
|
|
11
|
+
<MuiTextField
|
|
12
|
+
size="small"
|
|
13
|
+
variant='outlined'
|
|
14
|
+
type='color'
|
|
15
|
+
InputProps={{
|
|
16
|
+
endAdornment: (
|
|
17
|
+
<InputAdornment position="end">
|
|
18
|
+
<Button
|
|
19
|
+
size="small"
|
|
20
|
+
variant="contained"
|
|
21
|
+
onClick={(e) => {
|
|
22
|
+
// References color input via event in order to open color picker
|
|
23
|
+
const input = e.currentTarget?.parentElement?.parentElement?.firstElementChild as HTMLInputElement;
|
|
24
|
+
input?.click()
|
|
25
|
+
}}
|
|
26
|
+
>
|
|
27
|
+
<BrushIcon fontSize='small' />
|
|
28
|
+
</Button>
|
|
29
|
+
</InputAdornment>
|
|
30
|
+
),
|
|
31
|
+
// Spread props at the end to allow Input prop overrides
|
|
32
|
+
...InputProps,
|
|
33
|
+
}}
|
|
34
|
+
InputLabelProps={{
|
|
35
|
+
shrink: true,
|
|
36
|
+
// Spread props at the end to allow InputLabel prop overrides
|
|
37
|
+
...InputLabelProps,
|
|
38
|
+
}}
|
|
39
|
+
// Spread props at the end to allow prop overrides
|
|
40
|
+
{...props}
|
|
41
|
+
/>
|
|
42
|
+
);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export default FieldTypeColor;
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
textFieldProps: {
|
|
23
|
+
helperText: 'Date helper text',
|
|
24
|
+
error: false,
|
|
25
|
+
}
|
|
26
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
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 { TextField, TextFieldProps } from '@mui/material';
|
|
5
|
+
|
|
6
|
+
export interface FieldTypeDateProps extends Omit<DatePickerProps<Date, Date>, 'renderInput'> {
|
|
7
|
+
/**
|
|
8
|
+
* Props passed to TextField component
|
|
9
|
+
*/
|
|
10
|
+
textFieldProps?: TextFieldProps;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const FieldTypeDate = ({textFieldProps, ...props}: FieldTypeDateProps) => {
|
|
14
|
+
return (
|
|
15
|
+
<LocalizationProvider dateAdapter={AdapterDateFns}>
|
|
16
|
+
<DatePicker
|
|
17
|
+
data-testid="zds-date-picker"
|
|
18
|
+
renderInput={(params) =>
|
|
19
|
+
<TextField
|
|
20
|
+
InputLabelProps={{
|
|
21
|
+
shrink: true,
|
|
22
|
+
// Spread props at the end to allow InputLabelProps overrides
|
|
23
|
+
...textFieldProps?.InputLabelProps,
|
|
24
|
+
}}
|
|
25
|
+
{...params}
|
|
26
|
+
// Spread props at the end to allow textFieldProps overrides
|
|
27
|
+
{...textFieldProps}
|
|
28
|
+
/>
|
|
29
|
+
}
|
|
30
|
+
// Spread props at the end to allow prop overrides
|
|
31
|
+
{...props}
|
|
32
|
+
/>
|
|
33
|
+
</LocalizationProvider>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export default FieldTypeDate;
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
textFieldProps: {
|
|
23
|
+
helperText: 'Date helper text',
|
|
24
|
+
error: false,
|
|
25
|
+
}
|
|
26
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
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, TextFieldProps } from '@mui/material';
|
|
5
|
+
|
|
6
|
+
export interface FieldTypeDateTimeProps extends Omit<DateTimePickerProps<Date, Date>, 'renderInput'> {
|
|
7
|
+
/**
|
|
8
|
+
* Props passed to TextField component
|
|
9
|
+
*/
|
|
10
|
+
textFieldProps?: TextFieldProps;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const FieldTypeDateTime = ({textFieldProps, ...props}: FieldTypeDateTimeProps) => {
|
|
14
|
+
return (
|
|
15
|
+
<LocalizationProvider dateAdapter={AdapterDateFns}>
|
|
16
|
+
<DateTimePicker
|
|
17
|
+
data-testid="zds-date-picker"
|
|
18
|
+
renderInput={(params) =>
|
|
19
|
+
<TextField
|
|
20
|
+
InputLabelProps={{
|
|
21
|
+
shrink: true,
|
|
22
|
+
// Spread props at the end to allow InputLabelProps overrides
|
|
23
|
+
...textFieldProps?.InputLabelProps,
|
|
24
|
+
}}
|
|
25
|
+
{...params}
|
|
26
|
+
// Spread props at the end to allow textFieldProps overrides
|
|
27
|
+
{...textFieldProps}
|
|
28
|
+
/>
|
|
29
|
+
}
|
|
30
|
+
// Spread props at the end to allow prop overrides
|
|
31
|
+
{...props}
|
|
32
|
+
/>
|
|
33
|
+
</LocalizationProvider>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export default FieldTypeDateTime;
|
|
@@ -0,0 +1,51 @@
|
|
|
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: 'Number label',
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { MenuItem } from '@mui/material';
|
|
2
|
+
import MuiTextField, { OutlinedTextFieldProps } from '@mui/material/TextField';
|
|
3
|
+
|
|
4
|
+
interface Option {
|
|
5
|
+
label: string;
|
|
6
|
+
value: any;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface FieldTypeDropdownProps extends Omit<OutlinedTextFieldProps, 'variant'> {
|
|
10
|
+
options: Option[];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const FieldTypeDropdown = ({InputLabelProps, options, ...props }: FieldTypeDropdownProps) => {
|
|
14
|
+
|
|
15
|
+
return (
|
|
16
|
+
<MuiTextField
|
|
17
|
+
size="small"
|
|
18
|
+
variant='outlined'
|
|
19
|
+
select
|
|
20
|
+
InputLabelProps={{
|
|
21
|
+
shrink: true,
|
|
22
|
+
// Spread props at the end to allow InputLabel prop overrides
|
|
23
|
+
...InputLabelProps,
|
|
24
|
+
}}
|
|
25
|
+
// Spread props at the end to allow prop overrides
|
|
26
|
+
SelectProps={{
|
|
27
|
+
displayEmpty: true,
|
|
28
|
+
}}
|
|
29
|
+
{...props}
|
|
30
|
+
>
|
|
31
|
+
<MenuItem key={''} value={''}>
|
|
32
|
+
- None -
|
|
33
|
+
</MenuItem>
|
|
34
|
+
{options.map((option) => (
|
|
35
|
+
<MenuItem key={option.value} value={option.value}>
|
|
36
|
+
{option.label}
|
|
37
|
+
</MenuItem>
|
|
38
|
+
))}
|
|
39
|
+
</MuiTextField>
|
|
40
|
+
);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export default FieldTypeDropdown;
|
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
};
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|