UNPKG

@helpscout/hsds-react

Version:

React component library for Help Scout's Design System

80 lines (64 loc) 2.48 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); exports.__esModule = true; exports.default = exports.AccordionLink = void 0; var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose")); var _react = _interopRequireDefault(require("react")); var _propTypes = _interopRequireDefault(require("prop-types")); var _Accordion = _interopRequireDefault(require("./Accordion.Section")); var _Accordion2 = _interopRequireDefault(require("./Accordion.Title")); var _Accordion3 = require("./Accordion.utils"); var _jsxRuntime = require("react/jsx-runtime"); // Higher-order wrapper to render an enhanced Accordion.Section and Accordion.Title var AccordionLink = function AccordionLink(props) { var badge = props.badge, children = props.children, href = props.href, isCompact = props.isCompact, status = props.status, title = props.title, to = props.to, rest = (0, _objectWithoutPropertiesLoose2.default)(props, ["badge", "children", "href", "isCompact", "status", "title", "to"]); var isLink = !!(to || href); var isOpen = false; var sectionProps = (0, _extends2.default)({}, rest, { children: children, isOpen: isOpen, isLink: isLink, status: status, title: title }); var titleProps = { badge: badge, href: href, isCompact: isCompact, isOpen: isOpen, status: status, title: title, to: to }; return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Accordion.default, (0, _extends2.default)({}, sectionProps, { children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Accordion2.default, (0, _extends2.default)({}, titleProps, { children: (0, _Accordion3.renderChildrenSafely)(children) })) })); }; exports.AccordionLink = AccordionLink; AccordionLink.defaultProps = { 'data-cy': 'AccordionLink' }; AccordionLink.propTypes = { /** Content to render. */ children: _propTypes.default.any, /** Custom class names to be added to the component. */ className: _propTypes.default.string, /** Renders a `Link` with an href. */ href: _propTypes.default.string, /** Renders a routable `Link` with an href. */ to: _propTypes.default.string, /** Data attr for Cypress tests. */ 'data-cy': _propTypes.default.string }; var _default = AccordionLink; exports.default = _default;