web: Added clickAction property to GroupButton component

This commit is contained in:
Ilya Oleshko 2019-06-10 14:29:51 +03:00
parent 369825607e
commit f05abd2d84
3 changed files with 8 additions and 9 deletions

View File

@ -26,4 +26,5 @@ Base Button is used for a group action on a page.
| `isCheckbox` | `bool` | - | - | `false` | Tells when the button should present a checkbox state |
| `isDropdown` | `bool` | - | - | `false` | Tells when the button should present a dropdown state |
| `splitted` | `bool` | - | - | `false` | Tells when the button should present a dropdown state with button |
| `opened` | `bool` | - | - | `false` | Tells when the button should be opened by default |
| `opened` | `bool` | - | - | `false` | Tells when the button should be opened by default |
| `clickAction` | `func` | - | - | - | What the button will trigger when clicked |

View File

@ -174,10 +174,6 @@ const Caret = styled(Icons.ExpanderDownIcon)`
}
`;
const clickAction = (e) => {
console.log('Button "' + e.target.innerText + '" clicked!');
}
const useOuterClickNotifier = (onOuterClick, ref) => {
useEffect(() => {
const handleClick = (e) => !ref.current.contains(e.target) && onOuterClick(e);
@ -193,7 +189,7 @@ const useOuterClickNotifier = (onOuterClick, ref) => {
}
const GroupButton = (props) => {
const { text, children, splitted, isDropdown, isCheckbox, opened, disabled, primary } = props;
const { text, children, splitted, isDropdown, isCheckbox, opened, disabled, primary, clickAction } = props;
const [isOpen, toggle] = useState(opened);
const ref = useRef(null);
@ -261,7 +257,8 @@ GroupButton.propTypes = {
splitted: PropTypes.bool,
isCheckbox: PropTypes.bool,
isDropdown: PropTypes.bool,
tabIndex: PropTypes.number
tabIndex: PropTypes.number,
clickAction: PropTypes.func
};
GroupButton.defaultProps = {
@ -274,7 +271,8 @@ GroupButton.defaultProps = {
splitted: false,
isCheckbox: false,
isDropdown: false,
tabIndex: -1
tabIndex: -1,
clickAction: (e) => console.log('Button "' + e.target.innerText + '" clicked!')
};
export default GroupButton

View File

@ -6,4 +6,4 @@ export { default as NavMenu } from './components/nav-menu'
export { default as ModuleTile } from './components/module-tile'
export { default as Loader } from './components/loader'
export { Icons } from './components/icons'
export { default as GroupButton } from './components/group-button'
export { default as GroupButton } from './components/group-button'