A set of responsive & highly reusable UI components are used as building blocks for every page.
Components use styled-system for responsive, theme-based props.
Here is a comprehensive list of all styling props.
There are a couple of ways to extend UI components. The following examples are equivalent.
// Passing styled-system props
import Button from 'components/Button'
const ButtonExample = () => (
<Button
bg='green'
color='white'
margin='auto'
px='2rem'
py='1rem'
/>
)
OR
// Using styled-components
import styled from 'styled-components'
import { Button as Base } from 'components/Button'
const Button = styled(Base)`
background-color: #02BE57;
color: 'white';
margin: auto;
padding: 1rem 2rem;
`
Read more about extending styles.
Components use styled-system's color utility to pass color
and bg
props.
To promote design consistency, color values are defined in the theme.colors
object located in the styles
folder.
Pass an array for any styled-system prop to set mobile-first responsive styles through media queries defined in theme.breakpoints
ex.
<Box
width={[
1, // 100% below smallest breakpoint
1/2, // 50% next breakpoint and up
1/4 // 25% next breakpoint and up
]}
>
Theming is done using styled-components' ThemeProvider
and passing a theme
object as a prop.
Read more about theming in styled-system.
import { ThemeProvider } from 'styled-components'
import { theme } from 'styles/theme'
<ThemeProvider theme={theme}>
{children}
</ThemeProvider>
Responsive layout component for commonly used styles.
import Box from 'components/Box'
<Box
mx='auto'
p='2rem'
color='blue'
bg='white'
width={['100%', '90%', '80%']}
minWidth={400}
height='auto'
display={['none', 'block']}
/>
- Spacing props (see docs)
m
: marginmt
: margin-topmr
: margin-rightmb
: margin-bottomml
: margin-leftmx
: margin-left and margin-rightmy
: margin-top and margin-bottomp
: paddingpt
: padding-toppr
: padding-rightpb
: padding-bottompl
: padding-leftpx
: padding-left and padding-rightpy
: padding-top and padding-bottom
color
: text colorbg
: background colorheight
width
: responsive- min & max width & height
display
: responsivecss
: CSS object or string overrides for edge-case styling
Button component. Extends Card
import Button from 'components/Button'
Layout component with additional style props. Extends Box
.
import Card from 'components/Card'
<Card
backgroundImage='/static/path/to/some/background'
backgroundSize='100% 100%'
background-repeat='no-repeat'
p='2rem'
depth={3}
/>
- All
Box
props - borders
backgroundImage
backgroundSize
backgroundPosition
backgroundRepeat
depth
: shadow depth defined intheme.shadows
Extended Box
component for flexbox layouts.
import Flex from 'components/Flex'
<Flex
row
basis='50%'
justifyContent='flex-start'
alignItems='center'
/>
- All
Box
props direction
basis
row
column
reverse
wrap
order
center
: absolute centering
import styled from 'styled-components'
import { CheckCircle as Base } from 'styled-icons/feather/CheckCircle.cjs'
import { themeGet } from 'styled-system'
const CheckCircle = styled(Base)`
color: ${themeGet('colors.green')};
width: 60px;
height: 60px;
margin: 0 auto 1rem;
`
Icons are created using styled-icons
Make sure you import an Icon's .cjs
module or else Next will crash.
Image component. Extends Box
.
import Image from 'components/Image'
<Image
src='/static/some/image'
height={200}
width={200}
borderRadius={100}
/>
- All
Box
props borderRadius
Input component for use with Formik's Field component.
Modal component. Can be toggled using the Toggle
component
import Modal from 'components/Modal'
import Toggle from 'components/Toggle'
const ModalExample = () => (
<Toggle>
{({ toggled, onToggle }) => (
<>
<Button onClick={onToggle}>
Toggle Modal
</Button>
<Modal opened={toggled} onClose={onToggle}>
<Box p='2rem'>
<Text>I'm a modal! Click anywhere outside to close me.</Text>
</Box>
</Modal>
</>
)}
</Toggle>
)
onClose
: function to close the modal. Requiredopened
: whether or not the modal should be open
The Text
component allows consistent styling with minimal code.
Pass a variant
prop to style headings defined in theme.fonts
import Text from 'components/Text'
// styling via props
<Text
fontSize='3.75rem'
fontWeight='bold'
textAlign='center'
/>
// or using a variant
<Text variant='h1' textAlign='center'>