forked from quasarframework/quasar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQToggle.js
More file actions
51 lines (39 loc) · 1.17 KB
/
QToggle.js
File metadata and controls
51 lines (39 loc) · 1.17 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
import { h, computed } from 'vue'
import QIcon from '../icon/QIcon.js'
import useCheckbox, { useCheckboxProps, useCheckboxEmits } from '../checkbox/use-checkbox.js'
import { createComponent } from '../../utils/private/create.js'
export default createComponent({
name: 'QToggle',
props: {
...useCheckboxProps,
icon: String,
iconColor: String
},
emits: useCheckboxEmits,
setup (props) {
function getInner (isTrue, isIndeterminate) {
const icon = computed(() =>
(isTrue.value === true
? props.checkedIcon
: (isIndeterminate.value === true ? props.indeterminateIcon : props.uncheckedIcon)
) || props.icon
)
const color = computed(() => (isTrue.value === true ? props.iconColor : null))
return () => [
h('div', { class: 'q-toggle__track' }),
h('div', {
class: 'q-toggle__thumb absolute flex flex-center no-wrap'
}, icon.value !== void 0
? [
h(QIcon, {
name: icon.value,
color: color.value
})
]
: void 0
)
]
}
return useCheckbox('toggle', getInner)
}
})