forked from reactstrap/reactstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModalHeader.js
More file actions
64 lines (56 loc) · 1.54 KB
/
ModalHeader.js
File metadata and controls
64 lines (56 loc) · 1.54 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 } from './utils';
const propTypes = {
tag: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
wrapTag: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
toggle: PropTypes.func,
className: PropTypes.string,
cssModule: PropTypes.object,
children: PropTypes.node,
closeAriaLabel: PropTypes.string,
charCode: PropTypes.oneOfType([PropTypes.string, PropTypes.number])
};
const defaultProps = {
tag: 'h5',
wrapTag: 'div',
closeAriaLabel: 'Close',
charCode: 215,
};
const ModalHeader = (props) => {
let closeButton;
const {
className,
cssModule,
children,
toggle,
tag: Tag,
wrapTag: WrapTag,
closeAriaLabel,
charCode,
...attributes } = props;
const classes = mapToCssModules(classNames(
className,
'modal-header'
), cssModule);
if (toggle) {
const closeIcon = typeof charCode === 'number' ? String.fromCharCode(charCode) : charCode;
closeButton = (
<button type="button" onClick={toggle} className={mapToCssModules('close', cssModule)} aria-label={closeAriaLabel}>
<span aria-hidden="true">{closeIcon}</span>
</button>
);
}
return (
<WrapTag {...attributes} className={classes}>
<Tag className={mapToCssModules('modal-title', cssModule)}>
{children}
</Tag>
{closeButton}
</WrapTag>
);
};
ModalHeader.propTypes = propTypes;
ModalHeader.defaultProps = defaultProps;
export default ModalHeader;