import { UnfoldLess, UnfoldMore } from '@mui/icons-material' import clsx from 'clsx' import { useRouter } from 'next/router' import { ComponentType, ReactNode, useEffect, useState } from 'react' import { LinkWrapperProps, RowProps } from '@dao-dao/types' import { IconButton } from '../icon_buttons' import { Loader } from '../logo/Loader' import { Tooltip } from '../tooltip/Tooltip' export const Row = ({ Icon: _Icon, label, expandedLocalStorageKey, showBadge, onClick, children, rightNode, href, defaultExpanded = false, forceExpanded = false, hideExpand = false, compact = false, loading = false, selected = false, LinkWrapper, shallow, containerClassName, contentContainerClassName, }: RowProps) => { const { asPath } = useRouter() const [expanded, setExpanded] = useState( forceExpanded || (expandedLocalStorageKey && typeof localStorage !== 'undefined' ? localStorage.getItem(expandedLocalStorageKey) === '1' : defaultExpanded) ) useEffect(() => { if (forceExpanded) { return } if (expandedLocalStorageKey && typeof localStorage !== 'undefined') { localStorage.setItem(expandedLocalStorageKey, Number(expanded).toString()) } }, [expanded, expandedLocalStorageKey, forceExpanded]) const Icon = _Icon || ((props) =>
) const ExpandButton = expanded ? UnfoldLess : UnfoldMore // If no onClick or href, and has expandable children, set onClick to toggle // expanded. if (!onClick && !href && children && !loading) { onClick = () => setExpanded((e) => !e) } return compact ? ({label}
{/* Override expand button with loader. */} {loading ? (