mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-28 05:05:48 +08:00
refactor: delete defaultprops (#37834)
* refactor: delete defaultprops * fix: fix * fix: fix
This commit is contained in:
parent
cecfd1b65c
commit
c639b2f2ab
@ -172,12 +172,13 @@ const Modal: React.FC<ModalProps> = props => {
|
|||||||
prefixCls: customizePrefixCls,
|
prefixCls: customizePrefixCls,
|
||||||
footer,
|
footer,
|
||||||
visible,
|
visible,
|
||||||
open,
|
open = false,
|
||||||
wrapClassName,
|
wrapClassName,
|
||||||
centered,
|
centered,
|
||||||
getContainer,
|
getContainer,
|
||||||
closeIcon,
|
closeIcon,
|
||||||
focusTriggerAfterClose = true,
|
focusTriggerAfterClose = true,
|
||||||
|
width = 520,
|
||||||
...restProps
|
...restProps
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
@ -187,7 +188,7 @@ const Modal: React.FC<ModalProps> = props => {
|
|||||||
const defaultFooter = (
|
const defaultFooter = (
|
||||||
<LocaleReceiver componentName="Modal" defaultLocale={getConfirmLocale()}>
|
<LocaleReceiver componentName="Modal" defaultLocale={getConfirmLocale()}>
|
||||||
{contextLocale => {
|
{contextLocale => {
|
||||||
const { okText, okType, cancelText, confirmLoading } = props;
|
const { okText, okType = 'primary', cancelText, confirmLoading = false } = props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@ -221,6 +222,7 @@ const Modal: React.FC<ModalProps> = props => {
|
|||||||
return (
|
return (
|
||||||
<NoFormStyle status override>
|
<NoFormStyle status override>
|
||||||
<Dialog
|
<Dialog
|
||||||
|
width={width}
|
||||||
{...restProps}
|
{...restProps}
|
||||||
getContainer={
|
getContainer={
|
||||||
getContainer === undefined ? (getContextPopupContainer as getContainerFunc) : getContainer
|
getContainer === undefined ? (getContextPopupContainer as getContainerFunc) : getContainer
|
||||||
@ -240,11 +242,4 @@ const Modal: React.FC<ModalProps> = props => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
Modal.defaultProps = {
|
|
||||||
width: 520,
|
|
||||||
confirmLoading: false,
|
|
||||||
open: false,
|
|
||||||
okType: 'primary' as LegacyButtonType,
|
|
||||||
};
|
|
||||||
|
|
||||||
export default Modal;
|
export default Modal;
|
||||||
|
@ -2,6 +2,7 @@ import classNames from 'classnames';
|
|||||||
import RcTooltip from 'rc-tooltip';
|
import RcTooltip from 'rc-tooltip';
|
||||||
import type { placements as Placements } from 'rc-tooltip/lib/placements';
|
import type { placements as Placements } from 'rc-tooltip/lib/placements';
|
||||||
import type { TooltipProps as RcTooltipProps } from 'rc-tooltip/lib/Tooltip';
|
import type { TooltipProps as RcTooltipProps } from 'rc-tooltip/lib/Tooltip';
|
||||||
|
import type { AlignType } from 'rc-trigger/lib/interface';
|
||||||
import useMergedState from 'rc-util/lib/hooks/useMergedState';
|
import useMergedState from 'rc-util/lib/hooks/useMergedState';
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { ConfigContext } from '../config-provider';
|
import { ConfigContext } from '../config-provider';
|
||||||
@ -101,9 +102,12 @@ export interface TooltipPropsWithTitle extends AbstractTooltipProps {
|
|||||||
|
|
||||||
export declare type TooltipProps = TooltipPropsWithTitle | TooltipPropsWithOverlay;
|
export declare type TooltipProps = TooltipPropsWithTitle | TooltipPropsWithOverlay;
|
||||||
|
|
||||||
const splitObject = (obj: any, keys: string[]) => {
|
const splitObject = <T extends React.CSSProperties>(
|
||||||
const picked: any = {};
|
obj: T,
|
||||||
const omitted: any = { ...obj };
|
keys: (keyof T)[],
|
||||||
|
): Record<'picked' | 'omitted', T> => {
|
||||||
|
const picked: T = {} as T;
|
||||||
|
const omitted: T = { ...obj };
|
||||||
keys.forEach(key => {
|
keys.forEach(key => {
|
||||||
if (obj && key in obj) {
|
if (obj && key in obj) {
|
||||||
picked[key] = obj[key];
|
picked[key] = obj[key];
|
||||||
@ -112,6 +116,7 @@ const splitObject = (obj: any, keys: string[]) => {
|
|||||||
});
|
});
|
||||||
return { picked, omitted };
|
return { picked, omitted };
|
||||||
};
|
};
|
||||||
|
|
||||||
const PresetColorRegex = new RegExp(`^(${PresetColorTypes.join('|')})(-inverse)?$`);
|
const PresetColorRegex = new RegExp(`^(${PresetColorTypes.join('|')})(-inverse)?$`);
|
||||||
|
|
||||||
// Fix Tooltip won't hide at disabled button
|
// Fix Tooltip won't hide at disabled button
|
||||||
@ -136,13 +141,13 @@ function getDisabledCompatibleChildren(element: React.ReactElement<any>, prefixC
|
|||||||
'display',
|
'display',
|
||||||
'zIndex',
|
'zIndex',
|
||||||
]);
|
]);
|
||||||
const spanStyle = {
|
const spanStyle: React.CSSProperties = {
|
||||||
display: 'inline-block', // default inline-block is important
|
display: 'inline-block', // default inline-block is important
|
||||||
...picked,
|
...picked,
|
||||||
cursor: 'not-allowed',
|
cursor: 'not-allowed',
|
||||||
width: element.props.block ? '100%' : null,
|
width: element.props.block ? '100%' : undefined,
|
||||||
};
|
};
|
||||||
const buttonStyle = {
|
const buttonStyle: React.CSSProperties = {
|
||||||
...omitted,
|
...omitted,
|
||||||
pointerEvents: 'none',
|
pointerEvents: 'none',
|
||||||
};
|
};
|
||||||
@ -205,7 +210,7 @@ const Tooltip = React.forwardRef<unknown, TooltipProps>((props, ref) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const getTooltipPlacements = () => {
|
const getTooltipPlacements = () => {
|
||||||
const { builtinPlacements, arrowPointAtCenter, autoAdjustOverflow } = props;
|
const { builtinPlacements, arrowPointAtCenter = false, autoAdjustOverflow = true } = props;
|
||||||
return (
|
return (
|
||||||
builtinPlacements ||
|
builtinPlacements ||
|
||||||
getPlacements({
|
getPlacements({
|
||||||
@ -216,32 +221,31 @@ const Tooltip = React.forwardRef<unknown, TooltipProps>((props, ref) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// 动态设置动画点
|
// 动态设置动画点
|
||||||
const onPopupAlign = (domNode: HTMLElement, align: any) => {
|
const onPopupAlign = (domNode: HTMLElement, align: AlignType) => {
|
||||||
const placements: any = getTooltipPlacements();
|
const placements = getTooltipPlacements();
|
||||||
// 当前返回的位置
|
// 当前返回的位置
|
||||||
const placement = Object.keys(placements).find(
|
const placement = Object.keys(placements).find(
|
||||||
key =>
|
key =>
|
||||||
placements[key].points[0] === align.points[0] &&
|
placements[key].points![0] === align.points?.[0] &&
|
||||||
placements[key].points[1] === align.points[1],
|
placements[key].points![1] === align.points?.[1],
|
||||||
);
|
);
|
||||||
if (!placement) {
|
if (!placement) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 根据当前坐标设置动画点
|
// 根据当前坐标设置动画点
|
||||||
const rect = domNode.getBoundingClientRect();
|
const rect = domNode.getBoundingClientRect();
|
||||||
const transformOrigin = {
|
|
||||||
top: '50%',
|
const transformOrigin = { top: '50%', left: '50%' };
|
||||||
left: '50%',
|
|
||||||
};
|
if (['top', 'Bottom'].includes(placement)) {
|
||||||
if (placement.indexOf('top') >= 0 || placement.indexOf('Bottom') >= 0) {
|
transformOrigin.top = `${rect.height - align.offset![1]}px`;
|
||||||
transformOrigin.top = `${rect.height - align.offset[1]}px`;
|
} else if (['Top', 'bottom'].includes(placement)) {
|
||||||
} else if (placement.indexOf('Top') >= 0 || placement.indexOf('bottom') >= 0) {
|
transformOrigin.top = `${-align.offset![1]}px`;
|
||||||
transformOrigin.top = `${-align.offset[1]}px`;
|
|
||||||
}
|
}
|
||||||
if (placement.indexOf('left') >= 0 || placement.indexOf('Right') >= 0) {
|
if (['left', 'Right'].includes(placement)) {
|
||||||
transformOrigin.left = `${rect.width - align.offset[0]}px`;
|
transformOrigin.left = `${rect.width - align.offset![0]}px`;
|
||||||
} else if (placement.indexOf('right') >= 0 || placement.indexOf('Left') >= 0) {
|
} else if (['right', 'Left'].includes(placement)) {
|
||||||
transformOrigin.left = `${-align.offset[0]}px`;
|
transformOrigin.left = `${-align.offset![0]}px`;
|
||||||
}
|
}
|
||||||
domNode.style.transformOrigin = `${transformOrigin.left} ${transformOrigin.top}`;
|
domNode.style.transformOrigin = `${transformOrigin.left} ${transformOrigin.top}`;
|
||||||
};
|
};
|
||||||
@ -254,7 +258,13 @@ const Tooltip = React.forwardRef<unknown, TooltipProps>((props, ref) => {
|
|||||||
return overlay || title || '';
|
return overlay || title || '';
|
||||||
};
|
};
|
||||||
|
|
||||||
const { getPopupContainer, ...otherProps } = props;
|
const {
|
||||||
|
getPopupContainer,
|
||||||
|
placement = 'top',
|
||||||
|
mouseEnterDelay = 0.1,
|
||||||
|
mouseLeaveDelay = 0.1,
|
||||||
|
...otherProps
|
||||||
|
} = props;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
prefixCls: customizePrefixCls,
|
prefixCls: customizePrefixCls,
|
||||||
@ -292,7 +302,7 @@ const Tooltip = React.forwardRef<unknown, TooltipProps>((props, ref) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let formattedOverlayInnerStyle = overlayInnerStyle;
|
let formattedOverlayInnerStyle = overlayInnerStyle;
|
||||||
let arrowContentStyle;
|
let arrowContentStyle: React.CSSProperties = {};
|
||||||
if (color && !PresetColorRegex.test(color)) {
|
if (color && !PresetColorRegex.test(color)) {
|
||||||
formattedOverlayInnerStyle = { ...overlayInnerStyle, background: color };
|
formattedOverlayInnerStyle = { ...overlayInnerStyle, background: color };
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
@ -302,6 +312,9 @@ const Tooltip = React.forwardRef<unknown, TooltipProps>((props, ref) => {
|
|||||||
return (
|
return (
|
||||||
<RcTooltip
|
<RcTooltip
|
||||||
{...otherProps}
|
{...otherProps}
|
||||||
|
placement={placement}
|
||||||
|
mouseEnterDelay={mouseEnterDelay}
|
||||||
|
mouseLeaveDelay={mouseLeaveDelay}
|
||||||
prefixCls={prefixCls}
|
prefixCls={prefixCls}
|
||||||
overlayClassName={customOverlayClassName}
|
overlayClassName={customOverlayClassName}
|
||||||
getTooltipContainer={getPopupContainer || getTooltipContainer || getContextPopupContainer}
|
getTooltipContainer={getPopupContainer || getTooltipContainer || getContextPopupContainer}
|
||||||
@ -327,12 +340,4 @@ if (process.env.NODE_ENV !== 'production') {
|
|||||||
Tooltip.displayName = 'Tooltip';
|
Tooltip.displayName = 'Tooltip';
|
||||||
}
|
}
|
||||||
|
|
||||||
Tooltip.defaultProps = {
|
|
||||||
placement: 'top' as TooltipPlacement,
|
|
||||||
mouseEnterDelay: 0.1,
|
|
||||||
mouseLeaveDelay: 0.1,
|
|
||||||
arrowPointAtCenter: false,
|
|
||||||
autoAdjustOverflow: true,
|
|
||||||
};
|
|
||||||
|
|
||||||
export default Tooltip;
|
export default Tooltip;
|
||||||
|
@ -167,18 +167,26 @@ const Tree = React.forwardRef<RcTree, TreeProps>((props, ref) => {
|
|||||||
const {
|
const {
|
||||||
prefixCls: customizePrefixCls,
|
prefixCls: customizePrefixCls,
|
||||||
className,
|
className,
|
||||||
showIcon,
|
showIcon = false,
|
||||||
showLine,
|
showLine,
|
||||||
switcherIcon,
|
switcherIcon,
|
||||||
blockNode,
|
blockNode = false,
|
||||||
children,
|
children,
|
||||||
checkable,
|
checkable = false,
|
||||||
selectable,
|
selectable = true,
|
||||||
draggable,
|
draggable,
|
||||||
|
motion = { ...collapseMotion, motionAppear: false },
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
const prefixCls = getPrefixCls('tree', customizePrefixCls);
|
const prefixCls = getPrefixCls('tree', customizePrefixCls);
|
||||||
|
|
||||||
const newProps = {
|
const newProps = {
|
||||||
...props,
|
...props,
|
||||||
|
checkable,
|
||||||
|
selectable,
|
||||||
|
showIcon,
|
||||||
|
motion,
|
||||||
|
blockNode,
|
||||||
showLine: Boolean(showLine),
|
showLine: Boolean(showLine),
|
||||||
dropIndicatorRender,
|
dropIndicatorRender,
|
||||||
};
|
};
|
||||||
@ -193,12 +201,11 @@ const Tree = React.forwardRef<RcTree, TreeProps>((props, ref) => {
|
|||||||
case 'function':
|
case 'function':
|
||||||
mergedDraggable.nodeDraggable = draggable;
|
mergedDraggable.nodeDraggable = draggable;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'object':
|
case 'object':
|
||||||
mergedDraggable = { ...draggable };
|
mergedDraggable = { ...draggable };
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
break;
|
||||||
// Do nothing
|
// Do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -231,7 +238,7 @@ const Tree = React.forwardRef<RcTree, TreeProps>((props, ref) => {
|
|||||||
switcherIcon={(nodeProps: AntTreeNodeProps) =>
|
switcherIcon={(nodeProps: AntTreeNodeProps) =>
|
||||||
renderSwitcherIcon(prefixCls, switcherIcon, showLine, nodeProps)
|
renderSwitcherIcon(prefixCls, switcherIcon, showLine, nodeProps)
|
||||||
}
|
}
|
||||||
draggable={draggableConfig as any}
|
draggable={draggableConfig}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
</RcTree>
|
</RcTree>
|
||||||
@ -242,15 +249,4 @@ Tree.TreeNode = TreeNode;
|
|||||||
|
|
||||||
Tree.DirectoryTree = DirectoryTree;
|
Tree.DirectoryTree = DirectoryTree;
|
||||||
|
|
||||||
Tree.defaultProps = {
|
|
||||||
checkable: false,
|
|
||||||
selectable: true,
|
|
||||||
showIcon: false,
|
|
||||||
motion: {
|
|
||||||
...collapseMotion,
|
|
||||||
motionAppear: false,
|
|
||||||
},
|
|
||||||
blockNode: false,
|
|
||||||
};
|
|
||||||
|
|
||||||
export default Tree;
|
export default Tree;
|
||||||
|
Loading…
Reference in New Issue
Block a user