forked from react-bootstrap/react-bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModalHeader.js
More file actions
86 lines (71 loc) · 1.96 KB
/
Copy pathModalHeader.js
File metadata and controls
86 lines (71 loc) · 1.96 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import classNames from 'classnames';
import React from 'react';
import { bsClass, getClassSet, splitBsProps } from './utils/bootstrapUtils';
import createChainedFunction from './utils/createChainedFunction';
// TODO: `aria-label` should be `closeLabel`.
const propTypes = {
/**
* The 'aria-label' attribute provides an accessible label for the close
* button. It is used for Assistive Technology when the label text is not
* readable.
*/
'aria-label': React.PropTypes.string,
/**
* Specify whether the Component should contain a close button
*/
closeButton: React.PropTypes.bool,
/**
* A Callback fired when the close button is clicked. If used directly inside
* a Modal component, the onHide will automatically be propagated up to the
* parent Modal `onHide`.
*/
onHide: React.PropTypes.func,
};
const defaultProps = {
'aria-label': 'Close',
closeButton: false,
};
const contextTypes = {
$bs_modal: React.PropTypes.shape({
onHide: React.PropTypes.func,
}),
};
class ModalHeader extends React.Component {
render() {
const {
'aria-label': label,
closeButton,
onHide,
className,
children,
...props
} = this.props;
const modal = this.context.$bs_modal;
const [bsProps, elementProps] = splitBsProps(props);
const classes = getClassSet(bsProps);
return (
<div
{...elementProps}
className={classNames(className, classes)}
>
{closeButton &&
<button
type="button"
className="close"
aria-label={label}
onClick={createChainedFunction(modal.onHide, onHide)}
>
<span aria-hidden="true">
×
</span>
</button>
}
{children}
</div>
);
}
}
ModalHeader.propTypes = propTypes;
ModalHeader.defaultProps = defaultProps;
ModalHeader.contextTypes = contextTypes;
export default bsClass('modal-header', ModalHeader);