Categories
Vuetify

Vuetify — Transitions

Vuetify is a popular UI framework for Vue apps.

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

Transitions

Vuetify provides us with transition effective we van add.

We can add transition with the transition prop.

For example, we can write:

<template>
  <v-container>
    <v-row class="text-center">
      <v-col col="12">
        <v-menu transition="slide-x-transition">
          <template v-slot:activator="{ on, attrs }">
            <v-btn color="primary" class="ma-2" v-bind="attrs" v-on="on">Slide X Transition</v-btn>
          </template>
          <v-list>
            <v-list-item v-for="n in 3" :key="n" link>
              <v-list-item-title v-text="`Item ${n}`"></v-list-item-title>
            </v-list-item>
          </v-list>
        </v-menu>

        <div class="mx-4 hidden-sm-and-down"></div>
      </v-col>
    </v-row>
  </v-container>
</template>
<script>
export default {
  name: "HelloWorld",
  data: () => ({}),
};
</script>

The slide-x-transition provides us with a horizontal transition applied when displaying the menu.

We can reverse the direction of the transition with slide-x-reverse-transition .

Slide Y Transitions

We have the slide-y-transition to slide elements vertically.

For example, we can write:

<template>
  <v-container>
    <v-row class="text-center">
      <v-col col="12">
        <v-menu transition="slide-y-transition">
          <template v-slot:activator="{ on, attrs }">
            <v-btn color="primary" class="ma-2" v-bind="attrs" v-on="on">Slide Y Transition</v-btn>
          </template>
          <v-list>
            <v-list-item v-for="n in 3" :key="n" link>
              <v-list-item-title v-text="`Item ${n}`"></v-list-item-title>
            </v-list-item>
          </v-list>
        </v-menu>

        <div class="mx-4 hidden-sm-and-down"></div>
      </v-col>
    </v-row>
  </v-container>
</template>
<script>
export default {
  name: "HelloWorld",
  data: () => ({}),
};
</script>

Now we have vertical transition instead of horizontal.

Also, we have the slide-y-reverse-transition to apply the transition effect in the reverse direction.

Scroll Y Transitions

We can add scroll y transition with:

<template>
  <v-container>
    <v-row class="text-center">
      <v-col col="12">
        <v-menu transition="scroll-y-transition">
          <template v-slot:activator="{ on, attrs }">
            <v-btn color="primary" class="ma-2" v-bind="attrs" v-on="on">Scroll Y Transition</v-btn>
          </template>
          <v-list>
            <v-list-item v-for="n in 5" :key="n" link>
              <v-list-item-title v-text="`item ${n}`"></v-list-item-title>
            </v-list-item>
          </v-list>
        </v-menu>

        <div class="mx-4 hidden-sm-and-down"></div>
      </v-col>
    </v-row>
  </v-container>
</template>
<script>
export default {
  name: "HelloWorld",
  data: () => ({}),
};
</script>

We just set “scroll-y-transition” as the value of transition .

Fab Transition

We can add a rotating transition with fab-transition :

<template>
  <v-container>
    <v-row class="text-center">
      <v-col col="12">
        <v-menu transition="fab-transition">
          <template v-slot:activator="{ on, attrs }">
            <v-btn color="primary" class="ma-2" v-bind="attrs" v-on="on">Fab Transition</v-btn>
          </template>
          <v-list>
            <v-list-item v-for="n in 5" :key="n" link>
              <v-list-item-title v-text="`item ${n}`"></v-list-item-title>
            </v-list-item>
          </v-list>
        </v-menu>

        <div class="mx-4 hidden-sm-and-down"></div>
      </v-col>
    </v-row>
  </v-container>
</template>
<script>
export default {
  name: "HelloWorld",
  data: () => ({}),
};
</script>

Expand Transition

The v-expand-transition component lets us add an expand transition effect.

v-expand-x-transition is the horizontal version.

For example, we can write:

