UNPKG

2.76 kBJavaScriptView Raw
1import _extends from 'babel-runtime/helpers/extends';
2import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
3import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
4import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
5import _inherits from 'babel-runtime/helpers/inherits';
6import classNames from 'classnames';
7import PropTypes from 'prop-types';
8import React from 'react';
9
10import { bsClass, getClassSet, splitBsProps } from './utils/bootstrapUtils';
11import createChainedFunction from './utils/createChainedFunction';
12import CloseButton from './CloseButton';
13
14// TODO: `aria-label` should be `closeLabel`.
15
16var propTypes = {
17 /**
18 * Provides an accessible label for the close
19 * button. It is used for Assistive Technology when the label text is not
20 * readable.
21 */
22 closeLabel: PropTypes.string,
23
24 /**
25 * Specify whether the Component should contain a close button
26 */
27 closeButton: PropTypes.bool,
28
29 /**
30 * A Callback fired when the close button is clicked. If used directly inside
31 * a Modal component, the onHide will automatically be propagated up to the
32 * parent Modal `onHide`.
33 */
34 onHide: PropTypes.func
35};
36
37var defaultProps = {
38 closeLabel: 'Close',
39 closeButton: false
40};
41
42var contextTypes = {
43 $bs_modal: PropTypes.shape({
44 onHide: PropTypes.func
45 })
46};
47
48var ModalHeader = function (_React$Component) {
49 _inherits(ModalHeader, _React$Component);
50
51 function ModalHeader() {
52 _classCallCheck(this, ModalHeader);
53
54 return _possibleConstructorReturn(this, _React$Component.apply(this, arguments));
55 }
56
57 ModalHeader.prototype.render = function render() {
58 var _props = this.props,
59 closeLabel = _props.closeLabel,
60 closeButton = _props.closeButton,
61 onHide = _props.onHide,
62 className = _props.className,
63 children = _props.children,
64 props = _objectWithoutProperties(_props, ['closeLabel', 'closeButton', 'onHide', 'className', 'children']);
65
66 var modal = this.context.$bs_modal;
67
68 var _splitBsProps = splitBsProps(props),
69 bsProps = _splitBsProps[0],
70 elementProps = _splitBsProps[1];
71
72 var classes = getClassSet(bsProps);
73
74 return React.createElement(
75 'div',
76 _extends({}, elementProps, { className: classNames(className, classes) }),
77 closeButton && React.createElement(CloseButton, {
78 label: closeLabel,
79 onClick: createChainedFunction(modal && modal.onHide, onHide)
80 }),
81 children
82 );
83 };
84
85 return ModalHeader;
86}(React.Component);
87
88ModalHeader.propTypes = propTypes;
89ModalHeader.defaultProps = defaultProps;
90ModalHeader.contextTypes = contextTypes;
91
92export default bsClass('modal-header', ModalHeader);
\No newline at end of file