import React, { useState, useCallback } from 'react'; import PropTypes from 'prop-types'; import classnames from 'classnames'; import { Button, Icon } from '@ohif/ui'; const borderSize = 4; const expandedWidth = 320; const collapsedWidth = 60; const baseStyle = { maxWidth: `${expandedWidth}px`, width: `${expandedWidth}px`, }; const collapsedHideWidth = expandedWidth - collapsedWidth - borderSize; const styleMap = { open: { left: { marginLeft: '0px' }, right: { marginRight: '0px' }, }, closed: { left: { marginLeft: `-${collapsedHideWidth}px` }, right: { marginRight: `-${collapsedHideWidth}px` }, }, }; const baseClasses = 'transition-all duration-300 ease-in-out h-100 bg-primary-dark border-black flex flex-col justify-start'; const classesMap = { open: { left: `border-r-${borderSize}`, right: `border-l-${borderSize}`, }, closed: { left: `border-r-${borderSize} items-end`, right: `border-l-${borderSize} items-start`, }, }; const openIconName = { left: 'push-left', right: 'push-right', }; const SidePanel = ({ side, className, children, defaultIsOpen, componentLabel, iconLabel, iconName, }) => { const [isOpen, setIsOpen] = useState(defaultIsOpen); const openStatus = isOpen ? 'open' : 'closed'; const style = Object.assign({}, styleMap[openStatus][side], baseStyle); const getSidePanelHeader = useCallback(() => { return ( {isOpen ? ( ) : ( )} ); }, [componentLabel, iconLabel, iconName, isOpen, side]); return (
{getSidePanelHeader()} {isOpen && children}
); }; SidePanel.defaultProps = { defaultIsOpen: false, }; SidePanel.propTypes = { side: PropTypes.oneOf(['left', 'right']).isRequired, iconLabel: PropTypes.string.isRequired, componentLabel: PropTypes.string.isRequired, iconName: PropTypes.string.isRequired, defaultIsOpen: PropTypes.bool, className: PropTypes.string, children: PropTypes.node, }; export default SidePanel;