Skip to content

Commit c236de7

Browse files
authored
fix: avoid deep rc component imports (ant-design#58130)
1 parent afda2e6 commit c236de7

7 files changed

Lines changed: 28 additions & 25 deletions

File tree

components/mentions/demo/_semantic.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React from 'react';
22
import { UnstableContext } from '@rc-component/mentions';
3-
import type { UnstableContextProps } from '@rc-component/mentions/lib/context';
43
import type { MentionProps } from 'antd';
54
import { Mentions } from 'antd';
65

@@ -25,7 +24,10 @@ const locales = {
2524

2625
const Block: React.FC<MentionProps> = (props) => {
2726
const divRef = React.useRef<HTMLDivElement>(null);
28-
const memoizedValue = React.useMemo<UnstableContextProps>(() => ({ open: true }), []);
27+
const memoizedValue = React.useMemo<React.ContextType<typeof UnstableContext>>(
28+
() => ({ open: true }),
29+
[],
30+
);
2931
return (
3032
<div ref={divRef} style={{ position: 'absolute', height: 200, overflow: 'hidden' }}>
3133
<UnstableContext.Provider value={memoizedValue}>

components/mentions/index.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
import * as React from 'react';
22
import RcMentions from '@rc-component/mentions';
3-
import type {
4-
DataDrivenOptionProps as MentionsOptionProps,
5-
MentionsProps as RcMentionsProps,
6-
MentionsRef as RcMentionsRef,
7-
} from '@rc-component/mentions/lib/Mentions';
3+
import type { MentionsProps as RcMentionsProps } from '@rc-component/mentions';
84
import { composeRef } from '@rc-component/util';
95
import { clsx } from 'clsx';
106

@@ -37,7 +33,8 @@ function loadingFilterOption() {
3733

3834
export type MentionPlacement = 'top' | 'bottom';
3935

40-
export type { DataDrivenOptionProps as MentionsOptionProps } from '@rc-component/mentions/lib/Mentions';
36+
export type MentionsOptionProps = NonNullable<RcMentionsProps['options']>[number];
37+
type RcMentionsRef = React.ComponentRef<typeof RcMentions>;
4138

4239
export interface OptionProps {
4340
value: string;

components/menu/interface.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import type {
2-
MenuDividerType as RcMenuDividerType,
3-
MenuItemGroupType as RcMenuItemGroupType,
4-
MenuItemType as RcMenuItemType,
5-
SubMenuType as RcSubMenuType,
6-
} from '@rc-component/menu/lib/interface';
1+
import type { MenuProps as RcMenuProps } from '@rc-component/menu';
2+
3+
type RcItemType = NonNullable<NonNullable<RcMenuProps['items']>[number]>;
4+
type RcMenuDividerType = Extract<RcItemType, { type: 'divider' }>;
5+
type RcMenuItemGroupType = Extract<RcItemType, { type: 'group' }>;
6+
type RcMenuItemType = Extract<RcItemType, { type?: 'item' }>;
7+
type RcSubMenuType = Extract<RcItemType, { type?: 'submenu' }>;
78

89
export type DataAttributes = {
910
[Key in `data-${string}`]: unknown;

components/modal/PurePanel.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as React from 'react';
22
import { Panel } from '@rc-component/dialog';
3-
import type { PanelProps } from '@rc-component/dialog/lib/Dialog/Content/Panel';
43
import { clsx } from 'clsx';
54

65
import { useMergeSemantic } from '../_util/hooks/useMergeSemantic';
@@ -13,6 +12,8 @@ import type { ModalFuncProps, ModalSemanticAllType } from './interface';
1312
import { Footer, renderCloseIcon } from './shared';
1413
import useStyle from './style';
1514

15+
type PanelProps = React.ComponentPropsWithoutRef<typeof Panel>;
16+
1617
export interface PurePanelProps
1718
extends Omit<PanelProps, 'prefixCls' | 'footer' | 'classNames' | 'styles'>,
1819
Pick<ModalFuncProps, 'type' | 'footer'> {

components/rate/index.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import * as React from 'react';
22
import StarFilled from '@ant-design/icons/StarFilled';
33
import RcRate from '@rc-component/rate';
4-
import type { RateRef, RateProps as RcRateProps } from '@rc-component/rate/lib/Rate';
5-
import type { StarProps as RcStarProps } from '@rc-component/rate/lib/Star';
64
import { clsx } from 'clsx';
75

86
import { isPlainObject } from '../_util/is';
@@ -14,6 +12,10 @@ import Tooltip from '../tooltip';
1412
import type { TooltipProps } from '../tooltip';
1513
import useStyle from './style';
1614

15+
type RateRef = React.ComponentRef<typeof RcRate>;
16+
type RcRateProps = React.ComponentPropsWithoutRef<typeof RcRate>;
17+
type RcCharacterRender = NonNullable<RcRateProps['characterRender']>;
18+
1719
export interface RateProps extends RcRateProps {
1820
rootClassName?: string;
1921
tooltips?: (TooltipProps | string)[];
@@ -33,7 +35,7 @@ const Rate = React.forwardRef<RateRef, RateProps>((props, ref) => {
3335
...rest
3436
} = props;
3537

36-
const characterRender: RcStarProps['characterRender'] = (node, { index }) => {
38+
const characterRender: RcCharacterRender = (node, { index }) => {
3739
if (!tooltips) {
3840
return node;
3941
}

components/tooltip/index.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
import * as React from 'react';
22
import RcTooltip from '@rc-component/tooltip';
3-
import type { placements as Placements } from '@rc-component/tooltip/lib/placements';
4-
import type {
5-
TooltipProps as RcTooltipProps,
6-
TooltipRef as RcTooltipRef,
7-
} from '@rc-component/tooltip/lib/Tooltip';
83
import type { BuildInPlacements } from '@rc-component/trigger';
94
import { useControlledState } from '@rc-component/util';
105
import { clsx } from 'clsx';
@@ -33,6 +28,10 @@ import useStyle from './style';
3328
import UniqueProvider from './UniqueProvider';
3429
import { parseColor } from './util';
3530

31+
type RcTooltipProps = React.ComponentPropsWithoutRef<typeof RcTooltip>;
32+
type RcTooltipRef = React.ComponentRef<typeof RcTooltip>;
33+
type Placements = NonNullable<RcTooltipProps['builtinPlacements']>;
34+
3635
export type { AdjustOverflow, PlacementsConfig };
3736

3837
export interface TooltipRef {
@@ -110,7 +109,7 @@ export interface AbstractTooltipProps extends LegacyTooltipProps {
110109
rootClassName?: string;
111110
color?: LiteralUnion<PresetColorType>;
112111
placement?: TooltipPlacement;
113-
builtinPlacements?: typeof Placements;
112+
builtinPlacements?: Placements;
114113
openClassName?: string;
115114
arrow?: boolean | { pointAtCenter?: boolean };
116115
autoAdjustOverflow?: boolean | AdjustOverflow;

components/tree-select/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import RcTreeSelect, {
77
SHOW_PARENT,
88
TreeNode,
99
} from '@rc-component/tree-select';
10-
import type { DataNode } from '@rc-component/tree-select/lib/interface';
1110
import { omit } from '@rc-component/util';
1211
import { clsx } from 'clsx';
1312

@@ -42,6 +41,8 @@ import type { SwitcherIcon } from '../tree/Tree';
4241
import SwitcherIconCom from '../tree/utils/iconUtil';
4342
import useStyle from './style';
4443

44+
type DataNode = NonNullable<RcTreeSelectProps['treeData']>[number];
45+
4546
type RawValue = string | number;
4647

4748
export interface LabeledValue {

0 commit comments

Comments
 (0)