1 | import _Object$assign from "@babel/runtime-corejs2/core-js/object/assign";
|
2 | import _Object$values from "@babel/runtime-corejs2/core-js/object/values";
|
3 | import _extends from "@babel/runtime-corejs2/helpers/esm/extends";
|
4 | import _inheritsLoose from "@babel/runtime-corejs2/helpers/esm/inheritsLoose";
|
5 | import classNames from 'classnames';
|
6 | import PropTypes from 'prop-types';
|
7 | import React from 'react';
|
8 | import uncontrollable from 'uncontrollable';
|
9 | import warning from 'warning';
|
10 | import { bsStyles, bsClass, getClassSet, splitBsPropsAndOmit } from './utils/bootstrapUtils';
|
11 | import { State, Style } from './utils/StyleConfig';
|
12 | import Body from './PanelBody';
|
13 | import Heading from './PanelHeading';
|
14 | import Title from './PanelTitle';
|
15 | import Footer from './PanelFooter';
|
16 | import Toggle from './PanelToggle';
|
17 | import Collapse from './PanelCollapse';
|
18 | var has = Object.prototype.hasOwnProperty;
|
19 |
|
20 | var defaultGetId = function defaultGetId(id, type) {
|
21 | return id ? id + "--" + type : null;
|
22 | };
|
23 |
|
24 | var propTypes = {
|
25 | |
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | expanded: PropTypes.bool,
|
33 |
|
34 | |
35 |
|
36 |
|
37 |
|
38 |
|
39 | onToggle: PropTypes.func,
|
40 | eventKey: PropTypes.any,
|
41 |
|
42 | |
43 |
|
44 |
|
45 | id: PropTypes.string
|
46 | };
|
47 | var contextTypes = {
|
48 | $bs_panelGroup: PropTypes.shape({
|
49 | getId: PropTypes.func,
|
50 | activeKey: PropTypes.any,
|
51 | onToggle: PropTypes.func
|
52 | })
|
53 | };
|
54 | var childContextTypes = {
|
55 | $bs_panel: PropTypes.shape({
|
56 | headingId: PropTypes.string,
|
57 | bodyId: PropTypes.string,
|
58 | bsClass: PropTypes.string,
|
59 | onToggle: PropTypes.func,
|
60 | expanded: PropTypes.bool
|
61 | })
|
62 | };
|
63 |
|
64 | var Panel =
|
65 |
|
66 | function (_React$Component) {
|
67 | _inheritsLoose(Panel, _React$Component);
|
68 |
|
69 | function Panel() {
|
70 | var _this;
|
71 |
|
72 | for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
73 | args[_key] = arguments[_key];
|
74 | }
|
75 |
|
76 | _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
|
77 |
|
78 | _this.handleToggle = function (e) {
|
79 | var panelGroup = _this.context.$bs_panelGroup;
|
80 | var expanded = !_this.getExpanded();
|
81 |
|
82 | if (panelGroup && panelGroup.onToggle) {
|
83 | panelGroup.onToggle(_this.props.eventKey, expanded, e);
|
84 | } else {
|
85 | _this.props.onToggle(expanded, e);
|
86 | }
|
87 | };
|
88 |
|
89 | return _this;
|
90 | }
|
91 |
|
92 | var _proto = Panel.prototype;
|
93 |
|
94 | _proto.getChildContext = function getChildContext() {
|
95 | var _this$props = this.props,
|
96 | eventKey = _this$props.eventKey,
|
97 | id = _this$props.id;
|
98 | var idKey = eventKey == null ? id : eventKey;
|
99 | var ids;
|
100 |
|
101 | if (idKey !== null) {
|
102 | var panelGroup = this.context.$bs_panelGroup;
|
103 | var getId = panelGroup && panelGroup.getId || defaultGetId;
|
104 | ids = {
|
105 | headingId: getId(idKey, 'heading'),
|
106 | bodyId: getId(idKey, 'body')
|
107 | };
|
108 | }
|
109 |
|
110 | return {
|
111 | $bs_panel: _extends({}, ids, {
|
112 | bsClass: this.props.bsClass,
|
113 | expanded: this.getExpanded(),
|
114 | onToggle: this.handleToggle
|
115 | })
|
116 | };
|
117 | };
|
118 |
|
119 | _proto.getExpanded = function getExpanded() {
|
120 | var panelGroup = this.context.$bs_panelGroup;
|
121 |
|
122 | if (panelGroup && has.call(panelGroup, 'activeKey')) {
|
123 | process.env.NODE_ENV !== "production" ? warning(this.props.expanded == null, 'Specifying `<Panel>` `expanded` in the context of an accordion ' + '`<PanelGroup>` is not supported. Set `activeKey` on the ' + '`<PanelGroup>` instead.') : void 0;
|
124 | return panelGroup.activeKey === this.props.eventKey;
|
125 | }
|
126 |
|
127 | return !!this.props.expanded;
|
128 | };
|
129 |
|
130 | _proto.render = function render() {
|
131 | var _this$props2 = this.props,
|
132 | className = _this$props2.className,
|
133 | children = _this$props2.children;
|
134 |
|
135 | var _splitBsPropsAndOmit = splitBsPropsAndOmit(this.props, ['onToggle', 'eventKey', 'expanded']),
|
136 | bsProps = _splitBsPropsAndOmit[0],
|
137 | props = _splitBsPropsAndOmit[1];
|
138 |
|
139 | return React.createElement("div", _extends({}, props, {
|
140 | className: classNames(className, getClassSet(bsProps))
|
141 | }), children);
|
142 | };
|
143 |
|
144 | return Panel;
|
145 | }(React.Component);
|
146 |
|
147 | Panel.propTypes = propTypes;
|
148 | Panel.contextTypes = contextTypes;
|
149 | Panel.childContextTypes = childContextTypes;
|
150 | var UncontrolledPanel = uncontrollable(bsClass('panel', bsStyles(_Object$values(State).concat([Style.DEFAULT, Style.PRIMARY]), Style.DEFAULT, Panel)), {
|
151 | expanded: 'onToggle'
|
152 | });
|
153 |
|
154 | _Object$assign(UncontrolledPanel, {
|
155 | Heading: Heading,
|
156 | Title: Title,
|
157 | Body: Body,
|
158 | Footer: Footer,
|
159 | Toggle: Toggle,
|
160 | Collapse: Collapse
|
161 | });
|
162 |
|
163 | export default UncontrolledPanel; |
\ | No newline at end of file |