-
-
Notifications
You must be signed in to change notification settings - Fork 503
Expand file tree
/
Copy pathContextMenuItem.jsx
More file actions
43 lines (36 loc) · 974 Bytes
/
ContextMenuItem.jsx
File metadata and controls
43 lines (36 loc) · 974 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import cls from "classnames";
import PropTypes from "prop-types";
import * as styles from "./ContextMenuItem.css";
/**
* @returns {boolean} nothing
*/
function noop() {
return false;
}
/**
* @typedef {object} ContextMenuItemProps
* @property {React.ReactNode} children children
* @property {boolean=} disabled - true when disabled, otherwise false
* @property {React.MouseEventHandler<HTMLLIElement>=} onClick on click handler
*/
/**
* @param {ContextMenuItemProps} props props
* @returns {JSX.Element} context menu item
*/
export default function ContextMenuItem({ children, disabled, onClick }) {
const className = cls({
[styles.item]: true,
[styles.disabled]: disabled,
});
const handler = disabled ? noop : onClick;
return (
<li className={className} onClick={handler}>
{children}
</li>
);
}
ContextMenuItem.propTypes = {
disabled: PropTypes.bool,
children: PropTypes.node.isRequired,
onClick: PropTypes.func,
};