
superbox
Primitive React component for all your styles
npm i superbox styled-components
import React from 'react'import Box from 'superbox' <Box = = = ='white' ='black'> superbox </Box>
Superbox works with styled-components out of the box.
To use it with emotion, import superbox/emotion
,
and ensure the following are installed:
npm i emotion react-emotion emotion-theming
Try it out on CodeSandbox – it also works with emotion.
Usage
Responsive Styles
The core style props in the Box component are built with styled-system, which allows you to set style props in a mobile-first responsive way with arrays.
// responsive width<Box =/>
// responsive font size<Box = />
css
prop
The css
prop can be used to apply custom styling to the component.
// with style object<Box =/>
// with CSS string<Box =/>
Note: the css
prop expects an object or string, not tagged templates.
is
prop
Use the is
prop to change the underlying HTML element or React component.
// HTML example<Box ='header' />
// component example<Box = />
Extending
The Box component can be used to create custom style components without needing to import any CSS-in-JS libraries.
import React from 'react'import Box from 'superbox' const Button = <Box ='button' = = = = ='white' ='blue' = />
Styling based on props
You can adjust styling based on props when extending the Box component.
const Banner = large ...props <Box = = />
This also works with the css
prop.
const Text = caps ...props <Box = />
Theming
To use a custom theme, add a ThemeProvider
to the root of your application with a custom theme
object.
import React from 'react'import ThemeProvider from 'styled-components'import theme from './theme' <ThemeProvider => /* app */ </ThemeProvider>
See the styled-system docs on theming for more information.
Props
The Box
component's props come from styled-system, which provides theme-based, responsive props.
fontSize
: styled-system's fontSize propcolor
: styled-system's color propbg
: styled-system's bg prop- styled-system's space props
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
width
: styled-system's width propcss
: (string or object) pass custom CSS stylesis
: (string or components) change the underlying HTML tag or React component
Related
How is this different from...
grid-styled
Superbox does not include the Flex component or flexbox props. Grid Styled uses system-components, but this component does not.
styled-system
This component is built with styled-system.
Rebass
Rebass is a much larger library of React components. This is just one component.