﻿# nf-variable-select {#variable-select}

Searchable popover variable picker with field aliases, grouped results and custom group labels. The default slot supplies the trigger.

## Examples {#examples}

### Basic usage {#example-1}

### Basic usage
```vue
<script setup>
import { ref } from 'vue'
import { NfConfigProvider, NfVariableSelect, NfButton } from '@94ai-plus/common-ui'
const selected = ref('')
const data = [{ paramId: 0, name: 'Customer name' }, { paramId: 1, name: 'Phone' }]
</script>

<template>
  <NfConfigProvider theme="chalk" locale="en-US">
    <NfVariableSelect :data="data" @variate-click="row => selected = row.name"><NfButton>Insert variable</NfButton></NfVariableSelect>
    <output>{{ selected }}</output>
  </NfConfigProvider>
</template>
```

### Advanced usage {#example-2}

### Advanced usage
```vue
<script setup>
import { ref } from 'vue'
import { NfConfigProvider, NfVariableSelect, NfButton } from '@94ai-plus/common-ui'
const selected = ref('')
const data = [{ id: 0, title: 'Name', group: 'customer' }, { id: 1, title: 'Phone', group: 'customer' }, { id: 2, title: 'Agent', group: 'system' }]
</script>

<template>
  <NfConfigProvider theme="chalk" locale="en-US">
    <NfVariableSelect :data="data" key-alias="id" value-alias="title" groupable group-key="group" :group-labels="{ customer: 'Customer', system: 'System' }" @variate-click="row => selected = row.title"><NfButton>Grouped variables</NfButton></NfVariableSelect>
    <output>{{ selected }}</output>
  </NfConfigProvider>
</template>
```

## Props {#props}

Text props follow the library language when omitted; defaults below use this language.

| Parameter | Description | Type | Options | Default |
| --- | --- | --- | --- | --- |
| `data` | Data to display or restore. | `VariableItem[]` | — | `[]` |
| `valueAlias` | Alias for the value field. | `string` | — | `'name'` |
| `keyAlias` | Alias for the key field. | `string` | — | `'paramId'` |
| `placement` | Popup placement. | `string` | top / top-start / top-end / bottom / bottom-start / bottom-end / left / left-start / left-end / right / right-start / right-end | `'bottom'` |
| `width` | Popup width. | `string \| number` | — | `'160'` |
| `trigger` | Trigger mode; manual is controlled externally through visible. | `string` | click / focus / hover / manual | `'click'` |
| `visible` | Controlled visibility; supports v-model:visible. | `boolean` | — | `undefined` |
| `popperClass` | Custom class for the popup. | `string` | — | `''` |
| `disabled` | Whether to disable the component. | `boolean` | — | `false` |
| `offset` | Popup offset in pixels. | `number` | — | `0` |
| `transition` | Popup transition name. | `string` | — | `'fade-in-linear'` |
| `visibleArrow` | Whether to show the popup arrow. | `boolean` | — | `true` |
| `popperOptions` | Popper 2 options; use modifiers to customize positioning. | `Record<string, unknown>` | — | `{}` |
| `openDelay` | Show delay for hover, in milliseconds. | `number` | — | `undefined` |
| `closeDelay` | Hide delay for hover, in milliseconds. | `number` | — | `200` |
| `tabindex` | tabindex of the trigger. | `number` | — | `0` |
| `noMatchDesc` | Customize the “No matching data” text. | `string` | — | `No matching data` |
| `placeholder` | Customize the “Search by variable name” text. | `string` | — | `Search by variable name` |
| `size` | Control size; mini maps to small and medium to default. | `string` | mini / small / medium / default / large | `'mini'` |
| `groupable` | Enable grouping. | `boolean` | — | `false` |
| `groupKey` | Grouping field; required when groupable is true. | `string` | — | `''` |
| `groupLabels` | Group label mapping: keys are groupKey values and values are display text. | `Record<string, string>` | — | `{}` |

## Events {#events}

| Event | Description | Payload |
| --- | --- | --- |
| `variate-click` | Fires when a variable is clicked; returns the selected object. | `(item: VariableItem)` |
| `after-enter` | Fires after the show transition finishes. | — |
| `hidden` | Fires when hidden. | — |
| `show` | Fires when shown. | — |
| `after-leave` | Fires after the hide transition finishes. | — |
| `update:visible` | Update the bound value. | `(visible: boolean)` |

## Slots {#slots}

| Parameter | Description | Payload |
| --- | --- | --- |
| `default` | DOM content that triggers the dropdown. | — |

## Exposed methods and state {#methods}

- `keyword`
- `list`
- `groupedList`
- `handleItem(item)`

## Migration notes {#migration}

Vue 3 uses `modelValue` / `update:modelValue`; legacy `value`, `update:value` and `input` remain available on selection components. The implementation uses public Element Plus APIs, not Element UI internals. `mini` maps to `small`; `medium` maps to `default`.
