@imengyu/vue3-context-menu 1.1.1 → 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.CN.md CHANGED
@@ -17,7 +17,7 @@
17
17
 
18
18
  ### ❗ 重大升级
19
19
 
20
- 版本 1.1.0 做了很大升级,可能会存在与之前版本不兼容的情况,如果出现问题,请安装 1.0.9 版本。
20
+ 版本 1.1.0 做了很大升级,如果您从之前的版本升级过来,可能会存在与之前版本不兼容的情况,你需要参考文档修改菜单的数据格式。如果出现问题,请安装 1.0.9 版本。
21
21
 
22
22
  ## 安装
23
23
 
@@ -42,9 +42,11 @@ createApp(App).use(ContextMenu)
42
42
 
43
43
  显示菜单有两种方式:
44
44
 
45
- 第一种是函数模式,可以使用 `this.$contextmenu` 通过菜单数据显示一个右键菜单:
45
+ 第一种是函数模式,可以使用 `this.$contextmenu` 或者 `showContextMenu` 全局函数,通过菜单数据显示一个右键菜单:
46
46
 
47
47
  ```js
48
+ import ContextMenu from '@imengyu/vue3-context-menu'
49
+
48
50
  onContextMenu(e : MouseEvent) {
49
51
  //prevent the browser's default menu
50
52
  e.preventDefault();
@@ -69,6 +71,9 @@ onContextMenu(e : MouseEvent) {
69
71
  },
70
72
  ]
71
73
  });
74
+
75
+ //这个函数与 this.$contextmenu 一致
76
+ ContextMenu.showContextMenu({ ... });
72
77
  }
73
78
  ```
74
79
 
