Let’s code a dribble design with Vue.js & Tailwindcss (Working demo) — Part 1 of 2
Tags: vue, webdev, design, javascript
Published: 2020-04-24 06:09:06

---
title: Let’s code a dribble design with Vue.js & Tailwindcss (Working demo) — Part 1 of 2
published: true
date: 2020-04-24 05:57:05 UTC
tags: vuejs,webdev,design,javascript
canonical_url: https://medium.com/@fayazara/lets-code-a-dribble-design-with-vue-js-tailwindcss-working-demo-part-1-of-2-20fbf0e74c5f
cover_image: https://cdn-images-1.medium.com/max/1024/1*RjPARbM2O7QLIePBEi4HKw.png
---

### Let’s code a dribble design with Vue.js & Tailwindcss (Working demo) — Part 1 of 2

>Article #5 of my “1 article a day till lockdown ends”

Update: here's [part 2](https://dev.to/fayazara/let-s-code-a-dribble-design-with-vue-js-tailwindcss-working-demo-part-1-of-2-3h9)

Lets pick a small design from dribble and code it with Vue.js& tailwindcss, you will find out how Vue’s two way binding works and how tailwind lets you make beautiful apps while being completely flexible and without writing any css manually.

Let’s pick a design which is easy to implement so that it wont make the article too long and is also intuitive, fun and looks beautiful. I found this design which calculates BMI by letting you select your gender, height, weight & age.

