{"version":3,"file":"Button.mjs","sources":["../../../src/components/Button/Button.tsx"],"sourcesContent":["import clsx from 'clsx';\nimport React, { forwardRef } from 'react';\nimport { assertEdsUsage } from '../../util/logging';\nimport type { IconOrContent } from '../../util/utility-types';\nimport type { Size } from '../../util/variant-types';\nimport { hasSlotContent, IconSlot } from '../Icon';\nimport LoadingIndicator from '../LoadingIndicator';\nimport Text from '../Text';\n\nimport styles from './Button.module.css';\n\ntype ButtonHTMLElementProps = React.ButtonHTMLAttributes<HTMLButtonElement>;\n\nexport type ButtonProps<ExtendedElement = unknown> = Omit<\n  ButtonHTMLElementProps,\n  'style'\n> & {\n  // Component API\n  /**\n   * Component used to render the element. Meant to support interaction with framework navigation libraries.\n   *\n   * **Default is `\"button\"`**.\n   */\n  as?: string | React.ElementType;\n  /**\n   * `Button` contents or label.\n   */\n  children?: string;\n  /**\n   * CSS properties defined for the HTML element. Includes the component's CSS Custom Properties:\n   *\n   * - `--button__bg`\n   * - `--button__border`\n   * - `--button__fg`\n   */\n  style?: ButtonCSSProperties;\n  /**\n   * Determine the behavior of the button upon click:\n   * - **button** `Button` is a clickable button with no default behavior\n   * - **submit** `Button` is a clickable button that submits form data\n   * - **reset** `Button` is a clickable button that resets the form-data to its initial values\n   */\n  type?: 'button' | 'reset' | 'submit';\n\n  // Design API\n  /**\n   * Sets the hierarchy rank of the button\n   *\n   * **Default is `\"primary\"`**.\n   */\n  rank?: 'primary' | 'secondary' | 'tertiary';\n\n  /**\n   * The size of the button on screen\n   */\n  size?: Extract<Size, 'sm' | 'md' | 'lg'>;\n\n  /**\n   * The variant of the default tertiary button.\n   */\n  context?: 'default' | 'standalone';\n\n  /**\n   * Content for the icon slot, used when `iconLayout` is set. Takes an EDS icon name, or\n   * any content to render in its place, sized to match `size`.\n   *\n   * Required whenever `iconLayout` is anything but `\"none\"`, and has no default: the layout\n   * reserves space for an icon, so a missing one leaves a gap rather than falling back to\n   * some arbitrary glyph. EDS warns when the two disagree.\n   *\n   * Custom content is rendered as-is, so it carries its own accessible treatment. With\n   * `iconLayout=\"icon-only\"` the button still takes its accessible name from `aria-label`,\n   * the same as it does for an icon name.\n   */\n  icon?: IconOrContent;\n\n  /**\n   * Allows configuation of the icon's positioning within `Button`.\n   *\n   * - When set to a value besides `\"none\"`, an icon must be specified.\n   * - When `\"icon-only\"`, `aria-label` must be given a value.\n   */\n  iconLayout?: 'none' | 'left' | 'right' | 'icon-only';\n\n  /**\n   * Status (color) variant for `Button`.\n   *\n   * **Default is `\"default\"`**.\n   */\n  variant?: 'default' | 'neutral' | 'critical' | 'inverse';\n\n  /**\n   * Whether the width of the button is set to the full layout.\n   */\n  isFullWidth?: boolean;\n\n  /**\n   * Whether `Button` is set to disabled state (disables interaction and updates appearance).\n   *\n   * Note: this will set the internal field to `disabled` as well. Prefer this to just setting `disabled`.\n   */\n  isDisabled?: boolean;\n\n  /**\n   * Loading state passed down from higher level used to trigger loader and text change.\n   */\n  isLoading?: boolean;\n} & ExtendedElement;\n\nexport interface ButtonCSSProperties extends React.CSSProperties {\n  /**\n   * Custom property to customize the background color of this component (e.g., background color)\n   */\n  '--button__bg'?: string;\n\n  /**\n   * Custom property to customize the border color of this component\n   */\n  '--button__border'?: string;\n\n  /**\n   * Custom property to customize the foreground color of this component (e.g., text, icon, etc.)\n   */\n  '--button__fg'?: string;\n}\n\n/**\n * ## Usage\n *\n * | Type/Use | Description | Example |\n * |----------|-------------|---------|\n * | Primary default | Main call-to-action with highest visual prominence. | Submit form. Complete purchase. Save changes. |\n * | Secondary default | Less prominent than primary, used for alternative actions. | Cancel. Edit. Learn more. Go back. |\n * | Tertiary default | Minimal styling (often text-only); used for low-emphasis actions. | View details. Skip. Optional settings. |\n * | Critical | Styled to indicate danger. | Delete. Remove. Reset. Sign out. |\n * | Inverse | Transparent background; used on dark surfaces or inside modals. | De-emphasized actions on colored backgrounds. |\n * | Icon | Icon-only or icon + tooltip; compact for toolbars or utility actions. | Favorite. Share. Settings. Search. Close. |\n * | Loading | Temporarily disabled with a spinner or progress indicator. | \"Saving…\", \"Loading…\". |\n *\n * ### Best Practices\n *\n * * Use one primary button per action to highlight the action the user is most likely to take.\n * * Use secondary buttons alongside a primary button; don't use a secondary button in isolation.\n * * Use tertiary buttons alongside primary or secondary actions. To use a tertiary button alone, set its `context` to `\"standalone\"`.\n *\n * ## Content & Accessibility\n *\n * ### Do's\n *\n * * Use a label that indicates what will happen after the button is clicked.\n * * Start with a verb that encourages action.\n * * Use sentence case and try to stay to 3 or fewer words.\n * * Use the *{verb} + {noun}* formula, except for common actions like \"Done\", \"Close\", \"Cancel\", \"Add\", or \"Delete\".\n *\n * ### Don'ts\n *\n * * Use punctuation.\n */\nexport const Button = forwardRef<HTMLButtonElement, ButtonProps>(\n  (\n    {\n      as: Component = 'button',\n      children,\n      className,\n      context,\n      icon,\n      iconLayout = 'none',\n      isDisabled,\n      isFullWidth,\n      isLoading,\n      type = 'button',\n      rank = 'primary',\n      size = 'lg',\n      variant = 'default',\n      ...other\n    },\n    ref,\n  ) => {\n    const componentClassName = clsx(\n      styles['button'],\n      context && styles[`button--context-${context}`],\n      iconLayout && styles[`button--layout-${iconLayout}`],\n      isDisabled && styles['button--disabled'],\n      isFullWidth && styles['button--full-width'],\n      rank && styles[`button--${rank}`],\n      size && styles[`button--${size}`],\n      size && styles[`button--size-${size}`],\n      variant && styles[`button--variant-${variant}`],\n      className,\n    );\n\n    const buttonContentClassName = clsx(\n      styles['button__text'],\n      isLoading && styles['button--is-loading'],\n    );\n\n    assertEdsUsage(\n      [\n        typeof isDisabled === 'undefined' &&\n          typeof other.disabled !== 'undefined',\n      ],\n      'Use \"isDisabled\" instead of \"disabled\" on Button instances',\n      'error',\n    );\n\n    assertEdsUsage(\n      [iconLayout === 'icon-only' && typeof children !== 'undefined'],\n      'Specifying content for \"children\" when using icon-only layout is not required and can be removed.',\n    );\n\n    assertEdsUsage(\n      [iconLayout !== 'none' && !hasSlotContent(icon)],\n      `Button has iconLayout=\"${iconLayout}\" and no \"icon\" to put in it. The layout reserves space for one, so the button renders a gap where the icon should be — or nothing at all when the layout is \"icon-only\", since that hides \"children\" too. Pass an \"icon\", or leave \"iconLayout\" unset.`,\n    );\n\n    return (\n      <Component\n        className={componentClassName}\n        disabled={isDisabled}\n        ref={ref}\n        type={type}\n        {...other}\n      >\n        <Text\n          as=\"span\"\n          className={buttonContentClassName}\n          preset={`label-${size}`}\n        >\n          {iconLayout === 'icon-only' && hasSlotContent(icon) && (\n            <IconSlot\n              content={icon}\n              purpose=\"decorative\"\n              size={size === 'lg' ? '24px' : '16px'}\n            />\n          )}\n          {iconLayout === 'left' && hasSlotContent(icon) && (\n            <IconSlot\n              content={icon}\n              purpose=\"decorative\"\n              size={size === 'lg' ? '24px' : '16px'}\n            />\n          )}\n          {iconLayout !== 'icon-only' && children}\n          {iconLayout === 'right' && hasSlotContent(icon) && (\n            <IconSlot\n              content={icon}\n              purpose=\"decorative\"\n              size={size === 'lg' ? '24px' : '16px'}\n            />\n          )}\n        </Text>\n        {isLoading && (\n          <LoadingIndicator className={styles['button__loader']} size=\"xs\" />\n        )}\n      </Component>\n    );\n  },\n);\n\nButton.displayName = 'Button';\n"],"names":["React"],"mappings":";;;;;;;;;;AA8HA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BG;AACI,MAAM,MAAM,GAAG,UAAU,CAC9B,CACE,EACE,EAAE,EAAE,SAAS,GAAG,QAAQ,EACxB,QAAQ,EACR,SAAS,EACT,OAAO,EACP,IAAI,EACJ,UAAU,GAAG,MAAM,EACnB,UAAU,EACV,WAAW,EACX,SAAS,EACT,IAAI,GAAG,QAAQ,EACf,IAAI,GAAG,SAAS,EAChB,IAAI,GAAG,IAAI,EACX,OAAO,GAAG,SAAS,EACnB,GAAG,KAAK,EACT,EACD,GAAG,KACD;AACF,IAAA,MAAM,kBAAkB,GAAG,IAAI,CAC7B,MAAM,CAAC,QAAQ,CAAC,EAChB,OAAO,IAAI,MAAM,CAAC,CAAA,gBAAA,EAAmB,OAAO,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