1.1.2 • Published 7 years ago

react-boxen v1.1.2

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

React Boxen

A layout primitive for React.

React Boxen utilizes Styled Components to provide cross-browser layout.

Why?

  • Flex Box Plus - Provides a helpful layer of abstraction on top of the robust (and sometimes confusing) display flex properties
  • Child spacing - Provides consistent spacing between child elements vertically, horizontally, and wrapping

Installation

npm install react-boxen --save or yarn add react-boxen

Usage Examples

Spacing vertically

This example produces a layout with each child spaced vertically.

import React from "react"
import Box from "react-boxen"

const css = {
  parent: `
    padding: 1em;
    background: lightgray;
  `,
  child: `
    padding: 0.75em;
    background: white;
  `
}

export default () =>
  <Box
    css={css.parent}
    childSpacing="10px">
    <Box css={css.child}>Child 1</Box>
    <Box css={css.child}>Child 2</Box>
    <Box css={css.child}>Child 3</Box>
  </Box>

Spacing horizontally

This example produces a layout with each child spaced horizontally.

import React from "react"
import Box from "react-boxen"

const css = {
  parent: `
    padding: 1em;
    background: lightgray;
  `,
  child: `
    padding: 0.75em;
    background: white;
  `
}

export default () =>
  <Box
    css={css.parent}
    childDirection="row"
    childSpacing="10px">
    <Box css={css.child}>Child 1</Box>
    <Box css={css.child}>Child 2</Box>
    <Box css={css.child}>Child 3</Box>
  </Box>

Child grow

When a child receives grow as a prop (or data-grow for native elements) it fills the available space.

import React from "react"
import Box from "react-boxen"

const css = {
  parent: `
    padding: 1em;
    background: lightgray;
  `,
  child: `
    padding: 0.75em;
    background: white;
  `
}

export default () =>
  <Box
    css={css.parent}
    childDirection="row"
    childSpacing="10px">
    <Box css={css.child}>Child 1</Box>
    <Box grow css={css.child}>Child 2</Box>
    <Box css={css.child}>Child 3</Box>
  </Box>

API

Box Properties

Properties placed on the Box component directly.

PropertyTypeValue (default *)Description
cssStringTemplate literal containing valid CSSSee styled-components documentation
childAlignStringflex-start * flex-end center stretch baselineAlign children along the cross axis
childBasisStringLengthAssigns flex-basis on children
childDirectionStringcolumn * column-reverse row row-reverseVertical or horizontal orientation of children
childJustifyStringflex-start * flex-end center space-between space-aroundAlign children along the main axis
childWrapStringnowrap * wrap wrap-reverseDefine whether or not children can wrap
childWrapLastGrowBoolTrue *Setting to false preserves any orphan element's width when childWrap is wrap.
childSpacingStringLengthSpacing between children on any axis (accepts shorthand value 5px 10em)
paddingStringLengthAccepts shorthand 5px 10em
...restAnyAnyRest of props (aside from children) are spread onto Box itself (e.g. onClick, onPress, etc.)

Child Properties

Properties added to any direct child. For compound components use values as shown. For native elements (e.g. <div />) use data-<grow|shrink|...> (i.e. <div data-grow>Child</div>).

PropertyTypeValue (default *)Description
basisStringLengthIndividual flex-basis. This controls the length (width or height) along the main axis.
growNumber0 *Amount Box should grow to fill available space
scrollBoolFalse *Sets child wrapper to 100% height and overflow auto
shrinkNumber0 *Amount Box should shrink inside available space
spacerRefFuncnull *A function used to access the reference of the child's wrapping Spacer

Roadmap

Technically, there is nothing preventing usage with React Native. The web is a more immediate proving ground. As the API solidifies, testing and support will be hammered out for RN. PRs are always welcome!

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.0

7 years ago

0.0.35

7 years ago

0.0.34

7 years ago

0.0.33

7 years ago

0.0.32

7 years ago

0.0.31

7 years ago

0.0.30

7 years ago

0.0.29

7 years ago

0.0.28

7 years ago

0.0.27

7 years ago

0.0.26

7 years ago

0.0.25

7 years ago

0.0.24

7 years ago

0.0.23

7 years ago

0.0.22

7 years ago

0.0.21

7 years ago

0.0.20

7 years ago

0.0.19

7 years ago

0.0.18

7 years ago

0.0.17

7 years ago

0.0.16

7 years ago

0.0.15

7 years ago

0.0.13

7 years ago

0.0.12

7 years ago

0.0.11

7 years ago

0.0.10

7 years ago

0.0.9

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago