From b651ba02ffc6aa9a6cc1adfa8a82178bff771215 Mon Sep 17 00:00:00 2001 From: Rodrigo Antinarelli Date: Fri, 17 Apr 2020 17:25:59 -0300 Subject: [PATCH] make toolbar reusable to use as secondary --- platform/ui/index.js | 2 +- .../ui/src/components/PrimaryToolbar/index.js | 2 - .../Toolbar.jsx} | 22 +++++-- .../Toolbar.mdx} | 22 +++---- platform/ui/src/components/Toolbar/index.js | 2 + .../ToolbarButton/ToolbarButton.jsx | 19 ++++-- platform/ui/src/components/index.js | 4 +- .../ui/src/views/Viewer/components/Header.js | 8 +-- .../Viewer/components/ViewportToolBar.js | 58 ++----------------- 9 files changed, 53 insertions(+), 86 deletions(-) delete mode 100644 platform/ui/src/components/PrimaryToolbar/index.js rename platform/ui/src/components/{PrimaryToolbar/PrimaryToolbar.jsx => Toolbar/Toolbar.jsx} (79%) rename platform/ui/src/components/{PrimaryToolbar/PrimaryToolbar.mdx => Toolbar/Toolbar.mdx} (87%) create mode 100644 platform/ui/src/components/Toolbar/index.js diff --git a/platform/ui/index.js b/platform/ui/index.js index 4bd6b94f9..9446d374a 100644 --- a/platform/ui/index.js +++ b/platform/ui/index.js @@ -28,7 +28,6 @@ export { MeasurementTable, NavBar, Notification, - PrimaryToolbar, Select, SegmentationTable, SidePanel, @@ -47,6 +46,7 @@ export { Thumbnail, ThumbnailSR, ThumbnailList, + Toolbar, ToolbarButton, Tooltip, Typography, diff --git a/platform/ui/src/components/PrimaryToolbar/index.js b/platform/ui/src/components/PrimaryToolbar/index.js deleted file mode 100644 index 62ef7d92f..000000000 --- a/platform/ui/src/components/PrimaryToolbar/index.js +++ /dev/null @@ -1,2 +0,0 @@ -import PrimaryToolbar from './PrimaryToolbar'; -export default PrimaryToolbar; diff --git a/platform/ui/src/components/PrimaryToolbar/PrimaryToolbar.jsx b/platform/ui/src/components/Toolbar/Toolbar.jsx similarity index 79% rename from platform/ui/src/components/PrimaryToolbar/PrimaryToolbar.jsx rename to platform/ui/src/components/Toolbar/Toolbar.jsx index 13dd59b23..dd4c11f5b 100644 --- a/platform/ui/src/components/PrimaryToolbar/PrimaryToolbar.jsx +++ b/platform/ui/src/components/Toolbar/Toolbar.jsx @@ -4,9 +4,16 @@ import classnames from 'classnames'; import { ToolbarButton, IconButton, Icon, Tooltip } from '@ohif/ui'; -const PrimaryToolbar = ({ activeTool, tools, moreTools }) => { +const classes = { + type: { + primary: '', + secondary: 'w-full items-center bg-primary-dark px-3', + }, +}; + +const Toolbar = ({ activeTool, tools, moreTools, type }) => { return ( -
+
{tools.map((tool) => { const { id, onClick, icon, label, dropdownContent } = tool; const isActive = activeTool === tool.id; @@ -19,13 +26,14 @@ const PrimaryToolbar = ({ activeTool, tools, moreTools }) => { icon={icon} label={label} dropdownContent={dropdownContent} + type={type} />
); })} {!!moreTools.length && ( <> - + { ); }; -PrimaryToolbar.defaultProps = { +Toolbar.defaultProps = { activeTool: '', moreTools: [], + type: 'primary', }; -PrimaryToolbar.propTypes = { +Toolbar.propTypes = { + type: PropTypes.oneOf(['primary', 'secondary']), activeTool: PropTypes.string, tools: PropTypes.arrayOf( PropTypes.shape({ @@ -76,4 +86,4 @@ PrimaryToolbar.propTypes = { ), }; -export default PrimaryToolbar; +export default Toolbar; diff --git a/platform/ui/src/components/PrimaryToolbar/PrimaryToolbar.mdx b/platform/ui/src/components/Toolbar/Toolbar.mdx similarity index 87% rename from platform/ui/src/components/PrimaryToolbar/PrimaryToolbar.mdx rename to platform/ui/src/components/Toolbar/Toolbar.mdx index 50bada881..27c1aa54c 100644 --- a/platform/ui/src/components/PrimaryToolbar/PrimaryToolbar.mdx +++ b/platform/ui/src/components/Toolbar/Toolbar.mdx @@ -1,22 +1,22 @@ --- -name: Primary Toolbar +name: Toolbar menu: Data Display -route: components/primaryToolbar +route: components/toolbar --- import { useState } from 'react'; -import { Playground } from 'docz'; +import { Playground, Props } from 'docz'; import classnames from 'classnames'; -import { PrimaryToolbar } from '@ohif/ui'; +import { Toolbar } from '@ohif/ui'; -# Primary Toolbar +# Toolbar -Primary Toolbar is used to create a list of tools. +A Toolbar is used to create a list of tools. ## Import ```javascript -import { PrimaryToolbar } from '@ohif/ui'; +import { Toolbar } from '@ohif/ui'; ``` @@ -112,11 +112,7 @@ import { PrimaryToolbar } from '@ohif/ui'; ]; return (
- +
); }} @@ -124,4 +120,4 @@ import { PrimaryToolbar } from '@ohif/ui'; ## Properties - + diff --git a/platform/ui/src/components/Toolbar/index.js b/platform/ui/src/components/Toolbar/index.js new file mode 100644 index 000000000..7bd64e01f --- /dev/null +++ b/platform/ui/src/components/Toolbar/index.js @@ -0,0 +1,2 @@ +import Toolbar from './Toolbar'; +export default Toolbar; diff --git a/platform/ui/src/components/ToolbarButton/ToolbarButton.jsx b/platform/ui/src/components/ToolbarButton/ToolbarButton.jsx index 51aa861ad..fb44a3a24 100644 --- a/platform/ui/src/components/ToolbarButton/ToolbarButton.jsx +++ b/platform/ui/src/components/ToolbarButton/ToolbarButton.jsx @@ -5,6 +5,7 @@ import classnames from 'classnames'; import { IconButton, Icon, Tooltip } from '@ohif/ui'; const ToolbarButton = ({ + type, id, isActive, onClick, @@ -12,6 +13,17 @@ const ToolbarButton = ({ label, dropdownContent, }) => { + const classes = { + type: { + primary: isActive + ? 'text-black' + : 'text-common-bright hover:bg-primary-dark hover:text-primary-light', + secondary: isActive + ? 'text-black' + : 'text-white hover:bg-secondary-dark hover:text-white focus:bg-secondary-dark focus:text-white', + }, + }; + const shouldShowDropdown = !!isActive && !!dropdownContent; return (
@@ -21,10 +33,7 @@ const ToolbarButton = ({ > @@ -38,9 +47,11 @@ const ToolbarButton = ({ ToolbarButton.defaultProps = { dropdownContent: null, isActive: false, + type: 'primary', }; ToolbarButton.propTypes = { + type: PropTypes.oneOf(['primary', 'secondary']), id: PropTypes.string.isRequired, isActive: PropTypes.bool, onClick: PropTypes.func.isRequired, diff --git a/platform/ui/src/components/index.js b/platform/ui/src/components/index.js index 05916bec2..f775b3805 100644 --- a/platform/ui/src/components/index.js +++ b/platform/ui/src/components/index.js @@ -15,7 +15,6 @@ import MeasurementTable from './MeasurementTable'; import NavBar from './NavBar'; import Notification from './Notification'; import Select from './Select'; -import PrimaryToolbar from './PrimaryToolbar'; import SegmentationTable from './SegmentationTable'; import SidePanel from './SidePanel'; import StudyBrowser from './StudyBrowser'; @@ -33,6 +32,7 @@ import ThemeWrapper from './ThemeWrapper/'; import Thumbnail from './Thumbnail'; import ThumbnailSR from './ThumbnailSR'; import ThumbnailList from './ThumbnailList'; +import Toolbar from './Toolbar'; import ToolbarButton from './ToolbarButton'; import Tooltip from './Tooltip'; import Typography from './Typography'; @@ -56,7 +56,6 @@ export { MeasurementTable, NavBar, Notification, - PrimaryToolbar, Select, SegmentationTable, SidePanel, @@ -75,6 +74,7 @@ export { Thumbnail, ThumbnailSR, ThumbnailList, + Toolbar, ToolbarButton, Tooltip, Typography, diff --git a/platform/ui/src/views/Viewer/components/Header.js b/platform/ui/src/views/Viewer/components/Header.js index 3c6b2a228..fb90b06e4 100644 --- a/platform/ui/src/views/Viewer/components/Header.js +++ b/platform/ui/src/views/Viewer/components/Header.js @@ -1,5 +1,5 @@ import React, { useState } from 'react'; -import { NavBar, Svg, Icon, IconButton, PrimaryToolbar } from '@ohif/ui'; +import { NavBar, Svg, Icon, IconButton, Toolbar } from '@ohif/ui'; const Header = () => { const [activeTool, setActiveTool] = useState('Zoom'); @@ -89,11 +89,7 @@ const Header = () => {
- +
diff --git a/platform/ui/src/views/Viewer/components/ViewportToolBar.js b/platform/ui/src/views/Viewer/components/ViewportToolBar.js index 1c9e342f0..a2fa1c436 100644 --- a/platform/ui/src/views/Viewer/components/ViewportToolBar.js +++ b/platform/ui/src/views/Viewer/components/ViewportToolBar.js @@ -1,10 +1,9 @@ import React, { useState } from 'react'; import classnames from 'classnames'; -import { Icon, IconButton } from '@ohif/ui'; +import { Toolbar } from '@ohif/ui'; const ViewportToolbar = () => { - const [activeTool, setActiveTool] = useState(null); const tools = [ { id: 'Annotate', @@ -13,6 +12,7 @@ const ViewportToolbar = () => { type: null, commandName: 'setToolActive', commandOptions: { toolName: 'Annotate' }, + onClick: () => console.log('Activate Annotate'), }, { id: 'Bidirectional', @@ -21,6 +21,7 @@ const ViewportToolbar = () => { type: null, commandName: 'setToolActive', commandOptions: { toolName: 'Bidirectional' }, + onClick: () => console.log('Activate Bidirectional'), }, { id: 'Elipse', @@ -29,6 +30,7 @@ const ViewportToolbar = () => { type: null, commandName: 'setToolActive', commandOptions: { toolName: 'Elipse' }, + onClick: () => console.log('Activate Elipse'), }, { id: 'Length', @@ -37,58 +39,10 @@ const ViewportToolbar = () => { type: null, commandName: 'setToolActive', commandOptions: { toolName: 'Length' }, + onClick: () => console.log('Activate Length'), }, ]; - const renderToolbar = () => { - return tools.map((tool, i) => { - const isActive = activeTool === tool.id; - return ( -
- { - setActiveTool(tool.id); - }} - > - - -
- {tool.label} - - - -
-
- ); - }); - }; - return ( -
-
{renderToolbar()}
-
- ); + return ; }; export default ViewportToolbar;