forked from testing-library/testing-library-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.jsx
97 lines (84 loc) · 2.45 KB
/
index.jsx
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
/**
* Copyright (c) 2017-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import React from 'react'
import classNames from 'classnames'
import {MarkdownBlock} from '../MarkdownBlock'
const renderBlockImage = (image, imageLink, imageAlt) => {
if (!image) {
return null
}
return (
<div className="blockImage">
{imageLink ? (
<a href={imageLink}>
<img src={image} alt={imageAlt} />
</a>
) : (
<img src={image} alt={imageAlt} />
)}
</div>
)
}
const renderBlockTitle = title => {
if (!title) {
return null
}
return (
<h2>
<MarkdownBlock>{title}</MarkdownBlock>
</h2>
)
}
export const GridBlock = props => {
const renderBlock = origBlock => {
const blockDefaults = {
imageAlign: 'left',
}
const block = {
...blockDefaults,
...origBlock,
}
const blockClasses = classNames('blockElement', props.className, {
alignCenter: props.align === 'center',
alignRight: props.align === 'right',
fourByGridBlock: props.layout === 'fourColumn',
imageAlignSide:
block.image &&
(block.imageAlign === 'left' || block.imageAlign === 'right'),
imageAlignTop: block.image && block.imageAlign === 'top',
imageAlignRight: block.image && block.imageAlign === 'right',
imageAlignBottom: block.image && block.imageAlign === 'bottom',
imageAlignLeft: block.image && block.imageAlign === 'left',
threeByGridBlock: props.layout === 'threeColumn',
twoByGridBlock: props.layout === 'twoColumn',
})
const topLeftImage =
(block.imageAlign === 'top' || block.imageAlign === 'left') &&
renderBlockImage(block.image, block.imageLink, block.imageAlt)
const bottomRightImage =
(block.imageAlign === 'bottom' || block.imageAlign === 'right') &&
renderBlockImage(block.image, block.imageLink, block.imageAlt)
return (
<div className={blockClasses} key={block.title}>
{topLeftImage}
<div className="blockContent">
{renderBlockTitle(block.title)}
<MarkdownBlock>{block.content}</MarkdownBlock>
</div>
{bottomRightImage}
</div>
)
}
return (
<div className="gridBlock">{props.contents.map(renderBlock, this)}</div>
)
}
GridBlock.defaultProps = {
align: 'left',
contents: [],
layout: 'twoColumn',
}