refactor(utils): move function (#7336)

This commit is contained in:
三咲智子 2022-04-23 21:59:17 +08:00 committed by GitHub
parent 6c399d32d9
commit 9de79794a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 30 additions and 30 deletions

View File

@ -281,13 +281,10 @@ import ElScrollbar from '@element-plus/components/scrollbar'
import ElTag, { tagProps } from '@element-plus/components/tag'
import ElIcon from '@element-plus/components/icon'
import { useDeprecateAppendToBody } from '@element-plus/components/popper'
import {
CHANGE_EVENT,
UPDATE_MODEL_EVENT,
getComponentSize,
} from '@element-plus/constants'
import { CHANGE_EVENT, UPDATE_MODEL_EVENT } from '@element-plus/constants'
import {
addResizeListener,
getComponentSize,
isValidComponentSize,
removeResizeListener,
} from '@element-plus/utils'

View File

@ -15,9 +15,13 @@ import {
CHANGE_EVENT,
EVENT_CODE,
UPDATE_MODEL_EVENT,
getComponentSize,
} from '@element-plus/constants'
import { debugWarn, isKorean, scrollIntoView } from '@element-plus/utils'
import {
debugWarn,
getComponentSize,
isKorean,
scrollIntoView,
} from '@element-plus/utils'
import { useLocale, useNamespace, useSize } from '@element-plus/hooks'
import { formContextKey, formItemContextKey } from '@element-plus/tokens'

View File

@ -7,7 +7,3 @@ export const componentSizeMap = {
default: 32,
small: 24,
} as const
export const getComponentSize = (size: ComponentSize = 'default') => {
return componentSizeMap[size || 'default']
}

View File

@ -1,9 +1,12 @@
import { isClient } from '@vueuse/core'
import { isObject } from '../types'
import { isNumber, isObject, isString } from '../types'
import { camelize } from '../strings'
import { entriesOf, keysOf } from '../objects'
import { debugWarn } from '../error'
import type { CSSProperties } from 'vue'
const SCOPE = 'utils/dom/style'
export const classNameToArray = (cls = '') =>
cls.split(' ').filter((item) => !!item.trim())
@ -70,3 +73,13 @@ export const removeStyle = (
setStyle(element, style, '')
}
}
export function addUnit(value?: string | number, defaultUnit = 'px') {
if (!value) return ''
if (isString(value)) {
return value
} else if (isNumber(value)) {
return `${value}${defaultUnit}`
}
debugWarn(SCOPE, 'binding value must be a string or number')
}

View File

@ -3,7 +3,7 @@ export * from './icon'
export * from './install'
export * from './props'
export * from './refs'
export * from './style'
export * from './size'
export * from './typescript'
export * from './validator'
export * from './vnode'

View File

@ -0,0 +1,7 @@
import { componentSizeMap } from '@element-plus/constants'
import type { ComponentSize } from '@element-plus/constants'
export const getComponentSize = (size?: ComponentSize) => {
return componentSizeMap[size || 'default']
}

View File

@ -1,17 +0,0 @@
import { isNumber, isString } from '../types'
import { debugWarn } from '../error'
const SCOPE = 'utils/vue/style'
export function addUnit(
value: string | number | undefined,
defaultUnit = 'px'
) {
if (!value) return ''
if (isString(value)) {
return value
} else if (isNumber(value)) {
return `${value}${defaultUnit}`
}
debugWarn(SCOPE, 'binding value must be a string or number')
}