@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.
Files changed (65) hide show
  1. package/es/ConfirmDialog/ConfirmDialog.stories.d.ts +6 -0
  2. package/es/ConfirmDialog/ConfirmDialog.stories.js +24 -0
  3. package/es/ConfirmDialog/index.d.ts +18 -0
  4. package/es/ConfirmDialog/index.js +11 -0
  5. package/es/CopyButton/index.js +3 -3
  6. package/es/FieldTypeColor/index.d.ts +1 -1
  7. package/es/FieldTypeColor/index.js +12 -16
  8. package/es/FieldTypeDate/FieldTypeDate.stories.js +1 -4
  9. package/es/FieldTypeDate/index.d.ts +4 -6
  10. package/es/FieldTypeDate/index.js +4 -8
  11. package/es/FieldTypeDateTime/FieldTypeDateTime.stories.js +1 -4
  12. package/es/FieldTypeDateTime/index.d.ts +4 -6
  13. package/es/FieldTypeDateTime/index.js +4 -8
  14. package/es/FieldTypeDropdown/FieldTypeDropwdon.stories.js +2 -1
  15. package/es/FieldTypeDropdown/index.d.ts +1 -1
  16. package/es/FieldTypeDropdown/index.js +5 -10
  17. package/es/FieldTypeNumber/FieldTypeNumber.stories.js +1 -0
  18. package/es/FieldTypeNumber/index.d.ts +1 -1
  19. package/es/FieldTypeNumber/index.js +4 -7
  20. package/es/FieldTypeOneToMany/FieldTypeOneToMany.stories.d.ts +5 -0
  21. package/es/FieldTypeOneToMany/FieldTypeOneToMany.stories.js +28 -0
  22. package/es/FieldTypeOneToMany/index.d.ts +32 -0
  23. package/es/FieldTypeOneToMany/index.js +29 -0
  24. package/es/FieldTypeOneToOne/FieldTypeOneToOne.stories.d.ts +5 -0
  25. package/es/FieldTypeOneToOne/FieldTypeOneToOne.stories.js +28 -0
  26. package/es/FieldTypeOneToOne/index.d.ts +34 -0
  27. package/es/FieldTypeOneToOne/index.js +33 -0
  28. package/es/FieldTypeSort/FieldTypeSort.stories.js +1 -0
  29. package/es/FieldTypeSort/index.d.ts +1 -1
  30. package/es/FieldTypeSort/index.js +17 -27
  31. package/es/FieldTypeText/FieldTypeText.stories.js +4 -2
  32. package/es/FieldTypeText/index.d.ts +1 -1
  33. package/es/FieldTypeText/index.js +4 -12
  34. package/es/FieldTypeUrl/index.d.ts +1 -1
  35. package/es/FieldTypeUrl/index.js +8 -16
  36. package/es/index.d.ts +3 -1
  37. package/es/index.js +3 -1
  38. package/es/theme/index.js +10 -0
  39. package/es/utils/virtualization.d.ts +2 -0
  40. package/es/utils/virtualization.js +63 -0
  41. package/package.json +5 -3
  42. package/src/{ConfirmModal/ConfirmModal.stories.tsx → ConfirmDialog/ConfirmDialog.stories.tsx} +0 -0
  43. package/src/{ConfirmModal → ConfirmDialog}/index.tsx +0 -0
  44. package/src/CopyButton/index.tsx +6 -6
  45. package/src/FieldTypeColor/index.tsx +5 -7
  46. package/src/FieldTypeDate/FieldTypeDate.stories.tsx +1 -4
  47. package/src/FieldTypeDate/index.tsx +22 -25
  48. package/src/FieldTypeDateTime/FieldTypeDateTime.stories.tsx +1 -4
  49. package/src/FieldTypeDateTime/index.tsx +23 -25
  50. package/src/FieldTypeDropdown/FieldTypeDropwdon.stories.tsx +2 -1
  51. package/src/FieldTypeDropdown/index.tsx +5 -7
  52. package/src/FieldTypeNumber/FieldTypeNumber.stories.tsx +1 -0
  53. package/src/FieldTypeNumber/index.tsx +5 -6
  54. package/src/FieldTypeOneToMany/FieldTypeOneToMany.stories.tsx +47 -0
  55. package/src/FieldTypeOneToMany/index.tsx +90 -0
  56. package/src/FieldTypeOneToOne/FieldTypeOneToOne.stories.tsx +46 -0
  57. package/src/FieldTypeOneToOne/index.tsx +96 -0
  58. package/src/FieldTypeSort/FieldTypeSort.stories.tsx +1 -0
  59. package/src/FieldTypeSort/index.tsx +9 -18
  60. package/src/FieldTypeText/FieldTypeText.stories.tsx +9 -5
  61. package/src/FieldTypeText/index.tsx +11 -18
  62. package/src/FieldTypeUrl/index.tsx +11 -18
  63. package/src/index.ts +3 -1
  64. package/src/theme/index.ts +10 -0
  65. package/src/utils/virtualization.tsx +107 -0
