Skip to content

Commit

Permalink
feat: add callback functions to menu button
Browse files Browse the repository at this point in the history
  • Loading branch information
orrgottlieb committed Jan 26, 2021
1 parent 9e69c62 commit 4432cdc
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
1 change: 1 addition & 0 deletions .storybook/preview-body.html
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
<div id="dropdown-portal"></div>
<div id="tooltips-container"></div>
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "monday-ui-react-core",
"version": "0.0.61",
"version": "0.0.62",
"description": "Official monday.com UI resources for application development in React.js",
"main": "dist/main.js",
"scripts": {
Expand Down
28 changes: 22 additions & 6 deletions src/components/MenuButton/MenuButton.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React, { useCallback, useState, useMemo } from "react";
import PropTypes from "prop-types";
import cx from "classnames";
import NOOP from "lodash/noop";
import Dialog from "../Dialog/Dialog";
import Menu from "../Icon/Icons/components/Menu";
import "./MenuButton.scss";
import DialogContentContainer from "../DialogContentContainer/DialogContentContainer";
import "./MenuButton.scss";

function BEMClass(className) {
return `menu-button--wrapper--${className}`;
Expand All @@ -26,16 +27,21 @@ const MenuButton = ({
dialogOffset,
dialogPosition,
dialogClassName,
dialogPaddingSize
dialogPaddingSize,
onMenuHide,
onMenuShow
}) => {
const [isOpen, setIsOpen] = useState(open);

const onDialogDidHide = useCallback(() => {
setIsOpen(false);
}, [setIsOpen]);
onMenuHide();
}, [setIsOpen, onMenuHide]);

const onDialogDidShow = useCallback(() => {
setIsOpen(true);
}, [setIsOpen]);
onMenuShow();
}, [setIsOpen, onMenuShow]);

const hideTrigger = useMemo(() => {
const triggers = ["clickoutside", "esckey"];
Expand Down Expand Up @@ -156,7 +162,15 @@ MenuButton.propTypes = {
MenuButton.dialogPositions.BOTTOM_START,
MenuButton.dialogPositions.BOTTOM,
MenuButton.dialogPositions.BOTTOM_END
])
]),
/*
Callback function to be called when the menu is shown
*/
onMenuShow: PropTypes.func,
/*
Callback function to be called when the menu is shown
*/
onMenuHide: PropTypes.func
};
MenuButton.defaultProps = {
componentClassName: "",
Expand All @@ -170,7 +184,9 @@ MenuButton.defaultProps = {
openDialogComponentClassName: "",
dialogOffset: MOVE_BY,
dialogPaddingSize: DialogContentContainer.sizes.MEDIUM,
dialogPosition: MenuButton.dialogPositions.BOTTOM_START
dialogPosition: MenuButton.dialogPositions.BOTTOM_START,
onMenuShow: NOOP,
onMenuHide: NOOP
};

export default MenuButton;

0 comments on commit 4432cdc

Please sign in to comment.