1 | import _objectWithoutPropertiesLoose from "@babel/runtime-corejs2/helpers/esm/objectWithoutPropertiesLoose";
|
2 | import _inheritsLoose from "@babel/runtime-corejs2/helpers/esm/inheritsLoose";
|
3 | import _assertThisInitialized from "@babel/runtime-corejs2/helpers/esm/assertThisInitialized";
|
4 | import PropTypes from 'prop-types';
|
5 | import React from 'react';
|
6 | import classNames from 'classnames';
|
7 | import elementType from 'react-prop-types/lib/elementType';
|
8 | import SafeAnchor from './SafeAnchor';
|
9 | import createChainedFunction from './utils/createChainedFunction';
|
10 | var propTypes = {
|
11 | |
12 |
|
13 |
|
14 |
|
15 |
|
16 | onClick: PropTypes.func,
|
17 |
|
18 | |
19 |
|
20 |
|
21 | componentClass: elementType
|
22 | };
|
23 | var defaultProps = {
|
24 | componentClass: SafeAnchor
|
25 | };
|
26 | var contextTypes = {
|
27 | $bs_panel: PropTypes.shape({
|
28 | bodyId: PropTypes.string,
|
29 | onToggle: PropTypes.func,
|
30 | expanded: PropTypes.bool
|
31 | })
|
32 | };
|
33 |
|
34 | var PanelToggle =
|
35 |
|
36 | function (_React$Component) {
|
37 | _inheritsLoose(PanelToggle, _React$Component);
|
38 |
|
39 | function PanelToggle() {
|
40 | var _this;
|
41 |
|
42 | for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
43 | args[_key] = arguments[_key];
|
44 | }
|
45 |
|
46 | _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
|
47 | _this.handleToggle = _this.handleToggle.bind(_assertThisInitialized(_assertThisInitialized(_this)));
|
48 | return _this;
|
49 | }
|
50 |
|
51 | var _proto = PanelToggle.prototype;
|
52 |
|
53 | _proto.handleToggle = function handleToggle(event) {
|
54 | var _ref = this.context.$bs_panel || {},
|
55 | onToggle = _ref.onToggle;
|
56 |
|
57 | if (onToggle) {
|
58 | onToggle(event);
|
59 | }
|
60 | };
|
61 |
|
62 | _proto.render = function render() {
|
63 | var _this$props = this.props,
|
64 | onClick = _this$props.onClick,
|
65 | className = _this$props.className,
|
66 | componentClass = _this$props.componentClass,
|
67 | props = _objectWithoutPropertiesLoose(_this$props, ["onClick", "className", "componentClass"]);
|
68 |
|
69 | var _ref2 = this.context.$bs_panel || {},
|
70 | expanded = _ref2.expanded,
|
71 | bodyId = _ref2.bodyId;
|
72 |
|
73 | var Component = componentClass;
|
74 | props.onClick = createChainedFunction(onClick, this.handleToggle);
|
75 | props['aria-expanded'] = expanded;
|
76 | props.className = classNames(className, !expanded && 'collapsed');
|
77 |
|
78 | if (bodyId) {
|
79 | props['aria-controls'] = bodyId;
|
80 | }
|
81 |
|
82 | return React.createElement(Component, props);
|
83 | };
|
84 |
|
85 | return PanelToggle;
|
86 | }(React.Component);
|
87 |
|
88 | PanelToggle.propTypes = propTypes;
|
89 | PanelToggle.defaultProps = defaultProps;
|
90 | PanelToggle.contextTypes = contextTypes;
|
91 | export default PanelToggle; |
\ | No newline at end of file |