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

reflexbox

v4.0.6

Published

Responsive React grid system built with Styled System, with support for Emotion and Styled Components

Downloads

273,557

Readme

Reflexbox

📦 Ergonomic, responsive React layout and grid system. The original Box component™ since 2015

Build Status Downloads Version MIT License system-ui/theme

  • Primitive styled components for all your layout needs
  • Customize styles inline with the sx prop
  • Ergonomic responsive array-based values
  • Support for component variants
  • Styled System props
  • Themeable and compatible with the Theme Specification
  • Built with Styled System
  • Works with Theme UI
  • Built with Emotion, with support for Styled Components

Getting Started

npm i reflexbox
import React from 'react'
import { Flex, Box } from 'reflexbox'

export default props =>
  <Flex flexWrap='wrap'>
    <Box
      width={[ 1, 1/2 ]}
      p={3}>
      Reflex
    </Box>
    <Box
      width={[ 1, 1/2 ]}
      p={3}>
      Box
    </Box>
  </Flex>

sx Prop

The Box and Flex components both accept a sx prop that works with no additional setup required. The sx prop is similar to Emotion's css prop, but allows you to use values derived from the theme object.

Reflexbox follows the Theme Specification, which means that any theme created for use with Theme UI, Styled System, or other similar libraries will work out-of-the-box. This allows you to share design constraints for typography, color, and layout throughout your application using a theming context.

<Box
  sx={{
    p: 4,
    color: 'primary',
  }}
/>

Note: to opt-out of theme-based styles, use the css prop instead, which will not transform values.

Theming

Because Reflexbox follows the Theme Specification, all themes built for use with Styled System, Theme UI, or other related libraries are compatible with Reflexbox.

To add a theme to an application, import the ThemeProvider component from emotion-theming and pass a custom theme object in.

npm i emotion-theming
import React from 'react'
import { ThemeProvider } from 'emotion-theming'
import { Flex, Box } from 'reflexbox'

const theme = {
  breakpoints: [
    '40em', '52em', '64em',
  ],
  colors: {
    text: '#000',
    background: '#fff',
    primary: '#07c',
  },
  space: [
    0, 4, 8, 16, 32, 64, 128, 256,
  ],
}

export default props =>
  <ThemeProvider theme={theme}>
    <Box
      sx={{
        p: 4,
        bg: 'primary',
      }}>
      Hello
    </Box>
  </ThemeProvider>

For use with Theme UI, use gatsby-plugin-theme-ui or import the Theme UI ThemeProvider instead.

import { ThemeProvider } from 'theme-ui'

Variants

Reflexbox components also accept a variant prop, which allows you to define commonly used styles, such as cards, badges, and CSS grid layouts, in your theme object for reuse.

Add a variants object to your theme and include any variants as style objects. These styles can reference other values in your theme such as colors, typographic styles, and more.

// example theme
export default {
  colors: {
    text: '#000',
    background: '#fff',
    primary: '#07c',
  },
  radii: {
    default: 4,
  },
  shadows: {
    card: '0 0 4px rgba(0, 0, 0, .125)',
  },
  variants: {
    card: {
      p: 3,
      borderRadius: 'default',
      bg: 'white',
      boxShadow: 'card',
    },
    badge: {
      color: 'white',
      bg: 'primary',
      p: 1,
      borderRadius: 'default',
    },
  },
}

To apply a variant to your component, pass the name to the variant prop.

<Box variant='card'>Card</Box>
<Box variant='badge'>Badge</Box>

Responsive Styles

Use array values to quickly and ergonomically add mobile-first responsive styles to specific properties. This works on all style props and the sx prop. See the Styled System docs for more.

// 100% width at the smallest viewport width
// 50% width at the next breakpoint
// 25% width at the next breakpoint
<Box width={[ '100%', '50%', '25%' ]} />

You can customize the widths used for each breakpoint by defining a theme.breakpoints array in your theme.

Styled System Props

Reflexbox conforms to the Theme Specification and includes many common Styled System props. The Box and Flex components accept the following props:

Space Props

Prop | Theme Key ---|--- margin, m | space marginTop, mt | space marginRight, mr | space marginBottom, mb | space marginLeft, ml | space marginX, mx | space marginY, my | space padding, p | space paddingTop, pt | space paddingRight, pr | space paddingBottom, pb | space paddingLeft, pl | space paddingX, px | space paddingY, py | space

Layout Props

Prop | Theme Key ---|--- width | sizes height | sizes minWidth | sizes maxWidth | sizes minHeight | sizes maxHeight | sizes

Typography Props

Prop | Theme Key ---|--- fontFamily | fonts fontSize | fontSizes fontWeight | fontWeights lineHeight | lineHeights letterSpacing | letterSpacings fontStyle | N/A textAlign | N/A

Color Props

Prop | Theme Key ---|--- color | colors backgroundColor, bg | colors opacity | N/A

Flexbox Props

Prop | Theme Key ---|--- alignItems | N/A alignContent | N/A justifyItems | N/A justifyContent | N/A flexWrap | N/A flexDirection | N/A flex | N/A flexGrow | N/A flexShrink | N/A flexBasis | N/A justifySelf | N/A alignSelf | N/A order | N/A

Styled Components

To use Reflexbox with Styled Components, import components from reflexbox/styled-components.

import { Flex, Box } from 'reflexbox/styled-components'

About

This library is the result of consolidating APIs and ergonomics from the original Reflexbox library, Grid Styled, and Rebass Grid. Reflexbox originally appeared with the original version of Rebass in 2015.

MIT License