Categories
Vuetify

Vuetify — Chip Groups

Vuetify is a popular UI framework for Vue apps.

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

Chip Groups

We can group chips together with the v-chip-group component.

For example, we can write:

<template>
  <v-container class="grey lighten-5">
    <v-row>
      <v-col>
        <v-sheet elevation="10" class="pa-4">
          <v-chip-group column active-class="primary--text">
            <v-chip v-for="tag in tags" :key="tag">{{ tag }}</v-chip>
          </v-chip-group>
        </v-sheet>
      </v-col>
    </v-row>
  </v-container>
</template>
<script>
export default {
  name: "HelloWorld",
  data: () => ({
    tags: ["mango", "apple", "orange", "pear", "grape"],
  }),
};
</script>

We put the v-chip components in the v-chip-group component.

Mandatory

We can add the mandatory prop so that there’s a value selected.

For example, we can write:

<template>
  <v-container class="grey lighten-5">
    <v-row>
      <v-col>
        <v-sheet elevation="10" class="py-4 px-1">
          <v-chip-group mandatory active-class="primary--text">
            <v-chip v-for="tag in tags" :key="tag">{{ tag }}</v-chip>
          </v-chip-group>
        </v-sheet>
      </v-col>
    </v-row>
  </v-container>
</template>
<script>
export default {
  name: "HelloWorld",
  data: () => ({
    tags: ["mango", "apple", "orange", "pear", "grape"],
  }),
};
</script>

We put the mandatory prop on the v-chip-group component.

Multiple

The multiple prop lets us select multiple chips.

For instance, we can write:

<template>
  <v-container class="grey lighten-5">
    <v-row>
      <v-col>
        <v-sheet elevation="10" class="py-4 px-1">
          <v-chip-group multiple active-class="primary--text">
            <v-chip v-for="tag in tags" :key="tag">{{ tag }}</v-chip>
          </v-chip-group>
        </v-sheet>
      </v-col>
    </v-row>
  </v-container>
</template>
<script>
export default {
  name: "HelloWorld",
  data: () => ({
    tags: ["mango", "apple", "orange", "pear", "grape"],
  }),
};
</script>

then we can select multiple chips.

Filter Results

Chips can have additional feedback with the filter prop.

For example, we can write:

<template>
  <v-container class="grey lighten-5">
    <v-row>
      <v-col>
        <v-card class="mx-auto" max-width="400">
          <v-card-text>
            <h2 class="title mb-2">Choose fruits</h2>

            <v-chip-group v-model="fruits" column multiple>
              <v-chip filter outlined>apple</v-chip>
              <v-chip filter outlined>orange</v-chip>
              <v-chip filter outlined>grape</v-chip>
            </v-chip-group>
          </v-card-text>
        </v-card>
      </v-col>
    </v-row>
  </v-container>
</template>
<script>
export default {
  name: "HelloWorld",
  data: () => ({
    fruits: [],
  }),
};
</script>

to add chips that show a checkmark when it’s chosen.

v-model will bind the selected items to the model.

filter is what makes the checkmark shown.

outlined makes the chip displayed with a white background when it’s not selected.

Conclusion

We can add chip groups to show a group of chips that we can select.

Categories
Vuetify

Vuetify — Button Groups

Vuetify is a popular UI framework for Vue apps.

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

Button Groups

The v-btn-toggle component is a wrapper for v-item-group that works with v-btn components.

We can use it to add a group of buttons that can be toggled.

For example, we can write:

<template>
  <v-container class="grey lighten-5">
    <v-row>
      <v-col>
        <v-card flat class="py-12">
          <v-card-text>
            <v-row align="center" justify="center">
              <v-btn-toggle v-model="toggle" rounded>
                <v-btn>
                  <v-icon>mdi-format-align-left</v-icon>
                </v-btn>
                <v-btn>
                  <v-icon>mdi-format-align-center</v-icon>
                </v-btn>
                <v-btn>
                  <v-icon>mdi-format-align-right</v-icon>
                </v-btn>
                <v-btn>
                  <v-icon>mdi-format-align-justify</v-icon>
                </v-btn>
              </v-btn-toggle>
            </v-row>
          </v-card-text>
        </v-card>
      </v-col>
    </v-row>
  </v-container>
