mirror of
https://github.com/ant-design/ant-design.git
synced 2025-06-07 17:44:35 +08:00
type: optimize CompoundedComponent type (#48346)
* type: optimize CompoundedComponent type * chore: fix * type: fix type * chore: fix * type: fix type * type: add ts-ignore * fix: fix * chore: revert
This commit is contained in:
parent
44cd5342f7
commit
854cdb4352
@ -1,6 +1,3 @@
|
|||||||
import type { ForwardRefExoticComponent, RefAttributes } from 'react';
|
|
||||||
|
|
||||||
import type { AvatarProps } from './avatar';
|
|
||||||
import InternalAvatar from './avatar';
|
import InternalAvatar from './avatar';
|
||||||
import Group from './group';
|
import Group from './group';
|
||||||
|
|
||||||
@ -8,9 +5,7 @@ export type { AvatarProps } from './avatar';
|
|||||||
export type { GroupProps } from './group';
|
export type { GroupProps } from './group';
|
||||||
export { Group };
|
export { Group };
|
||||||
|
|
||||||
type CompoundedComponent = ForwardRefExoticComponent<
|
type CompoundedComponent = typeof InternalAvatar & {
|
||||||
AvatarProps & RefAttributes<HTMLSpanElement>
|
|
||||||
> & {
|
|
||||||
Group: typeof Group;
|
Group: typeof Group;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ import React from 'react';
|
|||||||
import { fireEvent, render } from '@testing-library/react';
|
import { fireEvent, render } from '@testing-library/react';
|
||||||
import { act } from 'react-dom/test-utils';
|
import { act } from 'react-dom/test-utils';
|
||||||
|
|
||||||
|
import type { GetRef } from '../../_util/type';
|
||||||
import mountTest from '../../../tests/shared/mountTest';
|
import mountTest from '../../../tests/shared/mountTest';
|
||||||
import rtlTest from '../../../tests/shared/rtlTest';
|
import rtlTest from '../../../tests/shared/rtlTest';
|
||||||
import Tooltip from '../../tooltip';
|
import Tooltip from '../../tooltip';
|
||||||
@ -75,7 +76,7 @@ describe('Badge', () => {
|
|||||||
|
|
||||||
// https://github.com/ant-design/ant-design/issues/10626
|
// https://github.com/ant-design/ant-design/issues/10626
|
||||||
it('should be composable with Tooltip', () => {
|
it('should be composable with Tooltip', () => {
|
||||||
const ref = React.createRef<typeof Tooltip>();
|
const ref = React.createRef<GetRef<typeof Tooltip>>();
|
||||||
const { container } = render(
|
const { container } = render(
|
||||||
<Tooltip title="Fix the error" ref={ref}>
|
<Tooltip title="Fix the error" ref={ref}>
|
||||||
<Badge status="error" />
|
<Badge status="error" />
|
||||||
|
@ -15,12 +15,6 @@ import useStyle from './style';
|
|||||||
|
|
||||||
export type { ScrollNumberProps } from './ScrollNumber';
|
export type { ScrollNumberProps } from './ScrollNumber';
|
||||||
|
|
||||||
type CompoundedComponent = React.ForwardRefExoticComponent<
|
|
||||||
BadgeProps & React.RefAttributes<HTMLSpanElement>
|
|
||||||
> & {
|
|
||||||
Ribbon: typeof Ribbon;
|
|
||||||
};
|
|
||||||
|
|
||||||
export interface BadgeProps {
|
export interface BadgeProps {
|
||||||
/** Number to show in badge */
|
/** Number to show in badge */
|
||||||
count?: React.ReactNode;
|
count?: React.ReactNode;
|
||||||
@ -51,7 +45,7 @@ export interface BadgeProps {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const InternalBadge: React.ForwardRefRenderFunction<HTMLSpanElement, BadgeProps> = (props, ref) => {
|
const InternalBadge = React.forwardRef<HTMLSpanElement, BadgeProps>((props, ref) => {
|
||||||
const {
|
const {
|
||||||
prefixCls: customizePrefixCls,
|
prefixCls: customizePrefixCls,
|
||||||
scrollNumberPrefixCls: customizeScrollNumberPrefixCls,
|
scrollNumberPrefixCls: customizeScrollNumberPrefixCls,
|
||||||
@ -271,9 +265,13 @@ const InternalBadge: React.ForwardRefRenderFunction<HTMLSpanElement, BadgeProps>
|
|||||||
{statusTextNode}
|
{statusTextNode}
|
||||||
</span>,
|
</span>,
|
||||||
);
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
type CompoundedComponent = typeof InternalBadge & {
|
||||||
|
Ribbon: typeof Ribbon;
|
||||||
};
|
};
|
||||||
|
|
||||||
const Badge = React.forwardRef<HTMLSpanElement, BadgeProps>(InternalBadge) as CompoundedComponent;
|
const Badge = InternalBadge as CompoundedComponent;
|
||||||
|
|
||||||
Badge.Ribbon = Ribbon;
|
Badge.Ribbon = Ribbon;
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ import * as React from 'react';
|
|||||||
|
|
||||||
import { ConfigContext } from '../config-provider';
|
import { ConfigContext } from '../config-provider';
|
||||||
|
|
||||||
type CompoundedComponent = React.FC<{ children?: React.ReactNode }> & {
|
type CompoundedComponent = React.FC<React.PropsWithChildren> & {
|
||||||
/** @internal */
|
/** @internal */
|
||||||
__ANT_BREADCRUMB_SEPARATOR: boolean;
|
__ANT_BREADCRUMB_SEPARATOR: boolean;
|
||||||
};
|
};
|
||||||
@ -10,7 +10,6 @@ type CompoundedComponent = React.FC<{ children?: React.ReactNode }> & {
|
|||||||
const BreadcrumbSeparator: CompoundedComponent = ({ children }) => {
|
const BreadcrumbSeparator: CompoundedComponent = ({ children }) => {
|
||||||
const { getPrefixCls } = React.useContext(ConfigContext);
|
const { getPrefixCls } = React.useContext(ConfigContext);
|
||||||
const prefixCls = getPrefixCls('breadcrumb');
|
const prefixCls = getPrefixCls('breadcrumb');
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<li className={`${prefixCls}-separator`} aria-hidden="true">
|
<li className={`${prefixCls}-separator`} aria-hidden="true">
|
||||||
{children === '' ? children : children || '/'}
|
{children === '' ? children : children || '/'}
|
||||||
|
@ -4,6 +4,7 @@ import { resetWarned } from 'rc-util/lib/warning';
|
|||||||
import { act } from 'react-dom/test-utils';
|
import { act } from 'react-dom/test-utils';
|
||||||
|
|
||||||
import Button from '..';
|
import Button from '..';
|
||||||
|
import type { GetRef } from '../../_util/type';
|
||||||
import mountTest from '../../../tests/shared/mountTest';
|
import mountTest from '../../../tests/shared/mountTest';
|
||||||
import rtlTest from '../../../tests/shared/rtlTest';
|
import rtlTest from '../../../tests/shared/rtlTest';
|
||||||
import { fireEvent, render, waitFakeTimer } from '../../../tests/utils';
|
import { fireEvent, render, waitFakeTimer } from '../../../tests/utils';
|
||||||
@ -292,7 +293,7 @@ describe('Button', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('skip check 2 words when ConfigProvider disable this', () => {
|
it('skip check 2 words when ConfigProvider disable this', () => {
|
||||||
const buttonInstance = React.createRef<HTMLElement>();
|
const buttonInstance = React.createRef<GetRef<typeof Button>>();
|
||||||
render(
|
render(
|
||||||
<ConfigProvider autoInsertSpaceInButton={false}>
|
<ConfigProvider autoInsertSpaceInButton={false}>
|
||||||
<Button ref={buttonInstance}>test</Button>
|
<Button ref={buttonInstance}>test</Button>
|
||||||
@ -369,13 +370,13 @@ describe('Button', () => {
|
|||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
||||||
const btnRef = React.createRef<HTMLButtonElement>();
|
const btnRef = React.createRef<GetRef<typeof Button>>();
|
||||||
const refBtn = <Button ref={btnRef} />;
|
const refBtn = <Button ref={btnRef} />;
|
||||||
|
|
||||||
const anchorRef = React.createRef<HTMLAnchorElement>();
|
const anchorRef = React.createRef<GetRef<typeof Button>>();
|
||||||
const refAnchor = <Button ref={anchorRef} />;
|
const refAnchor = <Button ref={anchorRef} />;
|
||||||
|
|
||||||
const htmlRef = React.createRef<HTMLElement>();
|
const htmlRef = React.createRef<GetRef<typeof Button>>();
|
||||||
const refHtml = <Button ref={htmlRef} />;
|
const refHtml = <Button ref={htmlRef} />;
|
||||||
|
|
||||||
const btnAttr = <Button name="hello" />;
|
const btnAttr = <Button name="hello" />;
|
||||||
|
@ -1,13 +1,5 @@
|
|||||||
/* eslint-disable react/button-has-type */
|
/* eslint-disable react/button-has-type */
|
||||||
import React, {
|
import React, { Children, createRef, useContext, useEffect, useMemo, useState } from 'react';
|
||||||
Children,
|
|
||||||
createRef,
|
|
||||||
forwardRef,
|
|
||||||
useContext,
|
|
||||||
useEffect,
|
|
||||||
useMemo,
|
|
||||||
useState,
|
|
||||||
} from 'react';
|
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import omit from 'rc-util/lib/omit';
|
import omit from 'rc-util/lib/omit';
|
||||||
import { composeRef } from 'rc-util/lib/ref';
|
import { composeRef } from 'rc-util/lib/ref';
|
||||||
@ -60,14 +52,6 @@ export interface ButtonProps extends BaseButtonProps, MergedHTMLAttributes {
|
|||||||
htmlType?: ButtonHTMLType;
|
htmlType?: ButtonHTMLType;
|
||||||
}
|
}
|
||||||
|
|
||||||
type CompoundedComponent = React.ForwardRefExoticComponent<
|
|
||||||
ButtonProps & React.RefAttributes<HTMLElement>
|
|
||||||
> & {
|
|
||||||
Group: typeof Group;
|
|
||||||
/** @internal */
|
|
||||||
__ANT_BUTTON: boolean;
|
|
||||||
};
|
|
||||||
|
|
||||||
type LoadingConfigType = {
|
type LoadingConfigType = {
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
delay: number;
|
delay: number;
|
||||||
@ -89,10 +73,10 @@ function getLoadingConfig(loading: BaseButtonProps['loading']): LoadingConfigTyp
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const InternalButton: React.ForwardRefRenderFunction<
|
const InternalCompoundedButton = React.forwardRef<
|
||||||
HTMLButtonElement | HTMLAnchorElement,
|
HTMLButtonElement | HTMLAnchorElement,
|
||||||
ButtonProps
|
ButtonProps
|
||||||
> = (props, ref) => {
|
>((props, ref) => {
|
||||||
const {
|
const {
|
||||||
loading = false,
|
loading = false,
|
||||||
prefixCls: customizePrefixCls,
|
prefixCls: customizePrefixCls,
|
||||||
@ -303,19 +287,22 @@ const InternalButton: React.ForwardRefRenderFunction<
|
|||||||
</Wave>
|
</Wave>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return wrapCSSVar(buttonNode);
|
return wrapCSSVar(buttonNode);
|
||||||
|
});
|
||||||
|
|
||||||
|
type CompoundedComponent = typeof InternalCompoundedButton & {
|
||||||
|
Group: typeof Group;
|
||||||
|
/** @internal */
|
||||||
|
__ANT_BUTTON: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
const Button = forwardRef<HTMLButtonElement | HTMLAnchorElement, ButtonProps>(
|
const Button = InternalCompoundedButton as CompoundedComponent;
|
||||||
InternalButton,
|
|
||||||
) as CompoundedComponent;
|
Button.Group = Group;
|
||||||
|
Button.__ANT_BUTTON = true;
|
||||||
|
|
||||||
if (process.env.NODE_ENV !== 'production') {
|
if (process.env.NODE_ENV !== 'production') {
|
||||||
Button.displayName = 'Button';
|
Button.displayName = 'Button';
|
||||||
}
|
}
|
||||||
|
|
||||||
Button.Group = Group;
|
|
||||||
Button.__ANT_BUTTON = true;
|
|
||||||
|
|
||||||
export default Button;
|
export default Button;
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
import type * as React from 'react';
|
|
||||||
import type { CheckboxRef } from 'rc-checkbox';
|
import type { CheckboxRef } from 'rc-checkbox';
|
||||||
|
|
||||||
import type { CheckboxProps } from './Checkbox';
|
|
||||||
import InternalCheckbox from './Checkbox';
|
import InternalCheckbox from './Checkbox';
|
||||||
import Group from './Group';
|
import Group from './Group';
|
||||||
|
|
||||||
@ -9,9 +7,7 @@ export type { CheckboxChangeEvent, CheckboxProps } from './Checkbox';
|
|||||||
export type { CheckboxGroupProps, CheckboxOptionType } from './Group';
|
export type { CheckboxGroupProps, CheckboxOptionType } from './Group';
|
||||||
export type { CheckboxRef };
|
export type { CheckboxRef };
|
||||||
|
|
||||||
type CompoundedComponent = React.ForwardRefExoticComponent<
|
type CompoundedComponent = typeof InternalCheckbox & {
|
||||||
CheckboxProps & React.RefAttributes<CheckboxRef>
|
|
||||||
> & {
|
|
||||||
Group: typeof Group;
|
Group: typeof Group;
|
||||||
/** @internal */
|
/** @internal */
|
||||||
__ANT_CHECKBOX: boolean;
|
__ANT_CHECKBOX: boolean;
|
||||||
|
@ -8,21 +8,23 @@ import type { ConfigConsumerProps } from '../config-provider';
|
|||||||
import { ConfigContext } from '../config-provider';
|
import { ConfigContext } from '../config-provider';
|
||||||
import useCSSVarCls from '../config-provider/hooks/useCSSVarCls';
|
import useCSSVarCls from '../config-provider/hooks/useCSSVarCls';
|
||||||
import Tooltip from '../tooltip';
|
import Tooltip from '../tooltip';
|
||||||
|
import type BackTop from './BackTop';
|
||||||
import FloatButtonGroupContext from './context';
|
import FloatButtonGroupContext from './context';
|
||||||
import Content from './FloatButtonContent';
|
import Content from './FloatButtonContent';
|
||||||
|
import type FloatButtonGroup from './FloatButtonGroup';
|
||||||
import type {
|
import type {
|
||||||
CompoundedComponent,
|
|
||||||
FloatButtonBadgeProps,
|
FloatButtonBadgeProps,
|
||||||
FloatButtonContentProps,
|
FloatButtonContentProps,
|
||||||
FloatButtonElement,
|
FloatButtonElement,
|
||||||
FloatButtonProps,
|
FloatButtonProps,
|
||||||
FloatButtonShape,
|
FloatButtonShape,
|
||||||
} from './interface';
|
} from './interface';
|
||||||
|
import type PurePanel from './PurePanel';
|
||||||
import useStyle from './style';
|
import useStyle from './style';
|
||||||
|
|
||||||
export const floatButtonPrefixCls = 'float-btn';
|
export const floatButtonPrefixCls = 'float-btn';
|
||||||
|
|
||||||
const FloatButton = React.forwardRef<FloatButtonElement, FloatButtonProps>((props, ref) => {
|
const InternalFloatButton = React.forwardRef<FloatButtonElement, FloatButtonProps>((props, ref) => {
|
||||||
const {
|
const {
|
||||||
prefixCls: customizePrefixCls,
|
prefixCls: customizePrefixCls,
|
||||||
className,
|
className,
|
||||||
@ -107,7 +109,15 @@ const FloatButton = React.forwardRef<FloatButtonElement, FloatButtonProps>((prop
|
|||||||
</button>
|
</button>
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}) as CompoundedComponent;
|
});
|
||||||
|
|
||||||
|
type CompoundedComponent = typeof InternalFloatButton & {
|
||||||
|
Group: typeof FloatButtonGroup;
|
||||||
|
BackTop: typeof BackTop;
|
||||||
|
_InternalPanelDoNotUseOrYouWillBeFired: typeof PurePanel;
|
||||||
|
};
|
||||||
|
|
||||||
|
const FloatButton = InternalFloatButton as CompoundedComponent;
|
||||||
|
|
||||||
if (process.env.NODE_ENV !== 'production') {
|
if (process.env.NODE_ENV !== 'production') {
|
||||||
FloatButton.displayName = 'FloatButton';
|
FloatButton.displayName = 'FloatButton';
|
||||||
|
@ -2,9 +2,6 @@ import type React from 'react';
|
|||||||
|
|
||||||
import type { BadgeProps } from '../badge';
|
import type { BadgeProps } from '../badge';
|
||||||
import type { TooltipProps } from '../tooltip';
|
import type { TooltipProps } from '../tooltip';
|
||||||
import type BackTop from './BackTop';
|
|
||||||
import type Group from './FloatButtonGroup';
|
|
||||||
import type PurePanel from './PurePanel';
|
|
||||||
|
|
||||||
export type FloatButtonElement = HTMLAnchorElement & HTMLButtonElement;
|
export type FloatButtonElement = HTMLAnchorElement & HTMLButtonElement;
|
||||||
|
|
||||||
@ -67,11 +64,3 @@ export interface BackTopProps extends Omit<FloatButtonProps, 'target'> {
|
|||||||
style?: React.CSSProperties;
|
style?: React.CSSProperties;
|
||||||
duration?: number;
|
duration?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type CompoundedComponent = React.ForwardRefExoticComponent<
|
|
||||||
FloatButtonProps & React.RefAttributes<FloatButtonElement>
|
|
||||||
> & {
|
|
||||||
Group: typeof Group;
|
|
||||||
BackTop: typeof BackTop;
|
|
||||||
_InternalPanelDoNotUseOrYouWillBeFired: typeof PurePanel;
|
|
||||||
};
|
|
||||||
|
@ -1,7 +1,4 @@
|
|||||||
import type * as React from 'react';
|
|
||||||
|
|
||||||
import Group from './Group';
|
import Group from './Group';
|
||||||
import type { InputProps, InputRef } from './Input';
|
|
||||||
import InternalInput from './Input';
|
import InternalInput from './Input';
|
||||||
import OTP from './OTP';
|
import OTP from './OTP';
|
||||||
import Password from './Password';
|
import Password from './Password';
|
||||||
@ -14,9 +11,7 @@ export type { PasswordProps } from './Password';
|
|||||||
export type { SearchProps } from './Search';
|
export type { SearchProps } from './Search';
|
||||||
export type { TextAreaProps } from './TextArea';
|
export type { TextAreaProps } from './TextArea';
|
||||||
|
|
||||||
type CompoundedComponent = React.ForwardRefExoticComponent<
|
type CompoundedComponent = typeof InternalInput & {
|
||||||
InputProps & React.RefAttributes<InputRef>
|
|
||||||
> & {
|
|
||||||
Group: typeof Group;
|
Group: typeof Group;
|
||||||
Search: typeof Search;
|
Search: typeof Search;
|
||||||
TextArea: typeof TextArea;
|
TextArea: typeof TextArea;
|
||||||
|
@ -1,13 +1,5 @@
|
|||||||
import type {
|
import type { CSSProperties, FC, HTMLAttributes, ReactElement, ReactNode } from 'react';
|
||||||
CSSProperties,
|
import React, { Children, useContext } from 'react';
|
||||||
FC,
|
|
||||||
ForwardRefExoticComponent,
|
|
||||||
ForwardRefRenderFunction,
|
|
||||||
HTMLAttributes,
|
|
||||||
ReactElement,
|
|
||||||
ReactNode,
|
|
||||||
} from 'react';
|
|
||||||
import React, { Children, forwardRef, useContext } from 'react';
|
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
|
|
||||||
import { cloneElement } from '../_util/reactNode';
|
import { cloneElement } from '../_util/reactNode';
|
||||||
@ -63,15 +55,16 @@ export const Meta: FC<ListItemMetaProps> = ({
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface ListItemTypeProps
|
const InternalItem = React.forwardRef<HTMLDivElement, ListItemProps>((props, ref) => {
|
||||||
extends ForwardRefExoticComponent<ListItemProps & React.RefAttributes<HTMLElement>> {
|
const {
|
||||||
Meta: typeof Meta;
|
prefixCls: customizePrefixCls,
|
||||||
}
|
children,
|
||||||
|
actions,
|
||||||
const InternalItem: ForwardRefRenderFunction<HTMLDivElement, ListItemProps> = (
|
extra,
|
||||||
{ prefixCls: customizePrefixCls, children, actions, extra, className, colStyle, ...others },
|
className,
|
||||||
ref,
|
colStyle,
|
||||||
) => {
|
...others
|
||||||
|
} = props;
|
||||||
const { grid, itemLayout } = useContext(ListContext);
|
const { grid, itemLayout } = useContext(ListContext);
|
||||||
const { getPrefixCls } = useContext(ConfigContext);
|
const { getPrefixCls } = useContext(ConfigContext);
|
||||||
|
|
||||||
@ -130,7 +123,6 @@ const InternalItem: ForwardRefRenderFunction<HTMLDivElement, ListItemProps> = (
|
|||||||
: [children, actionsContent, cloneElement(extra, { key: 'extra' })]}
|
: [children, actionsContent, cloneElement(extra, { key: 'extra' })]}
|
||||||
</Element>
|
</Element>
|
||||||
);
|
);
|
||||||
|
|
||||||
return grid ? (
|
return grid ? (
|
||||||
<Col ref={ref} flex={1} style={colStyle}>
|
<Col ref={ref} flex={1} style={colStyle}>
|
||||||
{itemChildren}
|
{itemChildren}
|
||||||
@ -138,8 +130,13 @@ const InternalItem: ForwardRefRenderFunction<HTMLDivElement, ListItemProps> = (
|
|||||||
) : (
|
) : (
|
||||||
itemChildren
|
itemChildren
|
||||||
);
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
export type ListItemTypeProps = typeof InternalItem & {
|
||||||
|
Meta: typeof Meta;
|
||||||
};
|
};
|
||||||
const Item = forwardRef(InternalItem) as ListItemTypeProps;
|
|
||||||
|
const Item = InternalItem as ListItemTypeProps;
|
||||||
|
|
||||||
Item.Meta = Meta;
|
Item.Meta = Meta;
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import React, { useEffect } from 'react';
|
import React, { useEffect } from 'react';
|
||||||
|
|
||||||
import List from '..';
|
import List from '..';
|
||||||
|
import type { GetRef } from '../../_util/type';
|
||||||
import { pureRender, render } from '../../../tests/utils';
|
import { pureRender, render } from '../../../tests/utils';
|
||||||
import ConfigProvider from '../../config-provider';
|
import ConfigProvider from '../../config-provider';
|
||||||
|
|
||||||
@ -189,15 +190,13 @@ describe('List Item Layout', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should ref', () => {
|
it('should ref', () => {
|
||||||
const ref = React.createRef<HTMLElement>();
|
const ref = React.createRef<GetRef<typeof List.Item>>();
|
||||||
|
|
||||||
render(<List.Item ref={ref}>Item</List.Item>);
|
render(<List.Item ref={ref}>Item</List.Item>);
|
||||||
expect(ref.current).toHaveClass('ant-list-item');
|
expect(ref.current).toHaveClass('ant-list-item');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should grid ref', () => {
|
it('should grid ref', () => {
|
||||||
const ref = React.createRef<HTMLElement>();
|
const ref = React.createRef<GetRef<typeof List.Item>>();
|
||||||
|
|
||||||
render(
|
render(
|
||||||
<List grid={{}}>
|
<List grid={{}}>
|
||||||
<List.Item ref={ref}>Item</List.Item>,
|
<List.Item ref={ref}>Item</List.Item>,
|
||||||
|
@ -64,18 +64,7 @@ interface MentionsEntity {
|
|||||||
value: string;
|
value: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
type CompoundedComponent = React.ForwardRefExoticComponent<
|
const InternalMentions = React.forwardRef<MentionsRef, MentionProps>((props, ref) => {
|
||||||
MentionProps & React.RefAttributes<MentionsRef>
|
|
||||||
> & {
|
|
||||||
Option: typeof Option;
|
|
||||||
_InternalPanelDoNotUseOrYouWillBeFired: typeof PurePanel;
|
|
||||||
getMentions: (value: string, config?: MentionsConfig) => MentionsEntity[];
|
|
||||||
};
|
|
||||||
|
|
||||||
const InternalMentions: React.ForwardRefRenderFunction<MentionsRef, MentionProps> = (
|
|
||||||
props,
|
|
||||||
ref,
|
|
||||||
) => {
|
|
||||||
const {
|
const {
|
||||||
prefixCls: customizePrefixCls,
|
prefixCls: customizePrefixCls,
|
||||||
className,
|
className,
|
||||||
@ -223,14 +212,20 @@ const InternalMentions: React.ForwardRefRenderFunction<MentionsRef, MentionProps
|
|||||||
);
|
);
|
||||||
|
|
||||||
return wrapCSSVar(mentions);
|
return wrapCSSVar(mentions);
|
||||||
|
});
|
||||||
|
|
||||||
|
type CompoundedComponent = typeof InternalMentions & {
|
||||||
|
Option: typeof Option;
|
||||||
|
_InternalPanelDoNotUseOrYouWillBeFired: typeof PurePanel;
|
||||||
|
getMentions: (value: string, config?: MentionsConfig) => MentionsEntity[];
|
||||||
};
|
};
|
||||||
|
|
||||||
const Mentions = React.forwardRef<MentionsRef, MentionProps>(
|
const Mentions = InternalMentions as CompoundedComponent;
|
||||||
InternalMentions,
|
|
||||||
) as CompoundedComponent;
|
|
||||||
if (process.env.NODE_ENV !== 'production') {
|
if (process.env.NODE_ENV !== 'production') {
|
||||||
Mentions.displayName = 'Mentions';
|
Mentions.displayName = 'Mentions';
|
||||||
}
|
}
|
||||||
|
|
||||||
Mentions.Option = Option;
|
Mentions.Option = Option;
|
||||||
|
|
||||||
// We don't care debug panel
|
// We don't care debug panel
|
||||||
|
@ -37,7 +37,7 @@ export interface PopconfirmState {
|
|||||||
open?: boolean;
|
open?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Popconfirm = React.forwardRef<TooltipRef, PopconfirmProps>((props, ref) => {
|
const InternalPopconfirm = React.forwardRef<TooltipRef, PopconfirmProps>((props, ref) => {
|
||||||
const {
|
const {
|
||||||
prefixCls: customizePrefixCls,
|
prefixCls: customizePrefixCls,
|
||||||
placement = 'top',
|
placement = 'top',
|
||||||
@ -112,12 +112,14 @@ const Popconfirm = React.forwardRef<TooltipRef, PopconfirmProps>((props, ref) =>
|
|||||||
{children}
|
{children}
|
||||||
</Popover>,
|
</Popover>,
|
||||||
);
|
);
|
||||||
}) as React.ForwardRefExoticComponent<
|
});
|
||||||
React.PropsWithoutRef<PopconfirmProps> & React.RefAttributes<unknown>
|
|
||||||
> & {
|
type CompoundedComponent = typeof InternalPopconfirm & {
|
||||||
_InternalPanelDoNotUseOrYouWillBeFired: typeof PurePanel;
|
_InternalPanelDoNotUseOrYouWillBeFired: typeof PurePanel;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const Popconfirm = InternalPopconfirm as CompoundedComponent;
|
||||||
|
|
||||||
// We don't care debug panel
|
// We don't care debug panel
|
||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
Popconfirm._InternalPanelDoNotUseOrYouWillBeFired = PurePanel;
|
Popconfirm._InternalPanelDoNotUseOrYouWillBeFired = PurePanel;
|
||||||
|
@ -36,7 +36,7 @@ const Overlay: React.FC<OverlayProps> = ({ title, content, prefixCls }) => (
|
|||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
||||||
const Popover = React.forwardRef<TooltipRef, PopoverProps>((props, ref) => {
|
const InternalPopover = React.forwardRef<TooltipRef, PopoverProps>((props, ref) => {
|
||||||
const {
|
const {
|
||||||
prefixCls: customizePrefixCls,
|
prefixCls: customizePrefixCls,
|
||||||
title,
|
title,
|
||||||
@ -109,16 +109,18 @@ const Popover = React.forwardRef<TooltipRef, PopoverProps>((props, ref) => {
|
|||||||
})}
|
})}
|
||||||
</Tooltip>,
|
</Tooltip>,
|
||||||
);
|
);
|
||||||
}) as React.ForwardRefExoticComponent<
|
});
|
||||||
React.PropsWithoutRef<PopoverProps> & React.RefAttributes<unknown>
|
|
||||||
> & {
|
type CompoundedComponent = typeof InternalPopover & {
|
||||||
_InternalPanelDoNotUseOrYouWillBeFired: typeof PurePanel;
|
_InternalPanelDoNotUseOrYouWillBeFired: typeof PurePanel;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const Popover = InternalPopover as CompoundedComponent;
|
||||||
|
|
||||||
|
Popover._InternalPanelDoNotUseOrYouWillBeFired = PurePanel;
|
||||||
|
|
||||||
if (process.env.NODE_ENV !== 'production') {
|
if (process.env.NODE_ENV !== 'production') {
|
||||||
Popover.displayName = 'Popover';
|
Popover.displayName = 'Popover';
|
||||||
}
|
}
|
||||||
|
|
||||||
Popover._InternalPanelDoNotUseOrYouWillBeFired = PurePanel;
|
|
||||||
|
|
||||||
export default Popover;
|
export default Popover;
|
||||||
|
@ -1,7 +1,4 @@
|
|||||||
import type * as React from 'react';
|
|
||||||
|
|
||||||
import Group from './group';
|
import Group from './group';
|
||||||
import type { RadioProps, RadioRef } from './interface';
|
|
||||||
import InternalRadio from './radio';
|
import InternalRadio from './radio';
|
||||||
import Button from './radioButton';
|
import Button from './radioButton';
|
||||||
|
|
||||||
@ -17,9 +14,7 @@ export {
|
|||||||
} from './interface';
|
} from './interface';
|
||||||
export { Button, Group };
|
export { Button, Group };
|
||||||
|
|
||||||
type CompoundedComponent = React.ForwardRefExoticComponent<
|
type CompoundedComponent = typeof InternalRadio & {
|
||||||
RadioProps & React.RefAttributes<RadioRef>
|
|
||||||
> & {
|
|
||||||
Group: typeof Group;
|
Group: typeof Group;
|
||||||
Button: typeof Button;
|
Button: typeof Button;
|
||||||
/** @internal */
|
/** @internal */
|
||||||
|
@ -30,7 +30,7 @@ export interface SpaceProps extends React.HTMLAttributes<HTMLDivElement> {
|
|||||||
styles?: { item: React.CSSProperties };
|
styles?: { item: React.CSSProperties };
|
||||||
}
|
}
|
||||||
|
|
||||||
const Space = React.forwardRef<HTMLDivElement, SpaceProps>((props, ref) => {
|
const InternalSpace = React.forwardRef<HTMLDivElement, SpaceProps>((props, ref) => {
|
||||||
const { getPrefixCls, space, direction: directionConfig } = React.useContext(ConfigContext);
|
const { getPrefixCls, space, direction: directionConfig } = React.useContext(ConfigContext);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
@ -141,18 +141,16 @@ const Space = React.forwardRef<HTMLDivElement, SpaceProps>((props, ref) => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
type CompoundedComponent = typeof InternalSpace & {
|
||||||
|
Compact: typeof Compact;
|
||||||
|
};
|
||||||
|
|
||||||
|
const Space = InternalSpace as CompoundedComponent;
|
||||||
|
|
||||||
|
Space.Compact = Compact;
|
||||||
|
|
||||||
if (process.env.NODE_ENV !== 'production') {
|
if (process.env.NODE_ENV !== 'production') {
|
||||||
Space.displayName = 'Space';
|
Space.displayName = 'Space';
|
||||||
}
|
}
|
||||||
|
|
||||||
type CompoundedComponent = React.ForwardRefExoticComponent<
|
export default Space;
|
||||||
SpaceProps & React.RefAttributes<HTMLDivElement>
|
|
||||||
> & {
|
|
||||||
Compact: typeof Compact;
|
|
||||||
};
|
|
||||||
|
|
||||||
const CompoundedSpace = Space as CompoundedComponent;
|
|
||||||
|
|
||||||
CompoundedSpace.Compact = Compact;
|
|
||||||
|
|
||||||
export default CompoundedSpace;
|
|
||||||
|
@ -47,14 +47,7 @@ export interface SwitchProps {
|
|||||||
id?: string;
|
id?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
type CompoundedComponent = React.ForwardRefExoticComponent<
|
const InternalSwitch = React.forwardRef<HTMLButtonElement, SwitchProps>((props, ref) => {
|
||||||
SwitchProps & React.RefAttributes<HTMLElement>
|
|
||||||
> & {
|
|
||||||
/** @internal */
|
|
||||||
__ANT_SWITCH: boolean;
|
|
||||||
};
|
|
||||||
|
|
||||||
const Switch = React.forwardRef<HTMLButtonElement, SwitchProps>((props, ref) => {
|
|
||||||
const {
|
const {
|
||||||
prefixCls: customizePrefixCls,
|
prefixCls: customizePrefixCls,
|
||||||
size: customizeSize,
|
size: customizeSize,
|
||||||
@ -131,7 +124,14 @@ const Switch = React.forwardRef<HTMLButtonElement, SwitchProps>((props, ref) =>
|
|||||||
/>
|
/>
|
||||||
</Wave>,
|
</Wave>,
|
||||||
);
|
);
|
||||||
}) as CompoundedComponent;
|
});
|
||||||
|
|
||||||
|
type CompoundedComponent = typeof InternalSwitch & {
|
||||||
|
/** @internal */
|
||||||
|
__ANT_SWITCH: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
const Switch = InternalSwitch as CompoundedComponent;
|
||||||
|
|
||||||
Switch.__ANT_SWITCH = true;
|
Switch.__ANT_SWITCH = true;
|
||||||
|
|
||||||
|
@ -33,12 +33,7 @@ export interface TagProps extends React.HTMLAttributes<HTMLSpanElement> {
|
|||||||
bordered?: boolean;
|
bordered?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TagType
|
const InternalTag = React.forwardRef<HTMLSpanElement, TagProps>((tagProps, ref) => {
|
||||||
extends React.ForwardRefExoticComponent<TagProps & React.RefAttributes<HTMLElement>> {
|
|
||||||
CheckableTag: typeof CheckableTag;
|
|
||||||
}
|
|
||||||
|
|
||||||
const InternalTag: React.ForwardRefRenderFunction<HTMLSpanElement, TagProps> = (tagProps, ref) => {
|
|
||||||
const {
|
const {
|
||||||
prefixCls: customizePrefixCls,
|
prefixCls: customizePrefixCls,
|
||||||
className,
|
className,
|
||||||
@ -153,9 +148,13 @@ const InternalTag: React.ForwardRefRenderFunction<HTMLSpanElement, TagProps> = (
|
|||||||
);
|
);
|
||||||
|
|
||||||
return wrapCSSVar(isNeedWave ? <Wave component="Tag">{tagNode}</Wave> : tagNode);
|
return wrapCSSVar(isNeedWave ? <Wave component="Tag">{tagNode}</Wave> : tagNode);
|
||||||
|
});
|
||||||
|
|
||||||
|
export type TagType = typeof InternalTag & {
|
||||||
|
CheckableTag: typeof CheckableTag;
|
||||||
};
|
};
|
||||||
|
|
||||||
const Tag = React.forwardRef<HTMLSpanElement, TagProps>(InternalTag) as TagType;
|
const Tag = InternalTag as TagType;
|
||||||
|
|
||||||
if (process.env.NODE_ENV !== 'production') {
|
if (process.env.NODE_ENV !== 'production') {
|
||||||
Tag.displayName = 'Tag';
|
Tag.displayName = 'Tag';
|
||||||
|
@ -123,7 +123,7 @@ export interface TooltipPropsWithTitle extends AbstractTooltipProps {
|
|||||||
|
|
||||||
export declare type TooltipProps = TooltipPropsWithTitle | TooltipPropsWithOverlay;
|
export declare type TooltipProps = TooltipPropsWithTitle | TooltipPropsWithOverlay;
|
||||||
|
|
||||||
const Tooltip = React.forwardRef<TooltipRef, TooltipProps>((props, ref) => {
|
const InternalTooltip = React.forwardRef<TooltipRef, TooltipProps>((props, ref) => {
|
||||||
const {
|
const {
|
||||||
prefixCls: customizePrefixCls,
|
prefixCls: customizePrefixCls,
|
||||||
openClassName,
|
openClassName,
|
||||||
@ -331,12 +331,14 @@ const Tooltip = React.forwardRef<TooltipRef, TooltipProps>((props, ref) => {
|
|||||||
return wrapCSSVar(
|
return wrapCSSVar(
|
||||||
<zIndexContext.Provider value={contextZIndex}>{content}</zIndexContext.Provider>,
|
<zIndexContext.Provider value={contextZIndex}>{content}</zIndexContext.Provider>,
|
||||||
);
|
);
|
||||||
}) as React.ForwardRefExoticComponent<
|
});
|
||||||
React.PropsWithoutRef<TooltipProps> & React.RefAttributes<unknown>
|
|
||||||
> & {
|
type CompoundedComponent = typeof InternalTooltip & {
|
||||||
_InternalPanelDoNotUseOrYouWillBeFired: typeof PurePanel;
|
_InternalPanelDoNotUseOrYouWillBeFired: typeof PurePanel;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const Tooltip = InternalTooltip as CompoundedComponent;
|
||||||
|
|
||||||
if (process.env.NODE_ENV !== 'production') {
|
if (process.env.NODE_ENV !== 'production') {
|
||||||
Tooltip.displayName = 'Tooltip';
|
Tooltip.displayName = 'Tooltip';
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
import React, { useRef, useState } from 'react';
|
import React, { useRef, useState } from 'react';
|
||||||
import { EllipsisOutlined } from '@ant-design/icons';
|
import { EllipsisOutlined } from '@ant-design/icons';
|
||||||
import type { TourProps } from 'antd';
|
import type { GetRef, TourProps } from 'antd';
|
||||||
import { Button, Divider, Space, Tour } from 'antd';
|
import { Button, Divider, Space, Tour } from 'antd';
|
||||||
|
|
||||||
const App: React.FC = () => {
|
const App: React.FC = () => {
|
||||||
const ref1 = useRef<HTMLButtonElement>(null);
|
const ref1 = useRef<GetRef<typeof Button>>(null);
|
||||||
const ref2 = useRef<HTMLButtonElement>(null);
|
const ref2 = useRef<GetRef<typeof Button>>(null);
|
||||||
const ref3 = useRef<HTMLButtonElement>(null);
|
const ref3 = useRef<GetRef<typeof Button>>(null);
|
||||||
|
|
||||||
const [open, setOpen] = useState<boolean>(false);
|
const [open, setOpen] = useState<boolean>(false);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user