<template>
  <v-container>
    <v-row class="text-center">
      <v-col col="12">
        <v-btn class="ma-2" color="primary" @click="expand = !expand">Expand Transition</v-btn>

        <v-expand-transition>
          <v-card v-show="expand" height="100" width="100" class="mx-auto"></v-card>
        </v-expand-transition>
      </v-col>
    </v-row>
  </v-container>
</template>
<script>
export default {
  name: "HelloWorld",
  data: () => ({
    expand: false
  }),
};
</script>

Now when we toggle the card, we see a transition effect applied to it.

Conclusion

We can add various transition effects with Vuetify.

Categories
Vuetify

Vuetify — Text Styles

Vuetify is a popular UI framework for Vue apps.

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

Typography

We can add classes for typography.

For example, we can write:

<template>
  <v-container>
    <v-row class="text-center">
      <div class="text-h1">heading 1</div>
    </v-row>
  </v-container>
</template>

<script>
export default {
  name: "HelloWorld",

  data: () => ({}),
};
</script>

We have the text-h1 class to render a large heading.

We can do the same for the other headings, body, button, caption, subtitle, overline with the class with the same names.

Text Decoration

Vuetify also provides text-decoration classes to set this CSS property.

For example, we can write:

<template>
  <v-container>
    <v-row class="text-center">
      <v-col col="12">
        <a href="#" class="text-decoration-none">Non-underlined link</a>
        <div class="text-decoration-line-through">Line-through text</div>
        <div class="text-decoration-overline">Overline text</div>
        <div class="text-decoration-underline">Underline text</div>
      </v-col>
    </v-row>
  </v-container>
</template>
<script>
export default {
  name: "HelloWorld",
  data: () => ({}),
};
</script>

to style text with or without lines.

Text Transform

We can transform text with some text- classes.

For example, we can write:

<template>
  <v-container>
    <v-row class="text-center">
      <v-col col="12">
        <p class="text-lowercase">Lowercased text.</p>
        <p class="text-uppercase">Uppercased text.</p>
        <p class="text-capitalize">CapiTaliZed text.</p>
      </v-col>
    </v-row>
  </v-container>
</template>
<script>
export default {
  name: "HelloWorld",
  data: () => ({}),
};
</script>

We can change the text to upper case, lower case, or capitalized as we wish.

Font Weights and Italics

We can change the font-weight and toggle on or off italics with classes provided by Vuwetify.

For example, we can write:

<template>
  <v-container>
    <v-row class="text-center">
      <v-col col="12">
        <p class="font-weight-black">Black text.</p>
        <p class="font-weight-bold">Bold text.</p>
        <p class="font-weight-medium">Medium weight text.</p>
        <p class="font-weight-regular">Normal weight text.</p>
        <p class="font-weight-light">Light weight text.</p>
        <p class="font-weight-thin">Thin weight text.</p>
        <p class="font-italic">Italic text.</p>
      </v-col>
    </v-row>
  </v-container>
</template>
<script>
export default {
  name: "HelloWorld",
  data: () => ({}),
};
</script>

The font-weight- classes let us set the font-weight to what we want.

Text Opacity

The text opacity can be changed with different classes.

For instance, we can write:

<template>
  <v-container>
    <v-row class="text-center">
      <v-col col="12">
        <p class="text--primary">opacity 87%.</p>
        <p class="text--secondary">opacity 60%.</p>
        <p class="text--disabled">opacity 38%.</p>
      </v-col>
    </v-row>
  </v-container>
</template>
<script>
export default {
  name: "HelloWorld",
  data: () => ({}),
};
</script>

The opacity can be changed with the text--primary , text--secondary and text--disabled classes.

They have the opacities listed.

RTL Alignment

Vuetify has classes to change the alignment to RTL.

For example, we can write:

<template>
  <v-container>
    <v-row class="text-center">
      <v-col col="12">
        <p class="subtitle-2 text-center">lorem ipsum</p>
        <p
          class="text-sm-left"
        >lorem ipsum</p>
        <p
          class="text-md-left"
        >lorem ipsum.</p>
        <p
          class="text-lg-right"
        >lorem ipsum.</p>
        <p
          class="text-xl-left"
        >lorem ipsum</p>
        <p class="subtitle-2 text-center">lorem ipsum</p>
        <p class="text-start">lorem ipsum</p>
        <p class="text-end">lorem ipsum</p>
      </v-col>
    </v-row>
  </v-container>
