Skip to content

Spacer

A flexible spacing component.

The Spacer component is used to create space between elements or push elements apart. By default, it grows to fill available space using flex: 1. It can be used in both horizontal (Row) and vertical (Column) layouts.

Usage

tsx
import { Row, Text, Spacer } from 'flexium/primitives';

function App() {
  return (
    <Row>
      <Text>Left</Text>
      <Spacer />
      <Text>Right</Text>
    </Row>
  );
}

Fixed Size Spacer

tsx
import { Column, Text, Spacer } from 'flexium/primitives';

function App() {
  return (
    <Column>
      <Text>Top</Text>
      <Spacer size={20} />
      <Text>Bottom</Text>
    </Column>
  );
}

Explicit Dimensions

tsx
import { Row, Spacer } from 'flexium/primitives';

function App() {
  return (
    <Row>
      <Spacer width={100} height={50} backgroundColor="lightblue" />
    </Row>
  );
}

Props

PropTypeDefaultDescription
sizeResponsiveValue<number | string>-Size on main axis (width for Row, height for Column). When specified, creates a fixed-size spacer.
widthResponsiveValue<number | string>-Explicit width of the spacer.
heightResponsiveValue<number | string>-Explicit height of the spacer.
flexResponsiveValue<number>1Flex grow factor. Defaults to 1 if no size specified.
asstring'div'HTML element to render.
classNamestring-CSS class name.
styleobject-Additional styles.

All BaseComponentProps are also supported, including spacing, sizing, and visual properties.

Behavior

The Spacer component adapts its behavior based on the props provided:

  1. No props: Acts as a flexible spacer with flex: 1, growing to fill available space
  2. With size prop: Creates a fixed-size spacer on the main axis
  3. With width or height: Creates a spacer with explicit dimensions
  4. With flex prop: Controls the grow factor for flexible spacing

Cross-Platform Notes

  • Web: Renders as a div element with flexbox properties
  • Canvas: Spacer behavior is handled through layout calculations in the canvas renderer

Released under the MIT License.