-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathModalHeader.js
More file actions
64 lines (57 loc) · 1.43 KB
/
ModalHeader.js
File metadata and controls
64 lines (57 loc) · 1.43 KB
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
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { mapToCssModules, tagPropType } from './utils';
const propTypes = {
children: PropTypes.node,
/** Add custom class */
className: PropTypes.string,
/** Custom close button */
close: PropTypes.object,
closeAriaLabel: PropTypes.string,
/** Change underlying component's CSS base class name */
cssModule: PropTypes.object,
/** Set a custom element for this component */
tag: tagPropType,
/** Function to be triggered when close button is clicked */
toggle: PropTypes.func,
wrapTag: tagPropType,
};
function ModalHeader(props) {
let closeButton;
const {
className,
cssModule,
children,
toggle,
tag: Tag = 'h5',
wrapTag: WrapTag = 'div',
closeAriaLabel = 'Close',
close,
...attributes
} = props;
const classes = mapToCssModules(
classNames(className, 'modal-header'),
cssModule,
);
if (!close && toggle) {
closeButton = (
<button
type="button"
onClick={toggle}
className={mapToCssModules('btn-close', cssModule)}
aria-label={closeAriaLabel}
/>
);
}
return (
<WrapTag {...attributes} className={classes}>
<Tag className={mapToCssModules('modal-title', cssModule)}>
{children}
</Tag>
{close || closeButton}
</WrapTag>
);
}
ModalHeader.propTypes = propTypes;
export default ModalHeader;