</template>
<script>
export default {
  name: "HelloWorld",
  data: () => ({}),
};
</script>

We have the classes to align text according to breakpoints and the position.

Conclusion

We can align text and change text style with the classes provided by Vuetify.

Categories
Vuetify

Vuetify — Paddings and Margins

Vuetify is a popular UI framework for Vue apps.

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

Flex align-content

We can add the align-content classes to change the alignment of flexbox content.

For example, we can write:

<template>
  <v-container>
    <v-row class="text-center">
      <v-col cols="12">
        <v-card
          class="d-flex align-content-start flex-wrap"
          color="grey lighten-2"
          flat
          tile
          min-height="200"
        >
          <v-card v-for="n in 10" :key="n" class="pa-2" outlined tile>item</v-card>
        </v-card>
      </v-col>
    </v-row>
  </v-container>
</template>

<script>
export default {
  name: "HelloWorld",

  data: () => ({}),
};
</script>

We have the align-content-start class to align the content to the left.

There are other classes for other alignments.

Flex Grow and Shrink

Vuetify has the flex-{condition}-{value} classes to grow and shrink the items.

For example, we can write:

<template>
  <v-container>
    <v-row class="text-center">
      <v-col cols="2" class="flex-grow-0 flex-shrink-0">
        <v-card class="pa-2" outlined tile>2 column wide</v-card>
      </v-col>
    </v-row>
  </v-container>
</template>

<script>
export default {
  name: "HelloWorld",

  data: () => ({}),
};
</script>

to create a column 2 columns wide and use the flex-grow-0 and flex-shrink-0 classes to fill the container.

Float

We can apply a custom float with Vuetify classes.

For example, we can write:

<template>
  <v-container>
    <v-row class="text-center">
      <v-col cols="12">
        <div>
          <div class="float-left">Float left</div>
          <br />
          <div class="float-right">Float right</div>
          <br />
          <div class="float-none">Don't float</div>
        </div>
      </v-col>
    </v-row>
  </v-container>
</template>

<script>
export default {
  name: "HelloWorld",

  data: () => ({}),
};
</script>

We have float-left class to float left.

float-right floats right.

float-none disables float.

Responsive

Floats can be applied with some breakpoints.

For example, we can write:

<template>
  <v-container>
    <v-row class="text-center">
      <v-col cols="12">
        <div>
          <div class="float-sm-left">sm</div>
          <br />
          <div class="float-md-left">md</div>
          <br />
          <div class="float-lg-left">lg</div>
          <br />
          <div class="float-xl-left">xl</div>
          <br />
        </div>
      </v-col>
    </v-row>
  </v-container>
</template>

<script>
export default {
  name: "HelloWorld",

  data: () => ({}),
};
</script>

We have the breakpoint in the class name to only apply the float if the breakpoint is the given one or wider.

Spacing

Spacing can be changed with classes in the following format:

{property}{direction}-{size}

property can be:

  • m – applies margin
  • p – applies padding

direction can be:

  • t – applies the spacing for margin-top and padding-top
  • b – applies the spacing for margin-bottom and padding-bottom
  • l – applies the spacing for margin-left and padding-left
  • r – applies the spacing for margin-right and padding-right
  • s – applies the spacing for margin-left/padding-left (in LTR mode) and margin-right/padding-right (in RTL mode)
  • e – applies the spacing for margin-right/padding-right (in LTR mode) and margin-left/padding-left (in RTL mode)
  • x – applies the spacing for both *-left and *-right
  • y – applies the spacing for both *-top and *-bottom
  • a – applies the spacing for the property in all directions

size is 0 to 16 to set the size from 0 to 64px.

n1 to n16 set the margin to -4px to -64px.

We can use mx-auto to set the margin size automatically:

