-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
/
FieldButtonContent.js
82 lines (76 loc) 路 2.51 KB
/
FieldButtonContent.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import React from 'react';
import styled from 'styled-components';
import PropTypes from 'prop-types';
import { useIntl } from 'react-intl';
import { Box } from '@strapi/design-system/Box';
import { Flex } from '@strapi/design-system/Flex';
import { IconButton } from '@strapi/design-system/IconButton';
import { Typography } from '@strapi/design-system/Typography';
import Pencil from '@strapi/icons/Pencil';
import Trash from '@strapi/icons/Trash';
import { getTrad } from '../../../utils';
import ComponentFieldList from './ComponentFieldList';
import DynamicZoneList from './DynamicZoneList';
const CustomIconButton = styled(IconButton)`
background-color: transparent;
path {
fill: ${({ theme }) => theme.colors.neutral600};
}
`;
const FieldButtonContent = ({ attribute, onEditField, onDeleteField, children }) => {
const { formatMessage } = useIntl();
return (
<Box overflow="hidden" width="100%">
<Flex paddingLeft={3} alignItems="center" justifyContent="space-between">
<Typography fontWeight="semiBold" textColor="neutral800" ellipsis>
{children}
</Typography>
<Flex>
<CustomIconButton
label={formatMessage(
{
id: getTrad('containers.ListSettingsView.modal-form.edit-label'),
defaultMessage: `Edit {fieldName}`,
},
{ fieldName: children }
)}
onClick={onEditField}
icon={<Pencil />}
noBorder
/>
<CustomIconButton
label={formatMessage(
{
id: 'global.delete-target',
defaultMessage: `Delete {target}`,
},
{
target: children,
}
)}
data-testid="delete-field"
onClick={onDeleteField}
icon={<Trash />}
noBorder
/>
</Flex>
</Flex>
{attribute?.type === 'component' && <ComponentFieldList componentUid={attribute.component} />}
{attribute?.type === 'dynamiczone' && <DynamicZoneList components={attribute.components} />}
</Box>
);
};
FieldButtonContent.defaultProps = {
attribute: undefined,
};
FieldButtonContent.propTypes = {
attribute: PropTypes.shape({
components: PropTypes.array,
component: PropTypes.string,
type: PropTypes.string,
}),
onEditField: PropTypes.func.isRequired,
onDeleteField: PropTypes.func.isRequired,
children: PropTypes.string.isRequired,
};
export default FieldButtonContent;