@zesty-io/material 0.1.4 → 0.2.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.
@@ -0,0 +1,5 @@
1
+ import { Story, Meta } from '@storybook/react/types-6-0';
2
+ import { VirtualizedAutocompleteProps } from './';
3
+ declare const _default: Meta<import("@storybook/react/types-6-0").Args>;
4
+ export default _default;
5
+ export declare const Default: Story<VirtualizedAutocompleteProps>;
@@ -0,0 +1,27 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useState } from 'react';
3
+ import VirtualizedAutocomplete from './';
4
+ export default {
5
+ title: 'VirtualizedAutocomplete',
6
+ component: VirtualizedAutocomplete,
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(VirtualizedAutocomplete, { ...args, value: value, onChange: handleOnChange, options: options, onOpen: handleOnOpen }));
22
+ };
23
+ export const Default = Template.bind({});
24
+ Default.args = {
25
+ helperText: 'OneToOne helperText',
26
+ placeholder: 'OneToOne placeholder'
27
+ };
@@ -0,0 +1,28 @@
1
+ import { ReactNode } from 'react';
2
+ import { AutocompleteProps } from '@mui/material';
3
+ export interface VirtualizedAutocompleteProps extends Omit<AutocompleteProps<any, false, false, false>, 'renderInput'> {
4
+ helperText?: string;
5
+ placeholder?: string;
6
+ error?: boolean;
7
+ startAdornment?: ReactNode;
8
+ endAdornment?: ReactNode;
9
+ /**
10
+ * Structure for option
11
+ */
12
+ options: {
13
+ /**
14
+ * Component to be rendered in the dropdown
15
+ */
16
+ component: ReactNode | string;
17
+ /**
18
+ * Value of option
19
+ */
20
+ value: string;
21
+ /**
22
+ * Label that should display in the input when selected
23
+ */
24
+ inputLabel: string;
25
+ }[];
26
+ }
27
+ declare const VirtualizedAutocomplete: ({ helperText, placeholder, error, startAdornment, endAdornment, ...props }: VirtualizedAutocompleteProps) => JSX.Element;
28
+ export default VirtualizedAutocomplete;
@@ -0,0 +1,21 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Popper, styled, TextField, InputAdornment } from '@mui/material';
3
+ import Autocomplete, { autocompleteClasses } from '@mui/material/Autocomplete';
4
+ import { ListboxComponent } from '../utils/virtualization';
5
+ const VirtualizedAutocomplete = ({ helperText, placeholder, error, startAdornment, endAdornment, ...props }) => {
6
+ return (_jsx(Autocomplete, { fullWidth: true, disableListWrap: true, size: 'small', PopperComponent: StyledPopper, ListboxComponent: ListboxComponent, renderInput: (params) => (_jsx(TextField, { ...params, helperText: helperText, error: error, placeholder: placeholder, InputProps: {
7
+ ...params.InputProps,
8
+ startAdornment: _jsx(InputAdornment, { position: 'end', children: startAdornment }),
9
+ endAdornment: _jsxs(_Fragment, { children: [params.InputProps.endAdornment, _jsx(InputAdornment, { sx: { position: 'relative', right: '40px' }, position: 'end', children: endAdornment })] })
10
+ } })), getOptionLabel: (option) => option.inputLabel, renderOption: (props, option) => [props, option.component], ...props }));
11
+ };
12
+ export default VirtualizedAutocomplete;
13
+ const StyledPopper = styled(Popper)({
14
+ [`& .${autocompleteClasses.listbox}`]: {
15
+ boxSizing: 'border-box',
16
+ '& ul': {
17
+ padding: 0,
18
+ margin: 0,
19
+ },
20
+ },
21
+ });
package/es/index.d.ts CHANGED
@@ -6,8 +6,8 @@ export { default as FieldTypeDate } from './FieldTypeDate';
6
6
  export { default as FieldTypeDateTime } from './FieldTypeDateTime';
7
7
  export { default as FieldTypeColor } from './FieldTypeColor';
8
8
  export { default as FieldTypeNumber } from './FieldTypeNumber';
9
- export { default as FieldTypeDropdown } from './FieldTypeDropdown';
10
9
  export { default as FieldTypeOneToOne } from './FieldTypeOneToOne';
11
10
  export { default as FieldTypeOneToMany } from './FieldTypeOneToMany';
12
11
  export { default as CopyButton } from './CopyButton';
13
12
  export { default as ConfirmDialog } from './ConfirmDialog';
13
+ export { default as VirtualizedAutocomplete } from './VitualizedAutocomplete';
package/es/index.js CHANGED
@@ -6,8 +6,8 @@ export { default as FieldTypeDate } from './FieldTypeDate';
6
6
  export { default as FieldTypeDateTime } from './FieldTypeDateTime';
