From c79054fcb03c87f18e65a57b3c5b88fd628af9d6 Mon Sep 17 00:00:00 2001 From: GeorgianStan Date: Tue, 20 Sep 2022 09:06:20 +0300 Subject: [PATCH] feat: add an icon as HTML string Add a new property for MenuItem to display an icon as an HTML string. The HTML will be sanitized internally using DOMPurify. --- README.md | 8 +++++--- demo/index.html | 8 ++++++++ package.json | 2 +- src/@types/interface.ts | 4 ++++ src/index.pug | 7 +++++-- src/index.scss | 12 ++++++++++-- src/index.ts | 32 ++++++++++++++++++++++++++++---- 7 files changed, 61 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index f93f3b8..914eac1 100644 --- a/README.md +++ b/README.md @@ -15,10 +15,10 @@ ### Browser CDN ```html - + ``` -Where `@1.2.2` is the version that you want to use. +Where `@1.3.0` is the version that you want to use. Then anywhere in your JavaScript code you can access the library with `window.VanillaContextMenu` or simply `VanillaContextMenu`. @@ -56,6 +56,7 @@ new VanillaContextMenu({ callback: pasteFunction, iconClass: 'fa fa-scissors', // this only works if you have FontAwesome icons }, + { label: 'Face', iconHTML: `face` // this only works if you have Google Material Icons icons }, ], }); ``` @@ -88,7 +89,8 @@ type MenuItem = MenuOption | 'hr'; | Option | Required | Type | Default | Description | |:-------------------:|:--------:|:---------:|:---------:|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------:| | label | **yes** | string | undefined | Menu option label. | -| iconClass | no | string | undefined | This property can be used in order to display an optional icon. It presents the CSS classes that will be added for the `` tag. | +| iconClass | no | string | undefined | This property can be used to display an optional icon. It presents the CSS classes that will be added for the `` tag. | +| iconHTML | no | string | undefined | This property can be used to display an optional icon. It presents an HTML string that will be sanitized internally using [DOMPurify](https://www.npmjs.com/package/dompurify). | | callback | **yes** | (ev:MouseEvent) => any | undefined | Callback to be executed. The parameter `ev` is the MouseEvent that occurred when the `contextmenu` event was triggered | | preventCloseOnClick | no | boolean | false | If this variable is `true`, then the context menu will not close when this menu option is clicked. A value set for this option, either `true` or `false` will override the global one. | diff --git a/demo/index.html b/demo/index.html index aa4b40c..7e5309d 100644 --- a/demo/index.html +++ b/demo/index.html @@ -14,6 +14,10 @@ href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" /> + + +