fix: signatures for Upload (#37861)

This commit is contained in:
Zheeeng 2022-10-06 18:53:06 +08:00 committed by GitHub
parent d7204f4aca
commit dcac4f66a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 22 additions and 37 deletions

View File

@ -77,7 +77,7 @@ class Affix extends React.Component<InternalAffixProps, AffixState> {
return target;
}
return getTargetContainer || getDefaultTarget;
return getTargetContainer ?? getDefaultTarget;
}
// Event handler

View File

@ -135,7 +135,7 @@ class Anchor extends React.Component<InternalAnchorProps, AnchorState, ConfigCon
const { getTargetContainer } = this.context;
const { getContainer } = this.props;
const getFunc = getContainer || getTargetContainer || getDefaultContainer;
const getFunc = getContainer ?? getTargetContainer ?? getDefaultContainer;
return getFunc();
};

View File

@ -12,8 +12,8 @@ import TimePicker from '../../time-picker';
import { act, render, fireEvent } from '../../../tests/utils';
describe('ConfigProvider.Locale', () => {
function $$(className: string): NodeListOf<Element> {
return document.body.querySelectorAll(className);
function $$(selector: string): NodeListOf<Element> {
return document.body.querySelectorAll(selector);
}
it('not throw', () => {

View File

@ -7,7 +7,7 @@ import { act, render } from '../../../tests/utils';
describe('ConfigProvider.getTargetContainer', () => {
it('Affix', () => {
jest.useFakeTimers();
const getTargetContainer = jest.fn(() => window as unknown as HTMLElement);
const getTargetContainer = jest.fn(() => window);
render(
<ConfigProvider getTargetContainer={getTargetContainer}>
<Affix>
@ -26,7 +26,7 @@ describe('ConfigProvider.getTargetContainer', () => {
it('Anchor', () => {
jest.useFakeTimers();
const getTargetContainer = jest.fn(() => window as unknown as HTMLElement);
const getTargetContainer = jest.fn(() => window);
render(
<ConfigProvider getTargetContainer={getTargetContainer}>
<Anchor>

View File

@ -47,13 +47,13 @@ describe('ConfigProvider.Theme', () => {
},
});
const styles: any[] = Array.from(document.querySelectorAll('style'));
const styles = Array.from(document.querySelectorAll('style'));
const themeStyle = styles.find(style =>
style.getAttribute('rc-util-key').includes('-dynamic-theme'),
style.getAttribute('rc-util-key')?.includes('-dynamic-theme'),
);
(Object.keys(infoColor) as Array<keyof typeof infoColor>).forEach(key => {
expect(themeStyle.innerHTML).toContain(
Object.keys(infoColor).forEach((key: keyof typeof infoColor) => {
expect(themeStyle?.innerHTML).toContain(
`--${prefixCls}-info-color-${kebabCase(key)}: ${infoColor[key]}`,
);
});

View File

@ -65,12 +65,6 @@ export const ConfigContext = React.createContext<ConfigConsumerProps>({
export const ConfigConsumer = ConfigContext.Consumer;
// =========================== withConfigConsumer ===========================
// We need define many types here. So let's put in the block region
type IReactComponent<P = any> =
| React.FC<P>
| React.ComponentClass<P>
| React.ClassicComponentClass<P>;
interface BasicExportProps {
prefixCls?: string;
}
@ -86,7 +80,7 @@ interface ConstructorProps {
/** @deprecated Use hooks instead. This is a legacy function */
export function withConfigConsumer<ExportProps extends BasicExportProps>(config: ConsumerConfig) {
return function withConfigConsumerFunc<ComponentDef>(
Component: IReactComponent,
Component: React.ComponentType<ExportProps>,
): React.FC<ExportProps> & ComponentDef {
// Wrap with ConfigConsumer. Since we need compatible with react 15, be care when using ref methods
const SFC = ((props: ExportProps) => (

View File

@ -57,7 +57,7 @@ const PASSED_PROPS: Exclude<keyof ConfigConsumerProps, 'rootPrefixCls' | 'getPre
];
export interface ConfigProviderProps {
getTargetContainer?: () => HTMLElement;
getTargetContainer?: () => HTMLElement | Window;
getPopupContainer?: (triggerNode?: HTMLElement) => HTMLElement;
prefixCls?: string;
iconPrefixCls?: string;
@ -198,7 +198,7 @@ const ProviderChildren: React.FC<ProviderChildrenProps> = props => {
// Pass the props used by `useContext` directly with child component.
// These props should merged into `config`.
PASSED_PROPS.forEach(propName => {
const propValue: any = props[propName];
const propValue = props[propName];
if (propValue) {
(config as any)[propName] = propValue;
}
@ -208,9 +208,9 @@ const ProviderChildren: React.FC<ProviderChildrenProps> = props => {
const memoedConfig = useMemo(
() => config,
config,
(prevConfig: Record<string, any>, currentConfig) => {
const prevKeys = Object.keys(prevConfig);
const currentKeys = Object.keys(currentConfig);
(prevConfig, currentConfig) => {
const prevKeys = Object.keys(prevConfig) as Array<keyof typeof config>;
const currentKeys = Object.keys(currentConfig) as Array<keyof typeof config>;
return (
prevKeys.length !== currentKeys.length ||
prevKeys.some(key => prevConfig[key] !== currentConfig[key])
@ -287,11 +287,7 @@ const ConfigProvider: React.FC<ConfigProviderProps> & {
{(_, __, legacyLocale) => (
<ConfigConsumer>
{context => (
<ProviderChildren
parentContext={context}
legacyLocale={legacyLocale}
{...props}
/>
<ProviderChildren parentContext={context} legacyLocale={legacyLocale} {...props} />
)}
</ConfigConsumer>
)}

View File

@ -50,6 +50,7 @@ export interface Locale {
export interface LocaleProviderProps {
locale: Locale;
children?: React.ReactNode;
/** @internal */
_ANT_MARK__?: string;
}

View File

@ -33,10 +33,7 @@ export default function getIcons({
showArrow?: boolean;
}) {
// Clear Icon
let mergedClearIcon = clearIcon;
if (!clearIcon) {
mergedClearIcon = <CloseCircleFilled />;
}
const mergedClearIcon = clearIcon ?? <CloseCircleFilled />;
// Validation Feedback Icon
const getSuffixIconNode = (arrowIcon?: ReactNode) => (

View File

@ -4,12 +4,9 @@ import Upload from './Upload';
export type DraggerProps = UploadProps & { height?: number };
const InternalDragger: React.ForwardRefRenderFunction<unknown, DraggerProps> = (
{ style, height, ...restProps },
ref,
) => <Upload ref={ref} {...restProps} type="drag" style={{ ...style, height }} />;
const Dragger = React.forwardRef(InternalDragger) as React.FC<DraggerProps>;
const Dragger = React.forwardRef<unknown, DraggerProps>(({ style, height, ...restProps }, ref) => (
<Upload ref={ref} {...restProps} type="drag" style={{ ...style, height }} />
));
if (process.env.NODE_ENV !== 'production') {
Dragger.displayName = 'Dragger';