@zesty-io/material 0.2.0 → 0.2.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.
@@ -5,6 +5,6 @@ import { DatePicker } from '@mui/x-date-pickers/DatePicker';
5
5
  import { FormControl, FormLabel, TextField } from '@mui/material';
6
6
  ;
7
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 }) })] }));
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, size: "small" }), ...props }) })] }));
9
9
  };
10
10
  export default FieldTypeDate;
@@ -5,6 +5,6 @@ import { DateTimePicker } from '@mui/x-date-pickers/DateTimePicker';
5
5
  import { TextField, FormControl, FormLabel } from '@mui/material';
6
6
  ;
7
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 }) })] }));
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, size: "small" }), ...props }) })] }));
9
9
  };
10
10
  export default FieldTypeDateTime;
@@ -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: ({ label, value, InputProps, required, ...props }: FieldTypeSortProps) => JSX.Element;
6
+ declare const FieldTypeSort: ({ label, value, InputProps, required, onChange, ...props }: FieldTypeSortProps) => JSX.Element;
7
7
  export default FieldTypeSort;
@@ -3,17 +3,29 @@ import MuiTextField from '@mui/material/TextField';
3
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 = ({ 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: {
6
+ const FieldTypeSort = ({ label, value, InputProps, required, onChange, ...props }) => {
7
+ return (_jsxs(FormControl, { fullWidth: true, required: required, children: [_jsx(FormLabel, { children: label }), _jsx(MuiTextField, { size: "small", variant: 'outlined', type: 'number', value: value, onChange: onChange, InputProps: {
8
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
9
+ e.stopPropagation();
10
+ // References input via click event in order to obtain its value
10
11
  const input = e.currentTarget?.parentElement?.parentElement?.childNodes?.[1];
11
- input.value = String(+input.value - 1);
12
+ const newValue = String(+input.value - 1);
13
+ // Updates internal input value in case component is not controlled
14
+ input.value = newValue;
15
+ // Mocks an event change
16
+ const event = { target: { value: newValue } };
17
+ onChange && onChange(event);
12
18
  }, children: _jsx(RemoveIcon, { fontSize: 'small' }) }) })),
13
19
  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
20
+ e.stopPropagation();
21
+ // References input via click event in order to obtain its value
15
22
  const input = e.currentTarget?.parentElement?.parentElement?.childNodes?.[1];
16
- input.value = String(+input.value + 1);
23
+ const newValue = String(+input.value + 1);
24
+ // Updates internal input value in case component is not controlled
25
+ input.value = newValue;
26
+ // Mocks an event change
27
+ const event = { target: { value: newValue } };
28
+ onChange && onChange(event);
17
29
  }, children: _jsx(AddIcon, { fontSize: 'small' }) }) })),
18
30
  // Spread props at the end to allow Input prop overrides
19
31
  ...InputProps,
@@ -1,13 +1,14 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useRef } from 'react';
2
+ import { useState } from 'react';
3
3
  import MuiTextField from '@mui/material/TextField';
4
4
  import { FormControl, FormLabel, Box } from '@mui/material';
5
5
  const FieldTypeUrl = ({ label, maxLength = 2000, value, helperText, required, inputProps, ...props }) => {
6
- const inputRef = useRef(null);
6
+ // Use state to hold input reference to re-render once ref changes in case error needs to be shown on mount
7
+ const [inputRef, setInputRef] = useState();
7
8
  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
+ ref: (inputRef) => setInputRef(inputRef),
9
10
  // Spread props at the end to allow inputProps prop overrides
10
11
  ...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 })] }));
12
+ }, error: (value && !inputRef?.validity.valid) || value?.length > maxLength, helperText: value?.length > maxLength ? 'Your input is over the specified limit' : (value && !inputRef?.validity.valid) ? 'Your input is not a valid url' : helperText, ...props })] }));
12
13
  };
13
14
  export default FieldTypeUrl;
package/es/theme/index.js CHANGED
@@ -7,6 +7,13 @@ let theme = createTheme({
7
7
  });
