@dotnaos/ui-base

中文文档
0.0.28发布于 2026/09/16MITTypeScriptES Module近 30 天下载 4325

Generic web UI foundations and controls for DotNaos.

原始使用文档
文档目录8 节
  1. Install
  2. Import
  3. Autocomplete
  4. QR codes
  5. Geometry capabilities
  6. CDN usage
  7. Build
  8. Licensing

@dotnaos/ui-base

Generic web foundations for DotNaos interfaces, built on top of the shared @dotnaos/design package.

Install

bun add @dotnaos/ui @dotnaos/ui-base

Web apps should import the complete public UI stylesheet before rendering the components:

import "@dotnaos/ui/styles.css";

Import

import { Button, Card, ThemeProvider } from "@dotnaos/ui-base";

The package exposes one web component family. Layout structures and native components live in their own packages so Base stays small and domain-neutral:

import { Button, Card } from "@dotnaos/ui-base";
import { ContentPageLayout } from "@dotnaos/ui-layout";
import { NativeContainer } from "@dotnaos/ui-native";

Strict component identity and finite Slot contracts are built into the normal components. There is no separate strict-mode component tree or public strict entrypoint.

Button intent and shape are expressed as variants of one component:

<Button variant="primary" label="Save" icon="save" onPress={save} />
<Button variant="secondary" label="Cancel" onPress={cancel} />
<Button variant="ghost" label="More" iconAfter="chevronDown" onPress={open} />
<Button variant="icon" accessibilityLabel="Delete item" icon="trash" onPress={remove} />

The public button API accepts structured data only. Icons must use names from the DotNaos icon catalog.

Autocomplete

Autocomplete is a controlled text input with floating, fuzzy-matched suggestions:

import { Autocomplete } from "@dotnaos/ui-base";

<Autocomplete
  accessibilityLabel="Project"
  value={query}
  onValueChange={setQuery}
  options={[
    { value: "Design System", label: "Design System" },
    { value: "DevOps Client", label: "DevOps Client" },
  ]}
/>

Set keepOpenOnSelect for continuous completion, such as browsing successive path segments. New suggestions appear after selection without another keystroke; Escape and blur still close them. While focused, the floating panel stays mounted during filtering and fetching. Loading keeps the previous results visible but inactive, with a small neutral spinner in the input; the first request uses quiet placeholders. Empty results show No suggestions. Neither state is selectable. Matched characters use a subtle medium weight in the surrounding text color, without underlines.

Optional backAction adds a separate navigation button above the list. It is never an automatic result or part of arrow-key wrapping: a fresh Up press from the first result focuses it, Enter activates it, and Down returns to the first result. Held Up presses stop at the first result. Escape closes the popup and returns focus to the input. Enable horizontalNavigation to accept the active result with Right and invoke backAction with Left while the popup is open. Modifier keys, text selections, and composition retain text-editing behavior; held horizontal arrows do not skip through multiple levels.

The first enabled result is selected automatically. Arrow keys navigate, Enter accepts, and Escape dismisses. Tab normally leaves the input; opt into repeated Tab completion with completeOnTab (Shift+Tab always leaves). Accepting a result writes its value into the input and calls onSelect if supplied. Matching characters in the label are highlighted.

Load remote or filesystem options in the host, pass loading while pending, and discard stale responses there. Use query when only part of the input should be matched, such as the last path segment. The component itself performs no network or filesystem access.

QR codes

QrCode renders a self-contained SVG without contacting an external QR service. It keeps the required four-module quiet zone and fixed black-on-white contrast for reliable scanning.

import { QrCode } from "@dotnaos/ui-base";

<QrCode
  accessibilityLabel="Open Devbox Mobile"
  value="https://devbox.os-pc.vpn.os-home.net/mobile"
  size={184}
/>

Use errorCorrectionLevel="H" when the code needs additional damage tolerance.

Geometry capabilities

Rounded geometry is expressed through small capability interfaces instead of repeated component-specific props. RadiusProps provides radius="theme" | "full"; AspectProps provides aspect="auto" | "square"; and GeometryProps combines both. The defaults are theme and auto.

theme follows the active theme's corner treatment. full always uses a fully rounded corner and is independent of the global squircle or superellipse setting. The aspect ratio determines the silhouette:

<Button variant="primary" label="Continue" radius="full" />
<Surface radius="full">Pill surface</Surface>
<Surface radius="full" aspect="square">Circular surface</Surface>

Container, Surface, Box, and Card expose both capabilities. Text buttons, Input, Textarea, and the Select trigger expose only radius. Components with a fixed silhouette use the same contract internally: icon buttons are full + square, while chips, slider parts, and tab pills are full + auto. Content and layout-only primitives do not expose geometry props.

CDN usage

Use the public npm package through npm-compatible CDNs:

import { Button } from "https://esm.sh/@dotnaos/ui-base@VERSION";
import { Button } from "https://cdn.jsdelivr.net/npm/@dotnaos/ui-base@VERSION/+esm";
import { Button } from "https://unpkg.com/@dotnaos/ui-base@VERSION/dist/index.js";

The unpkg entrypoint serves the built ESM file directly. Because react, react-dom, and react/jsx-runtime remain peer/runtime imports, esm.sh and jsDelivr +esm provide the smoothest browser CDN experience.

Build

bun --filter @dotnaos/ui-base build

Licensing

This package is published under the MIT license and includes LICENSE and THIRD_PARTY_NOTICES.md in the npm tarball.

The package owns its component implementations directly and does not wrap or select another component library.

版本与发布记录

@dotnaos/ui-base 共发布 19 个版本,首次发布于 2026/08/16;过去 12 个月发布了 19 个版本。

版本发布日期距今
0.0.28latest2026/09/161 个月前
0.0.272026/09/161 个月前
0.0.262026/09/062 个月前
0.0.252026/09/062 个月前
0.0.242026/09/052 个月前
0.0.232026/09/012 个月前

关于 @dotnaos/ui-base 的常见问题

@dotnaos/ui-base 是什么?

Generic web UI foundations and controls for DotNaos.

如何安装 @dotnaos/ui-base?

在项目目录运行 npm install @dotnaos/ui-base,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(^18.0.0 || ^19.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@dotnaos/ui-base 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@dotnaos/ui-base 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@dotnaos/ui-base 可以商用吗?

@dotnaos/ui-base 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@dotnaos/ui-base 的下载量有多少?

根据 npm 官方下载统计,@dotnaos/ui-base 在 2026/10/13 – 2026/11/11 这 30 天内被下载 4,325 次,日均约 144 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@dotnaos/ui-base 还在维护吗?

最新版本 0.0.28 发布于 2026/09/16(1 个月前);至今共发布 19 个版本,其中过去 12 个月发布了 19 个;首次发布于 2026/08/16。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。