mcpField
H
heroui

heroui

github.com/thatjuan设计与 UI142 次安装3 周前更新
代码仓库

关于 heroui

heroui 是介绍 HeroUI v3 的 skill;HeroUI v3 是面向 React Web 和 React Native 应用的 UI 组件库。内容涵盖无障碍组件、安装、组合方式、样式和表单验证。

主要功能

  1. 01Web 与原生组件目录
  2. 02复合组件组合方式
  3. 03BEM、变体与 Tailwind 样式
  4. 04主题与自定义指南
  5. 05表单验证模式

适用场景

  1. 01构建 React Web 界面
  2. 02创建 React Native 移动界面
  3. 03自定义组件样式与主题
  4. 04添加带验证的表单

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/thatjuan/agent-skills --skill heroui

安装后在 Claude Code 中输入/heroui确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

README.md
references/
native-components.md
native-setup.md
react-components.md
react-setup.md
theming-and-styling.md

详细介绍

HeroUI v3

一个适用于 React(Web)和 React Native(移动端)的开源 UI 组件库。基于 Tailwind CSS v4 和 React Aria Components 构建,提供 75+ 个无障碍且可自定义的 Web 组件,以及 40+ 个原生组件。

技术栈

平台包要求
React(Web)@heroui/react、@heroui/stylesReact 19+、Tailwind CSS v4
React Nativeheroui-nativeReact Native、Uniwind、react-native-reanimated 4.1+、react-native-gesture-handler 2.28+

快速设置

React(Web)
npm i @heroui/react @heroui/styles
/* globals.css — order matters */
@import "tailwindcss";
@import "@heroui/styles";
import { Button } from "@heroui/react";

function App() {
  return <Button>Click me</Button>;
}
React Native
npm install heroui-native react-native-reanimated@^4.1.1 react-native-gesture-handler@^2.28.0 react-native-worklets@^0.5.1 react-native-safe-area-context@^5.6.0 react-native-svg@^15.12.1 tailwind-variants@^3.2.2 tailwind-merge@^3.4.0
/* global.css */
@import "tailwindcss";
@import "uniwind";
@import "heroui-native/styles";
@source "./node_modules/heroui-native/lib";
import { HeroUINativeProvider } from "heroui-native";
import { GestureHandlerRootView } from "react-native-gesture-handler";
import { Button } from "heroui-native";

export default function App() {
  return (
    <GestureHandlerRootView style={{ flex: 1 }}>
      <HeroUINativeProvider>
        <Button onPress={() => console.log("Pressed!")}>Get Started</Button>
      </HeroUINativeProvider>
    </GestureHandlerRootView>
  );
}

详细的设置说明请参阅 react-setup.md 和 native-setup.md。

组件架构

HeroUI v3 使用复合组件组合,并采用点号表示法:

<Modal>
  <Button>Open</Button>
  <Modal.Backdrop>
    <Modal.Container>
      <Modal.Dialog>
        <Modal.Header>
          <Modal.Heading>Title</Modal.Heading>
        </Modal.Header>
        <Modal.Body>Content</Modal.Body>
        <Modal.Footer>
          <Button slot="close">Close</Button>
        </Modal.Footer>
      </Modal.Dialog>
    </Modal.Container>
  </Modal.Backdrop>
</Modal>
三种导入模式
// 1. Compound (recommended)
<Alert>
  <Alert.Icon />
  <Alert.Content>
    <Alert.Title>Success</Alert.Title>
  </Alert.Content>
</Alert>

// 2. With .Root suffix
<Alert.Root>
  <Alert.Icon />
</Alert.Root>

// 3. Named exports
import { AlertRoot, AlertIcon, AlertContent, AlertTitle } from "@heroui/react";
类型导入
import type { ButtonRootProps, AvatarRootProps } from "@heroui/react";

React Web 组件(75+)

