Gathering detailed insights and metrics for react-flexbox-layout
Gathering detailed insights and metrics for react-flexbox-layout
Gathering detailed insights and metrics for react-flexbox-layout
Gathering detailed insights and metrics for react-flexbox-layout
npm install react-flexbox-layout
Typescript
Module System
Node Version
NPM Version
JavaScript (94.48%)
CSS (5.52%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
44 Stars
105 Commits
13 Forks
3 Watchers
7 Branches
10 Contributors
Updated on May 12, 2022
Latest Version
1.2.8
Package Id
react-flexbox-layout@1.2.8
Unpacked Size
316.58 kB
Size
93.76 kB
File Count
37
NPM Version
6.4.1
Node Version
8.11.2
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
2
Simple flexible layouts for IE9+.
UI developers often need to implement layouts that grow and shrink with the size of the container, or align elements with each other. Flexbox is a great solution to this, but it's only supported in newer browsers.
The most common use case is a series of elements laid out in a row or column with some spacing between them (which we'll call gutters). react-flexbox-layout
makes this easy to achieve.
react-flexbox-layout
components expose a subset of flexbox functionality.
For Chrome, Firefox, IE10+, and Safari, native flexbox is used. For IE9, a Javascript shim is used.
1
2// Import the components with the default config
3import { HLayout, HLayoutItem, VLayout, VLayoutItem } from 'react-flexbox-layout';
4
5// Another way: Import the factory function to create the components with custom config
6import { createCustomClasses } from 'react-flexbox-layout';
7
8const { HLayout, HLayoutItem, VLayout, VLayoutItem } = createCustomClasses({
9 defaultGutter: ...,
10 gutterMultiplier: ...,
11 defaultGutterUnit: ...,
12 // wether to simulate flexbox behavior or not. In the browser it is automatically
13 // set by detecting flexbox support. In the server is false by default and should
14 // be set if supporting IE9, for example, by detecting the user agent.
15 simulateFlexbox: ...
16});
You should also include the .css
file that this library provides, either by
just referencing in your html, or by importing it using webpack
with css-loader
or any other bundler:
1<link rel="stylesheet" href="<path_to_react-flexbox-layout>/lib/styles.css" />
or, inside your JS:
1import { ... } from 'react-flexbox-layout'; 2import 'react-flexbox-layout/lib/styles.css'; 3 4...
HLayout
: short for horizontal layout. A series of elements laid out in a row.VLayout
: short for vertical layout. A series of elements laid out in a column.align
: vertical alignment, e.g., top
, middle
, bottom
justify
: horizontal alignment, e.g., left
, center
, right
flexGrow
: the relative amount to grow an element to take up available spacegutter
: the amount of spacing between consecutive elements. If consecutive elements specify a different gutter size for the gutter between them, the larger value is used.HLayout
alignItems: (top|middle|baseline|bottom|stretch)
: how to vertically align children relative to this element.justifyItems: (left|center|right)
: how to horizontally align children relative to this element. applies when no elements have flexGrow
gutter: number
: amount of spacing between child elementsgutterUnit: string
: e.g., px
, rem
onLayout: func
: called after flexbox layout has been calculated (mainly used for IE9)children: node(s)
: if you'd like to apply additional layout customization, use an HLayoutItem
(see below)HLayoutItem
align: (top|middle|baseline|bottom|stretch)
: overrides parent HLayout
s alignItems
flexGrow
: the relative amount to grow this element to take up available spacegutterLeft
: overrides parent HLayout
s gutter
gutterRight
: overrides parent HLayout
s gutter
children: node
: MUST be a single childVLayout
alignItems: (top|middle|bottom)
: how to vertically align children relative to this element. applies when no elements have flexGrow
justifyItems: (left|center|right|stretch)
: how to horizontally align children relative to this element.gutter: number
: amount of spacing between child elementsgutterUnit: string
: e.g., px
, rem
onLayout: func
: called after flexbox layout has been calculated (mainly used for IE9)children: node(s)
: if you'd like to apply additional layout customization, use an VLayoutItem
(see below)VLayoutItem
justify: (left|center|right|stretch)
: overrides parent VLayout
s justifyItems
flexGrow
: the relative amount to grow this element to take up available spacegutterTop
: overrides parent VLayout
s gutter
gutterBottom
: overrides parent VLayout
s gutter
children: node
: MUST be a single childrequestNextLayoutMinDelay(n)
Request that the next layout occur at least this n
milliseconds from now. Only applies for IE9. Useful for debouncing layouts after rapidly occuring events like keypresses. See /examples/debounce/app.jsx
for example usage.
LayoutItem
s must have style: box-sizing: border-box
.The easiest way to do this is to define this CSS: * { box-sizing: border-box }
LayoutItems
will simply overflow if they're too big. This is the CSS equivalent to * { flex-wrap: nowrap }
The JS layout algorithm used in the IE9 shim needs to unset certain styles in order to measure the intrinsic heights of elements. This may cause your scrollable elements to lose their scroll position.
In cases where scroll position is being lost, you should manually save the scroll position before the calculation, and restore the scroll position afterwards.
1class MyScrollingContainer extends React.Component { 2 componentWillUpdate() { 3 this._scrollPos = ReactDOM.findDOMNode(this).scrollTop; 4 } 5 6 restoreScroll() { 7 ReactDOM.findDOMNode(this).scrollTop = this._scrollPos; 8 } 9 10 render() { 11 return ( 12 <VLayout onLayout={this.restoreScroll.bind(this)}> 13 // lots of content 14 </VLayout> 15 ) 16 } 17}
When gutter
s are applied, dimensions won't add 100% because gutters add a non-percentage width. Use flexGrow
to take up remaining space instead. e.g.
1// won't work. will overflow. 2<HLayout gutter="10px"> 3 <HLayoutItem width="33%">a</HLayoutItem> 4 <HLayoutItem width="33%">b</HLayoutItem> 5 <HLayoutItem width="33%">c</HLayoutItem> 6</HLayout> 7 8// will work 9<HLayout gutter="10px"> 10 <HLayoutItem flexGrow>a</HLayoutItem> 11 <HLayoutItem flexGrow>b</HLayoutItem> 12 <HLayoutItem flexGrow>c</HLayoutItem> 13</HLayout>
height: 100%
doesn't work in flexboxreact-flexbox-layout
automatically expands a LayoutItem's immediate child to fill the LayoutItem's height if applicable (i.e. <HLayoutItem align="stretch">
or <VLayoutItem flexGrow>
). However, grand-children aren't automatically expanded in this way, and the CSS magic to make that happen differs depending on browser. In order to make this happen, add the classname constant EXPAND_CHILD
.
1// before 2<HLayoutItem align="stretch"> 3 <div> // child auto-expands. 4 <div> // grandchild doesn't auto-expand. 5 content is small 6 </div> 7 </div> 8</HLayoutItem> 9 10// after 11import {EXPAND_CHILD} from `react-flexbox-layout`; 12<HLayoutItem align="stretch"> 13 <div className={EXPAND_CHILD}> // child auto-expands. 14 <div> // grandchild auto-expands! 15 content is big 16 </div> 17 </div> 18</HLayoutItem>
If you need to use React 0.13 please use the version 0.x. Version 1.x or major DO NOT support React 0.13. Master and version 1.x or greater only work with React 0.14 or greater.
npm install
npm run watch
npm run examples
, http://localhost:8080
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 5/18 approved changesets -- score normalized to 2
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
86 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More