@stimulus-plumbers/controllers 0.2.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ryan Chang
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,144 @@
1
+ # @stimulus-plumbers/controllers
2
+
3
+ Stimulus Plumbers controllers for WCAG 2.1+ compliant UI components.
4
+
5
+ ## Philosophy
6
+
7
+ **Use native HTML5 first.** Only use controllers when native elements have limitations.
8
+
9
+ - ✅ `<details>` for disclosures
10
+ - ✅ `<dialog>` for basic modals
11
+ - ✅ **ModalController** for enhanced modals with accessibility features
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ npm install @stimulus-plumbers/controllers
17
+ ```
18
+
19
+ ## ModalController
20
+
21
+ Full-featured accessible modal dialog. Supports both native `<dialog>` elements and custom implementations.
22
+
23
+ ```javascript
24
+ import { Application } from '@hotwired/stimulus';
25
+ import { ModalController } from '@stimulus-plumbers/controllers';
26
+
27
+ const application = Application.start();
28
+ application.register('modal', ModalController);
29
+ ```
30
+
31
+ Native `<dialog>` element:
32
+ ```html
33
+ <div data-controller="modal">
34
+ <button data-action="modal#open">Open Modal</button>
35
+
36
+ <dialog data-modal-target="modal" aria-labelledby="modal-title">
37
+ <h2 id="modal-title">Modal Title</h2>
38
+ <p>Content...</p>
39
+ <button data-action="modal#close">Close</button>
40
+ </dialog>
41
+ </div>
42
+ ```
43
+
44
+ Custom implementation:
45
+ ```html
46
+ <div data-controller="modal">
47
+ <button data-action="modal#open">Open Modal</button>
48
+
49
+ <div data-modal-target="overlay" class="modal-overlay" hidden>
50
+ <div data-modal-target="modal"
51
+ role="dialog"
52
+ aria-modal="true"
53
+ aria-labelledby="modal-title">
54
+ <h2 id="modal-title">Modal Title</h2>
55
+ <p>Content...</p>
56
+ <button data-action="modal#close">Close</button>
57
+ </div>
58
+ </div>
59
+ </div>
60
+ ```
61
+
62
+ **Features:**
63
+ - Focus trap with proper cycling
64
+ - Escape key closes
65
+ - Click outside closes
66
+ - Focus restoration
67
+ - Screen reader announcements
68
+ - Body scroll lock (custom implementation)
69
+
70
+ **Targets:** `modal`, `overlay` (optional)
71
+ **Actions:** `open()`, `close()`
72
+
73
+ ## Utilities
74
+
75
+ ```javascript
76
+ import {
77
+ // Focus
78
+ FocusTrap,
79
+ FocusRestoration,
80
+ getFocusableElements,
81
+ focusFirst,
82
+
83
+ // ARIA
84
+ announce,
85
+ generateId,
86
+ ensureId,
87
+ setExpanded,
88
+ setPressed,
89
+ setChecked,
90
+ setDisabled,
91
+
92
+ // Keyboard
93
+ RovingTabIndex,
94
+ isKey,
95
+ isActivationKey,
96
+ isArrowKey,
97
+ preventDefault
98
+ } from '@stimulus-plumbers/controllers';
99
+ ```
100
+
101
+ **Example:**
102
+
103
+ ```javascript
104
+ import { FocusTrap, announce } from '@stimulus-plumbers/controllers';
105
+
106
+ export default class extends Controller {
107
+ connect() {
108
+ this.trap = new FocusTrap(this.element);
109
+ }
110
+
111
+ open() {
112
+ this.trap.activate();
113
+ announce('Panel opened');
114
+ }
115
+ }
116
+ ```
117
+
118
+ ## Additional Controllers (Experimental)
119
+
120
+ Available but not exported:
121
+
122
+ - **CalendarMonthController** - Calendar widget with date navigation
123
+ - **FormFieldController** - Dropdown field management
124
+ - **PopoverController** - Content loading and visibility
125
+ - **VisibilityController** - Show/hide with animations (prefer `<details>`)
126
+ - **DismisserController** - Click-outside dismissal
127
+ - **FlipperController** - Element positioning
128
+ - **PannerController** - Scroll management
129
+
130
+ ## Accessibility
131
+
132
+ All controllers follow:
133
+ - WCAG 2.1 Level AA
134
+ - WAI-ARIA Authoring Practices
135
+ - Keyboard navigation (Tab, Escape, Arrows)
136
+ - Screen reader compatibility
137
+
138
+ ## Browser Support
139
+
140
+ Chrome, Firefox, Safari, Edge (last 2 versions)
141
+
142
+ ## License
143
+
144
+ MIT © Ryan Chang