@asup/context-menu 1.5.1 → 2.0.0

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.md CHANGED
@@ -10,84 +10,133 @@
10
10
 
11
11
  # @asup/context-menu
12
12
 
13
- REACT Context menu, because I couldn't quite find what I wanted.
13
+ A small, highly-configurable React + TypeScript context menu component and helpers.
14
14
 
15
- ## Installation
15
+ Key points:
16
+
17
+ - Works with React 19 (package is built and tested against React 19; React is a peer dependency).
18
+ - TypeScript types included.
19
+ - Lightweight and focused on accessibility and nested sub-menus.
20
+
21
+ ## Storybook
22
+
23
+ Run Storybook to see interactive component examples and documentation.
24
+
25
+ ```powershell
26
+ # install dependencies
27
+ npm install
16
28
 
29
+ # run Storybook
30
+ npm run storybook
31
+
32
+ # run tests
33
+ npm run test
34
+
35
+ # build library bundle
36
+ npm run build
17
37
  ```
18
- # with npm
38
+
39
+ ## Installation
40
+
41
+ Install from npm:
42
+
43
+ ```powershell
19
44
  npm install @asup/context-menu
20
45
  ```
21
46
 
47
+ Note: React and ReactDOM are peer dependencies — install a compatible React version in your application.
48
+
22
49
  ## Usage
23
50
 
24
- Context menu provider, takes a list of available actions and renders a context menu on appropriate click.
25
- Sub menus can be added within each item.
26
- Wrap around the elements that need to have the menu.
51
+ ### ContextMenuHandler
52
+
53
+ ```tsx
54
+ import { ContextMenuHandler, IMenuItem } from "@asup/context-menu";
27
55
 
56
+ const menuItems: IMenuItem[] = [
57
+ { label: "Item 1", action: () => console.log("Item 1") },
58
+ {
59
+ label: "Item 2",
60
+ action: () => console.log("Item 2"),
61
+ group: [{ label: "Subitem 2.1", action: () => console.log("Subitem 2.1") }],
62
+ },
63
+ { label: "Item 3 (disabled)", disabled: true },
64
+ ];
65
+
66
+ <ContextMenuHandler menuItems={menuItems}>
67
+ <div>Right click here to open the menu</div>
68
+ </ContextMenuHandler>;
28
69
  ```
29
- import { ContextMenuProvider, IMenuItem } from '@asup/context-menu';
30
-
31
- <ContextMenuHandler
32
- menuItems={[
33
- {
34
- label: 'Item 1',
35
- action: () => {
36
- console.log('Item 1 function run');
37
- },
38
- },
39
- {
40
- label: 'Item 2',
41
- action: () => console.log('Item 2 function run'),
42
- group: [
43
- { label: 'Subitem 2.1', action: () => console.log('Item 2.1 function run') },
44
- ],
45
- },
46
- {
47
- label: 'Item 3',
48
- action: () => console.log('Item 3 function run'),
49
- disabled: true,
50
- },
51
- ]}
52
- >
53
- <Chilren
54
- where the context menu is applied...
55
- />
56
- </ContextMenuHandler>
57
70
 
71
+ ### AutoHeight
72
+
73
+ Use `AutoHeight` to wrap content that may expand/contract — it will manage layout height for smoother transitions.
74
+
75
+ ```tsx
76
+ import { AutoHeight } from "@asup/context-menu";
77
+
78
+ <AutoHeight>
79
+ <div style={{ padding: 12 }}>
80
+ This content can change size; AutoHeight will help the layout adjust smoothly.
81
+ </div>
82
+ </AutoHeight>;
58
83
  ```
59
84
 
85
+ ### ClickForMenu
86
+
87
+ `ClickForMenu` attaches a click-based menu to any element (useful for toolbar buttons or inline actions).
88
+
89
+ ```tsx
90
+ import { ClickForMenu, IMenuItem } from "@asup/context-menu";
91
+
92
+ const clickItems: IMenuItem[] = [
93
+ { label: "Edit", action: () => console.log("Edit") },
94
+ { label: "Delete", action: () => console.log("Delete") },
95
+ ];
96
+
97
+ <ClickForMenu menuItems={clickItems}>
98
+ <button type="button">Actions</button>
99
+ </ClickForMenu>;
60
100
  ```
61
- import { ContextWindowStack, ContextWindow }
62
-
63
- // Context window stack needs to cover the application, or portion where context windows cannot clash with each other
64
- <ContextWindowStack>
65
- ...rest of app
66
-
67
- <ContextWindow
68
- id='window-1'
69
- title={'Window 1'}
70
- visible={visible}
71
- style={ window styling, applied to the window div}
72
- onOpen={ called function on opening}
73
- onClose={ called function on closing (close cross in the window)}
74
- >
75
- {window contents}
76
- </ContextWindow>
77
-
78
- <ContextWindow
79
- id='window-2'
80
- title={'Window 2'}
81
- visible={visible}
82
- style={ window styling, applied to the window div}
83
- onOpen={ called function on opening}
84
- onClose={ called function on closing (close cross in the window)}
85
- >
86
- {window contents}
87
- </ContextWindow>
88
-
89
- ...end of app
90
-
91
- </ContextWindowStack>
92
101
 
102
+ ### ContextWindow
103
+
104
+ ```tsx
105
+ import { ContextWindow } from "@asup/context-menu";
106
+
107
+ <ContextWindow
108
+ id="window-1"
109
+ title="Window 1"
110
+ visible={true}
111
+ onClose={() => {}}
112
+ >
113
+ Window content
114
+ </ContextWindow>;
93
115
  ```
116
+
117
+ See the Storybook for interactive examples and more options.
118
+
119
+ ## Development
120
+
121
+ Useful scripts (from `package.json`):
122
+
123
+ - `npm run prepare` — run Husky (prepares Git hooks).
124
+ - `npm run storybook` — start Storybook to view component examples.
125
+ - `npm run build-storybook` — build a static Storybook site.
126
+ - `npm run test` — run Jest and collect coverage (`jest --collectCoverage=true`).
127
+ - `npm run test-watch` — run Jest in watch mode with coverage (`jest --watch --collectCoverage=true --maxWorkers=4`).
128
+ - `npm run eslint` — run ESLint over `src` (pattern: `src/**/*.{js,jsx,ts,tsx}`).
129
+ - `npm run build` — build the library bundle with Parcel. This script clears the Parcel cache before building (`parcel build src/main.ts`).
130
+
131
+ ## Contributing
132
+
133
+ Contributions and PRs are welcome. Please follow the repository conventions (linting, types, and tests).
134
+
135
+ 1. Fork the repo and create a feature branch.
136
+ 2. Run `npm install`.
137
+ 3. Run and update tests: `npm run test`.
138
+ 4. Submit a PR and describe your changes.
139
+
140
+ ## License
141
+
142
+ MIT — see the `LICENCE` file for details.