@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.
- package/es/FieldTypeDate/index.js +1 -1
- package/es/FieldTypeDateTime/index.js +1 -1
- package/es/FieldTypeSort/index.d.ts +1 -1
- package/es/FieldTypeSort/index.js +18 -6
- package/es/FieldTypeUrl/index.js +5 -4
- package/es/theme/index.js +7 -0
- package/package.json +1 -1
- package/src/FieldTypeDate/index.tsx +1 -0
- package/src/FieldTypeDateTime/index.tsx +1 -0
- package/src/FieldTypeSort/index.tsx +19 -5
- package/src/FieldTypeUrl/index.tsx +6 -5
- package/src/theme/index.ts +7 -0
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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,
|
package/es/FieldTypeUrl/index.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
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
|
-
|
|
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
|
|
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
package/package.json
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 {
|
|
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
|
-
|
|
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
|
|
35
|
-
helperText={value?.length > maxLength ? 'Your input is over the specified limit' : (value && !inputRef
|
|
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
|
/>
|
package/src/theme/index.ts
CHANGED