@@ -0,0 +1,6 @@
1
+ import { Story, Meta } from '@storybook/react/types-6-0';
2
+ import { ConfirmDialogProps } from '.';
3
+ declare const _default: Meta<import("@storybook/react/types-6-0").Args>;
4
+ export default _default;
5
+ export declare const Default: Story<ConfirmDialogProps>;
6
+ export declare const CustomChildren: Story<ConfirmDialogProps>;
@@ -0,0 +1,24 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState } from 'react';
3
+ import { Button } from '@mui/material';
4
+ import ConfirmDialog from '.';
5
+ export default {
6
+ title: 'ConfirmDialog',
7
+ component: ConfirmDialog,
8
+ argType: {},
9
+ };
10
+ const Template = (args) => {
11
+ const [open, setOpen] = useState(false);
12
+ return (_jsxs(_Fragment, { children: [_jsx(Button, { variant: "contained", onClick: () => setOpen(true), children: "Click me to open" }), _jsx(ConfirmDialog, { ...args, open: open, callback: (confirmed) => setOpen(false) })] }));
13
+ };
14
+ export const Default = Template.bind({});
15
+ Default.args = {
16
+ title: 'Confirm modal title',
17
+ content: 'Confirm modal content',
18
+ };
19
+ export const CustomChildren = Template.bind({});
20
+ CustomChildren.args = {
21
+ title: 'Confirm modal title',
22
+ content: 'Confirm modal content',
23
+ children: _jsxs(_Fragment, { children: [_jsx(Button, { color: "error", variant: "contained", children: "Custom 1" }), _jsx(Button, { color: "success", variant: "contained", children: "Custom 2" })] })
24
+ };
@@ -0,0 +1,18 @@
1
+ import { ReactNode } from 'react';
2
+ import { DialogProps } from '@mui/material/Dialog';
3
+ export interface ConfirmDialogProps extends Omit<DialogProps, 'title'> {
4
+ /**
5
+ * Title of confirm dialog
6
+ */
7
+ title: string | ReactNode;
8
+ /**
9
+ * Content of confirm dialog
10
+ */
11
+ content: string | ReactNode;
12
+ /**
13
+ * Callback of confirm dialog
14
+ */
15
+ callback: (confirmed: boolean) => void;
16
+ }
17
+ declare const ConfirmDialog: ({ title, content, onClose, children, callback, ...props }: ConfirmDialogProps) => JSX.Element;
18
+ export default ConfirmDialog;
@@ -0,0 +1,11 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import Dialog 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
+ const ConfirmDialog = ({ title, content, onClose, children, callback, ...props }) => {
9
+ return (_jsxs(Dialog, { ...props, children: [_jsx(DialogTitle, { children: title }), _jsx(DialogContent, { children: _jsx(DialogContentText, { children: content }) }), children ? _jsx(DialogActions, { children: children }) : (_jsxs(DialogActions, { children: [_jsx(Button, { variant: "contained", onClick: () => callback(false), children: "No" }), _jsx(Button, { variant: "contained", onClick: () => callback(true), autoFocus: true, children: "Yes" })] }))] }));
10
+ };
11
+ export default ConfirmDialog;
@@ -1,4 +1,4 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { useCallback, useState, useEffect } from 'react';
3
3
  import Button from '@mui/material/Button';
4
4
  import ContentCopyIcon from '@mui/icons-material/ContentCopy';
@@ -17,10 +17,10 @@ const CopyButton = ({ value, sx, ...props }) => {
17
17
  clearTimeout(iconTimer);
18
18
  };
19
19
  }, [copied]);
20
- return (_jsxs(Button, { variant: 'outlined', onClick: copyValue, size: "small", title: props.children ? `Copy ${props.children}` : `Copy ${value}`, sx: {
20
+ return (_jsx(Button, { variant: 'outlined', onClick: copyValue, size: "small", title: props.children ? `Copy ${props.children}` : `Copy ${value}`, sx: {
21
21
  textTransform: 'unset',
22
22
  // Spread sx prop at the end to allow sx prop overrides
23
23
  ...sx,
24
- }, ...props, children: [copied ? (_jsx(CheckIcon, { color: 'success', fontSize: 'small' })) : (_jsx(ContentCopyIcon, { fontSize: 'small' })), props.children ? props.children : value] }));
24
+ }, startIcon: copied ? (_jsx(CheckIcon, { color: 'success', fontSize: 'small' })) : (_jsx(ContentCopyIcon, { fontSize: 'small' })), ...props, children: props.children ? props.children : value }));
25
25
  };
26
26
  export default CopyButton;
@@ -2,5 +2,5 @@
2
2
  import { OutlinedTextFieldProps } from '@mui/material/TextField';
3
3
  export interface FieldTypeColorProps extends Omit<OutlinedTextFieldProps, 'variant'> {
4
4
  }
5
- declare const FieldTypeColor: ({ InputProps, InputLabelProps, ...props }: FieldTypeColorProps) => JSX.Element;
5
+ declare const FieldTypeColor: ({ InputProps, label, required, ...props }: FieldTypeColorProps) => JSX.Element;
6
6
  export default FieldTypeColor;
@@ -1,20 +1,16 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import MuiTextField from '@mui/material/TextField';
3
- import { Button, InputAdornment } from '@mui/material';
3
+ import { Button, FormControl, FormLabel, InputAdornment } from '@mui/material';
4
4
  import BrushIcon from '@mui/icons-material/Brush';
5
- const FieldTypeColor = ({ InputProps, InputLabelProps, ...props }) => {
6
- return (_jsx(MuiTextField, { size: "small", variant: 'outlined', type: 'color', InputProps: {
7
- endAdornment: (_jsx(InputAdornment, { position: "end", children: _jsx(Button, { size: "small", variant: "contained", onClick: (e) => {
8
- // References color input via event in order to open color picker
9
- const input = e.currentTarget?.parentElement?.parentElement?.firstElementChild;
10
- input?.click();
11
- }, children: _jsx(BrushIcon, { fontSize: 'small' }) }) })),
12
- // Spread props at the end to allow Input prop overrides
13
- ...InputProps,
14
- }, InputLabelProps: {
15
- shrink: true,
16
- // Spread props at the end to allow InputLabel prop overrides
17
- ...InputLabelProps,
18
- }, ...props }));
5
+ const FieldTypeColor = ({ InputProps, label, required, ...props }) => {
6
+ return (_jsxs(FormControl, { fullWidth: true, required: required, children: [_jsx(FormLabel, { children: label }), _jsx(MuiTextField, { size: "small", variant: 'outlined', type: 'color', InputProps: {
7
+ endAdornment: (_jsx(InputAdornment, { position: "end", children: _jsx(Button, { size: "small", variant: "contained", onClick: (e) => {
8
+ // References color input via event in order to open color picker
9
+ const input = e.currentTarget?.parentElement?.parentElement?.firstElementChild;
10
+ input?.click();
11
+ }, children: _jsx(BrushIcon, { fontSize: 'small' }) }) })),
12
+ // Spread props at the end to allow Input prop overrides
13
+ ...InputProps,
14
+ }, ...props })] }));
19
15
  };
20
16
  export default FieldTypeColor;
@@ -13,8 +13,5 @@ const Template = (args) => {
13
13
  export const Default = Template.bind({});
14
14
  Default.args = {
15
15
  label: 'Date label',
16
- textFieldProps: {
17
- helperText: 'Date helper text',
18
- error: false,
19
- }
16
+ helperText: 'Date helper text',
20
17
  };
@@ -1,11 +1,9 @@
1
1
  /// <reference types="react" />
2
2
  import { DatePickerProps } from '@mui/x-date-pickers/DatePicker';
3
- import { TextFieldProps } from '@mui/material';
4
3
  export interface FieldTypeDateProps extends Omit<DatePickerProps<Date, Date>, 'renderInput'> {
5
- /**
6
- * Props passed to TextField component
7
- */
8
- textFieldProps?: TextFieldProps;
4
+ helperText?: string;
5
+ error?: boolean;
6
+ required?: boolean;
9
7
  }
10
- declare const FieldTypeDate: ({ textFieldProps, ...props }: FieldTypeDateProps) => JSX.Element;
8
+ declare const FieldTypeDate: ({ label, helperText, error, required, ...props }: FieldTypeDateProps) => JSX.Element;
11
9
  export default FieldTypeDate;
@@ -1,14 +1,10 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { AdapterDateFns } from '@mui/x-date-pickers/AdapterDateFns';
3
3
  import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
4
4
  import { DatePicker } from '@mui/x-date-pickers/DatePicker';
5
- import { TextField } from '@mui/material';
5
+ import { FormControl, FormLabel, TextField } from '@mui/material';
6
6
  ;
7
- const FieldTypeDate = ({ textFieldProps, ...props }) => {
8
- return (_jsx(LocalizationProvider, { dateAdapter: AdapterDateFns, children: _jsx(DatePicker, { "data-testid": "zds-date-picker", renderInput: (params) => _jsx(TextField, { InputLabelProps: {
9
- shrink: true,
10
- // Spread props at the end to allow InputLabelProps overrides
11
- ...textFieldProps?.InputLabelProps,
12
- }, ...params, ...textFieldProps }), ...props }) }));
7
+ const FieldTypeDate = ({ label, helperText, error, required, ...props }) => {
8
+ return (_jsxs(FormControl, { fullWidth: true, required: required, children: [_jsx(FormLabel, { children: label }), _jsx(LocalizationProvider, { dateAdapter: AdapterDateFns, children: _jsx(DatePicker, { "data-testid": "zds-date-picker", renderInput: (params) => _jsx(TextField, { ...params, helperText: helperText, error: error }), ...props }) })] }));
13
9
  };
14
10
  export default FieldTypeDate;
@@ -13,8 +13,5 @@ const Template = (args) => {
13
13
  export const Default = Template.bind({});
14
14
  Default.args = {
15
15
  label: 'Date label',
16
- textFieldProps: {
17
- helperText: 'Date helper text',
18
- error: false,
19
- }
16
+ helperText: 'Date helper text',
20
17
  };
@@ -1,11 +1,9 @@
1
1
  /// <reference types="react" />
2
2
  import { DateTimePickerProps } from '@mui/x-date-pickers/DateTimePicker';
3
- import { TextFieldProps } from '@mui/material';
4
3
  export interface FieldTypeDateTimeProps extends Omit<DateTimePickerProps<Date, Date>, 'renderInput'> {
5
- /**
6
- * Props passed to TextField component
7
- */
8
- textFieldProps?: TextFieldProps;
4
+ helperText?: string;
5
+ error?: boolean;
6
+ required?: boolean;
9
7
  }
10
- declare const FieldTypeDateTime: ({ textFieldProps, ...props }: FieldTypeDateTimeProps) => JSX.Element;
8
+ declare const FieldTypeDateTime: ({ label, helperText, error, required, ...props }: FieldTypeDateTimeProps) => JSX.Element;
11
9
  export default FieldTypeDateTime;
@@ -1,14 +1,10 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { AdapterDateFns } from '@mui/x-date-pickers/AdapterDateFns';
3
3
  import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
4
4
  import { DateTimePicker } from '@mui/x-date-pickers/DateTimePicker';
5
- import { TextField } from '@mui/material';
5
+ import { TextField, FormControl, FormLabel } from '@mui/material';
6
6
  ;
7
- const FieldTypeDateTime = ({ textFieldProps, ...props }) => {
8
- return (_jsx(LocalizationProvider, { dateAdapter: AdapterDateFns, children: _jsx(DateTimePicker, { "data-testid": "zds-date-picker", renderInput: (params) => _jsx(TextField, { InputLabelProps: {
9
- shrink: true,
10
- // Spread props at the end to allow InputLabelProps overrides
11
- ...textFieldProps?.InputLabelProps,
12
- }, ...params, ...textFieldProps }), ...props }) }));
7
+ const FieldTypeDateTime = ({ label, helperText, error, required, ...props }) => {
8
+ return (_jsxs(FormControl, { fullWidth: true, required: required, children: [_jsx(FormLabel, { children: label }), _jsx(LocalizationProvider, { dateAdapter: AdapterDateFns, children: _jsx(DateTimePicker, { "data-testid": "zds-date-picker", renderInput: (params) => _jsx(TextField, { ...params, helperText: helperText, error: error }), ...props }) })] }));
13
9
  };
14
10
  export default FieldTypeDateTime;
@@ -30,5 +30,6 @@ const Template = (args) => {
30
30
  export const Default = Template.bind({});
31
31
  Default.args = {
32
32
  placeholder: 'Placeholder Text...',
33
- label: 'Number label',
33
+ label: 'Dropdown label',
34
+ helperText: 'Dropdown helper text',
34
35
  };
@@ -7,5 +7,5 @@ interface Option {
7
7
  export interface FieldTypeDropdownProps extends Omit<OutlinedTextFieldProps, 'variant'> {
8
8
  options: Option[];
9
9
  }
10
- declare const FieldTypeDropdown: ({ InputLabelProps, options, ...props }: FieldTypeDropdownProps) => JSX.Element;
10
+ declare const FieldTypeDropdown: ({ label, options, required, ...props }: FieldTypeDropdownProps) => JSX.Element;
11
11
  export default FieldTypeDropdown;
@@ -1,15 +1,10 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { MenuItem } from '@mui/material';
3
3
  import MuiTextField from '@mui/material/TextField';
4
- const FieldTypeDropdown = ({ InputLabelProps, options, ...props }) => {
5
- return (_jsxs(MuiTextField, { size: "small", variant: 'outlined', select: true, InputLabelProps: {
6
- shrink: true,
7
- // Spread props at the end to allow InputLabel prop overrides
8
- ...InputLabelProps,
9
- },
10
- // Spread props at the end to allow prop overrides
11
- SelectProps: {
12
- displayEmpty: true,
13
- }, ...props, children: [_jsx(MenuItem, { value: '', children: "- None -" }, ''), options.map((option) => (_jsx(MenuItem, { value: option.value, children: option.label }, option.value)))] }));
4
+ import { FormControl, FormLabel } from '@mui/material';
5
+ const FieldTypeDropdown = ({ label, options, required, ...props }) => {
6
+ return (_jsxs(FormControl, { fullWidth: true, required: required, children: [_jsx(FormLabel, { children: label }), _jsxs(MuiTextField, { size: "small", variant: 'outlined', select: true, SelectProps: {
7
+ displayEmpty: true,
8
+ }, ...props, children: [_jsx(MenuItem, { value: '', children: "- None -" }, ''), options.map((option) => (_jsx(MenuItem, { value: option.value, children: option.label }, option.value)))] })] }));
14
9
  };
15
10
  export default FieldTypeDropdown;
@@ -17,4 +17,5 @@ export const Default = Template.bind({});
17
17
  Default.args = {
18
18
  placeholder: 'Placeholder Text...',
19
19
  label: 'Number label',
20
+ helperText: 'Number helper text',
20
21
  };
@@ -2,5 +2,5 @@
2
2
  import { OutlinedTextFieldProps } from '@mui/material/TextField';
3
3
  export interface FieldTypeNumberProps extends Omit<OutlinedTextFieldProps, 'variant'> {
4
4
  }
5
- declare const FieldTypeText: ({ InputLabelProps, ...props }: FieldTypeNumberProps) => JSX.Element;
5
+ declare const FieldTypeText: ({ label, required, ...props }: FieldTypeNumberProps) => JSX.Element;
6
6
  export default FieldTypeText;
@@ -1,10 +1,7 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { FormControl, FormLabel } from '@mui/material';
2
3
  import MuiTextField from '@mui/material/TextField';
3
- const FieldTypeText = ({ InputLabelProps, ...props }) => {
4
- return (_jsx(MuiTextField, { size: "small", variant: 'outlined', type: 'number', InputLabelProps: {
5
- shrink: true,
6
- // Spread props at the end to allow InputLabel prop overrides
7
- ...InputLabelProps,
8
- }, ...props }));
4
+ const FieldTypeText = ({ label, required, ...props }) => {
5
+ return (_jsxs(FormControl, { fullWidth: true, required: required, children: [_jsx(FormLabel, { children: label }), _jsx(MuiTextField, { size: "small", variant: 'outlined', type: 'number', ...props })] }));
9
6
  };
10
7
  export default FieldTypeText;
@@ -0,0 +1,5 @@
1
+ import { Story, Meta } from '@storybook/react/types-6-0';
2
+ import { FieldTypeOneToManyProps } from '.';
3
+ declare const _default: Meta<import("@storybook/react/types-6-0").Args>;
4
+ export default _default;
5
+ export declare const Default: Story<FieldTypeOneToManyProps>;
@@ -0,0 +1,28 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useState } from 'react';
3
+ import FieldTypeOneToMany from '.';
4
+ export default {
5
+ title: 'FieldTypeOneToMany',
6
+ component: FieldTypeOneToMany,
7
+ argType: {},
8
+ };
9
+ const Template = (args) => {
10
+ const [value, setValue] = useState([]);
11
+ const [options, setOptions] = useState([]);
12
+ const handleOnOpen = async () => {
13
+ const largeArr = new Array(1000).fill(null);
14
+ await new Promise((resolve) => setTimeout(resolve, 3000));
15
+ const data = largeArr.map((_, idx) => ({ component: _jsx("div", { children: `Test ${idx}` }), value: String(Math.random()), inputLabel: `Test ${idx}` }));
16
+ setOptions(data);
17
+ };
18
+ const handleOnChange = (e, values) => {
19
+ setValue(values);
20
+ };
21
+ return (_jsx(FieldTypeOneToMany, { ...args, value: value, onChange: handleOnChange, options: options, onOpen: handleOnOpen }));
22
+ };
23
+ export const Default = Template.bind({});
24
+ Default.args = {
25
+ placeholder: 'Placeholder Text...',
26
+ label: 'OneToMany label',
27
+ helperText: 'OneToMany helperText',
28
+ };
@@ -0,0 +1,32 @@
1
+ import { ReactNode } from 'react';
2
+ import { AutocompleteProps } from '@mui/material';
3
+ export interface FieldTypeOneToManyProps extends Omit<AutocompleteProps<any, false, false, false>, 'onOpen' | 'renderInput'> {
4
+ label?: string;
5
+ helperText?: string;
6
+ placeholder?: string;
7
+ error?: boolean;
8
+ required?: boolean;
9
+ /**
10
+ * Callback to be fired upon opening the dropdown
11
+ */
12
+ onOpen: () => Promise<any>;
13
+ /**
14
+ * Structure for option
15
+ */
16
+ options: {
17
+ /**
18
+ * Component to be rendered in the dropdown
19
+ */
20
+ component: ReactNode | string;
21
+ /**
22
+ * Value of option
23
+ */
24
+ value: string;
25
+ /**
26
+ * Label that should display in the input when selected
27
+ */
28
+ inputLabel: string;
29
+ }[];
30
+ }
31
+ declare const FieldTypeOneToMany: ({ label, helperText, placeholder, error, onOpen, options, required, ...props }: FieldTypeOneToManyProps) => JSX.Element;
32
+ export default FieldTypeOneToMany;
@@ -0,0 +1,29 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState } from 'react';
3
+ import { FormControl, FormLabel, Popper, styled, TextField } from '@mui/material';
4
+ import Autocomplete, { autocompleteClasses } from '@mui/material/Autocomplete';
5
+ import { ListboxComponent } from '../utils/virtualization';
6
+ const FieldTypeOneToMany = ({ label, helperText, placeholder, error, onOpen, options, required, ...props }) => {
7
+ const [loaded, setLoaded] = useState(false);
8
+ const [loading, setLoading] = useState(false);
9
+ const handleOpen = () => {
10
+ if (!loaded && onOpen) {
11
+ onOpen().then(() => {
12
+ setLoading(false);
13
+ });
14
+ setLoading(true);
15
+ setLoaded(true);
16
+ }
17
+ };
18
+ return (_jsxs(FormControl, { fullWidth: true, required: required, children: [_jsx(FormLabel, { children: label }), _jsx(Autocomplete, { onOpen: handleOpen, loading: loading, fullWidth: true, multiple: true, disableListWrap: true, disableClearable: true, disablePortal: true, size: 'small', PopperComponent: StyledPopper, ListboxComponent: ListboxComponent, renderInput: (params) => (_jsx(TextField, { ...params, helperText: helperText, error: error, placeholder: placeholder })), options: loading ? [] : options, getOptionLabel: (option) => option.inputLabel, renderOption: (props, option) => [props, option.component], ...props })] }));
19
+ };
20
+ export default FieldTypeOneToMany;
21
+ const StyledPopper = styled(Popper)({
22
+ [`& .${autocompleteClasses.listbox}`]: {
23
+ boxSizing: 'border-box',
24
+ '& ul': {
25
+ padding: 0,
26
+ margin: 0,
27
+ },
28
+ },
29
+ });
@@ -0,0 +1,5 @@
1
+ import { Story, Meta } from '@storybook/react/types-6-0';
2
+ import { FieldTypeOneToOneProps } from './';
3
+ declare const _default: Meta<import("@storybook/react/types-6-0").Args>;
4
+ export default _default;
5
+ export declare const Default: Story<FieldTypeOneToOneProps>;
@@ -0,0 +1,28 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useState } from 'react';
3
+ import FieldTypeOneToOne from './';
4
+ export default {
5
+ title: 'FieldTypeOneToOne',
6
+ component: FieldTypeOneToOne,
7
+ argType: {},
8
+ };
9
+ const Template = (args) => {
10
+ const [value, setValue] = useState({ component: '- None -', value: '0', inputLabel: '- None -' });
11
+ const [options, setOptions] = useState([]);
12
+ const handleOnOpen = async () => {
13
+ const largeArr = new Array(1000).fill(null);
14
+ await new Promise((resolve) => setTimeout(resolve, 3000));
15
+ const data = largeArr.map((_, idx) => ({ component: _jsx("div", { children: `Test ${idx}` }), value: String(Math.random()), inputLabel: `Test ${idx}` }));
16
+ setOptions(data);
17
+ };
18
+ const handleOnChange = (e, option) => {
19
+ setValue(option);
20
+ };
21
+ return (_jsx(FieldTypeOneToOne, { ...args, value: value, onChange: handleOnChange, options: options, onOpen: handleOnOpen }));
22
+ };
23
+ export const Default = Template.bind({});
24
+ Default.args = {
25
+ label: 'OneToOne label',
26
+ helperText: 'OneToOne helperText',
27
+ placeholder: 'OneToOne placeholder'
28
+ };
@@ -0,0 +1,34 @@
1
+ import { ReactNode } from 'react';
2
+ import { AutocompleteProps } from '@mui/material';
3
+ export interface FieldTypeOneToOneProps extends Omit<AutocompleteProps<any, false, false, false>, 'onOpen' | 'renderInput'> {
4
+ label?: string;
5
+ helperText?: string;
6
+ placeholder?: string;
7
+ error?: boolean;
8
+ required?: boolean;
9
+ startAdornment?: ReactNode;
10
+ endAdornment?: ReactNode;
11
+ /**
12
+ * Callback to be fired upon opening the dropdown
13
+ */
14
+ onOpen?: () => Promise<any>;
15
+ /**
16
+ * Structure for option
17
+ */
18
+ options: {
19
+ /**
20
+ * Component to be rendered in the dropdown
21
+ */
22
+ component: ReactNode | string;
23
+ /**
24
+ * Value of option
25
+ */
26
+ value: string;
27
+ /**
28
+ * Label that should display in the input when selected
29
+ */
30
+ inputLabel: string;
31
+ }[];
32
+ }
33
+ declare const FieldTypeOneToOne: ({ label, helperText, placeholder, error, onOpen, options, required, startAdornment, endAdornment, ...props }: FieldTypeOneToOneProps) => JSX.Element;
34
+ export default FieldTypeOneToOne;
@@ -0,0 +1,33 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState } from 'react';
3
+ import { Popper, styled, TextField, FormLabel, FormControl, InputAdornment } from '@mui/material';
4
+ import Autocomplete, { autocompleteClasses } from '@mui/material/Autocomplete';
5
+ import { ListboxComponent } from '../utils/virtualization';
6
+ const FieldTypeOneToOne = ({ label, helperText, placeholder, error, onOpen, options, required, startAdornment, endAdornment, ...props }) => {
7
+ const [loaded, setLoaded] = useState(false);
8
+ const [loading, setLoading] = useState(false);
9
+ const handleOpen = () => {
10
+ if (!loaded && onOpen) {
11
+ onOpen().then(() => {
12
+ setLoading(false);
13
+ });
14
+ setLoading(true);
15
+ setLoaded(true);
16
+ }
17
+ };
18
+ return (_jsxs(FormControl, { fullWidth: true, required: required, children: [_jsx(FormLabel, { children: label }), _jsx(Autocomplete, { onOpen: handleOpen, loading: loading, fullWidth: true, disableListWrap: true, disableClearable: true, disablePortal: true, size: 'small', PopperComponent: StyledPopper, ListboxComponent: ListboxComponent, renderInput: (params) => (_jsx(TextField, { ...params, helperText: helperText, error: error, placeholder: placeholder, InputProps: {
19
+ ...params.InputProps,
20
+ startAdornment: _jsx(InputAdornment, { position: 'end', children: startAdornment }),
21
+ endAdornment: _jsxs(_Fragment, { children: [params.InputProps.endAdornment, _jsx(InputAdornment, { sx: { position: 'relative', right: '40px' }, position: 'end', children: endAdornment })] })
22
+ } })), options: loading ? [] : options, getOptionLabel: (option) => option.inputLabel, renderOption: (props, option) => [props, option.component], ...props })] }));
23
+ };
24
+ export default FieldTypeOneToOne;
25
+ const StyledPopper = styled(Popper)({
26
+ [`& .${autocompleteClasses.listbox}`]: {
27
+ boxSizing: 'border-box',
28
+ '& ul': {
29
+ padding: 0,
30
+ margin: 0,
31
+ },
32
+ },
33
+ });
@@ -18,4 +18,5 @@ Default.args = {
18
18
  placeholder: 'Placeholder Text...',
19
19
  label: 'Sort label',
20
20
  helperText: 'Sort helper text',
21
+ error: false,
21
22
  };
@@ -3,5 +3,5 @@ import { OutlinedTextFieldProps } from '@mui/material/TextField';
3
3
  export interface FieldTypeSortProps extends Omit<OutlinedTextFieldProps, 'variant'> {
4
4
  value: string;
5
5
  }
6
- declare const FieldTypeSort: ({ value, InputProps, InputLabelProps, sx, ...props }: FieldTypeSortProps) => JSX.Element;
6
+ declare const FieldTypeSort: ({ label, value, InputProps, required, ...props }: FieldTypeSortProps) => JSX.Element;
7
7
  export default FieldTypeSort;
@@ -1,32 +1,22 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import MuiTextField from '@mui/material/TextField';
3
- import { Button, InputAdornment } from '@mui/material';
3
+ import { Button, FormControl, FormLabel, InputAdornment } from '@mui/material';
4
4
  import AddIcon from '@mui/icons-material/Add';
5
5
  import RemoveIcon from '@mui/icons-material/Remove';
6
- const FieldTypeSort = ({ value, InputProps, InputLabelProps, sx, ...props }) => {
7
- return (_jsx(MuiTextField, { size: "small", variant: 'outlined', type: 'number', value: value, sx: {
8
- width: 165,
9
- // Spread props at the end to allow sx prop overrides
10
- ...sx
11
- }, InputProps: {
12
- startAdornment: (_jsx(InputAdornment, { position: "start", children: _jsx(Button, { size: "small", variant: "contained", onClick: (e) => {
13
- // References input via event in order to modify its value
14
- const input = e.currentTarget?.parentElement?.parentElement?.childNodes?.[1];
15
- console.log('testing input', input);
16
- input.value = String(+input.value + 1);
17
- }, children: _jsx(AddIcon, { fontSize: 'small' }) }) })),
18
- endAdornment: (_jsx(InputAdornment, { position: "end", children: _jsx(Button, { size: "small", variant: "contained", onClick: (e) => {
19
- // References input via event in order to modify its value
20
- const input = e.currentTarget?.parentElement?.parentElement?.childNodes?.[1];
21
- console.log('testing input', input);
22
- input.value = String(+input.value - 1);
23
- }, children: _jsx(RemoveIcon, { fontSize: 'small' }) }) })),
24
- // Spread props at the end to allow Input prop overrides
25
- ...InputProps,
26
- }, InputLabelProps: {
27
- shrink: true,
28
- // Spread props at the end to allow InputLabel prop overrides
29
- ...InputLabelProps,
30
- }, ...props }));
6
+ const FieldTypeSort = ({ label, value, InputProps, required, ...props }) => {
7
+ return (_jsxs(FormControl, { fullWidth: true, required: required, children: [_jsx(FormLabel, { children: label }), _jsx(MuiTextField, { size: "small", variant: 'outlined', type: 'number', value: value, InputProps: {
8
+ startAdornment: (_jsx(InputAdornment, { position: "start", children: _jsx(Button, { size: "small", variant: "contained", onClick: (e) => {
9
+ // References input via event in order to modify its value
10
+ const input = e.currentTarget?.parentElement?.parentElement?.childNodes?.[1];
11
+ input.value = String(+input.value - 1);
12
+ }, children: _jsx(RemoveIcon, { fontSize: 'small' }) }) })),
13
+ endAdornment: (_jsx(InputAdornment, { position: "end", children: _jsx(Button, { size: "small", variant: "contained", onClick: (e) => {
14
+ // References input via event in order to modify its value
15
+ const input = e.currentTarget?.parentElement?.parentElement?.childNodes?.[1];
16
+ input.value = String(+input.value + 1);
17
+ }, children: _jsx(AddIcon, { fontSize: 'small' }) }) })),
18
+ // Spread props at the end to allow Input prop overrides
19
+ ...InputProps,
20
+ }, ...props })] }));
31
21
  };
32
22
  export default FieldTypeSort;
@@ -1,4 +1,4 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
1
+ import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { useState } from 'react';
3
3
  import FieldTypeText from './';
4
4
  export default {
@@ -11,12 +11,13 @@ const Template = (args) => {
11
11
  const handleOnChange = (e) => {
12
12
  setValue(e.target.value);
13
13
  };
14
- return (_jsx(FieldTypeText, { ...args, value: value, onChange: handleOnChange }));
14
+ return (_jsx(_Fragment, { children: _jsx(FieldTypeText, { ...args, value: value, onChange: handleOnChange }) }));
15
15
  };
16
16
  export const Default = Template.bind({});
17
17
  Default.args = {
18
18
  placeholder: 'Placeholder Text...',
19
19
  label: 'Text label',
20
+ helperText: 'Text helper text',
20
21
  };
21
22
  export const TextArea = Template.bind({});
22
23
  TextArea.args = {
@@ -24,4 +25,5 @@ TextArea.args = {
24
25
  rows: 4,
25
26
  placeholder: 'Placeholder Text...',
26
27
  label: 'Text Label',
28
+ helperText: 'Text helper text',
27
29
  };
@@ -8,5 +8,5 @@ export interface FieldTypeTextProps extends Omit<OutlinedTextFieldProps, 'varian
8
8
  maxLength?: number;
9
9
  value: string;
10
10
  }
11
- declare const FieldTypeText: ({ maxLength, value, helperText, InputProps, InputLabelProps, ...props }: FieldTypeTextProps) => JSX.Element;
11
+ declare const FieldTypeText: ({ label, maxLength, value, helperText, required, ...props }: FieldTypeTextProps) => JSX.Element;
12
12
  export default FieldTypeText;