Skip to content

Instantly share code, notes, and snippets.

@lowmess
Created April 27, 2021 19:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lowmess/67b7979538268ed786315dc3bce640cd to your computer and use it in GitHub Desktop.
Save lowmess/67b7979538268ed786315dc3bce640cd to your computer and use it in GitHub Desktop.
Theme UI Stack with dividers
import * as React from 'react'
import { Box, Flex } from 'theme-ui'
import { ResponsiveStyleValue } from '@theme-ui/css'
import { BoxProps } from '@theme-ui/components'
interface Props extends BoxProps {
gap?: ResponsiveStyleValue<number>
dividers?: boolean
dividerColor?: ResponsiveStyleValue<string>
}
const Stack: React.FC<Props> = ({
gap = 0,
dividers,
dividerColor = 'border',
children,
sx,
...props
}) => {
const items = React.Children.toArray(children)
return (
<Flex
sx={{
flexFlow: 'column nowrap',
gap,
...sx,
}}
{...props}
>
{items.map((child, index) => (
<Box
key={index}
sx={{
'& + &': {
borderTop: dividers ? 1 : 0,
borderColor: dividerColor,
paddingTop: dividers ? gap : 0,
},
}}
>
{child}
</Box>
))}
</Flex>
)
}
export default Stack
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment