From db2b6c93f623a22429abd68581f05db1a3447368 Mon Sep 17 00:00:00 2001 From: lijianan <574980606@qq.com> Date: Sat, 25 Oct 2025 10:24:24 +0800 Subject: [PATCH] chore: code style optimization (#55450) * chore: code style optimization * update --- components/typography/Link.tsx | 23 ++++++++++++++++------- components/typography/Paragraph.tsx | 11 ++++++++--- components/typography/Text.tsx | 12 +++++++----- components/typography/Title.tsx | 8 ++++++-- components/upload/Dragger.tsx | 16 ++++++++++------ 5 files changed, 47 insertions(+), 23 deletions(-) diff --git a/components/typography/Link.tsx b/components/typography/Link.tsx index 1b9575dc42..a39dbf255a 100644 --- a/components/typography/Link.tsx +++ b/components/typography/Link.tsx @@ -10,22 +10,31 @@ export interface LinkProps ellipsis?: boolean; } -const Link = React.forwardRef(({ ellipsis, rel, ...restProps }, ref) => { +const Link = React.forwardRef((props, ref) => { + const { + ellipsis, + rel, + children, + // @ts-expect-error: https://github.com/ant-design/ant-design/issues/26622 + navigate: _navigate, + ...restProps + } = props; + if (process.env.NODE_ENV !== 'production') { const warning = devUseWarning('Typography.Link'); - warning(typeof ellipsis !== 'object', 'usage', '`ellipsis` only supports boolean value.'); } - const mergedProps = { + const mergedProps: LinkProps = { ...restProps, rel: rel === undefined && restProps.target === '_blank' ? 'noopener noreferrer' : rel, }; - // @ts-expect-error: https://github.com/ant-design/ant-design/issues/26622 - delete mergedProps.navigate; - - return ; + return ( + + {children} + + ); }); export default Link; diff --git a/components/typography/Paragraph.tsx b/components/typography/Paragraph.tsx index 2911e90fff..58eb8f6ddd 100644 --- a/components/typography/Paragraph.tsx +++ b/components/typography/Paragraph.tsx @@ -7,8 +7,13 @@ export interface ParagraphProps extends BlockProps<'div'>, Omit, 'type' | keyof BlockProps<'div'>> {} -const Paragraph = React.forwardRef((props, ref) => ( - -)); +const Paragraph = React.forwardRef((props, ref) => { + const { children, ...restProps } = props; + return ( + + {children} + + ); +}); export default Paragraph; diff --git a/components/typography/Text.tsx b/components/typography/Text.tsx index a20aa9ab0f..26670c6628 100644 --- a/components/typography/Text.tsx +++ b/components/typography/Text.tsx @@ -11,10 +11,8 @@ export interface TextProps ellipsis?: boolean | Omit; } -const Text: React.ForwardRefRenderFunction = ( - { ellipsis, ...restProps }, - ref, -) => { +const Text: React.ForwardRefRenderFunction = (props, ref) => { + const { ellipsis, children, ...restProps } = props; const mergedEllipsis = React.useMemo(() => { if (ellipsis && typeof ellipsis === 'object') { return omit(ellipsis as EllipsisConfig, ['expandable', 'rows']); @@ -34,7 +32,11 @@ const Text: React.ForwardRefRenderFunction = ( ); } - return ; + return ( + + {children} + + ); }; export default React.forwardRef(Text); diff --git a/components/typography/Title.tsx b/components/typography/Title.tsx index 0f74134a1a..63d0e04732 100644 --- a/components/typography/Title.tsx +++ b/components/typography/Title.tsx @@ -17,7 +17,7 @@ export interface TitleProps } const Title = React.forwardRef((props, ref) => { - const { level = 1, ...restProps } = props; + const { level = 1, children, ...restProps } = props; if (process.env.NODE_ENV !== 'production') { const warning = devUseWarning('Typography.Title'); @@ -30,7 +30,11 @@ const Title = React.forwardRef((props, ref) => { const component: keyof JSX.IntrinsicElements = TITLE_ELE_LIST.includes(level) ? `h${level}` : `h1`; - return ; + return ( + + {children} + + ); }); export default Title; diff --git a/components/upload/Dragger.tsx b/components/upload/Dragger.tsx index 27eaa400e8..f194e6e628 100644 --- a/components/upload/Dragger.tsx +++ b/components/upload/Dragger.tsx @@ -6,17 +6,21 @@ import Upload from './Upload'; export type DraggerProps = UploadProps & { height?: number }; -const Dragger = React.forwardRef( - ({ style, height, hasControlInside = false, ...restProps }, ref) => ( +const Dragger = React.forwardRef>((props, ref) => { + const { style, height, hasControlInside = false, children, ...restProps } = props; + const mergedStyle: React.CSSProperties = { ...style, height }; + return ( - ), -); + > + {children} + + ); +}); if (process.env.NODE_ENV !== 'production') { Dragger.displayName = 'Dragger';