Stack
Stack is a component that groups elements and provides spacing between child elements.
Import
import { Stack, VStack, HStack, ZStack } from "@yamada-ui/react"
Stackis used to stack child elements vertically or horizontally.VStackis used to stack child elements vertically.HStackis used to stack child elements horizontally.ZStackis used to stack child elements in depth.
Usage
Editable example
<Stack direction={{ base: "column", lg: "row" }}> <For each={["primary", "secondary", "warning", "danger"]}> {(bg, index) => ( <Box key={index} p="md" rounded="4" bg={bg} color="white"> Box </Box> )} </For> </Stack>
Stacking Vertically & Horizontally
Editable example
<VStack> <For each={["primary", "secondary", "warning", "danger"]}> {(bg, index) => ( <Box key={index} p="md" rounded="4" bg={bg} color="white"> Box </Box> )} </For> </VStack>
Editable example
<HStack> <For each={["primary", "secondary", "warning", "danger"]}> {(bg, index) => ( <Box key={index} p="md" rounded="4" bg={bg} color="white"> Box </Box> )} </For> </HStack>
Adding Separators Between Child Elements
Editable example
<VStack separator={<Separator />}> <Box p="md" rounded="4" bg="primary" color="white"> Box </Box> <Box p="md" rounded="4" bg="secondary" color="white"> Box </Box> <Box p="md" rounded="4" bg="warning" color="white"> Box </Box> <Box p="md" rounded="4" bg="danger" color="white"> Box </Box> </VStack>
Using Spacer
Editable example
<HStack> <Box p="md" rounded="4" bg="primary" color="white"> Box </Box> <Spacer /> <Box p="md" rounded="4" bg="danger" color="white"> Box </Box> </HStack>
Stacking in Depth
Editable example
<ZStack> <Box p="md" rounded="4" bg="primary" color="white"> Box </Box> <Box p="md" rounded="4" bg="secondary" color="white"> Box </Box> <Box p="md" rounded="4" bg="warning" color="white"> Box </Box> <Box p="md" rounded="4" bg="danger" color="white"> Box </Box> </ZStack>
Changing Direction
To change the direction, set direction to top, bottom-right, etc.
Editable example
<VStack> <ZStack direction="top"> <Box p="md" rounded="4" bg="primary" color="white"> Box </Box> <Box p="md" rounded="4" bg="secondary" color="white"> Box </Box> <Box p="md" rounded="4" bg="warning" color="white"> Box </Box> <Box p="md" rounded="4" bg="danger" color="white"> Box </Box> </ZStack> <ZStack direction="bottom-right"> <Box p="md" rounded="4" bg="primary" color="white"> Box </Box> <Box p="md" rounded="4" bg="secondary" color="white"> Box </Box> <Box p="md" rounded="4" bg="warning" color="white"> Box </Box> <Box p="md" rounded="4" bg="danger" color="white"> Box </Box> </ZStack> </VStack>
Reversing Direction
To reverse the direction, set reverse to true.
Editable example
<ZStack direction="left" reverse> <Box p="md" rounded="4" bg="primary" color="white"> Box </Box> <Box p="md" rounded="4" bg="secondary" color="white"> Box </Box> <Box p="md" rounded="4" bg="warning" color="white"> Box </Box> <Box p="md" rounded="4" bg="danger" color="white"> Box </Box> </ZStack>
Edit this page on GitHub

