Home / Blog / Why Use Shadcn Vue? Key Advantages for Your Next Project
Why Use Shadcn Vue? Key Advantages for Your Next Project

Why Use Shadcn Vue? Key Advantages for Your Next Project

Mostafa Said
Mostafa Said
September 23rd 2024

Shadcn Vue is a powerful and highly customizable UI component library built specifically for Vue.js. It offers a straightforward way to integrate accessible, customizable, and ready-to-use components into your Vue.js projects, enhancing both development speed and user experience. In this article, we’ll explore what Shadcn Vue is, its origins, how to integrate it into Vue apps, and most importantly, why it might be the perfect fit for your next project.

What is Shadcn Vue?

A dashboard created using Shadcn-Vue

Shadcn-Vue is a Vue.js adaptation of the popular Shadcn UI project, originally designed for React. While the original project was built for React, the Vue community saw its potential and adapted it for Vue.js. It delivers pre-built, highly customizable UI components that align with modern design systems, such as Radix UI, and offers support for technologies like Vue.js, TypeScript, and TailwindCSS. These components follow accessibility best practices and can be easily customized to suit the specific needs of your project.

Why Shadcn Vue?

Shadcn-Vue operates like a component factory, generating ready-to-use components into your projects with just a few commands. It's more than just a collection of static, styled components—it gives you full control over functionality, allowing you to fine-tune styles, behaviors, and interactions to fit your project’s specific needs. It’s like having a toolbox that adapts to whatever task you’re working on, saving you time while maintaining flexibility.

At VueSchool, we relied heavily on Shadcn-Vue in our Vue.js Master Class 2024 Edition course. The ability to drop in components without spending hours on layout and UI design allowed us to dive straight into the core application logic. This efficiency enabled faster development cycles, giving us the freedom to focus on what truly matters—building robust, feature-rich applications, rather than getting bogged down with boilerplate UI work.

Getting started with Shadcn Vue

Shadcn Vue fits naturally into Vue.js applications due to its component-based structure. You can easily grab the components from Shadcn-Vue, add them to your Vue components, and customize them using TailwindCSS. Here’s how to get started:

Let’s say you created a new Vue 3 project using the following command

npm create vue@latest

This command will scaffold a new Vue 3 project based on Vite.

Next, install tailwindcss and autoprefixer .

npm install -D tailwindcss autoprefixer

This command adds the TailwindCSS module to your Vue.js project.

The next step is to add tailwind and autoprefixer plugins to the css.postcss.plugins array in the vite.config.ts file. Also, make sure to set @ as the alias for the ./src directory.

import { fileURLToPath, URL } from 'node:url'
import tailwind from 'tailwindcss'
import autoprefixer from 'autoprefixer'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

export default defineConfig({
  plugins: [vue()],
  css: {
    postcss: {
      plugins: [tailwind(), autoprefixer()]
    }
  },
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  }
})

Then, delete the default Vite stylesheet that you probably have when you scaffolded a new Vue app ./src/style.css .

And Now, it’s time to get our Shadcn-Vue component machine started. Run the following command in the terminal:

npx shadcn-vue@latest init

During the CLI setup, you’ll be prompted to answer several questions to configure components.json. Here’s a typical setup:

Would you like to use TypeScript (recommended)? yes
Which framework are you using? Nuxt
Which style would you like to use? Default
Which color would you like to use as base color? Slate
Where is your tsconfig.json or jsconfig.json file? ./tsconfig.json
Where is your global CSS file? src/index.css
Do you want to use CSS variables for colors? yes
Where is your tailwind.config.js located? tailwind.config.js
Configure the import alias for components: @/components
Configure the import alias for utils: @/lib/utils
Write configuration to components.json. Proceed? Y

These settings ensure that your components and styles are correctly configured for use in your Vue.js project.

At this phase, Shadcn-Vue has created a new CSS file for you located at ./assets/index.css. Import that file in your src/main.ts file.

