{"version":3,"file":"BaseMenuButton.cjs","names":["_styled","_interopRequireDefault","require","_react","_Box","_index","_OdysseyDesignTokensContext","_useUniqueId","_BaseButton","_MenuContext","_jsxRuntime","e","__esModule","default","menuAlignmentValues","exports","verticalDividerAlignmentValues","StyledMenuButtonContainer","styled","shouldForwardProp","prop","hasVerticalDivider","odysseyDesignTokens","verticalDividerAlignment","position","display","top","left","width","height","Spacing6","backgroundColor","HueNeutral300","content","transform","transition","right","opacity","BaseMenuButton","ariaLabel","ariaLabelledBy","ariaDescribedBy","buttonChildren","buttonLabel","buttonVariant","children","popoverContent","endIcon","endIconProp","id","idOverride","isDisabled","isOverflow","menuAlignment","omitEndIcon","shouldCloseOnSelect","size","testId","tooltipText","translate","useOdysseyDesignTokens","anchorEl","setAnchorEl","useState","isOpen","Boolean","closeMenu","useCallback","openMenu","event","currentTarget","uniqueId","useUniqueId","menuListProps","useMemo","providerValue","undefined","jsx","MoreIcon","ChevronDownIcon","anchorOrigin","horizontal","vertical","transformOrigin","jsxs","BaseButton","ariaControls","ariaExpanded","ariaHasPopup","label","onClick","variant","_Menu2","MenuListProps","onClose","open","MenuContext","Provider","value","_Popover2","Box","sx","padding","Spacing4","MemoizedBaseMenuButton","memo","displayName"],"sources":["../../../src/Buttons/BaseMenuButton.tsx"],"sourcesContent":["/*!\n * Copyright (c) 2022-present, Okta, Inc. and/or its affiliates. All rights reserved.\n * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the \"License.\")\n *\n * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n *\n * See the License for the specific language governing permissions and limitations under the License.\n */\n\nimport styled from \"@emotion/styled\";\nimport {\n  Menu as MuiMenu,\n  Popover as MuiPopover,\n  PopoverOrigin,\n} from \"@mui/material\";\nimport {\n  memo,\n  type ReactElement,\n  ReactNode,\n  useCallback,\n  useMemo,\n  useState,\n} from \"react\";\n\nimport type { HtmlProps } from \"../HtmlProps.js\";\n\nimport { Box } from \"../Box.js\";\nimport { FieldComponentProps } from \"../FieldComponentProps.js\";\nimport { ChevronDownIcon, MoreIcon } from \"../icons.generated/index.js\";\nimport { NullElement } from \"../NullElement.js\";\nimport {\n  DesignTokens,\n  useOdysseyDesignTokens,\n} from \"../OdysseyDesignTokensContext.js\";\nimport { useUniqueId } from \"../useUniqueId.js\";\nimport {\n  BaseButton,\n  buttonSizeValues,\n  buttonVariantValues,\n} from \"./BaseButton.js\";\nimport { MenuContext, MenuContextType } from \"./MenuContext.js\";\n\nexport const menuAlignmentValues = [\"left\", \"right\"] as const;\nexport const verticalDividerAlignmentValues = [\"start\", \"end\"] as const;\n\nconst StyledMenuButtonContainer = styled(\"div\", {\n  shouldForwardProp: (prop) =>\n    prop !== \"hasVerticalDivider\" &&\n    prop !== \"odysseyDesignTokens\" &&\n    prop !== \"verticalDividerAlignment\",\n})<{\n  hasVerticalDivider: BaseMenuButtonProps[\"hasVerticalDivider\"];\n  odysseyDesignTokens: DesignTokens;\n  verticalDividerAlignment: BaseMenuButtonProps[\"verticalDividerAlignment\"];\n}>(({ hasVerticalDivider, odysseyDesignTokens, verticalDividerAlignment }) => ({\n  position: \"relative\",\n\n  ...(hasVerticalDivider && {\n    display: \"inline-block\",\n\n    \"&:before\": {\n      position: \"absolute\",\n      top: \"50%\",\n      left: 0,\n      width: 1,\n      height: odysseyDesignTokens.Spacing6,\n      backgroundColor: odysseyDesignTokens.HueNeutral300,\n      content: '\"\"',\n      transform: \"translate3d(0, -50%, 0)\",\n      transition: `opacity 200ms`,\n\n      ...(verticalDividerAlignment === \"end\" && {\n        left: \"unset\",\n        right: 0,\n      }),\n    },\n\n    \":has(> button:hover)\": {\n      \"&:before\": {\n        opacity: 0,\n      },\n    },\n\n    \":dir(rtl)\": {\n      \"&:before\": {\n        left: \"unset\",\n        right: 0,\n        ...(verticalDividerAlignment === \"end\" && {\n          right: \"unset\",\n          left: 0,\n        }),\n      },\n    },\n  }),\n}));\n\nexport type BaseMenuButtonProps = {\n  /**\n   * The button children for the triggering Button. Only available internal to Odyssey here in BaseMenuButton. If set, buttonLabel is ignored.\n   */\n  buttonChildren?: ReactNode;\n  /**\n   * The label on the triggering Button\n   */\n  buttonLabel?: string;\n  /**\n   * The variant of the triggering Button\n   */\n  buttonVariant?: (typeof buttonVariantValues)[number];\n  /**\n   * The end Icon on the triggering Button\n   */\n  endIcon?: ReactElement;\n  /**\n   * If `true`, renders a vertical divider adjacent to the button to separate it from surrounding content.\n   */\n  hasVerticalDivider?: boolean;\n  /**\n   * The id of the Button\n   */\n  id?: string;\n  /**\n   * If `true`, renders as an overflow (more-actions) trigger instead of a labeled menu button.\n   */\n  isOverflow?: boolean;\n  /**\n   * The horizontal alignment of the menu.\n   */\n  menuAlignment?: (typeof menuAlignmentValues)[number];\n  /**\n   * If `true`, suppresses the default end icon rather than falling back to the overflow or chevron default.\n   */\n  omitEndIcon?: boolean;\n  /**\n   * If `true`, the menu closes automatically when a child MenuItem is clicked.\n   * @default true\n   */\n  shouldCloseOnSelect?: boolean;\n  /**\n   * The size of the button\n   */\n  size?: (typeof buttonSizeValues)[number];\n  /**\n   * The tooltip text for the Button if it's icon-only\n   */\n  tooltipText?: string;\n\n  /**\n   * Show vertical rule before or after the button\n   */\n  verticalDividerAlignment?: (typeof verticalDividerAlignmentValues)[number];\n};\n\n// These are split and exported separately from the above because wrappers of this (e.g. MenuButton) will want to omit buttonChildren, which they cannot do from the combined union type. Instead, they should omit from BaseMenuButtonProps, then union with the AdditionalBaseMenuButtonProps (as seen in MenuButton)\nexport type AdditionalBaseMenuButtonProps = Pick<\n  HtmlProps,\n  \"ariaDescribedBy\" | \"ariaLabel\" | \"ariaLabelledBy\" | \"testId\" | \"translate\"\n> &\n  Pick<FieldComponentProps, \"isDisabled\"> &\n  (\n    | { buttonLabel: string }\n    | (Required<Pick<HtmlProps, \"ariaLabelledBy\">> &\n        Partial<Pick<HtmlProps, \"ariaLabel\">> & {\n          buttonLabel?: undefined | \"\";\n        })\n    | (Required<Pick<HtmlProps, \"ariaLabel\">> &\n        Partial<Pick<HtmlProps, \"ariaLabelledBy\">> & {\n          buttonLabel?: undefined | \"\";\n        })\n  ) &\n  (\n    | {\n        /**\n         * The <MenuItem> components within the Menu.\n         */\n        children: ReactNode | NullElement;\n        /**\n         * popoverContent is disallowed if children are present\n         */\n        popoverContent?: never;\n      }\n    | {\n        /**\n         * children is disallowed if popoverContent is present\n         */\n        children?: never;\n        /**\n         * The content for the popover that is triggered on click.\n         */\n        popoverContent: ReactNode | NullElement;\n      }\n  );\n\n/**\n * Base component for button-triggered menus and popovers. Renders a trigger button that opens a dropdown menu or popover content on click. Used internally by MenuButton and overflow menu patterns.\n */\nconst BaseMenuButton = ({\n  ariaLabel,\n  ariaLabelledBy,\n  ariaDescribedBy,\n  buttonChildren,\n  buttonLabel = \"\",\n  buttonVariant = \"secondary\",\n  children,\n  popoverContent,\n  endIcon: endIconProp,\n  hasVerticalDivider = false,\n  id: idOverride,\n  isDisabled,\n  isOverflow,\n  menuAlignment = \"left\",\n  omitEndIcon = false,\n  shouldCloseOnSelect = true,\n  size,\n  testId,\n  tooltipText,\n  translate,\n  verticalDividerAlignment = \"start\",\n}: BaseMenuButtonProps & AdditionalBaseMenuButtonProps) => {\n  const odysseyDesignTokens = useOdysseyDesignTokens();\n  const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);\n\n  const isOpen = Boolean(anchorEl);\n\n  const closeMenu = useCallback(() => {\n    setAnchorEl(null);\n  }, []);\n\n  const openMenu = useCallback<MenuContextType[\"openMenu\"]>((event) => {\n    setAnchorEl(event.currentTarget);\n  }, []);\n\n  const uniqueId = useUniqueId(idOverride);\n\n  const menuListProps = useMemo(\n    () => ({ \"aria-labelledby\": `${uniqueId}-button` }),\n    [uniqueId],\n  );\n\n  const providerValue = useMemo<MenuContextType>(\n    () => ({\n      closeMenu,\n      openMenu,\n      shouldCloseOnSelect,\n    }),\n    [closeMenu, openMenu, shouldCloseOnSelect],\n  );\n\n  const endIcon = omitEndIcon ? undefined : endIconProp ? (\n    endIconProp\n  ) : isOverflow ? (\n    <MoreIcon />\n  ) : (\n    <ChevronDownIcon />\n  );\n\n  const anchorOrigin = useMemo(\n    () =>\n      ({\n        horizontal: menuAlignment,\n        vertical: \"bottom\",\n      }) as PopoverOrigin,\n    [menuAlignment],\n  );\n\n  const transformOrigin = useMemo(\n    () =>\n      ({\n        horizontal: menuAlignment,\n        vertical: \"top\",\n      }) as PopoverOrigin,\n    [menuAlignment],\n  );\n\n  return (\n    <StyledMenuButtonContainer\n      hasVerticalDivider={hasVerticalDivider}\n      odysseyDesignTokens={odysseyDesignTokens}\n      verticalDividerAlignment={verticalDividerAlignment}\n    >\n      <BaseButton\n        ariaControls={isOpen ? `${uniqueId}-menu` : undefined}\n        ariaDescribedBy={ariaDescribedBy}\n        ariaExpanded={isOpen ? \"true\" : undefined}\n        ariaHasPopup=\"true\"\n        ariaLabel={ariaLabel}\n        ariaLabelledBy={ariaLabelledBy}\n        children={buttonChildren}\n        endIcon={endIcon}\n        id={`${uniqueId}-button`}\n        isDisabled={isDisabled}\n        label={buttonLabel}\n        onClick={openMenu}\n        size={size}\n        testId={testId}\n        tooltipText={tooltipText}\n        translate={translate}\n        variant={buttonVariant}\n      />\n\n      {children && (\n        <MuiMenu\n          anchorEl={anchorEl}\n          anchorOrigin={anchorOrigin}\n          id={`${uniqueId}-menu`}\n          MenuListProps={menuListProps}\n          onClose={closeMenu}\n          open={isOpen}\n          transformOrigin={transformOrigin}\n        >\n          <MenuContext.Provider value={providerValue}>\n            {children}\n          </MenuContext.Provider>\n        </MuiMenu>\n      )}\n\n      {popoverContent && (\n        <MuiPopover\n          anchorEl={anchorEl}\n          anchorOrigin={anchorOrigin}\n          onClose={closeMenu}\n          open={isOpen}\n          transformOrigin={transformOrigin}\n        >\n          <Box\n            sx={{\n              padding: odysseyDesignTokens.Spacing4,\n            }}\n          >\n            {popoverContent}\n          </Box>\n        </MuiPopover>\n      )}\n    </StyledMenuButtonContainer>\n  );\n};\n\nconst MemoizedBaseMenuButton = memo(BaseMenuButton);\nMemoizedBaseMenuButton.displayName = \"BaseMenuButton\";\n\nexport { MemoizedBaseMenuButton as BaseMenuButton };\n"],"mappings":";;;;;;;;AAYA,IAAAA,OAAA,GAAAC,sBAAA,CAAAC,OAAA;AAMA,IAAAC,MAAA,GAAAD,OAAA;AAWA,IAAAE,IAAA,GAAAF,OAAA;AAEA,IAAAG,MAAA,GAAAH,OAAA;AAEA,IAAAI,2BAAA,GAAAJ,OAAA;AAIA,IAAAK,YAAA,GAAAL,OAAA;AACA,IAAAM,WAAA,GAAAN,OAAA;AAKA,IAAAO,YAAA,GAAAP,OAAA;AAAgE,IAAAQ,WAAA,GAAAR,OAAA;AAAA,SAAAD,uBAAAU,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AA3ChE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAmCO,MAAMG,mBAAmB,GAAAC,OAAA,CAAAD,mBAAA,GAAG,CAAC,MAAM,EAAE,OAAO,CAAU;AACtD,MAAME,8BAA8B,GAAAD,OAAA,CAAAC,8BAAA,GAAG,CAAC,OAAO,EAAE,KAAK,CAAU;AAEvE,MAAMC,yBAAyB,GAAG,IAAAC,eAAM,EAAC,KAAK,EAAE;EAC9CC,iBAAiB,EAAGC,IAAI,IACtBA,IAAI,KAAK,oBAAoB,IAC7BA,IAAI,KAAK,qBAAqB,IAC9BA,IAAI,KAAK;AACb,CAAC,CAAC,CAIC,CAAC;EAAEC,kBAAkB;EAAEC,mBAAmB;EAAEC;AAAyB,CAAC,MAAM;EAC7EC,QAAQ,EAAE,UAAU;EAEpB,IAAIH,kBAAkB,IAAI;IACxBI,OAAO,EAAE,cAAc;IAEvB,UAAU,EAA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