npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

lt-contextmenu

v1.3.4

Published

一个基于Vue3的右键菜单组件

Downloads

14

Readme

image

lt-contextmenu

一款vue3开发的右键菜单组件

Nuget License: MIT

🚀 安装

NPM 安装(推荐)

$ npm i -S lt-contextmenu # yarn add lt-contextmenu # pnpm add lt-contextmenu

🎃 使用

<script setup lang="ts">
import 'lt-contextmenu/dist/style.css'
import { LtContextmenu, type MenuGroupOption, type MenuOption, type MenuValue } from 'lt-contextmenu'

const ltContextmenu = ref()

//传递的菜单参数
const data = {
  name: 'lijiatu'
}

//菜单配置项, 更多见下面的配置项说明
const menuOptions = ref<MenuGroupOption[]>([
    {
        group: 'default',
        options: [
            {
                id: '1',
                icon: () => h(FileExport),
                label: '菜单1',
            },
            {
                id: '2',
                icon: () => h(FileExport),
                label: '菜单2',
            },
        ]
    }
])

</script>

<template>
  <div style="width: 100%;height: 100%;" @click.right="(e) => ltContextmenu?.open(e, data)">
    <LtContextmenu ref="ltContextmenu" :menu-options="menuOptions" />
  </div>
</template>

配置项

| 参数 | 说明 | 类型 | 必填 | 默认值 | | --- | --- | --- | --- | --- | | menuOptions | 核心配置项 | Array<MenuOption|MenuGroupOption> | ✅ | 无 | | menuStyle | 菜单风格 | 'google' | 'edge' | ⬜ | 'google' | | menuTheme | 菜单主题 | 'light' | 'dark-element' | 'dark-naive' | ⬜ | 'light' | | menuSize | 菜单大小 | 'normal' | 'small' | 'large' | ⬜ | 'small' | | width | 菜单固定宽度, 不设置则动态宽度 | number|string | ⬜ | 无 | | maxWidth | 菜单最大宽度 | number|string | ⬜ | 无 | | groupClass | 菜单组的class | string | ⬜ | 无 | | groupStyle | 菜单组的style | CSSProperties | ⬜ | 无 | | itemClass | 菜单项的class | string | ⬜ | 无 | | itemStyle | 菜单项的style | CSSProperties | ⬜ | 无 | | beforeClose | 关闭前的回调,可终止菜单的关闭 | (close: () => void) => void | ⬜ | 无 |

类型说明

type MenuOption = {
    //必填项, 唯一id
    id: string | number
    //可选, 菜单图标
    icon?: (menuParam?: any, itemOption?: MenuOption) => VNode
    //必填, 菜单文本
    label: string | ((menuParam?: any, itemOption?: MenuOption) => VNode | string)
    //可选, 菜单是否可见, 为false时该菜单不会渲染(v-if)
    visible?: boolean | ((menuParam?: any, itemOption?: MenuOption) => boolean)
    //可选, 菜单是否禁用, 为true时该菜单不可点击
    disabled?: boolean | ((menuParam?: any, itemOption?: MenuOption) => boolean)
    //菜单项的类型, 默认menu, MenuItemType='menu'|'radio'
    type?: MenuItemType
    //菜单类型为'radio'、'toggle'时选中的值, MenuValue=string|number|boolean|Array<string|number|boolean>
    value?: MenuValue
    //菜单项点击事件
    handler?: (menuParam?: any, value?: MenuValue, itemOption?: MenuOption) => void
    //子菜单, MenuGenericOption=Array<MenuOption | MenuGroupOption>
    children?: MenuGenericOption
    //其类型为'radio'、'toggle'时改变值会执行
    change?: (menuParam?: any, value?: MenuValue, itemOption?: MenuOption) => void
}

type MenuGroupOption = {
    //菜单组名称
    group: string
    //菜单项
    options: MenuOption[]
}

函数参数说明

| 参数 | 说明 | | --- | --- | | menuParam | 菜单项传递的参数 | | value | 菜单类型为radio时选中的值 | | itemOption | 菜单项本身 |

Exposes

{
    //打开菜单
    open: (event: MouseEvent | { x: number, y: number }, param?: any) => void,
    //关闭菜单
    close: () => void,
    //根据菜单id获取菜单选项
    getMenuOption: (id: string | number) => MenuOption,
    //当菜单类型为radio时手动设置其value
    setRadioValue: (id: string | number, value?: MenuValue) => void,
    //当菜单类型为radio时根据菜单id获取其value
    getRadioValue: (id: string | number) => MenuValue
}

🎆 预览

image image