-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Copy pathBaseMiniContextMenuItem.js
80 lines (71 loc) · 2.42 KB
/
BaseMiniContextMenuItem.js
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import {Pressable, View} from 'react-native';
import React from 'react';
import PropTypes from 'prop-types';
import _ from 'underscore';
import styles from '../styles/styles';
import * as StyleUtils from '../styles/StyleUtils';
import getButtonState from '../libs/getButtonState';
import variables from '../styles/variables';
import Tooltip from './Tooltip';
const propTypes = {
/**
* Text to display when hovering the menu item
*/
tooltipText: PropTypes.string.isRequired,
/**
* Callback to fire on press
*/
onPress: PropTypes.func.isRequired,
/**
* The children to display within the menu item
*/
children: PropTypes.oneOfType([PropTypes.func, PropTypes.node]).isRequired,
/**
* Whether the button should be in the active state
*/
isDelayButtonStateComplete: PropTypes.bool,
/**
* A ref to forward to the Pressable
*/
innerRef: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
};
const defaultProps = {
isDelayButtonStateComplete: true,
innerRef: () => {},
};
/**
* Component that renders a mini context menu item with a
* pressable. Also renders a tooltip when hovering the item.
* @param {Object} props
* @returns {JSX.Element}
*/
const BaseMiniContextMenuItem = (props) => (
<Tooltip text={props.tooltipText}>
<Pressable
ref={props.innerRef}
focusable
onPress={props.onPress}
accessibilityLabel={props.tooltipText}
style={({hovered, pressed}) => [
styles.reportActionContextMenuMiniButton,
StyleUtils.getButtonBackgroundColorStyle(getButtonState(hovered, pressed, props.isDelayButtonStateComplete)),
]}
>
{(pressableState) => (
<View style={[StyleUtils.getWidthAndHeightStyle(variables.iconSizeNormal), styles.alignItemsCenter, styles.justifyContentCenter]}>
{_.isFunction(props.children) ? props.children(pressableState) : props.children}
</View>
)}
</Pressable>
</Tooltip>
);
BaseMiniContextMenuItem.propTypes = propTypes;
BaseMiniContextMenuItem.defaultProps = defaultProps;
BaseMiniContextMenuItem.displayName = 'BaseMiniContextMenuItem';
export default React.forwardRef((props, ref) => (
<BaseMiniContextMenuItem
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
innerRef={ref}
/>
));