Categories
Quasar

Developing Vue Apps with the Quasar Library — Button Groups

Spread the love

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.

Button Group

We can add button groups to group buttons together.

For example, we can write:

<!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"
      >
        <q-btn-group push>
          <q-btn push label="First" icon="timeline"></q-btn>
          <q-btn push label="Second" icon="visibility"></q-btn>
          <q-btn push label="Third" icon="update"></q-btn>
        </q-btn-group>
      </q-layout>
    </div>
    <script>
      new Vue({
        el: "#q-app",
        data: {}
      });
    </script>
  </body>
</html>

We add the buttons inside the q-btn-group components.

push changes the design.

We must use the same design prop on both the q-btn-group and q-btn .

Also, we can spread the buttons across the screen by using the spread 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"
      >
        <q-btn-group spread>
          <q-btn color="purple" label="First" icon="timeline"></q-btn>
          <q-btn color="purple" label="Second" icon="visibility"></q-btn>
        </q-btn-group>
      </q-layout>
    </div>
    <script>
      new Vue({
        el: "#q-app",
        data: {}
      });
    </script>
  </body>
</html>

Also, we can add a dropdown beside the button by writing:

<!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"
      >
        <q-btn-group rounded>
          <q-btn rounded color="primary" label="One" ></q-btn>

          <q-btn rounded color="primary" label="Two" ></q-btn>

          <q-btn-dropdown
            auto-close
            rounded
            color="primary"
            label="Three"
            split
          >
            <q-list padding style="width: 250px;">
              <q-item clickable>
                <q-item-section avatar>
                  <q-avatar icon="folder" color="purple" text-color="white" ></q-avatar>
                </q-item-section>
                <q-item-section>
                  <q-item-label>Photos</q-item-label>
                  <q-item-label caption>February 22, 2016</q-item-label>
                </q-item-section>
                <q-item-section side>
                  <q-icon name="info" color="amber" ></q-avatar>
                </q-item-section>
              </q-item>

              <q-item clickable>
                <q-item-section avatar>
                  <q-avatar icon="folder" color="purple" text-color="white" ></q-avatar>
                </q-item-section>
                <q-item-section>
                  <q-item-label>Videos</q-item-label>
                  <q-item-label caption>London</q-item-label>
                </q-item-section>
                <q-item-section side>
                  <q-icon name="info" color="amber" ></q-icon>
                </q-item-section>
              </q-item>

              <q-separator inset ></q-separator>
              <q-item-label header>Files</q-item-label>

              <q-item clickable>
                <q-item-section avatar>
                  <q-avatar icon="assignment" color="teal" text-color="white" />
                </q-item-section>
                <q-item-section>
                  <q-item-label>London</q-item-label>
                  <q-item-label caption>March 1st, 2020</q-item-label>
                </q-item-section>
                <q-item-section side>
                  <q-icon name="info" color="amber"></q-icon>
                </q-item-section>
              </q-item>

              <q-item clickable>
                <q-item-section avatar>
                  <q-avatar
                    icon="assignment"
                    color="teal"
                    text-color="white"
                  ></q-avatar>
                </q-item-section>
                <q-item-section>
                  <q-item-label>Paris</q-item-label>
                  <q-item-label caption>January 22nd, 2020</q-item-label>
                </q-item-section>
                <q-item-section side>
                  <q-icon name="info" color="amber"></q-icon>
                </q-item-section>
              </q-item>
            </q-list>
          </q-btn-dropdown>
        </q-btn-group>
      </q-layout>
    </div>
    <script>
      new Vue({
        el: "#q-app",
        data: {}
      });
    </script>
  </body>
</html>

We add the q-btn-dropdown component to add a button with a dropdown.

And we add the q-list component to add the dropdown list.

q-separator separates the items in the list.

Conclusion

We can add button groups into our Vue app with Quasar.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *