import { BreakpointScope, Stack, Text, TextField, useBreakpoints } from "@vortexlabs/vortex-native";
const NameFields = () => {
const layout = useBreakpoints({ xs: "Stacked fields", sm: "Side-by-side fields" });
return (
<Stack gap={2}>
<Text color="subtle">{layout}</Text>
<Stack direction={{ xs: "column", sm: "row" }} gap={2}>
<Stack.Item grow>
<TextField.Root>
<TextField.Label>First name</TextField.Label>
<TextField.Input name="firstName" placeholder="Ada" />
</TextField.Root>
</Stack.Item>
<Stack.Item grow>
<TextField.Root>
<TextField.Label>Last name</TextField.Label>
<TextField.Input name="lastName" placeholder="Lovelace" />
</TextField.Root>
</Stack.Item>
</Stack>
</Stack>
);
};
export const PaneComparison = () => (
<Stack width={320} maxWidth="100%" gap={4}>
<Stack gap={2}>
<Text weight="semibold">Window breakpoint</Text>
<NameFields />
</Stack>
<BreakpointScope style={{ width: "100%" }}>
<Stack gap={2}>
<Text weight="semibold">Pane breakpoint</Text>
<NameFields />
</Stack>
</BreakpointScope>
</Stack>
);Features
- Resolves responsive props and useBreakpoints from the pane’s measured width.
- Updates as the pane resizes and keeps its children mounted.
- Lets nested panes resolve their breakpoints independently.
Container Width
Wrap the part of the screen that needs to fit its own pane. Use style to size the measured view or let it fill a pane your layout already sizes.
Both forms above have the same available width. With the bundled themes, on a window at least 600pt wide and 480pt tall, the first form places its fields side by side. The scoped form stays stacked until its measured width reaches 600pt.
Change Pane width in the props panel to compare them. The preview caps the requested width at the available space.
Nested Scopes
Each scope resolves its own breakpoint after layout. With enough room for the 640pt outer pane, the bundled themes resolve it to sm and the 240pt inner pane to xs.
import { BreakpointScope, Stack, Text, useBreakpoints } from "@vortexlabs/vortex-native";
const BreakpointLabel = () => {
const breakpoint = useBreakpoints({ xs: "xs", sm: "sm", md: "md", lg: "lg", xl: "xl" });
return <Text color="subtle">Breakpoint: {breakpoint}</Text>;
};
export const NestedScopes = () => (
<BreakpointScope style={{ width: 640, maxWidth: "100%" }}>
<Stack gap={4}>
<Stack gap={1}>
<Text weight="semibold">Outer pane</Text>
<BreakpointLabel />
</Stack>
<BreakpointScope style={{ width: 240, maxWidth: "100%" }}>
<Stack gap={1}>
<Text weight="semibold">Inner pane</Text>
<BreakpointLabel />
</Stack>
</BreakpointScope>
</Stack>
</BreakpointScope>
);First Layout
Before the measured view reports its width, children use the nearest parent scope’s breakpoint or the window breakpoint. When the width arrives, responsive values update and the children stay mounted.
Use attributes.onLayout to read the measured width in your own callback.
Short Windows
The pane supplies the width and the app window supplies the height. When the window is shorter than the theme’s compactHeight, the scope uses xs at any pane width. The bundled themes use 480pt.
Pass a breakpoint map to a responsive prop such as Stack.direction, or call useBreakpoints inside the scope when your component needs the resolved value. See Breakpoint Tokens for the bundled thresholds.