Props#
Props#
The Divider
component is a single part component. All of the styling is
applied directly to the chakra.hr
element.
To learn more about styling single part components, visit the Component Style page
Theming properties#
The properties that affect the theming of the Divider
component are:
variant
: The visual variant of the divider. Defaults tosolid
.colorScheme
: The color scheme of the divider. No default value.size
: The size of the divider. No default value.
Theming utilities#
defineStyle
: a function used to create style objects.defineStyleConfig
: a function used to define the style configuration for a single part component.
import { defineStyle, defineStyleConfig } from '@chakra-ui/react'
Customizing the default theme#
import { defineStyle, defineStyleConfig } from '@chakra-ui/react'const thick = defineStyle({borderWidth: '5px', // change the width of the borderborderStyle: 'solid', // change the style of the borderborderRadius: 10, // set border radius to 10})export const dividerTheme = defineStyleConfig({variants: { thick },})
After customizing the divider theme, we can import it in our theme file and add it in the components property:
import { extendTheme } from '@chakra-ui/react'import { dividerTheme } from './components/divider'export const theme = extendTheme({components: { Divider: dividerTheme },})
This is a crucial step to make sure that any changes that we make to the divider theme are applied.
Adding a custom size#
Let's assume we want to include an extra large divider size. Here's how we can do that:
import { defineStyle, defineStyleConfig } from '@chakra-ui/react'const xl = defineStyle({border: "10px solid",borderRadius: 'lg',})export const dividerTheme = defineStyleConfig({sizes: { xl },})// Now we can use the new `xl` size<Divider size="xl" />
Every time you're adding anything new to the theme, you'd need to run the cli command to get proper autocomplete in your IDE. You can learn more about the CLI tool here.
Adding a custom variant#
Let's assume we want to include a custom branded variant. Here's how we can do that:
import { defineStyle, defineStyleConfig } from '@chakra-ui/react'const brandPrimary = defineStyle({borderWidth: '3px',borderStyle: 'dashed',borderColor: 'orange.500',// let's also provide dark mode alternatives_dark: {borderColor: 'orange.300',}})export const dividerTheme = defineStyleConfig({variants: { brandPrimary },})// Now we can use the new `brandPrimary` variant<Divider variant="brandPrimary" />
Changing the default properties#
import { defineStyleConfig } from '@chakra-ui/react'export const dividerTheme = defineStyleConfig({defaultProps: {size: 'xl',variant: 'thick',colorScheme: 'brand',},})// This saves you time, instead of manually setting the size,// variant and color scheme every time you use a divider:<Divider size="xl" variant="thick" colorPalette="brand" />
Showcase#
import { Box, SimpleGrid, IconButton, Center, Divider, useColorMode } from "@chakra-ui/react"; import { FaMoon, FaSun } from "react-icons/fa"; export default function App() { const { toggleColorMode, colorMode } = useColorMode(); return ( <Box position="relative" h="100vh"> <SimpleGrid gap={12} p={12} columns={2}> <Divider variant="thick" /> <Center height="50px"> <Divider orientation="vertical" variant="thick" /> </Center> <Divider variant="brand" /> <Center height="50px"> <Divider orientation="vertical" variant="brand" /> </Center> <Divider size="xl" /> <Center height="50px"> <Divider orientation="vertical" size="xl" /> </Center> </SimpleGrid> <IconButton aria-label="toggle theme" rounded="full" size="xs" position="absolute" bottom={4} left={4} onClick={toggleColorMode} icon={colorMode === "dark" ? <FaSun /> : <FaMoon />} /> </Box> ); }