Tablet Dashboard with Tailwind CSS and Livewire

Joey Antonisse
2 min readMar 1, 2021

That tablet that was always lying around, I had to do something with it. Obviously the result is a dashboard, but that kind of took a while. I tried multiple Dashboard templates, but that wasn’t it. So, I decided to built it from the ground up. The result is a neat looking Dashboard, find the demo here.

For the frontend I used TailwindCSS; A relative new CSS framework that allows you to create websites without writing a single line of CSS. The only downside; long class attributes in the HTML. The code snippet below is from the clock at the top.

tailwindcss class example

The dashboard needs to get the metrics automagically, but we need something fancy. What about, only update the parts of the website that needs updating; introducing Livewire. The dashboard emits an event so that Livewire does a post request to the server, and retrieves the new View component, where this is intelligently updated into the window.

Adding cards needs to be a walk in the park, so I created a constructor that has access to all the cards classes (yes each card is separated into its own class) . The array $metrics holds all the cards, and $ current_metric remembers which card we are displaying right now.

Metric class with attributes

Of course the metric cards needs to abide by some rules, written in the abstract class that all cards extend. The four functions are all the values needed for the card.

Abstract class with function definitions

And voilá, we have a dynamic Dashboard, adding and removing cards is as easy as adding it to the array! The only thing that remains is finding some good API endpoints, news, info, data?

Tablet Dashboard result

Thank you for reading, and have a nice day!

Originally published at https://joeyantonisse.nl on March 1, 2021.

--

--