-
-
Notifications
You must be signed in to change notification settings - Fork 871
Expand file tree
/
Copy pathEditBlockWrapper.jsx
More file actions
73 lines (65 loc) · 2.11 KB
/
Copy pathEditBlockWrapper.jsx
File metadata and controls
73 lines (65 loc) · 2.11 KB
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
/** This is the classic block wrapper. The BlocksForm uses either this one or
* the QuantaEditBlockWrapper
*/
import React from 'react';
import { Icon } from '@plone/volto/components';
import { blockHasValue } from '@plone/volto/helpers';
import dragSVG from '@plone/volto/icons/drag.svg';
import { injectIntl, defineMessages } from 'react-intl';
import config from '@plone/volto/registry';
import { Button } from 'semantic-ui-react';
import includes from 'lodash/includes';
import isBoolean from 'lodash/isBoolean';
import trashSVG from '@plone/volto/icons/delete.svg';
const messages = defineMessages({
delete: {
id: 'delete',
defaultMessage: 'delete',
},
});
const EditBlockWrapper = (props) => {
const hideHandler = (data) => {
return !!data.fixed || !(blockHasValue(data) && props.blockProps.editable);
};
const { intl, blockProps, draginfo, children } = props;
const { block, selected, type, onDeleteBlock, data, editable } = blockProps;
const visible = selected && !hideHandler(data);
const required = isBoolean(data.required)
? data.required
: includes(config.blocks.requiredBlocks, type);
return (
<div
ref={draginfo.innerRef}
{...draginfo.draggableProps}
className={`block-editor-${data['@type']}`}
>
<div style={{ position: 'relative' }}>
<div
style={{
visibility: visible ? 'visible' : 'hidden',
display: 'inline-block',
}}
{...draginfo.dragHandleProps}
className="drag handle wrapper"
>
<Icon name={dragSVG} size="18px" />
</div>
<div className={`ui drag block inner ${type}`}>
{children}
{selected && !required && editable && (
<Button
icon
basic
onClick={() => onDeleteBlock(block, true)}
className="delete-button"
aria-label={intl.formatMessage(messages.delete)}
>
<Icon name={trashSVG} size="18px" />
</Button>
)}
</div>
</div>
</div>
);
};
export default injectIntl(EditBlockWrapper);