-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
PatternSquares.js
59 lines (53 loc) · 1.67 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
50
51
52
53
54
55
56
57
58
59
import { memo } from 'react'
import PropTypes from 'prop-types'
export const PatternSquaresDefaultProps = {
color: '#000000',
background: '#ffffff',
size: 4,
padding: 4,
stagger: false,
}
export const PatternSquares = memo(props => {
const {
id,
color = PatternSquaresDefaultProps.color,
background = PatternSquaresDefaultProps.background,
size = PatternSquaresDefaultProps.size,
padding = PatternSquaresDefaultProps.padding,
stagger = PatternSquaresDefaultProps.stagger,
} = props
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,
}
export const patternSquaresDef = (id, options = {}) => ({
id,
type: 'patternSquares',
...options,
})