Build Your Own Component Library, With `Shadcn-vue`

Rate this content
Bookmark
The video discusses how to build your own component library using ShadCN Vue, a community port of ShadCN UI for Vue.js. Traditional component libraries often limit users with their exposed APIs, but ShadCN Vue allows for full ownership and customization. Built on top of RedixView, it enables users to design their own API, customize styling with Tailwind CSS, and freely add or move elements in the DOM. This flexibility makes it easier to build a design system and use custom icons. Tailwind Merge and CLSX functions further simplify the process. For more details and pre-made blocks, check the official documentation.

From Author:

In case you are unaware, shadcn (creator of `ui.shadcn`) created a new way for devs to build component libraries. Instead of a usual component library, where you are limited to the component styling, props, or events designed by the author, you now have the capability to modify the components to suit your needs.
Quote from the shadcn himself, "It's a collection of re-usable components that you can copy and paste into your apps."

In this talk, I will be showcasing the power of this approach, walking through how to customize it, and why it has gained such a popularity in the recent months.

This talk has been presented at Vue.js Live 2024, check out the latest edition of this JavaScript Conference.

FAQ

A traditional component library is essentially a collection of components where the API, including props, events, methods, and slots, is designed by the author or the team. Users often face limitations with the exposed API and find it challenging to customize styling or build wrappers around these components.

The challenges include being limited to the exposed API, difficulty in customizing styling especially when using Tailwind CSS or Uno CSS, and finding it hard to build wrappers around the components for different styling and behavior.

ShadCN Vue is a community port of ShadCN UI for Vue.js. It allows you to copy and paste accessible components into your project, offering full ownership over the components. This eliminates limitations with exposed APIs and allows for easy styling and DOM customization.

ShadCN Vue provides ownership of components, allowing you to design the API as needed. It also supports Tailwind Merge for styling, making it easy to customize elements and their positions in the DOM. Additionally, it facilitates building design systems around the components.

ShadCN Vue, built on top of RedixView, allows you to use primitive elements and style them easily with Tailwind CSS. You can merge custom classes with default classes using Tailwind Merge, and freely add or move elements in the DOM.

Yes, ShadCN Vue is built on top of RedixView, which is a styled and accessible component library. It allows you to build a design system around it, making it easy to customize and extend components to fit your project needs.

You can customize components by modifying their styles, animations, and adding or changing elements as needed. ShadCN Vue uses Tailwind Merge and CLSX functions to merge custom classes with default ones, allowing for easy and flexible customization.

Tailwind CSS plays a crucial role in ShadCN Vue by providing a utility-first approach to styling. It allows for easy customization through CSS variables or the Tailwind config, and Tailwind Merge helps combine custom and default classes seamlessly.

Yes, you are not bound by any specific icon library when using ShadCN Vue. You can add whatever component icons you want, allowing for greater flexibility and customization.

You can find more information, documentation, and pre-made blocks for ShadCN Vue on their official repository and documentation site. Be sure to check it out for detailed guides and customization options.

Zernonia Kong
Zernonia Kong
7 min
25 Apr, 2024

Comments

Sign in or register to post your comment.

Video Transcription

1. Introduction to Shed CN view and its benefits

Short description:

Hey, guys. I'm Xenonia, and welcome to the Lightning Talk. Today I'll be sharing with you regarding build your own component library with Shed CN view. So what is traditional component library? It is the component library where the component's API is designed by the author or the team itself. We are always limited to the exposed API and find it hard to customize styling and build a wrapper around it. But with ShadCN Vue, you can copy and paste accessible components into your project, design the API as you like, and customize styling easily.

Hey, guys. I'm Xenonia, and welcome to the Lightning Talk. Today I'll be sharing with you regarding build your own component library with Shed CN view. I'm from Malaysia, and I'm the front-end lead at TroopFail Inc. I'm also the co-maintainer of RedixView and Shed CN view.

So, first of all, what is traditional component library? So essentially, I describe it as the component library that the component's API were designed, such as props, event, methods, and slots were designed by the author or the team itself. So I believe all of us has used component library before. Definitely, we will come across a few challenges. So, first of all, we are always limited to the exposed API. Be it exposed a thousand props or events, we always somehow limited. We just think at the bottom of our mind, I just wish that I could modify just something of that component.