</template>
<script>
export default {
  name: "HelloWorld",
  data: () => ({
    toggle: undefined,
  }),
};
</script>

to add a button group with the v-btn-toggle component.

We just put the v-btn components inside the group.

The rounded prop makes the button group round.

Mandatory Button Groups

The mandatory prop makes the v-btn-toggle always has a value.

For example, we can write:

<template>
  <v-container class="grey lighten-5">
    <v-row>
      <v-col>
        <v-card flat class="py-12">
          <v-card-text>
            <v-row align="center" justify="center">

            <v-btn-toggle v-model="toggle" multiple>
                <v-btn>
                  <v-icon>mdi-format-align-left</v-icon>
                </v-btn>
                <v-btn>
                  <v-icon>mdi-format-align-center</v-icon>
                </v-btn>
                <v-btn>
                  <v-icon>mdi-format-align-right</v-icon>
                </v-btn>
                <v-btn>
                  <v-icon>mdi-format-align-justify</v-icon>
                </v-btn>
              </v-btn-toggle>

              <v-col cols="12" class="text-center">{{ toggle }}</v-col>
            </v-row>
          </v-card-text>
        </v-card>
      </v-col>
    </v-row>
  </v-container>
</template>
<script>
export default {
  name: "HelloWorld",
  data: () => ({
    toggle: []
  }),
};
</script>

The multiple prop lets us make multiple selections.

When we click on a button, the index of it will be added to the state.

Buttons in a Toolbar

We can add buttons to the v-toolbar .

For example, we can write:

<template>
  <v-container class="grey lighten-5">
    <v-row>
      <v-col>
        <v-toolbar dense>
          <v-overflow-btn :items="dropdownFont" label="Select font" hide-details class="pa-0"></v-overflow-btn>
          <template v-if="$vuetify.breakpoint.mdAndUp">
            <v-divider vertical></v-divider>
            <v-overflow-btn
              :items="dropdownEdit"
              editable
              label="Select size"
              hide-details
              class="pa-0"
              overflow
            ></v-overflow-btn>
            <v-divider vertical></v-divider>
            <v-spacer></v-spacer>
            <v-btn-toggle v-model="toggleMultiple" color="primary" dense group multiple>
              <v-btn :value="1" text>
                <v-icon>mdi-format-bold</v-icon>
              </v-btn>
              <v-btn :value="2" text>
                <v-icon>mdi-format-italic</v-icon>
              </v-btn>
              <v-btn :value="3" text>
                <v-icon>mdi-format-underline</v-icon>
              </v-btn>
            </v-btn-toggle>
            <div class="mx-4"></div>
            <v-btn-toggle v-model="toggleExclusive" color="primary" dense group>
              <v-btn :value="1" text>
                <v-icon>mdi-format-align-left</v-icon>
              </v-btn>
              <v-btn :value="2" text>
                <v-icon>mdi-format-align-center</v-icon>
              </v-btn>
              <v-btn :value="3" text>
                <v-icon>mdi-format-align-right</v-icon>
              </v-btn>
            </v-btn-toggle>
          </template>
        </v-toolbar>
      </v-col>
    </v-row>
  </v-container>
</template>
<script>
export default {
  name: "HelloWorld",
  data: () => ({
    dropdownFont: [
      { text: "Arial" },
      { text: "Calibri" },
      { text: "Courier" },
      { text: "Verdana" },
    ],
    dropdownEdit: [
      { text: "100%" },
      { text: "75%" },
      { text: "50%" },
      { text: "25%" },
      { text: "0%" },
    ],
    toggleExclusive: 2,
    toggleMultiple: [1, 2, 3],
  }),
};
</script>

