From 4b829ea7dd11b02d03ea6650dee255c16c0e7556 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=98=89=E6=B6=B5?= <chenjiahan@youzan.com> Date: Mon, 8 Jul 2019 17:42:24 +0800 Subject: [PATCH] [improvement] rename suffixPx to addUnit --- src/field/index.js | 4 ++-- src/grid-item/index.js | 6 +++--- src/grid/index.js | 4 ++-- src/icon/index.tsx | 4 ++-- src/image/index.js | 6 +++--- src/loading/index.tsx | 6 +++--- src/mixins/checkbox.js | 4 ++-- src/password-input/index.tsx | 4 ++-- src/rate/index.tsx | 6 +++--- src/skeleton/index.tsx | 8 ++++---- src/stepper/index.js | 8 ++++---- src/tabs/index.js | 6 +++--- src/uploader/index.js | 4 ++-- src/utils/format/unit.ts | 2 +- src/utils/index.ts | 2 +- 15 files changed, 37 insertions(+), 37 deletions(-) diff --git a/src/field/index.js b/src/field/index.js index 48cb288aa..418677aeb 100644 --- a/src/field/index.js +++ b/src/field/index.js @@ -3,7 +3,7 @@ import Cell from '../cell'; import { cellProps } from '../cell/shared'; import { preventDefault } from '../utils/dom/event'; import { getRootScrollTop } from '../utils/dom/scroll'; -import { createNamespace, isObj, isDef, suffixPx } from '../utils'; +import { createNamespace, isObj, isDef, addUnit } from '../utils'; import { isIOS } from '../utils/validate/system'; const [createComponent, bem] = createNamespace('field'); @@ -76,7 +76,7 @@ export default createComponent({ labelStyle() { const { labelWidth } = this; if (labelWidth) { - return { width: suffixPx(labelWidth) }; + return { width: addUnit(labelWidth) }; } } }, diff --git a/src/grid-item/index.js b/src/grid-item/index.js index 7c651e3df..a48965f3d 100644 --- a/src/grid-item/index.js +++ b/src/grid-item/index.js @@ -1,4 +1,4 @@ -import { createNamespace, suffixPx } from '../utils'; +import { createNamespace, addUnit } from '../utils'; import { ChildrenMixin } from '../mixins/relation'; import { route, routeProps } from '../utils/router'; import Icon from '../icon'; @@ -26,7 +26,7 @@ export default createComponent({ if (square) { style.paddingTop = percent; } else if (gutter) { - const gutterValue = suffixPx(gutter); + const gutterValue = addUnit(gutter); style.paddingRight = gutterValue; if (this.index >= columnNum) { @@ -41,7 +41,7 @@ export default createComponent({ const { square, gutter } = this.parent; if (square && gutter) { - const gutterValue = suffixPx(gutter); + const gutterValue = addUnit(gutter); return { right: gutterValue, diff --git a/src/grid/index.js b/src/grid/index.js index 9578c8f84..1f1af856a 100644 --- a/src/grid/index.js +++ b/src/grid/index.js @@ -1,4 +1,4 @@ -import { createNamespace, suffixPx } from '../utils'; +import { createNamespace, addUnit } from '../utils'; import { ParentMixin } from '../mixins/relation'; const [createComponent, bem] = createNamespace('grid'); @@ -30,7 +30,7 @@ export default createComponent({ if (gutter) { return { - paddingLeft: suffixPx(gutter) + paddingLeft: addUnit(gutter) }; } } diff --git a/src/icon/index.tsx b/src/icon/index.tsx index bdf0ef70e..468c2804e 100644 --- a/src/icon/index.tsx +++ b/src/icon/index.tsx @@ -1,4 +1,4 @@ -import { createNamespace, suffixPx } from '../utils'; +import { createNamespace, addUnit } from '../utils'; import { inherit } from '../utils/functional'; import Info from '../info'; import Image from '../image'; @@ -39,7 +39,7 @@ function Icon( class={[props.classPrefix, imageIcon ? '' : `${props.classPrefix}-${props.name}`]} style={{ color: props.color, - fontSize: suffixPx(props.size) + fontSize: addUnit(props.size) }} {...inherit(ctx, true)} > diff --git a/src/image/index.js b/src/image/index.js index 533c20c54..542699bfb 100644 --- a/src/image/index.js +++ b/src/image/index.js @@ -1,4 +1,4 @@ -import { createNamespace, isDef, suffixPx } from '../utils'; +import { createNamespace, isDef, addUnit } from '../utils'; import Icon from '../icon'; const [createComponent, bem] = createNamespace('image'); @@ -32,11 +32,11 @@ export default createComponent({ const style = {}; if (isDef(this.width)) { - style.width = suffixPx(this.width); + style.width = addUnit(this.width); } if (isDef(this.height)) { - style.height = suffixPx(this.height); + style.height = addUnit(this.height); } return style; diff --git a/src/loading/index.tsx b/src/loading/index.tsx index 414eac39c..e7bec1e65 100644 --- a/src/loading/index.tsx +++ b/src/loading/index.tsx @@ -1,4 +1,4 @@ -import { createNamespace, suffixPx } from '../utils'; +import { createNamespace, addUnit } from '../utils'; import { GRAY } from '../utils/color'; import { inherit } from '../utils/functional'; @@ -37,7 +37,7 @@ function LoadingIcon(h: CreateElement, props: LoadingProps) { function LoadingText(h: CreateElement, props: LoadingProps, slots: DefaultSlots) { if (slots.default) { const style = props.textSize && { - fontSize: suffixPx(props.textSize) + fontSize: addUnit(props.textSize) }; return ( @@ -58,7 +58,7 @@ function Loading( const style: { [key: string]: string } = { color }; if (size) { - const iconSize = suffixPx(size) as string; + const iconSize = addUnit(size) as string; style.width = iconSize; style.height = iconSize; } diff --git a/src/mixins/checkbox.js b/src/mixins/checkbox.js index 0b65c2011..cd482e48d 100644 --- a/src/mixins/checkbox.js +++ b/src/mixins/checkbox.js @@ -3,7 +3,7 @@ */ import Icon from '../icon'; import { ChildrenMixin } from './relation'; -import { suffixPx } from '../utils'; +import { addUnit } from '../utils'; export const CheckboxMixin = ({ parent, bem, role }) => ({ mixins: [ChildrenMixin(parent)], @@ -65,7 +65,7 @@ export const CheckboxMixin = ({ parent, bem, role }) => ({ const Children = [ <div class={bem('icon', [this.shape, { disabled: this.isDisabled, checked }])} - style={{ fontSize: suffixPx(this.iconSize) }} + style={{ fontSize: addUnit(this.iconSize) }} onClick={this.onClickIcon} > {CheckIcon} diff --git a/src/password-input/index.tsx b/src/password-input/index.tsx index 446003dc6..2f10d9944 100644 --- a/src/password-input/index.tsx +++ b/src/password-input/index.tsx @@ -1,4 +1,4 @@ -import { createNamespace, suffixPx } from '../utils'; +import { createNamespace, addUnit } from '../utils'; import { emit, inherit } from '../utils/functional'; // Types @@ -31,7 +31,7 @@ function PasswordInput( let style; if (i !== 0 && props.gutter) { - style = { marginLeft: suffixPx(props.gutter) }; + style = { marginLeft: addUnit(props.gutter) }; } Points.push( diff --git a/src/rate/index.tsx b/src/rate/index.tsx index b22135e26..b36ff0897 100644 --- a/src/rate/index.tsx +++ b/src/rate/index.tsx @@ -1,5 +1,5 @@ /* eslint-disable prefer-spread */ -import { createNamespace, suffixPx } from '../utils'; +import { createNamespace, addUnit } from '../utils'; import { emit, inherit } from '../utils/functional'; import { preventDefault } from '../utils/dom/event'; import Icon from '../icon'; @@ -90,13 +90,13 @@ function Rate( } } - const gutter = suffixPx(props.gutter); + const gutter = addUnit(props.gutter); function renderStar(status: RateStatus, index: number) { const isFull = status === 'full'; const isVoid = status === 'void'; const score = index + 1; - const size = suffixPx(props.size); + const size = addUnit(props.size); let style; if (gutter && score !== count) { diff --git a/src/skeleton/index.tsx b/src/skeleton/index.tsx index 58f247c11..ab467382b 100644 --- a/src/skeleton/index.tsx +++ b/src/skeleton/index.tsx @@ -1,4 +1,4 @@ -import { createNamespace, suffixPx } from '../utils'; +import { createNamespace, addUnit } from '../utils'; import { inherit } from '../utils/functional'; // Types @@ -33,7 +33,7 @@ function Skeleton( function Title() { if (props.title) { - return <h3 class={bem('title')} style={{ width: suffixPx(props.titleWidth) }} />; + return <h3 class={bem('title')} style={{ width: addUnit(props.titleWidth) }} />; } } @@ -54,7 +54,7 @@ function Skeleton( } for (let i = 0; i < props.row; i++) { - Rows.push(<div class={bem('row')} style={{ width: suffixPx(getRowWidth(i)) }} />); + Rows.push(<div class={bem('row')} style={{ width: addUnit(getRowWidth(i)) }} />); } return Rows; @@ -62,7 +62,7 @@ function Skeleton( function Avatar() { if (props.avatar) { - const size = suffixPx(props.avatarSize); + const size = addUnit(props.avatarSize); return ( <div class={bem('avatar', props.avatarShape)} diff --git a/src/stepper/index.js b/src/stepper/index.js index 9df870cea..d4aadfc23 100644 --- a/src/stepper/index.js +++ b/src/stepper/index.js @@ -1,4 +1,4 @@ -import { createNamespace, isDef, suffixPx } from '../utils'; +import { createNamespace, isDef, addUnit } from '../utils'; const [createComponent, bem] = createNamespace('stepper'); @@ -56,11 +56,11 @@ export default createComponent({ const style = {}; if (this.inputWidth) { - style.width = suffixPx(this.inputWidth); + style.width = addUnit(this.inputWidth); } if (this.buttonSize) { - style.height = suffixPx(this.buttonSize); + style.height = addUnit(this.buttonSize); } return style; @@ -70,7 +70,7 @@ export default createComponent({ const style = {}; if (this.buttonSize) { - const size = suffixPx(this.buttonSize); + const size = addUnit(this.buttonSize); style.width = size; style.height = size; } diff --git a/src/tabs/index.js b/src/tabs/index.js index e500d763d..c920520f0 100644 --- a/src/tabs/index.js +++ b/src/tabs/index.js @@ -1,4 +1,4 @@ -import { createNamespace, isDef, suffixPx } from '../utils'; +import { createNamespace, isDef, addUnit } from '../utils'; import { scrollLeftTo } from './utils'; import { on, off } from '../utils/dom/event'; import { ParentMixin } from '../mixins/relation'; @@ -222,7 +222,7 @@ export default createComponent({ const left = title.offsetLeft + title.offsetWidth / 2; const lineStyle = { - width: suffixPx(width), + width: addUnit(width), backgroundColor: this.color, transform: `translateX(${left}px) translateX(-50%)` }; @@ -232,7 +232,7 @@ export default createComponent({ } if (isDef(lineHeight)) { - const height = suffixPx(lineHeight); + const height = addUnit(lineHeight); lineStyle.height = height; lineStyle.borderRadius = height; } diff --git a/src/uploader/index.js b/src/uploader/index.js index a41c70e23..1869acc41 100644 --- a/src/uploader/index.js +++ b/src/uploader/index.js @@ -1,4 +1,4 @@ -import { createNamespace, suffixPx } from '../utils'; +import { createNamespace, addUnit } from '../utils'; import { toArray, readFile, isOversize } from './utils'; import Icon from '../icon'; import Image from '../image'; @@ -226,7 +226,7 @@ export default createComponent({ let style; if (this.previewSize) { - const size = suffixPx(this.previewSize); + const size = addUnit(this.previewSize); style = { width: size, height: size diff --git a/src/utils/format/unit.ts b/src/utils/format/unit.ts index 80ea0b597..547c265ae 100644 --- a/src/utils/format/unit.ts +++ b/src/utils/format/unit.ts @@ -1,7 +1,7 @@ import { isDef } from '..'; import { isNumber } from '../validate/number'; -export function suffixPx(value?: string | number): string | undefined { +export function addUnit(value?: string | number): string | undefined { if (!isDef(value)) { return undefined; } diff --git a/src/utils/index.ts b/src/utils/index.ts index fed678f6f..07f0a361b 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -1,7 +1,7 @@ import Vue from 'vue'; export { createNamespace } from './create'; -export { suffixPx } from './format/unit'; +export { addUnit } from './format/unit'; export const isServer: boolean = Vue.prototype.$isServer;