{"version":3,"file":"Menu.mjs","sources":["../../../src/components/Menu/Menu.tsx"],"sourcesContent":["import {\n  Menu as HeadlessMenu,\n  MenuItem as HeadlessMenuItem,\n  MenuItems as HeadlessMenuItems,\n  MenuButton as HeadlessMenuButton,\n  MenuSection as HeadlessMenuSection,\n  MenuHeading as HeadlessMenuHeading,\n  MenuSeparator as HeadlessMenuSeparator,\n} from '@headlessui/react';\n\nimport clsx from 'clsx';\nimport type {\n  ReactNode,\n  MouseEventHandler,\n  HTMLAttributeAnchorTarget,\n} from 'react';\nimport React from 'react';\n\nimport {\n  assertNoRemovedIconProp,\n  type WithRemovedIconProps,\n} from '../../util/logging';\nimport type { ExtractProps } from '../../util/utility-types';\n\nimport Button from '../Button';\n\nimport { useSemanticIcon } from '../Icon';\n\nimport PopoverContainer from '../PopoverContainer';\n\nimport PopoverListItem from '../PopoverListItem';\nimport type { PopoverListItemProps } from '../PopoverListItem/PopoverListItem';\nimport styles from './Menu.module.css';\n\n// Note: added className here to prevent private API collision within HeadlessUI\nexport type MenuProps = ExtractProps<typeof HeadlessMenu> & {\n  /**\n   * Allow custom classes to be applied to the menu container.\n   */\n  className?: string;\n};\n\nexport type MenuButtonProps = {\n  // Component API\n  /**\n   * The button contents placed left of the chevron icon.\n   */\n  children: string;\n  /**\n   * Allow custom classes to be applied to the menu button.\n   */\n  className?: string;\n};\n\nexport type MenuSeparatorProps = ExtractProps<typeof HeadlessMenuSeparator>;\nexport type MenuPlainButtonProps = ExtractProps<typeof HeadlessMenuButton>;\nexport type MenuHeadingProps = ExtractProps<typeof HeadlessMenuHeading>;\nexport type MenuSectionProps = ExtractProps<typeof HeadlessMenuSection>;\nexport type MenuItemsProps = ExtractProps<typeof HeadlessMenuItems>;\n\nexport type MenuItemProps = ExtractProps<typeof HeadlessMenuItem> &\n  PopoverListItemProps & {\n    // Component API\n    anchor?: MenuItemsProps['anchor'];\n    /**\n     * Target URL for the menu item action\n     */\n    href?: string;\n    /**\n     * Configurable action for the menu item upon click\n     */\n    onClick?: MouseEventHandler<HTMLAnchorElement>;\n    __type?: PopoverListItemProps['__type'];\n    /**\n     * Specify the target of the link if present\n     */\n    target?: HTMLAttributeAnchorTarget;\n  };\n\n/**\n * ## Usage\n *\n * | Type/Use | Description | Example |\n * |----------|-------------|---------|\n * | Dropdown | A list of actions or links that appears when a button or label is clicked. | Filter selectors; user profile actions; navigation inside buttons. |\n * | Context | Appears on right-click or long-press; offers contextual options. | File actions; custom user interactions. |\n * | Hamburger | Collapsible navigation menu, often hidden behind an icon. | Mobile nav; space-constrained UIs. |\n * | Overflow/More | Compact menu for additional actions, often shown as \"⋮\" or \"...\". | Table row actions; toolbar options. |\n *\n * ## Interaction\n *\n * The most common trigger for a Menu is a button with a chevron. An icon-only button might also trigger a Menu, and designers can define a custom trigger.\n *\n * ## Content & Accessibility\n *\n * ### Do's\n *\n * * Use short, precise labels.\n * * Place the most-used options at the top of the menu.\n * * Group similar commands, and order meaningfully in long menus using dividers between sections.\n *\n * ### Don'ts\n *\n * * Overload menus; try to stay below 12 options in a menu.\n * * Use helper text with menu options unless absolutely necessary.\n * * Truncate menu items unless absolutely necessary. If truncation is required, use a tooltip to reveal the full text on hover.\n */\nexport const Menu = ({ className, ...other }: MenuProps) => {\n  const menuClassNames = clsx(className, styles['menu']);\n  return <HeadlessMenu as=\"div\" className={menuClassNames} {...other} />;\n};\n\n/**\n * A styled button that when clicked, shows or hides the Options.\n *\n * @see https://headlessui.com/react/menu#menu-button\n */\nconst MenuButton = (props: MenuButtonProps) => {\n  const {\n    children,\n    className,\n    // TODO(next-major): remove these two, with the asserts below.\n    icon: removedIcon,\n    trailingContent: removedTrailingContent,\n    ...other\n  } = props as WithRemovedIconProps<\n    MenuButtonProps,\n    'icon' | 'trailingContent'\n  >;\n\n  // TODO(next-major): remove.\n  assertNoRemovedIconProp('Menu.Button', 'icon', 'expand', removedIcon);\n  // TODO(next-major): remove.\n  assertNoRemovedIconProp(\n    'Menu.Button',\n    'trailingContent',\n    'expand',\n    removedTrailingContent,\n  );\n\n  // The chevron is semantic: it marks the button as the thing that expands the menu, and\n  // reads as that role only if it looks the same on every menu in the app. It comes from\n  // `IconProvider` for that reason, and not from a prop on this button.\n  //\n  // No check on what comes back before reserving the layout for it: `expand` is always a\n  // role, and `IconProvider` rejects an entry that would not render, so this always draws\n  // something.\n  const expandIcon = useSemanticIcon('expand');\n\n  return (\n    <HeadlessMenuButton as={React.Fragment}>\n      <Button\n        // Spread first, so nothing reaching this component can displace the props below it.\n        // `Button` still takes an `icon`, so an `icon` arriving here — from JavaScript that\n        // has not run the codemod, or a dynamic spread — used to land after this one and win,\n        // quietly putting the button back to a per-instance icon.\n        {...other}\n        className={className}\n        icon={expandIcon}\n        iconLayout=\"right\"\n        rank=\"primary\"\n      >\n        {children}\n      </Button>\n    </HeadlessMenuButton>\n  );\n};\n\n/**\n * A minimally styled button that when clicked, shows or hides the Options.\n *\n * @see https://headlessui.com/react/menu#menu-button\n */\nconst MenuPlainButton = ({ className, ...other }: MenuPlainButtonProps) => (\n  <HeadlessMenuButton className={className} {...other} />\n);\n\n/**\n * Divides a list of `Menu.Item` components into sections with proper accessibility semantics.\n *\n * @see https://headlessui.com/react/menu#menu-section\n */\nconst MenuSection = (props: MenuSectionProps) => (\n  <HeadlessMenuSection {...props} />\n);\n\n/**\n * Separates two `Menu.Section` components, with proper accessibility semantics.\n *\n * @see https://headlessui.com/react/menu#menu-separator\n */\nconst MenuSeparator = (props: MenuSeparatorProps) => (\n  <HeadlessMenuSeparator {...props} __type=\"separator\" as={PopoverListItem} />\n);\n\n/**\n * Adds an accessible label to a `MenuSection`.\n *\n * @see https://headlessui.com/react/menu#menu-heading\n */\nconst MenuHeading = (props: MenuHeadingProps) => (\n  <HeadlessMenuHeading {...props} __type=\"label\" as={PopoverListItem} />\n);\n\n/**\n * A list of actions that are revealed in the menu\n *\n * @param props Props used on the set of menu items\n *\n * @see https://headlessui.com/react/menu#menu-items\n */\nconst MenuItems = ({\n  anchor = { to: 'bottom start', gap: 12 },\n  ...other\n}: MenuItemsProps) => {\n  return (\n    <HeadlessMenuItems\n      anchor={anchor}\n      as={PopoverContainer}\n      modal={false}\n      {...other}\n    />\n  );\n};\n\n/**\n * An individual option that represents an action in the menu. Can contain leading content, label, sublabel, and action (onClick).\n *\n * NOTE: for menus, all menu items should fill the leading slot, or none should; mixing the two is discouraged.\n *\n * @see https://headlessui.com/react/menu#menu-item\n */\nconst MenuItem = ({\n  children,\n  className,\n  href,\n  onClick,\n  target,\n  // Props from PopoverListItem\n  isDestructiveAction,\n  isFocused,\n  isDisabled,\n  leadingContent,\n  subLabel,\n  trailingContent,\n  __type = 'listitem',\n  ...other\n}: MenuItemProps) => {\n  return __type === 'separator' ||\n    __type === 'label' ||\n    __type === 'caption' ? (\n    <PopoverListItem\n      __type={__type}\n      isDestructiveAction={isDestructiveAction}\n      isDisabled={isDisabled}\n      isFocused={isFocused}\n      leadingContent={leadingContent}\n      subLabel={subLabel}\n      trailingContent={trailingContent}\n    >\n      {children}\n    </PopoverListItem>\n  ) : (\n    <HeadlessMenuItem {...other}>\n      {({ focus, disabled }) => {\n        const listItemView = (\n          <PopoverListItem\n            __type={__type}\n            className={className}\n            isDestructiveAction={isDestructiveAction}\n            isDisabled={disabled}\n            isFocused={focus}\n            leadingContent={leadingContent}\n            subLabel={subLabel}\n            trailingContent={trailingContent}\n          >\n            {children as ReactNode}\n          </PopoverListItem>\n        );\n        return disabled ? (\n          listItemView\n        ) : (\n          <a\n            className={clsx(styles['menu__item'])}\n            href={href}\n            onClick={onClick}\n            target={target}\n          >\n            {listItemView}\n          </a>\n        );\n      }}\n    </HeadlessMenuItem>\n  );\n};\n\nMenuPlainButton.displayName = 'Menu.PlainButton';\nMenuSeparator.displayName = 'Menu.Separator';\nMenuSection.displayName = 'Menu.Section';\nMenuHeading.displayName = 'Menu.Heading';\nMenuButton.displayName = 'Menu.Button';\nMenuItems.displayName = 'Menu.Items';\nMenuItem.displayName = 'Menu.Item';\nMenu.displayName = 'Menu';\n\nMenu.PlainButton = MenuPlainButton;\nMenu.Separator = MenuSeparator;\nMenu.Heading = MenuHeading;\nMenu.Section = MenuSection;\nMenu.Button = MenuButton;\nMenu.Items = MenuItems;\nMenu.Item = MenuItem;\n"],"names":["React","HeadlessMenu","HeadlessMenuButton","HeadlessMenuSection","HeadlessMenuSeparator","HeadlessMenuHeading","HeadlessMenuItems","HeadlessMenuItem"],"mappings":";;;;;;;;;;;;AA+EA;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BG;AACI,MAAM,IAAI,GAAG,CAAC,EAAE,SAAS,EAAE,GAAG,KAAK,EAAa,KAAI;IACzD,MAAM,cAAc,GAAG,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;AACtD,IAAA,OAAOA,cAAA,CAAA,aAAA,CAACC,MAAY,EAAA,EAAC,EAAE,EAAC,KAAK,EAAC,SAAS,EAAE,cAAc,EAAA,GAAM,KAAK,GAAI;AACxE;AAEA;;;;AAIG;AACH,MAAM,UAAU,GAAG,CAAC,KAAsB,KAAI;IAC5C,MAAM,EACJ,QAAQ,EACR,SAAS;;AAET,IAAA,IAAI,EAAE,WAAW,EACjB,eAAe,EAAE,sBAAsB,EACvC,GAAG,KAAK,EACT,GAAG,KAGH;;IAGD,uBAAuB,CAAC,aAAa,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,CAAC;;IAErE,uBAAuB,CACrB,aAAa,EACb,iBAAiB,EACjB,QAAQ,EACR,sBAAsB,CACvB;;;;;;;;AASD,IAAA,MAAM,UAAU,GAAG,eAAe,CAAC,QAAQ,CAAC;IAE5C,QACED,6BAACE,YAAkB,EAAA,EAAC,EAAE,EAAEF,cAAK,CAAC,QAAQ,EAAA;AACpC,QAAAA,cAAA,CAAA,aAAA,CAAC;;;;;eAKK,KAAK,EACT,SAAS,EAAE,SAAS,EACpB,IAAI,EAAE,UAAU,EAChB,UAAU,EAAC,OAAO,EAClB,IAAI,EAAC,SAAS,IAEb,QAA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