CxJS

FlexBox

import { FlexBox, FlexRow, FlexCol } from 'cx/widgets'; Copied

FlexBox is a convenience widget for setting up simple flex-box based layouts. It provides shortcut options for justifying, aligning, and adding spacing to content.

Note

FlexBox predates Tailwind CSS and is rarely used when Tailwind is available. Consider using Tailwind’s flex utilities instead.

Instead of using the base FlexBox component, you’ll typically use one of the following shortcut variants:

ComponentEquivalent
FlexRowFlexBox with direction="row"
FlexColFlexBox with direction="column"
<FlexCol spacing="large">
  <div>
    <strong>spacing</strong>
    <FlexRow spacing style="border: 1px dotted lightgray">
      <div style="width: 30px; height: 30px; background: lightgray" />
      <div style="width: 40px; height: 40px; background: lightgray" />
      <div style="width: 50px; height: 50px; background: lightgray" />
    </FlexRow>
  </div>
  <div>
    <strong>justify="center"</strong>
    <FlexRow spacing justify="center" style="border: 1px dotted lightgray">
      <div style="width: 30px; height: 30px; background: lightgray" />
      <div style="width: 40px; height: 40px; background: lightgray" />
      <div style="width: 50px; height: 50px; background: lightgray" />
    </FlexRow>
  </div>
  <div>
    <strong>align="center" justify="end"</strong>
    <FlexRow
      spacing
      align="center"
      justify="end"
      style="border: 1px dotted lightgray"
    >
      <div style="width: 30px; height: 30px; background: lightgray" />
      <div style="width: 40px; height: 40px; background: lightgray" />
      <div style="width: 50px; height: 50px; background: lightgray" />
    </FlexRow>
  </div>
  <div>
    <strong>wrap pad</strong>
    <FlexRow pad spacing wrap style="border: 1px dotted lightgray">
      {Array.from({ length: 16 }).map((_, i) => (
        <div key={i} style="width: 30px; height: 30px; background: lightgray" />
      ))}
    </FlexRow>
  </div>
</FlexCol>
spacing
justify="center"
align="center" justify="end"
wrap pad
Warning

The spacing option sets a negative margin which may cause unexpected behavior in some scenarios.

Configuration

PropertyTypeDescription
directionstringFlex direction. Default is row. Other values: column, column-reverse, row-reverse.
spacingstring | booleanAdd spacing between items. Values: xsmall, small, medium, large, xlarge. true = medium.
hspacingstring | booleanHorizontal spacing between items. Same values as spacing.
vspacingstring | booleanVertical spacing between items. Same values as spacing.
padstring | booleanAdd padding to the box. Values: xsmall, small, medium, large, xlarge. true = medium.
hpadstring | booleanHorizontal padding. Same values as pad.
vpadstring | booleanVertical padding. Same values as pad.
alignstringAlignment of items. Maps to CSS align-items. Default is stretch.
justifystringSpace distribution. Maps to CSS justify-content. Default is flex-start.
wrapbooleanSet to true to allow content to wrap.
targetstringTarget screen size. Values: any, tablet, desktop. On smaller screens, flexbox breaks into rows.
nestedbooleanSet to true for deeply nested flexbox calculations.
baseClassstringBase CSS class. Default is flexbox.