feat: Tooltip, ToolbarButton, Toolbar API and misc

This commit is contained in:
Rodrigo Antinarelli authored and James A. Petts committed 2020-05-15 13:54:28 +02:00
1 parent 3223d6a8a1
commit 9154f36477
15 files changed
+580 -290

No files matched your search

@@ -0,0 +1,53 @@
import React from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import { IconButton, Icon, Tooltip } from '@ohif/ui';
const ToolbarButton = ({
id,
isActive,
onClick,
icon,
label,
dropdownContent,
}) => {
const shouldShowDropdown = !!isActive && !!dropdownContent;
return (
<div key={id}>
<Tooltip
content={shouldShowDropdown ? dropdownContent : label}
tight={shouldShowDropdown}
>
<IconButton
variant={isActive ? 'contained' : 'text'}
className={classnames('mx-1', {
'text-black': isActive,
'text-common-bright hover:bg-primary-dark hover:text-primary-light': !isActive,
})}
onClick={onClick}
key={id}
>
<Icon name={icon} />
</IconButton>
</Tooltip>
</div>
);
};
ToolbarButton.defaultProps = {
dropdownContent: null,
isActive: false,
};
ToolbarButton.propTypes = {
id: PropTypes.string.isRequired,
isActive: PropTypes.bool,
onClick: PropTypes.func.isRequired,
icon: PropTypes.string.isRequired,
label: PropTypes.string.isRequired,
/** Tooltip content can be replaced for a customized content by passing a node to this value. */
dropdownContent: PropTypes.node,
};
export default ToolbarButton;
@@ -0,0 +1,44 @@
---
name: Toolbar Button
menu: General
route: components/toolbarButton
---
import { useState } from 'react';
import { Playground, Props } from 'docz';
import { ToolbarButton } from '@ohif/ui';
# Toolbar Button
Toolbar Buttons are used to populate the Toolbar.
## Import
```javascript
import { ToolbarButton } from '@ohif/ui';
```
<Playground>
{() => {
const [isActive, setIsActive] = useState(false);
const tool = {
id: 'Zoom',
label: 'Zoom',
icon: 'tool-zoom',
type: null,
commandName: 'setToolActive',
commandOptions: { toolName: 'Zoom' },
onClick: () => setIsActive(true),
isActive,
};
return (
<div className="py-10 flex justify-center">
<ToolbarButton {...tool} />
</div>
);
}}
</Playground>
## Properties
<Props of={ToolbarButton} />
@@ -0,0 +1,2 @@
import ToolbarButton from './ToolbarButton';
export default ToolbarButton;