Components

Spacer

Distribute unused space along a stack’s main axis.

Example

Requires React 18.2+ or 19 and shared styles. See setup.

Default

Loading preview…

Code
'use client';
import { HStack, Text } from '@swiftuijs/ui';
import { Spacer } from '@swiftuijs/ui';
export default function Example() {
    return ((<HStack style={{ width: '100%' }}>
      <Text>Left</Text>
      <Spacer />
      <Text>Right</Text>
    </HStack>));
}

In HStack

Use Spacer to push content to edges:

With Minimum Length

Set a minimum length for the spacer:

Multiple Spacers

Use multiple spacers for complex layouts:

Leading Spacer

Push content to the trailing edge:

Trailing Spacer

Push content to the leading edge:

Usage and limitations

  • Expands horizontally in HStack and vertically in VStack. Multiple spacers share the remaining space equally.
  • minLength sets a minimum; the parent needs available space, supplied by explicit dimensions or its layout.
  • Use it for flexible separation, and check narrow containers so minimum lengths do not crowd content.

More examples

In HStack
In VStack
With Minimum Length
Multiple Spacers
Leading Spacer
Trailing Spacer
Complex Layout

API reference

PropTypeRequiredDescription
minLengthnumber | stringNoThe minimum length of the spacer, in pixels or as a CSS value string. Default: 0

Inherits additional props from Omit<IBaseComponent, 'children'>.