@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
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type { NtDisposable } from '../types/index.js';
|
|
2
|
+
import { NT_KEYS } from './keyboard.js';
|
|
3
|
+
import { ntGetInlineArrowKeys } from './direction.js';
|
|
4
|
+
|
|
5
|
+
export interface NtCalendarGridOptions {
|
|
6
|
+
root: HTMLElement;
|
|
7
|
+
dateSelector?: string;
|
|
8
|
+
columns?: number;
|
|
9
|
+
liveRegion?: HTMLElement | null;
|
|
10
|
+
onSelect?: (date: HTMLElement) => void;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface NtCalendarGridController extends NtDisposable {
|
|
14
|
+
readonly root: HTMLElement;
|
|
15
|
+
focusDate(index: number): void;
|
|
16
|
+
announceRange(message: string): void;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function ntCreateCalendarGrid(options: NtCalendarGridOptions): NtCalendarGridController {
|
|
20
|
+
const {
|
|
21
|
+
root,
|
|
22
|
+
dateSelector = '[data-nt-calendar-date]',
|
|
23
|
+
columns = 7,
|
|
24
|
+
liveRegion = null,
|
|
25
|
+
onSelect,
|
|
26
|
+
} = options;
|
|
27
|
+
root.setAttribute('role', 'grid');
|
|
28
|
+
|
|
29
|
+
function dates(): HTMLElement[] {
|
|
30
|
+
return Array.from(root.querySelectorAll<HTMLElement>(dateSelector)).filter(
|
|
31
|
+
(date) => !date.hasAttribute('disabled') && date.getAttribute('aria-disabled') !== 'true',
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function focusDate(index: number): void {
|
|
36
|
+
const items = dates();
|
|
37
|
+
const target = items[Math.max(0, Math.min(index, items.length - 1))];
|
|
38
|
+
if (!target) return;
|
|
39
|
+
items.forEach((item) => {
|
|
40
|
+
item.tabIndex = item === target ? 0 : -1;
|
|
41
|
+
if (!item.hasAttribute('role')) item.setAttribute('role', 'gridcell');
|
|
42
|
+
});
|
|
43
|
+
target.focus({ preventScroll: true });
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const handleKeyDown = (event: KeyboardEvent) => {
|
|
47
|
+
const target = event.target;
|
|
48
|
+
if (!(target instanceof HTMLElement)) return;
|
|
49
|
+
const date = target.closest<HTMLElement>(dateSelector);
|
|
50
|
+
const items = dates();
|
|
51
|
+
const index = date ? items.indexOf(date) : -1;
|
|
52
|
+
if (index < 0) return;
|
|
53
|
+
const inlineKeys = ntGetInlineArrowKeys(root);
|
|
54
|
+
let next: number | null = null;
|
|
55
|
+
if (event.key === inlineKeys.next) next = index + 1;
|
|
56
|
+
else if (event.key === inlineKeys.previous) next = index - 1;
|
|
57
|
+
else if (event.key === NT_KEYS.arrowDown) next = index + columns;
|
|
58
|
+
else if (event.key === NT_KEYS.arrowUp) next = index - columns;
|
|
59
|
+
else if (event.key === NT_KEYS.home) next = index - (index % columns);
|
|
60
|
+
else if (event.key === NT_KEYS.end) next = index + (columns - 1 - (index % columns));
|
|
61
|
+
if (next !== null) {
|
|
62
|
+
event.preventDefault();
|
|
63
|
+
focusDate(next);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const handleClick = (event: MouseEvent) => {
|
|
68
|
+
const target = event.target;
|
|
69
|
+
if (!(target instanceof Element)) return;
|
|
70
|
+
const date = target.closest<HTMLElement>(dateSelector);
|
|
71
|
+
if (!date || !root.contains(date) || date.getAttribute('aria-disabled') === 'true') return;
|
|
72
|
+
for (const item of dates()) item.setAttribute('aria-selected', String(item === date));
|
|
73
|
+
onSelect?.(date);
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
root.addEventListener('keydown', handleKeyDown);
|
|
77
|
+
root.addEventListener('click', handleClick);
|
|
78
|
+
const initial = dates().findIndex((date) => date.getAttribute('aria-selected') === 'true');
|
|
79
|
+
focusDate(initial >= 0 ? initial : 0);
|
|
80
|
+
|
|
81
|
+
return {
|
|
82
|
+
root,
|
|
83
|
+
focusDate,
|
|
84
|
+
announceRange(message: string) {
|
|
85
|
+
if (liveRegion) liveRegion.textContent = message.trim();
|
|
86
|
+
},
|
|
87
|
+
destroy() {
|
|
88
|
+
root.removeEventListener('keydown', handleKeyDown);
|
|
89
|
+
root.removeEventListener('click', handleClick);
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import type { NtDisposable } from '../types/index.js';
|
|
2
|
+
import { NT_KEYS, ntIsActivationKey } from './keyboard.js';
|
|
3
|
+
import { ntGetInlineArrowKeys } from './direction.js';
|
|
4
|
+
|
|
5
|
+
export type NtGridSortDirection = 'ascending' | 'descending' | 'none';
|
|
6
|
+
|
|
7
|
+
export interface NtDataGridOptions {
|
|
8
|
+
root: HTMLElement;
|
|
9
|
+
rowSelector?: string;
|
|
10
|
+
cellSelector?: string;
|
|
11
|
+
selection?: 'none' | 'row' | 'cell';
|
|
12
|
+
liveRegion?: HTMLElement | null;
|
|
13
|
+
onActivate?: (cell: HTMLElement, event: KeyboardEvent) => void;
|
|
14
|
+
onSelectionChange?: (target: HTMLElement) => void;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface NtDataGridController extends NtDisposable {
|
|
18
|
+
readonly root: HTMLElement;
|
|
19
|
+
focusCell(row: number, column: number): void;
|
|
20
|
+
setSort(header: HTMLElement, direction: NtGridSortDirection, announcement?: string): void;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function ntCreateDataGrid(options: NtDataGridOptions): NtDataGridController {
|
|
24
|
+
const {
|
|
25
|
+
root,
|
|
26
|
+
rowSelector = '[role="row"]',
|
|
27
|
+
cellSelector = '[role="gridcell"],[role="columnheader"],[role="rowheader"]',
|
|
28
|
+
selection = 'none',
|
|
29
|
+
liveRegion = null,
|
|
30
|
+
onActivate,
|
|
31
|
+
onSelectionChange,
|
|
32
|
+
} = options;
|
|
33
|
+
root.setAttribute('role', 'grid');
|
|
34
|
+
|
|
35
|
+
function matrix(): HTMLElement[][] {
|
|
36
|
+
return Array.from(root.querySelectorAll<HTMLElement>(rowSelector))
|
|
37
|
+
.map((row) => Array.from(row.querySelectorAll<HTMLElement>(cellSelector)))
|
|
38
|
+
.filter((row) => row.length > 0);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function enabled(cell: HTMLElement | undefined): cell is HTMLElement {
|
|
42
|
+
return Boolean(
|
|
43
|
+
cell &&
|
|
44
|
+
cell.getAttribute('aria-disabled') !== 'true' &&
|
|
45
|
+
cell.dataset.disabled !== 'true',
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function focusCell(rowIndex: number, columnIndex: number): void {
|
|
50
|
+
const rows = matrix();
|
|
51
|
+
const row = rows[Math.max(0, Math.min(rowIndex, rows.length - 1))];
|
|
52
|
+
if (!row) return;
|
|
53
|
+
const cell = row[Math.max(0, Math.min(columnIndex, row.length - 1))];
|
|
54
|
+
if (!enabled(cell)) return;
|
|
55
|
+
for (const candidate of rows.flat()) candidate.tabIndex = candidate === cell ? 0 : -1;
|
|
56
|
+
cell.focus({ preventScroll: true });
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function coordinates(cell: HTMLElement): [number, number] {
|
|
60
|
+
const rows = matrix();
|
|
61
|
+
const row = rows.findIndex((candidate) => candidate.includes(cell));
|
|
62
|
+
return [row, row >= 0 ? rows[row]?.indexOf(cell) ?? -1 : -1];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function selectCell(cell: HTMLElement): void {
|
|
66
|
+
if (selection === 'none' || !enabled(cell)) return;
|
|
67
|
+
const selected = selection === 'row' ? cell.closest<HTMLElement>(rowSelector) : cell;
|
|
68
|
+
if (!selected) return;
|
|
69
|
+
const selector = selection === 'row' ? rowSelector : cellSelector;
|
|
70
|
+
for (const candidate of root.querySelectorAll<HTMLElement>(selector)) {
|
|
71
|
+
if (candidate.hasAttribute('aria-selected')) candidate.setAttribute('aria-selected', 'false');
|
|
72
|
+
}
|
|
73
|
+
selected.setAttribute('aria-selected', 'true');
|
|
74
|
+
onSelectionChange?.(selected);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const handleKeyDown = (event: KeyboardEvent) => {
|
|
78
|
+
const target = event.target;
|
|
79
|
+
if (!(target instanceof HTMLElement)) return;
|
|
80
|
+
const cell = target.closest<HTMLElement>(cellSelector);
|
|
81
|
+
if (!cell || !root.contains(cell)) return;
|
|
82
|
+
const [row, column] = coordinates(cell);
|
|
83
|
+
const inlineKeys = ntGetInlineArrowKeys(root);
|
|
84
|
+
let next: [number, number] | null = null;
|
|
85
|
+
if (event.key === inlineKeys.next) next = [row, column + 1];
|
|
86
|
+
else if (event.key === inlineKeys.previous) next = [row, column - 1];
|
|
87
|
+
else if (event.key === NT_KEYS.arrowDown) next = [row + 1, column];
|
|
88
|
+
else if (event.key === NT_KEYS.arrowUp) next = [row - 1, column];
|
|
89
|
+
else if (event.key === NT_KEYS.home) next = event.ctrlKey ? [0, 0] : [row, 0];
|
|
90
|
+
else if (event.key === NT_KEYS.end) {
|
|
91
|
+
const rows = matrix();
|
|
92
|
+
const targetRow = event.ctrlKey ? rows.length - 1 : row;
|
|
93
|
+
next = [targetRow, (rows[targetRow]?.length ?? 1) - 1];
|
|
94
|
+
} else if (event.target === cell && ntIsActivationKey(event)) {
|
|
95
|
+
event.preventDefault();
|
|
96
|
+
selectCell(cell);
|
|
97
|
+
onActivate?.(cell, event);
|
|
98
|
+
}
|
|
99
|
+
if (next) {
|
|
100
|
+
event.preventDefault();
|
|
101
|
+
focusCell(...next);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const handleClick = (event: MouseEvent) => {
|
|
106
|
+
const target = event.target;
|
|
107
|
+
if (!(target instanceof Element)) return;
|
|
108
|
+
const cell = target.closest<HTMLElement>(cellSelector);
|
|
109
|
+
if (!cell || !root.contains(cell)) return;
|
|
110
|
+
selectCell(cell);
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
root.addEventListener('keydown', handleKeyDown);
|
|
114
|
+
root.addEventListener('click', handleClick);
|
|
115
|
+
const first = matrix().flat().find(enabled);
|
|
116
|
+
if (first && !matrix().flat().some((cell) => cell.tabIndex === 0)) first.tabIndex = 0;
|
|
117
|
+
|
|
118
|
+
return {
|
|
119
|
+
root,
|
|
120
|
+
focusCell,
|
|
121
|
+
setSort(header, direction, announcement) {
|
|
122
|
+
for (const candidate of root.querySelectorAll<HTMLElement>('[aria-sort]')) {
|
|
123
|
+
if (candidate !== header) candidate.setAttribute('aria-sort', 'none');
|
|
124
|
+
}
|
|
125
|
+
header.setAttribute('aria-sort', direction);
|
|
126
|
+
if (liveRegion && announcement) liveRegion.textContent = announcement;
|
|
127
|
+
},
|
|
128
|
+
destroy() {
|
|
129
|
+
root.removeEventListener('keydown', handleKeyDown);
|
|
130
|
+
root.removeEventListener('click', handleClick);
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
}
|
package/src/behaviors/dialog.ts
CHANGED
|
@@ -1,168 +1,203 @@
|
|
|
1
|
-
import type { NtDisposable } from '../types/index.js';
|
|
2
|
-
import {
|
|
3
|
-
ntCreateFocusTrap,
|
|
4
|
-
type NtFocusTrapController,
|
|
5
|
-
type NtFocusTrapOptions,
|
|
6
|
-
} from './focus-trap.js';
|
|
7
|
-
import {
|
|
8
|
-
ntCreateOverlay,
|
|
9
|
-
type NtCreateOverlayOptions,
|
|
10
|
-
type NtOverlayController,
|
|
11
|
-
} from './overlay.js';
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
backdrop
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
1
|
+
import type { NtDisposable } from '../types/index.js';
|
|
2
|
+
import {
|
|
3
|
+
ntCreateFocusTrap,
|
|
4
|
+
type NtFocusTrapController,
|
|
5
|
+
type NtFocusTrapOptions,
|
|
6
|
+
} from './focus-trap.js';
|
|
7
|
+
import {
|
|
8
|
+
ntCreateOverlay,
|
|
9
|
+
type NtCreateOverlayOptions,
|
|
10
|
+
type NtOverlayController,
|
|
11
|
+
} from './overlay.js';
|
|
12
|
+
import {
|
|
13
|
+
ntSetAriaControls,
|
|
14
|
+
ntSetAriaDescribedBy,
|
|
15
|
+
ntSetAriaLabelledBy,
|
|
16
|
+
} from './ids.js';
|
|
17
|
+
|
|
18
|
+
export interface NtDialogOptions {
|
|
19
|
+
trigger?: HTMLElement | null;
|
|
20
|
+
dialog: HTMLElement;
|
|
21
|
+
backdrop?: HTMLElement | null;
|
|
22
|
+
title?: HTMLElement | null;
|
|
23
|
+
description?: HTMLElement | null;
|
|
24
|
+
/** Modal dialogs trap focus and make the background inert. Defaults to true. */
|
|
25
|
+
modal?: boolean;
|
|
26
|
+
role?: 'dialog' | 'alertdialog';
|
|
27
|
+
initialOpen?: boolean;
|
|
28
|
+
closeOnEscape?: boolean;
|
|
29
|
+
closeOnOutsideClick?: boolean;
|
|
30
|
+
lockScroll?: boolean;
|
|
31
|
+
restoreFocus?: boolean;
|
|
32
|
+
initialFocus?: NtFocusTrapOptions['initialFocus'];
|
|
33
|
+
onOpen?: () => void;
|
|
34
|
+
onClose?: () => void;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface NtDialogController extends NtDisposable {
|
|
38
|
+
readonly dialog: HTMLElement;
|
|
39
|
+
readonly trigger: HTMLElement | null;
|
|
40
|
+
readonly backdrop: HTMLElement | null;
|
|
41
|
+
readonly isOpen: boolean;
|
|
42
|
+
open(): void;
|
|
43
|
+
close(): void;
|
|
44
|
+
toggle(): void;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function ntCreateDialog(options: NtDialogOptions): NtDialogController {
|
|
48
|
+
const {
|
|
49
|
+
trigger = null,
|
|
50
|
+
dialog,
|
|
51
|
+
backdrop = null,
|
|
52
|
+
title = null,
|
|
53
|
+
description = null,
|
|
54
|
+
modal = true,
|
|
55
|
+
role = 'dialog',
|
|
56
|
+
initialOpen = false,
|
|
57
|
+
closeOnEscape = true,
|
|
58
|
+
closeOnOutsideClick = true,
|
|
59
|
+
lockScroll = modal,
|
|
60
|
+
restoreFocus = true,
|
|
61
|
+
initialFocus = null,
|
|
62
|
+
onOpen,
|
|
63
|
+
onClose,
|
|
64
|
+
} = options;
|
|
65
|
+
|
|
66
|
+
let isOpen = false;
|
|
67
|
+
|
|
68
|
+
const overlayOptions: NtCreateOverlayOptions = {
|
|
69
|
+
closeOnEscape,
|
|
70
|
+
closeOnOutsideClick,
|
|
71
|
+
lockScroll,
|
|
72
|
+
outsideElements: trigger ? [trigger] : [],
|
|
73
|
+
inertBackground: modal,
|
|
74
|
+
inertExcludeElements: [backdrop],
|
|
75
|
+
onClose: () => {
|
|
76
|
+
close();
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const overlay: NtOverlayController = ntCreateOverlay(dialog, overlayOptions);
|
|
81
|
+
|
|
82
|
+
const focusTrap: NtFocusTrapController = ntCreateFocusTrap(dialog, {
|
|
83
|
+
initialFocus,
|
|
84
|
+
fallbackFocus: dialog,
|
|
85
|
+
restoreFocus,
|
|
86
|
+
escapeDeactivates: false,
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
function syncAttributes(): void {
|
|
90
|
+
dialog.setAttribute('role', role);
|
|
91
|
+
if (modal) dialog.setAttribute('aria-modal', 'true');
|
|
92
|
+
else dialog.removeAttribute('aria-modal');
|
|
93
|
+
dialog.dataset.state = isOpen ? 'open' : 'closed';
|
|
94
|
+
|
|
95
|
+
if (backdrop) {
|
|
96
|
+
backdrop.dataset.state = isOpen ? 'open' : 'closed';
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (trigger) {
|
|
100
|
+
trigger.setAttribute('aria-expanded', String(isOpen));
|
|
101
|
+
ntSetAriaControls(trigger, dialog, 'nt-dialog');
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (title) {
|
|
105
|
+
ntSetAriaLabelledBy(dialog, title, 'nt-dialog-title');
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (description) {
|
|
109
|
+
ntSetAriaDescribedBy(dialog, description, 'nt-dialog-description');
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (isOpen) {
|
|
113
|
+
dialog.removeAttribute('hidden');
|
|
114
|
+
backdrop?.removeAttribute('hidden');
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
dialog.setAttribute('hidden', '');
|
|
119
|
+
backdrop?.setAttribute('hidden', '');
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function open(): void {
|
|
123
|
+
if (isOpen) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
isOpen = true;
|
|
128
|
+
syncAttributes();
|
|
129
|
+
overlay.activate();
|
|
130
|
+
if (modal) focusTrap.activate();
|
|
131
|
+
onOpen?.();
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function close(): void {
|
|
135
|
+
if (!isOpen) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
isOpen = false;
|
|
140
|
+
overlay.deactivate();
|
|
141
|
+
if (modal) focusTrap.deactivate();
|
|
142
|
+
syncAttributes();
|
|
143
|
+
onClose?.();
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function toggle(): void {
|
|
147
|
+
if (isOpen) {
|
|
148
|
+
close();
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
open();
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const triggerListener = () => {
|
|
156
|
+
toggle();
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
trigger?.addEventListener('click', triggerListener);
|
|
160
|
+
|
|
161
|
+
syncAttributes();
|
|
162
|
+
|
|
163
|
+
if (initialOpen) {
|
|
164
|
+
open();
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return {
|
|
168
|
+
dialog,
|
|
169
|
+
trigger,
|
|
170
|
+
backdrop,
|
|
171
|
+
|
|
172
|
+
get isOpen() {
|
|
173
|
+
return isOpen;
|
|
174
|
+
},
|
|
175
|
+
|
|
176
|
+
open,
|
|
177
|
+
close,
|
|
178
|
+
toggle,
|
|
179
|
+
|
|
180
|
+
destroy() {
|
|
181
|
+
trigger?.removeEventListener('click', triggerListener);
|
|
182
|
+
focusTrap.destroy();
|
|
183
|
+
overlay.destroy();
|
|
184
|
+
},
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** @deprecated Modal is a mode of `NtDialogOptions`; use `NtDialogOptions`. */
|
|
189
|
+
export type NtModalOptions = NtDialogOptions;
|
|
190
|
+
|
|
191
|
+
/** @deprecated Modal is a mode of `NtDialogController`; use `NtDialogController`. */
|
|
192
|
+
export type NtModalController = NtDialogController;
|
|
193
|
+
|
|
194
|
+
/** @deprecated Use `ntCreateDialog({ ...options, modal: true })`. */
|
|
195
|
+
export function ntCreateModal(options: NtModalOptions): NtModalController {
|
|
196
|
+
return ntCreateDialog({ ...options, modal: true });
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/** Unprefixed compatibility export; canonical Neetechs code uses `ntCreateDialog`. */
|
|
200
|
+
export const createDialog = ntCreateDialog;
|
|
201
|
+
|
|
202
|
+
/** @deprecated Use `ntCreateDialog` or `createDialog` with `modal: true`. */
|
|
203
|
+
export const createModal = ntCreateModal;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export type NtDirection = 'ltr' | 'rtl';
|
|
2
|
+
|
|
3
|
+
export interface NtInlineArrowKeys {
|
|
4
|
+
previous: 'ArrowLeft' | 'ArrowRight';
|
|
5
|
+
next: 'ArrowLeft' | 'ArrowRight';
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
function explicitDirection(element: Element | null): NtDirection | null {
|
|
9
|
+
for (let current: Element | null = element; current; current = current.parentElement) {
|
|
10
|
+
const value = current.getAttribute('dir')?.toLowerCase();
|
|
11
|
+
if (value === 'ltr' || value === 'rtl') return value;
|
|
12
|
+
}
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Resolves the nearest native direction without requiring window or layout reads. */
|
|
17
|
+
export function ntResolveDirection(
|
|
18
|
+
element?: Element | null,
|
|
19
|
+
fallback: NtDirection = 'ltr',
|
|
20
|
+
): NtDirection {
|
|
21
|
+
const fromElement = explicitDirection(element ?? null);
|
|
22
|
+
if (fromElement) return fromElement;
|
|
23
|
+
|
|
24
|
+
const documentElement = element?.ownerDocument?.documentElement;
|
|
25
|
+
const fromDocument = explicitDirection(documentElement ?? null);
|
|
26
|
+
return fromDocument ?? fallback;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Maps visual inline movement while leaving vertical and text-editing keys untouched. */
|
|
30
|
+
export function ntGetInlineArrowKeys(element?: Element | null): NtInlineArrowKeys {
|
|
31
|
+
return ntResolveDirection(element) === 'rtl'
|
|
32
|
+
? { previous: 'ArrowRight', next: 'ArrowLeft' }
|
|
33
|
+
: { previous: 'ArrowLeft', next: 'ArrowRight' };
|
|
34
|
+
}
|