@applica-software-guru/react-admin 1.3.159 → 1.3.161
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-fields/ReadonlyField.d.ts +20 -25
- package/dist/components/ra-fields/ReadonlyField.d.ts.map +1 -1
- package/dist/react-admin.cjs.js +51 -51
- package/dist/react-admin.cjs.js.map +1 -1
- package/dist/react-admin.es.js +4179 -4197
- package/dist/react-admin.es.js.map +1 -1
- package/dist/react-admin.umd.js +54 -54
- package/dist/react-admin.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/components/ra-fields/ReadonlyField.tsx +106 -0
- package/src/components/ra-fields/ReadonlyField.jsx +0 -105
package/package.json
CHANGED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { FieldTitle, useRecordContext, useResourceContext } from 'react-admin';
|
|
2
|
+
import { InputLabel, Tooltip, Typography } from '@mui/material';
|
|
3
|
+
import React, { Fragment, useMemo } from 'react';
|
|
4
|
+
|
|
5
|
+
import { get } from 'lodash';
|
|
6
|
+
import { styled } from '@mui/material/styles';
|
|
7
|
+
import { useAppConfig, useSx } from '../../hooks';
|
|
8
|
+
|
|
9
|
+
const StyledField = styled('div')(({ theme, fullWidth }: { theme: any; fullWidth: boolean }) => ({
|
|
10
|
+
borderBottom: `1px solid ${theme.palette.divider}`,
|
|
11
|
+
paddingTop: theme.spacing(1),
|
|
12
|
+
paddingBottom: theme.spacing(1),
|
|
13
|
+
marginBottom: theme.spacing(1),
|
|
14
|
+
whiteSpace: 'nowrap',
|
|
15
|
+
overflow: 'hidden',
|
|
16
|
+
textOverflow: 'ellipsis',
|
|
17
|
+
width: fullWidth ? '100%' : 'auto',
|
|
18
|
+
[theme.breakpoints.down('sm')]: {
|
|
19
|
+
whiteSpace: 'normal',
|
|
20
|
+
overflow: 'visible',
|
|
21
|
+
textOverflow: 'inherit'
|
|
22
|
+
}
|
|
23
|
+
}));
|
|
24
|
+
|
|
25
|
+
export type BasicFieldProps = {
|
|
26
|
+
source: string;
|
|
27
|
+
defaultValue: any;
|
|
28
|
+
record: any;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const BasicField = ({ source, defaultValue = ' ', ...props }: BasicFieldProps) => {
|
|
32
|
+
const record = useRecordContext(props);
|
|
33
|
+
const value = get(record, source, defaultValue);
|
|
34
|
+
return <Typography {...props} dangerouslySetInnerHTML={{ __html: value && value !== null ? value : defaultValue }} />;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export type ContentWrapperProps = {
|
|
38
|
+
title: string | boolean;
|
|
39
|
+
children: React.ReactNode;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const ContentWrapper = ({ title, children }: ContentWrapperProps) => {
|
|
43
|
+
if (children === null || children === undefined) return null;
|
|
44
|
+
if (typeof title === 'string' || title === true) {
|
|
45
|
+
return (
|
|
46
|
+
<Tooltip title={title} placement="top">
|
|
47
|
+
{children as React.ReactElement<any, any>}
|
|
48
|
+
</Tooltip>
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
return children as React.ReactElement<any, any>;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export type ReadonlyFieldProps = {
|
|
55
|
+
defaultValue: any;
|
|
56
|
+
tooltip: string | boolean | ((record: any) => string);
|
|
57
|
+
source: string;
|
|
58
|
+
label: string;
|
|
59
|
+
name: string;
|
|
60
|
+
children: React.ReactElement<any, any>;
|
|
61
|
+
fullWidth?: boolean;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const ReadonlyField = ({
|
|
65
|
+
label,
|
|
66
|
+
source,
|
|
67
|
+
defaultValue = ' ',
|
|
68
|
+
children = <BasicField source={''} defaultValue={undefined} record={undefined} />,
|
|
69
|
+
tooltip: _tooltip,
|
|
70
|
+
...props
|
|
71
|
+
}: ReadonlyFieldProps) => {
|
|
72
|
+
const { getCurrentDialog } = useAppConfig();
|
|
73
|
+
const record = useRecordContext(props);
|
|
74
|
+
const resource = useResourceContext(props as any);
|
|
75
|
+
const dialogResource = getCurrentDialog();
|
|
76
|
+
|
|
77
|
+
const tooltip = useMemo(() => {
|
|
78
|
+
if (_tooltip === false) return false;
|
|
79
|
+
if (typeof _tooltip === 'function') return _tooltip(record);
|
|
80
|
+
if (typeof _tooltip === 'string') {
|
|
81
|
+
return get(record, _tooltip, _tooltip);
|
|
82
|
+
}
|
|
83
|
+
return _tooltip;
|
|
84
|
+
}, [record, _tooltip]);
|
|
85
|
+
|
|
86
|
+
const sx = useSx(props, { width: props?.fullWidth ? '100%' : 'auto' });
|
|
87
|
+
return (
|
|
88
|
+
<ContentWrapper title={tooltip}>
|
|
89
|
+
<Fragment>
|
|
90
|
+
<InputLabel sx={{ pt: 1 }}>
|
|
91
|
+
<FieldTitle label={label} source={source} resource={dialogResource || resource} />
|
|
92
|
+
</InputLabel>
|
|
93
|
+
<StyledField {...props}>
|
|
94
|
+
{React.cloneElement(children, {
|
|
95
|
+
source,
|
|
96
|
+
record,
|
|
97
|
+
defaultValue,
|
|
98
|
+
resource: dialogResource || resource,
|
|
99
|
+
sx
|
|
100
|
+
})}
|
|
101
|
+
</StyledField>
|
|
102
|
+
</Fragment>
|
|
103
|
+
</ContentWrapper>
|
|
104
|
+
);
|
|
105
|
+
};
|
|
106
|
+
export default ReadonlyField;
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { FieldTitle, useRecordContext, useResourceContext } from 'react-admin';
|
|
2
|
-
import { InputLabel, Tooltip } from '@mui/material';
|
|
3
|
-
import React, { Fragment, useMemo } from 'react';
|
|
4
|
-
|
|
5
|
-
import PropTypes from 'prop-types';
|
|
6
|
-
import { get } from 'lodash';
|
|
7
|
-
import { styled } from '@mui/material/styles';
|
|
8
|
-
import { useAppConfig } from '../../hooks';
|
|
9
|
-
|
|
10
|
-
const StyledField = styled('div')(({ theme }) => ({
|
|
11
|
-
borderBottom: `1px solid ${theme.palette.divider}`,
|
|
12
|
-
paddingTop: theme.spacing(1),
|
|
13
|
-
paddingBottom: theme.spacing(1),
|
|
14
|
-
marginBottom: theme.spacing(1),
|
|
15
|
-
whiteSpace: 'nowrap',
|
|
16
|
-
overflow: 'hidden',
|
|
17
|
-
textOverflow: 'ellipsis',
|
|
18
|
-
[theme.breakpoints.down('sm')]: {
|
|
19
|
-
whiteSpace: 'normal',
|
|
20
|
-
overflow: 'visible',
|
|
21
|
-
textOverflow: 'inherit'
|
|
22
|
-
}
|
|
23
|
-
}));
|
|
24
|
-
|
|
25
|
-
const BasicField = ({ source, defaultValue, ...props }) => {
|
|
26
|
-
const record = useRecordContext(props);
|
|
27
|
-
const value = get(record, source, defaultValue);
|
|
28
|
-
return <span dangerouslySetInnerHTML={{ __html: value && value !== null ? value : defaultValue }} />;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
BasicField.propTypes = {
|
|
32
|
-
defaultValue: PropTypes.any,
|
|
33
|
-
source: PropTypes.string,
|
|
34
|
-
record: PropTypes.object
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
BasicField.defaultProps = {
|
|
38
|
-
defaultValue: ' '
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
const ContentWrapper = ({ title, children }) => {
|
|
42
|
-
if (title && title !== false) {
|
|
43
|
-
return (
|
|
44
|
-
<Tooltip title={title} placement="top">
|
|
45
|
-
{children}
|
|
46
|
-
</Tooltip>
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
return children;
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
ContentWrapper.propTypes = {
|
|
53
|
-
title: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
|
|
54
|
-
children: PropTypes.oneOfType([PropTypes.element, PropTypes.arrayOf(PropTypes.element)])
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
const ReadonlyField = ({ label, source, defaultValue, children, tooltip: _tooltip, ...props }) => {
|
|
58
|
-
const { getCurrentDialog } = useAppConfig();
|
|
59
|
-
const record = useRecordContext(props);
|
|
60
|
-
const resource = useResourceContext(props);
|
|
61
|
-
const dialogResource = getCurrentDialog();
|
|
62
|
-
|
|
63
|
-
const tooltip = useMemo(() => {
|
|
64
|
-
if (!_tooltip || _tooltip === false) return false;
|
|
65
|
-
if (typeof _tooltip === 'function') return _tooltip(record);
|
|
66
|
-
if (typeof _tooltip === 'string') {
|
|
67
|
-
return get(record, _tooltip, _tooltip);
|
|
68
|
-
}
|
|
69
|
-
return _tooltip;
|
|
70
|
-
}, [record, _tooltip]);
|
|
71
|
-
|
|
72
|
-
return (
|
|
73
|
-
<ContentWrapper title={tooltip}>
|
|
74
|
-
<Fragment>
|
|
75
|
-
<InputLabel>
|
|
76
|
-
<FieldTitle label={label} source={source} resource={dialogResource || resource} />
|
|
77
|
-
</InputLabel>
|
|
78
|
-
<StyledField {...props}>
|
|
79
|
-
{React.cloneElement(children, {
|
|
80
|
-
source,
|
|
81
|
-
record,
|
|
82
|
-
defaultValue,
|
|
83
|
-
resource: dialogResource || resource
|
|
84
|
-
})}
|
|
85
|
-
</StyledField>
|
|
86
|
-
</Fragment>
|
|
87
|
-
</ContentWrapper>
|
|
88
|
-
);
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
ReadonlyField.propTypes = {
|
|
92
|
-
defaultValue: PropTypes.any,
|
|
93
|
-
tooltip: PropTypes.oneOfType([PropTypes.string, PropTypes.bool, PropTypes.func]),
|
|
94
|
-
source: PropTypes.string,
|
|
95
|
-
label: PropTypes.string,
|
|
96
|
-
name: PropTypes.string,
|
|
97
|
-
children: PropTypes.element
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
ReadonlyField.defaultProps = {
|
|
101
|
-
defaultValue: ' ',
|
|
102
|
-
children: <BasicField />
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
export default ReadonlyField;
|