{"id":25644613,"url":"https://github.com/scssyworks/context-builder","last_synced_at":"2026-04-09T16:46:42.816Z","repository":{"id":57139506,"uuid":"285274018","full_name":"scssyworks/context-builder","owner":"scssyworks","description":"Build context menus with ease","archived":false,"fork":false,"pushed_at":"2021-11-05T08:26:19.000Z","size":1477,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-11T17:19:05.364Z","etag":null,"topics":["context-builder","context-menu","context-menus","events","javascript","listeners","right-click","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/scssyworks.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-08-05T11:55:19.000Z","updated_at":"2021-12-17T03:00:01.000Z","dependencies_parsed_at":"2022-08-23T02:00:39.077Z","dependency_job_id":null,"html_url":"https://github.com/scssyworks/context-builder","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scssyworks%2Fcontext-builder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scssyworks%2Fcontext-builder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scssyworks%2Fcontext-builder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scssyworks%2Fcontext-builder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/scssyworks","download_url":"https://codeload.github.com/scssyworks/context-builder/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240291547,"owners_count":19778292,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["context-builder","context-menu","context-menus","events","javascript","listeners","right-click","typescript"],"created_at":"2025-02-23T08:29:39.065Z","updated_at":"2026-04-09T16:46:42.756Z","avatar_url":"https://github.com/scssyworks.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Context Builder\n\nA powerful and easy to use library for building custom context menus.\n\n```sh\nnpm i @scssyworks/context-builder\n```\n\n# How does it work?\n\n## Create a context menu instance for a given target.\n\n```js\nimport { ContextMenu } from '@scssyworks/context-builder';\n\nconst contextMenu = new ContextMenu('div');\n// ...\nconst contextMenu = new ContextMenu(); // For body element\n```\n\nIf you don't specify a target selector, context menu is enabled for ``body`` element.\n\n## Add context menu items\n\n```js\nimport { ContextMenu, ContextItem } from '@scssyworks/context-builder';\n\nconst contextMenu = new ContextMenu('div');\ncontextMenu.add(\n    new ContextItem('Option 1'),\n    new ContextItem('Option 2'),\n    // ...\n);\n```\n\n## Add nested menu items\n\n```js\nimport { ContextMenu, ContextItem, ContextList } from '@scssyworks/context-builder';\n\nconst contextMenu = new ContextMenu('div');\ncontextMenu.add(\n    new ContextItem('Option 1'),\n    new ContextItem('Option 2'),\n    (new ContextList('Option 3')).add(\n        new ContextItem('Child Option 1')\n    )\n    // ...\n);\n```\n\nContext builder supports nesting of elements up to ``nth`` level.\n\n## Listen to click events\n\n```js\nimport { ContextMenu, ContextItem, ContextList } from '@scssyworks/context-builder';\n\nconst contextMenu = new ContextMenu('div', {\n    onClick(event) {\n        // Use event.target to get the target element\n        // ...\n        return true; // Return true to automatically close the menu\n    }\n});\n// ...\n```\n\n## Listen to activate and deactivate events\n\nActivate and Deactivate listeners are great for adding entry and exit transitions\n\n```js\nimport { ContextMenu, ContextItem, ContextList } from '@scssyworks/context-builder';\n\nconst contextMenu = new ContextMenu('div', {\n    onActivate(elements) {\n        elements.map(el =\u003e {\n            el.classList.add('show'); // Adding \"show\" class adds an entry transition\n        });\n    },\n    onDeactivate(elements, callback) {\n        elements.once('transitionend', callback); // Callback function is \"required\" to complete the exit transition\n        elements.map(el =\u003e {\n            el.classList.remove('show'); // Removing \"show\" class triggers an exit transition\n        });\n    }\n});\n// ...\n```\n\n## Listen to \"contextmenu\" event\n\nYou can listen to original contextmenu event if you want to capture text selection or do more stuff.\n\n```js\nimport { ContextMenu, ContextItem, ContextList } from '@scssyworks/context-builder';\n\nconst contextMenu = new ContextMenu('div', {\n    onContextMenu(event) {\n        console.log(event);\n    }\n});\n// ...\n```\n\n## Destroy context menu\n\n```js\ncontextMenu.cleanup();\n```\n\n# Customize\n\nContext Builder is fully customizable. You can use your own elements to build context menu. Use the following guide to customize your context menus:\n\nhttps://github.com/scssyworks/context-builder/blob/master/CUSTOMIZE.md","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscssyworks%2Fcontext-builder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fscssyworks%2Fcontext-builder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscssyworks%2Fcontext-builder/lists"}