1- import React , { forwardRef } from 'react' ;
1+ import React , { useMemo } from 'react' ;
22import classnames from 'classnames' ;
33import TLoading from '../loading' ;
4- import useConfig from '../hooks/useConfig' ;
54import parseTNode from '../_util/parseTNode' ;
65import { TdButtonProps } from './type' ;
76import { buttonDefaultProps } from './defaultProps' ;
7+ import { usePrefixClass } from '../hooks/useClass' ;
88import useDefaultProps from '../hooks/useDefaultProps' ;
9+ import useHover from '../hooks/useHover' ;
910
1011export interface ButtonProps
1112 extends TdButtonProps ,
1213 Omit < React . ButtonHTMLAttributes < HTMLButtonElement > , 'content' | 'children' > { }
1314
14- const Button = forwardRef < HTMLButtonElement , ButtonProps > ( ( originProps , ref ) => {
15+ const Button : React . FC < ButtonProps > = ( originProps ) => {
1516 const props = useDefaultProps ( originProps , buttonDefaultProps ) ;
1617 const {
1718 className,
@@ -32,40 +33,43 @@ const Button = forwardRef<HTMLButtonElement, ButtonProps>((originProps, ref) =>
3233 onClick,
3334 loadingProps,
3435 } = props ;
35- const { classPrefix } = useConfig ( ) ;
36-
36+ const buttonClass = usePrefixClass ( 'button' ) ;
3737 const childNode = content || children ;
3838
39+ const hoverDisabled = useMemo ( ( ) => disabled || loading , [ disabled , loading ] ) ;
40+ const ref = useHover ( { className : `${ buttonClass } --hover` , disabled : hoverDisabled } ) ;
41+
3942 return (
4043 < button
4144 ref = { ref }
4245 type = { type }
4346 className = { classnames (
4447 [
45- `${ classPrefix } -button ` ,
46- `${ classPrefix } -button --size-${ size } ` ,
47- `${ classPrefix } -button --${ variant } ` ,
48- `${ classPrefix } -button --${ theme } ` ,
49- `${ classPrefix } -button --${ shape } ` ,
48+ `${ buttonClass } ` ,
49+ `${ buttonClass } --size-${ size } ` ,
50+ `${ buttonClass } --${ variant } ` ,
51+ `${ buttonClass } --${ theme } ` ,
52+ `${ buttonClass } --${ shape } ` ,
5053 className ,
5154 ] ,
5255 {
53- [ `${ classPrefix } -button--ghost` ] : ghost ,
54- [ `${ classPrefix } -button--loading` ] : loading ,
55- [ `${ classPrefix } -button--disabled` ] : disabled ,
56- [ `${ classPrefix } -button--block` ] : block ,
56+ [ `${ buttonClass } --ghost` ] : ghost ,
57+ [ `${ buttonClass } --loading` ] : loading ,
58+ [ `${ buttonClass } --disabled` ] : disabled ,
59+ [ `${ buttonClass } --block` ] : block ,
60+ [ `${ buttonClass } --hover` ] : ghost ,
5761 } ,
5862 ) }
5963 style = { style }
6064 onClick = { ! loading && ! disabled ? onClick : undefined }
6165 disabled = { disabled || loading }
6266 >
6367 { loading ? < TLoading inheritColor { ...loadingProps } /> : parseTNode ( icon ) }
64- { childNode && < span className = { `${ classPrefix } -button__content ` } > { parseTNode ( childNode ) } </ span > }
68+ { childNode && < span className = { `${ buttonClass } __content ` } > { parseTNode ( childNode ) } </ span > }
6569 { parseTNode ( suffix ) }
6670 </ button >
6771 ) ;
68- } ) ;
72+ } ;
6973
7074Button . displayName = 'Button' ;
7175
0 commit comments