[Improvement] more component use bem mixin (#924)

This commit is contained in:
neverland 2018-04-24 16:31:16 +08:00 committed by GitHub
parent b0f4096e88
commit b48ee8eece
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 69 additions and 62 deletions

View File

@ -3,46 +3,45 @@
:title="label" :title="label"
:center="center" :center="center"
:required="required" :required="required"
class="van-field" :class="b({
:class="{ error,
'van-field--disabled': $attrs.disabled, disabled: $attrs.disabled,
'van-field--error': error, 'has-icon': hasIcon,
'van-field--min-height': type === 'textarea' && !autosize, 'min-height': type === 'textarea' && !autosize
'van-field--has-icon': hasIcon })"
}"
> >
<textarea <textarea
v-if="type === 'textarea'" v-if="type === 'textarea'"
v-bind="$attrs" v-bind="$attrs"
v-on="listeners" v-on="listeners"
ref="textarea" ref="textarea"
class="van-field__control" :class="b('control')"
:value="value" :value="value"
/> />
<input <input
v-else v-else
v-bind="$attrs" v-bind="$attrs"
v-on="listeners" v-on="listeners"
class="van-field__control" :class="b('control')"
:type="type" :type="type"
:value="value" :value="value"
> >
<div <div
v-if="errorMessage" v-if="errorMessage"
v-text="errorMessage" v-text="errorMessage"
class="van-field__error-message" :class="b('error-message')"
/> />
<div <div
v-if="hasIcon" v-if="hasIcon"
v-show="$slots.icon || value" v-show="$slots.icon || value"
class="van-field__icon" :class="b('icon')"
@touchstart.prevent="onClickIcon" @touchstart.prevent="onClickIcon"
> >
<slot name="icon"> <slot name="icon">
<icon :name="icon" /> <icon :name="icon" />
</slot> </slot>
</div> </div>
<div class="van-field__button" v-if="$slots.button" slot="extra"> <div v-if="$slots.button" :class="b('button')" slot="extra">
<slot name="button" /> <slot name="button" />
</div> </div>
</cell> </cell>

View File

@ -2,7 +2,7 @@
<van-button <van-button
tag="a" tag="a"
:href="url" :href="url"
class="van-goods-action__big-btn" :class="b()"
:type="primary ? 'primary' : 'default'" :type="primary ? 'primary' : 'default'"
bottom-action bottom-action
@click="onClick" @click="onClick"

View File

@ -1,6 +1,6 @@
<template> <template>
<a :href="url" class="van-goods-action__mini-btn van-hairline" @click="onClick"> <a :href="url" :class="b()" class="van-hairline" @click="onClick">
<icon class="van-goods-action__mini-btn-icon" :class="iconClass" :info="info" :name="icon" /> <icon :class="[b('icon'), iconClass]" :info="info" :name="icon" />
<slot>{{ text }}</slot> <slot>{{ text }}</slot>
</a> </a>
</template> </template>

View File

@ -1,5 +1,5 @@
<template> <template>
<div class="van-goods-action"> <div :class="b()">
<slot /> <slot />
</div> </div>
</template> </template>

View File

@ -1,7 +1,7 @@
<template> <template>
<i class="van-icon" :class="`van-icon-${name}`" v-on="$listeners"> <i :class="[b(), `van-icon-${name}`]" v-on="$listeners">
<slot /> <slot />
<div v-if="isDef(info)" class="van-icon__info">{{ info }}</div> <div v-if="isDef(info)" :class="b('info')">{{ info }}</div>
</i> </i>
</template> </template>

View File

@ -1,7 +1,7 @@
<template> <template>
<div <div
v-show="value" v-show="value"
class="van-image-preview" :class="b()"
@touchstart="onTouchStart" @touchstart="onTouchStart"
@touchmove.prevent="touchMove" @touchmove.prevent="touchMove"
@touchend="onTouchEnd" @touchend="onTouchEnd"
@ -9,7 +9,7 @@
> >
<swipe :initial-swipe="startPosition"> <swipe :initial-swipe="startPosition">
<swipe-item v-for="(item, index) in images" :key="index"> <swipe-item v-for="(item, index) in images" :key="index">
<img class="van-image-preview__image" :src="item" > <img :class="b('image')" :src="item" >
</swipe-item> </swipe-item>
</swipe> </swipe>
</div> </div>

View File

@ -1,10 +1,10 @@
<template> <template>
<div class="van-list"> <div :class="b()">
<slot /> <slot />
<div class="van-list__loading" v-show="loading"> <div v-show="loading" :class="b('loading')">
<slot name="loading"> <slot name="loading">
<loading /> <loading />
<span class="van-list__loading-text">{{ $t('loadingTip') }}</span> <span :class="b('loading-text')">{{ $t('loadingTip') }}</span>
</slot> </slot>
</div> </div>
</div> </div>

