mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-24 02:59:58 +08:00
fix: signatures for Upload (#37861)
This commit is contained in:
parent
d7204f4aca
commit
dcac4f66a4
@ -77,7 +77,7 @@ class Affix extends React.Component<InternalAffixProps, AffixState> {
|
||||
return target;
|
||||
}
|
||||
|
||||
return getTargetContainer || getDefaultTarget;
|
||||
return getTargetContainer ?? getDefaultTarget;
|
||||
}
|
||||
|
||||
// Event handler
|
||||
|
@ -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();
|
||||
};
|
||||
|
@ -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', () => {
|
||||
|
@ -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>
|
||||
|
@ -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]}`,
|
||||
);
|
||||
});
|
||||
|
@ -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) => (
|
||||
|
@ -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>
|
||||
)}
|
||||
|
@ -50,6 +50,7 @@ export interface Locale {
|
||||
export interface LocaleProviderProps {
|
||||
locale: Locale;
|
||||
children?: React.ReactNode;
|
||||
/** @internal */
|
||||
_ANT_MARK__?: string;
|
||||
}
|
||||
|
||||
|
@ -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) => (
|
||||
|
@ -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';
|
||||
|
Loading…
Reference in New Issue
Block a user