Skip to content

Commit cf6c87c

Browse files
committed
chore: remove forwardRef
1 parent 6e261a5 commit cf6c87c

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

src/fab/Fab.tsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
import React, { useMemo, forwardRef, useRef, useState, useEffect } from 'react';
1+
import React, { useRef, useState, useEffect } from 'react';
22
import { reconvertUnit } from '../_util/convertUnit';
33
import Button from '../button';
44
import { TdFabProps } from './type';
5+
import { fabDefaultProps } from './defaultProps';
56
import { StyledProps } from '../common';
6-
import useConfig from '../hooks/useConfig';
7+
import { usePrefixClass } from '../hooks/useClass';
8+
import useDefaultProps from '../hooks/useDefaultProps';
79

810
export interface FabProps extends TdFabProps, StyledProps {}
911

10-
const Fab: React.FC<FabProps> = forwardRef((props) => {
12+
const Fab: React.FC<FabProps> = (originProps) => {
13+
const props = useDefaultProps(originProps, fabDefaultProps);
1114
const { buttonProps, icon = null, text, onClick } = props;
1215

1316
const fabButtonRef = useRef(null);
@@ -43,10 +46,9 @@ const Fab: React.FC<FabProps> = forwardRef((props) => {
4346
endY: 0,
4447
};
4548

46-
const { classPrefix } = useConfig();
47-
const name = useMemo(() => `${classPrefix}-fab`, [classPrefix]);
49+
const fabClass = usePrefixClass('fab');
4850

49-
const onClickHandle = (e) => {
51+
const onClickHandle = (e: React.MouseEvent<HTMLDivElement>) => {
5052
onClick({ e });
5153
};
5254

@@ -169,7 +171,7 @@ const Fab: React.FC<FabProps> = forwardRef((props) => {
169171
return (
170172
<div
171173
ref={fabRef}
172-
className={name}
174+
className={fabClass}
173175
style={props.draggable && fabButtonSize.width ? { ...fabStyle } : props.style}
174176
onClick={onClickHandle}
175177
onTouchStart={onTouchStart}
@@ -180,15 +182,15 @@ const Fab: React.FC<FabProps> = forwardRef((props) => {
180182
size="large"
181183
theme="primary"
182184
shape={props.text ? 'round' : 'circle'}
183-
className={`${name}__button`}
185+
className={`${fabClass}__button`}
184186
{...(buttonProps as TdFabProps['buttonProps'])}
185187
icon={icon}
186188
>
187189
{text}
188190
</Button>
189191
</div>
190192
);
191-
});
193+
};
192194

193195
Fab.displayName = 'Fab';
194196
export default Fab;

0 commit comments

Comments
 (0)