# HandyUI > A Vue 3 component library: 122 components, themeable, dark mode built in, written in TypeScript. --- # 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: ```bash 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. ```ts // 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 `Hui` prefix, such as ``, `` and ``; - Registers the `v-loading` directive. ```vue ``` ## 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. ```ts // main.ts import '@nscode/handy-ui/style.css' ``` ```vue ``` With on-demand import, register the `v-loading` directive yourself: ```ts import { vLoading } from '@nscode/handy-ui' app.directive('loading', vLoading) ``` Inside ` ``` Many components have props like `icon` that also take an icon name, for example `Add`. ## Icon List `name` uses the built-in names below. Without a custom slot, an unknown name produces a development warning and leaves a blank 1em×1em box (16px by default). | Group | Icon names | | -------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Direction and navigation | `home` `menu` `apps` `top` `arrow-up` `arrow-down` `arrow-left` `arrow-right` `chevron-up` `chevron-down` `chevron-left` `chevron-right` `double-left` `double-right` `caret-up` `caret-down` `caret-left` `caret-right` `more-horizontal` `more-vertical` | | Actions | `close` `check` `plus` `minus` `edit` `trash` `refresh` `copy` `save` `share` `link` `upload` `download` `filter` `sort` `drag` `lock` `eye` `eye-off` `eye-dropper` `zoom-in` `zoom-out` `rotate-left` `rotate-right` `fullscreen` `fullscreen-exit` `density` `pin` | | Status | `success` `warning` `error` `info` `help` `loading` `star` `star-half` `heart` `clock` `calendar` | | User and general | `user` `users` `setting` `search` `bell` `phone` `location` `mail` | | Files | `file` `folder` `image` `table` | | Media | `play` `pause` `replay` `skip-previous` `skip-next` `fast-rewind` `fast-forward` `volume-up` `volume-down` `volume-off` `pip` `subtitles` | | Editing, cropping and chat | `undo` `redo` `format-bold` `format-italic` `format-underline` `format-strikethrough` `format-code` `format-quote` `format-list-bulleted` `format-list-numbered` `format-indent-increase` `format-indent-decrease` `format-align-left` `format-align-center` `format-align-right` `format-align-justify` `format-clear` `format-color-text` `format-color-fill` `format-heading` `horizontal-rule` `code-block` `link-off` `crop` `flip-horizontal` `flip-vertical` `send` `stop` `attach` `thumb-up` `thumb-down` `sparkle` | The 32 general-purpose editing, cropping and chat icons belong to the `editor` group and can be used independently in buttons, toolbars and content. Full screen exit uses the existing `fullscreen-exit` icon in Actions. ## Player icons Use these for playback, seeking, volume, picture-in-picture and subtitles. Full screen exit uses the existing `fullscreen-exit` icon. ```vue ``` ## Custom Icons The default slot of `HuiIcon` accepts any SVG, and size, color and rotation props still apply: ```vue ``` The SVG needs a `viewBox`, and its fill should be `currentColor` so it follows the `color` prop. When the slot is provided, it takes precedence and the built-in icon for `name` isn't rendered. `name` is still required, but it does not provide an accessible name. Icons have `aria-hidden="true"` by default. Set `aria-label` explicitly to use `role="img"` and announce that label. Give an icon-only action button its accessible name on the button itself. ## Using Icon Data Directly `@nscode/icons` exports the raw icon data for rendering icons yourself: ```ts import { icons, iconList, iconGroups } from '@nscode/icons' icons['arrow-up'] // { name: 'arrow-up', svg: '...' } iconList // all icons as an array, handy for an icon picker iconGroups.navigation // by group: navigation, action, status, user, file, media, editor iconGroups.media // playback, volume, picture-in-picture and subtitle icons iconGroups.editor // 32 general-purpose editing, cropping and chat icons icons['fullscreen-exit'] // reuse the full screen exit icon from Actions ``` Each icon can also be imported on its own by its camelCase name: `import { arrowUp, chevronLeft } from '@nscode/icons'`. --- # Utilities `@nscode/utils` contains small helpers used inside the component library. They are also exported from `@nscode/handy-ui`, so your code can use them directly: ```ts import { debounce, isEmpty, addClass } from '@nscode/handy-ui' // or import { debounce, isEmpty, addClass } from '@nscode/utils' ``` ## Type Checks | Function | Description | | --------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `isString(val)`, `isNumber(val)`, `isBoolean(val)`, `isFunction(val)` | Check primitive types | | `isThenable(val)` | Whether an object or function has a callable `then`; supports Promises and custom thenables, and does not call `then` | | `isArray(val)` | Same as `Array.isArray` | | `isObject(val)` | Not `null` and `typeof` is `object` (arrays included) | | `isEmpty(val)` | `true` for `null`, `undefined`, empty strings, empty arrays and plain objects without properties; Map and Set are checked by `size`; `0`, `false`, `Date` and other values return `false` | ## Functions and Strings | Function | Description | | --------------------- | --------------------------------------------------------------------------------------------- | | `debounce(fn, delay)` | Debounce: when called repeatedly, runs once `delay` ms after the last call | | `throttle(fn, delay)` | Throttle: the first call runs immediately; the last call within an interval runs when it ends | | `noop()` | Empty function | | `identity(val)` | Returns its argument | | `capitalize(str)` | Uppercase the first letter: `'button'` → `'Button'` | | `camelize(str)` | Kebab-case to camelCase: `'date-picker'` → `'datePicker'` | | `kebabCase(str)` | camelCase to kebab-case: `'datePicker'` → `'date-picker'` | ```ts import { debounce } from '@nscode/handy-ui' const search = debounce((keyword: string) => { // Sends the request only after typing stops for 300 ms }, 300) ``` Functions returned by `debounce` and `throttle` have a `cancel()` method; call it when the component unmounts to drop the pending call. When called as an object method, `this` is passed to the original function. ## DOM | Function | Description | | -------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------- | | `isClient` | Constant: whether running in a browser | | `inBrowser()` | Same as above, as a function | | `isDocumentVisible()` | Whether the page is visible (not in a background tab) | | `isWindow(val)` | Whether the value is the `window` object | | `addEventListener(el, event, handler, options?)`, `removeEventListener(...)` | Typed event binding; event names depend on the target (`beforeunload` on `window`, `visibilitychange` on `document`) | | `getComputedStyle(el)` | Get the computed style of an element | | `getScrollTop(el)`, `setScrollTop(el, value)` | Read and write the scroll position; `el` can be an element or `window` | | `getOffset(el)` | `top` and `left` of an element relative to the document | | `addClass(el, ...classes)`, `removeClass(el, ...classes)`, `hasClass(el, className)`, `toggleClass(el, className, force?)` | Class name helpers | ## Types ```ts import type { ComponentSize, ComponentType, MaybeArray, Nullable } from '@nscode/handy-ui' type ComponentSize = 'large' | 'default' | 'small' type ComponentType = 'primary' | 'success' | 'warning' | 'danger' | 'info' | 'help' | 'default' type MaybeArray = T | T[] type MaybeFunction = T | (() => T) type Nullable = T | null type Optional = T | undefined ``` ### Collection field mapping `CollectionFieldNames` is a shared mapping type available from `@nscode/handy-ui` and `@nscode/utils`. Its optional `value`, `label`, `children`, `disabled` and `isLeaf` fields accept a field name or `(item: T) => unknown`. Individual components select the fields appropriate to their data structure. ```ts import type { CollectionFieldNames } from '@nscode/handy-ui' interface City { id: number name: string inactive?: boolean children?: City[] } const fields: CollectionFieldNames = { value: 'id', label: (city) => city.name, children: 'children', disabled: (city) => Boolean(city.inactive), isLeaf: (city) => !city.children?.length } ``` ## Object paths and dates These helpers are available from both @nscode/utils and @nscode/handy-ui. Date functions follow the same rules used by the date picker. ### getPropByPath `getPropByPath(obj: unknown, path: string) => unknown` Read a property by dotted or bracket path. Missing paths return undefined; an empty path returns the original object. ```ts import { getPropByPath } from '@nscode/utils' const model = { users: [{ name: 'Alex' }] } getPropByPath(model, 'users[0].name') // 'Alex' getPropByPath(model, 'users.0.name') // 'Alex' ``` ### setPropByPath `setPropByPath(obj: unknown, path: string, value: unknown) => void` Set the final property of an existing path without creating missing intermediate objects. An empty path leaves the object unchanged. ```ts import { setPropByPath } from '@nscode/utils' const model = { users: [{ name: 'Alex' }] } setPropByPath(model, 'users.0.name', 'Sam') // model.users[0].name === 'Sam' ``` ### cloneValue `cloneValue(value: T) => T` Recursively clone arrays, plain objects and Date values, unwrapping existing Vue proxies. Blob, File and class instances retain their references. Circular references are unsupported. ```ts import { cloneValue } from '@nscode/utils' const original = { rows: [{ qty: 2 }], date: new Date(2026, 10, 19) } const copy = cloneValue(original) copy.rows[0].qty = 3 // original.rows[0].qty === 2 ``` ### formatDate `formatDate(date: Date, format: string) => string` Format local date/time fields using YYYY/YY, MM/M, DD/D, HH/H, mm/m and ss/s. `Z` emits the local offset at that instant as `±HH:mm`; `ZZ` emits `±HHmm`. A UTC environment emits `+00:00` / `+0000`. Date stores an instant without retaining the input offset: the same UTC instant displays local fields with `+08:00` in a UTC+08:00 environment. Bracketed text is literal, including `[Z]` and `[ZZ]`. A complete `x` format returns a millisecond timestamp string; `X` returns a second timestamp string rounded down. The return type remains string; only DatePicker and DatePickerPanel convert these formats into numeric model values. ```ts import { formatDate } from '@nscode/utils' formatDate(new Date(2026, 10, 19, 9, 5, 3), 'YYYY-MM-DD HH:mm:ss') // '2026-11-19 09:05:03' formatDate(new Date(1500), 'x') // '1500' formatDate(new Date(-1), 'X') // '-1', rounded down to seconds // The next two examples assume UTC+08:00; other time zones use their local fields and offsets. formatDate(new Date('2024-01-01T00:15:00Z'), 'YYYY-MM-DDTHH:mm:ssZ') // '2024-01-01T08:15:00+08:00' formatDate(new Date('2024-01-01T00:15:00Z'), 'YYYY-MM-DDTHH:mm:ssZZ') // '2024-01-01T08:15:00+0800' formatDate(new Date(), '[Z] [ZZ]') // 'Z ZZ' ``` ### parseLoose `parseLoose(text: string, nativeFallback?: boolean) => Date | null` Parse common date forms. Values without a zone use local time; zoned values identify an instant. Native Date fallback is enabled by default; false accepts only the supported numeric forms. Invalid values return null. ```ts import { parseLoose } from '@nscode/utils' parseLoose('2026-11-19 09:05:03', false) parseLoose('2026-11-19T01:05:03Z') parseLoose('invalid', false) // null ``` ### parseDate `parseDate(text: string, format: string) => Date | null` Parse numeric format tokens and bracketed literals. Without an offset token, fields use local time. `Z` accepts `Z` or `±HH:mm`; `ZZ` accepts `Z` or `±HHmm`, converting the explicit offset into an instant. Offset hours range from 00 to 23 and minutes from 00 to 59. Mismatched shapes, invalid offsets, conflicting repeated offsets or nonexistent dates return null. `[Z]` and `[ZZ]` are literal text and do not mark a date as UTC. YY maps to 2000–2099; omitted years use the current year, and other missing fields start at January 1, midnight. Complete `x`/`X` formats parse integer millisecond/second timestamps, including negative values and surrounding whitespace. Decimal, exponential or out-of-range values return null; `[x]` and `[X]` remain literals. ```ts import { parseDate } from '@nscode/utils' parseDate('2026/11/19 9:05', 'YYYY/MM/DD H:mm') parseDate('2026-02-30', 'YYYY-MM-DD') // null parseDate('2024-01-01T00:15:00+05:45', 'YYYY-MM-DDTHH:mm:ssZ')?.toISOString() // '2023-12-31T18:30:00.000Z' parseDate('2023-12-31T15:00:00-0330', 'YYYY-MM-DDTHH:mm:ssZZ')?.toISOString() // Same instant as above parseDate('2024-01-01T00:15:00+24:00', 'YYYY-MM-DDTHH:mm:ssZ') // null ``` ### isValidDate `isValidDate(value: unknown) => value is Date` Check for a valid Date instance; parsable strings are not Date objects. ```ts import { isValidDate } from '@nscode/utils' isValidDate(new Date()) // true isValidDate(new Date(NaN)) // false isValidDate('2026-11-19') // false ``` --- # Internationalization All UI texts in the components come from a locale pack: placeholders, OK and Cancel buttons, empty states, pagination, date panels, form validation messages and texts for screen readers. The default is Simplified Chinese, so nothing changes until you set a locale. 79 languages are built in: - **Simplified Chinese, Traditional Chinese and English** are proofread and imported from `@nscode/handy-ui` directly. - **The other 76** are imported from `@nscode/handy-ui/locale/`, so only the languages you use end up in your bundle. ## Setting the Locale for the Whole App With full registration, pass `locale` to `app.use`: ```ts import { createApp } from 'vue' import HandyUI, { localeEn } from '@nscode/handy-ui' import '@nscode/handy-ui/style.css' import App from './App.vue' createApp(App).use(HandyUI, { locale: localeEn }).mount('#app') ``` With on-demand import, put an [HuiConfigProvider](/en/components/config-provider.md) at the outermost level of the root component and place the app inside it: ```vue ``` The outermost `HuiConfigProvider` also sets the language of components created by function calls: `HuiMessage`, `HuiMessageBox`, `HuiNotification`, `HuiLoadingBar` and the Loading service. If you use both, `HuiConfigProvider` wins. ## Showing Multiple Languages `mergeLocales(locales, separator = ' / ')` joins texts in the supplied order on one line, such as “确定 / OK”. Identical texts appear once; empty texts and missing keys are skipped. Arrays such as weekdays and months are merged by position. The original packs stay unchanged. Supply at least one pack; an empty list throws a `RangeError`. ```vue ``` The resulting `name` is a combined identifier such as `zh-cn+en`, which cannot be passed to `Intl` directly. Use the first pack's `name` when formatting dates or numbers in your app. Component values and date formats remain unchanged. Longer texts need more horizontal space. ## Switching at Runtime `locale` is reactive. Give it another pack and the texts on the page change at once. ```vue ``` If your app has its own translations, derive the component library's locale from the app's current language: ```ts import { computed, ref } from 'vue' import { localeEn, localeZhCn, localeZhTw } from '@nscode/handy-ui' // The variable that holds the app's current language const appLang = ref('zh-cn') const huiLocales = { 'zh-cn': localeZhCn, 'zh-tw': localeZhTw, en: localeEn } export const huiLocale = computed(() => huiLocales[appLang.value] ?? localeZhCn) ``` Then bind it on the root: ``. ## Using Other Languages The other 76 languages are imported from subpaths. The default export is the pack: ```ts import { createApp } from 'vue' import HandyUI from '@nscode/handy-ui' import jaJp from '@nscode/handy-ui/locale/ja-jp' import App from './App.vue' createApp(App).use(HandyUI, { locale: jaJp }).mount('#app') ``` To support many languages, load each one only when it is needed. Write every import path as a fixed string, not built from a variable, so the bundler can split each language into its own file: ```ts import { shallowRef } from 'vue' import { localeZhCn, type HuiLocale } from '@nscode/handy-ui' const loaders: Record Promise<{ default: HuiLocale }>> = { 'ja-jp': () => import('@nscode/handy-ui/locale/ja-jp'), 'ko-kr': () => import('@nscode/handy-ui/locale/ko-kr'), 'fr-fr': () => import('@nscode/handy-ui/locale/fr-fr') } export const huiLocale = shallowRef(localeZhCn) export async function switchLanguage(name: string) { const load = loaders[name] huiLocale.value = load ? (await load()).default : localeZhCn } ``` ## Supported Languages Sorted by import path. Machine-translated languages have not been checked by native speakers. To fix an awkward phrase, override it as shown in "Overriding Texts" below. | Language | Import | Notes | | --------------------- | ----------------------------------------------- | ---------------------------------------------------------------------- | | Afrikaans | `@nscode/handy-ui/locale/af-za` | Machine-translated | | Amharic | `@nscode/handy-ui/locale/am-et` | Machine-translated | | Arabic | `@nscode/handy-ui/locale/ar` | Machine-translated; right-to-left (texts only); Modern Standard Arabic | | Azerbaijani | `@nscode/handy-ui/locale/az-az` | Machine-translated; Latin script | | Belarusian | `@nscode/handy-ui/locale/be-by` | Machine-translated | | Bulgarian | `@nscode/handy-ui/locale/bg-bg` | Machine-translated | | Bengali | `@nscode/handy-ui/locale/bn-bd` | Machine-translated | | Catalan | `@nscode/handy-ui/locale/ca-es` | Machine-translated | | Czech | `@nscode/handy-ui/locale/cs-cz` | Machine-translated | | Danish | `@nscode/handy-ui/locale/da-dk` | Machine-translated | | German | `@nscode/handy-ui/locale/de-de` | Machine-translated | | Greek | `@nscode/handy-ui/locale/el-gr` | Machine-translated | | English | `localeEn` or `@nscode/handy-ui/locale/en` | Proofread | | English (UK) | `@nscode/handy-ui/locale/en-gb` | Machine-translated; British spelling of the English pack | | Esperanto | `@nscode/handy-ui/locale/eo` | Machine-translated | | Spanish (Argentina) | `@nscode/handy-ui/locale/es-ar` | Machine-translated | | Spanish (Spain) | `@nscode/handy-ui/locale/es-es` | Machine-translated | | Estonian | `@nscode/handy-ui/locale/et-ee` | Machine-translated | | Basque | `@nscode/handy-ui/locale/eu-es` | Machine-translated | | Persian | `@nscode/handy-ui/locale/fa-ir` | Machine-translated; right-to-left (texts only) | | Finnish | `@nscode/handy-ui/locale/fi-fi` | Machine-translated | | Filipino | `@nscode/handy-ui/locale/fil-ph` | Machine-translated | | French | `@nscode/handy-ui/locale/fr-fr` | Machine-translated | | Galician | `@nscode/handy-ui/locale/gl-es` | Machine-translated | | Gujarati | `@nscode/handy-ui/locale/gu-in` | Machine-translated | | Hebrew | `@nscode/handy-ui/locale/he-il` | Machine-translated; right-to-left (texts only) | | Hindi | `@nscode/handy-ui/locale/hi-in` | Machine-translated | | Croatian | `@nscode/handy-ui/locale/hr-hr` | Machine-translated | | Hungarian | `@nscode/handy-ui/locale/hu-hu` | Machine-translated | | Armenian | `@nscode/handy-ui/locale/hy-am` | Machine-translated | | Indonesian | `@nscode/handy-ui/locale/id-id` | Machine-translated | | Icelandic | `@nscode/handy-ui/locale/is-is` | Machine-translated | | Italian | `@nscode/handy-ui/locale/it-it` | Machine-translated | | Japanese | `@nscode/handy-ui/locale/ja-jp` | Machine-translated | | Georgian | `@nscode/handy-ui/locale/ka-ge` | Machine-translated | | Kazakh | `@nscode/handy-ui/locale/kk-kz` | Machine-translated; Cyrillic script | | Khmer | `@nscode/handy-ui/locale/km-kh` | Machine-translated | | Kannada | `@nscode/handy-ui/locale/kn-in` | Machine-translated | | Korean | `@nscode/handy-ui/locale/ko-kr` | Machine-translated | | Kyrgyz | `@nscode/handy-ui/locale/ky-kg` | Machine-translated | | Lao | `@nscode/handy-ui/locale/lo-la` | Machine-translated | | Lithuanian | `@nscode/handy-ui/locale/lt-lt` | Machine-translated | | Latvian | `@nscode/handy-ui/locale/lv-lv` | Machine-translated | | Macedonian | `@nscode/handy-ui/locale/mk-mk` | Machine-translated | | Malayalam | `@nscode/handy-ui/locale/ml-in` | Machine-translated | | Mongolian | `@nscode/handy-ui/locale/mn-mn` | Machine-translated; Cyrillic script | | Marathi | `@nscode/handy-ui/locale/mr-in` | Machine-translated | | Malay | `@nscode/handy-ui/locale/ms-my` | Machine-translated | | Burmese | `@nscode/handy-ui/locale/my-mm` | Machine-translated | | Norwegian Bokmål | `@nscode/handy-ui/locale/nb-no` | Machine-translated | | Nepali | `@nscode/handy-ui/locale/ne-np` | Machine-translated | | Dutch | `@nscode/handy-ui/locale/nl-nl` | Machine-translated | | Norwegian Nynorsk | `@nscode/handy-ui/locale/nn-no` | Machine-translated | | Punjabi | `@nscode/handy-ui/locale/pa-in` | Machine-translated; Gurmukhi script | | Polish | `@nscode/handy-ui/locale/pl-pl` | Machine-translated | | Portuguese (Brazil) | `@nscode/handy-ui/locale/pt-br` | Machine-translated | | Portuguese (Portugal) | `@nscode/handy-ui/locale/pt-pt` | Machine-translated | | Romansh | `@nscode/handy-ui/locale/rm-ch` | Machine-translated | | Romanian | `@nscode/handy-ui/locale/ro-ro` | Machine-translated | | Russian | `@nscode/handy-ui/locale/ru-ru` | Machine-translated | | Sinhala | `@nscode/handy-ui/locale/si-lk` | Machine-translated | | Slovak | `@nscode/handy-ui/locale/sk-sk` | Machine-translated | | Slovenian | `@nscode/handy-ui/locale/sl-si` | Machine-translated | | Albanian | `@nscode/handy-ui/locale/sq-al` | Machine-translated | | Serbian | `@nscode/handy-ui/locale/sr-rs` | Machine-translated; Cyrillic script | | Swedish | `@nscode/handy-ui/locale/sv-se` | Machine-translated | | Swahili | `@nscode/handy-ui/locale/sw-ke` | Machine-translated | | Tamil | `@nscode/handy-ui/locale/ta-in` | Machine-translated | | Telugu | `@nscode/handy-ui/locale/te-in` | Machine-translated | | Thai | `@nscode/handy-ui/locale/th-th` | Machine-translated | | Turkish | `@nscode/handy-ui/locale/tr-tr` | Machine-translated | | Uyghur | `@nscode/handy-ui/locale/ug-cn` | Machine-translated; right-to-left (texts only); Arabic script | | Ukrainian | `@nscode/handy-ui/locale/uk-ua` | Machine-translated | | Urdu | `@nscode/handy-ui/locale/ur-pk` | Machine-translated; right-to-left (texts only) | | Uzbek | `@nscode/handy-ui/locale/uz-uz` | Machine-translated; Latin script | | Vietnamese | `@nscode/handy-ui/locale/vi-vn` | Machine-translated | | Simplified Chinese | `localeZhCn` or `@nscode/handy-ui/locale/zh-cn` | Proofread; Default | | Traditional Chinese | `localeZhTw` or `@nscode/handy-ui/locale/zh-tw` | Proofread; Taiwan usage | | Zulu | `@nscode/handy-ui/locale/zu-za` | Machine-translated | ## Using Another Language in Part of a Page Wrap any part of a page in `HuiConfigProvider`. Components inside use its language, and nothing outside changes. ```vue ``` ## Overriding Texts `locale` can be partial. Keys you leave out fall back to the outer language: the outer `HuiConfigProvider`, then the `locale` passed to `app.use`, then Simplified Chinese. Placeholders such as `{total}` are replaced with the actual values. ```vue ``` To change a few texts of another language, merge the two into one object, or nest two `HuiConfigProvider`s: ```ts import jaJp from '@nscode/handy-ui/locale/ja-jp' export const myJa = { ...jaJp, pagination: { ...jaJp.pagination, total: '全 {total} 件' } } ``` To see the keys and their Simplified Chinese texts, look at the `HuiLocale` type in your editor, or open `dist/locale/zh-cn.js` in the package. ## Props Come First A text prop set on a component takes priority over the locale pack: ```vue ``` When a text prop is not set, its default follows the language. The Props tables in the component docs show it as "Follows the locale (Simplified Chinese: 请选择)". ## Writing Your Own Pack For a language that is not built in, write a complete pack. Type it as `HuiLocale`, so type checking reports missing or extra keys. Copying `dist/locale/en.js` is a good start. ```ts import type { HuiLocale } from '@nscode/handy-ui' export const localeYue: HuiLocale = { name: 'yue-hk', common: { confirm: '確定', cancel: '取消' /* … */ } // … } ``` ## Lookup Order A component looks for each text in this order and stops at the first match: 1. The text prop set on the component. 2. The `locale` of the nearest `HuiConfigProvider`, then each outer one. 3. The `locale` of the outermost `HuiConfigProvider`, then the `locale` passed to `app.use`. 4. The built-in Simplified Chinese. ## Components Created by Function Calls `HuiMessage`, `HuiMessageBox`, `HuiNotification`, `HuiLoadingBar` and the Loading service are created separately, so they cannot see the `HuiConfigProvider` around the place where you call them. They use the outermost `HuiConfigProvider`'s language, then the one passed to `app.use`, then Simplified Chinese. If one part of the page uses another language, a message box opened from that part still uses the app's language. To match that part, pass the texts: ```ts HuiMessageBox.confirm('Delete this item?', 'Confirm', { confirmButtonText: 'OK', cancelButtonText: 'Cancel' }).catch(() => {}) ``` ## Notes - **Dates**: The date display format and the first day of the week do not follow the language. Set them with props such as `format` and `first-day-of-week`. - **Lunar calendar and solar terms**: These are in Chinese only. They stay in Chinese in every language. - **Right-to-left languages**: Arabic, Persian, Hebrew, Uyghur and Urdu have their texts translated, but the layout direction of the components does not change. - **Form validation messages**: Default messages are generated when validation runs. After switching languages, a message already on screen changes at the next validation. - **Server-side rendering**: Set the language with `HuiConfigProvider`, not the `locale` option of `app.use`. `app.use` sets global state, which requests handled by the server would share. - **Several outermost `HuiConfigProvider`s**: This happens, for example, when another app is mounted with `createApp`. Components created by function calls then follow the one mounted last. ## Extension locale schema Extension packages can augment the top-level message schema. Core locale packs gain no new required keys, and locale overrides can still supply partial fields. ```ts import type { HuiLocaleInput } from '@nscode/handy-ui' declare module '@nscode/handy-ui' { interface HuiLocaleExtensions { businessMessages: { saved: string } } } const locale: HuiLocaleInput = { businessMessages: { saved: 'Saved successfully' } } ``` Companion packages read the current Provider, application and global locale chain through `useLocaleChain()` from the internal `@nscode/handy-ui/internal` entry, then use generic `createTranslator` with their own fallback packs. Call the composable synchronously in setup. It does not register a new global locale root. Empty strings and whole-array overrides retain their existing meaning. ## Types | Name | Description | | ----------------------- | --------------------------------------------------------------------------------- | | `HuiLocale` | A complete locale pack | | `HuiLocaleInput` | A pack that may be partial. Used by `locale` on `HuiConfigProvider` and `app.use` | | `HandyUIInstallOptions` | The `options` of `app.use(HandyUI, options)`: `{ locale?: HuiLocaleInput }` | --- # LLMs The docs are also published as Markdown for LLMs and agents, following [llms.txt](https://llmstxt.org/). ## Files | File | Content | | ------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------- | | en/llms.txt | Index of all pages, grouped like the sidebar, one line per page | | en/llms-full.txt | All pages in one file | | llms.txt, llms-full.txt | Chinese version | The index covers guides, core components, and the changelog. Rich content, rich editing, and image cropping are core components. Each page uses its actual language source; missing translations are explicitly marked as a fallback. Traditional Chinese indexes are available at zh-tw/llms.txt and zh-tw/llms-full.txt. ## A page as Markdown Replace `.html` with `.md` in any docs or component page URL to get that page as Markdown, for example /en/components/button.md. Component pages include props, events, slots and the full code of every example. ## With an agent Give the agent the full URL of llms.txt (the site's domain followed by `/en/llms.txt`) and ask it to read the component pages it needs. It reads the index first and fetches only the pages it uses. llms-full.txt contains the code of every example and is large. It suits tools that can index a whole file; llms.txt is usually enough. --- # ActionGroup A row of action buttons occupying up to `max` positions, with overflow actions placed in a More dropdown. More displays text by default; `more-display` can show the number of overflow actions or use an icon. This is useful in a table's action column: pass each row as `row` to control action visibility and availability from that row's data. ## Import ```ts import { HuiActionGroup } from '@nscode/handy-ui' import type { ActionGroupItem } from '@nscode/handy-ui' ``` ## Basic Usage `actions` is an array of action items, each with at least a `key` and `label`. Clicking an action emits `actionClick` with the action item and `row`. ```vue ``` ## Maximum Visible Positions `max` defaults to 3, and More occupies one position: - When the number of visible actions does not exceed `max`, all actions are shown directly and More is omitted. - Otherwise, the first `max - 1` actions are shown directly and the rest go into More. The dropdown therefore contains at least two items; it is never created for only one overflow action. | Visible actions | max | Shown directly | Inside More | | --------------- | --- | -------------- | ----------- | | 3 | 3 | 3 items | - | | 4 | 3 | 2 items | 2 items | | 5 | 2 | 1 items | 4 items | | 5 | 1 | - | 5 items | Fractional `max` values are rounded down. Values below 1 (0, negative values, or `NaN`) are treated as 1 and produce a console warning. `Infinity` shows all actions directly. Each row below uses the same five actions, with its `max` value shown first: ```vue ``` ## Row-Based Visibility and Disabled State `visible` and `disabled` accept a boolean or a function receiving `row`. Actions are filtered by `visible` before `max` determines the overflow items. Hidden actions do not occupy a position. With `ActionGroupItem[]`, the callback's `row` is typed as `User`. ```vue ``` Each row below represents a user. Active users can be locked; locked users can be unlocked but cannot use Delete. Export is hidden for everyone (`visible: false`) and occupies no position. Clicking Lock or Unlock changes that row's status. ```vue ``` ## Table Action Columns Use the component in the table's action-column slot and pass the current `row`. `size="small"` is commonly used to match a small table. The buttons use `HuiButton` with `variant="link"` and no horizontal padding. They have no background or border, and only fade on hover, avoiding an additional background over the hovered table row. Text aligns with the cell's left edge, and spacing between buttons is 16 / 12 / 8px according to size. ```vue ``` ## Per-Action Click Callbacks An item's `onClick(row)` runs after the `actionClick` event. Use either approach or both: `onClick` keeps logic with each action, while `actionClick` allows centralized dispatch by `key`. ```vue ``` Click an action below to see the order when both are used: ```vue ``` ## Button Types, Icons, and More Display - `type` is the button type, defaulting to `primary` (primary-colored text). All `HuiButton` types are supported. In More, only `danger` changes the menu item's text to the danger color, such as Delete; other types use the regular menu-item appearance. - `icon` is an icon name supported by `HuiIcon` (see the Icons guide). It appears before the button text, or before the menu-item text in More. ```vue ``` `more-display` controls the More button's appearance and defaults to `text`: - `text`: the `more-text` label (localized by default, such as More in English) followed by a downward arrow. The arrow points up while the menu is open. No count is shown. - `text-count`: the label, an overflow count on a lightly shaded rounded background, and a downward arrow. - `count`: a lightly shaded pill showing `+N`, with a primary-colored border on hover or while the menu is open. - `icon`: only the horizontal ellipsis icon (`more-horizontal`), suitable for narrow table action columns. N is the number of overflow actions in the menu; hidden actions (`visible: false`) are excluded. The last three styles use `more-text` plus the count as their accessible name, such as More 2. Each row below demonstrates a style: ```vue ``` ## Triggers `trigger` controls how the More dropdown opens: `hover` (the default, also allowing a click to open it) or `click` (click to open, then click again to close). ```vue ``` ## Sizes `size` accepts `large`, `default`, or `small`: button heights are 40 / 32 / 24px, font sizes 16 / 14 / 12px, icon sizes 18 / 16 / 14px, and gaps 16 / 12 / 8px. More menu items also follow the size (row heights of 40 / approximately 36 / 28px, and font sizes of 16 / 14 / 12px). When omitted, the component follows `HuiConfigProvider.size`, falling back to `default`. ```vue ``` ## Keyboard Interaction - Tab focuses each button, skipping disabled buttons. Enter or Space activates it. - On More, Enter, Space, or ArrowDown opens the menu and focuses its first available item. ArrowUp/ArrowDown move between items, Home/End go to the first/last item, and Enter/Space select an item. - Esc or selecting an item closes the menu and returns focus to More. ## Props | Prop | Type | Default value | Description | | ----------- | --------------------------------------------- | ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- | | actions | `ActionGroupItem[]` | `[]` | Action items; see ActionGroupItem below | | max | `number` | `3` | Maximum number of positions, including More. Overflow shows the first `max - 1` actions directly and places the rest in More; values below 1 are treated as 1 | | row | `any` | - | Current row, passed unchanged to `disabled`, `visible`, `onClick`, and the `actionClick` event | | moreText | `string` | Localized (English: More) | More button label. When `moreDisplay` is not `text`, the label plus the count forms the accessible name, such as More 2 | | moreDisplay | `'text' \| 'text-count' \| 'count' \| 'icon'` | `'text'` | More appearance: text with an arrow, text with a count, a `+N` pill, or an ellipsis icon. The count excludes hidden actions | | trigger | `'hover' \| 'click'` | `'hover'` | Trigger for the More dropdown | | size | `'large' \| 'default' \| 'small'` | - | Size. Follows `HuiConfigProvider.size` when omitted, otherwise falls back to `'default'`; tables commonly use `small` | ### ActionGroupItem | Prop | Type | Default value | Description | | -------- | ------------------------------- | ------------- | -------------------------------------------------------------------------- | | key | `string` | - | Required unique identifier | | label | `string` | - | Required button text, also used as its accessible name | | icon | `string` | - | Icon name | | type | `ButtonType` | `'primary'` | Button type; in More, only `danger` changes the menu-item text color | | disabled | `boolean \| ((row) => boolean)` | `false` | Whether disabled. Disabled actions emit no event and do not call `onClick` | | visible | `boolean \| ((row) => boolean)` | `true` | Whether visible. Filtering occurs before calculating `max` | | onClick | `(row) => void` | - | Called on click, after the `actionClick` event | ## Events The declared and emitted event name is `actionClick`; the old name is not emitted as a second event. Vue templates should use `@action-click` (resolved by the compiler to the camelCase listener), and render functions use `onActionClick`. The raw JavaScript key `'onAction-click'` is not a compatibility alias for the new declaration. The action item, row argument, and event-before-onClick order are preserved. | Event | Callback arguments | Description | | ----------- | ------------------------------------- | --------------------------------------------------------------------------------------------------- | | actionClick | `(action: ActionGroupItem, row: any)` | Emitted when a direct button or a More menu item is clicked; `@actionClick` also works in templates | ## Slots There are no slots. Buttons are generated from `actions`; compose `HuiButton` and `HuiDropdown` directly for fully custom buttons. ## Methods No public methods are exposed. ## Types Public types use the component prefix. Compatibility mappings are `ActionRow` → `ActionGroupRow` and `ActionItem` → `ActionGroupItem`. The old names remain importable from `@nscode/handy-ui`, are marked `@deprecated`, and will be removed in 1.0. ```ts import type { ActionGroupProps, ActionGroupEmits, ActionGroupSize, ActionGroupMoreDisplay, ActionGroupTrigger, ActionGroupItem, ActionGroupRow } from '@nscode/handy-ui' type ActionGroupSize = 'large' | 'default' | 'small' type ActionGroupMoreDisplay = 'text' | 'text-count' | 'count' | 'icon' type ActionGroupTrigger = 'hover' | 'click' /** Row data; its type is unrestricted because the component does not read its fields */ type ActionGroupRow = any interface ActionGroupItem { key: string label: string icon?: HuiIconName type?: ButtonType disabled?: boolean | ((row: R) => boolean) visible?: boolean | ((row: R) => boolean) onClick?: (row: R) => void } interface ActionGroupProps { actions?: ActionGroupItem[] max?: number row?: ActionGroupRow moreText?: string moreDisplay?: ActionGroupMoreDisplay trigger?: ActionGroupTrigger size?: ActionGroupSize } interface ActionGroupEmits { actionClick: [action: ActionGroupItem, row: ActionGroupRow] } ``` --- # Button Trigger an action, submit a form, or navigate to a link. Buttons support theme colors, variants, icons, loading states, groups, and built-in popover hints. ## Import ```ts import { HuiButton } from '@nscode/handy-ui' import type { ButtonProps, ButtonExpose } from '@nscode/handy-ui' ``` ## Examples ### Colors and variants `type` controls color. `variant` selects solid, outline, plain, text, or link styling. `plain` is a shorthand for `variant="plain"`; an explicitly different variant takes priority. ```vue ``` ### Pressed state Explicit `true` or `false` enables toggle semantics and `aria-pressed`. Omitted or `undefined` keeps a regular button. A click requests `update:pressed` before `click`; rendering follows the parent value, with a stable button label. ```vue ``` Pressed solid buttons use the darker primary color; other variants use a soft primary background, primary text and border without changing spacing. Explicit custom colors keep their priority. Debounce and throttle apply to both events. A queued update uses the latest pressed value and is cancelled on disable, loading or unmount. `href` ignores pressed and warns in development. Use Button for action toggles, selectable Tag for filters, and Segmented or RadioGroup for mutually exclusive options. ### Sizes and shapes Large, default, and small use theme heights of 40, 32, and 24px. `round` creates pill corners. `circle` hides text and keeps a circular icon button; provide an accessible name. ```vue ``` ### Size and disabled inheritance inside forms Size priority is **button → ButtonGroup → InputGroup → ConfigProvider.button.size → ConfigProvider.size → default**. Disabled state uses the first explicit value from **button → ButtonGroup → InputGroup**. An explicit false overrides an inherited disabled value; loading still blocks clicks. Button does not directly inherit Form or FormItem size or disabled state. InputGroup merges its FormItem/Form size and Form disabled state into the group context, keeping grouped inputs and buttons aligned. A button outside InputGroup can remain clickable to enable a disabled form. An independent Form cuts off an outer input group. ```vue ``` ### Icons in all positions Icon-only buttons automatically use square proportions. `icon-position` accepts left, right, top, and bottom. Icons can also come from the default slot. ```vue ``` ### Loading and disabled states Loading replaces the icon and blocks clicks. Set loading-text to replace the label and loading-progress-bar for a bottom progress animation. Disabled controls emit no click event. ```vue ``` ### Colors, borders, dimensions, and links `color` sets a custom main color; text-color, bg-color, and border-color override individual parts. `width` and `height` accept pixels as numbers or CSS strings. Height cannot be smaller than the active size's minimum height. `href` renders an anchor; disabled or loading anchors have no href and expose aria-disabled. ```vue ``` ### Badges ```vue ``` ### Popover triggers and methods The built-in hint defaults to hover, while standalone Popover defaults to click. Manual ignores mouse/focus and uses showPopover()/hidePopover(). popover-disabled closes an open hint. The button must also be enabled. ```vue ``` ### All popover placements Placement flips automatically when the preferred side lacks space. ```vue ``` ### Debounce, throttle, and ripple Debounce delays the click until activity stops. Throttle accepts the first click in its interval. If both are supplied, debounce takes priority. Ripple animates from the click position. A queued click is cancelled if the button becomes disabled or loading, or its ButtonGroup becomes disabled. Restoring availability does not replay that click. Debounce controls the component click event; it does not delay native form submission with `native-type="submit"`. Click the delayed button, then toggle either state within one second to cancel its pending action: ```vue ``` ```vue ``` ### Native types and groups native-type selects button, submit, or reset. Buttons default to button, so they do not submit a form accidentally. ButtonGroup supplies shared size, type, and disabled values; a button's own values take priority. ```vue ``` ## Inherited Color Variable and Explicit Props `--hui-button-color` colors the loading progress bar and participates in custom plain-button color mixing; it does not replace `type` or `color`. Set it on the button or any ancestor. The explicit `color` prop takes priority, followed by the public variable, then the theme primary color. Each button resets its private prop override so nested buttons do not inherit an outer button's explicit color. The ordinary loading button inherits the success color for its progress bar. Another button has a local help-color variable and an explicit warning-color prop, so warning wins. Removing the prop restores the local help color; enabling it restores warning. Custom plain-button text, background tint, and border tint keep the same prop color. Existing priorities for `textColor`, `bgColor`, and `borderColor` remain unchanged. Set the public variable on an ancestor class in a parent ` ``` ## Vertical Layout `layout="vertical"` stacks buttons vertically, with rounded corners only on the first and last buttons. All button types, including icon-only buttons, can use this layout. ```vue ``` ## Grid Layout `layout="grid"` arranges buttons in a grid. `grid-columns` sets the column count (3 by default). `grid-direction` sets the filling direction: `row` (the default) fills rows, while `column` fills columns and makes `grid-columns` specify the row count. Compare the numbering order in the first two groups: ```vue ``` ## Spacing `gap` accepts `small`, `medium`, or `large` (4, 8, or 16px), a number in pixels, or a CSS length. With spacing set, buttons do not share borders and each retains its rounded corners. ```vue ``` ## Dividers `divider` adds separators between buttons, useful for rows of text buttons. Their length is half the button height: 20px for large, 16px for default, and 12px for small. In a vertical group, the dividers are horizontal. ```vue ``` Dividers are calculated from the rendered buttons, including buttons rendered by `v-for`. A button with a false `v-if` does not leave an extra divider. Clear the checkbox below to compare: ```vue ``` ## Props | Prop | Type | Default | Description | | ------------- | --------------------------------------------------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------ | | size | `'large' \| 'default' \| 'small'` | — | Size of the group's buttons. Follows ConfigProvider when omitted; the root receives the `hui-button-group--{size}` class | | type | `'primary' \| 'success' \| 'warning' \| 'danger' \| 'info' \| 'help'` | — | Type of the group's buttons; cannot be `default` | | disabled | `boolean` | — | Disable the group's buttons | | layout | `'horizontal' \| 'vertical' \| 'grid'` | — | Layout. When omitted, resolves to `vertical` or `horizontal` according to `vertical` | | vertical | `boolean` | `false` | Deprecated; use `layout="vertical"`. When both are set, `layout` takes precedence | | gap | `'small' \| 'medium' \| 'large' \| string \| number` | — | Spacing between buttons | | gridColumns | `number` | `3` | Grid column count (row count when filling columns) | | gridDirection | `'row' \| 'column'` | `'row'` | Grid filling direction | | divider | `boolean` | `false` | Show dividers between buttons | ## Slots | Slot | Description | | ------- | -------------------- | | default | Buttons in the group | ## Types ```ts import type { ButtonGroupProps, ButtonGroupGapSize, ButtonGroupLayoutMode, ButtonGroupGridDirection } from '@nscode/handy-ui' ``` --- # CollapseTransition Animate a content block's height when expanding or collapsing. No wrapper element is added. Place one element controlled by `v-show` or `v-if` in the default slot. ## Import ```ts import { HuiCollapseTransition } from '@nscode/handy-ui' import type { CollapseTransitionProps, CollapseTransitionEmits } from '@nscode/handy-ui' ``` ## Examples ### Toggle content `v-show` keeps the content and its internal state. The transition controls the outer element's height. Put padding and borders on an inner element so the collapsed block can reach zero height. ```vue ``` ### Duration `duration` is measured in milliseconds and defaults to 300. Compare 150, 300 and 600ms below; `0` completes immediately. All durations complete immediately when the system requests reduced motion. ```vue ``` ### More filters Keep the basic filter and transition in one block, with additional spacing inside the collapsible content. Collapsing leaves no empty grid item. With `v-show`, values remain when the extra fields are reopened. ```vue ``` ### Animate the initial appearance The initial render does not animate by default. Set `appear` to enable it. Changing `key` recreates the transition and its content to replay the initial expansion. ```vue ``` ### v-if and completion events `v-if` removes the content after the leave animation. Each completed animation emits one `afterEnter` or `afterLeave` event. Reversing an animation cancels the previous direction without emitting its completion event. ```vue ``` ## Props | Prop | Description | Type | Default | | -------- | ------------------------------------------------- | --------- | ------- | | duration | Animation duration in ms; 0 completes immediately | `number` | `300` | | appear | Animate the initial render | `boolean` | `false` | ## Events Public completion events are declared and emitted as `afterEnter` and `afterLeave`, once per completed direction. Vue templates may keep `@after-enter` and `@after-leave`; render functions use `onAfterEnter` and `onAfterLeave`. Old event names are not emitted alongside the new names. Cancelled directions remain silent; height/style restoration and the v-if removal point are unchanged. | Event | Description | Parameters | | ---------- | ------------------- | ---------- | | afterEnter | Expansion completed | — | | afterLeave | Collapse completed | — | ## Slots | Slot | Description | Parameters | | ------- | -------------------------------------------------------------------------------------------------- | ---------- | | default | One real element controlled by v-show or v-if; a component rendering one element is also supported | — | ## Methods None. Control expansion with `v-show` or `v-if` on the slotted content. ## Types ```ts interface CollapseTransitionProps { duration?: number appear?: boolean } interface CollapseTransitionEmits { afterEnter: [] afterLeave: [] } ``` --- # ConfigProvider Configure the locale, default size, button defaults, and overlay stacking level for descendant components. It can also switch the page theme. ## Import ```ts import { HuiConfigProvider } from '@nscode/handy-ui' ``` ## Basic Usage Wrap your application or a section of it. Descendant components use the ConfigProvider settings when the corresponding props are omitted. ```vue ``` ## Default Size `size` sets the default for descendant components that expose a `size` prop. It accepts `large`, `default`, or `small`. An explicit `size` on a component takes precedence. Change the size below to update several controls together: ```vue ``` Inside a button group, avatar group, chip group, or form, an explicit `size` on the group or form takes precedence over ConfigProvider: ```vue ``` ## Button Defaults `button` sets the default `type` and `size` for descendant buttons. Values on the button itself or its button group take precedence. `button.size` takes precedence over ConfigProvider's `size` and affects buttons only. Switch the type below to compare: ```vue ``` When both `button.size` and `size` are provided, buttons use `button.size` while other controls use `size`: ```vue ``` ## Switching Languages There are 79 built-in locales. See the [Internationalization guide](/en/guide/i18n.md) for the full list and on-demand imports. Changing `locale` immediately updates descendant component text. Explicit text props take precedence; application data and date formats are not translated. ```vue ``` ## Nested Locales A nested locale affects only its descendants. Below, the outer section uses English while the nested date picker uses Traditional Chinese. The outermost ConfigProvider determines the locale for components invoked through functions; nested providers do not change it. ```vue ``` ## Overriding Individual Messages `locale` accepts a partial locale. Missing keys are resolved from outer ConfigProviders, the locale configured through `app.use`, and finally the default Simplified Chinese locale, in that order. Placeholders such as `{total}` are replaced with their values. ```vue ``` ## Overlay Stacking `zIndex` is the base stacking level for internal overlays, applied as an inline style on their root elements. The first overlay uses this value, and subsequently opened automatic levels appear above currently visible layers. When a layer is hidden, automatic levels are rearranged by opening order; explicit zIndex values are preserved. You can also configure zIndex when installing the application, with a local ConfigProvider taking precedence. ```vue ``` ## Reactivity and Nesting Prop updates affect descendant components. ConfigProviders can be nested: omitted settings inherit from the outer provider, and explicit settings use the inner provider's value. Change the outer size below: ```vue ``` ## Theme `theme` sets `data-theme` on ``, equivalent to calling `document.documentElement.setAttribute('data-theme', theme)`. It affects the whole page, not only the provider's descendants. Omitting `theme` leaves the page theme unchanged. Unmounting the provider or removing the prop restores the value from before it took control. It is usually placed at the application root, for example ``. Selecting Dark changes every component on this page to the dark theme. Select Not provided or leave the page to restore the previous theme: ```vue ``` ## Reading Configuration in Custom Components ```ts import { useGlobalConfig } from '@nscode/handy-ui' // Call at the top level of setup; returns undefined outside ConfigProvider const config = useGlobalConfig() const size = computed(() => config?.value.size ?? 'default') ``` `ConfigViewer` below is a custom component that displays the configuration it reads. Inside ConfigProvider, it reads the surrounding settings and follows their updates. Outside a provider, it reads `undefined`: ```vue ``` ## Component Defaults `defaults` uses registered component names without the Hui prefix and camelCase prop names. The 25 supported components are Button, Input, Select, SelectInput, CascaderPanel, AudioPlayer, VideoPlayer, Schedule, DatePicker, Pagination, Form, FormItem, Modal, Drawer, Tooltip, Popconfirm, Upload, Card, Descriptions, Empty, Table, RichContent, RichEditor, ImageCropper, and ImageCropperDialog. The type map covers every registered component. Names that have not been integrated produce a development warning; their settings do not take effect ahead of implementation. Ordinary props resolve in this order: explicit prop → nearest merged component default → built-in component value. Explicit `undefined` skips that component default and retains the existing prop parsing and inheritance behavior. An empty string, false, and 0 are also explicit values. Replacing configuration or adding and deleting its keys in place updates the components. Function values remain props and are not called as factories. Nested providers merge shallowly by component and prop. An inner value replaces the same outer prop; an object-valued prop is replaced as a whole. Each layer first normalizes the legacy `button` setting into `defaults.Button`, then merges its new defaults, so the new setting wins within that layer. An explicitly supplied inner `size`, including undefined, blocks inherited common component sizes; a component size configured by that same inner layer still applies. Drawer.size is a panel length, so this common-size reset does not remove it. Inherited props keep their existing chain: Button.type first reads ButtonGroup. FormItem first reads actual Form settings for label position, label width, error placement, and message visibility. When Form has not configured a field, its built-in fallback does not hide the FormItem default. Controlled state, disabled/readonly, business data, and initial state cannot be configured through defaults. Both types and runtime reject them, including modelValue, visible, selectedKeys, fileList, model, data, options, columns, rules, dependencies, prop, schema, and defaultValue. A component's own width, colors, appearance, and policy props remain configurable; global defaults do not create implicit form state. The merged components retain their own data boundaries. RichContent.html cannot be supplied through defaults. RichEditor rejects modelValue, uploadImage, extensions, and starterKit. ImageCropper rejects src, zoom, and rotate; ImageCropperDialog also rejects visible. Supply those values, image sources, upload adapters, and editor initialization extensions explicitly on the relevant instance. Disabling and read-only state continue to use the shared restrictions above. Buttons, inputs, selectors, tooltips, and other controls used internally by the library retain their own baseline props. Public Button defaults such as href, loading, and debounce, or an Input password default, therefore do not change internal operations. Explicit application configuration still overrides that baseline, and components supplied through user slots still read their provider. Function-based Modal.open, messages, notifications, and message boxes do not read these defaults; their explicit call options retain precedence. Locale, overlay stacking, and application-context behavior keep their existing contracts. ```vue ``` Application installation can also provide the outermost defaults. Providers inside the component tree continue to override them layer by layer: ```ts import { createApp } from 'vue' import HandyUI from '@nscode/handy-ui' import App from './App.vue' createApp(App) .use(HandyUI, { defaults: { Button: { type: 'primary' }, Input: { clearable: true }, Table: { stripe: true } } }) .mount('#app') ``` ## Props | Prop | Type | Default | Description | | -------- | --------------------------------- | ----------- | ------------------------------------------------------------------------------------------------------------------ | | theme | `'light' \| 'dark'` | — | Page theme; leaves the page theme unchanged when omitted | | size | `'large' \| 'default' \| 'small'` | `'default'` | Default component size; an explicit component size takes precedence | | zIndex | `number` | `2000` | Overlay z-index; see the overlay stacking description | | button | `ConfigProviderButtonConfig` | `{}` | Legacy button `size` and `type`, merged per prop into `defaults.Button` | | defaults | `HuiComponentDefaults` | `{}` | Default props by component name; see Component Defaults for the supported set and inheritance rules | | locale | `HuiLocaleInput` | — | Full or partial locale; the outermost provider also determines the locale for components invoked through functions | Omitted settings inherit from the outer ConfigProvider, then fall back to the defaults in the table. ## Slots | Slot | Description | | ------- | --------------------------------------------------------------------- | | default | Content to configure. The component renders no additional DOM element | ## Types Public types use the component prefix. Compatibility mappings are `ThemeMode` → `ConfigProviderThemeMode`, `Size` → `ComponentSize`, and `ButtonConfig` → `ConfigProviderButtonConfig`. The old names remain importable from `@nscode/handy-ui`, are marked `@deprecated`, and will be removed in 1.0. ```ts import type { ConfigProviderProps, ConfigProviderContext, ConfigProviderButtonConfig, ConfigProviderThemeMode, HuiLocale, HuiLocaleInput, HuiComponentDefaults, HuiComponentPropsMap, HuiComponentDefaultName, HandyUIInstallOptions } from '@nscode/handy-ui' interface ConfigProviderButtonConfig { size?: 'large' | 'default' | 'small' type?: 'default' | 'primary' | 'success' | 'warning' | 'danger' | 'info' | 'help' } // Values returned by useGlobalConfig() interface ConfigProviderContext { locales: HuiLocaleInput[] // Locales ordered from innermost to outermost theme: 'light' | 'dark' | undefined // undefined when no provider specifies theme size: 'large' | 'default' | 'small' zIndex: number button: ConfigProviderButtonConfig defaults?: HuiComponentDefaults } ``` --- # Divider Separate paragraphs or items within a row. ## Import ```ts import { HuiDivider } from '@nscode/handy-ui' ``` ## Basic Usage The default divider is a horizontal 1px line in the theme's border color, with 16px of space above and below. ```vue ``` ## With Text Content in the default slot appears within the line. Set `content-position` to `left`, `center` (the default), or `right`. A divider aligned to either side leaves a 16px line on that side. ```vue ``` The slot also accepts elements such as icons and tags: ```vue ``` ## Line Styles Set `border-style` to `solid` (the default), `dashed`, or `dotted`. Each style works with or without text, at any content position. ```vue ``` ## Vertical Dividers Use `direction="vertical"` to separate items in a row. A vertical divider leaves 8px of space on each side. ```vue ``` Vertical dividers support all three line styles: ```vue ``` A vertical divider can also contain text, with 12px of space above and below it. The two line segments share the remaining height equally. Inside a flex container with a defined height, the divider stretches to the container's height: ```vue ``` ## Ancestor Variable Overrides Set `--hui-divider-border-style` on the component or any ancestor to override the line style of horizontal and vertical dividers. Without this variable, the `border-style` prop provides the `solid`/`dashed`/`dotted` default. The public variable takes precedence; the prop only determines the private default. Nested dividers inherit the ancestor's public configuration. ```vue ``` ## Props | Prop | Type | Default | Description | | --------------- | --------------------------------- | -------------- | ---------------- | | direction | `'horizontal' \| 'vertical'` | `'horizontal'` | Direction | | contentPosition | `'left' \| 'center' \| 'right'` | `'center'` | Content position | | borderStyle | `'solid' \| 'dashed' \| 'dotted'` | `'solid'` | Line style | ## Slots | Slot | Description | | ------- | ------------------------------------- | | default | Text or content shown within the line | ## Types ```ts import type { DividerProps } from '@nscode/handy-ui' ``` --- # FloatButton A circular or square button floating over the page, often placed in the bottom-right corner for global actions such as Help, Feedback, or Create. It supports tooltips, badges, and an expandable menu of child buttons. Use `HuiFloatButtonGroup` to arrange several buttons vertically. ## Import ```ts import { HuiFloatButton, HuiFloatButtonGroup } from '@nscode/handy-ui' ``` ## Basic Usage `icon` is an icon name. `tooltip` is the text shown on hover or focus, on the left by default. The default `position="fixed"` uses offsets such as `right` and `bottom`; numbers are pixels and strings are used as provided, such as `'10%'`. To keep buttons within the example area, examples on this page use `position="absolute"` relative to a `position: relative` container, or `position="relative"` to keep the button in the normal layout. The next section compares all three positioning modes. ```vue ``` For an icon-only button, `tooltip` supplies the accessible name (`aria-label`). Provide either `tooltip` or an explicit `aria-label`; otherwise, a warning is logged in development. ## Positioning `position` accepts: - `fixed` (the default): fixed to the browser viewport and unaffected by page scrolling. Its z-index follows `HuiConfigProvider.zIndex` (2000 by default). - `absolute`: positioned relative to the nearest positioned ancestor (an element whose `position` is not `static`). Use `left`, `right`, `top`, and `bottom` to place it within that region. - `relative`: remains in the normal layout alongside surrounding content. Offsets such as `left` are relative to its original position. Enable the switch below to show the `fixed` button in the browser window's bottom-right corner: ```vue ``` ## Types and Shapes - `type`: `default` (the default, with a white background) or `primary` (a primary-colored background with a white icon). - `shape`: `circle` (the default) or `square` (a rounded square with an 8px corner radius). ```vue ``` ## Tooltip Placement `tooltip-placement` sets the tooltip position, defaulting to `left`. It supports 12 placements and flips to the other side when there is insufficient space. Hover over the buttons below; their descriptions identify each placement: ```vue ``` ## Descriptions and Dimensions `description` is the small 12px text below the icon, usually used with `shape="square"`. When a description is present, the icon shrinks from 20px to 16px. A 40px-wide button fits about two Chinese characters; longer text is ellipsized, so increase `width` as needed. `width` and `height` both default to 40; numbers are pixels and strings are used as provided. The button grows taller if its content requires more space. The `description` slot allows custom content and takes precedence over the prop. Use the default slot for a custom icon or text. When the slot is provided, `icon` is not rendered. ```vue ``` ## Badges `badge` displays an `HuiBadge` in the top-right corner: - A number or string displays its content; numbers above 99 display `99+`. - `true`, or the `badge` attribute without a value, displays a dot. - `false` and `0` hide the badge. Pass the string `'0'` to display zero. On circular buttons, the badge sits on the circumference at the upper-right 45° position. On square buttons, it aligns with the outer corner. ```vue ``` Badges are hidden from screen readers and are not included in the button's accessible name. Include the count in `aria-label` when it needs to be announced, for example `:aria-label="'Notifications, ' + unread + ' unread'"`. ## Links Providing `href` renders an ``. With `target="_blank"`, `rel="noopener noreferrer"` is added automatically unless an explicit `rel` is provided. ```vue ``` ## Expandable Menus Place child `HuiFloatButton` components in the `menu` slot. They are arranged vertically above the main button. Click the main button to expand or collapse them; its icon changes to `close` while expanded. - `menu-trigger="click"` (the default): click to expand, then click again to collapse. Pressing the pointer elsewhere or moving focus away also closes the menu. - `menu-trigger="hover"`: pointer entry expands the menu; leaving closes it after 100ms. Moving onto a child button keeps it open. Clicking the main button also opens it for devices without hover, but does not close it. - Use `v-model:visible` to read and update the expanded state. - Clicking a child button does not close the menu. Set `visible` to `false` to close it. Child buttons are positioned by the menu, so they do not need `position`, `right`, or similar props. Their `shape` follows the main button when omitted. The left example opens on click; the right opens on hover and uses a square shape, which its children inherit: ```vue ``` ## Button Groups `HuiFloatButtonGroup` arranges floating buttons vertically. The group controls positioning through `position`, `left`, `right`, `top`, and `bottom`, using the same rules as `HuiFloatButton`. Positioning props on individual buttons inside the group have no effect. - `shape="circle"` (the default): circular buttons with a 16px gap and individual shadows. - `shape="square"`: square buttons form one connected block with separators. The shadow and outer rounded corners belong to the group. All buttons in the group follow its `shape`; an individual button's `shape` has no effect. The left group below uses `circle`, and the right uses `square`: ```vue ``` The group's root has `role="group"`. Give it an accessible name with an attribute such as `aria-label="Quick actions"`. ## Combining with Back to Top Use `HuiBacktop` for a standalone back-to-top button. It monitors scrolling and appears after `visibility-height`, with the same 40×40 circular shape, border, shadow, and icon size as `HuiFloatButton`. Offset separate buttons to avoid overlap, for example `bottom: 40` for `HuiBacktop` and `bottom: 96` for a floating button. `HuiBacktop` uses its own `fixed` positioning and **cannot be placed directly in `HuiFloatButtonGroup`**: it would remain fixed to the viewport using its own `right` and `bottom`, rather than joining the group. For a grouped back-to-top action, use `HuiFloatButton` with `icon="arrow-up"` and track the scroll position yourself. Scroll the box below past 200px to reveal the action: ```vue ``` ## Focus and Blur Call `focus()` or `blur()` through the ref to focus or blur the main button. Focusing it shows its tooltip. ```vue ``` ## Keyboard Interaction - The main button is a native `