Created
April 27, 2021 19:44
-
-
Save lowmess/67b7979538268ed786315dc3bce640cd to your computer and use it in GitHub Desktop.
Theme UI Stack with dividers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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