@zesty-io/material 0.1.0 → 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/es/CopyButton/index.js +3 -3
- package/es/FieldTypeColor/index.d.ts +1 -1
- package/es/FieldTypeColor/index.js +12 -16
- package/es/FieldTypeDate/FieldTypeDate.stories.js +1 -4
- package/es/FieldTypeDate/index.d.ts +4 -6
- package/es/FieldTypeDate/index.js +4 -8
- package/es/FieldTypeDateTime/FieldTypeDateTime.stories.js +1 -4
- package/es/FieldTypeDateTime/index.d.ts +4 -6
- package/es/FieldTypeDateTime/index.js +4 -8
- package/es/FieldTypeDropdown/FieldTypeDropwdon.stories.js +2 -1
- package/es/FieldTypeDropdown/index.d.ts +1 -1
- package/es/FieldTypeDropdown/index.js +5 -10
- package/es/FieldTypeNumber/FieldTypeNumber.stories.js +1 -0
- package/es/FieldTypeNumber/index.d.ts +1 -1
- package/es/FieldTypeNumber/index.js +4 -7
- package/es/FieldTypeOneToMany/FieldTypeOneToMany.stories.d.ts +5 -0
- package/es/FieldTypeOneToMany/FieldTypeOneToMany.stories.js +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.js +1 -0
- package/es/FieldTypeSort/index.d.ts +1 -1
- package/es/FieldTypeSort/index.js +17 -27
- package/es/FieldTypeText/FieldTypeText.stories.js +4 -2
- package/es/FieldTypeText/index.d.ts +1 -1
- package/es/FieldTypeText/index.js +4 -12
- package/es/FieldTypeUrl/index.d.ts +1 -1
- package/es/FieldTypeUrl/index.js +8 -16
- package/es/index.d.ts +2 -0
- package/es/index.js +2 -0
- package/es/theme/index.js +3 -0
- package/es/utils/virtualization.d.ts +3 -0
- package/es/utils/virtualization.js +74 -0
- package/package.json +5 -3
- package/src/CopyButton/index.tsx +6 -6
- package/src/FieldTypeColor/index.tsx +5 -7
- package/src/FieldTypeDate/FieldTypeDate.stories.tsx +1 -4
- package/src/FieldTypeDate/index.tsx +22 -25
- package/src/FieldTypeDateTime/FieldTypeDateTime.stories.tsx +1 -4
- package/src/FieldTypeDateTime/index.tsx +23 -25
- package/src/FieldTypeDropdown/FieldTypeDropwdon.stories.tsx +2 -1
- package/src/FieldTypeDropdown/index.tsx +5 -7
- package/src/FieldTypeNumber/FieldTypeNumber.stories.tsx +1 -0
- package/src/FieldTypeNumber/index.tsx +5 -6
- package/src/FieldTypeOneToMany/FieldTypeOneToMany.stories.tsx +47 -0
- package/src/FieldTypeOneToMany/index.tsx +65 -0
- package/src/FieldTypeOneToOne/FieldTypeOneToOne.stories.tsx +46 -0
- package/src/FieldTypeOneToOne/index.tsx +97 -0
- package/src/FieldTypeSort/FieldTypeSort.stories.tsx +1 -0
- package/src/FieldTypeSort/index.tsx +9 -18
- package/src/FieldTypeText/FieldTypeText.stories.tsx +9 -5
- package/src/FieldTypeText/index.tsx +11 -18
- package/src/FieldTypeUrl/index.tsx +11 -18
- package/src/index.ts +2 -0
- package/src/theme/index.ts +3 -0
- package/src/utils/virtualization.tsx +125 -0
package/es/CopyButton/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { jsx as _jsx
|
|
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 (
|
|
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
|
-
},
|
|
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,
|
|
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,
|
|
6
|
-
return (_jsx(MuiTextField, { size: "small", variant: 'outlined', type: 'color', InputProps: {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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;
|
|
@@ -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
|
-
|
|
7
|
-
|
|
8
|
-
textFieldProps?: TextFieldProps;
|
|
4
|
+
helperText?: string;
|
|
5
|
+
error?: boolean;
|
|
6
|
+
required?: boolean;
|
|
9
7
|
}
|
|
10
|
-
declare const FieldTypeDate: ({
|
|
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 = ({
|
|
8
|
-
return (_jsx(LocalizationProvider, { dateAdapter: AdapterDateFns, children: _jsx(DatePicker, { "data-testid": "zds-date-picker", renderInput: (params) => _jsx(TextField, {
|
|
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;
|
|
@@ -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
|
-
|
|
7
|
-
|
|
8
|
-
textFieldProps?: TextFieldProps;
|
|
4
|
+
helperText?: string;
|
|
5
|
+
error?: boolean;
|
|
6
|
+
required?: boolean;
|
|
9
7
|
}
|
|
10
|
-
declare const FieldTypeDateTime: ({
|
|
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 = ({
|
|
8
|
-
return (_jsx(LocalizationProvider, { dateAdapter: AdapterDateFns, children: _jsx(DateTimePicker, { "data-testid": "zds-date-picker", renderInput: (params) => _jsx(TextField, {
|
|
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;
|
|
@@ -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: ({
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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;
|
|
@@ -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: ({
|
|
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 = ({
|
|
4
|
-
return (_jsx(MuiTextField, { size: "small", variant: 'outlined', type: 'number',
|
|
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,29 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import FieldTypeOneToMany from '.';
|
|
4
|
+
import { randomOptions } from '../utils/virtualization';
|
|
5
|
+
export default {
|
|
6
|
+
title: 'FieldTypeOneToMany',
|
|
7
|
+
component: FieldTypeOneToMany,
|
|
8
|
+
argType: {},
|
|
9
|
+
};
|
|
10
|
+
const Template = (args) => {
|
|
11
|
+
const [value, setValue] = useState([]);
|
|
12
|
+
const [options, setOptions] = useState([]);
|
|
13
|
+
const handleOnOpen = async () => {
|
|
14
|
+
await new Promise((resolve) => setTimeout(resolve, 3000));
|
|
15
|
+
setOptions(randomOptions);
|
|
16
|
+
};
|
|
17
|
+
const handleOnChange = (e, values) => {
|
|
18
|
+
setValue(values);
|
|
19
|
+
};
|
|
20
|
+
return (_jsx(FieldTypeOneToMany, { ...args, value: value, onChange: handleOnChange, options: options, onOpen: handleOnOpen }));
|
|
21
|
+
};
|
|
22
|
+
export const Default = Template.bind({});
|
|
23
|
+
Default.args = {
|
|
24
|
+
textFieldProps: {
|
|
25
|
+
placeholder: 'Placeholder Text...',
|
|
26
|
+
label: 'OneToOne label',
|
|
27
|
+
helperText: 'OneToOne helperText',
|
|
28
|
+
}
|
|
29
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { AutocompleteProps, TextFieldProps } from '@mui/material';
|
|
3
|
+
export interface FieldTypeOneToManyProps extends Omit<AutocompleteProps<any, false, false, false>, 'onOpen' | 'renderInput'> {
|
|
4
|
+
/**
|
|
5
|
+
* Props passed to TextField component
|
|
6
|
+
*/
|
|
7
|
+
textFieldProps?: TextFieldProps;
|
|
8
|
+
/**
|
|
9
|
+
* Callback to be fired upon opening the dropdown
|
|
10
|
+
*/
|
|
11
|
+
onOpen: () => Promise<any>;
|
|
12
|
+
}
|
|
13
|
+
declare const FieldTypeOneToMany: ({ textFieldProps, onOpen, ...props }: FieldTypeOneToManyProps) => JSX.Element;
|
|
14
|
+
export default FieldTypeOneToMany;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { Popper, styled, TextField } from '@mui/material';
|
|
4
|
+
import Autocomplete, { autocompleteClasses } from '@mui/material/Autocomplete';
|
|
5
|
+
import { ListboxComponent } from '../utils/virtualization';
|
|
6
|
+
const FieldTypeOneToMany = ({ textFieldProps, onOpen, ...props }) => {
|
|
7
|
+
const [loaded, setLoaded] = useState(false);
|
|
8
|
+
const [loading, setLoading] = useState(true);
|
|
9
|
+
const handleOpen = () => {
|
|
10
|
+
if (!loaded && onOpen) {
|
|
11
|
+
onOpen().then(() => {
|
|
12
|
+
setLoading(false);
|
|
13
|
+
});
|
|
14
|
+
setLoaded(true);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
return (_jsx(Autocomplete, { onOpen: handleOpen, loading: loading, fullWidth: true, multiple: true, disableListWrap: true, PopperComponent: StyledPopper, ListboxComponent: ListboxComponent, renderInput: (params) => (_jsx(TextField, { ...params, ...textFieldProps, InputLabelProps: {
|
|
18
|
+
shrink: true,
|
|
19
|
+
} })), renderOption: (props, option) => [props, option], ...props }));
|
|
20
|
+
};
|
|
21
|
+
export default FieldTypeOneToMany;
|
|
22
|
+
const StyledPopper = styled(Popper)({
|
|
23
|
+
[`& .${autocompleteClasses.listbox}`]: {
|
|
24
|
+
boxSizing: 'border-box',
|
|
25
|
+
'& ul': {
|
|
26
|
+
padding: 0,
|
|
27
|
+
margin: 0,
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
});
|
|
@@ -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
|
+
});
|
|
@@ -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,
|
|
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,
|
|
7
|
-
return (_jsx(MuiTextField, { size: "small", variant: 'outlined', type: 'number', value: value,
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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,
|
|
11
|
+
declare const FieldTypeText: ({ label, maxLength, value, helperText, required, ...props }: FieldTypeTextProps) => JSX.Element;
|
|
12
12
|
export default FieldTypeText;
|
|
@@ -1,15 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import MuiTextField from '@mui/material/TextField';
|
|
3
|
-
import {
|
|
4
|
-
const FieldTypeText = ({ maxLength = 150, value, helperText,
|
|
5
|
-
return (_jsx(MuiTextField, { size: "small", variant: 'outlined', value: value,
|
|
6
|
-
endAdornment: (_jsx(InputAdornment, { position: "end", children: _jsxs(_Fragment, { children: [value.length, "/", maxLength] }) })),
|
|
7
|
-
// Spread props at the end to allow Input prop overrides
|
|
8
|
-
...InputProps,
|
|
9
|
-
}, InputLabelProps: {
|
|
10
|
-
shrink: true,
|
|
11
|
-
// Spread props at the end to allow InputLabel prop overrides
|
|
12
|
-
...InputLabelProps,
|
|
13
|
-
}, error: value.length > maxLength, helperText: value.length > maxLength ? 'Your input is over the specified limit' : helperText, ...props }));
|
|
3
|
+
import { FormControl, FormLabel, Box } from '@mui/material';
|
|
4
|
+
const FieldTypeText = ({ label, maxLength = 150, value, helperText, required, ...props }) => {
|
|
5
|
+
return (_jsxs(FormControl, { fullWidth: true, required: required, children: [_jsxs(FormLabel, { sx: { display: 'flex', justifyContent: 'space-between', '& .MuiFormLabel-asterisk': { order: 2 } }, children: [_jsx(Box, { sx: { order: 1 }, children: label }), _jsxs(Box, { sx: { order: 3, flex: 1, textAlign: 'right' }, children: [value?.length, "/", maxLength] })] }), _jsx(MuiTextField, { size: "small", variant: 'outlined', value: value, error: value?.length > maxLength, helperText: value?.length > maxLength ? 'Your input is over the specified limit' : helperText, ...props })] }));
|
|
14
6
|
};
|
|
15
7
|
export default FieldTypeText;
|
|
@@ -8,5 +8,5 @@ export interface FieldTypeUrlProps extends Omit<OutlinedTextFieldProps, 'variant
|
|
|
8
8
|
maxLength?: number;
|
|
9
9
|
value: string;
|
|
10
10
|
}
|
|
11
|
-
declare const FieldTypeUrl: ({ maxLength, value, helperText,
|
|
11
|
+
declare const FieldTypeUrl: ({ label, maxLength, value, helperText, required, inputProps, ...props }: FieldTypeUrlProps) => JSX.Element;
|
|
12
12
|
export default FieldTypeUrl;
|
package/es/FieldTypeUrl/index.js
CHANGED
|
@@ -1,21 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useRef } from 'react';
|
|
3
3
|
import MuiTextField from '@mui/material/TextField';
|
|
4
|
-
import {
|
|
5
|
-
const FieldTypeUrl = ({ maxLength = 2000, value, helperText,
|
|
4
|
+
import { FormControl, FormLabel, Box } from '@mui/material';
|
|
5
|
+
const FieldTypeUrl = ({ label, maxLength = 2000, value, helperText, required, inputProps, ...props }) => {
|
|
6
6
|
const inputRef = useRef(null);
|
|
7
|
-
return (_jsx(MuiTextField, { size: "small", type: 'url', variant: 'outlined', value: value,
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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 }));
|
|
7
|
+
return (_jsxs(FormControl, { fullWidth: true, required: required, children: [_jsxs(FormLabel, { sx: { display: 'flex', justifyContent: 'space-between', '& .MuiFormLabel-asterisk': { order: 2 } }, children: [_jsx(Box, { sx: { order: 1 }, children: label }), _jsxs(Box, { sx: { order: 3, flex: 1, textAlign: 'right' }, children: [value?.length, "/", maxLength] })] }), _jsx(MuiTextField, { size: "small", type: 'url', variant: 'outlined', value: value, inputProps: {
|
|
8
|
+
ref: inputRef,
|
|
9
|
+
// Spread props at the end to allow inputProps prop overrides
|
|
10
|
+
...inputProps,
|
|
11
|
+
}, 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
12
|
};
|
|
21
13
|
export default FieldTypeUrl;
|
package/es/index.d.ts
CHANGED
|
@@ -7,5 +7,7 @@ export { default as FieldTypeDateTime } from './FieldTypeDateTime';
|
|
|
7
7
|
export { default as FieldTypeColor } from './FieldTypeColor';
|
|
8
8
|
export { default as FieldTypeNumber } from './FieldTypeNumber';
|
|
9
9
|
export { default as FieldTypeDropdown } from './FieldTypeDropdown';
|
|
10
|
+
export { default as FieldTypeOneToOne } from './FieldTypeOneToOne';
|
|
11
|
+
export { default as FieldTypeOneToMany } from './FieldTypeOneToMany';
|
|
10
12
|
export { default as CopyButton } from './CopyButton';
|
|
11
13
|
export { default as ConfirmModal } from './ConfirmModal';
|
package/es/index.js
CHANGED
|
@@ -7,5 +7,7 @@ export { default as FieldTypeDateTime } from './FieldTypeDateTime';
|
|
|
7
7
|
export { default as FieldTypeColor } from './FieldTypeColor';
|
|
8
8
|
export { default as FieldTypeNumber } from './FieldTypeNumber';
|
|
9
9
|
export { default as FieldTypeDropdown } from './FieldTypeDropdown';
|
|
10
|
+
export { default as FieldTypeOneToOne } from './FieldTypeOneToOne';
|
|
11
|
+
export { default as FieldTypeOneToMany } from './FieldTypeOneToMany';
|
|
10
12
|
export { default as CopyButton } from './CopyButton';
|
|
11
13
|
export { default as ConfirmModal } from './ConfirmModal';
|