Center
Center is a layout component that centers its child within itself.
import { Center, Square, Circle } from "@chakra-ui/core"
- Center: centers it's child given
width
and height
- Square: centers it's child given
size
(width and height) - Circle: a
Square
with round border-radius
Put any child element inside it, give it any width
or/and height
, it'll
ensure the child is centered.
<Center bg="tomato" h="100px" color="white">
This is the Center
</Center>
Editable Example
Center can be used to create frames around icons or numbers
<HStack>
<Center w="40px" h="40px" bg="tomato" color="white">
<PhoneIcon />
</Center>
<Center w="40px" h="40px" bg="tomato" color="white">
<Box as="span" fontWeight="bold" fontSize="lg">
1
</Box>
</Center>
</HStack>
Editable Example
To reduce boilerplace, we've export Square
and Circle
components that
automatically centers it's children given the size
.
<HStack>
<Circle size="40px" bg="tomato" color="white">
<PhoneIcon />
</Circle>
<Square size="40px" bg="purple.700" color="white">
<PhoneIcon />
</Square>
</HStack>
Editable Example