[improvement] rename suffixPx to addUnit

This commit is contained in:
陈嘉涵
2019-07-08 17:42:24 +08:00
parent 1f03a703f5
commit 4b829ea7dd
15 changed files with 37 additions and 37 deletions

View File

@@ -3,7 +3,7 @@ import Cell from '../cell';
import { cellProps } from '../cell/shared'; import { cellProps } from '../cell/shared';
import { preventDefault } from '../utils/dom/event'; import { preventDefault } from '../utils/dom/event';
import { getRootScrollTop } from '../utils/dom/scroll'; 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'; import { isIOS } from '../utils/validate/system';
const [createComponent, bem] = createNamespace('field'); const [createComponent, bem] = createNamespace('field');
@@ -76,7 +76,7 @@ export default createComponent({
labelStyle() { labelStyle() {
const { labelWidth } = this; const { labelWidth } = this;
if (labelWidth) { if (labelWidth) {
return { width: suffixPx(labelWidth) }; return { width: addUnit(labelWidth) };
} }
} }
}, },

View File

@@ -1,4 +1,4 @@
import { createNamespace, suffixPx } from '../utils'; import { createNamespace, addUnit } from '../utils';
import { ChildrenMixin } from '../mixins/relation'; import { ChildrenMixin } from '../mixins/relation';
import { route, routeProps } from '../utils/router'; import { route, routeProps } from '../utils/router';
import Icon from '../icon'; import Icon from '../icon';
@@ -26,7 +26,7 @@ export default createComponent({
if (square) { if (square) {
style.paddingTop = percent; style.paddingTop = percent;
} else if (gutter) { } else if (gutter) {
const gutterValue = suffixPx(gutter); const gutterValue = addUnit(gutter);
style.paddingRight = gutterValue; style.paddingRight = gutterValue;
if (this.index >= columnNum) { if (this.index >= columnNum) {
@@ -41,7 +41,7 @@ export default createComponent({
const { square, gutter } = this.parent; const { square, gutter } = this.parent;
if (square && gutter) { if (square && gutter) {
const gutterValue = suffixPx(gutter); const gutterValue = addUnit(gutter);
return { return {
right: gutterValue, right: gutterValue,

View File

@@ -1,4 +1,4 @@
import { createNamespace, suffixPx } from '../utils'; import { createNamespace, addUnit } from '../utils';
import { ParentMixin } from '../mixins/relation'; import { ParentMixin } from '../mixins/relation';
const [createComponent, bem] = createNamespace('grid'); const [createComponent, bem] = createNamespace('grid');
@@ -30,7 +30,7 @@ export default createComponent({
if (gutter) { if (gutter) {
return { return {
paddingLeft: suffixPx(gutter) paddingLeft: addUnit(gutter)
}; };
} }
} }

View File

@@ -1,4 +1,4 @@
import { createNamespace, suffixPx } from '../utils'; import { createNamespace, addUnit } from '../utils';
import { inherit } from '../utils/functional'; import { inherit } from '../utils/functional';
import Info from '../info'; import Info from '../info';
import Image from '../image'; import Image from '../image';
@@ -39,7 +39,7 @@ function Icon(
class={[props.classPrefix, imageIcon ? '' : `${props.classPrefix}-${props.name}`]} class={[props.classPrefix, imageIcon ? '' : `${props.classPrefix}-${props.name}`]}
style={{ style={{
color: props.color, color: props.color,
fontSize: suffixPx(props.size) fontSize: addUnit(props.size)
}} }}
{...inherit(ctx, true)} {...inherit(ctx, true)}
> >

View File

@@ -1,4 +1,4 @@
import { createNamespace, isDef, suffixPx } from '../utils'; import { createNamespace, isDef, addUnit } from '../utils';
import Icon from '../icon'; import Icon from '../icon';
const [createComponent, bem] = createNamespace('image'); const [createComponent, bem] = createNamespace('image');
@@ -32,11 +32,11 @@ export default createComponent({
const style = {}; const style = {};
if (isDef(this.width)) { if (isDef(this.width)) {
style.width = suffixPx(this.width); style.width = addUnit(this.width);
} }
if (isDef(this.height)) { if (isDef(this.height)) {
style.height = suffixPx(this.height); style.height = addUnit(this.height);
} }
return style; return style;

View File

@@ -1,4 +1,4 @@
import { createNamespace, suffixPx } from '../utils'; import { createNamespace, addUnit } from '../utils';
import { GRAY } from '../utils/color'; import { GRAY } from '../utils/color';
import { inherit } from '../utils/functional'; import { inherit } from '../utils/functional';
@@ -37,7 +37,7 @@ function LoadingIcon(h: CreateElement, props: LoadingProps) {
function LoadingText(h: CreateElement, props: LoadingProps, slots: DefaultSlots) { function LoadingText(h: CreateElement, props: LoadingProps, slots: DefaultSlots) {
if (slots.default) { if (slots.default) {
const style = props.textSize && { const style = props.textSize && {
fontSize: suffixPx(props.textSize) fontSize: addUnit(props.textSize)
}; };
return ( return (
@@ -58,7 +58,7 @@ function Loading(
const style: { [key: string]: string } = { color }; const style: { [key: string]: string } = { color };
if (size) { if (size) {
const iconSize = suffixPx(size) as string; const iconSize = addUnit(size) as string;
style.width = iconSize; style.width = iconSize;
style.height = iconSize; style.height = iconSize;
} }

View File

@@ -3,7 +3,7 @@
*/ */
import Icon from '../icon'; import Icon from '../icon';
import { ChildrenMixin } from './relation'; import { ChildrenMixin } from './relation';
import { suffixPx } from '../utils'; import { addUnit } from '../utils';
export const CheckboxMixin = ({ parent, bem, role }) => ({ export const CheckboxMixin = ({ parent, bem, role }) => ({
mixins: [ChildrenMixin(parent)], mixins: [ChildrenMixin(parent)],
@@ -65,7 +65,7 @@ export const CheckboxMixin = ({ parent, bem, role }) => ({
const Children = [ const Children = [
<div <div
class={bem('icon', [this.shape, { disabled: this.isDisabled, checked }])} class={bem('icon', [this.shape, { disabled: this.isDisabled, checked }])}
style={{ fontSize: suffixPx(this.iconSize) }} style={{ fontSize: addUnit(this.iconSize) }}
onClick={this.onClickIcon} onClick={this.onClickIcon}
> >
{CheckIcon} {CheckIcon}

View File

@@ -1,4 +1,4 @@
import { createNamespace, suffixPx } from '../utils'; import { createNamespace, addUnit } from '../utils';
import { emit, inherit } from '../utils/functional'; import { emit, inherit } from '../utils/functional';
// Types // Types
@@ -31,7 +31,7 @@ function PasswordInput(
let style; let style;
if (i !== 0 && props.gutter) { if (i !== 0 && props.gutter) {
style = { marginLeft: suffixPx(props.gutter) }; style = { marginLeft: addUnit(props.gutter) };
} }
Points.push( Points.push(

View File

@@ -1,5 +1,5 @@
/* eslint-disable prefer-spread */ /* eslint-disable prefer-spread */
import { createNamespace, suffixPx } from '../utils'; import { createNamespace, addUnit } from '../utils';
import { emit, inherit } from '../utils/functional'; import { emit, inherit } from '../utils/functional';
import { preventDefault } from '../utils/dom/event'; import { preventDefault } from '../utils/dom/event';
import Icon from '../icon'; 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) { function renderStar(status: RateStatus, index: number) {
const isFull = status === 'full'; const isFull = status === 'full';
const isVoid = status === 'void'; const isVoid = status === 'void';
const score = index + 1; const score = index + 1;
const size = suffixPx(props.size); const size = addUnit(props.size);
let style; let style;
if (gutter && score !== count) { if (gutter && score !== count) {

View File

@@ -1,4 +1,4 @@
import { createNamespace, suffixPx } from '../utils'; import { createNamespace, addUnit } from '../utils';
import { inherit } from '../utils/functional'; import { inherit } from '../utils/functional';
// Types // Types
@@ -33,7 +33,7 @@ function Skeleton(
function Title() { function Title() {
if (props.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++) { 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; return Rows;
@@ -62,7 +62,7 @@ function Skeleton(
function Avatar() { function Avatar() {
if (props.avatar) { if (props.avatar) {
const size = suffixPx(props.avatarSize); const size = addUnit(props.avatarSize);
return ( return (
<div <div
class={bem('avatar', props.avatarShape)} class={bem('avatar', props.avatarShape)}

View File

@@ -1,4 +1,4 @@
import { createNamespace, isDef, suffixPx } from '../utils'; import { createNamespace, isDef, addUnit } from '../utils';
const [createComponent, bem] = createNamespace('stepper'); const [createComponent, bem] = createNamespace('stepper');
@@ -56,11 +56,11 @@ export default createComponent({
const style = {}; const style = {};
if (this.inputWidth) { if (this.inputWidth) {
style.width = suffixPx(this.inputWidth); style.width = addUnit(this.inputWidth);
} }
if (this.buttonSize) { if (this.buttonSize) {
style.height = suffixPx(this.buttonSize); style.height = addUnit(this.buttonSize);
} }
return style; return style;
@@ -70,7 +70,7 @@ export default createComponent({
const style = {}; const style = {};
if (this.buttonSize) { if (this.buttonSize) {
const size = suffixPx(this.buttonSize); const size = addUnit(this.buttonSize);
style.width = size; style.width = size;
style.height = size; style.height = size;
} }

View File

@@ -1,4 +1,4 @@
import { createNamespace, isDef, suffixPx } from '../utils'; import { createNamespace, isDef, addUnit } from '../utils';
import { scrollLeftTo } from './utils'; import { scrollLeftTo } from './utils';
import { on, off } from '../utils/dom/event'; import { on, off } from '../utils/dom/event';
import { ParentMixin } from '../mixins/relation'; import { ParentMixin } from '../mixins/relation';
@@ -222,7 +222,7 @@ export default createComponent({
const left = title.offsetLeft + title.offsetWidth / 2; const left = title.offsetLeft + title.offsetWidth / 2;
const lineStyle = { const lineStyle = {
width: suffixPx(width), width: addUnit(width),
backgroundColor: this.color, backgroundColor: this.color,
transform: `translateX(${left}px) translateX(-50%)` transform: `translateX(${left}px) translateX(-50%)`
}; };
@@ -232,7 +232,7 @@ export default createComponent({
} }
if (isDef(lineHeight)) { if (isDef(lineHeight)) {
const height = suffixPx(lineHeight); const height = addUnit(lineHeight);
lineStyle.height = height; lineStyle.height = height;
lineStyle.borderRadius = height; lineStyle.borderRadius = height;
} }

View File

@@ -1,4 +1,4 @@
import { createNamespace, suffixPx } from '../utils'; import { createNamespace, addUnit } from '../utils';
import { toArray, readFile, isOversize } from './utils'; import { toArray, readFile, isOversize } from './utils';
import Icon from '../icon'; import Icon from '../icon';
import Image from '../image'; import Image from '../image';
@@ -226,7 +226,7 @@ export default createComponent({
let style; let style;
if (this.previewSize) { if (this.previewSize) {
const size = suffixPx(this.previewSize); const size = addUnit(this.previewSize);
style = { style = {
width: size, width: size,
height: size height: size

View File

@@ -1,7 +1,7 @@
import { isDef } from '..'; import { isDef } from '..';
import { isNumber } from '../validate/number'; import { isNumber } from '../validate/number';
export function suffixPx(value?: string | number): string | undefined { export function addUnit(value?: string | number): string | undefined {
if (!isDef(value)) { if (!isDef(value)) {
return undefined; return undefined;
} }

View File

@@ -1,7 +1,7 @@
import Vue from 'vue'; import Vue from 'vue';
export { createNamespace } from './create'; export { createNamespace } from './create';
export { suffixPx } from './format/unit'; export { addUnit } from './format/unit';
export const isServer: boolean = Vue.prototype.$isServer; export const isServer: boolean = Vue.prototype.$isServer;