-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathInfoPopover.js
102 lines (94 loc) · 2.45 KB
/
InfoPopover.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/**
* InfoPopover
*/
import React from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import { FormattedMessage } from 'react-intl';
import noop from 'lodash/noop';
import Popover from '../Popover';
import Button from '../Button';
import IconButton from '../IconButton';
import css from './InfoPopover.css';
const propTypes = {
allowAnchorClick: PropTypes.bool,
buttonHref: PropTypes.string,
buttonLabel: PropTypes.node,
buttonProps: PropTypes.object,
buttonTarget: PropTypes.string,
content: PropTypes.node,
contentClass: PropTypes.string,
hideOnButtonClick: PropTypes.bool,
iconSize: PropTypes.oneOf(['small', 'medium']),
popperProps: PropTypes.object,
renderTrigger: PropTypes.func,
};
const InfoPopover = ({
content,
contentClass,
allowAnchorClick = false,
iconSize = 'small',
buttonLabel = <FormattedMessage id="stripes-components.readMore" />,
buttonHref,
buttonProps,
buttonTarget = '_blank',
hideOnButtonClick = false,
renderTrigger,
popperProps = {},
...rest
}) => {
const getContentClass = () => classnames(
css.content,
contentClass,
);
const trigger = typeof renderTrigger === 'function' ? renderTrigger :
({ toggle, open, ref }) => (
<IconButton
data-test-info-popover-trigger
className={classnames(css.icon, { [css.open]: open })}
icon="info"
size={iconSize}
iconSize={iconSize}
onClick={toggle}
ref={ref}
{...buttonProps}
/>
);
const renderContent = ({ toggle }) => (/* eslint-disable-line react/prop-types */
<>
<div data-test-info-popover-content className={getContentClass()}>{content}</div>
{buttonHref &&
<Button
data-test-info-popover-button
allowAnchorClick={allowAnchorClick}
onClick={hideOnButtonClick ? toggle : noop}
href={buttonHref}
target={buttonTarget}
buttonStyle="primary"
fullWidth
paddingSide0
marginBottom0
buttonClass={css.button}
>
{buttonLabel}
</Button>
}
</>
);
return (
<Popover
data-test-info-popover
className={css.root}
renderTrigger={trigger}
popperProps={{
portal: document.getElementById('OverlayContainer'),
...popperProps
}}
{...rest}
>
{renderContent}
</Popover>
);
};
InfoPopover.propTypes = propTypes;
export default InfoPopover;