1 | var _excluded = ["className", "cssModule", "tag", "innerRef", "children", "targetId"];
|
2 | function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
3 | function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
4 | function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
5 | import React, { useContext } from 'react';
|
6 | import PropTypes from 'prop-types';
|
7 | import classNames from 'classnames';
|
8 | import { mapToCssModules, tagPropType } from './utils';
|
9 | import { AccordionContext } from './AccordionContext';
|
10 | var propTypes = {
|
11 | children: PropTypes.node,
|
12 |
|
13 | className: PropTypes.string,
|
14 |
|
15 | cssModule: PropTypes.object,
|
16 | innerRef: PropTypes.oneOfType([PropTypes.object, PropTypes.string, PropTypes.func]),
|
17 |
|
18 | tag: tagPropType,
|
19 |
|
20 | targetId: PropTypes.string.isRequired
|
21 | };
|
22 | function AccordionHeader(props) {
|
23 | var className = props.className,
|
24 | cssModule = props.cssModule,
|
25 | _props$tag = props.tag,
|
26 | Tag = _props$tag === void 0 ? 'h2' : _props$tag,
|
27 | innerRef = props.innerRef,
|
28 | children = props.children,
|
29 | targetId = props.targetId,
|
30 | attributes = _objectWithoutProperties(props, _excluded);
|
31 | var _useContext = useContext(AccordionContext),
|
32 | open = _useContext.open,
|
33 | toggle = _useContext.toggle;
|
34 | var classes = mapToCssModules(classNames(className, 'accordion-header'), cssModule);
|
35 | var buttonClasses = mapToCssModules(classNames('accordion-button', {
|
36 | collapsed: !(Array.isArray(open) ? open.includes(targetId) : open === targetId)
|
37 | }), cssModule);
|
38 | return React.createElement(Tag, _extends({}, attributes, {
|
39 | className: classes,
|
40 | ref: innerRef
|
41 | }), React.createElement("button", {
|
42 | type: "button",
|
43 | className: buttonClasses,
|
44 | onClick: function onClick() {
|
45 | return toggle(targetId);
|
46 | }
|
47 | }, children));
|
48 | }
|
49 | AccordionHeader.propTypes = propTypes;
|
50 | export default AccordionHeader; |
\ | No newline at end of file |