vxui-react
v1.3.1
Published
A general-purpose React UI framework rebuilt from VXUI principles.
Maintainers
Readme
VXUI React · v1.3.1
官网:ui.vx.link | GitHub:tmplink/vxui_react | English
VXUI React 是一套适合后台、运营台、仪表盘和内部工具的通用 UI 组件库。
文档内容现在按流行 UI 框架的写法组织:先给安装方式,再给最小可运行示例,最后给分场景的组件代码。
安装
从 npm 安装:
npm install vxui-reactreact 和 react-dom 需要由宿主应用提供。
引入样式
安装完成后,包名仍然保持为 vxui-react。
import 'vxui-react/styles.css';基础接入
// src/main.tsx
import ReactDOM from 'react-dom/client';
import { ThemeProvider, ToastProvider, themePresets } from 'vxui-react';
import App from './App';
import 'vxui-react/styles.css';
ReactDOM.createRoot(document.getElementById('root')!).render(
<ThemeProvider themes={themePresets} defaultTheme="light">
<ToastProvider>
<App />
</ToastProvider>
</ThemeProvider>,
);第一个页面
import {
AppShell,
Button,
Card,
CardContent,
CardHeader,
CardTitle,
Input,
} from 'vxui-react';
const navSections = [
{
title: 'Workspace',
items: [{ key: 'overview', label: 'Overview', active: true }],
},
];
export function App() {
return (
<AppShell
brand="Acme Ops"
title="Overview"
description="Build internal tools with a single shell."
navSections={navSections}
headerActions={<Button size="sm">Create order</Button>}
>
<Card>
<CardHeader>
<CardTitle>Queue health</CardTitle>
</CardHeader>
<CardContent>
<Input label="Search orders" placeholder="PO-1024" />
</CardContent>
</Card>
</AppShell>
);
}表单示例
import { Button, Checkbox, Input, Select, Textarea } from 'vxui-react';
export function ProjectForm() {
return (
<form style={{ display: 'grid', gap: 16 }}>
<Input label="Project name" placeholder="Northwind migration" />
<Select
label="Release track"
defaultValue="stable"
options={[
{ value: 'stable', label: 'Stable' },
{ value: 'preview', label: 'Preview' },
{ value: 'internal', label: 'Internal' },
]}
/>
<Textarea
label="Summary"
rows={4}
placeholder="Describe what changed in this release."
/>
<Checkbox label="Notify operators after publish" defaultChecked />
<Button type="submit">Save changes</Button>
</form>
);
}反馈示例
import { Alert, Button, Progress, useToast } from 'vxui-react';
export function PublishActions() {
const { push } = useToast();
return (
<div style={{ display: 'grid', gap: 16 }}>
<Alert variant="info" title="Ready to publish">
Confirm the release notes before you notify customers.
</Alert>
<Progress label="Rollout progress" value={72} showLabel />
<Button
onClick={() =>
push({
tone: 'success',
title: 'Release published',
description: 'Customers can see the new version now.',
})
}
>
Publish release
</Button>
</div>
);
}自定义主题
import { ThemeProvider, createTheme, themePresets } from 'vxui-react';
const themes = {
...themePresets,
ocean: createTheme('dark', {
label: 'Ocean',
tokens: {
'--vx-primary': '#38bdf8',
'--vx-primary-strong': '#0ea5e9',
'--vx-primary-soft': 'rgba(56, 189, 248, 0.16)',
'--vx-bg': '#06131f',
'--vx-surface': '#0d2236',
},
}),
};
export function Root({ children }: { children: React.ReactNode }) {
return (
<ThemeProvider themes={themes} defaultTheme="ocean">
{children}
</ThemeProvider>
);
}运行时可以通过 useTheme() 获取当前主题并切换到任意已注册主题,例如 setTheme('ocean')。
当前包含
- Layout: AppShell、Card、Separator、Breadcrumb、Pagination、Resizable、ScrollArea
- Forms: Input、Select、Checkbox、Radio、Textarea、Slider、Switch、NumberInput、TagInput、ColorPicker、DatePicker、FileUpload、Form、Rating
- Feedback: Alert、AlertDialog、Toast、Progress、Skeleton、Spinner、Stepper、Timeline、EmptyState
- Overlay: Dialog、Sheet、Popover、DropdownMenu、ContextMenu、Tooltip、HoverCard、CommandPalette、Menubar、NavigationMenu
- Data Display: Avatar、Table、Badge、Tabs、Accordion、TreeView、Carousel、Calendar
- Typography: Heading、Text、Label、CodeBlock
- Mobile: MobileShell、BottomNav、ActionSheet、MobileDrawer、MobileList
本地开发
npm install
npm run dev验证与构建
# TypeScript 类型检查
npm run typecheck
# 构建组件库(用于 npm publish)
npm run build
# 构建演示站(用于 Pages 部署,输出至 dist-demo/)
npm run build:demo