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

Rate this content
Bookmark
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.
Zernonia Kong
Zernonia Kong
7 min
25 Apr, 2024

Comments

Sign in or register to post your comment.

Video Summary and Transcription

Shed CN Vue is a component library that allows for easy customization of components and styling. It is built on top of RedixView, which enables the use of primitives and element customization. Tailwind CSS is used for easy customization of layout, styling, animations, classes, and icons. The documentation provides more details on how to leverage these features.

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
React is a library for "rendering" UI from components, but many users find themselves confused about how React rendering actually works. What do terms like "rendering", "reconciliation", "Fibers", and "committing" actually mean? When do renders happen? How does Context affect rendering, and how do libraries like Redux cause updates? In this talk, we'll clear up the confusion and provide a solid foundation for understanding when, why, and how React renders. We'll look at: - What "rendering" actually is - How React queues renders and the standard rendering behavior - How keys and component types are used in rendering - Techniques for optimizing render performance - How context usage affects rendering behavior| - How external libraries tie into 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
Too much JavaScript is getting you down? New frameworks promising no JavaScript look interesting, but you have an existing React application to maintain. What if Qwik React is your answer for faster applications startup and better user experience? Qwik React allows you to easily turn your React application into a collection of islands, which can be SSRed and delayed hydrated, and in some instances, hydration skipped altogether. And all of this in an incremental way without a rewrite.
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
Design systems aim to bring consistency to a brand's design and make the UI development productive. Component libraries with well-thought API can make this a breeze. But, sometimes an API choice can accidentally overstep and slow the team down! There's a balance there... somewhere. Let's explore some of the problems and possible creative solutions.
React Concurrency, Explained
React Summit 2023React Summit 2023
23 min
React Concurrency, Explained
Top Content
React 18! Concurrent features! You might’ve already tried the new APIs like useTransition, or you might’ve just heard of them. But do you know how React 18 achieves the performance wins it brings with itself? In this talk, let’s peek under the hood of React 18’s performance features: - How React 18 lowers the time your page stays frozen (aka TBT) - What exactly happens in the main thread when you run useTransition() - What’s the catch with the improvements (there’s no free cake!), and why Vue.js and Preact straight refused to ship anything similar
The Future of Performance Tooling
JSNation 2022JSNation 2022
21 min
The Future of Performance Tooling
Top Content
Our understanding of performance & user-experience has heavily evolved over the years. Web Developer Tooling needs to similarly evolve to make sure it is user-centric, actionable and contextual where modern experiences are concerned. In this talk, Addy will walk you through Chrome and others have been thinking about this problem and what updates they've been making to performance tools to lower the friction for building great experiences on the web.
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
The open source PlayCanvas game engine is built specifically for the browser, incorporating 10 years of learnings about optimization. In this talk, you will discover the secret sauce that enables PlayCanvas to generate games with lightning fast load times and rock solid frame rates.

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 🤐)
Master JavaScript Patterns
JSNation 2024JSNation 2024
145 min
Master JavaScript Patterns
Workshop
Adrian Hajdin
Adrian Hajdin
During this workshop, participants will review the essential JavaScript patterns that every developer should know. Through hands-on exercises, real-world examples, and interactive discussions, attendees will deepen their understanding of best practices for organizing code, solving common challenges, and designing scalable architectures. By the end of the workshop, participants will gain newfound confidence in their ability to write high-quality JavaScript code that stands the test of time.
Points Covered:
1. Introduction to JavaScript Patterns2. Foundational Patterns3. Object Creation Patterns4. Behavioral Patterns5. Architectural Patterns6. Hands-On Exercises and Case Studies
How It Will Help Developers:
- Gain a deep understanding of JavaScript patterns and their applications in real-world scenarios- Learn best practices for organizing code, solving common challenges, and designing scalable architectures- Enhance problem-solving skills and code readability- Improve collaboration and communication within development teams- Accelerate career growth and opportunities for advancement in the software industry