-
Notifications
You must be signed in to change notification settings - Fork 9
/
TriggerButton.js
46 lines (39 loc) · 1.11 KB
/
TriggerButton.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
import React from "react";
import PropTypes from "prop-types";
import Button from "@paprika/button";
const propTypes = {
children: PropTypes.node,
confirmId: PropTypes.string,
icon: PropTypes.node,
isConfirmOpen: PropTypes.bool.isRequired,
onOpenConfirm: PropTypes.func.isRequired,
triggerRef: PropTypes.shape({ current: PropTypes.instanceOf(Object) }),
};
const defaultProps = {
children: null,
confirmId: null,
icon: null,
triggerRef: null,
};
const TriggerButton = props => {
const { icon, isConfirmOpen, children, onOpenConfirm, confirmId, triggerRef, ...moreProps } = props;
const TriggerComponent = icon ? Button.Icon : Button;
return (
<TriggerComponent
ref={triggerRef}
aria-controls={confirmId}
aria-expanded={isConfirmOpen}
aria-haspopup="true"
isSquare
isSemantic={false}
onClick={onOpenConfirm}
{...moreProps}
>
{icon || children}
</TriggerComponent>
);
};
TriggerButton.displayName = "Confirmation.TriggerButton";
TriggerButton.defaultProps = defaultProps;
TriggerButton.propTypes = propTypes;
export default TriggerButton;