Package detail

reflexbox

rebassjs323.4kMIT4.0.6

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

reflexbox, flexbox, grid-styled, rebass

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

changelog

Changelog

Unreleased

4.0.6 2019-09-21

  • Update dependencies
  • Add layout package
  • Add Slider and Switch to forms package

4.0.5 2019-08-21

  • Fix publish

4.0.4 2019-08-21

  • Add bundler setup & build for @rebass/forms/styled-system

4.0.3 2019-08-18

  • Add forms package
  • Update dependencies

4.0.2 2019-08-07

4.0.1 2019-08-06

  • Fix ignore files
  • Adjust build
  • Update dependencies

4.0.0 2019-08-04

  • New sx prop for theme-based styles
  • Use the css prop for un-themed, raw CSS values
  • No additional Babel configuration required for the sx or css props
  • Use the sx prop in MDX documents
  • Built-in support for themeable component variants
  • Fully compatible with Theme UI

Breaking Changes

  • The default package now uses Emotion. To use Rebass with Styled Components, import the components from rebass/styled-components instead.
  • The undocumented theme keys for Box, Flex, Text, Heading, Link, Button, Image, and Card are no longer supported. Use variants instead.
  • The @rebass/grid package has been renamed (back to) reflexbox
  • Heading: default fontWeight is now set to heading. Add styles to theme.fontWeights to customize the heading font weight.
  • Button no longer supports the following props. Use the sx prop instead. border, borderColor, borderWidth, borderStyle, borderRadius, borderTop, borderRight, borderBottom, borderLeft, borderX, borderY
  • Image no longer supports the following props. Use the sx prop instead. border, borderColor, borderWidth, borderStyle, borderRadius, borderTop, borderRight, borderBottom, borderLeft, borderX, borderY
  • Link no longer includes default styles. Add styles to theme.variants.link to customize link styles.
  • Card no longer supports the following props. Use the sx prop instead. border, borderColor, borderWidth, borderStyle, borderRadius, borderTop, borderRight, borderBottom, borderLeft, borderX, borderY, boxShadow, textShadow, background, backgroundImage, backgroundSize, backgroundPosition, backgroundRepeat,

[3.1.0] 2019-03-23

  • Update to Styled System v4

[3.0.1] 2019-01-18

  • Update styled-system #555

[3.0.0] 2018-12-01

  • Reduced package size
  • Reduced number of components to 8
  • Updated for Styled Components v4 and Emotion v10
  • Reduced dependencies
  • Removed default theme and colors
  • Removed Provider component
  • Added variant theme support for Button and Card components
  • Removed is prop in favor of Styled Components' and Emotion's as prop
  • Uses Box component as base for all other components
  • Removed css prop in favor of Styled Components' and Emotion's implementations

[3.0.0-12] 2018-11-29

  • Removes css prop in favor of babel-plugin-styled-components
  • Adds build setup for Emotion 10

[3.0.0-11] 2018-11-13

  • Update dependencies

[3.0.0-10] 2018-11-12

  • Sets box-sizing: border-box on base Box component

[3.0.0-9] 2018-09-22

  • Adds flexbox props back to Box component

[3.0.0-6] 2018-09-13

  • Adds emotion package

[3.0.0-2] 2018-09-11

  • Update styled-system
  • Update docs

[3.0.0-1] 2018-09-10

  • Update docs for v3

[3.0.0-0] 2018-09-08

  • Smaller package
  • Reduced number of components to 8
  • Upgraded for styled-components v4
  • Reduced dependencies to one
  • Removed default theme and colors
  • Removed Rebass Provider component
  • Added variant theme support to Button and Card
  • Removed is prop in favor of styled-components as prop
  • Uses Box component as the base for all other components

[2.3.2] 2018-09-08

  • Update repo in package.json
  • Update readme

[2.3.1] 2018-09-08

  • Fix bad prepublish build

[2.3.0] 2018-09-08

  • Upgrade to @rebass/components, @rebass/grid, and styled-system v3

[2.2.0] 2018-09-08

  • Use polished for color manipulation instead of chroma-js

[2.1.1] 2018-09-08

  • Support width prop on Card
  • Update docs

[2.1.0] 2018-08-14

  • Add Hide component

[2.0.1] 2018-06-30

  • Add fontFamily to Heading and Text components
  • Update docs

[2.0.0] 2018-06-24

Added

Changed

Breaking

  • Renamed components
    • TabItem -> Tab
    • DotButton -> Dot
    • PanelHeader -> Panel.Header
    • PanelFooter -> Panel.Footer
  • Default theme (changed to match styled-system)
    • The colors object no longer uses Palx
    • Array color values have been removed
    • radius has been replaced with radii
    • font has been replaced with fonts
    • monospace has been removed
    • Theme fields are no longer exposed as exports
  • Props
    • width is only available on Flex and Box
    • fontSize is only available on typographic components
    • direction is now flexDirection
    • Flex align is now alignItems
    • Flex justify is now justifyContent
    • Flex wrap is now flexWrap
    • Arrow up is now direction='up'
    • active props have been removed in favor of custom styles
    • Border now uses styled-system border props
    • Banner image is now backgroundImage
    • Absolute, Fixed, Relative, and Sticky now require values for top, right, bottom, and left props
    • Drawer position prop has been renamed to side
    • Drawer size prop has been replaced with width and height props

Removed

  • Custom HOC hoc
  • createLibrary function
  • util
  • createComponent
  • Palx dependency
  • ScrollCarousel component
  • CarouselSlide component
  • Star comonent