({
children,
trailing,
leading,
actions,
onClick,
className,
}: SectionHeaderProps)
| 83 | } |
| 84 | |
| 85 | export function SectionHeader({ |
| 86 | children, |
| 87 | trailing, |
| 88 | leading, |
| 89 | actions, |
| 90 | onClick, |
| 91 | className, |
| 92 | }: SectionHeaderProps) { |
| 93 | const ctx = useSectionContext(); |
| 94 | const isCollapsible = ctx?.collapsible ?? false; |
| 95 | const isOpen = ctx?.isOpen ?? true; |
| 96 | const isInteractive = isCollapsible || !!onClick; |
| 97 | const handleClick = isCollapsible ? ctx?.toggle : onClick; |
| 98 | |
| 99 | const chevronIcon = isCollapsible ? ( |
| 100 | <HugeiconsIcon |
| 101 | icon={ArrowDownIcon} |
| 102 | className={cn( |
| 103 | "size-4 shrink-0 transition-transform duration-200 ease-out", |
| 104 | isOpen ? "rotate-0 text-foreground" : "-rotate-90 text-muted-foreground", |
| 105 | )} |
| 106 | /> |
| 107 | ) : null; |
| 108 | |
| 109 | const headerContent = ( |
| 110 | <> |
| 111 | {leading} |
| 112 | <div className="min-w-0 flex-1">{children}</div> |
| 113 | {(trailing || chevronIcon) && ( |
| 114 | <div className="flex items-center"> |
| 115 | {trailing} |
| 116 | {chevronIcon && ( |
| 117 | <Button |
| 118 | variant="ghost" |
| 119 | size="icon" |
| 120 | aria-label={isOpen ? "Collapse section" : "Expand section"} |
| 121 | onClick={(event) => { |
| 122 | event.stopPropagation(); |
| 123 | handleClick?.(); |
| 124 | }} |
| 125 | > |
| 126 | {chevronIcon} |
| 127 | </Button> |
| 128 | )} |
| 129 | </div> |
| 130 | )} |
| 131 | {actions} |
| 132 | </> |
| 133 | ); |
| 134 | |
| 135 | if (!isInteractive) { |
| 136 | return ( |
| 137 | <div className={cn("flex h-11 w-full items-center gap-2 px-3.5", className)}> |
| 138 | {headerContent} |
| 139 | </div> |
| 140 | ); |
| 141 | } |
| 142 |
nothing calls this directly
no test coverage detected