import{B as c,_ as C}from"./chunks/DemoFrame.vue_vue_type_script_setup_true_lang.BibqOSJQ.js";import{d as E,D}from"./chunks/Dropdown.n_ZgEzUa.js";import{R as B,u as A}from"./chunks/Icon.GjDzw7hq.js";import{d as F,E as n,K as f,a9 as b,u as _,o as u,b as v,w as k,j as r,k as d,a as w,t as o,h as g,p as S,C as q,c as R,a3 as y}from"./chunks/framework.D8G7yXPy.js";import"./chunks/light.BQgF5P5u.js";import"./chunks/isSymbol.rCNNreax.js";import"./chunks/use-compitable.BN_sOfeF.js";import"./chunks/element.mIVMEYq_.js";function N(i,a){const s=i??(a==null?void 0:a.defaultElement)??null;return typeof s=="function"?s:()=>s}const M={...E,placement:{...E.placement,default:"bottom-start"},icon:{type:String,default:"action/more"},iconSize:{type:Number},triggerLabel:String,cursor:{type:String,default:"inherit"}};function x(i){return typeof i=="function"||Object.prototype.toString.call(i)==="[object Object]"&&!b(i)}const T=F({name:"RMoreDropdown",props:M,setup(){return{translate:A().translate}},render(){var l;let i;const{iconSize:a,cursor:s,icon:t}=this,{default:h}=this.$slots;return n(D,f(this.$props,this.$attrs),x(i=N(h,{defaultElement:n(c,{text:!0,"aria-label":this.triggerLabel??((l=this.translate)==null?void 0:l.call(this,"appComponents.moreActions"))??"More actions"},{default:()=>[n(B,{name:t,size:a,cursor:s},null)]})}))?i:{default:()=>[i]})}}),P={class:"ray-demo"},I={class:"ray-demo-result"},V=F({__name:"MoreDropdownDemo",setup(i){const{lang:a}=_(),s=g(()=>a.value.startsWith("en")?{edit:"Edit",copy:"Duplicate",archive:"Archive",more:"More actions",hint:"Select an action."}:{edit:"编辑",copy:"复制",archive:"归档",more:"更多操作",hint:"请选择一项操作"}),t=g(()=>[{key:"edit",label:s.value.edit},{key:"copy",label:s.value.copy},{key:"archive",label:s.value.archive,disabled:!0}]),h=S(""),l=e=>{var p;h.value=((p=t.value.find(m=>m.key===e))==null?void 0:p.label)??""};return(e,p)=>(u(),v(C,null,{default:k(()=>[r("div",P,[n(d(T),{trigger:"click",options:t.value,onSelect:l},{default:k(()=>[n(d(c),null,{default:k(()=>[w(o(s.value.more),1)]),_:1})]),_:1},8,["options"]),r("output",I,o(h.value||s.value.hint),1)])]),_:1}))}}),J=JSON.parse('{"title":"RMoreDropdown","description":"","frontmatter":{},"headers":[],"relativePath":"reference/components/more-dropdown.md","filePath":"reference/components/more-dropdown.md"}'),O={name:"reference/components/more-dropdown.md"},K=Object.assign(O,{setup(i){return(a,s)=>{const t=q("ClientOnly");return u(),R("div",null,[s[0]||(s[0]=y('

RMoreDropdown ​

包装 NDropdown,为行操作提供默认的更多图标。options、trigger、placement、onSelect(key, option)、受控显隐等沿用 Naive UI Dropdown。

交互示例 ​

',3)),n(t,null,{default:k(()=>[n(V)]),_:1}),s[1]||(s[1]=y(`
查看示例源码
vue
<template>
  <DemoFrame>
    <div class="ray-demo">
      <RMoreDropdown trigger="click" :options="options" @select="onSelect">
        <NButton>{{ copy.more }}</NButton>
      </RMoreDropdown>
      <output class="ray-demo-result">{{ result || copy.hint }}</output>
    </div>
  </DemoFrame>
</template>

<script setup lang="ts">
import { RMoreDropdown } from '@ray-template/ui/more-dropdown'
import { NButton } from 'naive-ui'
import { useData } from 'vitepress'
import { computed, ref } from 'vue'
import DemoFrame from './DemoFrame.vue'

const { lang } = useData()
const copy = computed(() =>
  lang.value.startsWith('en')
    ? {
        edit: 'Edit',
        copy: 'Duplicate',
        archive: 'Archive',
        more: 'More actions',
        hint: 'Select an action.',
      }
    : {
        edit: '编辑',
        copy: '复制',
        archive: '归档',
        more: '更多操作',
        hint: '请选择一项操作',
      },
)
const options = computed(() => [
  { key: 'edit', label: copy.value.edit },
  { key: 'copy', label: copy.value.copy },
  { key: 'archive', label: copy.value.archive, disabled: true },
])
const result = ref('')
const onSelect = (key: string | number) => {
  result.value = options.value.find((option) => option.key === key)?.label ?? ''
}
</script>
属性默认说明
icon'action/more'类型为 IconName,使用完整分包路径。
iconSize跟随 RIcon触发图标大小,省略时为 20 px。
cursor'inherit'默认继承所在控件的指针样式。
triggerLabel跟随注入翻译或 'More actions'默认图标按钮的可访问名称。

默认触发器是可键盘聚焦的图标按钮。placement 默认 'bottom-start',可由调用方覆盖。default 插槽替换整个触发器,自定义触发器应使用具有可访问名称的原生按钮或 NButton。列表行中根据业务需要阻止点击冒泡,避免同时触发行导航。

tsx
import { RIcon, RMoreDropdown } from '@/components'
import { NButton } from 'naive-ui'

export const renderRowActions = (edit: () => void) => (
  <RMoreDropdown
    trigger="click"
    placement="bottom-end"
    options={[{ key: 'edit', label: '编辑' }]}
    onSelect={(key) => {
      if (key === 'edit') edit()
    }}
  >
    <NButton
      text
      aria-label="更多操作"
      onClick={(event) => event.stopPropagation()}
    >
      <RIcon name="action/more" />
    </NButton>
  </RMoreDropdown>
)

组件实现 · Props

`,5))])}}});export{J as __pageData,K as default};