@neetechs/ui 0.0.2 → 0.0.4
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 +21 -0
- package/README.md +123 -11
- package/dist/ai/ai-action-button/ai-action-button.css +271 -270
- package/dist/ai/ai-approval-card/ai-approval-card.css +323 -320
- package/dist/ai/ai-conversation-panel/ai-conversation-panel.css +447 -403
- package/dist/ai/ai-prompt-input/ai-prompt-input.css +380 -377
- package/dist/ai/ai-proposal-card/ai-proposal-card.css +358 -358
- package/dist/ai/ai-suggestion-card/ai-suggestion-card.css +295 -293
- package/dist/ai/ai-tool-call/ai-tool-call.css +256 -255
- package/dist/ai/index.css +1 -1
- package/dist/appearance/cache.d.ts +55 -0
- package/dist/appearance/cache.d.ts.map +1 -0
- package/dist/appearance/cache.js +182 -0
- package/dist/appearance/cache.js.map +1 -0
- package/dist/appearance/cookie.d.ts +33 -0
- package/dist/appearance/cookie.d.ts.map +1 -0
- package/dist/appearance/cookie.js +125 -0
- package/dist/appearance/cookie.js.map +1 -0
- package/dist/appearance/index.d.ts +9 -0
- package/dist/appearance/index.d.ts.map +1 -0
- package/dist/appearance/index.js +5 -0
- package/dist/appearance/index.js.map +1 -0
- package/dist/appearance/preference.d.ts +21 -0
- package/dist/appearance/preference.d.ts.map +1 -0
- package/dist/appearance/preference.js +80 -0
- package/dist/appearance/preference.js.map +1 -0
- package/dist/appearance/theme-controller.d.ts +62 -0
- package/dist/appearance/theme-controller.d.ts.map +1 -0
- package/dist/appearance/theme-controller.js +240 -0
- package/dist/appearance/theme-controller.js.map +1 -0
- package/dist/appearance/types.d.ts +48 -0
- package/dist/appearance/types.d.ts.map +1 -0
- package/dist/appearance/types.js +2 -0
- package/dist/appearance/types.js.map +1 -0
- package/dist/behaviors/announcer.d.ts +34 -0
- package/dist/behaviors/announcer.d.ts.map +1 -0
- package/dist/behaviors/announcer.js +150 -0
- package/dist/behaviors/announcer.js.map +1 -0
- package/dist/behaviors/calendar.d.ts +15 -0
- package/dist/behaviors/calendar.d.ts.map +1 -0
- package/dist/behaviors/calendar.js +77 -0
- package/dist/behaviors/calendar.js.map +1 -0
- package/dist/behaviors/data-grid.d.ts +18 -0
- package/dist/behaviors/data-grid.d.ts.map +1 -0
- package/dist/behaviors/data-grid.js +114 -0
- package/dist/behaviors/data-grid.js.map +1 -0
- package/dist/behaviors/dialog.d.ts +14 -0
- package/dist/behaviors/dialog.d.ts.map +1 -1
- package/dist/behaviors/dialog.js +24 -6
- package/dist/behaviors/dialog.js.map +1 -1
- package/dist/behaviors/direction.d.ts +10 -0
- package/dist/behaviors/direction.d.ts.map +1 -0
- package/dist/behaviors/direction.js +24 -0
- package/dist/behaviors/direction.js.map +1 -0
- package/dist/behaviors/drawer.d.ts +15 -3
- package/dist/behaviors/drawer.d.ts.map +1 -1
- package/dist/behaviors/drawer.js +25 -10
- package/dist/behaviors/drawer.js.map +1 -1
- package/dist/behaviors/dropdown.d.ts +11 -0
- package/dist/behaviors/dropdown.d.ts.map +1 -1
- package/dist/behaviors/dropdown.js +53 -11
- package/dist/behaviors/dropdown.js.map +1 -1
- package/dist/behaviors/focus-trap.d.ts.map +1 -1
- package/dist/behaviors/focus-trap.js +45 -5
- package/dist/behaviors/focus-trap.js.map +1 -1
- package/dist/behaviors/forms.d.ts +32 -0
- package/dist/behaviors/forms.d.ts.map +1 -0
- package/dist/behaviors/forms.js +147 -0
- package/dist/behaviors/forms.js.map +1 -0
- package/dist/behaviors/index.d.ts +8 -0
- package/dist/behaviors/index.d.ts.map +1 -1
- package/dist/behaviors/index.js +8 -0
- package/dist/behaviors/index.js.map +1 -1
- package/dist/behaviors/keyboard.d.ts.map +1 -1
- package/dist/behaviors/keyboard.js +4 -2
- package/dist/behaviors/keyboard.js.map +1 -1
- package/dist/behaviors/overlay.d.ts +6 -0
- package/dist/behaviors/overlay.d.ts.map +1 -1
- package/dist/behaviors/overlay.js +93 -3
- package/dist/behaviors/overlay.js.map +1 -1
- package/dist/behaviors/state.d.ts +49 -0
- package/dist/behaviors/state.d.ts.map +1 -0
- package/dist/behaviors/state.js +220 -0
- package/dist/behaviors/state.js.map +1 -0
- package/dist/behaviors/tabs.d.ts +18 -0
- package/dist/behaviors/tabs.d.ts.map +1 -0
- package/dist/behaviors/tabs.js +103 -0
- package/dist/behaviors/tabs.js.map +1 -0
- package/dist/behaviors/viewport.d.ts +40 -0
- package/dist/behaviors/viewport.d.ts.map +1 -0
- package/dist/behaviors/viewport.js +47 -0
- package/dist/behaviors/viewport.js.map +1 -0
- package/dist/components/alert/alert.css +220 -217
- package/dist/components/avatar/avatar.css +220 -219
- package/dist/components/badge/badge.css +174 -174
- package/dist/components/breadcrumb/breadcrumb.css +207 -205
- package/dist/components/button/button.css +195 -167
- package/dist/components/card/card.css +221 -220
- package/dist/components/checkbox/checkbox.css +189 -187
- package/dist/components/chip/chip.css +269 -267
- package/dist/components/data-grid/data-grid.css +520 -369
- package/dist/components/dialog/dialog.css +339 -275
- package/dist/components/drawer/drawer.css +484 -403
- package/dist/components/dropdown/dropdown.css +316 -298
- package/dist/components/icon-button/icon-button.css +162 -158
- package/dist/components/index.css +1 -2
- package/dist/components/input/input.css +163 -163
- package/dist/components/menu/menu.css +315 -314
- package/dist/components/pagination/pagination.css +250 -249
- package/dist/components/panel/panel.css +284 -283
- package/dist/components/progress/progress.css +256 -248
- package/dist/components/radio/radio.css +166 -164
- package/dist/components/segmented-control/segmented-control.css +205 -205
- package/dist/components/select/select.css +117 -103
- package/dist/components/skeleton/skeleton.css +262 -262
- package/dist/components/split-button/split-button.css +292 -285
- package/dist/components/switch/switch.css +195 -181
- package/dist/components/table/table.css +220 -0
- package/dist/components/tabs/tabs.css +293 -289
- package/dist/components/textarea/textarea.css +86 -86
- package/dist/components/toast/toast.css +345 -323
- package/dist/components/tooltip/tooltip.css +258 -255
- package/dist/domain/billing/index.css +498 -498
- package/dist/domain/calendar/agenda-list/agenda-list.css +224 -0
- package/dist/domain/calendar/day-slice/day-slice.css +384 -383
- package/dist/domain/calendar/day-timeline/day-timeline.css +332 -324
- package/dist/domain/calendar/event-card/event-card.css +338 -336
- package/dist/domain/calendar/index.css +2 -1
- package/dist/domain/calendar/month-grid/month-grid.css +426 -420
- package/dist/domain/calendar/week-grid/week-grid.css +480 -470
- package/dist/domain/companies/index.css +526 -525
- package/dist/index.css +5 -5
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/localization/index.d.ts +8 -0
- package/dist/localization/index.d.ts.map +1 -0
- package/dist/localization/index.js +22 -0
- package/dist/localization/index.js.map +1 -0
- package/dist/patterns/command-palette/command-palette.css +447 -439
- package/dist/patterns/company-switcher/company-switcher.css +390 -363
- package/dist/patterns/content-state/content-state.css +236 -0
- package/dist/patterns/empty-state/empty-state.css +260 -259
- package/dist/patterns/error-state/error-state.css +272 -271
- package/dist/patterns/form-layout/form-layout.css +106 -0
- package/dist/patterns/index.css +8 -3
- package/dist/patterns/loading-state/loading-state.css +287 -287
- package/dist/patterns/master-detail/master-detail.css +103 -0
- package/dist/patterns/notification-center/notification-center.css +443 -438
- package/dist/patterns/page/page.css +219 -0
- package/dist/patterns/profile-menu/profile-menu.css +298 -297
- package/dist/patterns/search-bar/search-bar.css +457 -444
- package/dist/patterns/settings-layout/settings-layout.css +150 -0
- package/dist/patterns/workflow/workflow.css +168 -0
- package/dist/shell/app-shell/app-shell.css +74 -67
- package/dist/shell/content-frame/content-frame.css +93 -93
- package/dist/shell/header/header.css +180 -178
- package/dist/shell/index.css +6 -6
- package/dist/shell/mobile-nav/mobile-nav.css +173 -171
- package/dist/shell/sidebar/sidebar.css +146 -146
- package/dist/styles/accessibility.css +116 -0
- package/dist/styles/animations/motion.css +162 -162
- package/dist/styles/appearance/accent.css +173 -0
- package/dist/styles/appearance/density.css +61 -0
- package/dist/styles/appearance/motion.css +40 -0
- package/dist/styles/base.css +83 -82
- package/dist/styles/index.css +8 -1
- package/dist/styles/localization.css +56 -0
- package/dist/styles/reset.css +51 -50
- package/dist/styles/responsive.css +101 -0
- package/dist/styles/themes/dark.css +202 -120
- package/dist/styles/themes/high-contrast.css +290 -119
- package/dist/styles/themes/light.css +201 -119
- package/dist/styles/tokens/breakpoints.css +37 -15
- package/dist/styles/tokens/color.css +96 -96
- package/dist/styles/tokens/compatibility.css +33 -0
- package/dist/styles/tokens/elevation.css +26 -32
- package/dist/styles/tokens/index.css +2 -1
- package/dist/styles/tokens/motion.css +35 -35
- package/dist/styles/tokens/radius.css +26 -21
- package/dist/styles/tokens/spacing.css +56 -50
- package/dist/styles/tokens/typography.css +85 -84
- package/dist/styles/tokens/z-index.css +14 -14
- package/dist/styles/utilities/layout.css +153 -135
- package/dist/styles/utilities/text.css +152 -152
- package/dist/styles/utilities/visibility.css +47 -47
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/docs/accessibility.md +218 -0
- package/docs/appearance-and-theming.md +118 -0
- package/docs/component-architecture.md +137 -0
- package/docs/component-guidelines.md +64 -0
- package/docs/content-and-terminology.md +207 -0
- package/docs/design-system-baseline-audit.md +226 -0
- package/docs/design-token-contract.md +279 -0
- package/docs/localization-and-rtl.md +147 -0
- package/docs/migration.md +142 -0
- package/docs/page-patterns-and-workflows.md +260 -0
- package/docs/responsive-and-adaptive-design.md +351 -0
- package/docs/semantic-role-migration-audit.md +77 -0
- package/docs/states-feedback-and-recovery.md +206 -0
- package/docs/theming.md +5 -0
- package/package.json +53 -17
- package/src/ai/ai-action-button/ai-action-button.css +271 -270
- package/src/ai/ai-approval-card/ai-approval-card.css +323 -320
- package/src/ai/ai-conversation-panel/ai-conversation-panel.css +447 -403
- package/src/ai/ai-prompt-input/ai-prompt-input.css +380 -377
- package/src/ai/ai-proposal-card/ai-proposal-card.css +358 -358
- package/src/ai/ai-suggestion-card/ai-suggestion-card.css +295 -293
- package/src/ai/ai-tool-call/ai-tool-call.css +256 -255
- package/src/ai/index.css +1 -1
- package/src/appearance/cache.ts +236 -0
- package/src/appearance/cookie.ts +184 -0
- package/src/appearance/index.ts +80 -0
- package/src/appearance/preference.ts +121 -0
- package/src/appearance/theme-controller.ts +371 -0
- package/src/appearance/types.ts +61 -0
- package/src/behaviors/announcer.ts +222 -0
- package/src/behaviors/calendar.ts +92 -0
- package/src/behaviors/data-grid.ts +133 -0
- package/src/behaviors/dialog.ts +203 -168
- package/src/behaviors/direction.ts +34 -0
- package/src/behaviors/drawer.ts +210 -177
- package/src/behaviors/dropdown.ts +344 -281
- package/src/behaviors/focus-trap.ts +304 -261
- package/src/behaviors/forms.ts +205 -0
- package/src/behaviors/ids.ts +47 -47
- package/src/behaviors/index.ts +15 -7
- package/src/behaviors/keyboard.ts +305 -303
- package/src/behaviors/overlay.ts +344 -231
- package/src/behaviors/state.ts +282 -0
- package/src/behaviors/tabs.ts +137 -0
- package/src/behaviors/viewport.ts +61 -0
- package/src/components/alert/alert.css +220 -217
- package/src/components/avatar/avatar.css +220 -219
- package/src/components/badge/badge.css +174 -174
- package/src/components/breadcrumb/breadcrumb.css +207 -205
- package/src/components/button/button.css +195 -167
- package/src/components/card/card.css +221 -220
- package/src/components/checkbox/checkbox.css +189 -187
- package/src/components/chip/chip.css +269 -267
- package/src/components/data-grid/data-grid.css +520 -369
- package/src/components/dialog/dialog.css +339 -275
- package/src/components/drawer/drawer.css +484 -403
- package/src/components/dropdown/dropdown.css +316 -298
- package/src/components/icon-button/icon-button.css +162 -158
- package/src/components/index.css +1 -2
- package/src/components/input/input.css +163 -163
- package/src/components/menu/menu.css +315 -314
- package/src/components/pagination/pagination.css +250 -249
- package/src/components/panel/panel.css +284 -283
- package/src/components/progress/progress.css +256 -248
- package/src/components/radio/radio.css +166 -164
- package/src/components/segmented-control/segmented-control.css +205 -205
- package/src/components/select/select.css +117 -103
- package/src/components/skeleton/skeleton.css +262 -262
- package/src/components/split-button/split-button.css +292 -285
- package/src/components/switch/switch.css +195 -181
- package/src/components/table/table.css +220 -0
- package/src/components/tabs/tabs.css +293 -289
- package/src/components/textarea/textarea.css +86 -86
- package/src/components/toast/toast.css +345 -323
- package/src/components/tooltip/tooltip.css +258 -255
- package/src/domain/billing/index.css +498 -498
- package/src/domain/calendar/agenda-list/agenda-list.css +224 -0
- package/src/domain/calendar/day-slice/day-slice.css +384 -383
- package/src/domain/calendar/day-timeline/day-timeline.css +332 -324
- package/src/domain/calendar/event-card/event-card.css +338 -336
- package/src/domain/calendar/index.css +2 -1
- package/src/domain/calendar/month-grid/month-grid.css +426 -420
- package/src/domain/calendar/week-grid/week-grid.css +480 -470
- package/src/domain/companies/index.css +526 -525
- package/src/index.css +5 -5
- package/src/index.ts +7 -5
- package/src/localization/index.ts +56 -0
- package/src/patterns/command-palette/command-palette.css +447 -439
- package/src/patterns/company-switcher/company-switcher.css +390 -363
- package/src/patterns/content-state/content-state.css +236 -0
- package/src/patterns/empty-state/empty-state.css +260 -259
- package/src/patterns/error-state/error-state.css +272 -271
- package/src/patterns/form-layout/form-layout.css +106 -0
- package/src/patterns/index.css +8 -3
- package/src/patterns/loading-state/loading-state.css +287 -287
- package/src/patterns/master-detail/master-detail.css +103 -0
- package/src/patterns/notification-center/notification-center.css +443 -438
- package/src/patterns/page/page.css +219 -0
- package/src/patterns/profile-menu/profile-menu.css +298 -297
- package/src/patterns/search-bar/search-bar.css +457 -444
- package/src/patterns/settings-layout/settings-layout.css +150 -0
- package/src/patterns/workflow/workflow.css +168 -0
- package/src/shell/app-shell/app-shell.css +74 -67
- package/src/shell/content-frame/content-frame.css +93 -93
- package/src/shell/header/header.css +180 -178
- package/src/shell/index.css +6 -6
- package/src/shell/mobile-nav/mobile-nav.css +173 -171
- package/src/shell/sidebar/sidebar.css +146 -146
- package/src/styles/accessibility.css +116 -0
- package/src/styles/animations/motion.css +162 -162
- package/src/styles/appearance/accent.css +173 -0
- package/src/styles/appearance/density.css +61 -0
- package/src/styles/appearance/motion.css +40 -0
- package/src/styles/base.css +83 -82
- package/src/styles/index.css +8 -1
- package/src/styles/localization.css +56 -0
- package/src/styles/reset.css +51 -50
- package/src/styles/responsive.css +101 -0
- package/src/styles/themes/dark.css +202 -120
- package/src/styles/themes/high-contrast.css +290 -119
- package/src/styles/themes/light.css +201 -119
- package/src/styles/tokens/breakpoints.css +37 -15
- package/src/styles/tokens/color.css +96 -96
- package/src/styles/tokens/compatibility.css +33 -0
- package/src/styles/tokens/elevation.css +26 -32
- package/src/styles/tokens/index.css +2 -1
- package/src/styles/tokens/motion.css +35 -35
- package/src/styles/tokens/radius.css +26 -21
- package/src/styles/tokens/spacing.css +56 -50
- package/src/styles/tokens/typography.css +85 -84
- package/src/styles/tokens/z-index.css +14 -14
- package/src/styles/utilities/layout.css +153 -135
- package/src/styles/utilities/text.css +152 -152
- package/src/styles/utilities/visibility.css +47 -47
- package/src/types/index.ts +2 -1
- package/dist/components/modal/modal.css +0 -318
- package/dist/patterns/workspace-switcher/workspace-switcher.css +0 -380
- package/dist/shell/right-drawer/right-drawer.css +0 -108
- package/src/components/modal/modal.css +0 -318
- package/src/patterns/workspace-switcher/workspace-switcher.css +0 -380
- package/src/shell/right-drawer/right-drawer.css +0 -108
|
@@ -1,281 +1,344 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
NtAlign,
|
|
3
|
-
NtDisposable,
|
|
4
|
-
NtRovingFocusController,
|
|
5
|
-
NtSide,
|
|
6
|
-
} from '../types/index.js';
|
|
7
|
-
import { ntSetAriaControls } from './ids.js';
|
|
8
|
-
import {
|
|
9
|
-
NT_KEYS,
|
|
10
|
-
ntCreateRovingFocus,
|
|
11
|
-
ntIsActivationKey,
|
|
12
|
-
} from './keyboard.js';
|
|
13
|
-
import {
|
|
14
|
-
ntCreateOverlay,
|
|
15
|
-
type NtCreateOverlayOptions,
|
|
16
|
-
type NtOverlayController,
|
|
17
|
-
} from './overlay.js';
|
|
18
|
-
|
|
19
|
-
export interface NtDropdownOptions {
|
|
20
|
-
trigger: HTMLElement;
|
|
21
|
-
content: HTMLElement;
|
|
22
|
-
itemSelector?: string;
|
|
23
|
-
side?: NtSide;
|
|
24
|
-
align?: NtAlign;
|
|
25
|
-
initialOpen?: boolean;
|
|
26
|
-
closeOnEscape?: boolean;
|
|
27
|
-
closeOnOutsideClick?: boolean;
|
|
28
|
-
closeOnSelect?: boolean;
|
|
29
|
-
loopFocus?: boolean;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
readonly
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
'
|
|
48
|
-
'
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
content.setAttribute('
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
syncAttributes();
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
if (
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
if (
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
return;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
1
|
+
import type {
|
|
2
|
+
NtAlign,
|
|
3
|
+
NtDisposable,
|
|
4
|
+
NtRovingFocusController,
|
|
5
|
+
NtSide,
|
|
6
|
+
} from '../types/index.js';
|
|
7
|
+
import { ntSetAriaControls } from './ids.js';
|
|
8
|
+
import {
|
|
9
|
+
NT_KEYS,
|
|
10
|
+
ntCreateRovingFocus,
|
|
11
|
+
ntIsActivationKey,
|
|
12
|
+
} from './keyboard.js';
|
|
13
|
+
import {
|
|
14
|
+
ntCreateOverlay,
|
|
15
|
+
type NtCreateOverlayOptions,
|
|
16
|
+
type NtOverlayController,
|
|
17
|
+
} from './overlay.js';
|
|
18
|
+
|
|
19
|
+
export interface NtDropdownOptions {
|
|
20
|
+
trigger: HTMLElement;
|
|
21
|
+
content: HTMLElement;
|
|
22
|
+
itemSelector?: string;
|
|
23
|
+
side?: NtSide;
|
|
24
|
+
align?: NtAlign;
|
|
25
|
+
initialOpen?: boolean;
|
|
26
|
+
closeOnEscape?: boolean;
|
|
27
|
+
closeOnOutsideClick?: boolean;
|
|
28
|
+
closeOnSelect?: boolean;
|
|
29
|
+
loopFocus?: boolean;
|
|
30
|
+
pattern?: 'menu' | 'listbox';
|
|
31
|
+
typeahead?: boolean;
|
|
32
|
+
onOpen?: () => void;
|
|
33
|
+
onClose?: () => void;
|
|
34
|
+
onSelect?: (item: HTMLElement, event: Event) => void;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface NtDropdownController extends NtDisposable {
|
|
38
|
+
readonly trigger: HTMLElement;
|
|
39
|
+
readonly content: HTMLElement;
|
|
40
|
+
readonly isOpen: boolean;
|
|
41
|
+
open(): void;
|
|
42
|
+
close(): void;
|
|
43
|
+
toggle(): void;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const DEFAULT_ITEM_SELECTOR = [
|
|
47
|
+
'[role="menuitem"]',
|
|
48
|
+
'[role="option"]',
|
|
49
|
+
'.nt-dropdown__item',
|
|
50
|
+
'.nt-menu__item',
|
|
51
|
+
].join(',');
|
|
52
|
+
|
|
53
|
+
export function ntCreateMenuPopover(
|
|
54
|
+
options: NtDropdownOptions,
|
|
55
|
+
): NtDropdownController {
|
|
56
|
+
const {
|
|
57
|
+
trigger,
|
|
58
|
+
content,
|
|
59
|
+
itemSelector = DEFAULT_ITEM_SELECTOR,
|
|
60
|
+
side = 'bottom',
|
|
61
|
+
align = 'start',
|
|
62
|
+
initialOpen = false,
|
|
63
|
+
closeOnEscape = true,
|
|
64
|
+
closeOnOutsideClick = true,
|
|
65
|
+
closeOnSelect = true,
|
|
66
|
+
loopFocus = true,
|
|
67
|
+
pattern = 'menu',
|
|
68
|
+
typeahead = true,
|
|
69
|
+
onOpen,
|
|
70
|
+
onClose,
|
|
71
|
+
onSelect,
|
|
72
|
+
} = options;
|
|
73
|
+
|
|
74
|
+
let isOpen = false;
|
|
75
|
+
let rovingFocus: NtRovingFocusController | null = null;
|
|
76
|
+
let typeaheadBuffer = '';
|
|
77
|
+
let typeaheadTimer = 0;
|
|
78
|
+
|
|
79
|
+
const overlayOptions: NtCreateOverlayOptions = {
|
|
80
|
+
closeOnEscape,
|
|
81
|
+
closeOnOutsideClick,
|
|
82
|
+
lockScroll: false,
|
|
83
|
+
outsideElements: [trigger],
|
|
84
|
+
onClose: () => {
|
|
85
|
+
close();
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const overlay: NtOverlayController = ntCreateOverlay(content, overlayOptions);
|
|
90
|
+
|
|
91
|
+
function syncAttributes(): void {
|
|
92
|
+
trigger.setAttribute('aria-haspopup', pattern);
|
|
93
|
+
trigger.setAttribute('aria-expanded', String(isOpen));
|
|
94
|
+
ntSetAriaControls(trigger, content, 'nt-dropdown');
|
|
95
|
+
|
|
96
|
+
content.dataset.state = isOpen ? 'open' : 'closed';
|
|
97
|
+
content.dataset.side = side;
|
|
98
|
+
content.dataset.align = align;
|
|
99
|
+
content.setAttribute('role', pattern);
|
|
100
|
+
|
|
101
|
+
if (isOpen) {
|
|
102
|
+
content.removeAttribute('hidden');
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
content.setAttribute('hidden', '');
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function ensureRovingFocus(): void {
|
|
110
|
+
if (rovingFocus) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
for (const item of content.querySelectorAll<HTMLElement>(itemSelector)) {
|
|
115
|
+
if (!item.hasAttribute('role')) {
|
|
116
|
+
item.setAttribute('role', pattern === 'menu' ? 'menuitem' : 'option');
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
rovingFocus = ntCreateRovingFocus({
|
|
121
|
+
root: content,
|
|
122
|
+
itemSelector,
|
|
123
|
+
orientation: 'vertical',
|
|
124
|
+
loop: loopFocus,
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function focusFirstItem(): void {
|
|
129
|
+
ensureRovingFocus();
|
|
130
|
+
rovingFocus?.focusFirst();
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function focusLastItem(): void {
|
|
134
|
+
ensureRovingFocus();
|
|
135
|
+
rovingFocus?.focusLast();
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function open(): void {
|
|
139
|
+
if (isOpen) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
isOpen = true;
|
|
144
|
+
syncAttributes();
|
|
145
|
+
overlay.activate();
|
|
146
|
+
ensureRovingFocus();
|
|
147
|
+
onOpen?.();
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function close(): void {
|
|
151
|
+
if (!isOpen) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
isOpen = false;
|
|
156
|
+
overlay.deactivate();
|
|
157
|
+
syncAttributes();
|
|
158
|
+
trigger.focus({ preventScroll: true });
|
|
159
|
+
onClose?.();
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function toggle(): void {
|
|
163
|
+
if (isOpen) {
|
|
164
|
+
close();
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
open();
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const handleTriggerClick = () => {
|
|
172
|
+
toggle();
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
const handleTriggerKeyDown = (event: KeyboardEvent) => {
|
|
176
|
+
if (event.key === NT_KEYS.arrowDown) {
|
|
177
|
+
event.preventDefault();
|
|
178
|
+
open();
|
|
179
|
+
queueMicrotask(focusFirstItem);
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (event.key === NT_KEYS.arrowUp) {
|
|
184
|
+
event.preventDefault();
|
|
185
|
+
open();
|
|
186
|
+
queueMicrotask(focusLastItem);
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// Enter/Space remain native button behavior and are handled by click.
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
const handleContentClick = (event: MouseEvent) => {
|
|
194
|
+
const target = event.target;
|
|
195
|
+
|
|
196
|
+
if (!(target instanceof HTMLElement)) {
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const item = target.closest<HTMLElement>(itemSelector);
|
|
201
|
+
|
|
202
|
+
if (!item || !content.contains(item)) {
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
if (
|
|
207
|
+
item.hasAttribute('disabled') ||
|
|
208
|
+
item.getAttribute('aria-disabled') === 'true' ||
|
|
209
|
+
item.dataset.disabled === 'true'
|
|
210
|
+
) {
|
|
211
|
+
event.preventDefault();
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
onSelect?.(item, event);
|
|
216
|
+
|
|
217
|
+
if (closeOnSelect) {
|
|
218
|
+
close();
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
const handleContentKeyDown = (event: KeyboardEvent) => {
|
|
223
|
+
if (event.key === NT_KEYS.escape && closeOnEscape) {
|
|
224
|
+
event.preventDefault();
|
|
225
|
+
close();
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (
|
|
230
|
+
typeahead &&
|
|
231
|
+
event.key.length === 1 &&
|
|
232
|
+
!event.altKey &&
|
|
233
|
+
!event.ctrlKey &&
|
|
234
|
+
!event.metaKey
|
|
235
|
+
) {
|
|
236
|
+
typeaheadBuffer += event.key.toLocaleLowerCase();
|
|
237
|
+
const ownerWindow = content.ownerDocument.defaultView;
|
|
238
|
+
if (ownerWindow) {
|
|
239
|
+
ownerWindow.clearTimeout(typeaheadTimer);
|
|
240
|
+
typeaheadTimer = ownerWindow.setTimeout(() => {
|
|
241
|
+
typeaheadBuffer = '';
|
|
242
|
+
}, 500);
|
|
243
|
+
}
|
|
244
|
+
const items = Array.from(content.querySelectorAll<HTMLElement>(itemSelector)).filter(
|
|
245
|
+
(item) =>
|
|
246
|
+
!item.hasAttribute('disabled') &&
|
|
247
|
+
item.getAttribute('aria-disabled') !== 'true' &&
|
|
248
|
+
item.dataset.disabled !== 'true',
|
|
249
|
+
);
|
|
250
|
+
const match = items.find((item) =>
|
|
251
|
+
(item.textContent ?? '').trim().toLocaleLowerCase().startsWith(typeaheadBuffer),
|
|
252
|
+
);
|
|
253
|
+
if (match) {
|
|
254
|
+
event.preventDefault();
|
|
255
|
+
match.focus({ preventScroll: true });
|
|
256
|
+
}
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
if (!ntIsActivationKey(event)) {
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
const target = event.target;
|
|
265
|
+
|
|
266
|
+
if (!(target instanceof HTMLElement)) {
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
const item = target.closest<HTMLElement>(itemSelector);
|
|
271
|
+
|
|
272
|
+
if (!item || !content.contains(item)) {
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
if (
|
|
277
|
+
item.hasAttribute('disabled') ||
|
|
278
|
+
item.getAttribute('aria-disabled') === 'true' ||
|
|
279
|
+
item.dataset.disabled === 'true'
|
|
280
|
+
) {
|
|
281
|
+
event.preventDefault();
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
event.preventDefault();
|
|
286
|
+
onSelect?.(item, event);
|
|
287
|
+
|
|
288
|
+
if (closeOnSelect) {
|
|
289
|
+
close();
|
|
290
|
+
}
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
trigger.addEventListener('click', handleTriggerClick);
|
|
294
|
+
trigger.addEventListener('keydown', handleTriggerKeyDown);
|
|
295
|
+
content.addEventListener('click', handleContentClick);
|
|
296
|
+
content.addEventListener('keydown', handleContentKeyDown);
|
|
297
|
+
|
|
298
|
+
syncAttributes();
|
|
299
|
+
|
|
300
|
+
if (initialOpen) {
|
|
301
|
+
open();
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
return {
|
|
305
|
+
trigger,
|
|
306
|
+
content,
|
|
307
|
+
|
|
308
|
+
get isOpen() {
|
|
309
|
+
return isOpen;
|
|
310
|
+
},
|
|
311
|
+
|
|
312
|
+
open,
|
|
313
|
+
close,
|
|
314
|
+
toggle,
|
|
315
|
+
|
|
316
|
+
destroy() {
|
|
317
|
+
trigger.removeEventListener('click', handleTriggerClick);
|
|
318
|
+
trigger.removeEventListener('keydown', handleTriggerKeyDown);
|
|
319
|
+
content.removeEventListener('click', handleContentClick);
|
|
320
|
+
content.removeEventListener('keydown', handleContentKeyDown);
|
|
321
|
+
rovingFocus?.destroy();
|
|
322
|
+
content.ownerDocument.defaultView?.clearTimeout(typeaheadTimer);
|
|
323
|
+
overlay.destroy();
|
|
324
|
+
},
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* Compatibility name for the canonical menu/popover controller.
|
|
330
|
+
* The public dropdown pattern remains supported.
|
|
331
|
+
*/
|
|
332
|
+
export function ntCreateDropdown(
|
|
333
|
+
options: NtDropdownOptions,
|
|
334
|
+
): NtDropdownController {
|
|
335
|
+
return ntCreateMenuPopover(options);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
export type NtMenuOptions = Omit<NtDropdownOptions, 'pattern'>;
|
|
339
|
+
export type NtMenuController = NtDropdownController;
|
|
340
|
+
|
|
341
|
+
/** Creates the canonical application-menu behavior over the shared popover foundation. */
|
|
342
|
+
export function ntCreateMenu(options: NtMenuOptions): NtMenuController {
|
|
343
|
+
return ntCreateMenuPopover({ ...options, pattern: 'menu' });
|
|
344
|
+
}
|