forked from react-bootstrap/react-bootstrap
/
CloseButton.tsx
47 lines (39 loc) · 1.05 KB
/
CloseButton.tsx
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
import PropTypes from 'prop-types';
import * as React from 'react';
import classNames from 'classnames';
export type CloseButtonVariant = 'white' | string;
export interface CloseButtonProps
extends React.ButtonHTMLAttributes<HTMLButtonElement> {
variant?: CloseButtonVariant;
}
const propTypes = {
'aria-label': PropTypes.string,
onClick: PropTypes.func,
/**
* Render different color variant for the button.
*
* Omitting this will render the default dark color.
*/
variant: PropTypes.oneOf<CloseButtonVariant>(['white']),
};
const defaultProps = {
'aria-label': 'Close',
};
const CloseButton = React.forwardRef<HTMLButtonElement, CloseButtonProps>(
({ className, variant, ...props }, ref) => (
<button
ref={ref}
type="button"
className={classNames(
'btn-close',
variant && `btn-close-${variant}`,
className,
)}
{...props}
/>
),
);
CloseButton.displayName = 'CloseButton';
CloseButton.propTypes = propTypes;
CloseButton.defaultProps = defaultProps;
export default CloseButton;