7
7
  export { default as FieldTypeColor } from './FieldTypeColor';
8
8
  export { default as FieldTypeNumber } from './FieldTypeNumber';
9
- export { default as FieldTypeDropdown } from './FieldTypeDropdown';
10
9
  export { default as FieldTypeOneToOne } from './FieldTypeOneToOne';
11
10
  export { default as FieldTypeOneToMany } from './FieldTypeOneToMany';
12
11
  export { default as CopyButton } from './CopyButton';
13
12
  export { default as ConfirmDialog } from './ConfirmDialog';
13
+ export { default as VirtualizedAutocomplete } from './VitualizedAutocomplete';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zesty-io/material",
3
- "version": "0.1.4",
3
+ "version": "0.2.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",
@@ -0,0 +1,45 @@
1
+ import { ReactNode, SyntheticEvent, useState } from 'react';
2
+ import { Story, Meta } from '@storybook/react/types-6-0';
3
+ import VirtualizedAutocomplete, { VirtualizedAutocompleteProps } from './';
4
+
5
+ export default {
6
+ title: 'VirtualizedAutocomplete',
7
+ component: VirtualizedAutocomplete,
8
+ argType: {},
9
+ } as Meta;
10
+
11
+ const Template: Story<VirtualizedAutocompleteProps> = (args) => {
12
+ const [value, setValue] = useState<{component: string | ReactNode, value: string, inputLabel: string}>({component: '- None -', value: '0', inputLabel: '- None -'});
13
+
14
+ const [options, setOptions] = useState<{component: string | ReactNode, value: string, inputLabel: string}[]>([]);
15
+
16
+ const handleOnOpen = async () => {
17
+ const largeArr = new Array(1000).fill(null);
18
+ await new Promise((resolve) => setTimeout(resolve, 3000))
19
+ const data = largeArr.map((_, idx) => ({component: <div>{`Test ${idx}`}</div>, value: String(Math.random()), inputLabel: `Test ${idx}`}));
20
+ setOptions(data);
21
+ }
22
+
23
+ const handleOnChange = (e: SyntheticEvent<Element, Event>, option: {component: string | ReactNode, value: string, inputLabel: string}) => {
24
+ setValue(option);
25
+ }
26
+
27
+ return (
28
+ <VirtualizedAutocomplete
29
+ {...args}
30
+ value={value}
31
+ onChange={handleOnChange}
32
+ options={options}
33
+ onOpen={handleOnOpen}
34
+ />
35
+ );
36
+ };
37
+
38
+ export const Default = Template.bind({});
39
+ Default.args = {
40
+ helperText: 'OneToOne helperText',
41
+ placeholder: 'OneToOne placeholder'
42
+ };
43
+
44
+
45
+
@@ -0,0 +1,69 @@
1
+ import { ReactNode, useState } from 'react';
2
+ import { AutocompleteProps, Popper, styled, TextField, FormLabel, FormControl, InputAdornment } from '@mui/material';
3
+ import Autocomplete, { autocompleteClasses } from '@mui/material/Autocomplete';
4
+ import { ListboxComponent } from '../utils/virtualization';
5
+
6
+ export interface VirtualizedAutocompleteProps extends Omit<AutocompleteProps<any, false, false, false>, 'renderInput'> {
7
+ helperText?: string;
8
+ placeholder?: string;
9
+ error?: boolean;
10
+ startAdornment?: ReactNode;
11
+ endAdornment?: ReactNode;
12
+ /**
13
+ * Structure for option
14
+ */
15
+ options: {
16
+ /**
17
+ * Component to be rendered in the dropdown
18
+ */
19
+ component: ReactNode | string;
20
+ /**
21
+ * Value of option
22
+ */
23
+ value: string;
24
+ /**
25
+ * Label that should display in the input when selected
26
+ */
27
+ inputLabel: string;
28
+ }[]
29
+ }
30
+
31
+ const VirtualizedAutocomplete = ({helperText, placeholder, error, startAdornment, endAdornment, ...props }: VirtualizedAutocompleteProps) => {
32
+ return (
33
+ <Autocomplete
34
+ fullWidth
35
+ disableListWrap
36
+ size='small'
37
+ PopperComponent={StyledPopper}
38
+ ListboxComponent={ListboxComponent}
39
+ renderInput={(params) => (
40
+ <TextField
41
+ {...params}
42
+ helperText={helperText}
43
+ error={error}
44
+ placeholder={placeholder}
45
+ InputProps={{
46
+ ...params.InputProps,
47
+ startAdornment: <InputAdornment position='end'>{startAdornment}</InputAdornment>,
48
+ endAdornment: <>{params.InputProps.endAdornment}<InputAdornment sx={{ position: 'relative', right: '40px'}} position='end'>{endAdornment}</InputAdornment></>
49
+ }}
50
+ />
51
+ )}
52
+ getOptionLabel={(option) => option.inputLabel}
53
+ renderOption={(props, option) => [props, option.component]}
54
+ {...props}
55
+ />
56
+ );
57
+ };
58
+
59
+ export default VirtualizedAutocomplete;
60
+
61
+ const StyledPopper = styled(Popper)({
62
+ [`& .${autocompleteClasses.listbox}`]: {
63
+ boxSizing: 'border-box',
64
+ '& ul': {
65
+ padding: 0,
66
+ margin: 0,
67
+ },
68
+ },
69
+ });
package/src/index.ts CHANGED
@@ -6,8 +6,8 @@ export { default as FieldTypeDate } from './FieldTypeDate';
6
6
  export { default as FieldTypeDateTime } from './FieldTypeDateTime';
