diff --git a/components/_util/motion.tsx b/components/_util/motion.tsx index 1c69a9f05a..edac9ccda1 100644 --- a/components/_util/motion.tsx +++ b/components/_util/motion.tsx @@ -1,5 +1,6 @@ import { CSSMotionProps, MotionEventHandler, MotionEndEventHandler } from 'rc-motion'; import { MotionEvent } from 'rc-motion/lib/interface'; +import { tuple } from './type'; // ================== Collapse Motion ================== const getCollapsedHeight: MotionEventHandler = () => ({ height: 0, opacity: 0 }); @@ -25,11 +26,21 @@ const collapseMotion: CSSMotionProps = { motionDeadline: 500, }; +const SelectPlacements = tuple('bottomLeft', 'bottomRight', 'topLeft', 'topRight'); +export type SelectCommonPlacement = typeof SelectPlacements[number]; + +const getTransitionDirection = (placement: SelectCommonPlacement | undefined) => { + if (placement !== undefined && (placement === 'topLeft' || placement === 'topRight')) { + return `slide-down`; + } + return `slide-up`; +}; + const getTransitionName = (rootPrefixCls: string, motion: string, transitionName?: string) => { if (transitionName !== undefined) { return transitionName; } return `${rootPrefixCls}-${motion}`; }; -export { getTransitionName }; +export { getTransitionName, getTransitionDirection }; export default collapseMotion; diff --git a/components/tooltip/placements.tsx b/components/_util/placements.tsx similarity index 97% rename from components/tooltip/placements.tsx rename to components/_util/placements.tsx index 3fc9152268..eb4dead8a8 100644 --- a/components/tooltip/placements.tsx +++ b/components/_util/placements.tsx @@ -42,6 +42,7 @@ export default function getPlacements(config: PlacementsConfig) { horizontalArrowShift = 16, verticalArrowShift = 8, autoAdjustOverflow, + arrowPointAtCenter, } = config; const placementMap: BuildInPlacements = { left: { @@ -94,7 +95,7 @@ export default function getPlacements(config: PlacementsConfig) { }, }; Object.keys(placementMap).forEach(key => { - placementMap[key] = config.arrowPointAtCenter + placementMap[key] = arrowPointAtCenter ? { ...placementMap[key], overflow: getOverflowOptions(autoAdjustOverflow), diff --git a/components/_util/statusUtils.tsx b/components/_util/statusUtils.tsx new file mode 100644 index 0000000000..25153ba93f --- /dev/null +++ b/components/_util/statusUtils.tsx @@ -0,0 +1,44 @@ +import React from 'react'; +import CheckCircleFilled from '@ant-design/icons/CheckCircleFilled'; +import ExclamationCircleFilled from '@ant-design/icons/ExclamationCircleFilled'; +import CloseCircleFilled from '@ant-design/icons/CloseCircleFilled'; +import LoadingOutlined from '@ant-design/icons/LoadingOutlined'; +import classNames from 'classnames'; +import { ValidateStatus } from '../form/FormItem'; +import { tuple } from './type'; + +const InputStatuses = tuple('warning', 'error', ''); +export type InputStatus = typeof InputStatuses[number]; + +const iconMap = { + success: CheckCircleFilled, + warning: ExclamationCircleFilled, + error: CloseCircleFilled, + validating: LoadingOutlined, +}; + +export const getFeedbackIcon = (prefixCls: string, status?: ValidateStatus) => { + const IconNode = status && iconMap[status]; + return IconNode ? ( + + + + ) : null; +}; + +export function getStatusClassNames( + prefixCls: string, + status?: ValidateStatus, + hasFeedback?: boolean, +) { + return classNames({ + [`${prefixCls}-status-success`]: status === 'success', + [`${prefixCls}-status-warning`]: status === 'warning', + [`${prefixCls}-status-error`]: status === 'error', + [`${prefixCls}-status-validating`]: status === 'validating', + [`${prefixCls}-has-feedback`]: hasFeedback, + }); +} + +export const getMergedStatus = (contextStatus?: ValidateStatus, customStatus?: InputStatus) => + customStatus || contextStatus; diff --git a/components/auto-complete/__tests__/__snapshots__/demo-extend.test.ts.snap b/components/auto-complete/__tests__/__snapshots__/demo-extend.test.ts.snap index 6bedc29b73..08fcb1420c 100644 --- a/components/auto-complete/__tests__/__snapshots__/demo-extend.test.ts.snap +++ b/components/auto-complete/__tests__/__snapshots__/demo-extend.test.ts.snap @@ -107,7 +107,7 @@ exports[`renders ./components/auto-complete/demo/certain-category.md extend cont class="ant-select-selection-search" > `; +exports[`renders ./components/auto-complete/demo/status.md extend context correctly 1`] = ` +
+
+ +
+ +
+`; + exports[`renders ./components/auto-complete/demo/uncertain-category.md extend context correctly 1`] = `