We have the v-toolbar with the v-overflow-btn components to add the dropdowns.

And we add the v-divider to add the dividers to our toolbar.

v-btn-toggle lets us add the button toggles.

Also, we added the dense prop to make the toolbar smaller.

Conclusion

We can add button groups to toolbars and more with Vuetify.

Categories
Vuetify

Vuetify — Column Spacing and Ordering

Vuetify is a popular UI framework for Vue apps.

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

Order Last or First

We can set the order prop to last and first to set the columns to last and first.

For example, we can write:

<template>  
  <v-container class="grey lighten-5">  
    <v-row no-gutters>  
      <v-col order="last">  
        <v-card class="pa-2" outlined tile>First, but last</v-card>  
      </v-col>  
      <v-col>  
        <v-card class="pa-2" outlined tile>Second, but unordered</v-card>  
      </v-col>  
      <v-col order="first">  
        <v-card class="pa-2" outlined tile>Third, but first</v-card>  
      </v-col>  
    </v-row>  
  </v-container>  
</template>  
<script>  
export default {  
  name: "HelloWorld",  
  data: () => ({}),  
};  
</script>

Offset

We can use the offset props to add spaces between columns.

For example, we can write:

<template>  
  <v-container class="grey lighten-5">  
    <v-row class="mb-6" no-gutters>  
      <v-col md="4">  
        <v-card class="pa-2" outlined tile>.col-md-4</v-card>  
      </v-col>  
      <v-col md="2" offset-md="6">  
        <v-card class="pa-2" outlined tile>.col-md-2 .offset-md-6</v-card>  
      </v-col>  
    </v-row>  
  </v-container>  
</template>  
<script>  
export default {  
  name: "HelloWorld",  
  data: () => ({}),  
};  
</script>

We have the offset-md prop to set the number of columns between this and the div before it when the md breakpoint is hit.

Margin Utilities

We can add padding and margin to columns.

For example, we can write:

<template>  
  <v-container class="grey lighten-5">  
    <v-row>  
      <v-col md="4">  
        <v-card class="pa-2" outlined tile>.col-md-4</v-card>  
      </v-col>  
      <v-col md="4" class="ml-auto">  
        <v-card class="pa-2" outlined tile>.col-md-4 .ml-auto</v-card>  
      </v-col>  
    </v-row>  
  </v-container>  
</template>  
<script>  
export default {  
  name: "HelloWorld",  
  data: () => ({}),  
};  
</script>

The pa-2 class adds padding around the classes.

ml-auto adds margin between the v-col components.

Nested Grid

We can create a grid that’s nested in a parent grid.

For instance, we can write:

<template>  
  <v-container class="grey lighten-5">  
    <v-row>  
      <v-col sm="9">  
        <v-card class="pa-2" outlined tile>Level 1</v-card>  
        <v-row no-gutters>  
          <v-col cols="8" sm="6">  
            <v-card class="pa-2" outlined style="background-color: lightgrey;" tile>Level 2</v-card>  
          </v-col>  
          <v-col cols="4" sm="6">  
            <v-card class="pa-2" outlined style="background-color: lightgrey;" tile>Level 3</v-card>  
          </v-col>  
        </v-row>  
      </v-col>  
    </v-row>  
  </v-container>  
</template>  
<script>  
export default {  
  name: "HelloWorld",  
  data: () => ({}),  
};  
</script>

And we have v-row s inside v-col s to nest them.

Spacers

The v-spacer component is useful when we fill available space or make space between 2 components.

For example, we can write:

<template>  
  <v-container class="grey lighten-5">  
    <v-row>  
      <v-col>  
        <v-card class="pa-2" outlined tile>.col</v-card>  
      </v-col>  
      <v-spacer></v-spacer>  
      <v-col>  
        <v-card class="pa-2" outlined tile>.col</v-card>  
      </v-col>  
      <v-spacer></v-spacer>  
      <v-col>  
        <v-card class="pa-2" outlined tile>.col</v-card>  
      </v-col>  
    </v-row>  
  </v-container>  
