import { forwardRef, type ReactNode } from 'react'; import { View, type ViewProps } from 'react-native'; import { Slot, dataAttributes, mergeDataAttributes } from '@cdx-ui/primitives'; import { cn } from '@cdx-ui/utils'; import { Text, type TextProps } from '../Text'; import { dividerLabelVariants, dividerLineVariants, dividerRootVariants } from './styles'; const lineA11yProps = { accessibilityElementsHidden: true, importantForAccessibility: 'no-hide-descendants' as const, 'aria-hidden': true, }; export interface DividerProps extends ViewProps { className?: string; /** Renders a vertical divider instead of the default horizontal orientation. */ vertical?: boolean; children?: ReactNode; } export interface DividerLabelProps extends TextProps { asChild?: boolean; className?: string; } const DividerLine = ({ vertical, flex }: { vertical: boolean; flex: boolean }) => ( ); const DividerRoot = forwardRef( ({ vertical = false, className, style, children, ...props }, ref) => { const hasLabel = !!children; const computedClassName = cn(dividerRootVariants({ vertical, hasLabel }), className); if (!hasLabel) { return ( ); } return ( {children} ); }, ); DividerRoot.displayName = 'Divider'; const DividerLabel = forwardRef( ({ asChild, className, style, children, ...props }, ref) => { const Comp = asChild ? Slot : Text; return ( {children} ); }, ); DividerLabel.displayName = 'Divider.Label'; type DividerCompoundComponent = typeof DividerRoot & { Label: typeof DividerLabel; }; export const Divider = Object.assign(DividerRoot, { Label: DividerLabel, }) as DividerCompoundComponent;