Quick Start
HandyUI is a Vue 3 component library made up of 4 packages:
| Package | Contents |
|---|---|
@nscode/handy-ui | All components (86), the v-loading directive, and functional APIs like Message |
@nscode/theme | Theme: CSS variables, dark theme, 5 color palettes, reset styles, utility classes |
@nscode/icons | SVG icons |
@nscode/utils | Utilities (type checks, debounce and throttle, DOM helpers) |
Most projects only need to install @nscode/handy-ui. The other three packages are its dependencies and are installed along with it.
Requirements
- Vue 3.5 or later (Modal, Drawer and Popover use
useId, added in Vue 3.5) - Node.js 18 or later
- Browsers: Chrome / Edge 111, Firefox 113, Safari 16.2 or later (the theme's light color scale uses CSS
color-mix; older browsers fall back to fixed colors)
Installation
The packages are published to the public npm registry. Install with:
pnpm add @nscode/handy-ui
# or
npm install @nscode/handy-ui
Full Import
Register the library once in your entry file. After that every component can be used in templates directly, without importing them one by one.
// main.ts
import { createApp } from 'vue'
import HandyUI from '@nscode/handy-ui'
import '@nscode/handy-ui/style.css'
import App from './App.vue'
const app = createApp(App)
app.use(HandyUI)
app.mount('#app')
app.use(HandyUI) does two things:
- Registers every component. Tag names are PascalCase with an
Huiprefix, such as<HuiButton>,<HuiDatePicker>and<HuiFormItem>; - Registers the
v-loadingdirective.
<template>
<HuiButton type="primary" @click="count++">Clicked {{ count }} times</HuiButton>
</template>
<script setup lang="ts">
import { ref } from 'vue'
const count = ref(0)
</script>
On-demand Import
If you only use a few components, skip app.use(HandyUI) and import them where they are used. The style file still needs to be imported once in the entry file.
// main.ts
import '@nscode/handy-ui/style.css'
<script setup lang="ts">
import { ref } from 'vue'
import { HuiButton, HuiInput } from '@nscode/handy-ui'
const keyword = ref('')
</script>
<template>
<HuiInput v-model="keyword" placeholder="Enter a keyword" />
<HuiButton type="primary">Search</HuiButton>
</template>
With on-demand import, register the v-loading directive yourself:
import { vLoading } from '@nscode/handy-ui'
app.directive('loading', vLoading)
Inside <script setup> you can also import { vLoading } from '@nscode/handy-ui' directly. Because the variable is named vLoading, v-loading works in the template.
Functional APIs
Message, MessageBox, Notification and full-screen Loading are not written in templates. Call them as functions:
import { HuiMessage, HuiMessageBox, HuiNotification, HuiLoading } from '@nscode/handy-ui'
HuiMessage.success('Saved')
HuiMessageBox.confirm('Delete this record?', 'Confirm')
.then(() => {
// OK was clicked
})
.catch(() => {
// Cancel or close was clicked
})
HuiNotification({ title: 'Notice', message: 'You have a new message' })
const loading = HuiLoading.service({ fullscreen: true, text: 'Loading...' })
loading.close()
See each component's page for the full options.
TypeScript
Props, events and option shapes of every component are typed. Import the types from @nscode/handy-ui:
import type { ButtonProps, SelectOption, TableColumnConfig, FormRule } from '@nscode/handy-ui'
The "Types" section of each component page lists the types it exports.
Global Configuration
Full installation accepts application defaults. Functional dialogs and message content can read these defaults through their application context:
import HandyUI from '@nscode/handy-ui'
app.use(HandyUI, {
size: 'small',
zIndex: 3000,
button: { type: 'primary' }
})
Component-tree ConfigProviders take priority over application defaults. A page-local provider's size, button settings and level do not cross into functional roots. For SSR, set the language with ConfigProvider rather than changing the global locale through app.use.
To set the default component size, the default button type and the z-index of overlays in one place, wrap your app with HuiConfigProvider:
<template>
<HuiConfigProvider size="small" :z-index="3000">
<App />
</HuiConfigProvider>
</template>
A size written on the component itself wins, and a size on Form, ButtonGroup and similar containers also wins over the global setting. The supported components are listed in the ConfigProvider section of docs/组件注意事项.md.
Notes
@nscode/handy-ui/style.cssincludes reset styles:marginandpaddingof all elements are zeroed,box-sizingisborder-box, and media elements such asimgandsvgbecome block-level. When adding HandyUI to an existing project, check pages that rely on the browser's default spacing.- The text color and background of
bodycome from theme variables (--hui-text-color,--hui-bg-color), so the page background follows when switching to the dark theme. - Overlays such as dialogs, dropdowns and messages are mounted on
body. Don't rely on parent selectors from your page when styling them.
Optional router versions
Menu router mode and Breadcrumb navigate through the router instance installed by the application. Ordinary controls and usage without routing do not require vue-router. The optional HandyUI peer range is ^4.0.0 || ^5.4.0. Isolated checks cover Router 4.6.4 and 5.4.0 with real plugins, menu push, guard cancellation and redirection, breadcrumb push/replace and navigation failures.
Router 5.4.0 itself requires Vue ^3.5.34 || ^4.0.0. Consumers must satisfy the intersection of HandyUI and Router peers. Any installed optional compiler, Vite or other integrations must also satisfy Router's corresponding peer ranges. This work does not upgrade the HandyUI development project's Vue 3.5.31 or Vite 5. Isolated consumer checks do not establish that the whole development stack has upgraded to Router 5, or that file-based routing, built output or deployment have been verified.
Continue installing the application's own router instance. When a guard throws or an asynchronous page fails to load, Menu and Breadcrumb preserve the previous route and report an error prefixed with [HandyUI]. Cancelled navigation is not treated as success.