diff --git a/packages/react/src/components/Button/Button.tsx b/packages/react/src/components/Button/Button.tsx index c28581774654..b75384839f93 100644 --- a/packages/react/src/components/Button/Button.tsx +++ b/packages/react/src/components/Button/Button.tsx @@ -7,13 +7,11 @@ import PropTypes from 'prop-types'; import React, { useRef } from 'react'; -import classNames from 'classnames'; import { IconButton, IconButtonKind } from '../IconButton'; import { composeEventHandlers } from '../../tools/events'; -import { usePrefix } from '../../internal/usePrefix'; -import { useId } from '../../internal/useId'; import { PolymorphicProps } from '../../types/common'; import { PopoverAlignment } from '../Popover'; +import ButtonBase from './ButtonBase'; export const ButtonKinds = [ 'primary', @@ -40,7 +38,7 @@ export const ButtonTooltipPositions = ['top', 'right', 'bottom', 'left']; export type ButtonTooltipPosition = (typeof ButtonTooltipPositions)[number]; -interface ButtonBaseProps +export interface ButtonBaseProps extends React.ButtonHTMLAttributes { /** * Specify the message read by screen readers for the danger button variant @@ -124,17 +122,15 @@ function isIconOnlyButton( } const Button = React.forwardRef(function Button( - { + props: ButtonProps, + ref: React.Ref +) { + const tooltipRef = useRef(null); + const { as, children, - className, - dangerDescription = 'danger', - disabled = false, hasIconOnly = false, - href, iconDescription, - isExpressive = false, - isSelected, kind = 'primary', onBlur, onClick, @@ -143,16 +139,10 @@ const Button = React.forwardRef(function Button( onMouseLeave, renderIcon: ButtonImageElement, size, - tabIndex, tooltipAlignment = 'center', tooltipPosition = 'top', - type = 'button', ...rest - }: ButtonProps, - ref: React.Ref -) { - const tooltipRef = useRef(null); - const prefix = usePrefix(); + } = props; const handleClick = (evt: React.MouseEvent) => { // Prevent clicks on the tooltip from triggering the button click event @@ -161,92 +151,10 @@ const Button = React.forwardRef(function Button( } }; - const buttonClasses = classNames(className, { - [`${prefix}--btn`]: true, - [`${prefix}--btn--sm`]: size === 'sm' && !isExpressive, // TODO: V12 - Remove this class - [`${prefix}--btn--md`]: size === 'md' && !isExpressive, // TODO: V12 - Remove this class - [`${prefix}--btn--xl`]: size === 'xl', // TODO: V12 - Remove this class - [`${prefix}--btn--2xl`]: size === '2xl', // TODO: V12 - Remove this class - [`${prefix}--layout--size-${size}`]: size, - [`${prefix}--btn--${kind}`]: kind, - [`${prefix}--btn--disabled`]: disabled, - [`${prefix}--btn--expressive`]: isExpressive, - [`${prefix}--btn--icon-only`]: hasIconOnly, - [`${prefix}--btn--selected`]: hasIconOnly && isSelected && kind === 'ghost', - }); - - const commonProps = { - tabIndex, - className: buttonClasses, - ref, - }; - - const buttonImage = !ButtonImageElement ? null : ( -