{"version":3,"file":"Accordion.mjs","sources":["../../../src/components/Accordion/Accordion.tsx"],"sourcesContent":["import {\n  Disclosure,\n  DisclosureButton,\n  DisclosurePanel,\n} from '@headlessui/react';\nimport clsx from 'clsx';\nimport React, { createContext, useContext } from 'react';\nimport type { ReactNode } from 'react';\nimport { ENTER_KEYCODE, SPACEBAR_KEYCODE } from '../../util/keycodes';\nimport {\n  assertEdsUsage,\n  assertNoRemovedIconProp,\n  type WithRemovedIconProps,\n} from '../../util/logging';\nimport type { IconOrContent } from '../../util/utility-types';\n\nimport Heading, { type HeadingElement } from '../Heading';\nimport { hasSlotContent, IconSlot, useSemanticIcon } from '../Icon';\nimport Text from '../Text';\n\nimport styles from './Accordion.module.css';\n\ntype AccordionProps = {\n  // Component API\n  /**\n   * Child node(s) that can be nested inside component.\n   */\n  children: ReactNode;\n  /**\n   * Additional classnames passed in for styling.\n   */\n  className?: string;\n  // Design API\n  /**\n   * Used to specify which heading element should be rendered for each `Accordion.Title` child.\n   *\n   * **Default is `\"h2\"`**.\n   */\n  headingAs: HeadingElement;\n};\n\ntype AccordionButtonProps = {\n  // Component API\n  /**\n   * Child node(s) that can be nested inside component.\n   */\n  children?: ReactNode;\n  /**\n   * Additional classnames passed in for styling\n   */\n  className?: string;\n  /**\n   * Callback for when accordion is closed.\n   */\n  onClose?: () => void;\n  /**\n   * Callback for when according is opened.\n   */\n  onOpen?: () => void;\n  // Design API\n  /**\n   * Used to specify which heading element should be rendered for the title.\n   * If provided, overrides parent <Accordion> headingAs prop.\n   */\n  headingAs?: HeadingElement;\n  /**\n   * Content that precedes the text in an accordion header. Pass an EDS icon name to render\n   * a decorative icon, or a node to render it as-is.\n   */\n  leadingContent?: IconOrContent;\n  /**\n   * Secondary text used to describe the content in more detail\n   */\n  subTitle?: ReactNode;\n  /**\n   * The title/heading of the component\n   */\n  title?: string;\n  /**\n   * Slot which follows the text in an accordion header\n   */\n  trailingContent?: ReactNode;\n};\n\ntype AccordionPanelProps = {\n  /**\n   * Child node(s) that can be nested inside component.\n   */\n  children: ReactNode;\n  /**\n   * Additional class names passed in for styling\n   */\n  className?: string;\n};\n\ntype AccordionRowProps = {\n  /**\n   * Child node(s) that can be nested inside component.\n   */\n  children: ReactNode | (({ open }: { open: boolean }) => ReactNode);\n  /**\n   * Additional class names passed in for styling.\n   */\n  className?: string;\n  /**\n   * Whether panel is expanded by default.\n   */\n  defaultOpen?: boolean;\n  /**\n   * Whether the row can show expandable content\n   */\n  isExpandable?: boolean;\n  /**\n   * Whether the row has content on the row's trigger that leads in front of the title\n   */\n  hasLeadingContent?: boolean;\n  /**\n   * Whether the row has a content on the row's trigger that trails the title\n   */\n  hasTrailingContent?: boolean;\n};\n\nconst AccordionContext = createContext<{\n  headingAs: HeadingElement;\n}>({\n  headingAs: 'h2',\n});\n\nconst AccordionRowContext = createContext<\n  Pick<\n    AccordionRowProps,\n    'isExpandable' | 'hasLeadingContent' | 'hasTrailingContent'\n  >\n>({\n  isExpandable: true,\n  hasLeadingContent: false,\n  hasTrailingContent: false,\n});\n\n/**\n * ## Usage\n *\n * * **Reducing visual clutter**: Especially when dealing with long pages or dense content.\n * * **FAQs**: Users can click to reveal answers one at a time.\n * * **Grouped settings**: Like categories of options or configuration panels.\n *\n * | Type/Use | Description | Example |\n * |----------|-------------|---------|\n * |Standard|Expands/collapses content vertically when clicked.|FAQs. Lists with optional detail. Simple disclosure sections.|\n * |Multi-expand|Allows multiple sections to be expanded at once.|Filter panels. Settings grouped by category. Multi-topic summaries.|\n * |Single-Expand|Only one section can be open at a time (others collapse automatically).|Navigation menus. Step-by-step instructions. Content prioritization.|\n * |Nested|Accordion items contain sub-accordions inside.|Complex data views. Multi-level navigation or documentation.|\n * |Summary|Shows a brief summary even when collapsed.|Preview content like stats or status. Highlight key info without expanding.|\n * |Disabled|Cannot be expanded; often used to show unavailable or locked content.|Permissions-based content. Progress-dependent sections.|\n *\n * ### Best Practices\n *\n * * Don't mix accordions where some have icons and others do not.\n *\n * ## Interaction\n *\n * ### Collapsed and Expanded Rows\n *\n * By default, clicking another row does not collapse the row that has already been expanded.\n * Designers can customize this  to only allow 1 accordion row to be open at a time. However, beware that this interaction can cause the UI to “jump around” in an unpleasant way.\n *\n * ## Content & Accessibility\n *\n * ### Do's\n *\n * * Order stacked accordions by priority and importance.\n * * Use short, descriptive text for the accordion title.\n * * Number the steps in the accordion section sequentially.\n * * Use paragraphs and subheads as needed within the accordion body.\n * * Use sentence case for titles.\n *\n * ### Don'ts\n *\n * * Don't use paragraphs of text in the accordion title.\n *\n * ## Resources\n *\n * * https://headlessui.com/react/disclosure\n */\nexport const Accordion = ({\n  children,\n  className,\n  headingAs,\n  ...other\n}: AccordionProps) => {\n  return (\n    <AccordionContext.Provider value={{ headingAs }}>\n      <div className={className} {...other}>\n        {children}\n      </div>\n    </AccordionContext.Provider>\n  );\n};\n\nconst AccordionButton = (props: AccordionButtonProps) => {\n  const {\n    children,\n    className,\n    headingAs,\n    leadingContent,\n    title,\n    trailingContent,\n    subTitle,\n    onClose,\n    onOpen,\n    // TODO(next-major): remove these two, with the asserts below.\n    indicatorContent: removedIndicatorContent,\n    trailingIcon: removedTrailingIcon,\n    ...other\n  } = props as WithRemovedIconProps<\n    AccordionButtonProps,\n    'indicatorContent' | 'trailingIcon'\n  >;\n\n  // TODO(next-major): remove.\n  assertNoRemovedIconProp(\n    'Accordion.Button',\n    'indicatorContent',\n    'expand',\n    removedIndicatorContent,\n  );\n  // TODO(next-major): remove.\n  assertNoRemovedIconProp(\n    'Accordion.Button',\n    'trailingIcon',\n    'expand',\n    removedTrailingIcon,\n  );\n\n  const { headingAs: contextHeadingAs } = useContext(AccordionContext);\n\n  const { isExpandable } = useContext(AccordionRowContext);\n\n  // The indicator is semantic: it marks the row as the thing that expands, and reads as\n  // that only if every expandable thing in the app carries the same mark. It comes from\n  // `IconProvider` for that reason, and not from a prop on this row. The leading and\n  // trailing slots above are the consumer's to fill, and are left alone.\n  const expandIcon = useSemanticIcon('expand');\n\n  const componentClassName = clsx(\n    styles['accordion-button'],\n    !isExpandable && styles['accordion-button--empty'],\n    className,\n  );\n\n  assertEdsUsage(\n    [\n      typeof children !== 'undefined' &&\n        (typeof title !== 'undefined' || typeof subTitle !== 'undefined'),\n    ],\n    'Cannot use `children` with `title`/`subTitle',\n  );\n\n  return (\n    <DisclosureButton as={React.Fragment}>\n      {({ open }) => (\n        <button\n          className={componentClassName}\n          onClick={() => {\n            if (open && isExpandable && onClose) {\n              onClose();\n            }\n            if (!open && isExpandable && onOpen) {\n              onOpen();\n            }\n          }}\n          onKeyDown={(e) => {\n            if (e.key === SPACEBAR_KEYCODE || e.key === ENTER_KEYCODE) {\n              if (open && isExpandable && onClose) {\n                onClose();\n              }\n              if (!open && isExpandable && onOpen) {\n                onOpen();\n              }\n            }\n          }}\n          {...other}\n        >\n          {hasSlotContent(leadingContent) && (\n            <span className={styles['accordion-button__leading-content']}>\n              <IconSlot content={leadingContent} size=\"24px\" />\n            </span>\n          )}\n          <Heading\n            as={headingAs || contextHeadingAs}\n            className={styles['accordion-button__heading']}\n            preset=\"title-md\"\n          >\n            {(title || children) && (\n              <Text\n                as=\"span\"\n                className={styles['accordion-button__title']}\n                preset=\"title-md\"\n              >\n                {title}\n                {children}\n              </Text>\n            )}\n            {subTitle && (\n              <Text\n                as=\"span\"\n                className={styles['accordion-button__subTitle']}\n                preset=\"body-md\"\n              >\n                {subTitle}\n              </Text>\n            )}\n          </Heading>\n          {trailingContent}\n          {isExpandable && hasSlotContent(expandIcon) && (\n            <IconSlot\n              className={clsx(\n                styles['accordion-button__indicator'],\n                open && styles['accordion-button__indicator--open'],\n              )}\n              content={expandIcon}\n              purpose=\"informative\"\n              size=\"24px\"\n              title={open ? 'hide content' : 'show content'}\n            />\n          )}\n        </button>\n      )}\n    </DisclosureButton>\n  );\n};\n\nconst AccordionPanel = ({\n  className,\n  children,\n  ...other\n}: AccordionPanelProps) => {\n  const { isExpandable, hasLeadingContent } = useContext(AccordionRowContext);\n\n  const componentClassName = clsx(\n    styles['accordion-panel'],\n    !isExpandable && styles['accordion-panel--hidden'],\n    hasLeadingContent && styles['accordion-panel--leading-content'],\n    className,\n  );\n\n  return (\n    <DisclosurePanel className={componentClassName} {...other}>\n      {isExpandable && (\n        <Text as=\"span\" preset=\"body-md\">\n          {children}\n        </Text>\n      )}\n    </DisclosurePanel>\n  );\n};\n\nconst AccordionRow = ({\n  className,\n  defaultOpen,\n  children,\n  isExpandable = true,\n  hasLeadingContent,\n  hasTrailingContent,\n  ...other\n}: AccordionRowProps) => {\n  const componentClassName = clsx(styles['accordion-row'], className);\n  return (\n    <AccordionRowContext.Provider value={{ isExpandable, hasLeadingContent }}>\n      <Disclosure defaultOpen={defaultOpen}>\n        {({ open }) => (\n          <div className={componentClassName} {...other}>\n            {typeof children === 'function' ? children({ open }) : children}\n          </div>\n        )}\n      </Disclosure>\n    </AccordionRowContext.Provider>\n  );\n};\n\nAccordion.displayName = 'Accordion';\nAccordionButton.displayName = 'Accordion.Button';\nAccordionPanel.displayName = 'Accordion.Panel';\nAccordionRow.displayName = 'Accordion.Row';\n\nAccordion.Button = AccordionButton;\nAccordion.Panel = AccordionPanel;\nAccordion.Row = AccordionRow;\n"],"names":["React"],"mappings":";;;;;;;;;;;;AA0HA,MAAM,gBAAgB,GAAG,aAAa,CAEnC;AACD,IAAA,SAAS,EAAE,IAAI;AAChB,CAAA,CAAC;AAEF,MAAM,mBAAmB,GAAG,aAAa,CAKvC;AACA,IAAA,YAAY,EAAE,IAAI;AAClB,IAAA,iBAAiB,EAAE,KAAK;AACxB,IAAA,kBAAkB,EAAE,KAAK;AAC1B,CAAA,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CG;AACI,MAAM,SAAS,GAAG,CAAC,EACxB,QAAQ,EACR,SAAS,EACT,SAAS,EACT,GAAG,KAAK,EACO,KAAI;IACnB,QACEA,cAAA,CAAA,aAAA,CAAC,gBAAgB,CAAC,QAAQ,IAAC,KAAK,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