Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

layabout

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

layabout

Simple layout components for React

  • 0.9.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

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>  

Keywords

FAQs

Package last updated on 02 Apr 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc