npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

superbox

v2.1.0

Published

Primitive React component for all your styles

Downloads

60

Readme

superbox

Primitive React component for all your styles

Build Status

npm i superbox styled-components
import React from 'react'
import Box from 'superbox'

export default props =>
  <Box
    fontSize={5}
    px={3}
    py={4}
    color='white'
    bg='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
import Box from 'superbox/emotion'

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
  width={[
    1,    // 100% width at the smallest breakpoint
    1/2,  // 50% width at the next breakpoint and up
    1/4   // 25% width at the next breakpoint and up
  ]}
/>
// responsive font size
<Box fontSize={[ 2, 3, 4, 5 ]} />

css prop

The css prop can be used to apply custom styling to the component.

// with style object
<Box
  css={{
    fontFamily: 'monospace'
  }}
/>
// with CSS string
<Box
  css={`
    font-family: monospace;
  `}
/>

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 is='header' />
// component example
<Box is={Link} />

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 = props =>
  <Box
    is='button'
    fontSize={1}
    m={0}
    px={3}
    py={2}
    color='white'
    bg='blue'
    {...props}
    css={{
      fontFamily: 'inherit',
      fontWeight: 'bold',
      display: 'inline-block',
      verticalAlign: 'middle',
      textAlign: 'center',
      border: 0,
      borderRadius: 2,
      textDecoration: 'none',
      appearance: 'none',
      '&:disabled': {
        opacity: 1/4
      }
    }}
  />

export default Button

Styling based on props

You can adjust styling based on props when extending the Box component.

const Banner = ({
  large,
  ...props
}) =>
  <Box
    px={large ? 4 : 3}
    py={large ? 3 : 2}
    {...props}
  />

This also works with the css prop.

const Text = ({
  caps,
  ...props
}) =>
  <Box
    {...props}
    css={{
      textTransform: caps ? 'uppercase' : null
    }}
  />

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'

export default () =>
  <ThemeProvider theme={theme}>
    {/* 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 prop
  • color: styled-system's color prop
  • bg: styled-system's bg prop
  • styled-system's space props
    • m: margin
    • mt: margin-top
    • mr: margin-right
    • mb: margin-bottom
    • ml: margin-left
    • mx: margin-left and margin-right
    • my: margin-top and margin-bottom
    • p: padding
    • pt: padding-top
    • pr: padding-right
    • pb: padding-bottom
    • pl: padding-left
    • px: padding-left and padding-right
    • py: padding-top and padding-bottom
  • width: styled-system's width prop
  • css: (string or object) pass custom CSS styles
  • is: (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.