Base Components
Breadcrumb
Guiding users by displaying their path within an app or website.
Blogs
The Power of Minimalism in Design
Installation
Install the following dependencies:
npm install @radix-ui/react-slotCreate a breadcrumb.tsx file and paste the following code into it.
// CoreUI Breadcrumb v0.0.0import * as React from 'react';import { Slot } from '@radix-ui/react-slot';import { cn } from '@/utils/cn';import { PolymorphicComponentProps } from '@/utils/polymorphic';const BREADCRUMB_ROOT_NAME = 'BreadcrumbRoot';const BREADCRUMB_ITEM_NAME = 'BreadcrumbItem';const BREADCRUMB_ICON_NAME = 'BreadcrumbIcon';const BREADCRUMB_ARROW_NAME = 'BreadcrumbArrow';type BreadcrumbRootProps = React.HTMLAttributes<HTMLDivElement> & { asChild?: boolean;};function BreadcrumbRoot({ asChild, children, className, ...rest}: BreadcrumbRootProps) { const Component = asChild ? Slot : 'div'; return ( <Component className={cn('flex flex-wrap gap-1.5', className)} {...rest}> {children} </Component> );}BreadcrumbRoot.displayName = BREADCRUMB_ROOT_NAME;type BreadcrumbItemProps = React.HTMLAttributes<HTMLDivElement> & { asChild?: boolean; active?: boolean;};const BreadcrumbItem = React.forwardRef<HTMLDivElement, BreadcrumbItemProps>( ({ asChild, children, className, active, ...rest }, forwardedRef) => { const Component = asChild ? Slot : 'div'; return ( <Component ref={forwardedRef} className={cn( // base 'flex items-center gap-1.5 transition-colors duration-200 ease-out', 'text-label-sm text-text-sub-600', { // not active 'underline decoration-transparent': !active, // hover 'hover:text-text-strong-950 hover:decoration-current': !active, // active 'text-text-strong-950': active, }, className, )} {...rest} > {children} </Component> ); },);BreadcrumbItem.displayName = BREADCRUMB_ITEM_NAME;function BreadcrumbItemIcon<T extends React.ElementType>({ className, as, ...rest}: PolymorphicComponentProps<T>) { const Component = as || 'div'; return <Component className={cn('size-5', className)} {...rest} />;}BreadcrumbItemIcon.displayName = BREADCRUMB_ICON_NAME;function BreadcrumbItemArrowIcon<T extends React.ElementType>({ className, as, ...rest}: PolymorphicComponentProps<T>) { const Component = as || 'div'; return ( <Component className={cn( 'flex size-5 select-none items-center justify-center text-text-disabled-300', className, )} {...rest} /> );}BreadcrumbItemArrowIcon.displayName = BREADCRUMB_ARROW_NAME;export { BreadcrumbRoot as Root, BreadcrumbItem as Item, BreadcrumbItemIcon as Icon, BreadcrumbItemArrowIcon as ArrowIcon,};Examples
As Link
Slash Separator
Settings
/
Notifications
/
Email Notifications
API Reference
Breadcrumb.Root
This component is based on the <div> element and supports all of its props. And adds:
| Prop | Type | Default |
|---|---|---|
asChild | boolean |
Breadcrumb.Item
Individual breadcrumb item. This component is based on the <div> element initially and supports all of its props. And adds:
| Prop | Type | Default |
|---|---|---|
active | boolean | |
asChild | boolean |
Breadcrumb.Icon
Icon used within a breadcrumb item. The Breadcrumb.Icon component is polymorphic, allowing you to change the underlying HTML element using the as prop.
| Prop | Type | Default |
|---|---|---|
as | React.ElementType | div |
Breadcrumb.ArrowIcon
Icon used to separate breadcrumb items, usually an arrow. The Breadcrumb.ArrowIcon component is polymorphic, allowing you to change the underlying HTML element using the as prop.
| Prop | Type | Default |
|---|---|---|
as | React.ElementType | div |