Flex
Compose elements in a flex container.
Import
import { Flex } from '@tidbcloud/uikit'Usage
import { Flex, Button } from '@tidbcloud/uikit'
function Demo() {
return (
<Flex mih={50} bg="rgba(0, 0, 0, .3)" gap="md" justify="center" align="center" direction="row" wrap="wrap">
<Button>Button 1</Button>
<Button>Button 2</Button>
<Button>Button 3</Button>
</Flex>
)
}Supported props
Flex component supports the following props:
gap– gap between elements, key oftheme.spacingor number valuerowGap– row gap, key oftheme.spacingor number valuecolumnGap– column gap, key oftheme.spacingor number valuealign–align-itemsCSS propertyjustify–justify-contentCSS propertywrap–flex-wrapCSS propertydirection–flex-directionCSS property
Responsive props
All Flex props support responsive values:
import { Flex, Button } from '@tidbcloud/uikit'
function Demo() {
return (
<Flex direction={{ base: 'column', sm: 'row' }} gap={{ base: 'sm', sm: 'lg' }} justify={{ sm: 'center' }}>
<Button>Button 1</Button>
<Button>Button 2</Button>
<Button>Button 3</Button>
</Flex>
)
}Difference from Group and Stack
Flex component is a more general alternative to Group and Stack components:
GroupisFlexwithdirection="row"and some additional features (children positioning based onjustifyprop)StackisFlexwithdirection="column"
Use Flex when you need more control over flex properties or when you need responsive direction changes.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| gap | MantineSpacing | - | Gap between elements |
| rowGap | MantineSpacing | - | Row gap |
| columnGap | MantineSpacing | - | Column gap |
| align | CSS align-items | - | Align items |
| justify | CSS justify-content | - | Justify content |
| wrap | CSS flex-wrap | ’nowrap’ | Flex wrap |
| direction | CSS flex-direction | ’row’ | Flex direction |