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.
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.
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.
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>
As for the advantages of Shadcn-Vue, they are a lot! Here are some of the key advantages:
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
You can also control the theme of your Shadcn Vue components across the entire app.
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.
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.
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.
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!
© All rights reserved. Made with ❤️ by BitterBrains, Inc.