Build faster with Premium Chakra UI Components 💎
Learn moreAfter the launch of Chakra UI v3, a common feedback we received was around snippets. Users felt that snippets were required to make components work, unlike in v2.
This wasn't our intention - snippets were designed to be helpful pre-made component compositions, not mandatory boilerplate. We want to clarify that snippets are entirely optional and simply provide convenient starting points.
For this reason, we've reworked the documentation to always show the complete
code that imports directly from @chakra-ui/react
.
This way, you can copy and paste the code without having to run any commands.
Here's a quick overview of the changes:
Before:
import {
AccordionItem,
AccordionItemContent,
AccordionItemTrigger,
AccordionRoot,
} from "@/components/ui/accordion"
const Demo = () => {
return (
<AccordionRoot>
<AccordionItem>
<AccordionItemTrigger>Item</AccordionItemTrigger>
<AccordionItemContent>Content</AccordionItemContent>
</AccordionItem>
</AccordionRoot>
)
}
After:
import { Accordion } from "@chakra-ui/react"
const Demo = () => {
return (
<Accordion.Root>
<Accordion.Item>
<Accordion.ItemTrigger>
Item
<Accordion.ItemIndicator />
</Accordion.ItemTrigger>
<Accordion.ItemContent>
<Accordion.ItemBody>Content</Accordion.ItemBody>
</Accordion.ItemContent>
</Accordion.Item>
</Accordion.Root>
)
}
Before:
import {
MenuContent,
MenuItem,
MenuRoot,
MenuTrigger,
} from "@/components/ui/menu"
const Demo = () => {
return (
<MenuRoot>
<MenuTrigger asChild>
<Button>Open</Button>
</MenuTrigger>
<MenuContent>
<MenuItem value="..." />
</MenuContent>
</MenuRoot>
)
}
After:
import { Menu, Portal } from "@chakra-ui/react"
const Demo = () => {
return (
<Menu.Root>
<Menu.Trigger asChild>
<Button>Open</Button>
</Menu.Trigger>
<Portal>
<Menu.Positioner>
<Menu.Content>
<Menu.Item value="..." />
</Menu.Content>
</Menu.Positioner>
</Portal>
</Menu.Root>
)
}
To make your code more concise and easier to write, we've introduced shortcut components for common use cases.
We achieved that by setting the default children
prop, or creating sugar
components that compose the existing components.
Here's a checkbox example.
This works:
<Checkbox.Control>
<Checkbox.Indicator />
</Checkbox.Control>
but can be simplified if you don't need to customize the checkbox icons:
<Checkbox.Control />
The same goes for the Rating
component.
This works:
<RatingGroup.Control>
{Array.from({ length: 5 }).map((_, index) => (
<RatingGroup.Item key={index} index={index + 1}>
<RatingGroup.ItemIndicator />
</RatingGroup.Item>
))}
</RatingGroup.Control>
but can be simplified if you don't need to customize the rating icons:
<RatingGroup.Control />
The following components are exceptions to the rule and will continue to use snippets:
Provider
: The provider is the root component that you need to wrap your appToaster
: The toaster is a component that is used to display notificationsPasswordInput
: The password input is used to collect passwordsTooltip
: The tooltip is a component that is used to display a tooltipToggletip
: The toggletip looks like a tooltip, but works like a popoverThese components will remain as snippets due to the ease of use they provide.
Now that we've refactored the snippets, we're moving on to next phase of Chakra.
@ark-ui/react
to v5 to boost render performanceCombobox
and CommandMenu
components@chakra-ui/charts
for data visualizationIf you have any feedback, please open an discussion and let us know.