@applica-software-guru/react-admin 1.0.39 → 1.0.40
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/dist/components/ra-inputs/LabeledInput.d.ts.map +1 -1
- package/dist/components/ra-inputs/index.d.ts +2 -1
- package/dist/components/ra-inputs/index.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/react-admin.cjs.js +44 -44
- package/dist/react-admin.es.js +4623 -4544
- package/dist/react-admin.umd.js +50 -50
- package/package.json +1 -1
- package/src/components/ra-inputs/ArrayInput.tsx +39 -0
- package/src/components/ra-inputs/LabeledArrayInput.tsx +116 -0
- package/src/components/ra-inputs/LabeledInput.jsx +7 -5
- package/src/components/ra-inputs/index.jsx +24 -22
- package/src/index.jsx +2 -0
- package/dist/components/ra-inputs/ArrayInput.d.ts +0 -6
- package/dist/components/ra-inputs/ArrayInput.d.ts.map +0 -1
- package/src/components/ra-inputs/ArrayInput.jsx +0 -29
package/package.json
CHANGED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import LabeledArrayInput, { LabeledArrayInputProps } from './LabeledArrayInput';
|
|
2
|
+
import { ArrayInput as RaArrayInput, ArrayInputProps as RaArrayInputProps } from 'react-admin';
|
|
3
|
+
|
|
4
|
+
import { styled } from '@mui/material/styles';
|
|
5
|
+
|
|
6
|
+
const StyledArrayInput = styled(RaArrayInput, {
|
|
7
|
+
name: 'ApplicaArrayInput',
|
|
8
|
+
slot: 'root'
|
|
9
|
+
})(({ theme }) => ({
|
|
10
|
+
'& label:first-of-type': {
|
|
11
|
+
marginTop: theme.spacing(2)
|
|
12
|
+
},
|
|
13
|
+
marginTop: '0 !important',
|
|
14
|
+
'& .RaSimpleFormIterator-line > .RaSimpleFormIterator-form': {
|
|
15
|
+
paddingBottom: theme.spacing(0.5),
|
|
16
|
+
'& > div': {
|
|
17
|
+
width: '100%'
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}));
|
|
21
|
+
|
|
22
|
+
export type ArrayInputProps = RaArrayInputProps & LabeledArrayInputProps;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Espone un componente di tipo ArrayInput con stile grafico di Applica.
|
|
26
|
+
* Se vuoi utilizzare il componente puro di react-admin puoi usare RaArrayInput esposto nella libreria.
|
|
27
|
+
*
|
|
28
|
+
* @param {ArrayInputProps}
|
|
29
|
+
* @returns {React.ReactElement}
|
|
30
|
+
*/
|
|
31
|
+
const ArrayInput = ({ children, label, addLabel, source, helperText, ...props }: ArrayInputProps): React.ReactElement => (
|
|
32
|
+
<LabeledArrayInput label={label} addLabel={addLabel} source={source} helperText={helperText} divider>
|
|
33
|
+
<StyledArrayInput source={source} label={false} {...props}>
|
|
34
|
+
{children}
|
|
35
|
+
</StyledArrayInput>
|
|
36
|
+
</LabeledArrayInput>
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
export default ArrayInput;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { FormHelperText, InputLabel, Stack, SxProps } from '@mui/material';
|
|
2
|
+
|
|
3
|
+
import { FieldTitle } from 'react-admin';
|
|
4
|
+
import PropTypes from 'prop-types';
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import { useAppConfig } from '../../hooks';
|
|
7
|
+
import { useFormContext } from 'react-hook-form';
|
|
8
|
+
import { useTheme } from '@emotion/react';
|
|
9
|
+
|
|
10
|
+
export type LabeledArrayInputProps = {
|
|
11
|
+
label?: string | boolean;
|
|
12
|
+
addLabel?: boolean;
|
|
13
|
+
resource?: string;
|
|
14
|
+
isRequired?: boolean;
|
|
15
|
+
source: string;
|
|
16
|
+
display?: 'legend' | 'label';
|
|
17
|
+
helperText?: string | boolean;
|
|
18
|
+
divider?: boolean;
|
|
19
|
+
sx?: SxProps;
|
|
20
|
+
children: React.ReactElement;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Consente di visualizzare un array di input con un label e un helper text con lo stile del tema Mantis.
|
|
25
|
+
*
|
|
26
|
+
* @param {LabeledArrayInputProps}
|
|
27
|
+
* @returns {React.ReactElement}
|
|
28
|
+
*/
|
|
29
|
+
const LabeledArrayInput = ({
|
|
30
|
+
label,
|
|
31
|
+
children,
|
|
32
|
+
display,
|
|
33
|
+
helperText,
|
|
34
|
+
sx,
|
|
35
|
+
addLabel,
|
|
36
|
+
divider,
|
|
37
|
+
...props
|
|
38
|
+
}: LabeledArrayInputProps): React.ReactElement => {
|
|
39
|
+
const theme = useTheme() as any;
|
|
40
|
+
const { getCurrentDialog } = useAppConfig();
|
|
41
|
+
const { source, resource, isRequired } = props;
|
|
42
|
+
const { getFieldState, formState } = useFormContext();
|
|
43
|
+
const { error } = getFieldState(source, formState);
|
|
44
|
+
const dialogResource = getCurrentDialog();
|
|
45
|
+
|
|
46
|
+
return (
|
|
47
|
+
<Stack
|
|
48
|
+
spacing={1}
|
|
49
|
+
sx={{
|
|
50
|
+
'& .MuiFormHelperText-root': {
|
|
51
|
+
// @see: https://github.com/marmelab/react-admin/blob/master/packages/ra-ui-materialui/src/input/SelectArrayInput.tsx#L340
|
|
52
|
+
// the 'invalid' prop is not used inside the react-admin component. This is necessary if we want to support
|
|
53
|
+
// remove error message colorization when the field is in error state.
|
|
54
|
+
color: error ? theme.palette.error.main : theme.palette.text.secondary,
|
|
55
|
+
'& span': {
|
|
56
|
+
display: 'none'
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
...sx
|
|
60
|
+
}}
|
|
61
|
+
>
|
|
62
|
+
{display === 'label' && label !== false && addLabel !== false && (
|
|
63
|
+
<InputLabel
|
|
64
|
+
error={!!error}
|
|
65
|
+
sx={{
|
|
66
|
+
borderBottom: divider ? `1px solid ${theme.palette.divider}` : 'none',
|
|
67
|
+
pb: divider ? 1 : 0,
|
|
68
|
+
mt: divider ? 1 : 0
|
|
69
|
+
}}
|
|
70
|
+
>
|
|
71
|
+
<FieldTitle label={label} source={source} resource={dialogResource || resource} isRequired={isRequired} />
|
|
72
|
+
</InputLabel>
|
|
73
|
+
)}
|
|
74
|
+
{React.isValidElement(children)
|
|
75
|
+
? React.cloneElement(children, {
|
|
76
|
+
// @ts-ignore
|
|
77
|
+
...children.props,
|
|
78
|
+
...props,
|
|
79
|
+
label: display === 'legend' ? label : false
|
|
80
|
+
})
|
|
81
|
+
: children}
|
|
82
|
+
{display === 'label' && helperText && (
|
|
83
|
+
<FormHelperText
|
|
84
|
+
sx={{
|
|
85
|
+
pl: 1.8,
|
|
86
|
+
pb: 2,
|
|
87
|
+
marginTop: '0 !important'
|
|
88
|
+
}}
|
|
89
|
+
error={!!error}
|
|
90
|
+
>
|
|
91
|
+
{helperText}
|
|
92
|
+
</FormHelperText>
|
|
93
|
+
)}
|
|
94
|
+
</Stack>
|
|
95
|
+
);
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
LabeledArrayInput.propTypes = {
|
|
99
|
+
sx: PropTypes.object,
|
|
100
|
+
children: PropTypes.element,
|
|
101
|
+
label: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
|
|
102
|
+
addLabel: PropTypes.bool,
|
|
103
|
+
resource: PropTypes.string,
|
|
104
|
+
isRequired: PropTypes.bool,
|
|
105
|
+
source: PropTypes.string,
|
|
106
|
+
display: PropTypes.oneOf(['legend', 'label']),
|
|
107
|
+
helperText: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
|
|
108
|
+
divider: PropTypes.bool
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
LabeledArrayInput.defaultProps = {
|
|
112
|
+
display: 'label',
|
|
113
|
+
divider: false
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
export default LabeledArrayInput;
|
|
@@ -42,11 +42,13 @@ const LabeledInput = ({ label, children, display, helperText, sx, addLabel, divi
|
|
|
42
42
|
<FieldTitle label={label} source={source} resource={dialogResource || resource} isRequired={isRequired} />
|
|
43
43
|
</InputLabel>
|
|
44
44
|
)}
|
|
45
|
-
{React.
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
45
|
+
{React.isValidElement(children)
|
|
46
|
+
? React.cloneElement(children, {
|
|
47
|
+
...children.props,
|
|
48
|
+
...props,
|
|
49
|
+
label: display === 'legend' ? label : false
|
|
50
|
+
})
|
|
51
|
+
: children}
|
|
50
52
|
{display === 'label' && helperText && (
|
|
51
53
|
<FormHelperText
|
|
52
54
|
sx={{
|
|
@@ -1,23 +1,24 @@
|
|
|
1
|
-
import ArrayInput from './ArrayInput'
|
|
2
|
-
import AttachmentInput from './AttachmentInput'
|
|
3
|
-
import AutocompleteArrayInput from './AutocompleteArrayInput'
|
|
4
|
-
import AutocompleteInput from './AutocompleteInput'
|
|
5
|
-
import BooleanInput from './BooleanInput'
|
|
6
|
-
import DateInput from './DateInput'
|
|
7
|
-
import FileInput from './FileInput'
|
|
8
|
-
import ImageInput from './ImageInput'
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
import
|
|
17
|
-
import
|
|
18
|
-
import
|
|
19
|
-
import
|
|
20
|
-
import
|
|
1
|
+
import ArrayInput from './ArrayInput';
|
|
2
|
+
import AttachmentInput from './AttachmentInput';
|
|
3
|
+
import AutocompleteArrayInput from './AutocompleteArrayInput';
|
|
4
|
+
import AutocompleteInput from './AutocompleteInput';
|
|
5
|
+
import BooleanInput from './BooleanInput';
|
|
6
|
+
import DateInput from './DateInput';
|
|
7
|
+
import FileInput from './FileInput';
|
|
8
|
+
import ImageInput from './ImageInput';
|
|
9
|
+
import LabeledArrayInput from './LabeledArrayInput';
|
|
10
|
+
import LabeledInput from './LabeledInput';
|
|
11
|
+
import NumberInput from './NumberInput';
|
|
12
|
+
import RecordInput from './RecordInput';
|
|
13
|
+
import ReferenceArrayInput from './ReferenceArrayInput';
|
|
14
|
+
import ReferenceInput from './ReferenceInput';
|
|
15
|
+
import ReferenceManyInput from './ReferenceManyInput';
|
|
16
|
+
import SearchInput from './SearchInput';
|
|
17
|
+
import SelectArrayInput from './SelectArrayInput';
|
|
18
|
+
import SelectInput from './SelectInput';
|
|
19
|
+
import SmartTextInput from './SmartTextInput';
|
|
20
|
+
import TextInput from './TextInput';
|
|
21
|
+
import TimeInput from './TimeInput';
|
|
21
22
|
export {
|
|
22
23
|
ArrayInput,
|
|
23
24
|
AttachmentInput,
|
|
@@ -28,6 +29,7 @@ export {
|
|
|
28
29
|
FileInput,
|
|
29
30
|
ImageInput,
|
|
30
31
|
LabeledInput,
|
|
32
|
+
LabeledArrayInput,
|
|
31
33
|
NumberInput,
|
|
32
34
|
RecordInput,
|
|
33
35
|
ReferenceArrayInput,
|
|
@@ -38,5 +40,5 @@ export {
|
|
|
38
40
|
SelectInput,
|
|
39
41
|
SmartTextInput,
|
|
40
42
|
TextInput,
|
|
41
|
-
TimeInput
|
|
42
|
-
}
|
|
43
|
+
TimeInput
|
|
44
|
+
};
|
package/src/index.jsx
CHANGED
|
@@ -7,6 +7,7 @@ export * from './contexts';
|
|
|
7
7
|
export * from './utils';
|
|
8
8
|
|
|
9
9
|
export {
|
|
10
|
+
ArrayInput as RaArrayInput,
|
|
10
11
|
ArrayInputContext,
|
|
11
12
|
BooleanField,
|
|
12
13
|
BulkDeleteWithConfirmButton,
|
|
@@ -41,6 +42,7 @@ export {
|
|
|
41
42
|
Resource,
|
|
42
43
|
ResourceContextProvider,
|
|
43
44
|
SaveButton,
|
|
45
|
+
SimpleFormIterator as RaSimpleFormIterator,
|
|
44
46
|
SimpleFormIteratorContext,
|
|
45
47
|
SimpleList,
|
|
46
48
|
SingleFieldList,
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ArrayInput.d.ts","sourceRoot":"","sources":["../../../../src/components/ra-inputs/ArrayInput.jsx"],"names":[],"mappings":";AAiBA,iFAIC"}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import LabeledInput from './LabeledInput';
|
|
2
|
-
import { ArrayInput as RaArrayInput } from 'react-admin';
|
|
3
|
-
import { styled } from '@mui/material/styles';
|
|
4
|
-
|
|
5
|
-
const StyledArrayInput = styled(RaArrayInput, {
|
|
6
|
-
name: 'RaApplicaArrayInput',
|
|
7
|
-
slot: 'root'
|
|
8
|
-
})(({ theme }) => ({
|
|
9
|
-
marginTop: '0 !important',
|
|
10
|
-
'& .RaSimpleFormIterator-line > .RaSimpleFormIterator-form': {
|
|
11
|
-
paddingBottom: theme.spacing(0.5),
|
|
12
|
-
'& > div': {
|
|
13
|
-
width: '100%'
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
}));
|
|
17
|
-
|
|
18
|
-
const ArrayInput = (props) => (
|
|
19
|
-
<LabeledInput {...props} divider>
|
|
20
|
-
<StyledArrayInput {...props} />
|
|
21
|
-
</LabeledInput>
|
|
22
|
-
);
|
|
23
|
-
|
|
24
|
-
ArrayInput.propTypes = {
|
|
25
|
-
...RaArrayInput.propTypes,
|
|
26
|
-
...LabeledInput.propTypes
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export default ArrayInput;
|