diff --git a/components/_util/statusUtils.tsx b/components/_util/statusUtils.tsx new file mode 100644 index 000000000..b61614f7d --- /dev/null +++ b/components/_util/statusUtils.tsx @@ -0,0 +1,23 @@ +import type { ValidateStatus } from '../form/FormItem'; +import classNames from './classNames'; +import { tuple } from './type'; + +const InputStatuses = tuple('warning', 'error', ''); +export type InputStatus = typeof InputStatuses[number]; + +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/_util/throttleByAnimationFrame.ts b/components/_util/throttleByAnimationFrame.ts index dd84132a4..45bae734b 100644 --- a/components/_util/throttleByAnimationFrame.ts +++ b/components/_util/throttleByAnimationFrame.ts @@ -1,20 +1,26 @@ import raf from './raf'; -export default function throttleByAnimationFrame(fn: (...args: any[]) => void) { - let requestId: number; +export default function throttleByAnimationFrame(fn: (...args: T) => void) { + let requestId: number | null; - const later = (args: any[]) => () => { + const later = (args: T) => () => { requestId = null; fn(...args); }; - const throttled = (...args: any[]) => { + const throttled: { + (...args: T): void; + cancel: () => void; + } = (...args: T) => { if (requestId == null) { requestId = raf(later(args)); } }; - (throttled as any).cancel = () => raf.cancel(requestId!); + throttled.cancel = () => { + raf.cancel(requestId!); + requestId = null; + }; return throttled; } diff --git a/components/_util/util.ts b/components/_util/util.ts index 1adfa26ef..7be837e53 100644 --- a/components/_util/util.ts +++ b/components/_util/util.ts @@ -56,7 +56,7 @@ function resolvePropValue(options, props, key, value) { export function getDataAndAriaProps(props) { return Object.keys(props).reduce((memo, key) => { - if (key.substr(0, 5) === 'data-' || key.substr(0, 5) === 'aria-') { + if (key.startsWith('data-') || key.startsWith('aria-')) { memo[key] = props[key]; } return memo; diff --git a/components/affix/utils.ts b/components/affix/utils.ts index 4ce8c11bb..ec9189476 100644 --- a/components/affix/utils.ts +++ b/components/affix/utils.ts @@ -1,5 +1,4 @@ import addEventListener from '../vc-util/Dom/addEventListener'; -import type { ComponentPublicInstance } from 'vue'; import supportsPassive from '../_util/supportsPassive'; export type BindElement = HTMLElement | Window | null | undefined; @@ -42,7 +41,7 @@ const TRIGGER_EVENTS = [ interface ObserverEntity { target: HTMLElement | Window; - affixList: ComponentPublicInstance[]; + affixList: any[]; eventHandlers: { [eventName: string]: any }; } @@ -53,10 +52,7 @@ export function getObserverEntities() { return observerEntities; } -export function addObserveTarget( - target: HTMLElement | Window | null, - affix: ComponentPublicInstance, -): void { +export function addObserveTarget(target: HTMLElement | Window | null, affix: T): void { if (!target) return; let entity: ObserverEntity | undefined = observerEntities.find(item => item.target === target); @@ -88,7 +84,7 @@ export function addObserveTarget( } } -export function removeObserveTarget(affix: ComponentPublicInstance): void { +export function removeObserveTarget(affix: T): void { const observerEntity = observerEntities.find(oriObserverEntity => { const hasAffix = oriObserverEntity.affixList.some(item => item === affix); if (hasAffix) { diff --git a/components/alert/index.en-US.md b/components/alert/index.en-US.md index 798566acb..de53d0c55 100644 --- a/components/alert/index.en-US.md +++ b/components/alert/index.en-US.md @@ -19,7 +19,7 @@ Alert component for feedback. | afterClose | Called when close animation is finished | () => void | - | | | banner | Whether to show as banner | boolean | false | | | closable | Whether Alert can be closed | boolean | | | -| closeIcon | Custom close icon | slot | | 3.0 | +| closeIcon | Custom close icon | slot | `` | 3.0 | | closeText | Close text to show | string\|slot | - | | | description | Additional content of Alert | string\|slot | - | | | icon | Custom icon, effective when `showIcon` is `true` | vnode \| slot | - | | diff --git a/components/alert/index.zh-CN.md b/components/alert/index.zh-CN.md index f754d25a8..b7ae476ae 100644 --- a/components/alert/index.zh-CN.md +++ b/components/alert/index.zh-CN.md @@ -20,7 +20,7 @@ cover: https://gw.alipayobjects.com/zos/alicdn/8emPa3fjl/Alert.svg | afterClose | 关闭动画结束后触发的回调函数 | () => void | - | | | banner | 是否用作顶部公告 | boolean | false | | | closable | 默认不显示关闭按钮 | boolean | 无 | | -| closeIcon | 自定义关闭 Icon | slot | | 3.0 | +| closeIcon | 自定义关闭 Icon | slot | `` | 3.0 | | closeText | 自定义关闭按钮 | string\|slot | 无 | | | description | 警告提示的辅助性文字介绍 | string\|slot | 无 | | | icon | 自定义图标,`showIcon` 为 `true` 时有效 | vnode\|slot | - | | diff --git a/components/vc-checkbox/Checkbox.tsx b/components/vc-checkbox/Checkbox.tsx index a8b7ea89a..854659f18 100644 --- a/components/vc-checkbox/Checkbox.tsx +++ b/components/vc-checkbox/Checkbox.tsx @@ -114,7 +114,7 @@ export default defineComponent({ onKeyup, } = attrs as HTMLAttributes; const globalProps = Object.keys({ ...others, ...attrs }).reduce((prev, key) => { - if (key.substr(0, 5) === 'aria-' || key.substr(0, 5) === 'data-' || key === 'role') { + if (key.startsWith('data-') || key.startsWith('aria-') || key === 'role') { prev[key] = others[key]; } return prev; diff --git a/components/vc-notification/Notice.tsx b/components/vc-notification/Notice.tsx index e29039a88..61fda86a6 100644 --- a/components/vc-notification/Notice.tsx +++ b/components/vc-notification/Notice.tsx @@ -101,7 +101,7 @@ export default defineComponent({ const componentClass = `${prefixCls}-notice`; const dataOrAriaAttributeProps = Object.keys(attrs).reduce( (acc: Record, key: string) => { - if (key.substr(0, 5) === 'data-' || key.substr(0, 5) === 'aria-' || key === 'role') { + if (key.startsWith('data-') || key.startsWith('aria-') || key === 'role') { acc[key] = (attrs as any)[key]; } return acc; diff --git a/components/vc-picker/utils/miscUtil.ts b/components/vc-picker/utils/miscUtil.ts index 4ba6c67f2..9900e151c 100644 --- a/components/vc-picker/utils/miscUtil.ts +++ b/components/vc-picker/utils/miscUtil.ts @@ -21,11 +21,8 @@ export default function getDataOrAriaProps(props: any) { Object.keys(props).forEach(key => { if ( - (key.substr(0, 5) === 'data-' || - key.substr(0, 5) === 'aria-' || - key === 'role' || - key === 'name') && - key.substr(0, 7) !== 'data-__' + (key.startsWith('data-') || key.startsWith('aria-') || key === 'role' || key === 'name') && + !key.startsWith('data-__') ) { retProps[key] = props[key]; } diff --git a/components/vc-table/utils/legacyUtil.ts b/components/vc-table/utils/legacyUtil.ts index a4303f406..7d075d372 100644 --- a/components/vc-table/utils/legacyUtil.ts +++ b/components/vc-table/utils/legacyUtil.ts @@ -52,7 +52,7 @@ export function getExpandableProps( export function getDataAndAriaProps(props: object) { /* eslint-disable no-param-reassign */ return Object.keys(props).reduce((memo, key) => { - if (key.substr(0, 5) === 'data-' || key.substr(0, 5) === 'aria-') { + if (key.startsWith('data-') || key.startsWith('aria-')) { memo[key] = props[key]; } return memo;