Trying to set a component as a repeating background image to a div
I have a pattern that is re-used throughout a site.
Stripped-down pattern component:
import React from 'react'
import PropTypes from 'prop-types'
import styled from 'styled-components'
const Container = styled.svg`
height: ${({ height }) => height};
`
const Path = styled.path`
fill: ${({ color }) => color};
`
export default function Pattern({ height, color }) {
return (
<Container height={height} viewBox="0 0 20 20" data-cy="svg-pattern">
<Path
color={color}
d="M0.5,0.4v19.2h19V0.4H0.5z M13.5,15.5L7,15.9l-3.5-5.5l3-5.9L13,4.1l3.5,5.5L13.5,15.5z"
/>
</Container>
)
}
Pattern.propTypes = {
height: PropTypes.string,
color: PropTypes.string,
}
Pattern.defaultProps = {
height: '10px',
color: 'blue',
}
I bring in the pattern component and pass it.
Stripped down component:
import React from 'react'
import PropTypes from 'prop-types'
import styled from 'styled-components'
// Components
import { Pattern } from '../atoms'
const Container = styled.div`
// Removed
`
// HERE
const Repeat = styled.div`
margin-bottom: ${({ theme }) => theme.space.normal};
width: 100%;
background-image: url(${({ background }) => background});
background-repeat: repeat-x;
`
export default function SoQues(props) {
return (
<Container>
<Repeat background={<Pattern color={'red'} />}/>
</Container>
)
}
SoQues.propTypes = {
// props
}
but for some reason, it will not render.
Research
- Change background image with styled-component
- pass background url as prop to styled component
- Set Background Image using props in Styled Components
- background image in styled components react
- Props to set styled components background image using in React 17
What am I doing wrong and how can I bring a component and set it as a horizontal repeating background image?