Flex
import { Button, Flex } from "@cherry-design-system/react";
export function Actions() {
return (
<Flex gap={3} align="center">
<Button variant="outline">Cancel</Button>
<Button>Save</Button>
</Flex>
);
}Flex lays out its children with flexbox, and every layout prop can change per breakpoint. Stack is a vertical Flex that does not wrap, for form fields and lists of blocks. Use Grid when you want equal columns.
Examples
Stack
Stack defaults to direction="column", wrap="nowrap" and gap={4} (16px). Every Flex prop still works and overrides those defaults.
import { Stack, Field, Input } from "@cherry-design-system/react";
export function ProfileForm() {
return (
<Stack gap={4}>
<Field label="Name">
<Input name="name" />
</Field>
<Field label="Email">
<Input name="email" type="email" />
</Field>
</Stack>
);
}Responsive direction
Pass an object keyed by breakpoint (xs, sm, md, lg, xl, xxl, xxxl). Values are mobile first and hold until a larger breakpoint overrides them.
import { Flex } from "@cherry-design-system/react";
export function Split() {
return (
<Flex direction={{ xs: "column", md: "row" }} justify="space-between" gap={{ xs: 4, lg: 8 }}>
<div>Summary</div>
<div>Details</div>
</Flex>
);
}Inline and full width
inline switches to display: inline-flex. fullWidth stretches the row to the width of its container.
import { Flex } from "@cherry-design-system/react";
export function Toolbar() {
return (
<Flex fullWidth justify="space-between" align="center" wrap="nowrap">
<span>3 selected</span>
<span>Page 1</span>
</Flex>
);
}Properties
Main axis. Defaults to "row" ("column" on Stack).
Alignment along the main axis. Defaults to "flex-start".
Alignment across the main axis. Defaults to "stretch".
Wrapping. Defaults to "wrap" as in cherry 1.x ("nowrap" on Stack).
Gap as a spacing step: 0, 1, 2, 3, 4, 5, 6, 8, 10, 12, 16, 20 or 24. Defaults to the gutter (20px, 40px from lg), or 4 (16px) on Stack.
Use display: inline-flex.
Stretch to the container width.
Flex and Stack render a <div>, forward their ref to it and pass every other <div> attribute through. Both are safe in Server Components.
Styling
| Hook | Values |
|---|---|
| Class | cherry-flex (Stack renders the same class) |
| States | data-inline, data-full-width |
The default gap reads --cherry-gutter-mobile and --cherry-gutter-desktop. Spacing steps map to --cherry-space-<step>.
Accessibility
Flex is layout only and has no role. Keep the DOM order the reading order: do not use direction (such as row-reverse) to reorder content in a way that breaks it.