Stack
Stack
is a component that groups elements and provides spacing between child elements.
Import
import { Stack, VStack, HStack, ZStack } from "@yamada-ui/react"
Stack
is used to stack child elements vertically or horizontally.VStack
is used to stack child elements vertically.HStack
is used to stack child elements horizontally.ZStack
is used to stack child elements in depth.
Usage
Editable example
<Stack direction={{ base: "column", lg: "row" }}> <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> </Stack>
Stacking Vertically & Horizontally
Editable example
<VStack> <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>
Editable example
<HStack> <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> </HStack>
Adding Dividers Between Child Elements
Editable example
<VStack divider={<Divider />}> <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