Skip to main content
View on YouTube to comment and like!

Syntax Video

Next.js / React Tailwind Component Library Options | shadcn/ui, NextUI, HeadlessUI and more

Chapter 1 00:00

Transcript

[Music]

next up I'm going to set up a Tailwind based component library now our app is already ready to go with tailwind and if you're not familiar with Tailwind it is essentially a CSS utility library but Tailwind doesn't give us any pre-built components they essentially give us utilities we can use to build our own components and the best example of this is to kind of just look at what they show in their documentation that talks about what Tailwind is and so in a traditional CSS framework you might actually have some class names like chat notification or whatever else but if you look at the Tailwind implementation there are no class names they are just a bunch of utilities so we have P6 Max width margin Auto background white and so all of these are utility classes that are provided by Tailwind that essentially allow us to style with CSS but without having to directly specify classes inside of a CSS file now there's a lot more to Tailwind than just that essentially it's Al a design system so even though we see p-6 that's a padding of six but that doesn't mean six Rim six

is a unit in their design language so it actually means 1.5 but once you get used to their design system um it's nice and easy to use and all of your CSS is kind of scoped to where you defined the components now I'm not here to sell you on Tailwind we are going to use it and we're already using it but I want something more than just these utility classes and for that I am going to choose a component library and essentially component libraries take the building blocks of tailwind and give us reusable components so we don't have to write everything from scratch uh whenever we're using and defining components now sometimes we will if we want to customize it but it's nice to have things that come out of the box already styled so we don't have to build up button styles from scratch now one of the most popular component libraries out there is a library called Shad CN UI you've probably heard a lot about it recently especially with the launch of their CLI and integration with vzer but essentially they give you components that are ready to go you don't have to assemble all of the Tailwind classes yourself so for instance if I want to add this button to my app all I need to

do is import it and then I get a nice styled button that also supports like other variants like secondary destructive outline and um I don't have to write all the custom CSS for that but the thing about Shad Cen is all these components are very minimally styled and so I would say Shad CN is a really good choice if you have your own design system or branding in mind where you want to take these base components and highly customize them to fit your specific look in style of the kind of website that you're building uh but they provide a really good base and the interesting thing about Shaden also one of the controversial things about it is you aren't actually installing the library they have a CLI tool that literally copy pastes the component code into your application so if you look at this manual tab here literally this is all of the code required for this button component and this file will live inside of your code base but because you have direct access to the source code you can modify it and customize it to your heart content so that's what Shaden is really good for essentially they give you the

base Styles and base components that you would then further customize within your app and again every single one of these components if you bring it into your application that source code is going to be living inside of your application it's not an mpm dependency definitely take a look at their introduction they have an FAQ that talks about all those things uh but for me specifically a lot of the apps that I build I'm not designing all of the styles from scratch a lot of times I'm building like a quick prototype or I'm just trying to get some internal tool ready to go and I don't necessarily need highly custom Styles and because of that I'm actually going to choose a library called Next UI now this actually has no relation to nextjs it's just called Next UI but it's a component Library based on top of Tailwind that has some default Styles so if we take a look at these buttons they're a little bit more stylized right they don't look as plain as like the shadan ones and essentially if you pull these components into your app you're basically saying your app's going to look like this maybe with a few slight modifications because of course you can always customize the styles by adding new Tailwind classes but these give you good styles by default like if we look

at the card component we can see a lot of like highly stylized elements that are pretty much built in and ready to go now this library is installed as an mpm dependency and whenever you need to use one of their components you're actually importing from nexi org um but of course you actually don't have any way to modify the source code of this button component the only way to customize it would be through like the props that they make available and then of course you can always pass down custom CSS classes and if you take a look at their section here called called overriding Styles they talk about basically the mechanisms they provide for customizing it but because you don't have direct access to the source code for it sometimes your customizations might be limited and for the apps that I'm building that's completely fine most of the time I'm just going to be using the default Styles provided by these components but it's really great that I don't have to add any of my own Tailwind CSS classes for most situations I can literally just import the component in and it looks good by default I might add some maybe like padding or margin or layout styles to customize my app

further but the base styles of all these components are essentially what I'm going to be using and this is how my application is going to look when I choose these components now a few other popular libraries you should take a look at are headless UI headless UI is very similar to Shaden and that they are completely unstyled they're very like minimal generic Styles and essentially these are more interactive components that need some JavaScript behind the scenes and if you take a look at them you actually do import directly from the installed library and they give you these reusable components but they're completely unstyled and you can look at their docs for further styling them and like I said they actually don't provide a ton of components cuz they're ultimately providing some of the JavaScript functionality you might need for more interactive components because if you are building out your Styles completely from scratch you wouldn't necessarily want to implement all of the functionalities of these types of components from scratch yourself These are nice CU you get some base functionality and then you can further customize the Styles and and move on from there uh but there aren't a lot of components included because it's expected that you're likely going to be styling all of the other things yourself

from scratch with Tailwind now the last two I'll point you to are flow bite react and Daisy UI give them all a try and pick the one that you like the most but specifically for my starter kit I'm going to be using next UI I have been testing out all of these libraries and this is the one that I like the most it has most of the components that I need the Styles look good by default it's customizable in the way that I want to and it works really well with react server components so this is one of the other aspects of choosing one of these component libraries is if they are have not been updated or they're not aware of this idea of server and client components it might make it so that anytime you want to use one of their components you literally have to only import it inside of a client component and that gets really cumbersome especially if you just want to like show a button inside of a server component for like flowy and Daisy UI these haven't been updated yet to support react server components so any component you want to use has to be inside of a client component but that is not the case with next UI you can actually use these components inside of server components and all of their components

have the ability to be serers side rendered now there probably a lot of other libraries based on tawin that give you react components that I didn't mention and maybe I don't even know about let me know down in the comments if you know of a library that you like to use that's based on tailwind and gives you react components but for my starter kit I'm going to be using next UI so that's what we're going to set up in the next section of this video so to get started with next UI we'll head to their documentation and they have an installation section [Music]

Quote it with credit and a link. Quoting Syntax