﻿# nf-action {#action}

Action groups that move overflow items into a dropdown or popover.

Import the components below; see the package README for standalone installation.

## Dynamic dropdown mode {#example-1}

### Dynamic dropdown mode
```vue
<script setup lang="ts">
import { NfAction } from '@94ai-plus/common-ui'
import { ElButton } from 'element-plus'

  import { ref, onMounted, onBeforeUnmount } from 'vue'

  const testAsync = ref(false)
  const visibleChange = (value) => {
     console.log('visibleChange', value)
  }
  let timer
onBeforeUnmount(() => clearTimeout(timer))
onMounted(() => {
    timer = setTimeout(() => {
      testAsync.value = true
    }, 5000)
  })
</script>

<template>
<div class="action-examples">
      <nf-action style='width: fit-content;' @visible-change='visibleChange' :span='3'>
         <el-button text size="small" v-if='testAsync'>import</el-button>
         <el-button text size="small">Details</el-button>
         <el-button text size="small" >Copy</el-button>
         <el-button text size="small" >deactivate</el-button>
         <el-button text size="small" >enable</el-button>
         <el-button text size="small" v-if='testAsync'>Edit</el-button>
      </nf-action>
       <nf-action :span='2'  style='width: fit-content;'>
         <el-button text size="small" v-if='testAsync'>Edit</el-button>
         <el-button text size="small" >Details</el-button>
         <el-button text size="small" >Copy</el-button>
         <el-button text size="small" v-if='testAsync'>import</el-button>
         <el-button text size="small" >deactivate</el-button>
         <el-button text size="small" >enable</el-button>
      </nf-action>
       <nf-action :span='4' style="width: fit-content;">
         <el-button text size="small" v-if='testAsync'>Edit</el-button>
         <el-button text size="small" >Details</el-button>
         <el-button text size="small" >Copy</el-button>
         <el-button text size="small" v-if='testAsync'>import</el-button>
         <el-button text size="small" >deactivate</el-button>
         <el-button text size="small" >enable</el-button>
      </nf-action>
  </div>
</template>

<style scoped>
.action-examples {display:flex;flex-wrap:wrap;align-items:center;gap:32px;max-width:100%}
</style>
```

## Dynamic popover mode {#example-2}

### Dynamic popover mode
```vue
<script setup lang="ts">
import { NfAction } from '@94ai-plus/common-ui'
import { ElButton } from 'element-plus'

  import { ref, onMounted, onBeforeUnmount } from 'vue'

  const testAsync = ref(false)
  const show = () => {
     console.log('show')
  }
  const alterEnter = () => {
     console.log('alterEnter')
  }
  const afterLeave = () => {
     console.log('afterLeave')
  }
  const hide = () => {
     console.log('hide')
  }
  let timer
onBeforeUnmount(() => clearTimeout(timer))
onMounted(() => {
    timer = setTimeout(() => {
      testAsync.value = true
    }, 5000)
  })
</script>

<template>
<div class="action-examples">
   <nf-action mode='popover' style='width: fit-content;' :visible-arrow='false' placement='right' @show='show' @after-enter='alterEnter' @after-leave='afterLeave' @hide='hide'>
       <el-button text size="small" v-if='testAsync'>Edit</el-button>
       <el-button text size="small">Details</el-button>
       <el-button text size="small" >Copy</el-button>
       <el-button text size="small" v-if='testAsync'>import</el-button>
       <el-button text size="small" >deactivate</el-button>
       <el-button text size="small" >enable</el-button>
    </nf-action>
    <nf-action mode='popover' :span='2'  style='width: fit-content;' :visible-arrow='false' placement='right'>
       <el-button text size="small" v-if='testAsync'>Edit</el-button>
       <el-button text size="small" >Details</el-button>
       <el-button text size="small" >Copy</el-button>
       <el-button text size="small" v-if='testAsync'>import</el-button>
       <el-button text size="small" >deactivate</el-button>
       <el-button text size="small" >enable</el-button>
    </nf-action>
     <nf-action mode='popover' :span='4' :visible-arrow='false' placement='right' style="width: fit-content;">
       <el-button text size="small" v-if='testAsync'>Edit</el-button>
       <el-button text size="small" >Details</el-button>
       <el-button text size="small" >Copy</el-button>
       <el-button text size="small" v-if='testAsync'>import</el-button>
       <el-button text size="small" >deactivate</el-button>
       <el-button text size="small" >enable</el-button>
    </nf-action>
  </div>
</template>

<style scoped>
.action-examples {display:flex;flex-wrap:wrap;align-items:center;gap:32px;max-width:100%}
</style>
```

