UNPKG

3.01 kBJavaScriptView Raw
1var _excluded = ["flush", "open", "toggle", "className", "cssModule", "tag", "innerRef"];
2function _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); }
3function _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; }
4function _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; }
5import React, { useMemo } from 'react';
6import PropTypes from 'prop-types';
7import classNames from 'classnames';
8import { mapToCssModules, tagPropType } from './utils';
9import { AccordionContext } from './AccordionContext';
10var propTypes = {
11 children: PropTypes.node,
12 /** Add custom class */
13 className: PropTypes.string,
14 /** Change existing className with a new className */
15 cssModule: PropTypes.object,
16 /** Render accordions edge-to-edge with their parent container */
17 flush: PropTypes.bool,
18 innerRef: PropTypes.oneOfType([PropTypes.object, PropTypes.string, PropTypes.func]),
19 /** The current active key that corresponds to the currently expanded card */
20 open: PropTypes.oneOfType([PropTypes.array, PropTypes.string]).isRequired,
21 /** Set a custom element for this component */
22 tag: tagPropType,
23 /** Function that's triggered on clicking `AccordionHeader` */
24 toggle: PropTypes.func.isRequired
25};
26function 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 /*#__PURE__*/React.createElement(AccordionContext.Provider, {
46 value: accordionContext
47 }, /*#__PURE__*/React.createElement(Tag, _extends({}, attributes, {
48 className: classes,
49 ref: innerRef
50 })));
51}
52Accordion.propTypes = propTypes;
53export default Accordion;
\No newline at end of file