A separator line that is accessible to screen readers. The Separator component extends Base UI's Separator. It adds a text prop for a label in the middle of the separator.
Here is the component implementation code that you can copy to your project:
// https://devie-ui.com/components/separator
// https://base-ui.com/react/components/separator
import { Separator as BaseSeparator } from "@base-ui/react/separator";
import clsx from "clsx";
import styles from "./Separator.module.scss";
function Separator({ text, className, ...props }: Separator.Props) {
if (text) {
return (
<BaseSeparator
aria-label={text}
className={clsx(styles.withTextContainer, className)}
{...props}
>
<span className={styles.line} />
<span className={styles.text} aria-hidden="true">
{text}
</span>
<span className={styles.line} />
</BaseSeparator>
);
}
return (
<BaseSeparator className={clsx(styles.separator, className)} {...props} />
);
}
namespace Separator {
export interface Props extends Omit<BaseSeparator.Props, "className"> {
className?: string;
text?: string;
}
}
export default Separator;Place a Separator between two blocks of content. The default orientation is horizontal.
Set text to show a label in the middle, such as "Or". The text also becomes the separator's accessible name.
Set orientation to vertical. The line fills the height of its parent.