diff --git a/striker-ui/components/Panels/ExpandablePanel.tsx b/striker-ui/components/Panels/ExpandablePanel.tsx new file mode 100644 index 00000000..b1c1da23 --- /dev/null +++ b/striker-ui/components/Panels/ExpandablePanel.tsx @@ -0,0 +1,61 @@ +import { + ExpandLess as ExpandLessIcon, + ExpandMore as ExpandMoreIcon, +} from '@mui/icons-material'; +import { Box, IconButton } from '@mui/material'; +import { FC, ReactNode, useMemo, useState } from 'react'; + +import { GREY } from '../../lib/consts/DEFAULT_THEME'; + +import InnerPanel from './InnerPanel'; +import InnerPanelBody from './InnerPanelBody'; +import InnerPanelHeader from './InnerPanelHeader'; + +type ExpandablePanelOptionalProps = { + isExpandInitially?: boolean; +}; + +type ExpandablePanelProps = ExpandablePanelOptionalProps & { + header: ReactNode; +}; + +const EXPANDABLE_PANEL_DEFAULT_PROPS: Required = { + isExpandInitially: false, +}; + +const ExpandablePanel: FC = ({ + children, + header, + isExpandInitially = EXPANDABLE_PANEL_DEFAULT_PROPS.isExpandInitially, +}) => { + const [isExpand, setIsExpand] = useState(isExpandInitially); + + const expandButtonIcon = useMemo( + () => (isExpand ? : ), + [isExpand], + ); + const contentHeight = useMemo(() => (isExpand ? 'auto' : '.2em'), [isExpand]); + + return ( + + + {header} + { + setIsExpand((previous) => !previous); + }} + sx={{ color: GREY, padding: '.2em' }} + > + {expandButtonIcon} + + + + {children} + + + ); +}; + +ExpandablePanel.defaultProps = EXPANDABLE_PANEL_DEFAULT_PROPS; + +export default ExpandablePanel; diff --git a/striker-ui/components/Panels/InnerPanelBody.tsx b/striker-ui/components/Panels/InnerPanelBody.tsx new file mode 100644 index 00000000..d535793e --- /dev/null +++ b/striker-ui/components/Panels/InnerPanelBody.tsx @@ -0,0 +1,18 @@ +import { Box, BoxProps } from '@mui/material'; +import { FC } from 'react'; + +const InnerPanelBody: FC = ({ sx, ...innerPanelBodyRestProps }) => ( + +); + +export default InnerPanelBody; diff --git a/striker-ui/components/Panels/index.tsx b/striker-ui/components/Panels/index.tsx index a7eb7e18..29bb8dee 100644 --- a/striker-ui/components/Panels/index.tsx +++ b/striker-ui/components/Panels/index.tsx @@ -1,6 +1,15 @@ +import ExpandablePanel from './ExpandablePanel'; import InnerPanel from './InnerPanel'; +import InnerPanelBody from './InnerPanelBody'; import InnerPanelHeader from './InnerPanelHeader'; import Panel from './Panel'; import PanelHeader from './PanelHeader'; -export { InnerPanel, InnerPanelHeader, Panel, PanelHeader }; +export { + ExpandablePanel, + InnerPanel, + InnerPanelBody, + InnerPanelHeader, + Panel, + PanelHeader, +};