View File

@ -1,8 +1,8 @@
<template> <template>
<div class="van-loading" :class="['van-loading--' + type, 'van-loading--' + color]" :style="style"> <div :class="b([type, color])" :style="style">
<span class="van-loading__spinner" :class="'van-loading__spinner--' + type"> <span :class="b('spinner', type)">
<i v-for="item in (type === 'spinner' ? 12 : 0)" /> <i v-for="item in (type === 'spinner' ? 12 : 0)" />
<svg v-if="type === 'circular'" class="van-loading__circular" viewBox="25 25 50 50"> <svg v-if="type === 'circular'" :class="b('circular')" viewBox="25 25 50 50">
<circle cx="50" cy="50" r="20" fill="none"/> <circle cx="50" cy="50" r="20" fill="none"/>
</svg> </svg>
</span> </span>

View File

@ -1,21 +1,21 @@
<template> <template>
<div <div
class="van-nav-bar van-hairline--bottom" class="van-hairline--bottom"
:class="{ 'van-nav-bar--fixed': fixed }" :class="b({ fixed })"
:style="style" :style="style"
> >
<div class="van-nav-bar__left" @click="$emit('click-left')"> <div :class="b('left')" @click="$emit('click-left')">
<slot name="left"> <slot name="left">
<icon v-if="leftArrow" class="van-nav-bar__arrow" name="arrow" /> <icon v-if="leftArrow" :class="b('arrow')" name="arrow" />
<span v-if="leftText" v-text="leftText" class="van-nav-bar__text" /> <span v-if="leftText" v-text="leftText" :class="b('text')" />
</slot> </slot>
</div> </div>
<div class="van-nav-bar__title van-ellipsis"> <div :class="b('title')" class="van-ellipsis">
<slot name="title">{{ title }}</slot> <slot name="title">{{ title }}</slot>
</div> </div>
<div class="van-nav-bar__right" @click="$emit('click-right')"> <div :class="b('right')" @click="$emit('click-right')">
<slot name="right"> <slot name="right">
<span v-if="rightText" v-text="rightText" class="van-nav-bar__text" /> <span v-if="rightText" v-text="rightText" :class="b('text')" />
</slot> </slot>
</div> </div>
</div> </div>

View File

@ -1,19 +1,17 @@
<template> <template>
<div <div
v-show="showNoticeBar" v-show="showNoticeBar"
class="van-notice-bar" :class="b({ withicon: mode })"
:class="{ 'van-notice-bar--withicon': mode }"
:style="barStyle" :style="barStyle"
@click="$emit('click')" @click="$emit('click')"
> >
<div class="van-notice-bar__left-icon" v-if="leftIcon"> <div v-if="leftIcon" :class="b('left-icon')">
<img :src="leftIcon" > <img :src="leftIcon" >
</div> </div>
<div class="van-notice-bar__content-wrap" ref="contentWrap"> <div :class="b('wrap')" ref="wrap">
<div <div
ref="content" ref="content"
class="van-notice-bar__content" :class="[b('content'), animationClass]"
:class="animationClass"
:style="contentStyle" :style="contentStyle"
@animationend="onAnimationEnd" @animationend="onAnimationEnd"
@webkitAnimationEnd="onAnimationEnd" @webkitAnimationEnd="onAnimationEnd"
@ -21,7 +19,12 @@
<slot>{{ text }}</slot> <slot>{{ text }}</slot>
</div> </div>
</div> </div>
<icon class="van-notice-bar__right-icon" :name="iconName" v-if="iconName" @click="onClickIcon" /> <icon
v-if="iconName"
:class="b('right-icon')"
:name="iconName"
@click="onClickIcon"
/>
</div> </div>
</template> </template>
@ -95,21 +98,23 @@ export default create({
onClickIcon() { onClickIcon() {
this.showNoticeBar = this.mode !== 'closeable'; this.showNoticeBar = this.mode !== 'closeable';
}, },
onAnimationEnd() { onAnimationEnd() {
this.firstRound = false; this.firstRound = false;
this.$nextTick(() => { this.$nextTick(() => {
this.duration = (this.offsetWidth + this.wrapWidth) / this.speed; this.duration = (this.offsetWidth + this.wrapWidth) / this.speed;
this.animationClass = 'van-notice-bar__play--infinite'; this.animationClass = this.b('play--infinite');
}); });
}, },
initAnimation() { initAnimation() {
const offsetWidth = this.$refs.content.getBoundingClientRect().width; const offsetWidth = this.$refs.content.getBoundingClientRect().width;
const wrapWidth = this.$refs.contentWrap.getBoundingClientRect().width; const wrapWidth = this.$refs.wrap.getBoundingClientRect().width;
if (this.scrollable && offsetWidth > wrapWidth) { if (this.scrollable && offsetWidth > wrapWidth) {
this.wrapWidth = wrapWidth; this.wrapWidth = wrapWidth;
this.offsetWidth = offsetWidth; this.offsetWidth = offsetWidth;
this.duration = offsetWidth / this.speed; this.duration = offsetWidth / this.speed;
this.animationClass = 'van-notice-bar__play'; this.animationClass = this.b('play');
} }
} }
} }