Second challenge, we always find it hard to customize the styling, especially when we are using, let's say, Tailwind CSS or Uno CSS, we always need to force the important exclamation mark for the style, to assert the styling, because just the component library wasn't built around, wasn't designed to have inline classes styling.

Third of all, which is we always find it difficult to build a wrapper around it. So in my company, we were trying to build a design system, a component library around a component library, because we want to have different styling, different component behavior, as such, and we always find it so hard to do so. So I believe this problem has always been the case, until ShadCN arrives.

So this was, the project was initially released last year, on January, and since then, it has gained so much popularity in the React world, and it also affected the Vue, as well as Shelf world. So what is this ShadCN Vue? It is essentially a concept that for you to copy and paste accessible components into your project. And it solves all the problem that I mentioned earlier. How so? So I'm not going to talk about ShadCN UI, because that project is built for React. So let's look at ShadCN Vue, which essentially is the same idea, same concept, but it is a community viewport of ShadCN UI. And it is a collection of reusable components that you can copy and paste or use the CLI to add the components into your project. So it eliminates three of the problems just now. So we are no longer bound by the exposed API. So right now we are free to design the API however we like. So because all the components right now are in your project, you have the ownership of the component. So let's take a look at this button here. So you can add however, whatever props, events, slot props, however you want, anything you want into the button because right now you have ownership of that. Just design it as you see fit. Got it? Secondly, we always find it hard to customize styling and let's say the DOM positions of certain elements. No longer the case as well.

2. Customizing ShadCN view and its benefits

Short description:

Because of how ShadCN is built on top of RedixView, it allows you to use the primitive and style the element itself. You are no longer bound and can add or move elements in the DOM. It is no longer difficult to build a REPL as it is built on top of RedixView, a style and accessible component library. Tailwind CSS makes customization easy. You can customize the layout, styling, animations, classes, and even the component icons. Check out the documentation for more details.

Because of how ShadCN is built on top of RedixView, it allows you to use the primitive and to style the element itself here. So if you can see the menu trigger, we pass in the class of however, whatever classes here and it will overwrite, not overwrite, it will merge with the default classes by using Tailwind Merge. Other than that, it also allows us to do add whatever elements we want or move however the element we want to be rendered in the DOM. So let's say I want to add a separator or I want to add a span in between the drop-down options. Yeah, we are no longer bound but we can do whatever we want right now.

And lastly, it no longer finds it difficult to build a REPL because like I mentioned earlier, it is built on top of RedixView, which is a style and accessible component library that you can build your design system around it. Also, we are using Tailwind CSS, which is super easy to customize by either using your CSS variable or the Tailwind config to fit your own project. So let's look at how could we customize it instead of just talking about the point. Let's look at the case.

So here in the repository, if you initiate, if you include dialogues into a component, you will receive all these .view files as well as this index.cx. So let's look at how we can customize it to your own project. So right now, let's say I have this dialogue overview. Let's say I don't want to have black layout. I can just modify it. I can change the styling here. I also can change the animations however I like for this overlay. And here, dialogue content, you can see that here we have a CN functions, which is essentially functions that Tailwind merges as well as CLSX together. So right now, the first parameters here is designed by us, the shadcn library, and prop.class essentially is what you want to merge with. Let's say you don't want to have left one stroke two, you want to have left 33%. In your component usage, you can just add the class equals to left-33%. And it will merge and overwrite this specific view and persist all the other file, all the other styling here. You don't need to have exclamation mark or anything. And of course, you can add whatever component icon you want. It's no longer bound by the specific icon library. You can change however you want. So these are just some of the quick preview of how to customize it. There's so much more I would love to share with you. Unfortunately, I don't have the time today. So do give us a star as well as check out the doc. There's so many things for you to customize. So if you look at the team, you can change however you want. As well as there's a lot of pre-made blocks for you to copy and paste into your project. So see you next. So that's all for me. See you next time.

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

