import React, { forwardRef, type ElementRef } from 'react'; import { composeEventHandlers } from '@radix-ui/primitive'; import { type ElementProps } from '../../types'; import { cn } from '../../utils/cn'; import { withAttr } from '../../utils/withAttr'; import { Button, type ButtonProps } from '../button'; import { ChevronRightIcon } from '../icons'; import { useSidebarContext } from './sidebar.context'; export interface SidebarHeaderProps extends ElementProps<'div'> { withDivider?: boolean; } const SidebarHeader = forwardRef, SidebarHeaderProps>( ({ children, withDivider = true, className, ...props }, ref) => { const { open, isExpanded } = useSidebarContext(); return (
{children}
); } ); const SidebarToggle = forwardRef, ButtonProps>(({ children, onClick, ...props }, ref) => { const { open, toggleOpen, isMobile } = useSidebarContext(); if (isMobile) return null; return ( ); }); const SidebarLogo = forwardRef, ElementProps<'div'>>(({ children, className, ...props }, ref) => { return (
{children}
); }); const SidebarHeadTitle = forwardRef, ElementProps<'div'>>( ({ children, className, ...props }, ref) => { const { isExpanded } = useSidebarContext(); if (!isExpanded) return null; return (
{children}
); } ); export const SidebarHead = Object.assign(SidebarHeader, { Toggle: SidebarToggle, Title: SidebarHeadTitle, Logo: SidebarLogo, });