View File

@ -5,13 +5,17 @@
@touchmove="onBlur" @touchmove="onBlur"
@touchend="onBlur" @touchend="onBlur"
@touchcancel="onBlur" @touchcancel="onBlur"
class="van-hairline van-key" class="van-hairline"
:class="className" :class="[b(), className]"
/> />
</template> </template>
<script> <script>
export default { import create from '../utils/create';
export default create({
name: 'key',
props: { props: {
text: [String, Number], text: [String, Number],
type: { type: {
@ -31,7 +35,7 @@ export default {
const types = this.type.slice(0); const types = this.type.slice(0);
this.active && types.push('active'); this.active && types.push('active');
return types.map(type => `van-key--${type}`); return types.map(type => this.b([type]));
} }
}, },
@ -45,5 +49,5 @@ export default {
this.active = false; this.active = false;
} }
} }
}; });
</script> </script>

View File

@ -3,30 +3,29 @@
<div <div
v-show="show" v-show="show"
:style="style" :style="style"
class="van-number-keyboard" :class="b([theme])"
:class="`van-number-keyboard--${theme}`"
@animationend="onAnimationEnd" @animationend="onAnimationEnd"
@webkitAnimationEnd="onAnimationEnd" @webkitAnimationEnd="onAnimationEnd"
> >
<div class="van-number-keyboard__title van-hairline--top" v-if="title || showTitleClose"> <div :class="b('title')" class="van-hairline--top" v-if="title || showTitleClose">
<span v-text="title" /> <span v-text="title" />
<span <span
class="van-number-keyboard__close" :class="b('close')"
v-if="showTitleClose" v-if="showTitleClose"
v-text="closeButtonText" v-text="closeButtonText"
@click="onBlur" @click="onBlur"
/> />
</div> </div>
<div class="van-number-keyboard__body"> <div :class="b('body')">
<key <key
v-for="(key, index) in keys" v-for="(key, index) in keys"
:key="index" :key="key.text"
:text="key.text" :text="key.text"
:type="key.type" :type="key.type"
@press="onPressKey" @press="onPressKey"
/> />
</div> </div>
<div class="van-number-keyboard__sidebar" v-if="theme === 'custom'"> <div v-if="theme === 'custom'" :class="b('sidebar')">
<key :text="'delete'" :type="['delete', 'big']" @press="onPressKey" /> <key :text="'delete'" :type="['delete', 'big']" @press="onPressKey" />
<key :text="closeButtonText" :type="['green', 'big']" @press="onPressKey" /> <key :text="closeButtonText" :type="['green', 'big']" @press="onPressKey" />
</div> </div>

View File

@ -7,7 +7,7 @@
display: flex; display: flex;
position: fixed; position: fixed;
&__big-btn { &-big-btn {
flex: 1; flex: 1;
padding: 0; padding: 0;
@ -16,7 +16,7 @@
} }
} }
&__mini-btn { &-mini-btn {
color: $gray-darker; color: $gray-darker;
display: flex; display: flex;
height: 50px; height: 50px;
@ -40,7 +40,7 @@
background-color: $active-color; background-color: $active-color;
} }
&-icon { &__icon {
font-size: 20px; font-size: 20px;
margin-bottom: 5px; margin-bottom: 5px;
} }

View File

@ -34,7 +34,7 @@
line-height: 1; line-height: 1;
} }
&__content-wrap { &__wrap {
flex: 1; flex: 1;
height: 18px; height: 18px;
overflow: hidden; overflow: hidden;

View File

@ -16,8 +16,8 @@ describe('GoodsAction', () => {
DOMChecker(wrapper, { DOMChecker(wrapper, {
count: { count: {
'.van-goods-action__mini-btn': 2, '.van-goods-action-mini-btn': 2,
'.van-goods-action__big-btn': 2, '.van-goods-action-big-btn': 2,
'.van-icon-chat': 1 '.van-icon-chat': 1
} }
}); });