Quasar is a popular Vue UI library for developing good looking Vue apps.
In this article, we’ll take a look at how to create Vue apps with the Quasar UI library.
Toggle Indeterminate State
A Quasar toggle can be set to an indeterminate state.
To add it, we set the indeterminate-value
prop:
<!DOCTYPE html>
<html>
<head>
<link
href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900|Material+Icons"
rel="stylesheet"
type="text/css"
/>
<link
href="https://cdn.jsdelivr.net/npm/quasar@1.12.13/dist/quasar.min.css"
rel="stylesheet"
type="text/css"
/>
</head>
<body class="body--dark">
<script src="https://cdn.jsdelivr.net/npm/vue@^2.0.0/dist/vue.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/quasar@1.12.13/dist/quasar.umd.min.js"></script>
<div id="q-app">
<q-layout
view="lHh Lpr lFf"
container
style="height: 100vh;"
class="shadow-2 rounded-borders"
>
<div class="q-pa-md">
<q-toggle
indeterminate-value="maybe"
false-value="disagree"
true-value="agree"
v-model="value"
color="green"
>
</q-toggle>
</div>
</q-layout>
</div>
<script>
new Vue({
el: "#q-app",
data: {
value: "maybe"
}
});
</script>
</body>
</html>
We set the indeterminate-value
prop to set the value when the toggle button is displayed in the middle.
Toggle Order
The order of toggling can be changed.
We change it with the toggle-order
prop:
<!DOCTYPE html>
<html>
<head>
<link
href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900|Material+Icons"
rel="stylesheet"
type="text/css"
/>
<link
href="https://cdn.jsdelivr.net/npm/quasar@1.12.13/dist/quasar.min.css"
rel="stylesheet"
type="text/css"
/>
</head>
<body class="body--dark">
<script src="https://cdn.jsdelivr.net/npm/vue@^2.0.0/dist/vue.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/quasar@1.12.13/dist/quasar.umd.min.js"></script>
<div id="q-app">
<q-layout
view="lHh Lpr lFf"
container
style="height: 100vh;"
class="shadow-2 rounded-borders"
>
<div class="q-pa-md">
<q-toggle
toggle-indeterminate
toggle-order="ft"
v-model="value"
label="'ft' order"
color="orange"
></q-toggle>
</div>
</q-layout>
</div>
<script>
new Vue({
el: "#q-app",
data: {
value: ""
}
});
</script>
</body>
</html>
toggle-order
set to ft
sets the toggle to first toggle to false
and then to false
.
We can also set it to tf
to do the opposite.
We can set the q-toggle
to display on a dark background with the dark
prop:
<!DOCTYPE html>
<html>
<head>
<link
href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900|Material+Icons"
rel="stylesheet"
type="text/css"
/>
<link
href="https://cdn.jsdelivr.net/npm/quasar@1.12.13/dist/quasar.min.css"
rel="stylesheet"
type="text/css"
/>
</head>
<body class="body--dark">
<script src="https://cdn.jsdelivr.net/npm/vue@^2.0.0/dist/vue.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/quasar@1.12.13/dist/quasar.umd.min.js"></script>
<div id="q-app">
<q-layout
view="lHh Lpr lFf"
container
style="height: 100vh;"
class="shadow-2 rounded-borders"
>
<div class="q-pa-md bg-grey-10 text-white">
<q-toggle color="blue" dark v-model="value"></q-toggle>
</div>
</q-layout>
</div>
<script>
new Vue({
el: "#q-app",
data: {
value: false
}
});
</script>
</body>
</html>
We add the bg-grey-10
class to show a dark background and text-white
to display the text in white.
To disable the toggle, we add the disabled
prop:
<!DOCTYPE html>
<html>
<head>
<link
href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900|Material+Icons"
rel="stylesheet"
type="text/css"
/>
<link
href="https://cdn.jsdelivr.net/npm/quasar@1.12.13/dist/quasar.min.css"
rel="stylesheet"
type="text/css"
/>
</head>
<body class="body--dark">
<script src="https://cdn.jsdelivr.net/npm/vue@^2.0.0/dist/vue.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/quasar@1.12.13/dist/quasar.umd.min.js"></script>
<div id="q-app">
<q-layout
view="lHh Lpr lFf"
container
style="height: 100vh;"
class="shadow-2 rounded-borders"
>
<div class="q-pa-md">
<q-toggle color="primary" disable v-model="value"></q-toggle>
</div>
</q-layout>
</div>
<script>
new Vue({
el: "#q-app",
data: {
value: false
}
});
</script>
</body>
</html>
The size of the toggle can be changed with the size
prop:
<!DOCTYPE html>
<html>
<head>
<link
href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900|Material+Icons"
rel="stylesheet"
type="text/css"
/>
<link
href="https://cdn.jsdelivr.net/npm/quasar@1.12.13/dist/quasar.min.css"
rel="stylesheet"
type="text/css"
/>
</head>
<body class="body--dark">
<script src="https://cdn.jsdelivr.net/npm/vue@^2.0.0/dist/vue.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/quasar@1.12.13/dist/quasar.umd.min.js"></script>
<div id="q-app">
<q-layout
view="lHh Lpr lFf"
container
style="height: 100vh;"
class="shadow-2 rounded-borders"
>
<div class="q-pa-md">
<q-toggle size="xl" color="primary" v-model="value"></q-toggle>
</div>
</q-layout>
</div>
<script>
new Vue({
el: "#q-app",
data: {
value: false
}
});
</script>
</body>
</html>
We set the size
prop to xl
to make it extra large.
Other possible values include xs
, sm
, md
, lg
, and xl
.
Conclusion
We can change many options with Quasar’s toggle.