/
PatternSquares.js
49 lines (45 loc) · 1.41 KB
/
PatternSquares.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
import { memo } from 'react'
import PropTypes from 'prop-types'
export const PatternSquares = memo(({ id, background, color, size, padding, stagger }) => {
let fullSize = size + padding
const halfPadding = padding / 2
if (stagger === true) {
fullSize = size * 2 + padding * 2
}
return (
<pattern id={id} width={fullSize} height={fullSize} patternUnits="userSpaceOnUse">
<rect width={fullSize} height={fullSize} fill={background} />
<rect x={halfPadding} y={halfPadding} width={size} height={size} fill={color} />
{stagger && (
<rect
x={padding * 1.5 + size}
y={padding * 1.5 + size}
width={size}
height={size}
fill={color}
/>
)}
</pattern>
)
})
PatternSquares.displayName = 'PatternSquares'
PatternSquares.propTypes = {
id: PropTypes.string.isRequired,
color: PropTypes.string.isRequired,
background: PropTypes.string.isRequired,
size: PropTypes.number.isRequired,
padding: PropTypes.number.isRequired,
stagger: PropTypes.bool.isRequired,
}
PatternSquares.defaultProps = {
color: '#000000',
background: '#ffffff',
size: 4,
padding: 4,
stagger: false,
}
export const patternSquaresDef = (id, options = {}) => ({
id,
type: 'patternSquares',
...options,
})