## Automatic folding by width {#example-3}

### Automatic folding by width
```vue
<script setup lang="ts">
import { NfAction } from '@94ai-plus/common-ui'
import { ElButton } from 'element-plus'

  import { ref, onMounted, onBeforeUnmount } from 'vue'

  const testAsync = ref(false)
  console.log('nf-action')
  let timer
onBeforeUnmount(() => clearTimeout(timer))
onMounted(() => {
    timer = setTimeout(() => {
      testAsync.value = true
    }, 5000)
  })
</script>

<template>
<div class="action-examples">
    <nf-action style='width: 70px;' :span='0'>
       <el-button text size="small" v-if='testAsync'>Edit</el-button>
       <el-button text size="small" >Details</el-button>
       <el-button text size="small" >Copy</el-button>
       <el-button text size="small" v-if='testAsync'>import</el-button>
       <el-button text size="small" >deactivate</el-button>
       <el-button text size="small" >enable</el-button>
    </nf-action>

     <nf-action style='width: 100px;' :span='0' mode='popover'>
       <el-button text size="small" v-if='testAsync'>Edit</el-button>
       <el-button text size="small" >Details</el-button>
       <el-button text size="small" >Copy</el-button>
       <el-button text size="small" v-if='testAsync'>import</el-button>
       <el-button text size="small" >deactivate</el-button>
       <el-button text size="small" >enable</el-button>
    </nf-action>
  </div>
</template>

<style scoped>
.action-examples {display:flex;flex-wrap:wrap;align-items:center;gap:32px;max-width:100%}
</style>
```

## Attribute {#props}

| parameters | Description | Type | Optional value | Default value |
| --- | --- | --- | --- | --- |
| mode | displayed mode | string | dropdown/popover | 'dropdown' |
| unique | The key of the component loop. If there is no loop, it does not need to be passed. | number/string | — | 0 |
| span | The upper limit of the number of child elements that triggers the drop-down; span=0 is calculated based on the available width; when span is exceeded, span−1 operations and one more entry are displayed. | number | — | 3 |
| trigger | The behavior that triggers the drop-down | string | hover/click/focus/manual | 'hover' |
| tabindex | tabindex of dropdown component | number | — | 0 |
| hide-timeout | The delay of dropdown closing the drop-down menu (only valid when trigger is hover) | number | — | 150 |
| show-timeout | The delay of dropdown expansion drop-down menu (only valid when trigger is hover) | number | — | 250 |
| hide-on-click | Whether dropdown hides the menu after clicking the menu item | boolean | — | true |
| placement | popover drop-down position | string | top/top-start/top-end/bottom/bottom-start/bottom-end/left/left-start/left-end/right/right-start/right-end | 'bottom' |
| offset | The offset of where the popover appears | number | — | 0 |
| transition | Popover defines gradient animation | string | — | 'fade-in-linear' |
| popper-class | The custom class name of the popover popup layer. | string | — | — |
| popper-options | Popper 2 configuration of popover; the old version boundariesElement and gpuAcceleration need to be changed to modifiers. | Object | — | { boundariesElement: 'body', gpuAcceleration: false } |
| open-delay | Popover display delay, in milliseconds; handled by Element Plus if not set. | number | — | 200 |
| close-delay | Popover hiding delay, in milliseconds. | number | — | 0 |
| visible-arrow | Whether the popover displays arrows. | boolean | — | true |
| width | popover elastic layer width. | string / number | — | auto |

## Event {#events}

| event name | Description | callback parameters |
| --- | --- | --- |
| show | Triggered when popover is displayed | — |
| after-enter | Triggered after the popover display animation is finished playing | — |
| hide | Triggered when popover is hidden | — |
| after-leave | Triggered after the popover hidden animation finishes playing | — |
| visible-change | Dropdown triggers when the drop-down box appears/hides | visible: boolean |

## Slot {#slots}

| Name | Description |
| --- | --- |
| default | action content |

## Methods {#methods}

| method name | Description | return value |
| --- | --- | --- |
| refreshStyle() | Recalculated after layout changes. | Promise&lt;void&gt; |
| open() | Open the floating layer manually. | void |
| close() | Close the overlay manually. | void |

## Instructions for use {#configuration-notes}

Dynamic DOM child elements also support drop-down, such as buttons added or removed after permission control. The example shows the edit and import buttons after 5 seconds; the width example shows after 3 seconds. Each operation component is instantiated only once, and the floating layer moves the original node through Teleport.