A Guide to React Rendering Behavior
React Advanced Conference 2022React Advanced Conference 2022
25 min
A Guide to React Rendering Behavior
Top Content
This transcription provides a brief guide to React rendering behavior. It explains the process of rendering, comparing new and old elements, and the importance of pure rendering without side effects. It also covers topics such as batching and double rendering, optimizing rendering and using context and Redux in React. Overall, it offers valuable insights for developers looking to understand and optimize React rendering.
Speeding Up Your React App With Less JavaScript
React Summit 2023React Summit 2023
32 min
Speeding Up Your React App With Less JavaScript
Top Content
Watch video: Speeding Up Your React App With Less JavaScript
Mishko, the creator of Angular and AngularJS, discusses the challenges of website performance and JavaScript hydration. He explains the differences between client-side and server-side rendering and introduces Quik as a solution for efficient component hydration. Mishko demonstrates examples of state management and intercommunication using Quik. He highlights the performance benefits of using Quik with React and emphasizes the importance of reducing JavaScript size for better performance. Finally, he mentions the use of QUIC in both MPA and SPA applications for improved startup performance.
Design Systems: Walking the Line Between Flexibility and Consistency
React Advanced Conference 2021React Advanced Conference 2021
47 min
Design Systems: Walking the Line Between Flexibility and Consistency
Top Content
The Talk discusses the balance between flexibility and consistency in design systems. It explores the API design of the ActionList component and the customization options it offers. The use of component-based APIs and composability is emphasized for flexibility and customization. The Talk also touches on the ActionMenu component and the concept of building for people. The Q&A session covers topics such as component inclusion in design systems, API complexity, and the decision between creating a custom design system or using a component library.
React Concurrency, Explained
React Summit 2023React Summit 2023
23 min
React Concurrency, Explained
Top Content
Watch video: React Concurrency, Explained
React 18's concurrent rendering, specifically the useTransition hook, optimizes app performance by allowing non-urgent updates to be processed without freezing the UI. However, there are drawbacks such as longer processing time for non-urgent updates and increased CPU usage. The useTransition hook works similarly to throttling or bouncing, making it useful for addressing performance issues caused by multiple small components. Libraries like React Query may require the use of alternative APIs to handle urgent and non-urgent updates effectively.
The Future of Performance Tooling
JSNation 2022JSNation 2022
21 min
The Future of Performance Tooling
Top Content
Today's Talk discusses the future of performance tooling, focusing on user-centric, actionable, and contextual approaches. The introduction highlights Adi Osmani's expertise in performance tools and his passion for DevTools features. The Talk explores the integration of user flows into DevTools and Lighthouse, enabling performance measurement and optimization. It also showcases the import/export feature for user flows and the collaboration potential with Lighthouse. The Talk further delves into the use of flows with other tools like web page test and Cypress, offering cross-browser testing capabilities. The actionable aspect emphasizes the importance of metrics like Interaction to Next Paint and Total Blocking Time, as well as the improvements in Lighthouse and performance debugging tools. Lastly, the Talk emphasizes the iterative nature of performance improvement and the user-centric, actionable, and contextual future of performance tooling.
Optimizing HTML5 Games: 10 Years of Learnings
JS GameDev Summit 2022JS GameDev Summit 2022
33 min
Optimizing HTML5 Games: 10 Years of Learnings
Top Content
PlayCanvas is an open-source game engine used by game developers worldwide. Optimization is crucial for HTML5 games, focusing on load times and frame rate. Texture and mesh optimization can significantly reduce download sizes. GLTF and GLB formats offer smaller file sizes and faster parsing times. Compressing game resources and using efficient file formats can improve load times. Framerate optimization and resolution scaling are important for better performance. Managing draw calls and using batching techniques can optimize performance. Browser DevTools, such as Chrome and Firefox, are useful for debugging and profiling. Detecting device performance and optimizing based on specific devices can improve game performance. Apple is making progress with WebGPU implementation. HTML5 games can be shipped to the App Store using Cordova.

Workshops on related topic