7
7
  export { default as FieldTypeColor } from './FieldTypeColor';
8
8
  export { default as FieldTypeNumber } from './FieldTypeNumber';
9
- export { default as FieldTypeDropdown } from './FieldTypeDropdown';
10
9
  export { default as FieldTypeOneToOne} from './FieldTypeOneToOne';
11
10
  export { default as FieldTypeOneToMany} from './FieldTypeOneToMany';
12
11
  export { default as CopyButton } from './CopyButton';
13
- export { default as ConfirmDialog } from './ConfirmDialog';
12
+ export { default as ConfirmDialog } from './ConfirmDialog';
13
+ export { default as VirtualizedAutocomplete } from './VitualizedAutocomplete';
Binary file
@@ -1,52 +0,0 @@
1
- import { ChangeEvent, useState } from 'react';
2
- import { Story, Meta } from '@storybook/react/types-6-0';
3
- import FieldTypeDropdown, { FieldTypeDropdownProps } from './';
4
- import { MenuItem } from '@mui/material';
5
-
6
- export default {
7
- title: 'FieldTypeDropdown',
8
- component: FieldTypeDropdown,
9
- argType: {},
10
- } as Meta;
11
-
12
- const options = [
13
- {
14
- value: 'option1',
15
- label: 'Option 1',
16
- },
17
- {
18
- value: 'option2',
19
- label: 'Option 2',
20
- },
21
- {
22
- value: 'option3',
23
- label: 'Option 3',
24
- },
25
- ];
26
-
27
- const Template: Story<FieldTypeDropdownProps> = (args) => {
28
- const [value, setValue] = useState('');
29
-
30
- const handleOnChange = (e: ChangeEvent<HTMLInputElement>) => {
31
- setValue(e.target.value);
32
- }
33
-
34
- return (
35
- <FieldTypeDropdown
36
- {...args}
37
- value={value}
38
- onChange={handleOnChange}
39
- options={options}
40
- />
41
- );
42
- };
43
-
44
- export const Default = Template.bind({});
45
- Default.args = {
46
- placeholder: 'Placeholder Text...',
47
- label: 'Dropdown label',
48
- helperText: 'Dropdown helper text',
49
- };
50
-
51
-
52
-
@@ -1,41 +0,0 @@
1
- import { MenuItem } from '@mui/material';
2
- import MuiTextField, { OutlinedTextFieldProps } from '@mui/material/TextField';
3
- import { FormControl, FormLabel } from '@mui/material';
4
-
5
- interface Option {
6
- label: string;
7
- value: any;
8
- }
9
-
10
- export interface FieldTypeDropdownProps extends Omit<OutlinedTextFieldProps, 'variant'> {
11
- options: Option[];
12
- }
13
-
14
- const FieldTypeDropdown = ({label, options, required, ...props }: FieldTypeDropdownProps) => {
15
-
16
- return (
17
- <FormControl fullWidth required={required}>
18
- <FormLabel>{label}</FormLabel>
19
- <MuiTextField
20
- size="small"
21
- variant='outlined'
22
- select
23
- SelectProps={{
24
- displayEmpty: true,
25
- }}
26
- {...props}
27
- >
28
- <MenuItem key={''} value={''}>
29
- - None -
30
- </MenuItem>
31
- {options.map((option) => (
32
- <MenuItem key={option.value} value={option.value}>
33
- {option.label}
34
- </MenuItem>
35
- ))}
36
- </MuiTextField>
37
- </FormControl>
38
- );
39
- };
40
-
41
- export default FieldTypeDropdown;