Layout & primitives
Flex
Free1.8 KB gzippedFull flexbox container: direction (fixed or responsive), wrapping, alignment on both axes, line distribution, and token-based gaps.
Accessibility: WCAG 2.2 AA · No A or AA violations in light or dark mode · No keyboard interaction of its own · Full report
Import
import { Flex } from "@vjdesigns/vjdesigns-ui";
Importing only Flex adds about 1.8 KB of minified, gzipped JavaScript to your app (React not included). The stylesheet is shared by every component and loaded once: 75.1 KB gzipped.
Examples
Alignment
Props map to flexbox, with spacing steps for gap.
Jordan Lee
jordan@example.com
import { Avatar, Badge, Box, Flex, Text } from "@vjdesigns/vjdesigns-ui";
export function Alignment() {
return (
<Flex justify="between" align="center" gap={4} wrap="wrap" style={{ width: "100%", maxWidth: "30rem" }}>
<Flex align="center" gap={3}>
<Avatar name="Jordan Lee" colorFromName />
<Box>
<Text weight="semibold">Jordan Lee</Text>
<Text size="sm" tone="muted">
jordan@example.com
</Text>
</Box>
</Flex>
<Badge tone="success">Owner</Badge>
</Flex>
);
}
Responsive
Any layout prop takes one value per breakpoint. This row stacks on narrow screens.
grow
auto
import { Box, Button, Flex, Text } from "@vjdesigns/vjdesigns-ui";
export function Responsive() {
return (
<Flex direction={{ base: "column", sm: "row" }} gap={{ base: 2, sm: 4 }} style={{ width: "100%" }}>
<Flex.Item grow>
<Box tone="primary" radius="md" p={4}>
<Text weight="semibold" tone="inherit">
grow
</Text>
</Box>
</Flex.Item>
<Box tone="neutral" radius="md" p={4}>
<Text weight="semibold" tone="inherit">
auto
</Text>
</Box>
<Button>Action</Button>
</Flex>
);
}
Accessibility
Keep the visual order the same as the source order (SC 1.3.2 and 2.4.3): keyboard and screen reader users follow the source. Place items with justify and align rather than order or reversed directions.
Total
$42.00
import { Box, Button, Flex, Text } from "@vjdesigns/vjdesigns-ui";
export function Accessibility() {
return (
<Box border radius="lg" p={4} style={{ width: "100%", maxWidth: "24rem" }}>
<Flex justify="between" align="center">
<Text>Total</Text>
<Text weight="bold">$42.00</Text>
</Flex>
<Flex justify="end" gap={2} style={{ marginTop: "1rem" }}>
<Button variant="ghost" tone="neutral">
Back
</Button>
<Button>Pay</Button>
</Flex>
</Box>
);
}
Translated
In Arabic a row runs right to left on its own: the first item sits on the right and justify="end" means the left edge. The DOM order stays the same, so reading order does too.
الإجمالي
42.00 $
import {
Box,
Button,
Flex,
Text,
LocaleProvider,
} from "@vjdesigns/vjdesigns-ui";
import ar from "@vjdesigns/vjdesigns-ui/locales/ar";
export function Translated() {
return (
<LocaleProvider locale="ar" messages={ar}>
<Box border radius="lg" p={4} style={{ width: "100%", maxWidth: "24rem" }}>
<Flex justify="between" align="center">
<Text>الإجمالي</Text>
<Text weight="bold">42.00 $</Text>
</Flex>
<Flex justify="end" gap={2} style={{ marginTop: "1rem" }}>
<Button variant="ghost" tone="neutral">
رجوع
</Button>
<Button>ادفع</Button>
</Flex>
</Box>
</LocaleProvider>
);
}
Usage notes
Use Stack for the common case of evenly spaced children in one direction. Reach for Flex when you need real flexbox control: justify="between" toolbars, wrapping chip rows, reversing order, direction that flips at a breakpoint, or per-child sizing via Flex.Item.
Purely presentational: it adds no role or keyboard behavior. Pick a semantic element with as (ul, nav, header, ...) when the group has meaning. Reverse directions change only the visual order, not the reading or tab order, so keep DOM order meaningful (WCAG 1.3.2, 2.4.3).
API reference
Flex
| Prop | Type | Default |
|---|---|---|
asElement or component to render as. Native props follow the chosen element. Defaults to | ElementType | — |
directionMain axis ( | FlexResponsive<FlexDirection> | — |
wrapWhether items wrap onto new lines ( | FlexResponsive<FlexWrap> | — |
alignCross-axis alignment of items ( | FlexResponsive<FlexAlign> | — |
justifyMain-axis distribution of items ( | FlexResponsive<FlexJustify> | — |
alignContentDistribution of wrapped lines ( | FlexResponsive<FlexAlignContent> | — |
gapGap between items on both axes, as a | FlexResponsive<Space> | — |
rowGapGap between rows (lines), as a | FlexResponsive<Space> | — |
columnGapGap between columns (items in a row), as a | FlexResponsive<Space> | — |
inlineRender as | boolean | — |
fullWidthStretch to the full width of the container. | boolean | — |
childrenFlex items. | ReactNode | — |
Flex.Item
A child of Flex with its own sizing (grow, shrink, basis), order, and alignSelf. Only the properties you pass are applied, so an item with no props behaves like a plain child. Also available as Flex.Item.
| Prop | Type | Default |
|---|---|---|
asElement or component to render as. Native props follow the chosen element. Defaults to | ElementType | — |
growShare of free space to take ( | boolean | number | — |
shrinkShare of overflow to give up ( | boolean | number | — |
basisStarting size before growing or shrinking ( | string | number | — |
orderVisual order ( | number | — |
alignSelfCross-axis alignment for this item only ( | "auto""start""center""end""stretch""baseline" | — |
childrenItem content. | ReactNode | — |
See what changed in each version in the Changelog.
Accessibility report
Flex targets WCAG 2.2 AA. Below: a live axe-core audit of this page's examples, Lighthouse scores for the page in both modes, the accessibility behavior built into the component, and the checks only a person can do.
axe-core audit (live)
Checking the examples above…
Lighthouse audit
Light mode
Score 10035 passed · 0 failed · 30 not applicable · 10 to check by hand
Dark mode
Score 10035 passed · 0 failed · 30 not applicable · 10 to check by hand
Lighthouse 13.5.0 audits the whole docs page (header and sidebar included), not just the examples, in English. Last run 11/27/2026. Some failed audits carry no weight in the score, so a page can score 100 and still list one.
Built-in behavior
Keyboard
Not focusable, so there's no keyboard interaction of its own.
Roles and states
| Element | Role | States and properties |
|---|---|---|
<div>, or the element in as | Native role of that element | — |
Manual checks
Automated tools find roughly a third of accessibility issues. Test these in your app, with your content.
| Check | What to test | WCAG 2.2 |
|---|---|---|
| Keyboard | Every action works with Tab, Shift+Tab, Enter, Space and the arrow keys, and focus never gets stuck. | 2.1.1 (A), 2.1.2 (A) |
| Focus | Focus moves in a logical order, is always visible, and isn't hidden behind sticky headers. | 2.4.3 (A), 2.4.7 (AA), 2.4.11 (AA), 2.4.13 (AAA) |
| Screen readers | Names, roles and states are announced correctly, and status changes are announced without moving focus. | 1.3.1 (A), 4.1.2 (A), 4.1.3 (AA) |
| Color | Meaning never depends on color alone; your own colors meet contrast in both modes. | 1.4.1 (A), 1.4.3 (AA), 1.4.11 (AA), 1.4.6 (AAA) |
| Zoom and reflow | At 200% text size and at 320px wide (400% zoom), nothing is cut off and no sideways scrolling is needed. | 1.4.4 (AA), 1.4.10 (AA), 1.4.12 (AA) |
| Pointer targets | Click and tap targets are at least 24×24px (44×44px for AAA), or spaced so they don't overlap. | 2.5.8 (AA), 2.5.5 (AAA) |
| Motion | Animations respect the reduced-motion setting. | 2.3.3 (AAA) |