React Performance Debugging Masterclass
React Summit 2023React Summit 2023
170 min
React Performance Debugging Masterclass
Top Content
Featured WorkshopFree
Ivan Akulov
Ivan Akulov
Ivan’s first attempts at performance debugging were chaotic. He would see a slow interaction, try a random optimization, see that it didn't help, and keep trying other optimizations until he found the right one (or gave up).
Back then, Ivan didn’t know how to use performance devtools well. He would do a recording in Chrome DevTools or React Profiler, poke around it, try clicking random things, and then close it in frustration a few minutes later. Now, Ivan knows exactly where and what to look for. And in this workshop, Ivan will teach you that too.
Here’s how this is going to work. We’ll take a slow app → debug it (using tools like Chrome DevTools, React Profiler, and why-did-you-render) → pinpoint the bottleneck → and then repeat, several times more. We won’t talk about the solutions (in 90% of the cases, it’s just the ol’ regular useMemo() or memo()). But we’ll talk about everything that comes before – and learn how to analyze any React performance problem, step by step.
(Note: This workshop is best suited for engineers who are already familiar with how useMemo() and memo() work – but want to get better at using the performance tools around React. Also, we’ll be covering interaction performance, not load speed, so you won’t hear a word about Lighthouse 🤐)
Building WebApps That Light Up the Internet with QwikCity
JSNation 2023JSNation 2023
170 min
Building WebApps That Light Up the Internet with QwikCity
Featured WorkshopFree
Miško Hevery
Miško Hevery
Building instant-on web applications at scale have been elusive. Real-world sites need tracking, analytics, and complex user interfaces and interactions. We always start with the best intentions but end up with a less-than-ideal site.
QwikCity is a new meta-framework that allows you to build large-scale applications with constant startup-up performance. We will look at how to build a QwikCity application and what makes it unique. The workshop will show you how to set up a QwikCitp project. How routing works with layout. The demo application will fetch data and present it to the user in an editable form. And finally, how one can use authentication. All of the basic parts for any large-scale applications.
Along the way, we will also look at what makes Qwik unique, and how resumability enables constant startup performance no matter the application complexity.
Next.js 13: Data Fetching Strategies
React Day Berlin 2022React Day Berlin 2022
53 min
Next.js 13: Data Fetching Strategies
Top Content
WorkshopFree
Alice De Mauro
Alice De Mauro
- Introduction- Prerequisites for the workshop- Fetching strategies: fundamentals- Fetching strategies – hands-on: fetch API, cache (static VS dynamic), revalidate, suspense (parallel data fetching)- Test your build and serve it on Vercel- Future: Server components VS Client components- Workshop easter egg (unrelated to the topic, calling out accessibility)- Wrapping up
Build a Data-Rich Beautiful Dashboard With MUI X's Data Grid and Joy UI
React Summit 2023React Summit 2023
137 min
Build a Data-Rich Beautiful Dashboard With MUI X's Data Grid and Joy UI
Top Content
WorkshopFree
Sam Sycamore
Siriwat (Jun) Kunaporn
2 authors
Learn how to put MUI’s complete ecosystem to use to build a beautiful and sophisticated project management dashboard in a fraction of the time that it would take to construct it from scratch. In particular, we’ll see how to integrate the MUI X Data Grid with Joy UI, our newest component library and sibling to the industry-standard Material UI.
Table of contents:- Introducing our project and tools- App setup and package installation- Constructing the dashboard- Prototyping, styling, and themes - Joy UI features- Filtering, sorting, editing - Data Grid features- Conclusion, final thoughts, Q&A
React Performance Debugging
React Advanced Conference 2023React Advanced Conference 2023
148 min
React Performance Debugging
Workshop
Ivan Akulov
Ivan Akulov
Ivan’s first attempts at performance debugging were chaotic. He would see a slow interaction, try a random optimization, see that it didn't help, and keep trying other optimizations until he found the right one (or gave up).
Back then, Ivan didn’t know how to use performance devtools well. He would do a recording in Chrome DevTools or React Profiler, poke around it, try clicking random things, and then close it in frustration a few minutes later. Now, Ivan knows exactly where and what to look for. And in this workshop, Ivan will teach you that too.
Here’s how this is going to work. We’ll take a slow app → debug it (using tools like Chrome DevTools, React Profiler, and why-did-you-render) → pinpoint the bottleneck → and then repeat, several times more. We won’t talk about the solutions (in 90% of the cases, it’s just the ol’ regular useMemo() or memo()). But we’ll talk about everything that comes before – and learn how to analyze any React performance problem, step by step.
(Note: This workshop is best suited for engineers who are already familiar with how useMemo() and memo() work – but want to get better at using the performance tools around React. Also, we’ll be covering interaction performance, not load speed, so you won’t hear a word about Lighthouse 🤐)
High-performance Next.js
React Summit 2022React Summit 2022
50 min
High-performance Next.js
Workshop
Michele Riva
Michele Riva
Next.js is a compelling framework that makes many tasks effortless by providing many out-of-the-box solutions. But as soon as our app needs to scale, it is essential to maintain high performance without compromising maintenance and server costs. In this workshop, we will see how to analyze Next.js performances, resources usage, how to scale it, and how to make the right decisions while writing the application architecture.