feat: initialize Vue component library and aligned documentation
This commit is contained in:
@@ -0,0 +1,142 @@
|
||||
---
|
||||
title: Button 按钮
|
||||
description: 可点击的按钮组件,支持多种变体与状态
|
||||
component: button
|
||||
group: 组件
|
||||
---
|
||||
|
||||
## 用法
|
||||
|
||||
```vue
|
||||
<script setup lang="ts">
|
||||
import { Button } from "@heroui-vue/components";
|
||||
</script>
|
||||
```
|
||||
|
||||
<ComponentPreview name="button-basic" />
|
||||
|
||||
## 示例
|
||||
|
||||
### 变体
|
||||
|
||||
<ComponentPreview name="button-variants" />
|
||||
|
||||
### 尺寸
|
||||
|
||||
<ComponentPreview name="button-sizes" />
|
||||
|
||||
### 带图标
|
||||
|
||||
<ComponentPreview name="button-with-icons" />
|
||||
|
||||
### 仅图标
|
||||
|
||||
<ComponentPreview name="button-icon-only" />
|
||||
|
||||
### 加载中
|
||||
|
||||
此例固定展示上传中的外观;加载期间阻止重复提交,但保留键盘焦点。要体验开始、完成和再次上传,请使用下一例。
|
||||
|
||||
<ComponentPreview name="button-loading" />
|
||||
|
||||
### 加载中(点击触发)
|
||||
|
||||
点击“上传文件”后进入加载状态,2 秒后恢复,可重复操作。
|
||||
|
||||
<ComponentPreview name="button-loading-state" />
|
||||
|
||||
### 宽度充满
|
||||
|
||||
<ComponentPreview name="button-full-width" />
|
||||
|
||||
### 禁用状态
|
||||
|
||||
<ComponentPreview name="button-disabled" />
|
||||
|
||||
### 社交媒体按钮
|
||||
|
||||
<ComponentPreview name="button-social" />
|
||||
|
||||
### 渲染函数
|
||||
|
||||
Vue 使用 `asChild` 将按钮属性与交互合并到一个自定义原生 button,作用域插槽提供状态。对应上游 render 函数示例,不将 render prop 原样搬入 Vue。
|
||||
|
||||
<ComponentPreview name="button-render-function" />
|
||||
|
||||
### 添加自定义变体
|
||||
|
||||
可通过包装组件并添加自定义变体来扩展组件。下面使用与上游相同的 `tv` 扩展方式,提供额外的圆角与尺寸配置。
|
||||
|
||||
<ComponentPreview name="button-custom-variants" />
|
||||
|
||||
### 添加涟漪效果
|
||||
|
||||
通过组合添加涟漪。本示例使用 Vue 和 CSS 实现,支持指针、Enter 和空格触发;不直接依赖上游 React 的 m3-ripple,减少动态效果时缩短动画。
|
||||
|
||||
<ComponentPreview name="button-ripple-effect" />
|
||||
|
||||
## 自定义样式
|
||||
|
||||
### Tailwind CSS
|
||||
|
||||
<ComponentPreview name="button-custom-styles" />
|
||||
|
||||
使用标准 `class` 属性添加工具类。组件保持上游的尺寸、间距、BEM 结构与状态钩子;类名前缀改为 `hv-`。
|
||||
|
||||
```vue
|
||||
<Button class="rounded-lg">自定义圆角</Button>
|
||||
```
|
||||
|
||||
### 全局 CSS
|
||||
|
||||
```css
|
||||
@layer components {
|
||||
.hv-button--primary {
|
||||
--button-bg: oklch(0.6 0.2 300);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 样式参考
|
||||
|
||||
基础类为 `.hv-button`,变体为 `.hv-button--primary` 等;尺寸为 `.hv-button--sm` / `md` / `lg`。支持 `.hv-button--icon-only` 和 `.hv-button--full-width`。
|
||||
|
||||
### 交互状态
|
||||
|
||||
保留 `data-hovered`、`data-pressed`、`data-focused`、`data-focus-visible`、`data-pending` 状态;键盘焦点样式与鼠标焦点区分。加载期间保留焦点并阻止重复点击,通过 aria-disabled 呈现半透明的原变体颜色。
|
||||
|
||||
## API 参考
|
||||
|
||||
### Button
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ------------ | --------------------------------------------------------------------------------------------- | ----------- | --------------------------------------------- |
|
||||
| `variant` | `'primary' \| 'secondary' \| 'tertiary' \| 'outline' \| 'ghost' \| 'danger' \| 'danger-soft'` | `'primary'` | 视觉样式变体 |
|
||||
| `size` | `'sm' \| 'md' \| 'lg'` | `'md'` | 按钮尺寸 |
|
||||
| `fullWidth` | `boolean` | `false` | 是否占满容器宽度 |
|
||||
| `isDisabled` | `boolean` | `false` | 是否禁用 |
|
||||
| `isPending` | `boolean` | `false` | 是否处于加载状态 |
|
||||
| `isIconOnly` | `boolean` | `false` | 是否仅包含图标 |
|
||||
| `asChild` | `boolean` | `false` | 将属性与交互合并到默认插槽中唯一的原生 button |
|
||||
| `type` | `'button' \| 'submit' \| 'reset'` | `'button'` | 原生按钮类型 |
|
||||
|
||||
### 事件与插槽
|
||||
|
||||
Vue 使用 `@click` 和默认作用域插槽。插槽提供 `isPending`、`isPressed`、`isHovered`、`isFocused`、`isFocusVisible`、`isDisabled`。原生属性、class、style、事件透传至 button。
|
||||
|
||||
`onPress` / PressEvent 与 `@click` 的事件模型不同,不宣称完全等价。初版 `disabled` / `loading` 继续作为兼容别名;新代码使用 `isDisabled` / `isPending`。`isPending` 不自动插入加载图标,采用上游的组合方式。`loading` 是相同加载语义的兼容别名,额外自动显示旋转图标;不会设置原生 disabled。`asChild` 下内容由调用者完整组合,默认插槽必须只包含一个原生 button。
|
||||
|
||||
### 作用域插槽状态
|
||||
|
||||
| 参数 | 类型 | 描述 |
|
||||
| ---------------- | --------- | -------------------------------- |
|
||||
| `isPending` | `boolean` | 是否处于加载状态 |
|
||||
| `isPressed` | `boolean` | 是否正在按下 |
|
||||
| `isHovered` | `boolean` | 是否悬停 |
|
||||
| `isFocused` | `boolean` | 是否聚焦 |
|
||||
| `isFocusVisible` | `boolean` | 是否显示键盘焦点指示器 |
|
||||
| `isDisabled` | `boolean` | 是否由禁用属性禁用,不与加载混用 |
|
||||
|
||||
## 相关组件
|
||||
|
||||
[Card 卡片](/components/card) · [Input 输入框](/components/input) · [Switch 开关](/components/switch)
|
||||
Reference in New Issue
Block a user