@@ -95,30 +100,6 @@ onContextMenu(e : MouseEvent) {
95
100
  data() {
96
101
  return {
97
102
  show: false,
98
- //For $contextmenu
99
- options: {
100
- items:[
101
- {
102
- label: "Copy",
103
- onClick: () => {
104
- document.execCommand('copy');
105
- }
106
- },
107
- { label: "Paste", disabled: true },
108
- {
109
- label: "Print",
110
- icon: 'icon-print',
111
- onClick: () => {
112
- document.execCommand('print');
113
- }
114
- },
115
- ],
116
- iconFontClass: 'iconfont',
117
- customClass: "class-a",
118
- minWidth: 230,
119
- x: 0,
120
- y: 0
121
- },
122
103
  //For component
123
104
  optionsComopnent: {
124
105
  zIndex: 3,
@@ -140,9 +121,46 @@ methods: {
140
121
 
141
122
  ## 菜单图标
142
123
 
143
- 菜单组件不提供任何图标,如果您想添加图标,推荐使用 [iconfont](http://iconfont.cn) 图标库,导入后填写 MenuItem 的 icon 属性,即可在菜单项前面显示图标。
124
+ 菜单组件不提供任何图标,如果您想添加图标,推荐使用 [iconfont](http://iconfont.cn) 图标库。
125
+
126
+ ### 字体图标
127
+
128
+ 使用 iconfont 图标库,导入字体后填写 `MenuItem` 的 `icon` 属性,即可在菜单项前面显示图标。
129
+
130
+ * 如果字体名称不一样,可用 `MenuItem` 或者 `MenuOptions` 的 `iconFontClass` 属性指定其他字体。
131
+ * 默认使用 `<i>` 元素来显示图标。
132
+
133
+ ### SVG 图标
134
+
135
+ 支持使用 svg symbol 来显示图标:
144
136
 
145
- *默认使用 `<i>` 元素来显示图标。*
137
+ ```html
138
+ <svg viewBox="0 0 80 20" xmlns="http://www.w3.org/2000/svg">
139
+ <!-- Your icon -->
140
+ <symbol id="icon-multiply" viewBox="0 0 1024 1024">
141
+ <path d="M512 64C264.608 64 64 264.608 64 512c0 247.36 200.608 448 448 448 247.36 0 448-200.64 448-448 0-247.392-200.64-448-448-448z m158.4 651.552L512 557.312l-158.4 158.24-45.312-45.248L466.688 512l-158.304-158.4 45.312-45.312L512 466.688l158.4-158.4 45.28 45.312L557.312 512l158.368 158.4-45.28 45.152z" fill="#F74A21"></path>
142
+ </symbol>
143
+ </svg>
144
+ ```
145
+
146
+ ```js
147
+ this.$contextmenu({
148
+ items: [
149
+ {
150
+ label: "Item with svg icon",
151
+ svgIcon: "#icon-multiply",
152
+ svgProps: {
153
+ fill: '#f60',
154
+ },
155
+ },
156
+ ],
157
+ //...省略
158
+ } as MenuOptions);
159
+ ```
160
+
161
+ > 注:使用 iconfont 库导出的图标库,会附带 `iconfont.js` ,你只需要在 html 中引入这个js,他会自动为你导入所有的 svg symbol,你可直接复制图标名称使用。
162
+
163
+ ### 自定义渲染
146
164
 
147
165
  你也可以通过菜单的插槽来完全自定义渲染图标,如:
148
166
 
@@ -174,6 +192,8 @@ methods: {
174
192
  在函数模式自定义图标:
175
193
 
176
194
  ```js
195
+ import { h } from 'vue';
196
+
177
197
  {
178
198
  label: "Item with custom icon render",
179
199
  icon: h('img', {
@@ -198,7 +218,7 @@ import '你的样式css文件路径.css'
198
218
 
199
219
  ## 自定义渲染
200
220
 
201
- 菜单提供了一些插槽,允许你自定义渲染某些部分,具体您可以参考案例源码 [examples\views\BasicCustomize.vue](examples\views\BasicCustomize.vue) [examples\views\ComponentCustomize.vue](examples\views\ComponentCustomize.vue)。
221
+ 菜单提供了一些插槽,允许你自定义渲染某些部分,具体您可以参考案例源码 [examples/views/BasicCustomize.vue](examples/views/BasicCustomize.vue) [examples/views/ComponentCustomize.vue](examples/views/ComponentCustomize.vue)。
202
222
 
203
223
  ## API 参考
204
224
 
@@ -236,10 +256,14 @@ import '你的样式css文件路径.css'
236
256
  | 属性名 | 描述 | 类型 |
237
257
  | :----: | :----: | :----: |
238
258
  | theme | 菜单主题 | `'light' 'dark'` |
259
+ | isOpen | 指示当前菜单子菜单是否处于打开状态 | `boolean` |
260
+ | hasChildren | 指示当前菜单是否有子级菜单 | `boolean` |
239
261
  | onClick | 自定义元素的点击事件回调,它用于菜单内部事件处理,当自定义渲染时,请回调此函数,否则菜单无法正常响应事件 | - |
240
262
  | onMouseEnter | 自定义元素的鼠标移入事件回调,它用于菜单内部事件处理,当自定义渲染时,请回调此函数,否则菜单无法正常响应事件 | - |
241
263
  | ... | 其他参数与 `MenuItem` 一致 | - |
242
264
 
265
+ ---
266
+
243
267
  #### ContextMenuItem
244
268
 
245
269
  菜单条目组件。
@@ -250,6 +274,9 @@ import '你的样式css文件路径.css'
250
274
  | :----: | :----: | :----: | :----: |
251
275
  | label | 菜单项名称 | `string` | — |
252
276
  | icon | 菜单项图标 | `string` | — |
277
+ | iconFontClass | 自定义图标字体类名 | `string` | — | `iconfont` |
278
+ | svgIcon | 菜单项图标 svg,仅在 icon 为空时有效 | `string` | — | — |
279
+ | svgProps | 当使用 svg 图标时,自定义 svg 标签属性 | `SVGAttributes` | — | — |
253
280
  | disabled | 是否禁用菜单项 | `boolean` | `false` |
254
281
  | clickableWhenHasChildren | 指定当本菜单下有子菜单时,点击当前菜单是否触发点击事件 | `boolean` | `false` |
255
282
  | clickClose | 点击当前菜单项是否自动关闭整个菜单 | `boolean` | `true` |
@@ -271,6 +298,8 @@ import '你的样式css文件路径.css'
271
298
  | :----: | :----: | :----: |
272
299
  | click | 点击菜单时触发此事件 | - |
273
300
 
301
+ ---
302
+
274
303
  #### ContextMenuGroup
275
304
 
276
305
  子菜单组件。
@@ -281,6 +310,9 @@ import '你的样式css文件路径.css'
281
310
  | :----: | :----: | :----: | :----: |
282
311
  | label | 菜单项名称 | `string` | — |
283
312
  | icon | 菜单项图标 | `string` | — |
313
+ | iconFontClass | 自定义图标字体类名 | `string` | — | `iconfont` |
314
+ | svgIcon | 菜单项图标 svg,仅在 icon 为空时有效 | `string` | — | — |
315
+ | svgProps | 当使用 svg 图标时,自定义 svg 标签属性 | `SVGAttributes` | — | — |
284
316
  | disabled | 是否禁用菜单项 | `boolean` | `false` |
285
317
  | clickableWhenHasChildren | 指定当本菜单下有子菜单时,点击当前菜单是否触发点击事件 | `boolean` | `false` |
286
318
  | adjustSubMenuPosition | 是否在子菜单超出屏幕后进行自动调整 | `boolean` | `true` |
@@ -296,12 +328,35 @@ import '你的样式css文件路径.css'
296
328
  | :----: | :----: | :----: |
297
329
  | default | 子菜单渲染插槽 | - |
298
330
 
331
+ ---
332
+
299
333
  #### ContextMenuSperator
300
334
 
301
335
  菜单分隔符组件。
302
336
 
337
+ ---
338
+
303
339
  ### 函数模式:参数说明
304
340
 
341
+ #### 全局函数
342
+
343
+ * `ContextMenu.showContextMenu(options: MenuOptions, customSlots?: Record<string, Slot>)`
344
+
345
+ 显示菜单.
346
+
347
+ | 参数 | 说明 |
348
+ | :----: | :----: |
349
+ | options | 菜单的数据 |
350
+ | customSlots | 这些插槽允许您自定义当前菜单的样式,这些插槽的名称与 [组件模式](#ContextMenu) 中的插槽名称相同 |
351
+
352
+ * `ContextMenu.closeContextMenu()`
353
+
354
+ 手动关闭当前打开的菜单.
355
+
356
+ * `this.$contextmenu`
357
+
358
+ 与 `ContextMenu.showContextMenu` 相同,但此函数注册到 Vue 全局属性中,可以在Vue实例中直接使用。
359
+
305
360
  #### MenuOptions
306
361
 
307
362
  | 属性 | 描述 | 类型 | 可选值 | 默认值 |
@@ -325,6 +380,9 @@ import '你的样式css文件路径.css'
325
380
  | :----: | :----: | :----: | :----: | :----: |
326
381
  | label | 菜单项名称,可传入VNode | `string` or `VNode` or `((label: string) => VNode)` | — | — |
327
382
  | icon | 菜单项图标,可传入VNode | `string` or `VNode` or `((icon: string) => VNode)` | — | — |
383
+ | iconFontClass | 自定义图标字体类名 | `string` | — | `iconfont` |
384
+ | svgIcon | 菜单项图标 svg,仅在 icon 为空时有效 | `string` | — | — |
385
+ | svgProps | 当使用 svg 图标时,自定义 svg 标签属性 | `SVGAttributes` | — | — |
328
386
  | disabled | 是否禁用菜单项 | `boolean` | — | `false` |
329
387
  | adjustSubMenuPosition | 是否在子菜单超出屏幕后进行自动调整 | `boolean` | — | `true` |
330
388
  | clickableWhenHasChildren | 指定当本菜单下有子菜单时,点击当前菜单是否触发点击事件 | `boolean` | — | `false` |
package/README.md CHANGED
@@ -44,9 +44,11 @@ createApp(App).use(ContextMenu)
44
44
 
45
45
  There are two ways to display menus:
46
46
 
47
- The first is the function mode. You can use `this.$contextmenu` displays a menu through menu data:
47
+ The first is the function mode. You can use `this.$contextmenu` or `showContextMenu` global function displays a menu through menu data:
48
48
 
49
49
  ```js
50
+ import ContextMenu from '@imengyu/vue3-context-menu'
51
+
50
52
  onContextMenu(e : MouseEvent) {
51
53
  //prevent the browser's default menu
52
54
  e.preventDefault();
@@ -71,6 +73,9 @@ onContextMenu(e : MouseEvent) {
71
73
  },
72
74
  ]
73
75
  });
76
+
77
+ //Same as this.$contextmenu
78
+ ContextMenu.showContextMenu({ ... });
74
79
  }
75
80
  ```
76
81
 
@@ -97,31 +102,6 @@ The second is the component mode. You can use the component and template to disp
97
102
  data() {
98
103
  return {
99
104
  show: false,
100
- //For $contextmenu
101
- options: {
102
- items:[
103
- {
104
- label: "Copy",
105
- onClick: () => {
106
- document.execCommand('copy');
107
- }
108
- },
109
- { label: "Paste", disabled: true },
110
- {
111
- label: "Print",
112
- icon: 'icon-print',
113
- onClick: () => {
114
- document.execCommand('print');
115
- }
116
- },
117
- ],
118
- iconFontClass: 'iconfont',
119
- customClass: "class-a",
120
- minWidth: 230,
121
- x: 0,
122
- y: 0
123
- },
124
- //For component
125
105
  optionsComopnent: {
126
106
  zIndex: 3,
127
107
  minWidth: 230,
@@ -142,11 +122,50 @@ methods: {
142
122
 
143
123
  ## Menu icon
144
124
 
145
- The menu component does not provide any icons. If you want to add an icon, it is recommended to use [iconfont](http://iconfont.cn) Icon library. After importing, fill in the `icon` attribute of MenuItem to display the icon in front of the menu item.
125
+ The menu component does not provide any icons. If you want to add an icon, it is recommended to use [iconfont](http://iconfont.cn) Icon library.
146
126
 
147
- *By default, the `<i>` element is used to display icons*
127
+ ### Font icon
148
128
 
149
- ---
129
+ Use iconfont library: After importing, fill in the `icon` attribute of `MenuItem` to display the icon in front of the menu item.
130
+
131
+ * If the font names are different, you can specify other fonts by writing the `iconFontClass` attribute of `MenuItem` or `MenuOptions`.
132
+ * By default, the `<i>` element is used to display icons
133
+
134
+ ### SVG Icon
135
+
136
+ Support the use of svg `<symbol>` to display icons:
137
+
138
+ ```html
139
+ <svg viewBox="0 0 80 20" xmlns="http://www.w3.org/2000/svg">
140
+ <!-- Your icon -->
141
+ <symbol id="icon-multiply" viewBox="0 0 1024 1024">
142
+ <path d="M512 64C264.608 64 64 264.608 64 512c0 247.36 200.608 448 448 448 247.36 0 448-200.64 448-448 0-247.392-200.64-448-448-448z m158.4 651.552L512 557.312l-158.4 158.24-45.312-45.248L466.688 512l-158.304-158.4 45.312-45.312L512 466.688l158.4-158.4 45.28 45.312L557.312 512l158.368 158.4-45.28 45.152z" fill="#F74A21"></path>
143
+ </symbol>
144
+ </svg>
145
+ ```
146
+
147
+ ```js
148
+ //Function mode
149
+ this.$contextmenu({
150
+ items: [
151
+ {
152
+ label: "Item with svg icon",
153
+ svgIcon: "#icon-multiply",
154
+ svgProps: {
155
+ fill: '#f60',
156
+ },
157
+ },
158
+ ],
159
+ //...
160
+ } as MenuOptions);
161
+ ```
162
+
163
+ ```js
164
+ //Component mode
165
+ <context-menu-item label="Item with svg icon" svgIcon="#icon-multiply" :svgProps="{ fill: '#f60' }" />
166
+ ```
167
+
168
+ ### Customize icon
150
169
 
151
170
  You can also completely customize the rendering icon through the slot of the menu, such as:
152
171
 
@@ -176,6 +195,8 @@ Customize the icon of the entire menu:
176
195
  Customize icon in function mode:
177
196
 
178
197
  ```js
198
+ import { h } from 'vue';
199
+
179
200
  {
180
201
  label: "Item with custom icon render",
181
202
  icon: h('img', {
@@ -199,7 +220,7 @@ import 'your-style-file-path.css'
199
220
 
200
221
  ## Customize
201
222
 
202
- The menu provides some slots that allow you to customize some parts of the rendering. For details, please refer to the example source code [examples\views\BasicCustomize.vue](examples\views\BasicCustomize.vue) [examples\views\ComponentCustomize.vue](examples\views\ComponentCustomize.vue)。
223
+ The menu provides some slots that allow you to customize some parts of the rendering. For details, please refer to the example source code [examples/views/BasicCustomize.vue](examples/views/BasicCustomize.vue) [examples/views/ComponentCustomize.vue](examples/views/ComponentCustomize.vue)。
203
224
 
204
225
  ## API reference
205
226
 
@@ -237,10 +258,14 @@ Menu component.
237
258
  | Property | Description | Type |
238
259
  | :----: | :----: | :----: |
239
260
  | theme | Menu theme | `'light' 'dark'` |
261
+ | isOpen | This value indicates whether the current menu submenu is open | `boolean` |
262
+ | hasChildren | This value indicates whether the current menu has submenus | `boolean` |
240
263
  | onClick | Define the click event callback of the element, which is used for the internal event processing of the menu. When rendering item with slot, please call this function back, otherwise the menu cannot respond to the event normally | - |
241
264
  | onMouseEnter | Mouse in event callback of custom element. When rendering item with slot, please call this function back, otherwise the menu cannot respond to the event normally | - |
242
265
  | ... | Other arguments are same with `MenuItem` | - |
243
266
 
267
+ ---
268
+
244
269
  #### ContextMenuItem
245
270
 
246
271
  Menu item component.
@@ -251,6 +276,9 @@ Menu item component.
251
276
  | :----: | :----: | :----: | :----: |
252
277
  | label | The label of menu. | `string` | — |
253
278
  | icon | The icon for menu item. | `string` | — |
279
+ | iconFontClass | Custom icon library font class name. | `string` | — | `iconfont` |
280
+ | svgIcon | Display icons use svg symbol (`<use xlink:href="...">`) , only valid when icon attribute is empty. | `string` | — | — |
281
+ | svgProps | The user-defined attribute of the svg tag, which is valid when using `svgIcon`. | `SVGAttributes` | — | — |
254
282
  | disabled | Disable menu item? | `boolean` | `false` |
255
283
  | clickableWhenHasChildren | When there are subitems in this item, is it allowed to trigger its own click event? | `boolean` | `false` |
256
284
  | clickClose | Should close menu when Click this menu item ? | `boolean` | `true` |
@@ -272,6 +300,8 @@ Menu item component.
272
300
  | :----: | :----: | :----: |
273
301
  | click | This event is triggered when the click this menu item | - |
274
302
 
303
+ ---
304
+
275
305
  #### ContextMenuGroup
276
306
 
277
307
  Submenu component.
@@ -282,6 +312,9 @@ Submenu component.
282
312
  | :----: | :----: | :----: | :----: |
283
313
  | label | The label of menu. | `string` | — |
284
314
  | icon | The icon for menu item. | `string` | — |
315
+ | iconFontClass | Custom icon library font class name. | `string` | — | `iconfont` |
316
+ | svgIcon | Display icons use svg symbol (`<use xlink:href="...">`) , only valid when icon attribute is empty. | `string` | — | — |
317
+ | svgProps | The user-defined attribute of the svg tag, which is valid when using `svgIcon`. | `SVGAttributes` | — | — |
285
318
  | disabled | Disable menu item? | `boolean` | `false` |
286
319
  | clickableWhenHasChildren | When there are subitems in this item, is it allowed to trigger its own click event? | `boolean` | `false` |
287
320
  | adjustSubMenuPosition | Specifies should submenu adjust it position when the menu exceeds the screen.| `boolean` | `true` |
@@ -297,12 +330,35 @@ Submenu component.
297
330
  | :----: | :----: | :----: |
298
331
  | default | Submenu render slot | - |
299
332
 
333
+ ---
334
+
300
335
  #### ContextMenuSperator
301
336
 
302
337
  Menu separator component.
303
338
 
339
+ ---
340
+
304
341
  ### Function mode
305
342
 
343
+ #### Global Function
344
+
345
+ * `ContextMenu.showContextMenu(options: MenuOptions, customSlots?: Record<string, Slot>)`
346
+
347
+ Show context menu.
348
+
349
+ | Param | Description |
350
+ | :----: | :----: |
351
+ | options | The options of menu. |
352
+ | customSlots | These slots to allow you to customize the style of the current menu, the names of these slots are the same as those in the [component mode](#ContextMenu). |
353
+
354
+ * `ContextMenu.closeContextMenu()`
355
+
356
+ Manually close the currently open context menu.
357
+
358
+ * `this.$contextmenu`
359
+
360
+ Same as `ContextMenu.showContextMenu` but this function is registered to vue global property.
361
+
306
362
  #### MenuOptions
307
363
 
308
364
  | Property | Description | Type | Optional value | Default |
@@ -326,6 +382,9 @@ Menu separator component.
326
382
  | :----: | :----: | :----: | :----: | :----: |
327
383
  | label | The label of menu. | `string` or `VNode` or `((label: string) => VNode)` | — | — |
328
384
  | icon | The icon for menu item. | `string` or `VNode` or `((icon: string) => VNode)` | — | — |
385
+ | iconFontClass | Custom icon library font class name. | `string` | — | `iconfont` |
386
+ | svgIcon | Display icons use svg symbol (`<use xlink:href="...">`) , only valid when icon attribute is empty. | `string` | — | — |
387
+ | svgProps | The user-defined attribute of the svg tag, which is valid when using `svgIcon`. | `SVGAttributes` | — | — |
329
388
  | disabled | Disable menu item? | `boolean` | — | `false` |
330
389
  | adjustSubMenuPosition | Specifies should submenu adjust it position when the menu exceeds the screen. | `boolean` | — | `true` |
331
390
  | clickableWhenHasChildren | When there are subitems in this item, is it allowed to trigger its own click event? | `boolean` | — | `false` |
@@ -6,8 +6,7 @@
6
6
  <meta name="viewport" content="width=device-width,initial-scale=1.0">
7
7
  <link rel="icon" href="<%= BASE_URL %>favicon.ico">
8
8
  <title><%= htmlWebpackPlugin.options.title %></title>
9
- <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.0.1/styles/default.min.css">
10
- <script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.0.1/highlight.min.js"></script>
9
+ <script src="https://imengyu.top/static/iconfont-small-test.js"></script>
11
10
  </head>
12
11
  <body>
13
12
  <noscript>
@@ -16,5 +15,7 @@
16
15
  <a href="https://github.com/imengyu/vue3-context-menu"><img style="position: absolute; top: 0; left: 0; border: 0; z-index: 100" src="https://camo.githubusercontent.com/82b228a3648bf44fc1163ef44c62fcc60081495e/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f6c6566745f7265645f6161303030302e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_left_red_aa0000.png"></a>
17
16
  <div id="app"></div>
18
17
  <!-- built files will be auto injected -->
18
+ <script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.0.1/highlight.min.js"></script>
19
+ <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.0.1/styles/default.min.css">
19
20
  </body>
20
21
  </html>
@@ -87,7 +87,7 @@ export default defineComponent({
87
87
  hljs: {
88
88
  highlightAll: () => void
89
89
  }
90
- }).hljs.highlightAll();
90
+ }).hljs?.highlightAll?.();
91
91
  },
92
92
  data() {
93
93
  return {
@@ -61,7 +61,7 @@ export default defineComponent({
61
61
  hljs: {
62
62
  highlightAll: () => void
63
63
  }
64
- }).hljs.highlightAll();
64
+ }).hljs?.highlightAll?.();
65
65
  },
66
66
  methods: {
67
67
  onContextMenu(e : MouseEvent) {
@@ -91,7 +91,7 @@ export default defineComponent({
91
91
  hljs: {
92
92
  highlightAll: () => void
93
93
  }
94
- }).hljs.highlightAll();
94
+ }).hljs?.highlightAll?.();
95
95
  },
96
96
  methods: {
97
97
  test() {
@@ -140,7 +140,6 @@ export default defineComponent({
140
140
  alert("You click Print");
141
141
  }
142
142
  },
143
-
144
143
  { label: "View source", icon: "icon-terminal" },
145
144
  { label: "Inspect" }
146
145
  ],
@@ -206,6 +205,21 @@ export default defineComponent({
206
205
  },
207
206
  ]
208
207
  },
208
+ {
209
+ label: 'Item with icon',
210
+ icon: "icon-reload-1",
211
+ },
212
+ {
213
+ label: "Item with svg icon",
214
+ svgIcon: "#icon-clock",
215
+ },
216
+ {
217
+ label: "Item with svg icon",
218
+ svgIcon: "#icon-multiply",
219
+ svgProps: {
220
+ fill: '#f60',
221
+ },
222
+ },
209
223
  ],
210
224
  iconFontClass: 'iconfont',
211
225
  customClass: "class-a",
package/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { App, Slot, VNode } from "vue";
1
+ import { App, Slot, SVGAttributes, VNode } from "vue";
2
2
 
3
3
  declare module 'vue3-context-menu' {
4
4
  }
@@ -44,7 +44,7 @@ export declare interface MenuOptions {
44
44
  */
45
45
  customClass ?: string,
46
46
  /**
47
- * Custom icon library font class name.
47
+ * Custom icon library font class name. (global)
48
48
  */
49
49
  iconFontClass ?: string,
50
50
  /**
@@ -73,6 +73,18 @@ export declare interface MenuItem {
73
73
  * The icon for menu item.
74
74
  */
75
75
  icon ?: string|VNode|((icon: string) => VNode),
76
+ /**
77
+ * Custom icon library font class name.
78
+ */
79
+ iconFontClass ?: string,
80
+ /**
81
+ * Display icons use svg symbol (`<use xlink:href="...">`) , only valid when icon attribute is empty.
82
+ */
83
+ svgIcon ?: string,
84
+ /**
85
+ * The user-defined attribute of the svg tag, which is valid when using `svgIcon`.
86
+ */
87
+ svgProps ?: SVGAttributes,
76
88
  /**
77
89
  * Disable menu item?
78
90
  */
@@ -125,6 +137,14 @@ export declare interface MenuItemRenderData extends Omit<MenuItem, 'children'|'c
125
137
  * Global theme
126
138
  */
127
139
  theme: 'light'|'dark',
140
+ /**
141
+ * This value indicates whether the current menu submenu is open
142
+ */
143
+ isOpen: boolean,
144
+ /**
145
+ * This value indicates whether the current menu has submenus
146
+ */
147
+ hasChildren: boolean,
128
148
  /**
129
149
  * Click event callback of custom element, which is used for menu internal event
130
150
  */