</template>  
<script>  
export default {  
  name: "HelloWorld",  
  data: () => ({}),  
};  
</script>

to add the v-spacer component to space out the v-col s evenly.

Conclusion

We can order columns and space them out the way we like with various props.

Categories
Vuetify

Vuetify — Text Fields

Vuetify is a popular UI framework for Vue apps.

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

Text Field

We can add text fields to accept user input.

For example, we can write:

<template>  
  <v-container>  
    <v-row>  
      <v-col col="12">  
        <v-text-field label="Regular" single-line></v-text-field>  
      </v-col>  
      <v-col col="12">  
        <v-text-field label="Solo" single-line solo></v-text-field>  
      </v-col>  
    </v-row>  
  </v-container>  
</template>  
<script>  
export default {  
  name: "HelloWorld",  
  data: () => ({}),  
};  
</script>

We have the single-line prop to make the text field display as a single line.

The solo prop makes the input display as the box.

There’s also the outlined prop to display an input with an outline.

Shaped Text Input

The shaped text fields are rounded if the outlined prop is applied.

For example, we can write:

<template>  
  <v-container>  
    <v-row>  
      <v-col col="12">  
        <v-text-field v-model="first" label="First Name" outlined shaped></v-text-field>  
      </v-col>  
    </v-row>  
  </v-container>  
</template>  
<script>  
export default {  
  name: "HelloWorld",  
  data: () => ({  
    first: "",  
  }),  
};  
</script>

The outlined and shaped props together will make the text field displayed with the top 2 corners rounded.

Disabled and Readonly Text Fields

Text fields can also be disabled and readonly .

For example, we can write:

<template>  
  <v-container>  
    <v-row>  
      <v-col col="12">  
        <v-text-field v-model="first" label="First Name" disabled></v-text-field>  
      </v-col>  
    </v-row>  
  </v-container>  
</template>  
<script>  
export default {  
  name: "HelloWorld",  
  data: () => ({  
    first: "",  
  }),  
};  
</script>

or:

<template>  
  <v-container>  
    <v-row>  
      <v-col col="12">  
        <v-text-field v-model="first" label="First Name" readonly></v-text-field>  
      </v-col>  
    </v-row>  
  </v-container>  
</template>  
<script>  
export default {  
  name: "HelloWorld",  
  data: () => ({  
    first: "",  
  }),  
};  
</script>

Both props make the input inactive.

But readonly won’t change the styles.

Dense

The dense prop makes the text input shorter than the default size.

So we can write:

<template>  
  <v-container>  
    <v-row>  
      <v-col col="12">  
        <v-text-field dense label="Regular"></v-text-field>  
      </v-col>  
    </v-row>  
  </v-container>  
</template>  
<script>  
export default {  
  name: "HelloWorld",  
  data: () => ({  
    first: "",  
  }),  
};  
</script>

Icons

We can add icons with the prepend-icon , append-icon , and append-outer-icon props.

For instance, we can write:

<template>  
  <v-container>  
    <v-row>  
      <v-col col="12">  
        <v-text-field label="Prepend" prepend-icon="mdi-map-marker"></v-text-field>  
      </v-col>  
    </v-row>  
  </v-container>  
</template>  
<script>  
export default {  
  name: "HelloWorld",  
  data: () => ({}),  
};  
</script>

or:

<template>  
  <v-container>  
    <v-row>  
      <v-col col="12">  
        <v-text-field label="Append" append-icon="mdi-map-marker"></v-text-field>  
      </v-col>  
    </v-row>  
  </v-container>  
</template>  
<script>  
export default {  
  name: "HelloWorld",  
  data: () => ({}),  
};  
</script>

or:

<template>  
  <v-container>  
    <v-row>  
      <v-col col="12">  
        <v-text-field label="Append Outer" append-outer-icon="mdi-map-marker"></v-text-field>  
      </v-col>  
    </v-row>  
  </v-container>  
