aui-components
ComponentsUI

Button

按钮组件,支持 5 种变体和 6 种尺寸

Button 是对 @base-ui/react/button 的封装,通过 class-variance-authority 提供丰富的样式变体。

引入

import { Button } from "aui-components";

基本用法

<Button>Click me</Button>
<Button variant="outline">Outline</Button>
<Button size="lg">Large</Button>

Props

属性类型默认值说明
focusableWhenDisabledenumfalseWhether the button should be focusable when disabled.
nativeButtonenumtrueWhether the component renders a native `<button>` element when replacing it via the `render` prop. Set to `false` if the rendered element is not a button (for example, `<div>`).
classNameenum—CSS class applied to the element, or a function that returns a class based on the component's state.
renderenum—Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render.
styleenum—Style applied to the element, or a function that returns a style object based on the component's state.
variantenumdefault—
sizeenumdefault—

变体

Variants

变体说明样式特征
default默认bg-primary text-primary-foreground
outline轮廓border-border bg-background
secondary次要bg-secondary text-secondary-foreground
ghost幽灵透明背景,hover 才显示
destructive危险操作bg-destructive/10 text-destructive
link链接风格text-primary underline-offset-4
<div className="flex gap-2">
  <Button variant="default">Default</Button>
  <Button variant="outline">Outline</Button>
  <Button variant="secondary">Secondary</Button>
  <Button variant="ghost">Ghost</Button>
  <Button variant="destructive">Destructive</Button>
  <Button variant="link">Link</Button>
</div>

Sizes

尺寸说明
defaulth-8 gap-1.5 px-2.5
xsh-6 gap-1 px-2 text-xs
smh-7 gap-1 px-2.5 text-[0.8rem]
lgh-9 gap-1.5 px-2.5
iconsize-8 — 方形图标按钮
icon-xssize-6 — 小方图标按钮
icon-smsize-7 — 中方图标按钮
icon-lgsize-9 — 大方图标按钮
<div className="flex items-center gap-2">
  <Button size="xs">Extra Small</Button>
  <Button size="sm">Small</Button>
  <Button size="default">Default</Button>
  <Button size="lg">Large</Button>
</div>

<div className="flex items-center gap-2">
  <Button size="icon-xs"><SearchIcon /></Button>
  <Button size="icon-sm"><SearchIcon /></Button>
  <Button size="icon"><SearchIcon /></Button>
  <Button size="icon-lg"><SearchIcon /></Button>
</div>

与 TooltipIconButton

TooltipIconButton 基于 Button 封装,添加了 Tooltip:

// 基础 Button
<Button variant="ghost" size="icon"><CopyIcon /></Button>

// 带 Tooltip 的 Button(推荐在聊天 UI 中使用)
<TooltipIconButton tooltip="Copy"><CopyIcon /></TooltipIconButton>

相关链接

On this page