@applica-software-guru/react-admin 1.0.39 → 1.0.41

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applica-software-guru/react-admin",
3
- "version": "1.0.39",
3
+ "version": "1.0.41",
4
4
  "private": false,
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,5 +1,5 @@
1
1
  import { IconButton, MenuItem, styled } from '@mui/material';
2
- import React, { Children, useState } from 'react';
2
+ import React, { Children, useCallback, useState } from 'react';
3
3
 
4
4
  import MenuPopover from './MenuPopover/MenuPopover';
5
5
  import { MoreVert } from '@mui/icons-material';
@@ -14,7 +14,7 @@ const StyledRoot = styled('div', {
14
14
  }));
15
15
 
16
16
  const StyledMenuPopover = styled(MenuPopover, {
17
- name: 'ApplicaActionsMenuPopover',
17
+ name: 'ApplicaActionsMenu',
18
18
  slot: 'root'
19
19
  })(({ theme }) => ({
20
20
  '& .MuiMenuItem-root': {
@@ -50,9 +50,9 @@ const ActionsMenu = ({ children }: ActionsMenuProps): React.ReactElement | null
50
50
  e.preventDefault();
51
51
  setOpen(e.currentTarget);
52
52
  };
53
- const handleClose = () => {
53
+ const handleClose = useCallback(() => {
54
54
  setOpen(null);
55
- };
55
+ }, []);
56
56
 
57
57
  if (
58
58
  !children ||
@@ -71,12 +71,7 @@ const ActionsMenu = ({ children }: ActionsMenuProps): React.ReactElement | null
71
71
  <StyledMenuPopover open={open} onClose={handleClose} arrow="right-top">
72
72
  {Children.map(
73
73
  children,
74
- (action, index) =>
75
- React.isValidElement(action) && (
76
- <MenuItem key={index} onClick={handleClose}>
77
- {React.cloneElement(action)}
78
- </MenuItem>
79
- )
74
+ (action, index) => React.isValidElement(action) && <MenuItem key={index}>{React.cloneElement(action)}</MenuItem>
80
75
  )}
81
76
  </StyledMenuPopover>
82
77
  </StyledRoot>
@@ -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.cloneElement(children, {
46
- ...children.props,
47
- ...props,
48
- label: display === 'legend' ? label : false
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 LabeledInput from './LabeledInput'
10
- import NumberInput from './NumberInput'
11
- import RecordInput from './RecordInput'
12
- import ReferenceArrayInput from './ReferenceArrayInput'
13
- import ReferenceInput from './ReferenceInput'
14
- import ReferenceManyInput from './ReferenceManyInput'
15
- import SearchInput from './SearchInput'
16
- import SelectArrayInput from './SelectArrayInput'
17
- import SelectInput from './SelectInput'
18
- import SmartTextInput from './SmartTextInput'
19
- import TextInput from './TextInput'
20
- import TimeInput from './TimeInput'
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,6 +0,0 @@
1
- export default ArrayInput;
2
- declare function ArrayInput(props: any): import("react/jsx-runtime").JSX.Element;
3
- declare namespace ArrayInput {
4
- const propTypes: any;
5
- }
6
- //# sourceMappingURL=ArrayInput.d.ts.map
@@ -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;