</template>  
<script>  
export default {  
  name: "HelloWorld",  
  data: () => ({}),  
};  
</script>

We set the props so that we can add the icons.

prepend-icon and append-icon adds the icon inside the line.

And append-outer-icon adds the icon outside the line.

Conclusion

We can add text fields with icons and make them read only.

Categories
Vuetify

Vuetify — Text Areas

Vuetify is a popular UI framework for Vue apps.

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

Text Areas

We can add text areas to collect large amounts of text data.

To add it, we can use the v-textarea component.

For example, we can write:

<template>
  <v-container>
    <v-row>
      <v-col col="12">
        <v-textarea class="mx-2" label="prepend-icon" rows="1" prepend-icon="mdi-comment"></v-textarea>
      </v-col>
    </v-row>
  </v-container>
</template>
<script>
export default {
  name: "HelloWorld",
  data: () => ({}),
};
</script>

We add the prepend-icon prop to add an icon to the left of the text area.

rows is the number of rows to display.

To add an icon to the right, we use the append-icon prop.

There’s also the prepend-inner-icon to add the icon within the line of the text area.

For example, we can write:

<template>
  <v-container>
    <v-row>
      <v-col col="12">
        <v-textarea
          class="mx-2"
          label="prepend-inner-icon"
          rows="1"
          prepend-inner-icon="mdi-comment"
        ></v-textarea>
      </v-col>
    </v-row>
  </v-container>
</template>
<script>
export default {
  name: "HelloWorld",
  data: () => ({}),
};
</script>

Auto Grow

We can use the auto-grow prop to create a text area that increases in size with the text.

For instance, we can write:

<template>
  <v-container>
    <v-row>
      <v-col col="12">
        <v-textarea
          name="input-7-1"
          filled
          label="Label"
          auto-grow
          value="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus massa sapien, rutrum vitae luctus sit amet."
        ></v-textarea>
      </v-col>
    </v-row>
  </v-container>
</template>
<script>
export default {
  name: "HelloWorld",
  data: () => ({}),
};
</script>

We add the auto-grow prop to make the text area always show all the text without scrolling.

Background Color

The background-color and color props can be used to change the background color and the text color respectively.

For example, we can write:

<template>
  <v-container>
    <v-row>
      <v-col col="12">
        <v-textarea background-color="light-blue" color="black" label="Label"></v-textarea>
      </v-col>
    </v-row>
  </v-container>
</template>
<script>
export default {
  name: "HelloWorld",
  data: () => ({}),
};
</script>

to set the colors.

Browser Autocomplete

We can set the autocomplete prop to enable the browser to predict user input:

<template>
  <v-container>
    <v-row>
      <v-col col="12">
        <v-textarea autocomplete="email" label="Email"></v-textarea>
      </v-col>
    </v-row>
  </v-container>
</template>
<script>
export default {
  name: "HelloWorld",
  data: () => ({}),
};
</script>

Clearable Text Area

The clearable prop makes the text area clearable.

The icon for clearing the text can be changed with the clearable-icon prop.

So we can write:

<template>
  <v-container>
    <v-row>
      <v-col col="12">
        <v-textarea clearable clear-icon="mdi-cancel" label="Text" value="Clearable text."></v-textarea>
      </v-col>
    </v-row>
  </v-container>
</template>
<script>
export default {
  name: "HelloWorld",
  data: () => ({}),
};
</script>

We clear the text area by clicking on the clear-icon .

Counter

The counter prop shows the user the character limit for the v-textarea :

<template>
  <v-container>
    <v-row>
      <v-col col="12">
        <v-textarea counter label="Text" :rules="rules" :value="value"></v-textarea>
      </v-col>
    </v-row>
  </v-container>
</template>
<script>
export default {
  name: "HelloWorld",
  data: () => ({
    rules: [(v) => v.length <= 25 || "Max 25 characters"],
    value: "foo bar",
  }),
};
</script>

The counter prop lets us show the character count.

Conclusion

We can add text areas with various things to display with Vuetify.