# 按钮 · JGuang UI

> 触发操作或提交表单的基础交互控件。

- 页面: https://jiguang132.com/zh/systems/jguang-ui/docs/components/radix/button
- 改编自: shadcn/ui 文档 (MIT) @ bc0705384b51252af26dcc65425b216bf5eb063c
- 说明：正文保留英文原文。

> 示例 `button-demo`: 交互预览见 https://jiguang132.com/zh/systems/jguang-ui/docs/components/radix/button


## Installation


  

**Command**


  

**Manual**


```text
Use the JGuang UI Registry URL provided on /systems/jguang-ui#install.
```


### Install the following dependencies:


```bash
npm install radix-ui
```


### Copy and paste the following code into your project.


[View complete source: components/ui/button.tsx](/r/jguang-ui/radix/button.json)


### Update the import paths to match your project setup.


## Usage

```tsx
import { Button } from "@/components/ui/button"
```

```tsx
<Button variant="outline">Button</Button>
```

## Cursor

Tailwind v4 [switched](https://tailwindcss.com/docs/upgrade-guide#buttons-use-the-default-cursor) from `cursor: pointer` to `cursor: default` for the button component.

If you want to keep the `cursor: pointer` behavior, add the following code to your CSS file:

You can also enable this during project setup with `JGuang UI Registry`.

```css showLineNumbers title="globals.css"
@layer base {
  button:not(:disabled),
  [role="button"]:not(:disabled) {
    cursor: pointer;
  }
}
```

## Size

Use the `size` prop to change the size of the button.


> 示例 `button-size`: 交互预览见 https://jiguang132.com/zh/systems/jguang-ui/docs/components/radix/button


## Default


> 示例 `button-default`: 交互预览见 https://jiguang132.com/zh/systems/jguang-ui/docs/components/radix/button


## Outline


> 示例 `button-outline`: 交互预览见 https://jiguang132.com/zh/systems/jguang-ui/docs/components/radix/button


## Secondary


> 示例 `button-secondary`: 交互预览见 https://jiguang132.com/zh/systems/jguang-ui/docs/components/radix/button


## Ghost


> 示例 `button-ghost`: 交互预览见 https://jiguang132.com/zh/systems/jguang-ui/docs/components/radix/button


## Destructive


> 示例 `button-destructive`: 交互预览见 https://jiguang132.com/zh/systems/jguang-ui/docs/components/radix/button


## Link


> 示例 `button-link`: 交互预览见 https://jiguang132.com/zh/systems/jguang-ui/docs/components/radix/button


## Icon


> 示例 `button-icon`: 交互预览见 https://jiguang132.com/zh/systems/jguang-ui/docs/components/radix/button


## With Icon

Remember to add the `data-icon="inline-start"` or `data-icon="inline-end"` attribute to the icon for the correct spacing.


> 示例 `button-with-icon`: 交互预览见 https://jiguang132.com/zh/systems/jguang-ui/docs/components/radix/button


## Rounded

Use the `rounded-full` class to make the button rounded.


> 示例 `button-rounded`: 交互预览见 https://jiguang132.com/zh/systems/jguang-ui/docs/components/radix/button


## Spinner

Render a `` component inside the button to show a loading state. Remember to add the `data-icon="inline-start"` or `data-icon="inline-end"` attribute to the spinner for the correct spacing.


> 示例 `button-spinner`: 交互预览见 https://jiguang132.com/zh/systems/jguang-ui/docs/components/radix/button


## Button Group

To create a button group, use the `ButtonGroup` component. See the [Button Group](/systems/jguang-ui/docs/components/radix/button-group) documentation for more details.


> 示例 `button-group-demo`: 交互预览见 https://jiguang132.com/zh/systems/jguang-ui/docs/components/radix/button


## As Child

You can use the `asChild` prop on `` to make another component look like a button. Here's an example of a link that looks like a button.


> 示例 `button-aschild`: 交互预览见 https://jiguang132.com/zh/systems/jguang-ui/docs/components/radix/button


## RTL

To enable RTL support in JGuang UI, see the [RTL configuration guide](/systems/jguang-ui/docs/rtl).


> 示例 `button-rtl`: 交互预览见 https://jiguang132.com/zh/systems/jguang-ui/docs/components/radix/button


## API Reference

### Button

The `Button` component is a wrapper around the `button` element that adds a variety of styles and functionality.

| Prop      | Type                                                                                 | Default     |
| --------- | ------------------------------------------------------------------------------------ | ----------- |
| `variant` | `"default" \| "outline" \| "ghost" \| "destructive" \| "secondary" \| "link"`        | `"default"` |
| `size`    | `"default" \| "xs" \| "sm" \| "lg" \| "icon" \| "icon-xs" \| "icon-sm" \| "icon-lg"` | `"default"` |
| `asChild` | `boolean`                                                                            | `false`     |

---

JGuang 全部资源索引: https://jiguang132.com/llms.txt
