Flex
Flex arranges inline or wrapping content with a small layout API.
@duskmoon-dev/components/flex Usage
When to use
- Use it to build predictable page, toolbar, panel, or grid structure.
- Keep layout primitives responsible for geometry and let child components own behavior.
Implementation notes
Features
Documents spacing, responsive behavior, and nested regions used to build larger screens.
Examples keep predictable dimensions so the surrounding UI does not jump while content changes.
Flex is most often configured through `component`, `vertical`, `wrap`, `justify`.
Renders children with default class
Feature Demos
Feature demos are authored for the component page, then supplemented with behavior scenarios from the component test coverage.
Basic usage
Import the component stylesheet and Flex from its package subpath, then render it with the core props.
import "@duskmoon-dev/components/styles.css";
import { Flex } from "@duskmoon-dev/components/flex";
export function Example() {
return (<Flex gap="middle" wrap align="center">
<span>Alpha</span>
<span>Beta</span>
<span>Gamma</span>
</Flex>);
} Renders children with default class
test-backedFlex scenario from the component test coverage: renders children with default class.
import "@duskmoon-dev/components/styles.css";
import { Flex } from "@duskmoon-dev/components/flex";
export function FlexRendersChildrenWithDefaultDemo() {
return (<Flex gap="middle" wrap align="center">
<span>Alpha</span>
<span>Beta</span>
<span>Gamma</span>
</Flex>);
} Supports gap, justify, and align
test-backedFlex scenario from the component test coverage: supports gap, justify, and align.
import "@duskmoon-dev/components/styles.css";
import { Flex } from "@duskmoon-dev/components/flex";
export function FlexSupportsGapJustifyAndDemo() {
return (<Flex gap="middle" wrap align="center">
<span>Alpha</span>
<span>Beta</span>
<span>Gamma</span>
</Flex>);
} Supports vertical and wrap
test-backedFlex scenario from the component test coverage: supports vertical and wrap.
import "@duskmoon-dev/components/styles.css";
import { Flex } from "@duskmoon-dev/components/flex";
export function FlexSupportsVerticalAndWrapDemo() {
return (<Flex gap="middle" wrap align="center">
<span>Alpha</span>
<span>Beta</span>
<span>Gamma</span>
</Flex>);
} Forwards root ref
test-backedFlex scenario from the component test coverage: forwards root ref.
import "@duskmoon-dev/components/styles.css";
import { Flex } from "@duskmoon-dev/components/flex";
export function FlexForwardsRootRefDemo() {
return (<Flex gap="middle" wrap align="center">
<span>Alpha</span>
<span>Beta</span>
<span>Gamma</span>
</Flex>);
} Theme aware
Docs previews inherit the DuskMoon data-theme value. Use the header switch to compare light and dark rendering.
<div data-theme="sunshine">
<Flex gap="middle" wrap align="center">
<span>Alpha</span>
<span>Beta</span>
<span>Gamma</span>
</Flex>
</div>
<div data-theme="moonlight">
<Flex gap="middle" wrap align="center">
<span>Alpha</span>
<span>Beta</span>
<span>Gamma</span>
</Flex>
</div> API
The API reference below lists every parsed exported type or interface for Flex. Start with `component`, `vertical`, `wrap`, `justify` for common usage.
packages/components/src/components/flex/Flex.types.ts
Scenarios: packages/components/src/components/flex/Flex.test.tsx | Prop | Type | Required | Description |
|---|---|---|---|
component | ElementType | No | component configures Flex. |
vertical | boolean | No | vertical configures Flex. |
wrap | boolean | React.CSSProperties["flexWrap"] | No | wrap configures Flex. |
justify | FlexJustify | No | justify configures Flex. |
align | FlexAlign | No | align configures Flex. |
gap | FlexGap | [FlexGap, FlexGap] | No | gap configures Flex. |
flex | React.CSSProperties["flex"] | No | flex configures Flex. |
| "normal" | "start" | "end" | "center" | "space-between" | "space-around" | "space-evenly" | "normal" | "start" | "end" | "center" | "baseline" | "stretch" "small" | "middle" | "large" | number