8
8
  theme = createTheme(theme, {
9
9
  components: {
10
+ MuiAccordionSummary: {
11
+ styleOverrides: {
12
+ root: {
13
+ backgroundColor: '#e4e9f1',
14
+ },
15
+ },
16
+ },
10
17
  MuiButton: {
11
18
  styleOverrides: {
12
19
  root: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zesty-io/material",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Contains custom components which are in addition to the @mui design-system",
5
5
  "author": "Zesty.io",
6
6
  "license": "MIT",
@@ -21,6 +21,7 @@ const FieldTypeDate = ({label, helperText, error, required, ...props}: FieldType
21
21
  {...params}
22
22
  helperText={helperText}
23
23
  error={error}
24
+ size="small"
24
25
  />
25
26
  }
26
27
  // Spread props at the end to allow prop overrides
@@ -22,6 +22,7 @@ const FieldTypeDateTime = ({label, helperText, error, required, ...props}: Field
22
22
  {...params}
23
23
  helperText={helperText}
24
24
  error={error}
25
+ size="small"
25
26
  />
26
27
  }
27
28
  // Spread props at the end to allow prop overrides
@@ -1,3 +1,4 @@
1
+ import { ChangeEvent } from 'react';
1
2
  import MuiTextField, { OutlinedTextFieldProps } from '@mui/material/TextField';
2
3
  import { Button, FormControl, FormLabel, InputAdornment } from '@mui/material';
3
4
  import AddIcon from '@mui/icons-material/Add';
@@ -7,7 +8,7 @@ export interface FieldTypeSortProps extends Omit<OutlinedTextFieldProps, 'varian
7
8
  value: string;
8
9
  }
9
10
 
10
- const FieldTypeSort = ({label, value, InputProps, required, ...props }: FieldTypeSortProps) => {
11
+ const FieldTypeSort = ({label, value, InputProps, required, onChange, ...props }: FieldTypeSortProps) => {
11
12
  return (
12
13
  <FormControl fullWidth required={required}>
13
14
  <FormLabel>{label}</FormLabel>
@@ -16,6 +17,7 @@ const FieldTypeSort = ({label, value, InputProps, required, ...props }: FieldTyp
16
17
  variant='outlined'
17
18
  type='number'
18
19
  value={value}
20
+ onChange={onChange}
19
21
  InputProps={{
20
22
  startAdornment: (
21
23
  <InputAdornment position="start">
@@ -23,9 +25,15 @@ const FieldTypeSort = ({label, value, InputProps, required, ...props }: FieldTyp
23
25
  size="small"
24
26
  variant="contained"
25
27
  onClick={(e) => {
26
- // References input via event in order to modify its value
28
+ e.stopPropagation();
29
+ // References input via click event in order to obtain its value
27
30
  const input = e.currentTarget?.parentElement?.parentElement?.childNodes?.[1] as HTMLInputElement;
28
- input.value = String(+input.value - 1)
31
+ const newValue = String(+input.value - 1)
32
+ // Updates internal input value in case component is not controlled
33
+ input.value = newValue
34
+ // Mocks an event change
35
+ const event = {target: {value: newValue}}
36
+ onChange && onChange(event as ChangeEvent<HTMLTextAreaElement | HTMLInputElement>);
29
37
  }}><RemoveIcon fontSize='small' />
30
38
  </Button>
31
39
  </InputAdornment>
@@ -36,9 +44,15 @@ const FieldTypeSort = ({label, value, InputProps, required, ...props }: FieldTyp
36
44
  size="small"
37
45
  variant="contained"
38
46
  onClick={(e) => {
39
- // References input via event in order to modify its value
47
+ e.stopPropagation();
48
+ // References input via click event in order to obtain its value
40
49
  const input = e.currentTarget?.parentElement?.parentElement?.childNodes?.[1] as HTMLInputElement;
41
- input.value = String(+input.value + 1)
50
+ const newValue = String(+input.value + 1)
51
+ // Updates internal input value in case component is not controlled
52
+ input.value = newValue
53
+ // Mocks an event change
54
+ const event = {target: {value: newValue}}
55
+ onChange && onChange(event as ChangeEvent<HTMLTextAreaElement | HTMLInputElement>);
42
56
  }}><AddIcon fontSize='small' />
43
57
  </Button>
44
58
  </InputAdornment>
@@ -1,4 +1,4 @@
1
- import { useRef } from 'react';
1
+ import { useState } from 'react';
2
2
  import MuiTextField, { OutlinedTextFieldProps } from '@mui/material/TextField';
3
3
  import { FormControl, FormLabel, Box } from '@mui/material';
4
4
 
@@ -12,7 +12,8 @@ export interface FieldTypeUrlProps extends Omit<OutlinedTextFieldProps, 'variant
12
12
  }
13
13
 
14
14
  const FieldTypeUrl = ({label, maxLength = 2000, value, helperText, required, inputProps, ...props }: FieldTypeUrlProps) => {
15
- const inputRef = useRef<HTMLInputElement>(null);
15
+ // Use state to hold input reference to re-render once ref changes in case error needs to be shown on mount
16
+ const [inputRef, setInputRef] = useState<HTMLInputElement>();
16
17
 
17
18
  return (
18
19
  <FormControl fullWidth required={required}>
@@ -27,12 +28,12 @@ const FieldTypeUrl = ({label, maxLength = 2000, value, helperText, required, inp
27
28
  variant='outlined'
28
29
  value={value}
29
30
  inputProps={{
30
- ref: inputRef,
31
+ ref: (inputRef: HTMLInputElement) => setInputRef(inputRef),
31
32
  // Spread props at the end to allow inputProps prop overrides
32
33
  ...inputProps,
33
34
  }}
34
- error={(value && !inputRef.current?.validity.valid) || value?.length > maxLength}
35
- helperText={value?.length > maxLength ? 'Your input is over the specified limit' : (value && !inputRef.current?.validity.valid) ? 'Your input is not a valid url' : helperText}
35
+ error={(value && !inputRef?.validity.valid) || value?.length > maxLength}
36
+ helperText={value?.length > maxLength ? 'Your input is over the specified limit' : (value && !inputRef?.validity.valid) ? 'Your input is not a valid url' : helperText}
36
37
  // Spread props at the end to allow prop overrides
37
38
  {...props}
38
39
  />
@@ -9,6 +9,13 @@ let theme: Theme = createTheme({
9
9
 
10
10
  theme = createTheme(theme, {
11
11
  components: {
12
+ MuiAccordionSummary: {
13
+ styleOverrides: {
14
+ root: {
15
+ backgroundColor: '#e4e9f1',
16
+ },
17
+ },
18
+ },
12
19
  MuiButton: {
13
20
  styleOverrides: {
14
21
  root: {