类别组件
按钮Button、ButtonGroup、CloseButton、ToggleButton、ToggleButtonGroup
集合Dropdown、ListBox、TagGroup
颜色ColorArea、ColorField、ColorPicker、ColorSlider、ColorSwatch、ColorSwatchPicker
控件Slider、Switch
数据展示Badge、Chip、Table
日期和时间Calendar、DateField、DatePicker、DateRangePicker、RangeCalendar、TimeField
反馈Alert、Meter、ProgressBar、ProgressCircle、Skeleton、Spinner、Toast
表单Checkbox、CheckboxGroup、Description、ErrorMessage、FieldError、Fieldset、Form、Input、InputGroup、InputOTP、Label、NumberField、RadioGroup、SearchField、TextField、TextArea
布局Card、Separator、Surface、Toolbar
媒体Avatar
导航Accordion、Breadcrumbs、Disclosure、DisclosureGroup、Link、Pagination、Tabs
覆盖层AlertDialog、Drawer、Modal、Popover、Tooltip
选择器Autocomplete、ComboBox、Select
排版Kbd
工具ScrollShadow

有关组件结构、属性和用法模式,请参阅 react-components.md。

React Native 组件(40+)

类别组件
按钮Button、CloseButton、LinkButton
集合Menu、TagGroup
控件Slider、Switch、Checkbox
数据展示Chip、Avatar
反馈Alert、Spinner、Skeleton、SkeletonGroup、Toast
表单ControlField、Description、FieldError、Input、InputGroup、InputOTP、Label、RadioGroup、SearchField、Select、TextArea、TextField
布局Card、Separator、Surface、Accordion、ListGroup、Tabs
覆盖层BottomSheet、Dialog、Popover
工具PressableFeedback、ScrollShadow

有关原生组件的详细信息,请参阅 native-components.md。

样式系统

HeroUI v3 提供三种样式设置方式:

1. BEM 类
<button className="button button--primary button--lg">Click</button>

类名模式:.{block}、.{block}__{element}、.{block}--{modifier}

2. 变体函数(类型安全)
import { buttonVariants } from "@heroui/styles";

<a className={buttonVariants({ variant: "primary", size: "lg" })} href="/about">
  About
</a>

变体函数与框架无关,可用于 Vue、Svelte 和原生 HTML。

3. Tailwind CSS 类 + className 属性
<Button className="rounded-full shadow-lg">Styled</Button>
自定义变体
import { buttonVariants, tv } from "@heroui/styles";

const myButton = tv({
  extend: buttonVariants,
  base: "font-semibold shadow-md",
  variants: {
    radius: { lg: "rounded-lg", md: "rounded-md" },
  },
});
用于自定义元素的 render 属性
<Button
  render={(domProps, { isPressed }) => (
    <motion.button {...domProps} animate={{ scale: isPressed ? 0.9 : 1 }} />
  )}
>
  Animated
</Button>

有关主题设置、CSS 变量、深色模式、自定义主题和组件级覆盖,请参阅 theming-and-styling.md。

常见属性模式

交互状态(数据属性)
状态属性CSS 伪类
悬停[data-hovered="true"]:hover
按下[data-pressed="true"]:active
焦点[data-focus-visible="true"]:focus-visible
禁用[aria-disabled="true"]:disabled
已选中[data-selected="true"]—
打开[data-open="true"]—
进入中[data-entering]—
退出中[data-exiting]—
事件处理器

HeroUI 使用 React Aria 的按压事件,而不是原生点击事件:

<Button onPress={(e) => console.log("pressed")} />
覆盖层状态管理
import { useOverlayState } from "@heroui/react";

const state = useOverlayState({ defaultOpen: false });
// state.isOpen, state.open(), state.close(), state.toggle(), state.setOpen()

表单验证

import { Form, TextField, Button } from "@heroui/react";

<Form validationBehavior="aria" onSubmit={handleSubmit}>
  <TextField name="email" isRequired>
    <Label>Email</Label>
    <Input />
    <FieldError />
  </TextField>
  <Button type="submit">Submit</Button>
</Form>

两种验证模式:"native"(阻止提交)和 "aria"(实时显示错误)。

文档资源

资源URL
React 文档https://www.heroui.com/docs/react/getting-started
Native 文档https://www.heroui.com/docs/native/getting-started
所有 React 组件https://www.heroui.com/docs/react/components
所有 Native 组件https://www.heroui.com/docs/native/components
主题构建器https://www.heroui.com/themes
迁移(v2 到 v3)https://www.heroui.com/docs/react/migration

评论

支持 Markdown