Skip to content

Theme

Built-in themes

The menu contains the following themes, which you can choose to use.

Just set the 'theme' field in the menu options:

js
this.$contextmenu({
  theme: 'mac dark',
  items: [
  ],
  //...
});
ThemeExplainImage
defaultDefault themeexample-default-dark.jpg
default darkDefault theme with darkexample-default-dark.jpg
flatSimple flat themeexample-default-dark.jpg
flat darkSimple flat theme with darkexample-default-dark.jpg
win10Win10 like themeexample-default-dark.jpg
win10 darkWin10 like theme with darkexample-default-dark.jpg
macMac like themeexample-default-dark.jpg
mac darkMac like theme with darkexample-default-dark.jpg

Custom Theme

You can write your own theme, just make sure that the theme name is different from the built-in name.

All CSS style definitions are in /ContextMenu.scss. You can copy all the styles, modify them as needed, and store them in your file.

Custom Theme Example

For example, the following is the implementation of an example theme `my-theme-name. Your own theme can also be implemented in this way:

scss
.mx-context-menu.my-theme-name {
  & {
    //Overwrite the value of the default css variable here
    --mx-menu-backgroud: #ececec;
    --mx-menu-hover-backgroud: #0165e1;
  }
  
  //Customize menu outer style
  padding: 8px 0;
  box-shadow: 0px 5px 7px 1px var(--mx-menu-shadow-color);
  border: 1px solid var(--mx-menu-border-color);

  //Customize the style of menu item
  .mx-context-menu-item {
    border-radius: 5px;
    margin: 0 6px;
    padding: 3px 6px;
  }

  //Please view the complete style of each part in ContextMenu.scss
}
.mx-menu-bar.my-theme-name {
  //Customize the style of the menu bar
}

Then import the theme file and use it in theme:

js
import '@imengyu/vue3-context-menu/lib/vue3-context-menu.css'
import 'your-style-file-path.scss'
js
this.$contextmenu({
  theme: 'my-theme-name',
  items: [
  ],
  //...
});

Released under the MIT License.