Methods
-
<static> buildMenuItem( props ) → {object}
-
Description
Builds a single menu item. The only prop shown here is the type, the rest should match the actual component being built. View those to see what options exist for each, they often have less in common than you might think. See module:DiscordContextMenu.MenuItem for the majority of props commonly available. Check the documentation for the rest of the components.
Parameters
Name Type Description props
object props used to build the item
Name Type Attributes Default Description type
string <optional> "text" type of the item, options: text, submenu, toggle, radio, custom, separator
Returns
Examples
// Creates a single menu item that prints "MENU ITEM" on click DiscordContextMenu.buildMenuItem({ label: "Menu Item", action: () => {console.log("MENU ITEM");} });
// Creates a single toggle item that starts unchecked // and print the new value on every toggle DiscordContextMenu.buildMenuItem({ type: "toggle", label: "Item Toggle", checked: false, action: (newValue) => {console.log(newValue);} });
Details
-
<static> buildMenuChildren( setup ) → {Array.<object>}
-
Description
Creates the all the items and groups of a context menu recursively. There is no hard limit to the number of groups within groups or number of items in a menu.
Parameters
Name Type Description setup
Array.<object> array of item props used to build items. See module:DiscordContextMenu.buildMenuItem
Returns
Examples
// Creates a single item group item with a toggle item DiscordContextMenu.buildMenuChildren([{ type: "group", items: [{ type: "toggle", label: "Item Toggle", active: false, action: (newValue) => {console.log(newValue);} }] }]);
// Creates two item groups with a single toggle item each DiscordContextMenu.buildMenuChildren([{ type: "group", items: [{ type: "toggle", label: "Item Toggle", active: false, action: (newValue) => { console.log(newValue); } }] }, { type: "group", items: [{ type: "toggle", label: "Item Toggle", active: false, action: (newValue) => { console.log(newValue); } }] }]);
Details
-
<static> buildMenu( setup ) → {function}
-
Description
Creates the menu component including the wrapping
ContextMenu
. Calls module:DiscordContextMenu.buildMenuChildren under the covers. Used to call in combination with module:DiscordContextMenu.openContextMenu.Parameters
Name Type Description setup
Array.<object> array of item props used to build items. See module:DiscordContextMenu.buildMenuChildren
Returns
Details
-
<static> openContextMenu( event, menuComponent, config )
-
Parameters
Name Type Description event
MouseEvent The context menu event. This can be emulated, requires target, and all X, Y locations.
menuComponent
function Component to render. This can be any react component or output of module:DiscordContextMenu.buildMenu
config
object configuration/props for the context menu
Name Type Attributes Default Description position
string <optional> "right" default position for the menu, options: "left", "right"
align
string <optional> "top" default alignment for the menu, options: "bottom", "top"
onClose
function <optional> function to run when the menu is closed
noBlurEvent
boolean <optional> false No clue
Details
-
<static> getDiscordMenu( nameOrFilter ) → {Promise.<object>}
-
Description
Attempts to find and return a specific context menu type's module. Useful when patching the render of these menus.
Parameters
Name Type Description nameOrFilter
string | function name of the context menu type
Returns
Details
-
<static> forceUpdateMenus()
-
Description
Calls
forceUpdate()
on all context menus it can find. Useful for after patching a menu.Details
Type Definitions
-
MenuItemOnClick( event )
-
Description
Fires when the item is clicked.
Parameters
Name Type Description event
MouseEvent The event generated on click
Details