/
block.js
97 lines (92 loc) 路 2.62 KB
/
block.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
import React from 'react';
import CmsBlock from '@magento/venia-ui/lib/components/CmsBlock/block';
import { arrayOf, string } from 'prop-types';
/**
* Page Builder Block component.
*
* This component is part of the Page Builder / PWA integration. It can be consumed without Page Builder.
*
* @typedef Block
* @kind functional component
*
* @param {props} props React component props
*
* @returns {React.Element} A React component that displays a Block.
*/
const Block = props => {
const {
richContent,
textAlign,
border,
borderColor,
borderWidth,
borderRadius,
marginTop,
marginRight,
marginBottom,
marginLeft,
paddingTop,
paddingRight,
paddingBottom,
paddingLeft,
cssClasses = []
} = props;
const dynamicStyles = {
textAlign,
border,
borderColor,
borderWidth,
borderRadius,
marginTop,
marginRight,
marginBottom,
marginLeft,
paddingTop,
paddingRight,
paddingBottom,
paddingLeft
};
return (
<div style={dynamicStyles} className={cssClasses.join(' ')}>
<CmsBlock content={richContent} />
</div>
);
};
/**
* Props for {@link Block}
*
* @typedef props
*
* @property {String} richContent Rich content of the block
* @property {String} textAlign Alignment of the block 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
*/
Block.propTypes = {
richContent: 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 Block;