1.0.0 • Published 1 year ago

tb-design-pc v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

An enterprise-class UI design language and cross-framework UI library, Based on Web Components.

English | 简体中文

🤔 Motivation

The emergence of the technical framework has improved the development experience and page performance, but the continuous iterative update of the technical framework has brought many challenges to the maintenance of the project, such as:

  • Visual components cannot be used across technical frameworks (React, Vue, etc.)
  • Once the technical framework is upgraded, visual components often have to be upgraded iteratively

Therefore, we developed this UI framework to isolate it from the technology framework (no technology stack), so that visual components can avoid falling into the vicious circle of technology stack iteration and iteration.

✨ Features

  • Support Vue, React, Angular, JQ and no framework project
  • 40+ High quality components
  • Support Tree Shaking
  • 90%+ Unit test coverage
  • Written in TypeScript
  • Support TypeScript
  • Support Custom Theme
  • Support i18n, built-in 20+ languages
Component LibraryCDNImport on demandBuild toolsTypeScriptopen source timeSupport technology stack/framework
Hdg80.1kbRollup2022Vue/React/Angular/JQ/Svelte/no framework
Vant183kbVite(Vant-cli)2017Vue only
Nutui275.5kbVite2018Vue only
TDesign Mobile-Gulp2021React only
Antd Mobile-Gulp2016React only

The CDN volume comparison above includes the runtime, js, and css required for various component libraries to function properly.

🔗 CDN

The easiest way to use hdg is to directly introduce the CDN link in the HTML file, and then you can use it anywhere in the world. Since hdg has achieved CSS-IN-JS, you only need to load the link below.

<!-- Introduce CDN files, only 80kb -->
<script src="https://fastly.jsdelivr.net/npm/hdgd@latest/umd/index.js"></script>

📦 Install

Using npm to install:

# install for Vue/React/Angular/No framework project
npm i hdgd --save

React usage notes: Since the components provided by hdgd are all native custom elements (analogous to div), events dispatched in the component need to be received by addEventLisener, such as the custom close event close inside the dialog component. The Vue technology stack can directly use @xx to receive natively dispatched events, so there is no need to use addEventLisener to receive.

In order to improve the development experience, we have Reactify (Reactify) for hdgd! So, we recommend that you use @hdgd/hdg-react in your React/Preact projects!

# Recommended Use for React
npm i @hdgd/hdg-react --save

🔨 Quickstart

Vue.x

// 1. Import the components you need
import "hdgd/lib/button";

// 2. Use it
<hdg-button type="primary">Button</hdg-button>;

React.x

// 1. Import the components you need
import { Button } from "@hdgd/hdg-react";

// 2. Use it
const App = () => (
  <>
    <Button type="primary">Button</Button>
  </>
);

Angular

// 1. Import the components you need
import "hdgd/lib/button"

// 2. Use it
@Component({
  template: `<hdg-button loading="{{loading}}"" (click)="handleClick()">
    Button
  </hdg-button>`
})

No framework project

<!DOCTYPE html>
<html lang="en">
  <!-- 1. CDN, import all components -->
  <script src="https://fastly.jsdelivr.net/npm/hdgd@latest/umd/index.js"></script>
  <body>

    <!-- 2. use it -->
    <hdg-button loading="true">Button</hdg-button>

  </body>
</html>

🎨 Custom theme

See custom theme.

🌍 Internationalization

Dozens of languages supported in, see Docs.

🖥 Browser Support

Modern browsers and Internet Explorer 11 (with polyfills).

Special Note

  • Since the components provided by hdgd are all native custom elements (analogous to div), the events dispatched by the components need to be received using addEventListener.
  • The Vue stack uses @xx to receive natively dispatched events, so there is no need to use addEventListener to receive them.
  • For the React technology stack, in order to avoid developers manually addingEventLisener to receive events, we rely on hdgd at the bottom and Reactify (Reactize) the upper layer! Therefore the React project recommends using @hdgd/hdg-react.

Pay attention

  • Unknown custom element in Vue project:
<!-- vue2: -->
Unknown custom element:
<hdg-icon>
  - did you register the component correctly? For recursive components, make
  sure to provide the "name" option.
  <!-- vue3 -->
  [Vue warn]: Failed to resolve component: hdg-icon
</hdg-icon>

This is because the syntax part of Vue components refers to custom elements. In order to avoid conflicts with Vue components, custom elements need to be ignored! Please inject the following code into the project:

// VUE2.x
Vue.config.ignoredElements = [/^hdg-/];

// VUE3.x
// https://v3.cn.vuejs.org/guide/migration/global-api.html#config-productiontip-%E7%A7%BB%E9%99%A4
const app = createApp({});
app.config.compilerOptions.isCustomElement = (tag) => tag.startsWith("hdg-");

If you are using vite, modify vite.config.js:

import vue from "@vitejs/plugin-vue";

export default {
  plugins: [
    vue({
      template: {
        compilerOptions: {
          isCustomElement: (tag) => tag.startsWith("hdg-"),
        },
      },
    }),
  ],
};

👋 Contributions PRs Welcome

Contributions are welcome! See Contributor's Guide before making a pull request.

1.0.0

1 year ago