{"version":3,"file":"BaseButton.cjs","names":["_react","require","_MuiPropsContext","_OdysseyDesignTokensContext","_Tooltip","_ButtonContext","_jsxRuntime","_interopRequireDefault","e","__esModule","default","buttonSizeValues","exports","buttonTypeValues","buttonVariantValues","BaseButton","ariaControls","ariaDescribedBy","ariaExpanded","ariaHasPopup","ariaLabel","ariaLabelledBy","ariaPressed","buttonRef","children","endIcon","formId","href","id","isDisabled","isFullWidth","isFullWidthProp","isLoading","label","onClick","size","startIcon","tabIndex","testId","tooltipText","translate","type","variant","variantProp","muiProps","useMuiProps","localButtonRef","useRef","buttonContext","useButton","odysseyDesignTokens","useOdysseyDesignTokens","useMemo","buttonContent","loadingIndicator","jsx","_CircularProgress2","color","Spacing4","handleClick","useCallback","event","preventDefault","useImperativeHandle","focus","current","renderButton","_Button2","form","fullWidth","ref","element","Tooltip","ariaType","placement","text","MuiPropsContext","Consumer","MemoizedBaseButton","memo","displayName"],"sources":["../../../src/Buttons/BaseButton.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 type { ButtonProps as MuiButtonProps } from \"@mui/material\";\n\nimport {\n  Button as MuiButton,\n  CircularProgress as MuiCircularProgress,\n} from \"@mui/material\";\nimport {\n  HTMLAttributes,\n  memo,\n  ReactElement,\n  ReactNode,\n  RefObject,\n  useCallback,\n  useImperativeHandle,\n  useMemo,\n  useRef,\n} from \"react\";\n\nimport type { HtmlProps } from \"../HtmlProps.js\";\n\nimport { FocusHandle } from \"../inputUtils.js\";\nimport {\n  MuiPropsContext,\n  MuiPropsContextType,\n  useMuiProps,\n} from \"../MuiPropsContext.js\";\nimport { useOdysseyDesignTokens } from \"../OdysseyDesignTokensContext.js\";\nimport { Tooltip } from \"../Tooltip.js\";\nimport { useButton } from \"./ButtonContext.js\";\n\nexport const buttonSizeValues = [\"small\", \"medium\", \"large\"] as const;\nexport const buttonTypeValues = [\"button\", \"submit\", \"reset\"] as const;\nexport const buttonVariantValues = [\n  \"primary\",\n  \"secondary\",\n  \"danger\",\n  \"dangerSecondary\",\n  \"floating\",\n  \"floatingAction\",\n] as const;\n\nexport type BaseButtonProps = {\n  /**\n   * Ref attached to the underlying button element, exposing a `focus()` handle.\n   */\n  buttonRef?: RefObject<FocusHandle>;\n  /**\n   * The contents of the button. Only available internal to Odyssey here in BaseButton. If set, label is ignored.\n   */\n  children?: ReactNode;\n  /**\n   * The icon element to display at the end of the Button\n   */\n  endIcon?: ReactElement;\n  /**\n   * The ID of the form the Button belongs to. Use it to submit or reset a form from a Button outside that form, such as a `Dialog` footer action. Has no effect when `href` is set.\n   */\n  formId?: string;\n  /**\n   * Optional href to render the button as a link\n   */\n  href?: string;\n  /**\n   * The ID of the Button\n   */\n  id?: string;\n  /**\n   * If `true`, the button is disabled and cannot be activated.\n   */\n  isDisabled?: boolean;\n  /**\n   * If `true`, the button expands to fill its container's full width.\n   */\n  isFullWidth?: boolean;\n  /**\n   * If `true`, the button shows a progress spinner in place of its start icon and stops responding to clicks, while keeping the background and border of its default state. To reword the button while it works (for example `\"Saving…\"`), swap `label` alongside this.\n   */\n  isLoading?: boolean;\n  /**\n   * The text content of the Button.\n   * @default \"\"\n   */\n  label?: string;\n  /**\n   * Called when the button is clicked.\n   */\n  onClick?: MuiButtonProps[\"onClick\"];\n  /**\n   * The size of the button.\n   * @default \"medium\"\n   */\n  size?: (typeof buttonSizeValues)[number];\n  /**\n   * The icon element to display at the start of the Button\n   */\n  startIcon?: ReactElement;\n  /** The tab order of the Button relative to other focusable elements. */\n  tabIndex?: HTMLAttributes<HTMLElement>[\"tabIndex\"];\n  /**\n   * The tooltip text for the Button if it's icon-only\n   */\n  tooltipText?: string;\n  /**\n   * The HTML button type attribute.\n   * - If `'button'`, no default form behavior.\n   * - If `'submit'`, submits the nearest form.\n   * - If `'reset'`, resets the nearest form to its initial values.\n   * @default \"button\"\n   */\n  type?: (typeof buttonTypeValues)[number];\n  /**\n   * Controls the visual hierarchy and intent of the button.\n   * - If `'primary'`, high-emphasis action; use for the single most important action on a page.\n   * - If `'secondary'`, medium-emphasis action; use for secondary actions alongside a primary.\n   * - If `'danger'`, high-emphasis destructive action.\n   * - If `'dangerSecondary'`, medium-emphasis destructive action.\n   * - If `'floating'`, low-emphasis action without a border or background.\n   * - If `'floatingAction'`, icon-only floating action, typically fixed-positioned.\n   * - If `'tertiary'`, deprecated low-emphasis style; use `'floating'` instead.\n   */\n  variant: (typeof buttonVariantValues)[number] | \"tertiary\";\n};\n\n// These are split and exported separately from the above because wrappers of this (e.g. Button) will want to omit children, which they cannot do from the combined union type. Instead, they should omit from BaseButtonProps, then union with the AdditionalBaseButtonProps (as seen in Button)\nexport type AdditionalBaseButtonProps = Pick<\n  HtmlProps,\n  | \"ariaControls\"\n  | \"ariaDescribedBy\"\n  | \"ariaExpanded\"\n  | \"ariaHasPopup\"\n  | \"ariaLabel\"\n  | \"ariaLabelledBy\"\n  | \"ariaPressed\"\n  | \"tabIndex\"\n  | \"testId\"\n  | \"translate\"\n>;\n\n/**\n * The internal base button primitive used by all Odyssey button variants. Handles icon placement, full-width layout, tooltip wrapping, focus handle forwarding, and MUI prop context integration.\n */\nconst BaseButton = ({\n  ariaControls,\n  ariaDescribedBy,\n  ariaExpanded,\n  ariaHasPopup,\n  ariaLabel,\n  ariaLabelledBy,\n  ariaPressed,\n  buttonRef,\n  children,\n  endIcon,\n  formId,\n  href,\n  id,\n  isDisabled,\n  isFullWidth: isFullWidthProp,\n  isLoading,\n  label = \"\",\n  onClick,\n  size = \"medium\",\n  startIcon,\n  tabIndex,\n  testId,\n  tooltipText,\n  translate,\n  type = \"button\",\n  variant: variantProp,\n}: BaseButtonProps & AdditionalBaseButtonProps) => {\n  const muiProps = useMuiProps();\n\n  // We're deprecating the \"tertiary\" variant, so map it to \"secondary\" in lieu of making a breaking change\n  const variant = variantProp === \"tertiary\" ? \"secondary\" : variantProp;\n  const localButtonRef = useRef<HTMLButtonElement | HTMLAnchorElement>(null);\n  const buttonContext = useButton();\n  const odysseyDesignTokens = useOdysseyDesignTokens();\n  const isFullWidth = useMemo(\n    () =>\n      buttonContext.isFullWidth ? buttonContext.isFullWidth : isFullWidthProp,\n    [buttonContext, isFullWidthProp],\n  );\n\n  const buttonContent = children ?? label;\n\n  const loadingIndicator = useMemo(\n    () => (\n      // Design specifies each variant's spinner color as that variant's own label color, so `color=\"inherit\"` keeps the two in step instead of restating the palette per variant. MUI's CircularProgress is used directly because Odyssey's wrapper deliberately exposes neither a size nor a color prop, and design asked for the 16px sizing to stay internal to Button. Stroke weight comes from the shared theme default, which holds a 1:12 stroke-to-diameter ratio at any size.\n      <MuiCircularProgress\n        aria-hidden\n        color=\"inherit\"\n        size={odysseyDesignTokens.Spacing4}\n      />\n    ),\n    [odysseyDesignTokens],\n  );\n\n  // An inert button keeps its `href` so it stays focusable and keeps its link role, which leaves the browser's own activation as the thing to stop: `pointer-events: none` from the theme only blocks the mouse, and because `aria-disabled` is advisory, Enter still dispatches a click that would follow the link or submit the form. Preventing the default on that click covers every input method without swapping the element out.\n  const handleClick = useCallback<NonNullable<MuiButtonProps[\"onClick\"]>>(\n    (event) => {\n      if (isLoading || isDisabled) {\n        event.preventDefault();\n        return;\n      }\n\n      onClick?.(event);\n    },\n    [isDisabled, isLoading, onClick],\n  );\n\n  useImperativeHandle(\n    buttonRef,\n    () => ({\n      focus: () => {\n        localButtonRef.current?.focus();\n      },\n    }),\n    [],\n  );\n\n  const renderButton = useCallback(\n    (muiProps: MuiPropsContextType) => {\n      return (\n        <MuiButton\n          {...muiProps}\n          aria-busy={isLoading}\n          aria-controls={ariaControls}\n          aria-describedby={ariaDescribedBy}\n          aria-disabled={isLoading || isDisabled}\n          aria-expanded={ariaExpanded}\n          aria-haspopup={ariaHasPopup}\n          aria-label={ariaLabel}\n          aria-labelledby={ariaLabelledBy}\n          aria-pressed={ariaPressed}\n          data-se={testId}\n          endIcon={endIcon}\n          form={formId}\n          fullWidth={isFullWidth}\n          href={href}\n          id={id}\n          onClick={handleClick}\n          ref={(element) => {\n            if (element) {\n              (\n                localButtonRef as React.MutableRefObject<\n                  HTMLButtonElement | HTMLAnchorElement\n                >\n              ).current = element;\n              //@ts-expect-error ref is not an optional prop on the props context type\n              muiProps?.ref?.(element);\n            }\n          }}\n          size={size}\n          startIcon={isLoading ? loadingIndicator : startIcon}\n          tabIndex={tabIndex}\n          translate={translate}\n          type={type}\n          variant={variant}\n        >\n          {buttonContent}\n        </MuiButton>\n      );\n    },\n    [\n      ariaControls,\n      ariaDescribedBy,\n      ariaExpanded,\n      ariaHasPopup,\n      ariaLabel,\n      ariaLabelledBy,\n      ariaPressed,\n      buttonContent,\n      endIcon,\n      formId,\n      handleClick,\n      href,\n      id,\n      isDisabled,\n      isFullWidth,\n      isLoading,\n      loadingIndicator,\n      size,\n      startIcon,\n      tabIndex,\n      testId,\n      translate,\n      type,\n      variant,\n    ],\n  );\n\n  if (tooltipText) {\n    return (\n      <Tooltip ariaType=\"description\" placement=\"top\" text={tooltipText}>\n        <MuiPropsContext.Consumer>{renderButton}</MuiPropsContext.Consumer>\n      </Tooltip>\n    );\n  }\n\n  return renderButton(muiProps);\n};\n\nconst MemoizedBaseButton = memo(BaseButton);\nMemoizedBaseButton.displayName = \"BaseButton\";\n\nexport { MemoizedBaseButton as BaseButton };\n"],"mappings":";;;;;;;;AAkBA,IAAAA,MAAA,GAAAC,OAAA;AAeA,IAAAC,gBAAA,GAAAD,OAAA;AAKA,IAAAE,2BAAA,GAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AACA,IAAAI,cAAA,GAAAJ,OAAA;AAA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