![](https://cdn-images-1.medium.com/max/800/0*tQ7aMgg6_TMGmmpD.png)<figcaption>Simple BMI calculator by <a href="https://dribbble.com/shots/4585382-Simple-BMI-Calculator">Rubel Vaalt</a></figcaption>

I will make use of [Nuxt.js](https://nuxtjs.org/) which is a framework for [Vue](https://vuejs.org/) & [tailwindcss](https://tailwindcss.com/).

#### Why Vue & Nuxt?

[Vue.js](https://vuejs.org/) is a progressive framework which lets you makes web apps fast and quickly, it has two way binding and makes use of single file components which will let you make custom html tags like<gender /> or <height-slider /> etc, it let’s you divide your html markup into smaller blocks and make your code cleaner, readable and more maintainable. [Nuxt](https://nuxtjs.org/) is a framework for a vue. Why do we need a framework for a framework, as Nuxt handles at lot of real world use cases for websites, out the box which are practical, where you will end up writing lesser boilerplate code if you had chosen vue. You can still choose vue if you want to, I just like Nuxt better because of its routing and folder structure.

#### Why Tailwindcss?

[Tailwindcss](https://tailwindcss.com/) is a CSS framework with only low level css classes, it provides all the feature of a full fledged CSS framework and yet still provide all the flexibility and freedom CSS provides you, it’s not opinionated and won’t force you to write CSS in a restricted way, like a traditional framework would (Bootstrap), in simpler terms there’s a class form **_almost_** every single css rule (which you use most of the time). Technically this would mean it’s a very huge framework, which it is, but purgeCss comes to the rescue, it will remove all excess classes and only keeps whats used in your HTML (Nuxt.js has purgeCSS built in, so you don’t have to do it manually)

#### Step 1: Let’s create a Nuxt project and select TailwindCSS as our UI Framework.

![](https://cdn-images-1.medium.com/max/796/1*kXk0Jfnrsl_06VZSm7pP6Q.png)<figcaption>Creating a Nuxtjs project with Tailwindcss</figcaption>

Once done, open the project in your favourite code editor, I prefer VS Code. you can start the project in development mode by running the command npm run dev where you will be greeted with a template. Remove all the code from pages/index.vue and remove the css from layouts/default.vue. The layouts/default.vue will act as the entry point of your project, here all the route content will be shown dynamically & your routes will be defined in the pages folder, each .vue file inside the pages folder means a webpage, and the route will be the file name. You can find more about the nuxt routing [here](https://nuxtjs.org/guide/routing/) and a free udemy [course](https://vueschool.io/courses/nuxtjs-fundamentals) entire dedicated to nuxt.js.

We will be having two page in the app, one is the calculator which will be shown as soon as the site is opened and one would be the result page, we already have a index.vue file for it in pages folder, add another called result.vue this will add a new route to our project like example.com/result.

That’s how easy it is to create routes in nuxt.js.The project structure below.

![](https://cdn-images-1.medium.com/max/1024/1*XwVWWeg8UENlb-jk-oNkNA.png)<figcaption>Basic Project structure for app</figcaption>

Start the project by running npm run dev and open localhost:3000 in your browser and see “The Home Page” text which is our index.vue rendered, try opening localhost:3000/result you will see “The Result Page”, the result.vue page rendered.

The default.vue will be rendering these routes inside inside <nuxt /> component. If you want any component to be shown in both routes, you can just add them in default.vue it will be automatically shown, instead of repeating the code in both pages, it’s great for n_avbar_, _navigation drawers_, _back top buttons_ etc.

#### Step 2: Let’s code the calculator/index/home page.

We will begin by dividing the code into different components

![](https://cdn-images-1.medium.com/max/1024/1*b6WCjdaIf3wIby3wFNMaqA.png)<figcaption>Components</figcaption>

So we have 4 different components here.The Navigation Bar which will be shown in boh the index page and the result page, so we can just include it once in layout/default.vue. The other three components will be shown in the index/calculator page. Here’s the folder structure I always follow to keep the code clean and readable.

![](https://cdn-images-1.medium.com/max/1024/1*6YJp1l-TJSIfoD5g8bNO-w.png)

#### Step 3: Code the components

- The entire app has a dark them, so let’s apply the bg-gray-900 class to our top most div, which is is layouts/default.vue.
- Make the Navigation bar. It has one div with a icon and some text in the center, with a thich box shadow, we will use css flex to align the content and the shadow classes of tailwindcss. The below HTML code generates the navbar for us

{% gist https://gist.github.com/fayazara/d8f96b258de79a33a5755bcb8bc289e0 %}

![](https://cdn-images-1.medium.com/max/507/1*6HriJmvlrpb9-L0w6n4-IQ.png)<figcaption>Icon used from <a href="https://heroicons.dev/">Heroicons</a></figcaption>

So the above code generate this navbar with zero custom css written. Basically we have a parent div with with two children, a div with a svg icon and a paragrarh tag with some text. I applied flex & items-center to it to divide them on the same line and vertically aligning them in center with items-center.

I will be adding the navbar component in our layouts/default.vue file so that its available in both routes.

![](https://cdn-images-1.medium.com/max/882/1*loViqM1vy2AEzxHSSm9O2w.png)<figcaption>Navbar code being imported in default.vue file</figcaption>

- The Gender component has two divs, we will make use of css grid, it’s not necessary to make use of css grid, this can be easily achievable with other ways too, just wanted explain tailwindcss features for you.

Here’s how CSS Grid works in tailwindcss, more on it [here](https://tailwindcss.com/docs/grid-template-columns/#app).

{% gist https://gist.github.com/fayazara/8804822278a2107645aca50e78cb5052 %}

![](https://cdn-images-1.medium.com/max/407/1*OD_ikV-FZkLJHBw028PyDg.png)<figcaption>Gnder card grid with tailwindcss</figcaption>

The above code generates this layout, its simple and is responsive with tailwinds responsive helpers, the grid-cols-2 is specifying that we our layout will have two columns and there’s a gap of 4 units between then, no more margin hacks with columns.

{% gist https://gist.github.com/fayazara/14161860d2952121db678b8de92ff319 %}

![](https://cdn-images-1.medium.com/max/400/1*sKY2wntVL8q2kzTXp-WhPQ.png)<figcaption>Gender component</figcaption>

Let’s pick the gender icons from [flaticon](http://flaticon.com) and add them inside these cards. This is how it will end up looking. I have added a little opacity to the non selected card with class opacity-75 to hightlight the other one.

Looks good, now let’s design the Height component. I have used a html range slider with some custom css because tailwindcss does not allow customising at this level, I made a small image to act as the slider button, because it had a border radius with opacity which we cannot do with css, yet.

{% gist https://gist.github.com/fayazara/766836575926fec554baf5a270eae15f %}

![](https://cdn-images-1.medium.com/max/398/1*LOvP-hcb37Fh3eOiGPg6qw.png)

We now have end up with this design in our code, matches the design, though not pixel to pixel, I am still happy with the result. I have added a v-model directive to capture the range slider value whenever a user slides it and used string interpolation to display the value on top of it `{{height}}`, that’s a good example of how two way binding works.

Similar to the gender component with two equal divs, lets make a component to get the user’s age and weight.

{% gist https://gist.github.com/fayazara/0c6190f606390e448e3cbdec0034d105 %}

![](https://cdn-images-1.medium.com/max/397/1*b4fasvAwiKkROkpwinys0Q.png)

So far we have achievedmakign most of the calculator part, all that’s left to add in the markup is a button at the bottom.

We will add a fixed button at the bottom which will calculate, and display the result in the second page, where we will make use of events emitted from our components and getting captured in the parent.

This is how the index.vue page will look at the end. I have also added a button at the bottom, which finishes coding the first page. It’s not pixel perfect but we have made good progress. Here is the code [commited](https://github.com/fayazara/bmi-calculator-example) so far (I might update it soon once the project is completed) and a[live demo ](https://bmi-app.netlify.app/).

![](https://cdn-images-1.medium.com/max/1024/1*lQlFbaGGVr-C_ydS8B9Bkw.png)

This article has become long enough hence I will break it in two parts and publish the part 2 later today.

Hope you enjoyed. You can follow me on [twitter](https://twitter.com/fayazara) to get updated on part 2 as I will keep posting about my series over there.

Let me know if you need any help or have suggestions on this.

> PS, A very happy Ramadan to everyone. Peace!