Switch add large size and optimize style

Switch add large size and optimize style
This commit is contained in:
梁灏 2016-11-02 12:07:52 +08:00
parent 77b4e431e0
commit 2af5843d96
7 changed files with 81 additions and 22 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -23,7 +23,7 @@
}, },
size: { size: {
validator (value) { validator (value) {
return oneOf(value, ['small']); return oneOf(value, ['large', 'small']);
} }
} }
}, },

View file

@ -2,10 +2,10 @@
.@{switch-prefix-cls} { .@{switch-prefix-cls} {
display: inline-block; display: inline-block;
width: 44px; width: 48px;
height: 24px; height: 24px;
line-height: 22px; line-height: 22px;
border-radius: 22px; border-radius: 24px;
vertical-align: middle; vertical-align: middle;
border: 1px solid #ccc; border: 1px solid #ccc;
background-color: #ccc; background-color: #ccc;
@ -18,7 +18,7 @@
color: #fff; color: #fff;
font-size: 12px; font-size: 12px;
position: absolute; position: absolute;
left: 24px; left: 25px;
i{ i{
width: 12px; width: 12px;
@ -29,13 +29,13 @@
&:after { &:after {
content: ''; content: '';
width: 22px; width: 20px;
height: 22px; height: 20px;
border-radius: 50%; border-radius: 20px;
background-color: #fff; background-color: #fff;
position: absolute; position: absolute;
left: 0; left: 1px;
top: 0; top: 1px;
cursor: pointer; cursor: pointer;
.transition2(left @transition-time @ease-in-out, width @transition-time @ease-in-out); .transition2(left @transition-time @ease-in-out, width @transition-time @ease-in-out);
} }
@ -54,26 +54,45 @@
} }
&-small { &-small {
height: 14px; width: 24px;
line-height: 12px;
width: 28px;
&:after {
width: 12px;
height: 12px; height: 12px;
line-height: 10px;
&:after {
width: 10px;
height: 10px;
top: 0; top: 0;
left: 0; left: 0;
} }
&:active:after { &:active:after {
width: 16px; width: 14px;
} }
} }
&-small&-checked:after { &-small&-checked:after {
left: 14px; left: 12px;
} }
&-small:active&-checked:after { &-small:active&-checked:after {
left: 10px; left: 8px;
}
&-large{
width: 60px;
&:active:after {
width: 26px;
}
}
&-large:active:after {
width: 32px;
}
&-large&-checked:after {
left: 37px;
}
&-large:active&-checked:after {
left: 25px;
} }
&-checked { &-checked {
@ -81,15 +100,15 @@
background-color: @primary-color; background-color: @primary-color;
.@{switch-prefix-cls}-inner { .@{switch-prefix-cls}-inner {
left: 6px; left: 8px;
} }
&:after { &:after {
left: 20px; left: 25px;
} }
&:active:after { &:active:after {
left: 16px; left: 19px;
} }
} }

View file

@ -35,6 +35,7 @@ li + li {
<li><a v-link="'/select'">Select</a></li> <li><a v-link="'/select'">Select</a></li>
<li><a v-link="'/slider'">Slider</a></li> <li><a v-link="'/slider'">Slider</a></li>
<li><a v-link="'/step'">Step</a></li> <li><a v-link="'/step'">Step</a></li>
<li><a v-link="'/switch'">Switch</a></li>
</ul> </ul>
</nav> </nav>
<router-view></router-view> <router-view></router-view>

View file

@ -65,6 +65,11 @@ router.map({
component: function (resolve) { component: function (resolve) {
require(['./routers/step.vue'], resolve); require(['./routers/step.vue'], resolve);
} }
},
'/switch': {
component: function (resolve) {
require(['./routers/switch.vue'], resolve);
}
} }
}); });

34
test/routers/switch.vue Normal file
View file

@ -0,0 +1,34 @@
<template>
<Switch @on-change="change"></Switch>
<Switch>
<span slot="open"></span>
<span slot="close"></span>
</Switch>
<Switch size="large">
<span slot="open">ON</span>
<span slot="close">OFF</span>
</Switch>
<Switch>
<Icon type="android-done" slot="open"></Icon>
<Icon type="android-close" slot="close"></Icon>
</Switch>
<Switch :disabled="disabled"></Switch>
<i-button type="primary" @click="disabled = !disabled">Toggle Disabled</i-button>
<Switch size="small"></Switch>
</template>
<script>
import { Switch, Message, iButton, Icon } from 'iview';
export default {
components: { Switch, Message, iButton, Icon },
data () {
return {
disabled: true
}
},
methods: {
change (status) {
Message.info('开关状态:' + status);
}
}
}
</script>