1 | var _excluded = ["flush", "open", "toggle", "className", "cssModule", "tag", "innerRef"];
|
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, { useMemo } 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 |
|
17 | flush: PropTypes.bool,
|
18 | innerRef: PropTypes.oneOfType([PropTypes.object, PropTypes.string, PropTypes.func]),
|
19 |
|
20 | open: PropTypes.oneOfType([PropTypes.array, PropTypes.string]).isRequired,
|
21 |
|
22 | tag: tagPropType,
|
23 |
|
24 | toggle: PropTypes.func.isRequired
|
25 | };
|
26 | function Accordion(props) {
|
27 | var flush = props.flush,
|
28 | open = props.open,
|
29 | toggle = props.toggle,
|
30 | className = props.className,
|
31 | cssModule = props.cssModule,
|
32 | _props$tag = props.tag,
|
33 | Tag = _props$tag === void 0 ? 'div' : _props$tag,
|
34 | innerRef = props.innerRef,
|
35 | attributes = _objectWithoutProperties(props, _excluded);
|
36 | var classes = mapToCssModules(classNames(className, 'accordion', {
|
37 | 'accordion-flush': flush
|
38 | }), cssModule);
|
39 | var accordionContext = useMemo(function () {
|
40 | return {
|
41 | open: open,
|
42 | toggle: toggle
|
43 | };
|
44 | });
|
45 | return React.createElement(AccordionContext.Provider, {
|
46 | value: accordionContext
|
47 | }, React.createElement(Tag, _extends({}, attributes, {
|
48 | className: classes,
|
49 | ref: innerRef
|
50 | })));
|
51 | }
|
52 | Accordion.propTypes = propTypes;
|
53 | export default Accordion; |
\ | No newline at end of file |