Vuetify — Timeline Customization

Image for post
Image for post
Photo by Isabella Christina on Unsplash

Vuetify is a popular UI framework for Vue apps.

In this article, we’ll look at how to work with the Vuetify framework.

Reverse Direction

We can reverse the direction of the timeline items with the reverse prop:

<template>
<v-timeline align-top :dense="$vuetify.breakpoint.smAndDown" reverse>
<v-timeline-item
v-for="(item, i) in items"
:key="i"
:color="item.color"
:icon="item.icon"
fill-dot
>
<v-card :color="item.color" dark>
<v-card-title class="title">Lorem Ipsum Dolor</v-card-title>
<v-card-text class="white text--primary">
<p>Lorem ipsum dolor sit amet.</p>
<v-btn :color="item.color" class="mx-0" outlined>Button</v-btn>
</v-card-text>
</v-card>
</v-timeline-item>
</v-timeline>
</template>
<script>
export default {
name: "HelloWorld",
data: () => ({
items: [
{
color: "red lighten-2",
icon: "mdi-star",
},
{
color: "purple darken-1",
icon: "mdi-book-variant",
},
{
color: "green lighten-1",
icon: "mdi-airballoon",
},
],
}),
};
</script>

Timeline Card

We can place a v-card in a v-timeline-item component.

A caret will appear on the side of the card.

For example, we can write:

<template>
<v-timeline>
<v-timeline-item v-for="n in 3" :key="n" color="red lighten-2" large>
<template v-slot:opposite>
<span>Foo</span>
</template>
<v-card class="elevation-2">
<v-card-title class="headline">Lorem ipsum</v-card-title>
<v-card-text>Lorem ipsum dolor sit amet.</v-card-text>
</v-card>
</v-timeline-item>
</v-timeline>
</template>
<script>
export default {
name: "HelloWorld",
data: () => ({}),
};
</script>

The opposite slot has some text.

And the cards will be displayed on the side opposite of the opposite slot.

Dense Alert

We can make the timeline smaller with the dense prop.

For example, we can write:

<template>
<v-card class="mx-auto" max-width="600">
<v-card-title class="blue-grey white--text">
<span class="title">Logs</span>
</v-card-title>
<v-card-text class="py-0">
<v-timeline dense>
<v-slide-x-reverse-transition group hide-on-leave>
<v-timeline-item v-for="item in items" :key="item.id" :color="item.color" small fill-dot>
<v-alert
:value="true"
:color="item.color"
:icon="item.icon"
class="white--text"
>Lorem ipsum dolor sit amet.</v-alert>
</v-timeline-item>
</v-slide-x-reverse-transition>
</v-timeline>
</v-card-text>
</v-card>
</template>
<script>
export default {
name: "HelloWorld",
data: () => ({
items: [
{
id: 1,
color: "red lighten-2",
icon: "mdi-star",
},
{
id: 2,
color: "purple darken-1",
icon: "mdi-book-variant",
},
{
id: 3,
color: "green lighten-1",
icon: "mdi-airballoon",
},
],
}),
};
</script>

We added the dense prop to the v-timeline to display items in a compressed form.

The entries will all be on the right side and they’re smaller than the default size.

Opposite Slot

The opposite slot lets us put items to the opposite side of the timeline item.

For example, we can write:

<template>
<v-timeline>
<v-timeline-item v-for="(year, i) in years" :key="i" :color="year.color" small>
<template v-slot:opposite>
<span :class="`headline font-weight-bold ${year.color}--text`" v-text="year.year"></span>
</template>
<div class="py-4">
<h2 :class="`headline font-weight-light mb-4 ${year.color}--text`">Lorem ipsum</h2>
<div>Lorem ipsum dolor sit amet.</div>
</div>
</v-timeline-item>
</v-timeline>
</template>
<script>
export default {
name: "HelloWorld",
data: () => ({
years: [
{
color: "cyan",
year: "1960",
},
{
color: "green",
year: "1970",
},
{
color: "pink",
year: "1980",
},
],
}),
};
</script>

We have the opposite slot to add items to the opposite side of our main timeline item content.

Conclusion

We can add timeline items in various ways with Vuetify.

Written by

Web developer. Subscribe to my email list now at http://jauyeung.net/subscribe/. Email me at hohanga@gmail.com

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store