import './assets/index.css'

//..

That’s it! You can now selectively integrate any component into your project with ease. Just run a simple command, and voilà! The component is seamlessly added, ready for customization and use. For example, if you want to grab the Avatar component from Shadcn-Vue, you can run the following command:

npx shadcn-vue@latest add avatar

This command will add the Avatar component to your project’s src/components/ui directory. Then, you can easily import it and use it in your components.

<script setup lang="ts">
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar'
</script>

<template>
  <Avatar>
    <AvatarImage src="https://github.com/radix-vue.png" alt="@radix-vue" />
    <AvatarFallback>CN</AvatarFallback>
  </Avatar>
</template>

Key Advantages of Shadcn Vue

As for the advantages of Shadcn-Vue, they are a lot! Here are some of the key advantages:

1. Customizable and Themeable

Shadcn Vue components come with a flexible design system that allows you to tailor the look and feel to match your project’s branding or style guide. For instance, you can easily customize components using pre-configured props

<template>
  <Avatar size="lg" shape="square">
    <AvatarImage src="https://github.com/radix-vue.png" alt="@radix-vue" />
    <AvatarFallback>CN</AvatarFallback>
  </Avatar>
</template>

By passing those props, you’ll tweak the default appearance for the component

Variation of the Shadcn-Vue’s Avatar component

You can also control the theme of your Shadcn Vue components across the entire app.

2. Accessibility First

All Shadcn Vue components are designed to meet accessibility standards right out of the box. These components leverage the best practices in web accessibility (ARIA guidelines, keyboard navigability, etc.), making it easier to build web apps that cater to a wide range of users.

3. Reusable Components for Faster Development

Shadcn Vue offers a broad range of reusable components like buttons, modals, forms, and tables, all designed with consistency and flexibility in mind. This allows you to focus on building core business logic instead of spending time on repetitive UI tasks. Each component is built to be modular, which means you can import and use only the components you need without adding unnecessary bloat to your project.

Conclusion

Shadcn Vue offers a modern, flexible, and highly customizable way to build stunning UIs in Vue.js applications. Its ease of integration, accessibility focus, and compatibility with TailwindCSS make it an excellent choice for both small and large projects. By using Shadcn Vue, you can reduce development time while maintaining a high standard of design and usability.

For more details and advanced usage, you can refer to the official Shadcn Vue documentation.

Start learning Vue.js for free

Mostafa Said
Mostafa Said
With over 7 years of e-learning expertise honed at major companies like Vodafone Intelligent Solutions (_VOIS), Mostafa is full-time instructor at Vue School and a full-stack developer in the wild. He built and maintained dozens of apps using Vue, Nuxt, Laravel, Tailwind, and more. He merges modern teaching methods with coding education to empower aspiring developers of all experience levels. When he's not glued to the code editor, hackathons fuel his competitive spirit, with Deepgram and Appwrite grand prizes under his belt.

Comments

Latest Vue School Articles

Vue Language Tools: Volar, TypeScript, and the Official VSCode Extension

Vue Language Tools: Volar, TypeScript, and the Official VSCode Extension

Discover how Vue.js Language Tools, powered by Volar, revolutionize your development experience in VSCode. This comprehensive guide explores the key packages, TypeScript support, and evolution of Volar, making it a must-read for Vue developers.
Mostafa Said
Mostafa Said
10 Practical Tips for Better Vue Apps

10 Practical Tips for Better Vue Apps

Take your Vue.js skills to the next level with these 10 practical tips including: script setup, provide/inject, defineExpose, toRefs, and more
Daniel Kelly
Daniel Kelly

Our goal is to be the number one source of Vue.js knowledge for all skill levels. We offer the knowledge of our industry leaders through awesome video courses for a ridiculously low price.

More than 200.000 users have already joined us. You are welcome too!

Follow us on Social

© All rights reserved. Made with ❤️ by BitterBrains, Inc.