Flex
General-purpose flex container — direction, align, justify, wrap, gap, plus grow/shrink/basis as props. The escape hatch when Stack/Inline don't quite fit.
Plain <div> by default (polymorphic via as). No semantics beyond what the children carry; pair with <nav>, <main>, <header> via as when the flex container is itself a landmark.
import { Box, Flex } from '@arshad-shah/cynosure-react';
export default function Example() {
return (
<Flex
direction="row"
gap="3"
justify="between"
align="center"
padding="4"
background="bg.subtle"
borderRadius="md"
>
<Box padding="3" background="bg.surface" borderRadius="sm">
Left
</Box>
<Box padding="3" background="bg.surface" borderRadius="sm">
Middle
</Box>
<Box padding="3" background="bg.surface" borderRadius="sm">
Right
</Box>
</Flex>
);
}
Direction
Section titled “Direction”direction accepts row (default), column, and the matching *-reverse variants. All four accept a responsive map — a common pattern is direction={{ base: 'column', md: 'row' }} for “stack on mobile, side-by-side on desktop”.
import { Box, Flex } from '@arshad-shah/cynosure-react';
export default function Example() {
return (
<Flex
direction={{ base: 'column', md: 'row' }}
gap="3"
padding="4"
background="bg.subtle"
borderRadius="md"
>
<Box padding="3" background="bg.surface" borderRadius="sm" flex="1">
Stacks on narrow viewports
</Box>
<Box padding="3" background="bg.surface" borderRadius="sm" flex="1">
Sits side-by-side from `md` up
</Box>
</Flex>
);
}
Grow, shrink, basis
Section titled “Grow, shrink, basis”The grow, shrink, and basis props are flex-item hints. They apply to the child Boxes (Box, Stack, Inline, Flex, Grid all forward these), letting a child claim or yield space inside a Flex parent without writing custom CSS.
import { Box, Flex } from '@arshad-shah/cynosure-react';
export default function Example() {
return (
<Flex gap="3" padding="4" background="bg.subtle" borderRadius="md">
<Box padding="3" background="bg.surface" borderRadius="sm">
Fixed
</Box>
<Box padding="3" background="bg.surface" borderRadius="sm" flex="1">
Grows to fill remaining space
</Box>
<Box padding="3" background="bg.surface" borderRadius="sm">
Fixed
</Box>
</Flex>
);
}
Recipes
Section titled “Recipes”- For most row/column layouts prefer
InlineorStack— they’reFlexwith fewer knobs and clearer intent. - “Stack on mobile, side-by-side on desktop”:
<Flex direction={{ base: 'column', md: 'row' }} gap="4" />. - App shell main area:
<Flex direction="column" flex="1" minHeight="0" />so a nested scroll area can claim the remaining height.