Flex
A low-level Flexbox container with explicit direction, alignment, wrapping, and gap controls.
Usage
Loading demo...
Wrapping Toolbar
<template>
<TxFlex align="center" justify="space-between" wrap="wrap" gap="0.75rem">
<TxFlex align="center" gap="0.5rem" wrap="wrap">
<TxTag label="Docs" />
<TxTag label="Reviewed" color="var(--tx-color-success)" />
</TxFlex>
<TxButton size="sm">Publish</TxButton>
</TxFlex>
</template>
Reverse Direction
<template>
<TxFlex direction="row-reverse" align="center" gap="8px">
<TxButton variant="primary">Primary</TxButton>
<TxButton variant="ghost">Secondary</TxButton>
</TxFlex>
</template>
Best Practices
- Use
TxFlexwhen you need exact Flexbox semantics. UseTxStackfor common horizontal/vertical rhythm. - Use
wrap="wrap"on toolbars and filter rows that must survive narrow containers. - Keep
gapresponsible for spacing; avoid margin hacks on child components. - Prefer semantic child controls (
TxButton, links, form controls) insideTxFlex; the container itself does not add roles or keyboard behavior. - For grid-like repeated cards, use
TxGridLayoutinstead of nested flex rows.
API Reference
Props
| Prop | Type | Default | Description |
|---|---|---|---|
direction | 'row' | 'row-reverse' | 'column' | 'column-reverse' | 'row' | Main-axis direction; row lays children out horizontally, column stacks them vertically. |
gap | number | string | 12 | Gap between children. Numbers become px. |
align | string | 'stretch' | Cross-axis alignment (align-items); use center for icon+label rows and keep stretch when children should share the tallest height. Typed as a free string, so any CSS keyword is accepted. |
justify | string | 'flex-start' | Main-axis distribution (justify-content); space-between pushes items apart, flex-start groups them at the start. Also a free string. |
wrap | 'nowrap' | 'wrap' | 'wrap-reverse' | 'nowrap' | Whether children wrap; use wrap for toolbars and filter rows that must survive narrow containers. |
inline | boolean | false | Use inline-flex instead of block-level flex. |
Slots
| Slot | Props | Description |
|---|---|---|
default | - | Flex children. |
Events
No public events are emitted.
Exposed Methods
No public instance methods are exposed.
CSS Variables
| Variable | Source | Description |
|---|---|---|
--tx-flex-gap | gap | CSS gap. |
--tx-flex-align | align | align-items. |
--tx-flex-justify | justify | justify-content. |
--tx-flex-direction | direction | flex-direction. |
--tx-flex-wrap | wrap | flex-wrap. |
--tx-flex-display | inline | flex or inline-flex. |
Overview
- The root is a
divwithdisplay: flexby default. direction,wrap,align, andjustifyare passed directly through to Flexbox CSS variables.- Numeric
gapvalues become px; string values are passed through unchanged. inline=trueswitches display fromflextoinline-flex.- Empty
align,justify,direction, orwrapvalues fall back to the component defaults when computed. - The root sets
min-width: 0so children can shrink inside constrained cards.
Technologies
- Reviewed against
packages/tuffex/packages/components/src/flex/src/types.ts,TxFlex.vue, andflex.test.ts. TxFlexis intentionally behaviorless: it adds no role, events, or focus handling beyond the slotted children.- Numeric
gapis normalized to pixels; string gap values remain caller-owned CSS. - Component source:
packages/tuffex/packages/components/src/flex/src/TxFlex.vue. - Types:
packages/tuffex/packages/components/src/flex/src/types.ts. - Verified coverage: Coverage:
packages/tuffex/packages/components/src/flex/__tests__/flex.test.tsverifies default CSS variables and slot content, custom layout variable forwarding, inline display, and numeric gap normalization.
查看源码
packages/tuffex/packages/components/src/flex/index.ts