From 08ebfd586598d528ec85354a1dc0a94ffb7f8de0 Mon Sep 17 00:00:00 2001 From: Gustavo Lelis Date: Wed, 22 Apr 2020 23:13:08 -0300 Subject: [PATCH] Update sidePanel to support multiple components --- .../ui/src/components/SidePanel/SidePanel.jsx | 137 +++++++++++------- .../ui/src/components/SidePanel/SidePanel.mdx | 47 +++++- platform/ui/src/views/Viewer/Viewer.mdx | 102 +++++++------ 3 files changed, 181 insertions(+), 105 deletions(-) diff --git a/platform/ui/src/components/SidePanel/SidePanel.jsx b/platform/ui/src/components/SidePanel/SidePanel.jsx index f716b95c5..1929e3b79 100644 --- a/platform/ui/src/components/SidePanel/SidePanel.jsx +++ b/platform/ui/src/components/SidePanel/SidePanel.jsx @@ -1,4 +1,4 @@ -import React, { useState, useCallback } from 'react'; +import React, { useState } from 'react'; import PropTypes from 'prop-types'; import classnames from 'classnames'; @@ -53,30 +53,78 @@ const position = { }, }; +const getChildComponent = (childComponents, componentOpen) => { + if (Array.isArray(childComponents)) { + return childComponents.find( + (_childComponent) => _childComponent.name === componentOpen + ); + } else { + return childComponents; + } +}; + const SidePanel = ({ side, className, - children, - defaultIsOpen, - componentLabel, - iconLabel, - iconName, + defaultComponentOpen, + childComponents, }) => { - const [isOpen, setIsOpen] = useState(defaultIsOpen); - const openStatus = isOpen ? 'open' : 'closed'; + const [componentOpen, setComponentOpen] = useState(defaultComponentOpen); + + const openStatus = componentOpen ? 'open' : 'closed'; const style = Object.assign({}, styleMap[openStatus][side], baseStyle); - const getSidePanelHeader = useCallback(() => { - return ( - - {isOpen ? ( + const childComponent = getChildComponent(childComponents, componentOpen); + + const getPanelButtons = () => { + const _childComponents = Array.isArray(childComponents) + ? childComponents + : [childComponents]; + return _childComponents.map((childComponent) => { + return ( + + ); + }); + }; + + return ( +
+ {componentOpen ? ( +
- ) : ( - - )} -
- ); - }, [componentLabel, iconLabel, iconName, isOpen, side]); - - return ( -
+ ) : ( + {getPanelButtons()} )} - style={style} - > - {getSidePanelHeader()} - {isOpen && children}
); }; SidePanel.defaultProps = { - defaultIsOpen: false, + defaultComponentOpen: null, }; 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, + defaultComponentOpen: PropTypes.string, + childComponents: PropTypes.oneOfType([ + PropTypes.shape({ + iconName: PropTypes.string.isRequired, + iconLabel: PropTypes.string.isRequired, + name: PropTypes.string.isRequired, + label: PropTypes.string.isRequired, + content: PropTypes.node, + }), + PropTypes.arrayOf( + PropTypes.shape({ + iconName: PropTypes.string.isRequired, + iconLabel: PropTypes.string.isRequired, + name: PropTypes.string.isRequired, + label: PropTypes.string.isRequired, + content: PropTypes.node, + }) + ), + ]), }; export default SidePanel; diff --git a/platform/ui/src/components/SidePanel/SidePanel.mdx b/platform/ui/src/components/SidePanel/SidePanel.mdx index 8216ffdb6..f6467bdee 100644 --- a/platform/ui/src/components/SidePanel/SidePanel.mdx +++ b/platform/ui/src/components/SidePanel/SidePanel.mdx @@ -24,19 +24,52 @@ import { SidePanel } from '@ohif/ui'; > -
panel content
-
+ childComponents={{ + iconName: "group-layers", + iconLabel: "Studies", + name: "studies", + label: "Studies", + content:
panel content
, + }} + />
CONTENT
+ +## Multiple panels + + +
+ studies panel content
, + }, + { + iconName: "list-bullets", + iconLabel: "Measure", + name: "measurements", + label: "Measurements", + content:
measure panel content
, + }]} + /> +
+ CONTENT +
+ +
+ + ## Properties diff --git a/platform/ui/src/views/Viewer/Viewer.mdx b/platform/ui/src/views/Viewer/Viewer.mdx index 2ab180950..47ddcc4f9 100644 --- a/platform/ui/src/views/Viewer/Viewer.mdx +++ b/platform/ui/src/views/Viewer/Viewer.mdx @@ -57,14 +57,18 @@ import { tabs } from './studyBrowserMockData'; > - - -
+ defaultComponentOpen='studies' + childComponents={{ + iconName: 'group-layers', + iconLabel: 'Studies', + label: 'Studies', + name: 'studies', + content: ( + + ) + }} + /> +
@@ -100,45 +104,49 @@ import { tabs } from './studyBrowserMockData';
- - alert('Export')}> - - - - - - - - } - /> - + defaultComponentOpen="measurements" + childComponents={{ + iconName: 'list-bullets', + iconLabel: 'Measure', + label: 'Measurements', + name: 'measurements', + content: ( + + alert('Export')}> + + + + + + + + } + /> + ) + }} + />
);