UNPKG

@carbon/react

Version:

React components for the Carbon Design System

77 lines (71 loc) 2.27 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 Accordion({ align = 'end', children, className: customClassName, disabled = false, isFlush = false, ordered = false, size, ...rest }) { const prefix = usePrefix.usePrefix(); const className = cx(`${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.createElement(AccordionProvider.AccordionProvider, { disabled: disabled }, /*#__PURE__*/React.createElement(ListTag, _rollupPluginBabelHelpers.extends({ className: className }, rest), children)); } Accordion.propTypes = { /** * Specify the alignment of the accordion heading title and chevron. */ align: PropTypes.oneOf(['start', 'end']), /** * Pass in the children that will be rendered within the Accordion */ children: PropTypes.node, /** * Specify an optional className to be applied to the container node */ className: PropTypes.string, /** * Specify whether an individual AccordionItem should be disabled */ disabled: PropTypes.bool, /** * Specify whether Accordion text should be flush, default is false, does not work with align="start" */ isFlush: PropTypes.bool, /** * Specify if the Accordion should be an ordered list, * default is `false` */ ordered: PropTypes.bool, /** * Specify the size of the Accordion. Currently supports the following: */ size: PropTypes.oneOf(['sm', 'md', 'lg']) }; exports.default = Accordion;