This is a Proof of Concept (POC) demonstrating the usage of a design system library and how it can be consumed in an application.
- Live Demo: You can check out a live demo of the design system and app consumer in action: https://design-system-stenciljs-sb-poc.netlify.app/?path=/docs/components-mycomponent--docs
It includes two repositories:
Contains the web components and their associated functionality.
- Stencil JS 4.27
- Storybook 8.6.4
This design system aims to support React output only. Due to significant issues with the react-output-target library, this starter doesn't currently support it.
A sample application that consumes the design system library and displays its components.
- Next JS 15 (app router, turbopack, typescript support)
-
Install dependencies (if not already installed): To get started with development, follow these steps:
yarn install
-
To add new files or components, run the following:
yarn generate
-
Manually add your Storybook file inside the
src/stories
folder to showcase the components. -
To see your components and work on them interactively, run:
yarn storybook
To deploy your design system:
-
yarn build
-
Create the .tgz package for distribution:
yarn pack
In the app that consumes the design system:
-
First, add the .tgz package that was generated by the design system.
yarn add ./name-of-library.tgz
-
In your client-side rendered file, register the components using defineCustomElements: For further details, check the App Consumer Repository
import { defineCustomElements } from 'name-of-library';
defineCustomElements(window);
IntelliSense support: After registering the components, your IDE should now be able to locate your web components and provide IntelliSense for their props and methods.
Example:
<second-component background="black" borderRadius="large" color="green" size="large" label="world" clickButton={(e) => { alert("hello world"); }} > <p>Hello</p> </second-component>
-
Some components, like
my-component
example (or especially those with complex props such as objects or arrays), might face rendering issues in Next.js projects. In such cases, rendering them lazily may resolve the problem. For example:
const MyComponent = dynamic(() => import("../components/MyComponent"), {
ssr: false,
});
Then, you can render the component just like:
<MyComponent />
As web components don't support libraries like Shadcn and Bootstrap, it will be necessary to conduct tests using alternative libraries such as FAST and Shoelace. These libraries are designed to work well with web components, providing the required functionality and styling without depending on traditional CSS frameworks.
-
Integration with FAST: Test the components by integrating them with the FAST library. FAST provides a set of tools and patterns to help build high-performance web components, which is crucial for creating scalable and accessible designs.
-
Integration with Shoelace: Implement tests with Shoelace, a library that offers a collection of reusable and customizable web components. Shoelace is designed to work seamlessly with web components and will be helpful to ensure consistent design behavior.
By leveraging these libraries, you can ensure better support and behavior of your components in environments that rely on web component standards, especially for more complex UIs and cross-platform consistency.