{"version":3,"file":"AnchorButton.cjs","sources":["../../../src/components/Button/AnchorButton.tsx"],"sourcesContent":["'use client'\n\nimport {\n  type ComponentPropsWithoutRef,\n  type ElementType,\n  type FC,\n  type PropsWithoutRef,\n  type ReactElement,\n  type Ref,\n  forwardRef,\n  useMemo,\n} from 'react'\nimport { tv } from 'tailwind-variants'\n\nimport { OpenInNewTabIcon } from '../Icon'\n\nimport { ButtonWrapper } from './ButtonWrapper'\nimport { DisabledReason } from './DisabledReason'\n\nimport type { AbstractProps as ButtonProps } from './types'\nimport type { ElementRef, ElementRefProps } from '../../types'\n\ntype AbstractProps<T extends ElementType> = Omit<ButtonProps, 'variant' | 'disabledReason'> & {\n  /** next/linkなどのカスタムコンポーネントを指定します。指定がない場合はデフォルトで `a` タグが使用されます。 */\n  elementAs?: T\n  // tertiaryはAnchorButtonでは使用不可\n  variant?: Exclude<ButtonProps['variant'], 'tertiary'>\n  inactiveReason?: ButtonProps['disabledReason']\n}\n\ntype ElementProps<T extends ElementType> = Omit<\n  ComponentPropsWithoutRef<T>,\n  keyof AbstractProps<T> & ElementRefProps<T>\n>\n\nconst classNameGenerator = tv({\n  base: 'smarthr-ui-AnchorButton',\n})\n\nconst AnchorButton = forwardRef(\n  <T extends ElementType = 'a'>(\n    {\n      size = 'M',\n      prefix,\n      suffix,\n      wide = false,\n      variant = 'secondary',\n      inactiveReason,\n      target,\n      rel,\n      elementAs,\n      className,\n      children,\n      href,\n      ...rest\n    }: PropsWithoutRef<AbstractProps<T>> & ElementProps<T>,\n    ref: Ref<ElementRef<T>>,\n  ): ReactElement => {\n    const actualClassName = useMemo(() => classNameGenerator({ className }), [className])\n\n    const actualSuffix = useMemo(() => {\n      // target=\"_blank\" だが OpenInNewTabIcon を表示したくない場合 suffix に null を指定すれば表示しないようにしている\n      if (target === '_blank' && !prefix && suffix === undefined) {\n        return <OpenInNewTabIcon />\n      }\n\n      return suffix\n    }, [prefix, suffix, target])\n\n    const button = (\n      <ButtonWrapper\n        {...rest}\n        href={href}\n        size={size}\n        wide={wide}\n        variant={variant}\n        className={actualClassName}\n        target={target}\n        rel={rel === undefined && target === '_blank' ? 'noopener noreferrer' : rel}\n        isAnchor\n        anchorRef={ref}\n        elementAs={elementAs}\n        prefix={prefix}\n        suffix={actualSuffix}\n      >\n        {children}\n      </ButtonWrapper>\n    )\n\n    if (!href && inactiveReason) {\n      return <DisabledReason button={button} disabledReason={inactiveReason} />\n    }\n\n    return button\n  },\n)\n\n// 型キャストなしで ForwardRefExoticComponent に合わせた型をエクスポートするための処理\ntype AnchorButtonType = <T extends ElementType = 'a'>(\n  props: AbstractProps<T> & ElementProps<T> & ElementRefProps<T>,\n) => ReturnType<FC>\n\nconst ForwardedAnchorButton = AnchorButton as unknown as AnchorButtonType & {\n  displayName: string\n}\n\n// BottomFixedArea での判定に用いるために displayName を明示的に設定する\nForwardedAnchorButton.displayName = 'AnchorButton'\n\nexport { ForwardedAnchorButton as AnchorButton }\n"],"names":[],"mappings":";;;;;;;;;;;AAmCA;AACE;AACD;AAED;AAmBI;AAEA;;;;;AAME;;AAGF;AAoBA;;;AAIA;AACF;AAQF;AAIA;AACA;;"}