(props: SectionProps)
| 15 | defaultOpen: boolean |
| 16 | } |
| 17 | export const ProductCollapsibleSection = (props: SectionProps) => { |
| 18 | const { routePath, defaultOpen, title, page } = props |
| 19 | const [isOpen, setIsOpen] = useState(defaultOpen) |
| 20 | |
| 21 | const onToggle = (e: SyntheticEvent) => { |
| 22 | const newIsOpen = (e.target as HTMLDetailsElement).open |
| 23 | setIsOpen(newIsOpen) |
| 24 | sendEvent({ |
| 25 | type: EventType.navigate, |
| 26 | navigate_label: `details ${newIsOpen ? 'open' : 'close'}: ${title}`, |
| 27 | }) |
| 28 | } |
| 29 | |
| 30 | // The lowest level page link displayed in the tree |
| 31 | const renderTerminalPageLink = (page: ProductTreeNode) => { |
| 32 | const title = page.shortTitle || page.title |
| 33 | |
| 34 | const isCurrent = routePath === page.href |
| 35 | return ( |
| 36 | <ActionList.Item |
| 37 | key={page.href} |
| 38 | data-testid="sidebar-article" |
| 39 | data-is-current-page={isCurrent} |
| 40 | className={cx( |
| 41 | 'width-full position-relative', |
| 42 | styles.sidebarArticle, |
| 43 | isCurrent && ['text-bold', styles.sidebarArticleActive] |
| 44 | )} |
| 45 | sx={{ |
| 46 | padding: '2px 0', |
| 47 | ':hover': { |
| 48 | borderRadius: 0, |
| 49 | }, |
| 50 | }} |
| 51 | > |
| 52 | <Link |
| 53 | href={page.href} |
| 54 | className={cx( |
| 55 | 'd-block pl-6 pr-5 py-1 no-underline width-full', |
| 56 | isCurrent ? 'color-fg-accent' : 'color-fg-default' |
| 57 | )} |
| 58 | > |
| 59 | {title} |
| 60 | </Link> |
| 61 | </ActionList.Item> |
| 62 | ) |
| 63 | } |
| 64 | |
| 65 | return ( |
| 66 | <details open={defaultOpen} onToggle={onToggle} className="details-reset"> |
| 67 | <summary className="outline-none"> |
| 68 | <div className="d-flex flex-justify-between"> |
| 69 | <div className="pl-4 pr-1 py-2 f5 d-block flex-auto mr-3 color-fg-default no-underline text-bold"> |
| 70 | {title} |
| 71 | </div> |
| 72 | <span style={{ marginTop: 7 }} className="flex-shrink-0 pr-3"> |
| 73 | <ChevronDownIcon className={cx('opacity-60', isOpen && 'rotate-180')} /> |
| 74 | </span> |
nothing calls this directly
no test coverage detected