mirror of
https://gitee.com/ant-design-vue/ant-design-vue.git
synced 2024-12-02 20:18:22 +08:00
style: update some code
This commit is contained in:
parent
1d08e80165
commit
a8dbea7c32
23
components/_util/statusUtils.tsx
Normal file
23
components/_util/statusUtils.tsx
Normal file
@ -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;
|
@ -1,20 +1,26 @@
|
||||
import raf from './raf';
|
||||
|
||||
export default function throttleByAnimationFrame(fn: (...args: any[]) => void) {
|
||||
let requestId: number;
|
||||
export default function throttleByAnimationFrame<T extends unknown[]>(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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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<any>[];
|
||||
affixList: any[];
|
||||
eventHandlers: { [eventName: string]: any };
|
||||
}
|
||||
|
||||
@ -53,10 +52,7 @@ export function getObserverEntities() {
|
||||
return observerEntities;
|
||||
}
|
||||
|
||||
export function addObserveTarget(
|
||||
target: HTMLElement | Window | null,
|
||||
affix: ComponentPublicInstance<any>,
|
||||
): void {
|
||||
export function addObserveTarget<T>(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<any>): void {
|
||||
export function removeObserveTarget<T>(affix: T): void {
|
||||
const observerEntity = observerEntities.find(oriObserverEntity => {
|
||||
const hasAffix = oriObserverEntity.affixList.some(item => item === affix);
|
||||
if (hasAffix) {
|
||||
|
@ -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 | <CloseOutlined /> | 3.0 |
|
||||
| closeIcon | Custom close icon | slot | `<CloseOutlined />` | 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 | - | |
|
||||
|
@ -20,7 +20,7 @@ cover: https://gw.alipayobjects.com/zos/alicdn/8emPa3fjl/Alert.svg
|
||||
| afterClose | 关闭动画结束后触发的回调函数 | () => void | - | |
|
||||
| banner | 是否用作顶部公告 | boolean | false | |
|
||||
| closable | 默认不显示关闭按钮 | boolean | 无 | |
|
||||
| closeIcon | 自定义关闭 Icon | slot | <CloseOutlined /> | 3.0 |
|
||||
| closeIcon | 自定义关闭 Icon | slot | `<CloseOutlined />` | 3.0 |
|
||||
| closeText | 自定义关闭按钮 | string\|slot | 无 | |
|
||||
| description | 警告提示的辅助性文字介绍 | string\|slot | 无 | |
|
||||
| icon | 自定义图标,`showIcon` 为 `true` 时有效 | vnode\|slot | - | |
|
||||
|
@ -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;
|
||||
|
@ -101,7 +101,7 @@ export default defineComponent<NoticeProps>({
|
||||
const componentClass = `${prefixCls}-notice`;
|
||||
const dataOrAriaAttributeProps = Object.keys(attrs).reduce(
|
||||
(acc: Record<string, string>, 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;
|
||||
|
@ -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];
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ export function getExpandableProps<RecordType>(
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user