forked from quasarframework/quasar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQToggle.vue
More file actions
70 lines (67 loc) · 1.75 KB
/
QToggle.vue
File metadata and controls
70 lines (67 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<template>
<div
class="q-toggle q-option cursor-pointer no-outline q-focusable row inline no-wrap items-center"
:class="{disabled: disable, reverse: leftLabel}"
v-touch-swipe.horizontal="__swipe"
@click.stop.prevent="toggle"
tabindex="0"
@focus="$emit('focus')"
@blur="$emit('blur')"
@keydown.space.enter.prevent="toggle(false)"
>
<div class="q-option-inner relative-position" :class="classes">
<input
type="checkbox"
v-model="model"
:value="val"
:disabled="disable"
@click.stop
@change="__change"
>
<div class="q-focus-helper"></div>
<div class="q-toggle-base"></div>
<div class="q-toggle-handle shadow-1 row flex-center">
<q-icon v-if="currentIcon" class="q-toggle-icon" :name="currentIcon"></q-icon>
<div v-if="$q.theme !== 'ios'" ref="ripple" class="q-radial-ripple"></div>
</div>
</div>
<span class="q-option-label" v-if="label" v-html="label"></span>
<slot></slot>
</div>
</template>
<script>
import Mixin from '../checkbox/checkbox-mixin'
import OptionMixin from '../option-group/option-mixin'
import { QIcon } from '../icon'
import TouchSwipe from '../../directives/touch-swipe'
export default {
name: 'q-toggle',
components: {
QIcon
},
directives: {
TouchSwipe
},
mixins: [Mixin, OptionMixin],
props: {
icon: String,
checkedIcon: String,
uncheckedIcon: String
},
computed: {
currentIcon () {
return (this.isActive ? this.checkedIcon : this.uncheckedIcon) || this.icon
}
},
methods: {
__swipe (evt) {
if (evt.direction === 'left') {
this.unselect()
}
else if (evt.direction === 'right') {
this.select()
}
}
}
}
</script>