0.9.0 • Published 5 years ago

layabout v0.9.0

Weekly downloads
1
License
Apache-2.0
Repository
github
Last release
5 years ago

Layabout

Build Status

Low config layout components for React.

View the storybook demo at https://yearofthedan.github.io/layabout/


Issues and contributions are welcome. Specifics on how and the guiding philosophy are under CONTRIBUTING.md.

This is very much in alpha, so expect the api to shift a lot.


Components

Grid

Lays out children according to a defined grid structure

PropDescriptionOptionsDefault
containerElement to hold container styles and render children into.Any string representing a HTML DOM element (eg. div) or a React component. For React components the style prop must be received by the container and passed to an underlying DOM element to render it (eg. a HTML DOM element).generates a div
widthsAn array of column widthsString values will be mapped directly to css so feel free to use things like minmax(). If an integer is given it will be mapped as an fr unit.['auto']
heightsAn array of row heightsString values will be mapped directly to css so feel free to use things like minmax(). If an integer is given it will be mapped as an fr unit.['auto']
columnGapThe gap or gutter between each columnA string property to be mapped directly as css (eg.4px)none
rowGapThe gap or gutter between each rowA string property to be mapped directly as css (eg.4px)none
styleStyle properties to be applied to the container. This particularly supports use cases where you're combining layout components.A style objectnone
layoutA template expressing the entries in the grid. See below for some advice on useA multiline string where each line represents one row in the grid and each line contains the list of elements at each column position. Use the child component name, or a . to denote an empty cell. If a component is named multiple times it means that the component takes up multiple cells.Empty layout, meaning the children will flow into the provided column and row structure defined by the widths and heights props

Any other props are passed through to the container.

Hey! Some things to think about with the layout prop The magic of Grid is in the binding between the template as described in the layout prop and the children.

1. everything needs to have a unique name

If you have multiple same named elements - lets us div as an example - as children there's no way to define different div sections in the template since you should just write 'div'. To avoid this you should wrap them in a uniquely named component (nb. this is more semantic anyway). Alternatively, you can just not use the template prop, in which case the elements will just flow across the rows and columns.

2. use fromComponents for safety

The renderer will try to connect the display name of the element to the token in the layout string. A few things can interfere here, particularly minimisation steps in your build which may mean that the child elements display name is no longer the same as what you wrote in the template. To get around this you can import and use fromComponents and refer to the components in the template directly. This will map any provided components to their actual display name at run time.

Usage

import {fromComponents} from 'layabout';
<Grid  
  widths={[1, 4, 1]}  
  heights={['100px', 'minmax(100px, 200px)', '100px', 'auto', '50px']}  
  layout={fromComponents`  
   ${MenuHeader} ${MenuHeader}   ${MenuHeader}
   .             ${LogoSection}  .
   .             ${Search}       .
   .             .               .
   ${Footer}     ${Footer}       ${Footer}  
 `}  
  container={Page}  
>  
 <MenuHeader />
 <LogoSection />
 <Search />
 <Footer />
</Grid>

FlexRow / FlexColumn

Lays out its children one by one according to a set of relative sizes. Overflow continues onto the new row/column, following the same template.

PropDescriptionOptionsDefault
sizesSet of relative weights for the amount of space available to children on a rowAn array of numbers for the rowChildren will share available space equally
containerElement to hold container styles and render children into.Any string representing a HTML DOM element (eg. div) or a React component. For React components the style prop must be received by the container and passed to an underlying DOM element to render it (eg. a HTML DOM element).generates a div
alignCrossAxisHow to align content on the cross axisstart,middle, endmiddle
styleStyle properties to be applied to the container. This particularly supports use cases where you're combining layout components.A style objectnone

Usage

<FlexRow  
 sizes={[2, 4, 4]} container={Article}>  
 <section />
 <section />
 <section />
</FlexRow>  

In the example above the sections would have spacing of 2/10ths, 4/10ths, and 4/10ths of the total available width.

SpacedColumn / SpacedRow

Lays out children within the space available. Any remaining spacing is allocated according to the spacing prop.

PropDescriptionOptionsDefault
spacingHow to allocate remaining spacebetween, around, start, middle, endbetween
containerElement to hold container styles and render children into.Any string representing a HTML DOM element (eg. div) or a React component. For React components the style prop must be received by the container and passed to an underlying DOM element to render it (eg. a HTML DOM element).generates a div
alignCrossAxisHow to align content on the cross axisstart, middle, endmiddle
styleStyle properties to be applied to the container. This particularly supports use cases where you're combining layout components.A style objectnone

Usage

<SpacedRow spacing="between" container={MyCustomContainer}>  
 <section />
 <section />
 <section />
</SpacedRow>  

0.9.0

5 years ago

0.8.10

5 years ago

0.8.9

5 years ago

0.8.8

5 years ago

0.8.7

5 years ago

0.8.6

5 years ago

0.8.5

5 years ago

0.8.2

5 years ago

0.8.1

5 years ago

0.8.0

5 years ago

0.7.3

6 years ago

0.7.2

7 years ago

0.7.1

7 years ago

0.7.0

7 years ago

0.6.2

7 years ago

0.6.1

7 years ago

0.6.0

7 years ago

0.5.3

7 years ago

0.5.2

7 years ago

0.5.1

7 years ago

0.5.0

7 years ago

0.4.0

7 years ago

0.3.1

7 years ago

0.3.0

7 years ago

0.2.2

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago