/
dynamicBlock.ee.js
134 lines (126 loc) 路 3.87 KB
/
dynamicBlock.ee.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import React from 'react';
import { arrayOf, bool, oneOf, shape, string } from 'prop-types';
import { useStyle } from '@magento/venia-ui/lib/classify';
import CmsDynamicBlockGroup, {
DISPLAY_MODE_FIXED_TYPE,
DISPLAY_MODE_SALES_RULE_TYPE,
DISPLAY_MODE_CATALOG_RULE_TYPE
} from '@magento/venia-ui/lib/components/CmsDynamicBlock';
import defaultClasses from './dynamicBlock.module.css';
/**
* Page Builder Dynamic Block component.
*
* This component is part of the Page Builder / PWA integration. It can be consumed without Page Builder.
*
* @typedef DynamicBlock
* @kind functional component
*
* @param {props} props React component props
*
* @returns {React.Element} A React component that displays a Dynamic Block.
*/
const DynamicBlock = props => {
const classes = useStyle(defaultClasses, props.classes);
const {
displayInline,
displayMode,
uids = '',
textAlign,
border,
borderColor,
borderWidth,
borderRadius,
marginTop,
marginRight,
marginBottom,
marginLeft,
minHeight,
paddingTop,
paddingRight,
paddingBottom,
paddingLeft,
cssClasses = []
} = props;
const dynamicStyles = {
textAlign,
border,
borderColor,
borderWidth,
borderRadius,
marginTop,
marginRight,
marginBottom,
marginLeft,
minHeight,
paddingTop,
paddingRight,
paddingBottom,
paddingLeft
};
const RootTag = displayInline ? 'span' : 'div';
// If no uids are found, do not render
if (!uids || (uids && uids.length === 0)) {
return null;
}
return (
<RootTag
style={dynamicStyles}
className={[classes.root, ...cssClasses].join(' ')}
aria-live="polite"
aria-busy="false"
>
<CmsDynamicBlockGroup displayMode={displayMode} uids={uids} />
</RootTag>
);
};
/**
* Props for {@link DynamicBlock}
*
* @typedef props
*
* @property {Object} classes An object containing the class names for the component
* @property {String} classes.root CSS class for the component root element
* @property {Boolean} displayInline Select display inline or display block
* @property {String} displayMode Display mode of the dynamic block
* @property {String} uids ID of the dynamic block
* @property {String} textAlign Alignment of the component within the parent container
* @property {String} border CSS border property
* @property {String} borderColor CSS border color property
* @property {String} borderWidth CSS border width property
* @property {String} borderRadius CSS border radius property
* @property {String} marginTop CSS margin top property
* @property {String} marginRight CSS margin right property
* @property {String} marginBottom CSS margin bottom property
* @property {String} marginLeft CSS margin left property
* @property {String} paddingTop CSS padding top property
* @property {String} paddingRight CSS padding right property
* @property {String} paddingBottom CSS padding bottom property
* @property {String} paddingLeft CSS padding left property
* @property {Array} cssClasses List of CSS classes to be applied to the component
*/
DynamicBlock.propTypes = {
classes: shape({
root: string
}),
displayInline: bool,
displayMode: oneOf([
DISPLAY_MODE_FIXED_TYPE,
DISPLAY_MODE_SALES_RULE_TYPE,
DISPLAY_MODE_CATALOG_RULE_TYPE
]),
uids: string,
textAlign: string,
border: string,
borderColor: string,
borderWidth: string,
borderRadius: string,
marginTop: string,
marginRight: string,
marginBottom: string,
marginLeft: string,
paddingTop: string,
paddingRight: string,
paddingBottom: string,
cssClasses: arrayOf(string)
};
export default DynamicBlock;