<template>
  <v-container>
    <v-row class="text-center">
      <v-col cols="12">
        <v-card class="mx-auto" color="white" width="200px">
          <v-card-text>Centered</v-card-text>
        </v-card>
      </v-col>
    </v-row>
  </v-container>
</template>

<script>
export default {
  name: "HelloWorld",

  data: () => ({}),
};
</script>

We can change the padding by writing:

<template>
  <v-container>
    <v-row class="text-center">
      <v-card class="pa-md-4 mx-lg-auto" color="white" width="250px">
        <v-card-text>text</v-card-text>
      </v-card>
    </v-row>
  </v-container>
</template>

<script>
export default {
  name: "HelloWorld",

  data: () => ({}),
};
</script>

We have the pa-md-4 class to change the padding for md breakpoint and up to 16px.

Conclusion

Vuetify provides us with many classes for changing margins and padding.

Categories
Vuetify

Vuetify — Flexbox

Vuetify is a popular UI framework for Vue apps.

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

Flex Justify

We can justify-content in a flexbox container with the classes provided by Vuetify.

For example, we can write:

<template>
  <v-container>
    <v-row class="text-center">
      <v-col cols="12">
        <v-card
          v-for="j in justify"
          :key="j"
          :class="`d-flex justify-${j} mb-2`"
          color="grey lighten-2"
          flat
          tile
        >
          <v-card v-for="n in 3" :key="n" class="pa-2" outlined tile>item</v-card>
        </v-card>
      </v-col>
    </v-row>
  </v-container>
</template>

<script>
export default {
  name: "HelloWorld",

  data: () => ({
    justify: ["start", "end", "center", "space-between", "space-around"],
  }),
};
</script>

to set the justification of our content to what we want.

There are also responsive variants of the classes.

Flex Align

Vuetify also provides us with flex align classes to align content.

For example, we can write:

<template>
  <v-container>
    <v-row class="text-center">
      <v-col cols="12">
        <v-card
          v-for="a in align"
          :key="a"
          :class="`d-flex align-${a} mb-6`"
          flat
          height="100"
          tile
        >
          <v-card v-for="n in 3" :key="n" class="pa-2" outlined tile>item</v-card>
        </v-card>
      </v-col>
    </v-row>
  </v-container>
</template>

<script>
export default {
  name: "HelloWorld",

  data: () => ({
    align: ["start", "end", "center", "baseline", "stretch"],
  }),
};
</script>

to align our content our way.

We have the d-flex and align classes to align the containers in various ways.

Flex Align Self

We can use the align-self classes to apply the align-self property.

For example, we can write:

<template>
  <v-container>
    <v-row class="text-center">
      <v-col cols="12">
        <v-card
          v-for="j in justify"
          :key="j"
          class="d-flex mb-6"
          height="100"
        >
          <v-card
            v-for="n in 3"
            :key="n"
            class="pa-2"
            :class="[n === 1 && `align-self-${j}`]"
          >{{ n === 1 ? 'Aligned flex item' : 'Flex item' }}</v-card>
        </v-card>
      </v-col>
    </v-row>
  </v-container>
</template>

<script>
export default {
  name: "HelloWorld",

  data: () => ({
    justify: ["start", "end", "center", "baseline", "auto", "stretch"],
  }),
};
</script>

We have the align-self classes to align the classes our way.

Flex Wrap

Vuetify also provides the flex wrap classes.

For example, we can write:

<template>
  <v-container>
    <v-row class="text-center">
      <v-col cols="12">
        <v-card class="d-flex flex-nowrap py-3" color="grey lighten-2" flat tile>
          <v-card v-for="n in 5" :key="n" class="pa-2" outlined tile>Flex item</v-card>
        </v-card>
      </v-col>
    </v-row>
  </v-container>
</template>

<script>
export default {
  name: "HelloWorld",

  data: () => ({
    justify: ["start", "end", "center", "baseline", "auto", "stretch"],
  }),
};
</script>

We have the flex-nowrap to prevent wrapping.

The general format of the classes is flex-{breakpoint}-{condition} .

Flex Order

