﻿# Button {#button}

## Basic types {#types}

### Default and semantic types
```vue
<div>
  <nf-button>Default</nf-button>
  <nf-button type="primary">Primary</nf-button>
  <nf-button type="success">Success</nf-button>
  <nf-button type="info">Info</nf-button>
  <nf-button type="warning">Warning</nf-button>
  <nf-button type="danger">Danger</nf-button>
</div>
```

## Plain, text and shapes {#variants}

### States and shapes
```vue
<div>
  <nf-button type="primary" plain>Plain</nf-button>
  <nf-button text>Default text</nf-button>
  <nf-button type="text">Primary text</nf-button>
  <nf-button type="danger" text>Danger text</nf-button>
  <nf-button type="primary" round>Round</nf-button>
  <nf-button icon="el-icon-search" circle aria-label="Search" />
</div>
```

## Disabled and loading {#states}

### Disabled and loading
```vue
<div>
  <nf-button disabled>Disabled</nf-button>
  <nf-button type="primary" disabled>Disabled primary</nf-button>
  <nf-button type="text" disabled>Disabled text</nf-button>
  <nf-button loading>Loading</nf-button>
  <nf-button type="primary" loading plain>Loading</nf-button>
</div>
```

Loading disables the native button, shows a spinning SVG and hides the normal icon without requiring Element UI fonts. Disabled/loading buttons do not emit `click`.

## Sizes {#sizes}

### Legacy sizes
```vue
<div>
  <nf-button type="primary">Default mini</nf-button>
  <nf-button type="primary" size="medium">medium</nf-button>
  <nf-button type="primary" size="small">small</nf-button>
  <nf-button type="primary" size="mini">mini</nf-button>
</div>
```

The default remains `mini` (12px font, 7px × 12px padding), not Element Plus's default. `medium` uses 14px and 10px × 12px; `small` uses 12px and 9px × 12px.

## Interaction, icons and native forms {#interaction}


See expanded example example-6 (ButtonExamples).


`icon` accepts legacy class strings or Vue icon components. Common legacy names (`el-icon-search/edit/check/message/star-off/delete/plus/close/download/upload`) map to built-in SVGs. Other strings remain CSS classes; consumers supply their fonts/styles, just as before. Element Plus does not include the Element UI icon font: replace unmapped names with a component, such as `:icon="Search"` imported from `@element-plus/icons-vue`. Give icon-only buttons an `aria-label`.

## Global configuration {#global-config}

`NfConfigProvider` accepts all button props through `nf-button`. Explicit button values (including `false`) win; nested providers inherit per property and update reactively. The fallback size remains `mini`. This configuration is separate from Element Plus's top-level `size` / `button`.

```vue
<NfConfigProvider :nf-button="{ size: 'medium', type: 'primary', loading: true }">
  <NfButton>Inherited</NfButton>
  <NfButton size="small" :loading="false">Local override</NfButton>
</NfConfigProvider>
```

See the [interactive provider example](https://front.94ai.com/common-ui-plus/en/components/fixture#nf-button-config).

## On-demand installation {#installation}

```ts
import NfButton from '@94ai-plus/nf-button'
import '@94ai-plus/nf-theme-chalk/nf-button.css'

app.use(NfButton)
```

For OEM use `@94ai-plus/nf-theme-oem/nf-button.css`. Installing `CommonUI` already registers `NfButton`. Named imports and `CommonUIResolver()` are supported. The component's standalone CSS entry is `@94ai-plus/nf-button/style.css`.

## Props {#props}

| Prop | Description | Type / values | Default |
| --- | --- | --- | --- |
| type | Semantic type | primary / success / info / warning / danger / text | — |
| size | Legacy size | mini / small / medium | mini |
| icon | Icon class or Vue component | string / Component | — |
| plain | Plain button | boolean | false |
| text | Text button; also enabled by `type="text"` | boolean | false |
| round | Rounded corners | boolean | false |
| circle | Circular button | boolean | false |
| loading | Show loading and block clicks | boolean | false |
| disabled | Disable button | boolean | false |
| autofocus | Native autofocus | boolean | false |
| native-type | Native form behavior | button / submit / reset | button |

Undeclared attributes such as `id`, `class`, `style`, `name`, `value`, `aria-*` and `data-*` fall through to the native button. Vue 3 listener fallthrough replaces Vue 2 `.native`. Keyboard `:focus-visible` styles do not change mouse states.

## Events and slots {#events-slots}

| Name | Contract |
| --- | --- |
| click | `(event: MouseEvent) => void`, preserving the native event |
| default | Button content; no content span is generated when absent |

## Expanded component examples

### ButtonExamples

Source: docs/.vitepress/theme/examples/ButtonInteractions.vue

```vue
<script setup lang="ts">
import { ref } from 'vue'
import { Search } from '@element-plus/icons-vue'
import { NfButton } from '@94ai-plus/common-ui'

const { english = false } = defineProps<{ english?: boolean }>()

const count = ref(0)
const loading = ref(false)
const disabled = ref(false)
const submitted = ref(0)
const reset = ref(0)
const lastEvent = ref('')
const showAutofocus = ref(false)
function onClick(event: MouseEvent) { count.value++; lastEvent.value = event.constructor.name }
</script>

<template>
  <section class="button-examples" :aria-label="english ? 'Button interaction examples' : '按钮交互示例'">
    <div class="button-example-row">
      <NfButton data-testid="interactive-button" type="primary" :loading="loading" :disabled="disabled" @click="onClick">{{ english ? 'Clicks' : '点击' }} {{ count }}</NfButton>
      <output data-testid="click-event">{{ lastEvent }}</output>
      <label><input v-model="loading" type="checkbox" data-testid="toggle-loading" /> {{ english ? 'Loading' : '加载中' }}</label>
      <label><input v-model="disabled" type="checkbox" data-testid="toggle-disabled" /> {{ english ? 'Disabled' : '禁用' }}</label>
    </div>
    <div class="button-example-row">
      <NfButton icon="el-icon-search" data-testid="legacy-icon">{{ english ? 'Search' : '搜索' }}</NfButton>
      <NfButton :icon="Search" data-testid="component-icon" circle :aria-label="english ? 'Search icon button' : '搜索图标按钮'" />
      <NfButton class="company-button" icon="company-icon" data-testid="custom-icon">{{ english ? 'Custom icon' : '自定义图标' }}</NfButton>
    </div>
    <form @submit.prevent="submitted++" @reset="reset++">
      <input name="query" :value="english ? 'Initial value' : '初始值'" :aria-label="english ? 'Form content' : '表单内容'" />
      <NfButton data-testid="native-button" @click="onClick">{{ english ? 'Normal button' : '普通按钮' }}</NfButton>
      <NfButton data-testid="submit-button" native-type="submit">{{ english ? 'Submit' : '提交' }}</NfButton>
      <NfButton data-testid="reset-button" native-type="reset">{{ english ? 'Reset' : '重置' }}</NfButton>
      <output data-testid="form-result">submit:{{ submitted }} reset:{{ reset }}</output>
    </form>
    <div>
      <NfButton @click="showAutofocus = true">{{ english ? 'Mount autofocus button' : '挂载自动聚焦按钮' }}</NfButton>
      <NfButton v-if="showAutofocus" data-testid="autofocus-button" autofocus>{{ english ? 'Autofocus attribute' : '自动聚焦属性' }}</NfButton>
    </div>
  </section>
</template>

<style scoped>
.button-examples { display: grid; gap: 20px; }
.button-example-row, form { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.button-examples :deep(.company-icon::before) { content: '★'; }
</style>
```
