{"version":3,"file":"Button.cjs","names":[],"sources":["../../../src/components/Button/Button.tsx"],"sourcesContent":["/*\nCopyright 2023, 2024 New Vector Ltd.\n\nSPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial\nPlease see LICENSE files in the repository root for full details.\n*/\n\nimport classNames from \"classnames\";\nimport React, {\n  type ComponentType,\n  type PropsWithChildren,\n  forwardRef,\n  type ForwardedRef,\n  type Ref,\n} from \"react\";\nimport styles from \"./Button.module.css\";\nimport { UnstyledButton, type UnstyledButtonPropsFor } from \"./UnstyledButton\";\nimport type { Size } from \"../../utils/size\";\n\ninterface ButtonComponent {\n  // With the explicit `as` prop\n  <C extends React.ElementType>(\n    props: { as: C } & ButtonPropsFor<C>,\n  ): React.ReactElement;\n  // Without the explicit `as` prop, defaulting to a <button>\n  (props: ButtonPropsFor<\"button\">): React.ReactElement;\n}\n\ntype ButtonOwnProps = PropsWithChildren<{\n  /**\n   * The type of button.\n   * Note: \"destructive\" is deprecated, please use the destructive prop in\n   * conjunction with another button kind.\n   */\n  kind?: \"primary\" | \"secondary\" | \"tertiary\" | \"destructive\";\n  /**\n   * The t-shirt size of the button.\n   */\n  size?: Size & (\"sm\" | \"lg\");\n\n  /**\n   * Whether the button is an icon only button.\n   */\n  iconOnly?: boolean;\n\n  /**\n   * An icon to display within the button.\n   */\n  Icon?: ComponentType<React.SVGAttributes<SVGElement>>;\n  /**\n   * Whether this button triggers a destructive action.\n   * @default false\n   */\n  destructive?: boolean;\n}>;\n\ntype ButtonPropsFor<C extends React.ElementType> = ButtonOwnProps &\n  UnstyledButtonPropsFor<C>;\n\n/**\n * A button component that can be transformed into a link, but keep the button\n * styling using the `as` property.\n */\nexport const Button = forwardRef(function Button<\n  C extends React.ElementType = \"button\",\n>(\n  {\n    as,\n    kind: kindProp = \"primary\",\n    size = \"lg\",\n    children,\n    className,\n    iconOnly,\n    Icon,\n    destructive: destructiveProp,\n    disabled,\n    ...props\n  }: ButtonPropsFor<C> & { as?: C },\n  ref: ForwardedRef<C>,\n): React.ReactElement {\n  // Fallback for the deprecated \"destructive\" kind\n  const [kind, destructive] =\n    kindProp === \"destructive\"\n      ? [\"secondary\", true]\n      : [kindProp, destructiveProp];\n\n  const classes = classNames(styles.button, className, {\n    [styles[\"has-icon\"]]: Icon,\n    [styles[\"icon-only\"]]: iconOnly,\n    [styles.destructive]: destructive,\n  });\n\n  const iconSize = iconOnly && size === \"lg\" ? 24 : 20;\n\n  return (\n    <UnstyledButton\n      {...props}\n      as={as || (\"button\" as const)}\n      ref={ref as Ref<C>}\n      className={classes}\n      data-size={size}\n      data-kind={kind}\n      tabIndex={0}\n      disabled={disabled}\n    >\n      {Icon && (\n        <Icon\n          width={iconSize}\n          height={iconSize}\n          className={styles.icon}\n          aria-hidden={true}\n        />\n      )}\n      {children}\n    </UnstyledButton>\n  );\n}) as ButtonComponent;\n"],"mappings":";;;;;;;;;;;;;AA+DA,IAAa,UAAA,GAAA,MAAA,YAAoB,SAAS,OAGxC,EACE,IACA,MAAM,WAAW,WACjB,OAAO,MACP,UACA,WACA,UACA,MACA,aAAa,iBACb,UACA,GAAG,SAEL,KACoB;CAEpB,MAAM,CAAC,MAAM,eACX,aAAa,gBACT,CAAC,aAAa,KAAK,GACnB,CAAC,UAAU,gBAAgB;CAEjC,MAAM,WAAA,GAAA,WAAA,SAAqB,sBAAA,QAAO,QAAQ,WAAW;GAClD,sBAAA,QAAO,cAAc;GACrB,sBAAA,QAAO,eAAe;GACtB,sBAAA,QAAO,cAAc;EACvB,CAAC;CAEF,MAAM,WAAW,YAAY,SAAS,OAAO,KAAK;AAElD,QACE,iBAAA,GAAA,kBAAA,MAAC,uBAAA,gBAAD;EACE,GAAI;EACJ,IAAI,MAAO;EACN;EACL,WAAW;EACX,aAAW;EACX,aAAW;EACX,UAAU;EACA;YARZ,CAUG,QACC,iBAAA,GAAA,kBAAA,KAAC,MAAD;GACE,OAAO;GACP,QAAQ;GACR,WAAW,sBAAA,QAAO;GAClB,eAAa;GACb,CAAA,EAEH,SACc;;EAEnB"}