Flex

A Flexbox container with explicit direction, alignment, wrapping, and gap.

VerifiedSince 0.3.4

Usage

Basic

Loading demo...

Wrapping Toolbar

wrap="wrap" lets a toolbar wrap in a narrow container.

<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 TxFlex when you need exact Flexbox semantics, and TxStack for everyday horizontal or vertical rhythm.
  • Space children with gap, not margins on the children.
  • The container adds no roles or keyboard behavior; leave interaction to semantic child controls.
  • Lay out repeated cards with TxGridLayout, not nested flex rows.

API Reference

Props

PropTypeDefaultDescription
direction'row' | 'row-reverse' | 'column' | 'column-reverse''row'Main-axis direction.
gapnumber | string12Gap between children; numbers are px, strings pass through.
alignstring'stretch'align-items; accepts any CSS value. Use center for icon-and-label rows.
justifystring'flex-start'justify-content; accepts any CSS value.
wrap'nowrap' | 'wrap' | 'wrap-reverse''nowrap'flex-wrap.
inlinebooleanfalseUses inline-flex.

Slots

SlotPropsDescription
default-Flex children.

CSS Variables

VariableSourceDescription
--tx-flex-gapgapCSS gap.
--tx-flex-alignalignalign-items.
--tx-flex-justifyjustifyjustify-content.
--tx-flex-directiondirectionflex-direction.
--tx-flex-wrapwrapflex-wrap.
--tx-flex-displayinlineflex or inline-flex.

Overview

  • The root is a div with min-width: 0, so children can shrink inside constrained containers.
  • Props write the --tx-flex-* variables on the root, and the stylesheet reads them.
  • Empty align, justify, direction, or wrap values fall back to the defaults.

Technologies

  • Source: packages/tuffex/packages/components/src/flex/.
查看源码
packages/tuffex/packages/components/src/flex/index.ts