Layout is a 1-dimensional layout system with options to control the relative sizing of its children's elements. Layout spans the full width of the viewport area.
Usage
import { Layout } from 'nr1'
Examples
Basic
<Layout preview> <LayoutItem> <div className="nr1-Box">Main content</div> </LayoutItem></Layout>
Split left small
<Layout preview> <LayoutItem type={LayoutItem.TYPE.SPLIT_LEFT} sizeType={LayoutItem.SIZE_TYPE.SMALL} > <div className="nr1-Box">Navigation</div> </LayoutItem> <LayoutItem> <div className="nr1-Box">Main content</div> </LayoutItem></Layout>
Split right medium
<Layout preview> <LayoutItem> <div className="nr1-Box">Main content</div> </LayoutItem> <LayoutItem type={LayoutItem.TYPE.SPLIT_RIGHT}> <div className="nr1-Box">Activity stream</div> </LayoutItem></Layout>
Split left small and split right medium
<Layout preview> <LayoutItem type={LayoutItem.TYPE.SPLIT_LEFT} sizeType={LayoutItem.SIZE_TYPE.SMALL} > <div className="nr1-Box">Navigation</div> </LayoutItem> <LayoutItem> <div className="nr1-Box">Main content</div> </LayoutItem> <LayoutItem type={LayoutItem.TYPE.SPLIT_RIGHT}> <div className="nr1-Box">Activity stream</div> </LayoutItem></Layout>
Split left and right collapsible
<Layout preview fullHeight> <CollapsibleLayoutItem triggerType={CollapsibleLayoutItem.TRIGGER_TYPE.INBUILT} type={LayoutItem.TYPE.SPLIT_LEFT} sizeType={LayoutItem.SIZE_TYPE.SMALL} > <div className="nr1-Box">Navigation</div> </CollapsibleLayoutItem>
<LayoutItem> <div className="nr1-Box">Main content</div> </LayoutItem>
<CollapsibleLayoutItem triggerType={CollapsibleLayoutItem.TRIGGER_TYPE.INBUILT} type={LayoutItem.TYPE.SPLIT_RIGHT} > <div className="nr1-Box">Activity stream</div> </CollapsibleLayoutItem></Layout>
Collapsible in controlled mode
class Example extends React.Component { constructor(props) { super(props);
this.state = { collapsedLeft: false, collapsedRight: false, }; }
render() { return ( <> <Stack> <StackItem> <label> Collapsed on the left side? <input type="checkbox" onChange={(e) => this.setState({ collapsedLeft: e.currentTarget.checked }) } /> </label> </StackItem>
<StackItem> <label> Collapsed on the right side? <input type="checkbox" onChange={(e) => this.setState({ collapsedRight: e.currentTarget.checked }) } /> </label> </StackItem> </Stack>
<Layout preview fullHeight> <CollapsibleLayoutItem collapsed={this.state.collapsedLeft} triggerType={CollapsibleLayoutItem.TRIGGER_TYPE.CUSTOM} type={LayoutItem.TYPE.SPLIT_LEFT} sizeType={LayoutItem.SIZE_TYPE.SMALL} > <div className="nr1-Box">Navigation</div> </CollapsibleLayoutItem>
<LayoutItem> <div className="nr1-Box">Main content</div> </LayoutItem>
<CollapsibleLayoutItem collapsed={this.state.collapsedRight} triggerType={CollapsibleLayoutItem.TRIGGER_TYPE.CUSTOM} type={LayoutItem.TYPE.SPLIT_RIGHT} > <div className="nr1-Box">Activity stream</div> </CollapsibleLayoutItem> </Layout> </> ); }}
Stacked layout
<> <Layout preview> <LayoutItem> <div className="nr1-Box">Chart</div> </LayoutItem> </Layout> <Layout preview> <LayoutItem type={LayoutItem.TYPE.SPLIT_LEFT} sizeType={LayoutItem.SIZE_TYPE.SMALL} > <div className="nr1-Box">Navigation</div> </LayoutItem> <LayoutItem> <div className="nr1-Box">Main Content</div> </LayoutItem> </Layout></>
Props
REQUIREDnode | Layout items to display. |
string | Appends class names to the component. |
boolean | Expands the layout to occupy all available height. |
boolean | Visually draws the boxes of the layout and its layout items. |
object | Inline style for custom styling. |
string | Adds a Note: You might not see |