From 7cec8614b0684505a55678feb4449ebfb0698a82 Mon Sep 17 00:00:00 2001 From: Amour1688 Date: Wed, 16 Sep 2020 12:45:04 +0800 Subject: [PATCH] chore: classNames es --- .../_util/{classNames.js => classNames.ts} | 28 +++++++++++++++---- components/_util/props-util.ts | 18 +----------- 2 files changed, 24 insertions(+), 22 deletions(-) rename components/_util/{classNames.js => classNames.ts} (56%) diff --git a/components/_util/classNames.js b/components/_util/classNames.ts similarity index 56% rename from components/_util/classNames.js rename to components/_util/classNames.ts index 55875ffb7..310700c9d 100644 --- a/components/_util/classNames.js +++ b/components/_util/classNames.ts @@ -1,9 +1,27 @@ import { isArray, isString, isObject } from './util'; -function classNames() { - let classes = []; - for (let i = 0; i < arguments.length; i++) { - const value = arguments[i]; - if (!value) continue; + +export type ClassArray = ClassValue[]; + +export interface ClassDictionary { + [id: string]: any; +} + +export type ClassValue = + | string + | number + | ClassDictionary + | ClassArray + | undefined + | null + | boolean; + +function classNames(...args: ClassValue[]): string { + const classes = []; + for (let i = 0; i < args.length; i++) { + const value = args[i]; + if (!value) { + continue; + } if (isString(value)) { classes.push(value); } else if (isArray(value)) { diff --git a/components/_util/props-util.ts b/components/_util/props-util.ts index 9572a7f3f..47c47f3ab 100644 --- a/components/_util/props-util.ts +++ b/components/_util/props-util.ts @@ -1,21 +1,5 @@ -<<<<<<< HEAD:components/_util/props-util.ts -import isPlainObject from 'lodash/isPlainObject'; -import classNames from 'classnames'; -import { - isVNode, - Fragment, - Comment, - Text, - h, - VNode, - ComponentPublicInstance, - PropOptions, -} from 'vue'; -======= +import { isVNode, Fragment, Comment, Text, h, VNode, ComponentPublicInstance } from 'vue'; import isPlainObject from 'lodash-es/isPlainObject'; -import classNames from './classNames'; -import { isVNode, Fragment, Comment, Text, h } from 'vue'; ->>>>>>> @{-1}:components/_util/props-util.js import { camelize, hyphenate, isOn, resolvePropValue } from './util'; import isValid from './isValid'; // function getType(fn) {