2018-06-14 00:52:37 -05:00
|
|
|
<template>
|
|
|
|
<div
|
|
|
|
class="ui-switch"
|
|
|
|
:class="{ disabled, checked }"
|
|
|
|
role="switch"
|
|
|
|
:aria-checked="checked"
|
|
|
|
:aria-disabled="disabled"
|
2018-06-14 07:38:39 -05:00
|
|
|
@click="toggle"
|
2018-06-14 00:52:37 -05:00
|
|
|
>
|
|
|
|
<input
|
|
|
|
type="checkbox"
|
|
|
|
ref="input"
|
|
|
|
:disabled="disabled"
|
2018-06-14 07:38:39 -05:00
|
|
|
@keydown.enter="toggle"
|
2018-06-14 00:52:37 -05:00
|
|
|
>
|
|
|
|
<span class="button">
|
2018-06-14 02:48:49 -05:00
|
|
|
<span></span>
|
2018-06-14 00:52:37 -05:00
|
|
|
</span>
|
|
|
|
<span class="label">
|
|
|
|
<span :aria-hidden="!checked"><slot></slot></span>
|
|
|
|
<p :aria-hidden="!checked">
|
2018-09-28 07:48:53 -05:00
|
|
|
<slot name="desc"></slot>
|
2018-06-14 00:52:37 -05:00
|
|
|
</p>
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import Vue from 'vue';
|
|
|
|
export default Vue.extend({
|
2018-06-14 07:38:39 -05:00
|
|
|
model: {
|
|
|
|
prop: 'value',
|
|
|
|
event: 'change'
|
|
|
|
},
|
2018-06-14 00:52:37 -05:00
|
|
|
props: {
|
|
|
|
value: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
|
|
|
disabled: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
}
|
2018-06-14 07:38:39 -05:00
|
|
|
},
|
2018-06-14 00:52:37 -05:00
|
|
|
computed: {
|
|
|
|
checked(): boolean {
|
|
|
|
return this.value;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2018-06-14 07:38:39 -05:00
|
|
|
toggle() {
|
2018-06-14 00:52:37 -05:00
|
|
|
this.$emit('change', !this.checked);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="stylus" scoped>
|
2018-09-26 22:55:10 -05:00
|
|
|
.ui-switch
|
2018-06-14 00:52:37 -05:00
|
|
|
display flex
|
2018-06-14 02:48:49 -05:00
|
|
|
margin 32px 0
|
2018-06-14 00:52:37 -05:00
|
|
|
cursor pointer
|
|
|
|
transition all 0.3s
|
|
|
|
|
2018-09-04 23:47:26 -05:00
|
|
|
&:first-child
|
|
|
|
margin-top 0
|
|
|
|
|
|
|
|
&:last-child
|
|
|
|
margin-bottom 0
|
|
|
|
|
2018-06-14 00:52:37 -05:00
|
|
|
> *
|
|
|
|
user-select none
|
|
|
|
|
|
|
|
&.disabled
|
|
|
|
opacity 0.6
|
|
|
|
cursor not-allowed
|
|
|
|
|
|
|
|
&.checked
|
|
|
|
> .button
|
2018-12-30 11:33:03 -06:00
|
|
|
background-color var(--switchActiveTrack)
|
|
|
|
border-color var(--switchActiveTrack)
|
2018-06-14 00:52:37 -05:00
|
|
|
|
2018-06-14 02:48:49 -05:00
|
|
|
> *
|
2018-12-30 11:33:03 -06:00
|
|
|
background-color var(--switchActive)
|
2018-06-14 02:48:49 -05:00
|
|
|
transform translateX(14px)
|
2018-06-14 00:52:37 -05:00
|
|
|
|
|
|
|
> input
|
|
|
|
position absolute
|
|
|
|
width 0
|
|
|
|
height 0
|
|
|
|
opacity 0
|
|
|
|
margin 0
|
|
|
|
|
|
|
|
> .button
|
|
|
|
display inline-block
|
2018-09-04 23:47:26 -05:00
|
|
|
flex-shrink 0
|
2018-06-14 02:48:49 -05:00
|
|
|
margin 3px 0 0 0
|
|
|
|
width 34px
|
|
|
|
height 14px
|
2018-09-26 22:55:10 -05:00
|
|
|
background var(--switchTrack)
|
2018-06-14 00:52:37 -05:00
|
|
|
outline none
|
2018-06-14 02:48:49 -05:00
|
|
|
border-radius 14px
|
2018-06-14 00:52:37 -05:00
|
|
|
transition inherit
|
|
|
|
|
|
|
|
> *
|
|
|
|
position absolute
|
2018-06-14 02:48:49 -05:00
|
|
|
top -3px
|
|
|
|
left 0
|
|
|
|
border-radius 100%
|
|
|
|
transition background-color 0.3s, transform 0.3s
|
|
|
|
width 20px
|
|
|
|
height 20px
|
2018-06-14 00:52:37 -05:00
|
|
|
background-color #fff
|
2018-06-14 02:48:49 -05:00
|
|
|
box-shadow 0 2px 1px -1px rgba(#000, 0.2), 0 1px 1px 0 rgba(#000, 0.14), 0 1px 3px 0 rgba(#000, 0.12)
|
2018-06-14 00:52:37 -05:00
|
|
|
|
|
|
|
> .label
|
|
|
|
margin-left 8px
|
|
|
|
display block
|
|
|
|
font-size 16px
|
|
|
|
cursor pointer
|
|
|
|
transition inherit
|
2019-02-05 08:45:27 -06:00
|
|
|
color var(--text)
|
2018-06-14 00:52:37 -05:00
|
|
|
|
|
|
|
> span
|
|
|
|
display block
|
2018-06-14 02:48:49 -05:00
|
|
|
line-height 20px
|
2018-06-14 00:52:37 -05:00
|
|
|
transition inherit
|
|
|
|
|
|
|
|
> p
|
|
|
|
margin 0
|
2018-12-03 18:42:55 -06:00
|
|
|
opacity 0.7
|
2018-11-06 00:51:18 -06:00
|
|
|
font-size 90%
|
2018-06-14 00:52:37 -05:00
|
|
|
|
|
|
|
</style>
|