We can switch the visual order of the flex items with the order classes.

So we can write:

<template>
  <v-container>
    <v-row class="text-center">
      <v-col cols="12">
        <v-card class="d-flex flex-wrap-reverse" color="grey lighten-2" flat tile>
          <v-card class="order-3 pa-2" outlined tile>First</v-card>
          <v-card class="order-2 pa-2" outlined tile>Second</v-card>
          <v-card class="order-1 pa-2" outlined tile>Third</v-card>
        </v-card>
      </v-col>
    </v-row>
  </v-container>
</template>

<script>
export default {
  name: "HelloWorld",

  data: () => ({
  }),
};
</script>

We flipped the order with the flex-wrap-reverse class.

Conclusion

Vuetify provides us with various flexbox utilities to lay out our items.

Categories
Vuetify

Getting Started with Vuetify

Vuetify is a popular UI framework for Vue apps.

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

Vue CLI Install

The easiest way to create a Vuetify Vue app is to use the Vue CLI.

We create a project directory, go into it, and run:

npx vue create .

We choose the options we want when prompted.

Once we did that, we run:

vue add vuetify

to add the Vuetify files.

We choose Default when prompted.

This is the recommended configuration.

It comes with all the components and assets we need to build an app with it.

Colors

Once we did that, we can set the colors by using the classes.

So we can write:

<div class="red">

or

<span class="red--text">

and to set the colors to red.

We can also change the colors in vuetify.js :

import Vue from 'vue';
import Vuetify from 'vuetify/lib';
import colors from 'vuetify/lib/util/colors'

Vue.use(Vuetify);

export default new Vuetify({
  theme: {
    themes: {
      light: {
        primary: colors.red.darken1,
        secondary: colors.red.lighten4,
        accent: colors.indigo.base
      },
    },
  },
});

We import the colors object and set the colors to what we want.

SASS Colors

We can also import SASS colors by writing:

@import '~vuetify/src/styles/main.sass';

They can also be imported in the src/index.js file writing;

import './src/sass/main.scss'
// OR
require('./src/sass/main.scss')

This works if we configured our Vue CLI to use SASS.

Content

We can create content with various elements.

Vuetify provides styles for them.

For instance, we can create a blockquote by writing:

<template>
  <v-container>
    <v-row class="text-center">
      <v-col cols="12">
        <blockquote class="blockquote">Lorem ipsum dolor sit amet, consectetur adipisicing elit.</blockquote>
      </v-col>
    </v-row>
  </v-container>
</template>

<script>
export default {
  name: "HelloWorld",

  data: () => ({}),
};
</script>

We just put them inside a component within the v-container to have the styling applied.

We can do the same for code:

<template>
  <v-container>
    <v-row class="text-center">
      <v-col cols="12">
         <code>&lt;code&gt;</code>
      </v-col>
    </v-row>
  </v-container>
</template>

<script>
export default {
  name: "HelloWorld",

  data: () => ({}),
};
</script>

Also, we can apply styles to the kbd element:

<template>
  <v-container>
    <v-row class="text-center">
      <v-col cols="12">
        <kbd>npm install vuetify</kbd>
      </v-col>
    </v-row>
  </v-container>
</template>

<script>
export default {
  name: "HelloWorld",

  data: () => ({}),
};
</script>

Display Helpers

We can add various classes to add padding, colors, set the display CSS property and more.

For example, we can write:

<template>
  <v-container>
    <v-row class="text-center">
      <v-col cols="12">
        <div class="d-inline pa-3 deep-purple accent-4 white--text">foo</div>
        <div class="d-inline pa-3 black white--text">bar</div>
      </v-col>
    </v-row>
  </v-container>
</template>

<script>
export default {
  name: "HelloWorld",

  data: () => ({}),
};
</script>

We create a purple and black divs with some classes.

pa-3 created padding.

d-inline make the divs display inline.

deep-purple , accent-4 , white--text , and black are the color classes.

Conclusion

We can create a Vuetify app with a few commands.

It adds styles to elements and we can also add our own style with the classes it provides.