0

In Styled Components to build a div separator that implements an image background I've used:

const Separator = styled.div`
  margin-bottom: ${({ theme }) => theme.spacings.normal};
  mask-image: url('data:image/svg+xml,code');
  background-color: ${({ theme }) => theme.primary};
  height: ${({ theme }) => theme.spacings.small};
  background-repeat: repeat-x;
`

but when looking at Chakra's Divider I'm not seeing a way to use a background image as the divider and this approach did not work:

<Divider
  backgroundRepeat="repeat-x"
  height="1rem"
  opacity="1"
  backgroundImage={`url('data:image/svg+xml,code')`}
/>

Research

In Chakra what is the correct approach to building a div separator that uses a background image?

DᴀʀᴛʜVᴀᴅᴇʀ
  • 7,681
  • 17
  • 73
  • 127

1 Answers1

0

Was able to figure out how with adding sx prop:

Because Divider has an added opacity and border wrote the divider as:

<Divider
  opacity="1"
  border="none"
  mb="5"
  sx={{
    bgRepeat: 'repeat-x',
    height: 2,
    bgColor: 'color2.600',
    bgPosition: '25% 75%',
    maskImage: `url(
      'data:image/svg+xml,code'
    )`,
  }}
/>

but when looking at Background props bgPosition doesn't seem to work in the scenario with sx.

DᴀʀᴛʜVᴀᴅᴇʀ
  • 7,681
  • 17
  • 73
  • 127