Flexbox is only available in the React API for SWAN.
Use Flexbox...
- To layout content to best organize and fill the available space.
- To align elements within a container with a specific direction.
The preview has been updated.
<Card bordered><FlexBoxstyle={{ height: 360 }}justifyContent="center"alignItems="center"flexWrap="wrap"flexDirection="column">{[1, 2, 3, 4, 5, 6].map(u => (<Cardkey={u}m={2}bgc="accent"style={{ border: '1px solid red', height: 90, width: 90 }}><FlexBoxstyle={{ height: '100%' }}justifyContent="center"alignItems="center">{u}</FlexBox></Card>))}</FlexBox></Card>
<div class="swan-card swan-card-bordered"><divclass="swan-display-flex"style="height: 360px; align-items: center; flex-flow: column wrap; justify-content: center;"><divclass="swan-card swan-m-2 swan-bgc-accent"style="border: 1px solid red; height: 90px; width: 90px;"><divclass="swan-display-flex"style="height: 100%; align-items: center; justify-content: center;">1</div></div><divclass="swan-card swan-m-2 swan-bgc-accent"style="border: 1px solid red; height: 90px; width: 90px;"><divclass="swan-display-flex"style="height: 100%; align-items: center; justify-content: center;">2</div></div><divclass="swan-card swan-m-2 swan-bgc-accent"style="border: 1px solid red; height: 90px; width: 90px;"><divclass="swan-display-flex"style="height: 100%; align-items: center; justify-content: center;">3</div></div><divclass="swan-card swan-m-2 swan-bgc-accent"style="border: 1px solid red; height: 90px; width: 90px;"><divclass="swan-display-flex"style="height: 100%; align-items: center; justify-content: center;">4</div></div><divclass="swan-card swan-m-2 swan-bgc-accent"style="border: 1px solid red; height: 90px; width: 90px;"><divclass="swan-display-flex"style="height: 100%; align-items: center; justify-content: center;">5</div></div><divclass="swan-card swan-m-2 swan-bgc-accent"style="border: 1px solid red; height: 90px; width: 90px;"><divclass="swan-display-flex"style="height: 100%; align-items: center; justify-content: center;">6</div></div></div></div>
Justify Content
Use justifyContent
to align items along the primary axis, which is the x-axis by default.
The preview has been updated.
<Card bordered><FlexBoxstyle={{ height: 260 }}justifyContent="space-evenly"alignItems="center"flexWrap="wrap"flexDirection="row"gap="3"><Cardbgc="accent"style={{ border: '1px solid red', height: 90, width: 120 }}><FlexBoxstyle={{ height: '100%' }}justifyContent="center"alignItems="center">1</FlexBox></Card><Cardbgc="accent"style={{ border: '1px solid red', height: 90, width: 160 }}><FlexBoxstyle={{ height: '100%' }}justifyContent="center"alignItems="center">2</FlexBox></Card><Cardbgc="accent"style={{ border: '1px solid red', height: 90, width: 90 }}><FlexBoxstyle={{ height: '100%' }}justifyContent="center"alignItems="center">3</FlexBox></Card><Cardbgc="accent"style={{ border: '1px solid red', height: 90, width: 90 }}><FlexBoxstyle={{ height: '100%' }}justifyContent="center"alignItems="center">4</FlexBox></Card></FlexBox></Card>
<div class="swan-card swan-card-bordered"><divclass="swan-display-flex"style="height: 260px; align-items: center; flex-flow: wrap; justify-content: space-evenly; gap: var(--swan-sem-space-3);"><divclass="swan-card swan-bgc-accent"style="border: 1px solid red; height: 90px; width: 120px;"><divclass="swan-display-flex"style="height: 100%; align-items: center; justify-content: center;">1</div></div><divclass="swan-card swan-bgc-accent"style="border: 1px solid red; height: 90px; width: 160px;"><divclass="swan-display-flex"style="height: 100%; align-items: center; justify-content: center;">2</div></div><divclass="swan-card swan-bgc-accent"style="border: 1px solid red; height: 90px; width: 90px;"><divclass="swan-display-flex"style="height: 100%; align-items: center; justify-content: center;">3</div></div><divclass="swan-card swan-bgc-accent"style="border: 1px solid red; height: 90px; width: 90px;"><divclass="swan-display-flex"style="height: 100%; align-items: center; justify-content: center;">4</div></div></div></div>
Align Items
Use alignItems
to align items along the secondary axis, which is the y-axis by default.
The preview has been updated.
<Card bordered><FlexBoxstyle={{ height: 260 }}justifyContent="center"alignItems="flex-end"flexWrap="wrap"flexDirection="row"gap="3"><Cardbgc="accent"style={{ border: '1px solid red', height: 120, width: 90 }}><FlexBoxstyle={{ height: '100%' }}justifyContent="center"alignItems="center">1</FlexBox></Card><Cardbgc="accent"style={{ border: '1px solid red', height: 160, width: 90 }}><FlexBoxstyle={{ height: '100%' }}justifyContent="center"alignItems="center">2</FlexBox></Card><Cardbgc="accent"style={{ border: '1px solid red', height: 90, width: 90 }}><FlexBoxstyle={{ height: '100%' }}justifyContent="center"alignItems="center">3</FlexBox></Card><Cardbgc="accent"style={{ border: '1px solid red', height: 120, width: 90 }}><FlexBoxstyle={{ height: '100%' }}justifyContent="center"alignItems="center">4</FlexBox></Card></FlexBox></Card>
<div class="swan-card swan-card-bordered"><divclass="swan-display-flex"style="height: 260px; align-items: flex-end; flex-flow: wrap; justify-content: center; gap: var(--swan-sem-space-3);"><divclass="swan-card swan-bgc-accent"style="border: 1px solid red; height: 120px; width: 90px;"><divclass="swan-display-flex"style="height: 100%; align-items: center; justify-content: center;">1</div></div><divclass="swan-card swan-bgc-accent"style="border: 1px solid red; height: 160px; width: 90px;"><divclass="swan-display-flex"style="height: 100%; align-items: center; justify-content: center;">2</div></div><divclass="swan-card swan-bgc-accent"style="border: 1px solid red; height: 90px; width: 90px;"><divclass="swan-display-flex"style="height: 100%; align-items: center; justify-content: center;">3</div></div><divclass="swan-card swan-bgc-accent"style="border: 1px solid red; height: 120px; width: 90px;"><divclass="swan-display-flex"style="height: 100%; align-items: center; justify-content: center;">4</div></div></div></div>
Flex Wrap
Use flexWrap
to control whether the items in the Flexbox should wrap to the next line or not.
The preview has been updated.
<Card bordered><FlexBoxstyle={{ height: 260, width: '100%' }}justifyContent="flex-start"alignItems="center"flexWrap="wrap"gap="3"><Cardbgc="accent"style={{ border: '1px solid red', height: 90, width: '30%' }}><FlexBoxstyle={{ height: '100%' }}justifyContent="center"alignItems="center">1</FlexBox></Card><Cardbgc="accent"style={{ border: '1px solid red', height: 90, width: '30%' }}><FlexBoxstyle={{ height: '100%' }}justifyContent="center"alignItems="center">2</FlexBox></Card><Cardbgc="accent"style={{ border: '1px solid red', height: 90, width: '30%' }}><FlexBoxstyle={{ height: '100%' }}justifyContent="center"alignItems="center">3</FlexBox></Card><Cardbgc="accent"style={{ border: '1px solid red', height: 90, width: '30%' }}><FlexBoxstyle={{ height: '100%' }}justifyContent="center"alignItems="center">4</FlexBox></Card></FlexBox></Card>
<div class="swan-card swan-card-bordered"><divclass="swan-display-flex"style="height: 260px; width: 100%; align-items: center; flex-wrap: wrap; justify-content: flex-start; gap: var(--swan-sem-space-3);"><divclass="swan-card swan-bgc-accent"style="border: 1px solid red; height: 90px; width: 30%;"><divclass="swan-display-flex"style="height: 100%; align-items: center; justify-content: center;">1</div></div><divclass="swan-card swan-bgc-accent"style="border: 1px solid red; height: 90px; width: 30%;"><divclass="swan-display-flex"style="height: 100%; align-items: center; justify-content: center;">2</div></div><divclass="swan-card swan-bgc-accent"style="border: 1px solid red; height: 90px; width: 30%;"><divclass="swan-display-flex"style="height: 100%; align-items: center; justify-content: center;">3</div></div><divclass="swan-card swan-bgc-accent"style="border: 1px solid red; height: 90px; width: 30%;"><divclass="swan-display-flex"style="height: 100%; align-items: center; justify-content: center;">4</div></div></div></div>
Flex Direction
Use flexDirection
to control whether the items in the Flexbox are laid out in a row or column; this also switches the primary and secondary axis.
The preview has been updated.
<GridContainer><Row><Column span={6}><Card bordered><FlexBoxstyle={{ height: 360 }}justifyContent="center"alignItems="center"flexWrap="wrap"flexDirection="row"gap="3"><Cardbgc="accent"style={{ border: '1px solid red', height: 90, width: 120 }}><FlexBoxstyle={{ height: '100%' }}justifyContent="center"alignItems="center">1</FlexBox></Card><Cardbgc="accent"style={{ border: '1px solid red', height: 90, width: 160 }}><FlexBoxstyle={{ height: '100%' }}justifyContent="center"alignItems="center">2</FlexBox></Card><Cardbgc="accent"style={{ border: '1px solid red', height: 90, width: 120 }}><FlexBoxstyle={{ height: '100%' }}justifyContent="center"alignItems="center">3</FlexBox></Card></FlexBox></Card></Column><Column span={6}><Card bordered><FlexBoxstyle={{ height: 360 }}justifyContent="center"alignItems="center"flexWrap="wrap"flexDirection="column"gap="3"><Cardbgc="accent"style={{ border: '1px solid red', height: 90, width: 120 }}><FlexBoxstyle={{ height: '100%' }}justifyContent="center"alignItems="center">1</FlexBox></Card><Cardbgc="accent"style={{ border: '1px solid red', height: 90, width: 160 }}><FlexBoxstyle={{ height: '100%' }}justifyContent="center"alignItems="center">2</FlexBox></Card><Cardbgc="accent"style={{ border: '1px solid red', height: 90, width: 120 }}><FlexBoxstyle={{ height: '100%' }}justifyContent="center"alignItems="center">3</FlexBox></Card></FlexBox></Card></Column></Row></GridContainer>
<div class="swan-grid-container"><div class="swan-row"><div class="swan-col-6"><div class="swan-card swan-card-bordered"><divclass="swan-display-flex"style="height: 360px; align-items: center; flex-flow: wrap; justify-content: center; gap: var(--swan-sem-space-3);"><divclass="swan-card swan-bgc-accent"style="border: 1px solid red; height: 90px; width: 120px;"><divclass="swan-display-flex"style="height: 100%; align-items: center; justify-content: center;">1</div></div><divclass="swan-card swan-bgc-accent"style="border: 1px solid red; height: 90px; width: 160px;"><divclass="swan-display-flex"style="height: 100%; align-items: center; justify-content: center;">2</div></div><divclass="swan-card swan-bgc-accent"style="border: 1px solid red; height: 90px; width: 120px;"><divclass="swan-display-flex"style="height: 100%; align-items: center; justify-content: center;">3</div></div></div></div></div><div class="swan-col-6"><div class="swan-card swan-card-bordered"><divclass="swan-display-flex"style="height: 360px; align-items: center; flex-flow: column wrap; justify-content: center; gap: var(--swan-sem-space-3);"><divclass="swan-card swan-bgc-accent"style="border: 1px solid red; height: 90px; width: 120px;"><divclass="swan-display-flex"style="height: 100%; align-items: center; justify-content: center;">1</div></div><divclass="swan-card swan-bgc-accent"style="border: 1px solid red; height: 90px; width: 160px;"><divclass="swan-display-flex"style="height: 100%; align-items: center; justify-content: center;">2</div></div><divclass="swan-card swan-bgc-accent"style="border: 1px solid red; height: 90px; width: 120px;"><divclass="swan-display-flex"style="height: 100%; align-items: center; justify-content: center;">3</div></div></div></div></div></div></div>
Gap
Use gap
to put a gutter between the items in the Flexbox. This accepts one of the semantic space units as values. Note that this controls the inline gap property in the style attribute, so you cannot set the gap via style
.
The preview has been updated.
<Card bordered><FlexBoxstyle={{ height: 260 }}justifyContent="center"alignItems="center"flexWrap="wrap"flexDirection="row"gap="8"><Cardbgc="accent"style={{ border: '1px solid red', height: 120, width: 90 }}><FlexBoxstyle={{ height: '100%' }}justifyContent="center"alignItems="center">1</FlexBox></Card><Cardbgc="accent"style={{ border: '1px solid red', height: 160, width: 90 }}><FlexBoxstyle={{ height: '100%' }}justifyContent="center"alignItems="center">2</FlexBox></Card><Cardbgc="accent"style={{ border: '1px solid red', height: 90, width: 90 }}><FlexBoxstyle={{ height: '100%' }}justifyContent="center"alignItems="center">3</FlexBox></Card><Cardbgc="accent"style={{ border: '1px solid red', height: 120, width: 90 }}><FlexBoxstyle={{ height: '100%' }}justifyContent="center"alignItems="center">4</FlexBox></Card></FlexBox></Card>
<div class="swan-card swan-card-bordered"><divclass="swan-display-flex"style="height: 260px; align-items: center; flex-flow: wrap; justify-content: center; gap: var(--swan-sem-space-8);"><divclass="swan-card swan-bgc-accent"style="border: 1px solid red; height: 120px; width: 90px;"><divclass="swan-display-flex"style="height: 100%; align-items: center; justify-content: center;">1</div></div><divclass="swan-card swan-bgc-accent"style="border: 1px solid red; height: 160px; width: 90px;"><divclass="swan-display-flex"style="height: 100%; align-items: center; justify-content: center;">2</div></div><divclass="swan-card swan-bgc-accent"style="border: 1px solid red; height: 90px; width: 90px;"><divclass="swan-display-flex"style="height: 100%; align-items: center; justify-content: center;">3</div></div><divclass="swan-card swan-bgc-accent"style="border: 1px solid red; height: 120px; width: 90px;"><divclass="swan-display-flex"style="height: 100%; align-items: center; justify-content: center;">4</div></div></div></div>
Stack/Inline
Use Flexbox to emulate the functionality of these legacy Emu components:
- For Stack, use a Flexbox with
flexDirection="column"
, plus agap
property to put a gutter between the children. - For Inline, SWAN usually uses the Grid component instead for horizontal layout, to provide the site-standard spacing between the columns and to create visual harmony from page to page. However, for smaller spaces or unusual layouts, use a Flexbox with with
flexDirection="row"
and agap
.