> For AI agents: the complete documentation index is available at /next/zh/llms.txt, the full documentation bundle is available at /next/zh/llms-full.txt.

# 

# Button

一个适用于 ReactLynx 的无样式按钮组件，提供按压态（`active`）追踪和用于自定义样式的 render props。
:::info

你可以查看[源码](https://github.com/lynx-family/lynx-ui/tree/main/packages/lynx-ui-button)来了解它的运行原理，也欢迎大家提 MR 来丰富其能力。

此外，你也可以参考这个实现，自行实现定制化的 Button 能力；

:::

## 基础用法


**下面是一个示例: lynx-ui-button**

**Entry:** `Basic`
**Bundle:** `dist/ButtonBasic.lynx.bundle` | Web: `dist/ButtonBasic.web.bundle`

```tsx {19-27,29-34}
// Copyright 2026 The Lynx Authors. All rights reserved.
// Licensed under the Apache License Version 2.0 that can be found in the
// LICENSE file in the root directory of this source tree.

import { root } from '@lynx-js/react'

import { Button } from '@lynx-js/lynx-ui'
import { clsx } from 'clsx'

import { Heart } from '../shared/Heart'

import './index.css'

function App() {
  return (
    <view className='demo-container lunaris-dark luna-gradient-rose'>
      <view className='demo-canvas'>
        {/* Usage 1: render props to read `active` state and toggle `.active` for styling */}
        <Button onClick={() => console.info('clicked')} className='button-root'>
          {({ active = false }) => (
            <view className={clsx('button', { 'active': active })}>
              <text className='button-text'>
                Button
              </text>
            </view>
          )}
        </Button>
        {/* Usage 2: regular children; styles rely on the primitives-injected `ui-active` state class */}
        <Button className='button'>
          <Heart />
          <text className='button-text'>
            Button
          </text>
        </Button>
      </view>
    </view>
  )
}
root.render(<App />)
export default App

```

v0.0.24



## 结构


```tsx
<Button>
  {/* Your content */}
</Button>
```

## Component API \{#api}

### Button \{#api-button}

The root component of the Button, containing all of its child components.




### 基于状态的样式与渲染

该组件通过以下一种或两种方式暴露运行时状态。下表仅展示每个状态实际支持的方式：

- **UI variant class**：支持时，对应组件节点会动态加上 `ui-<state>` 形式的类名，可用 `.ui-<state> { ... }` 选择器定制样式；
- **Render-prop 字段**：支持时，当 `children` 传入函数，状态会以 `children({ <state>: boolean, ... })` 的形式作为参数传入，便于在运行时做条件渲染。


UI variants applied by Button based on its render state.


| 类名 | 渲染属性 | 类型 | 说明 |
| --- | --- | --- | --- |
| 类名ui-active | 渲染属性`active` | 类型`boolean` | 说明按钮当前是否处于按下态（且未被禁用）。
当 status.active 为 true 时生效，可用于 `.ui-active { ... }`。 |
| 类名ui-disabled | 渲染属性`disabled` | 类型`boolean` | 说明按钮是否处于禁用态。
当 status.disabled 为 true 时生效，可用于 `.ui-disabled { ... }`。 |

