UNPKG

@carbon/react

Version:

React components for the Carbon Design System

83 lines (75 loc) 2.78 kB
/** * Copyright IBM Corp. 2016, 2023 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js'); var cx = require('classnames'); var usePrefix = require('../../internal/usePrefix.js'); var PropTypes = require('prop-types'); var React = require('react'); var AccordionProvider = require('./AccordionProvider.js'); function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } var cx__default = /*#__PURE__*/_interopDefaultLegacy(cx); var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes); var React__default = /*#__PURE__*/_interopDefaultLegacy(React); function Accordion({ align = 'end', children, className: customClassName, disabled = false, isFlush = false, ordered = false, size, ...rest }) { const prefix = usePrefix.usePrefix(); const className = cx__default["default"](`${prefix}--accordion`, customClassName, { [`${prefix}--accordion--${align}`]: align, [`${prefix}--accordion--${size}`]: size, // TODO: V12 - Remove this class [`${prefix}--layout--size-${size}`]: size, [`${prefix}--accordion--flush`]: isFlush && align !== 'start' }); const ListTag = ordered ? 'ol' : 'ul'; return /*#__PURE__*/React__default["default"].createElement(AccordionProvider.AccordionProvider, { disabled: disabled }, /*#__PURE__*/React__default["default"].createElement(ListTag, _rollupPluginBabelHelpers["extends"]({ className: className }, rest), children)); } Accordion.propTypes = { /** * Specify the alignment of the accordion heading title and chevron. */ align: PropTypes__default["default"].oneOf(['start', 'end']), /** * Pass in the children that will be rendered within the Accordion */ children: PropTypes__default["default"].node, /** * Specify an optional className to be applied to the container node */ className: PropTypes__default["default"].string, /** * Specify whether an individual AccordionItem should be disabled */ disabled: PropTypes__default["default"].bool, /** * Specify whether Accordion text should be flush, default is false, does not work with align="start" */ isFlush: PropTypes__default["default"].bool, /** * Specify if the Accordion should be an ordered list, * default is `false` */ ordered: PropTypes__default["default"].bool, /** * Specify the size of the Accordion. Currently supports the following: */ size: PropTypes__default["default"].oneOf(['sm', 'md', 'lg']) }; exports["default"] = Accordion;