Skip to content

Commit

Permalink
feat: [v6] Retire deprecated api for typography (ant-design#52472)
Browse files Browse the repository at this point in the history
Co-authored-by: thinkasany <480968828@qq.com>
  • Loading branch information
kiner-tang and thinkasany authored Jan 20, 2025
1 parent b598467 commit 921caf9
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 24 deletions.
17 changes: 2 additions & 15 deletions components/typography/Typography.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import * as React from 'react';
import type { JSX } from 'react';
import { composeRef } from '@rc-component/util/lib/ref';
import classNames from 'classnames';

import { devUseWarning } from '../_util/warning';
import type { ConfigConsumerProps, DirectionType } from '../config-provider';
import { ConfigContext } from '../config-provider';
import useStyle from './style';
Expand All @@ -23,10 +20,7 @@ export interface TypographyProps<C extends keyof JSX.IntrinsicElements>
}

interface InternalTypographyProps<C extends keyof JSX.IntrinsicElements>
extends TypographyProps<C> {
/** @deprecated Use `ref` directly if using React 16 */
setContentRef?: (node: HTMLElement) => void;
}
extends TypographyProps<C> {}

const Typography = React.forwardRef<
HTMLElement,
Expand All @@ -37,7 +31,6 @@ const Typography = React.forwardRef<
component: Component = 'article',
className,
rootClassName,
setContentRef,
children,
direction: typographyDirection,
style,
Expand All @@ -51,14 +44,8 @@ const Typography = React.forwardRef<
} = React.useContext<ConfigConsumerProps>(ConfigContext);

const direction = typographyDirection ?? contextDirection;
const mergedRef = setContentRef ? composeRef(ref, setContentRef) : ref;
const prefixCls = getPrefixCls('typography', customizePrefixCls);

if (process.env.NODE_ENV !== 'production') {
const warning = devUseWarning('Typography');
warning.deprecated(!setContentRef, 'setContentRef', 'ref');
}

// Style
const [wrapCSSVar, hashId, cssVarCls] = useStyle(prefixCls);
const componentClassName = classNames(
Expand All @@ -77,7 +64,7 @@ const Typography = React.forwardRef<

return wrapCSSVar(
// @ts-expect-error: Expression produces a union type that is too complex to represent.
<Component className={componentClassName} style={mergedStyle} ref={mergedRef} {...restProps}>
<Component className={componentClassName} style={mergedStyle} ref={ref} {...restProps}>
{children}
</Component>,
);
Expand Down
9 changes: 0 additions & 9 deletions components/typography/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import Paragraph from '../Paragraph';
import Text from '../Text';
import type { TitleProps } from '../Title';
import Title from '../Title';
import Typography from '../Typography';

jest.mock('copy-to-clipboard');

Expand Down Expand Up @@ -445,14 +444,6 @@ describe('Typography', () => {
});
});

it('warning if use setContentRef', () => {
const setContentRef = { setContentRef() {} } as any;
render(<Typography {...setContentRef} />);
expect(errorSpy).toHaveBeenCalledWith(
'Warning: [antd: Typography] `setContentRef` is deprecated. Please use `ref` instead.',
);
});

it('no italic warning', () => {
resetWarned();
render(<Text italic>Little</Text>);
Expand Down

0 comments on commit 921caf9

Please sign in to comment.