@a11ypros/a11y-ui-components 1.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/dist/components/Button/Button.css +259 -0
- package/dist/components/Button/Button.d.ts +37 -0
- package/dist/components/Button/Button.d.ts.map +1 -0
- package/dist/components/Button/Button.js +52 -0
- package/dist/components/Button/index.d.ts +3 -0
- package/dist/components/Button/index.d.ts.map +1 -0
- package/dist/components/Button/index.js +1 -0
- package/dist/components/DataTable/DataTable.css +132 -0
- package/dist/components/DataTable/DataTable.d.ts +71 -0
- package/dist/components/DataTable/DataTable.d.ts.map +1 -0
- package/dist/components/DataTable/DataTable.js +122 -0
- package/dist/components/DataTable/index.d.ts +3 -0
- package/dist/components/DataTable/index.d.ts.map +1 -0
- package/dist/components/DataTable/index.js +1 -0
- package/dist/components/Form/Checkbox.css +46 -0
- package/dist/components/Form/Checkbox.d.ts +36 -0
- package/dist/components/Form/Checkbox.d.ts.map +1 -0
- package/dist/components/Form/Checkbox.js +39 -0
- package/dist/components/Form/Fieldset.css +43 -0
- package/dist/components/Form/Fieldset.d.ts +33 -0
- package/dist/components/Form/Fieldset.d.ts.map +1 -0
- package/dist/components/Form/Fieldset.js +34 -0
- package/dist/components/Form/Input.css +76 -0
- package/dist/components/Form/Input.d.ts +37 -0
- package/dist/components/Form/Input.d.ts.map +1 -0
- package/dist/components/Form/Input.js +41 -0
- package/dist/components/Form/Label.css +13 -0
- package/dist/components/Form/Label.d.ts +30 -0
- package/dist/components/Form/Label.d.ts.map +1 -0
- package/dist/components/Form/Label.js +30 -0
- package/dist/components/Form/Radio.css +81 -0
- package/dist/components/Form/Radio.d.ts +53 -0
- package/dist/components/Form/Radio.d.ts.map +1 -0
- package/dist/components/Form/Radio.js +39 -0
- package/dist/components/Form/Select.css +69 -0
- package/dist/components/Form/Select.d.ts +51 -0
- package/dist/components/Form/Select.d.ts.map +1 -0
- package/dist/components/Form/Select.js +49 -0
- package/dist/components/Form/Textarea.css +79 -0
- package/dist/components/Form/Textarea.d.ts +44 -0
- package/dist/components/Form/Textarea.d.ts.map +1 -0
- package/dist/components/Form/Textarea.js +43 -0
- package/dist/components/Form/index.d.ts +8 -0
- package/dist/components/Form/index.d.ts.map +1 -0
- package/dist/components/Form/index.js +7 -0
- package/dist/components/Link/Link.css +70 -0
- package/dist/components/Link/Link.d.ts +34 -0
- package/dist/components/Link/Link.d.ts.map +1 -0
- package/dist/components/Link/Link.js +48 -0
- package/dist/components/Link/index.d.ts +3 -0
- package/dist/components/Link/index.d.ts.map +1 -0
- package/dist/components/Link/index.js +1 -0
- package/dist/components/Modal/Modal.css +118 -0
- package/dist/components/Modal/Modal.d.ts +64 -0
- package/dist/components/Modal/Modal.d.ts.map +1 -0
- package/dist/components/Modal/Modal.js +108 -0
- package/dist/components/Modal/index.d.ts +3 -0
- package/dist/components/Modal/index.d.ts.map +1 -0
- package/dist/components/Modal/index.js +1 -0
- package/dist/components/Tabs/Tabs.css +132 -0
- package/dist/components/Tabs/Tabs.d.ts +63 -0
- package/dist/components/Tabs/Tabs.d.ts.map +1 -0
- package/dist/components/Tabs/Tabs.js +134 -0
- package/dist/components/Tabs/index.d.ts +3 -0
- package/dist/components/Tabs/index.d.ts.map +1 -0
- package/dist/components/Tabs/index.js +1 -0
- package/dist/components/Toast/Toast.css +100 -0
- package/dist/components/Toast/Toast.d.ts +59 -0
- package/dist/components/Toast/Toast.d.ts.map +1 -0
- package/dist/components/Toast/Toast.js +91 -0
- package/dist/components/Toast/ToastProvider.css +48 -0
- package/dist/components/Toast/ToastProvider.d.ts +22 -0
- package/dist/components/Toast/ToastProvider.d.ts.map +1 -0
- package/dist/components/Toast/ToastProvider.js +33 -0
- package/dist/components/Toast/index.d.ts +5 -0
- package/dist/components/Toast/index.d.ts.map +1 -0
- package/dist/components/Toast/index.js +2 -0
- package/dist/hooks/useAriaLive.d.ts +9 -0
- package/dist/hooks/useAriaLive.d.ts.map +1 -0
- package/dist/hooks/useAriaLive.js +39 -0
- package/dist/hooks/useFocusReturn.d.ts +9 -0
- package/dist/hooks/useFocusReturn.d.ts.map +1 -0
- package/dist/hooks/useFocusReturn.js +33 -0
- package/dist/hooks/useFocusTrap.d.ts +9 -0
- package/dist/hooks/useFocusTrap.d.ts.map +1 -0
- package/dist/hooks/useFocusTrap.js +68 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/styles/components.css +33 -0
- package/dist/styles/global.css +289 -0
- package/dist/styles/index.d.ts +3 -0
- package/dist/styles/index.d.ts.map +1 -0
- package/dist/styles/index.js +1 -0
- package/dist/tokens/breakpoints.d.ts +25 -0
- package/dist/tokens/breakpoints.d.ts.map +1 -0
- package/dist/tokens/breakpoints.js +23 -0
- package/dist/tokens/colors.d.ts +81 -0
- package/dist/tokens/colors.d.ts.map +1 -0
- package/dist/tokens/colors.js +86 -0
- package/dist/tokens/index.d.ts +6 -0
- package/dist/tokens/index.d.ts.map +1 -0
- package/dist/tokens/index.js +5 -0
- package/dist/tokens/motion.d.ts +30 -0
- package/dist/tokens/motion.d.ts.map +1 -0
- package/dist/tokens/motion.js +34 -0
- package/dist/tokens/spacing.d.ts +22 -0
- package/dist/tokens/spacing.d.ts.map +1 -0
- package/dist/tokens/spacing.js +20 -0
- package/dist/tokens/theme.d.ts +159 -0
- package/dist/tokens/theme.d.ts.map +1 -0
- package/dist/tokens/theme.js +15 -0
- package/dist/tokens/typography.d.ts +45 -0
- package/dist/tokens/typography.d.ts.map +1 -0
- package/dist/tokens/typography.js +56 -0
- package/dist/utils/aria.d.ts +60 -0
- package/dist/utils/aria.d.ts.map +1 -0
- package/dist/utils/aria.js +86 -0
- package/dist/utils/focus.d.ts +30 -0
- package/dist/utils/focus.d.ts.map +1 -0
- package/dist/utils/focus.js +80 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +3 -0
- package/dist/utils/keyboard.d.ts +38 -0
- package/dist/utils/keyboard.d.ts.map +1 -0
- package/dist/utils/keyboard.js +59 -0
- package/package.json +68 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import './Modal.css';
|
|
3
|
+
export interface ModalProps {
|
|
4
|
+
/**
|
|
5
|
+
* Whether the modal is open
|
|
6
|
+
*/
|
|
7
|
+
isOpen: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Callback when modal should close
|
|
10
|
+
*/
|
|
11
|
+
onClose: () => void;
|
|
12
|
+
/**
|
|
13
|
+
* Title of the modal (required for accessibility)
|
|
14
|
+
*/
|
|
15
|
+
title: string;
|
|
16
|
+
/**
|
|
17
|
+
* Content of the modal
|
|
18
|
+
*/
|
|
19
|
+
children: React.ReactNode;
|
|
20
|
+
/**
|
|
21
|
+
* Whether to close on backdrop click
|
|
22
|
+
*/
|
|
23
|
+
closeOnBackdropClick?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Whether to close on ESC key press
|
|
26
|
+
*/
|
|
27
|
+
closeOnEscape?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Size of the modal
|
|
30
|
+
*/
|
|
31
|
+
size?: 'sm' | 'md' | 'lg' | 'full';
|
|
32
|
+
/**
|
|
33
|
+
* Element to return focus to when modal closes
|
|
34
|
+
*/
|
|
35
|
+
returnFocusTo?: HTMLElement | null;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Accessible Modal component using HTML5 dialog element
|
|
39
|
+
*
|
|
40
|
+
* Uses the native `<dialog>` element which provides:
|
|
41
|
+
* - Built-in focus management and focus trapping
|
|
42
|
+
* - Automatic body scroll prevention
|
|
43
|
+
* - Native backdrop overlay
|
|
44
|
+
* - ESC key handling (configurable)
|
|
45
|
+
*
|
|
46
|
+
* WCAG Compliance:
|
|
47
|
+
* - 2.1.1 Keyboard: ESC key support, built-in focus trap
|
|
48
|
+
* - 2.1.2 No Keyboard Trap: Focus returns to trigger
|
|
49
|
+
* - 2.4.3 Focus Order: Focus trapped within modal (native behavior)
|
|
50
|
+
* - 4.1.2 Name, Role, Value: ARIA modal pattern
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```tsx
|
|
54
|
+
* <Modal
|
|
55
|
+
* isOpen={isOpen}
|
|
56
|
+
* onClose={() => setIsOpen(false)}
|
|
57
|
+
* title="Confirm Action"
|
|
58
|
+
* >
|
|
59
|
+
* <p>Are you sure?</p>
|
|
60
|
+
* </Modal>
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export declare const Modal: React.FC<ModalProps>;
|
|
64
|
+
//# sourceMappingURL=Modal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Modal.d.ts","sourceRoot":"","sources":["../../../src/components/Modal/Modal.tsx"],"names":[],"mappings":"AAEA,OAAO,KAA4B,MAAM,OAAO,CAAA;AAGhD,OAAO,aAAa,CAAA;AAEpB,MAAM,WAAW,UAAU;IACzB;;OAEG;IACH,MAAM,EAAE,OAAO,CAAA;IAEf;;OAEG;IACH,OAAO,EAAE,MAAM,IAAI,CAAA;IAEnB;;OAEG;IACH,KAAK,EAAE,MAAM,CAAA;IAEb;;OAEG;IACH,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;IAEzB;;OAEG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAA;IAE9B;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;IAEvB;;OAEG;IACH,IAAI,CAAC,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,MAAM,CAAA;IAElC;;OAEG;IACH,aAAa,CAAC,EAAE,WAAW,GAAG,IAAI,CAAA;CACnC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,KAAK,EAAE,KAAK,CAAC,EAAE,CAAC,UAAU,CA2HtC,CAAA"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import React, { useEffect, useRef } from 'react';
|
|
4
|
+
import { useFocusReturn } from '../../hooks/useFocusReturn';
|
|
5
|
+
import { Button } from '../Button/Button';
|
|
6
|
+
import './Modal.css';
|
|
7
|
+
/**
|
|
8
|
+
* Accessible Modal component using HTML5 dialog element
|
|
9
|
+
*
|
|
10
|
+
* Uses the native `<dialog>` element which provides:
|
|
11
|
+
* - Built-in focus management and focus trapping
|
|
12
|
+
* - Automatic body scroll prevention
|
|
13
|
+
* - Native backdrop overlay
|
|
14
|
+
* - ESC key handling (configurable)
|
|
15
|
+
*
|
|
16
|
+
* WCAG Compliance:
|
|
17
|
+
* - 2.1.1 Keyboard: ESC key support, built-in focus trap
|
|
18
|
+
* - 2.1.2 No Keyboard Trap: Focus returns to trigger
|
|
19
|
+
* - 2.4.3 Focus Order: Focus trapped within modal (native behavior)
|
|
20
|
+
* - 4.1.2 Name, Role, Value: ARIA modal pattern
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```tsx
|
|
24
|
+
* <Modal
|
|
25
|
+
* isOpen={isOpen}
|
|
26
|
+
* onClose={() => setIsOpen(false)}
|
|
27
|
+
* title="Confirm Action"
|
|
28
|
+
* >
|
|
29
|
+
* <p>Are you sure?</p>
|
|
30
|
+
* </Modal>
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export const Modal = ({ isOpen, onClose, title, children, closeOnBackdropClick = true, closeOnEscape = true, size = 'md', returnFocusTo, }) => {
|
|
34
|
+
const dialogRef = useRef(null);
|
|
35
|
+
const contentRef = useRef(null);
|
|
36
|
+
const titleId = React.useId();
|
|
37
|
+
const descriptionId = React.useId();
|
|
38
|
+
// Return focus on close
|
|
39
|
+
useFocusReturn(isOpen, returnFocusTo);
|
|
40
|
+
// Handle dialog open/close
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
const dialog = dialogRef.current;
|
|
43
|
+
if (!dialog)
|
|
44
|
+
return;
|
|
45
|
+
if (isOpen) {
|
|
46
|
+
// Show modal dialog
|
|
47
|
+
dialog.showModal();
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
// Close dialog
|
|
51
|
+
dialog.close();
|
|
52
|
+
}
|
|
53
|
+
return () => {
|
|
54
|
+
// Cleanup: ensure dialog is closed when component unmounts
|
|
55
|
+
if (dialog.open) {
|
|
56
|
+
dialog.close();
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}, [isOpen]);
|
|
60
|
+
// Handle backdrop clicks
|
|
61
|
+
// The ::backdrop pseudo-element doesn't bubble events to the dialog element,
|
|
62
|
+
// so we need to listen for clicks on the document and check if they're outside
|
|
63
|
+
// the dialog content area.
|
|
64
|
+
useEffect(() => {
|
|
65
|
+
if (!isOpen || !closeOnBackdropClick)
|
|
66
|
+
return;
|
|
67
|
+
const handleDocumentClick = (event) => {
|
|
68
|
+
const dialog = dialogRef.current;
|
|
69
|
+
const content = contentRef.current;
|
|
70
|
+
if (!dialog || !content)
|
|
71
|
+
return;
|
|
72
|
+
// Check if click target is outside the dialog content area
|
|
73
|
+
const target = event.target;
|
|
74
|
+
// If the click is not inside the content wrapper, it's a backdrop click
|
|
75
|
+
if (!content.contains(target)) {
|
|
76
|
+
// Verify click coordinates are outside content bounds for extra safety
|
|
77
|
+
const rect = content.getBoundingClientRect();
|
|
78
|
+
const clickX = event.clientX;
|
|
79
|
+
const clickY = event.clientY;
|
|
80
|
+
const isOutsideContent = clickX < rect.left ||
|
|
81
|
+
clickX > rect.right ||
|
|
82
|
+
clickY < rect.top ||
|
|
83
|
+
clickY > rect.bottom;
|
|
84
|
+
if (isOutsideContent) {
|
|
85
|
+
event.preventDefault();
|
|
86
|
+
event.stopPropagation();
|
|
87
|
+
onClose();
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
// Use capture phase to catch events before they bubble
|
|
92
|
+
document.addEventListener('mousedown', handleDocumentClick, true);
|
|
93
|
+
return () => {
|
|
94
|
+
document.removeEventListener('mousedown', handleDocumentClick, true);
|
|
95
|
+
};
|
|
96
|
+
}, [isOpen, closeOnBackdropClick, onClose]);
|
|
97
|
+
// Handle cancel event (fires when ESC key is pressed)
|
|
98
|
+
const handleCancel = (event) => {
|
|
99
|
+
// Prevent default close behavior
|
|
100
|
+
event.preventDefault();
|
|
101
|
+
// Only close if closeOnEscape is enabled
|
|
102
|
+
if (closeOnEscape) {
|
|
103
|
+
onClose();
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
return (_jsx("dialog", { ref: dialogRef, className: `modal modal--${size} ${isOpen ? 'modal--open' : ''}`, "aria-labelledby": titleId, "aria-describedby": descriptionId, onCancel: handleCancel, children: _jsxs("div", { ref: contentRef, className: "modal-content-wrapper", children: [_jsxs("div", { className: "modal-header", children: [_jsx("h2", { id: titleId, className: "modal-title", children: title }), _jsx(Button, { variant: "ghost", size: "sm", onClick: onClose, "aria-label": "Close modal", className: "modal-close", children: "\u00D7" })] }), _jsx("div", { id: descriptionId, className: "modal-content", children: children })] }) }));
|
|
107
|
+
};
|
|
108
|
+
Modal.displayName = 'Modal';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/Modal/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAC/B,YAAY,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Modal } from './Modal';
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
.tabs {
|
|
2
|
+
width: 100%;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
.tabs--vertical {
|
|
6
|
+
display: flex;
|
|
7
|
+
align-items: flex-start;
|
|
8
|
+
gap: var(--spacing-6, 1.5rem);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.tabs-list {
|
|
12
|
+
display: flex;
|
|
13
|
+
border-bottom: 1px solid var(--color-border-default, #bbbbbb);
|
|
14
|
+
gap: var(--spacing-1, 0.25rem);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.tabs--vertical .tabs-list {
|
|
18
|
+
flex-direction: column;
|
|
19
|
+
flex-shrink: 0;
|
|
20
|
+
min-width: 200px;
|
|
21
|
+
border-bottom: none;
|
|
22
|
+
border-right: none;
|
|
23
|
+
align-items: stretch;
|
|
24
|
+
gap: 0;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.tabs-tab {
|
|
28
|
+
display: flex;
|
|
29
|
+
align-items: center;
|
|
30
|
+
padding: var(--spacing-3, 0.75rem) var(--spacing-4, 1rem);
|
|
31
|
+
font-size: var(--font-size-base, 1rem);
|
|
32
|
+
font-weight: var(--font-weight-medium, 500);
|
|
33
|
+
color: var(--color-text-secondary, #525252);
|
|
34
|
+
background: none;
|
|
35
|
+
border: none;
|
|
36
|
+
border-bottom: 2px solid transparent;
|
|
37
|
+
cursor: pointer;
|
|
38
|
+
transition: color var(--motion-duration-normal, 200ms) var(--motion-easing-ease-out, cubic-bezier(0, 0, 0.2, 1)),
|
|
39
|
+
border-color var(--motion-duration-normal, 200ms) var(--motion-easing-ease-out, cubic-bezier(0, 0, 0.2, 1)),
|
|
40
|
+
background-color var(--motion-duration-normal, 200ms) var(--motion-easing-ease-out, cubic-bezier(0, 0, 0.2, 1));
|
|
41
|
+
white-space: nowrap;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/* Respect reduced motion */
|
|
45
|
+
@media (prefers-reduced-motion: reduce) {
|
|
46
|
+
.tabs-tab {
|
|
47
|
+
transition: none;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.tabs--vertical .tabs-tab {
|
|
52
|
+
border-bottom: none;
|
|
53
|
+
border-right: none;
|
|
54
|
+
border-left: 3px solid transparent;
|
|
55
|
+
text-align: left;
|
|
56
|
+
justify-content: flex-start;
|
|
57
|
+
padding-left: var(--spacing-4, 1rem);
|
|
58
|
+
padding-right: var(--spacing-4, 1rem);
|
|
59
|
+
border-radius: 0;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.tabs-tab:hover:not(:disabled) {
|
|
63
|
+
color: var(--color-text-primary, #171717);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.tabs-tab--selected {
|
|
67
|
+
color: var(--color-primary-700, #0369a1);
|
|
68
|
+
border-bottom-color: var(--color-primary-700, #0369a1);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
.tabs--vertical .tabs-tab--selected {
|
|
72
|
+
border-bottom-color: transparent;
|
|
73
|
+
border-left-color: var(--color-primary-700, #0369a1);
|
|
74
|
+
background-color: var(--color-neutral-50, #fafafa);
|
|
75
|
+
color: var(--color-primary-700, #0369a1);
|
|
76
|
+
font-weight: var(--font-weight-semibold, 600);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
.tabs-tab:focus-visible {
|
|
80
|
+
outline: 2px solid var(--color-border-focus, #0ea5e9);
|
|
81
|
+
outline-offset: -2px;
|
|
82
|
+
border-radius: 0.25rem 0.25rem 0 0;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
.tabs--vertical .tabs-tab:focus-visible {
|
|
86
|
+
border-radius: 0;
|
|
87
|
+
outline-offset: -2px;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
.tabs--vertical .tabs-tab:hover:not(:disabled):not(.tabs-tab--selected) {
|
|
91
|
+
background-color: var(--color-neutral-50, #fafafa);
|
|
92
|
+
color: var(--color-text-primary, #171717);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
.tabs-tab--disabled {
|
|
96
|
+
opacity: 0.5;
|
|
97
|
+
cursor: not-allowed;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
.tabs-panel {
|
|
101
|
+
padding: var(--spacing-6, 1.5rem);
|
|
102
|
+
flex: 1;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.tabs--vertical .tabs-panel {
|
|
106
|
+
padding: 0;
|
|
107
|
+
flex: 1;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/* High contrast mode support */
|
|
111
|
+
@media (prefers-contrast: high) {
|
|
112
|
+
.tabs-list {
|
|
113
|
+
border-bottom-width: 2px;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
.tabs--vertical .tabs-list {
|
|
117
|
+
border-right-width: 2px;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
.tabs-tab--selected {
|
|
121
|
+
border-bottom-width: 3px;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
.tabs--vertical .tabs-tab--selected {
|
|
125
|
+
border-left-width: 4px;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
.tabs-tab:focus-visible {
|
|
129
|
+
outline-width: 3px;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import './Tabs.css';
|
|
3
|
+
export interface TabItem {
|
|
4
|
+
id: string;
|
|
5
|
+
label: string;
|
|
6
|
+
content: React.ReactNode;
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface TabsProps {
|
|
10
|
+
/**
|
|
11
|
+
* Tab items
|
|
12
|
+
*/
|
|
13
|
+
items: TabItem[];
|
|
14
|
+
/**
|
|
15
|
+
* Default selected tab ID
|
|
16
|
+
*/
|
|
17
|
+
defaultSelectedId?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Controlled selected tab ID
|
|
20
|
+
*/
|
|
21
|
+
selectedId?: string;
|
|
22
|
+
/**
|
|
23
|
+
* Callback when tab selection changes
|
|
24
|
+
*/
|
|
25
|
+
onSelectionChange?: (id: string) => void;
|
|
26
|
+
/**
|
|
27
|
+
* Orientation of tabs
|
|
28
|
+
*/
|
|
29
|
+
orientation?: 'horizontal' | 'vertical';
|
|
30
|
+
/**
|
|
31
|
+
* Activation mode for tabs
|
|
32
|
+
* - 'automatic': Arrow keys both move focus and activate tabs immediately
|
|
33
|
+
* - 'manual': Arrow keys move focus only, Enter/Space activates the focused tab
|
|
34
|
+
* @default 'automatic'
|
|
35
|
+
*/
|
|
36
|
+
activationMode?: 'automatic' | 'manual';
|
|
37
|
+
/**
|
|
38
|
+
* Label for the tab list (required for accessibility)
|
|
39
|
+
*/
|
|
40
|
+
'aria-label'?: string;
|
|
41
|
+
'aria-labelledby'?: string;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Accessible Tabs component
|
|
45
|
+
*
|
|
46
|
+
* WCAG Compliance:
|
|
47
|
+
* - 2.1.1 Keyboard: Arrow key navigation, Home/End support
|
|
48
|
+
* - 4.1.2 Name, Role, Value: ARIA tabs pattern
|
|
49
|
+
* - 2.4.3 Focus Order: Proper focus management
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```tsx
|
|
53
|
+
* <Tabs
|
|
54
|
+
* items={[
|
|
55
|
+
* { id: 'tab1', label: 'Tab 1', content: <div>Content 1</div> },
|
|
56
|
+
* { id: 'tab2', label: 'Tab 2', content: <div>Content 2</div> },
|
|
57
|
+
* ]}
|
|
58
|
+
* aria-label="Settings tabs"
|
|
59
|
+
* />
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export declare const Tabs: React.FC<TabsProps>;
|
|
63
|
+
//# sourceMappingURL=Tabs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Tabs.d.ts","sourceRoot":"","sources":["../../../src/components/Tabs/Tabs.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAwC,MAAM,OAAO,CAAA;AAG5D,OAAO,YAAY,CAAA;AAEnB,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,EAAE,MAAM,CAAA;IACb,OAAO,EAAE,KAAK,CAAC,SAAS,CAAA;IACxB,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB;AAED,MAAM,WAAW,SAAS;IACxB;;OAEG;IACH,KAAK,EAAE,OAAO,EAAE,CAAA;IAEhB;;OAEG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAE1B;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;IAEnB;;OAEG;IACH,iBAAiB,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAA;IAExC;;OAEG;IACH,WAAW,CAAC,EAAE,YAAY,GAAG,UAAU,CAAA;IAEvC;;;;;OAKG;IACH,cAAc,CAAC,EAAE,WAAW,GAAG,QAAQ,CAAA;IAEvC;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,iBAAiB,CAAC,EAAE,MAAM,CAAA;CAC3B;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,IAAI,EAAE,KAAK,CAAC,EAAE,CAAC,SAAS,CA0KpC,CAAA"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useState, useCallback, useRef } from 'react';
|
|
4
|
+
import { isNavigationKey, isArrowKey } from '../../utils/keyboard';
|
|
5
|
+
import { getCurrentAttributes } from '../../utils/aria';
|
|
6
|
+
import './Tabs.css';
|
|
7
|
+
/**
|
|
8
|
+
* Accessible Tabs component
|
|
9
|
+
*
|
|
10
|
+
* WCAG Compliance:
|
|
11
|
+
* - 2.1.1 Keyboard: Arrow key navigation, Home/End support
|
|
12
|
+
* - 4.1.2 Name, Role, Value: ARIA tabs pattern
|
|
13
|
+
* - 2.4.3 Focus Order: Proper focus management
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```tsx
|
|
17
|
+
* <Tabs
|
|
18
|
+
* items={[
|
|
19
|
+
* { id: 'tab1', label: 'Tab 1', content: <div>Content 1</div> },
|
|
20
|
+
* { id: 'tab2', label: 'Tab 2', content: <div>Content 2</div> },
|
|
21
|
+
* ]}
|
|
22
|
+
* aria-label="Settings tabs"
|
|
23
|
+
* />
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export const Tabs = ({ items, defaultSelectedId, selectedId: controlledSelectedId, onSelectionChange, orientation = 'horizontal', activationMode = 'automatic', 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, }) => {
|
|
27
|
+
const initialSelectedId = defaultSelectedId || items[0]?.id;
|
|
28
|
+
const [internalSelectedId, setInternalSelectedId] = useState(initialSelectedId);
|
|
29
|
+
const [focusedId, setFocusedId] = useState(initialSelectedId);
|
|
30
|
+
const tabRefs = useRef(new Map());
|
|
31
|
+
const selectedId = controlledSelectedId ?? internalSelectedId;
|
|
32
|
+
const selectedIndex = items.findIndex((item) => item.id === selectedId);
|
|
33
|
+
// In automatic mode, focused tab is always the selected tab
|
|
34
|
+
// In manual mode, focused tab can be different from selected tab
|
|
35
|
+
const effectiveFocusedId = activationMode === 'automatic' ? selectedId : (focusedId || selectedId);
|
|
36
|
+
const handleSelect = useCallback((id) => {
|
|
37
|
+
if (onSelectionChange) {
|
|
38
|
+
onSelectionChange(id);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
setInternalSelectedId(id);
|
|
42
|
+
}
|
|
43
|
+
// In manual mode, update focused tab when selecting
|
|
44
|
+
if (activationMode === 'manual') {
|
|
45
|
+
setFocusedId(id);
|
|
46
|
+
}
|
|
47
|
+
}, [onSelectionChange, activationMode]);
|
|
48
|
+
const handleKeyDown = useCallback((event, currentIndex) => {
|
|
49
|
+
const isHorizontal = orientation === 'horizontal';
|
|
50
|
+
let newIndex = currentIndex;
|
|
51
|
+
// Handle Enter/Space for manual activation
|
|
52
|
+
if (activationMode === 'manual' && (event.key === 'Enter' || event.key === ' ')) {
|
|
53
|
+
event.preventDefault();
|
|
54
|
+
const currentTab = items[currentIndex];
|
|
55
|
+
if (currentTab && !currentTab.disabled) {
|
|
56
|
+
handleSelect(currentTab.id);
|
|
57
|
+
}
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
// Handle arrow keys and Home/End
|
|
61
|
+
if (isNavigationKey(event.key) || isArrowKey(event.key)) {
|
|
62
|
+
event.preventDefault();
|
|
63
|
+
switch (event.key) {
|
|
64
|
+
case 'Home':
|
|
65
|
+
newIndex = 0;
|
|
66
|
+
break;
|
|
67
|
+
case 'End':
|
|
68
|
+
newIndex = items.length - 1;
|
|
69
|
+
break;
|
|
70
|
+
case 'ArrowRight':
|
|
71
|
+
if (isHorizontal) {
|
|
72
|
+
newIndex = (currentIndex + 1) % items.length;
|
|
73
|
+
}
|
|
74
|
+
break;
|
|
75
|
+
case 'ArrowLeft':
|
|
76
|
+
if (isHorizontal) {
|
|
77
|
+
newIndex = (currentIndex - 1 + items.length) % items.length;
|
|
78
|
+
}
|
|
79
|
+
break;
|
|
80
|
+
case 'ArrowDown':
|
|
81
|
+
if (!isHorizontal) {
|
|
82
|
+
newIndex = (currentIndex + 1) % items.length;
|
|
83
|
+
}
|
|
84
|
+
break;
|
|
85
|
+
case 'ArrowUp':
|
|
86
|
+
if (!isHorizontal) {
|
|
87
|
+
newIndex = (currentIndex - 1 + items.length) % items.length;
|
|
88
|
+
}
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
// Skip disabled tabs
|
|
92
|
+
while (items[newIndex]?.disabled && newIndex !== currentIndex) {
|
|
93
|
+
if (event.key === 'Home' || event.key === 'ArrowRight' || event.key === 'ArrowDown') {
|
|
94
|
+
newIndex = (newIndex + 1) % items.length;
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
newIndex = (newIndex - 1 + items.length) % items.length;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const newTab = items[newIndex];
|
|
101
|
+
if (newTab && !newTab.disabled) {
|
|
102
|
+
if (activationMode === 'automatic') {
|
|
103
|
+
// Automatic: move focus and activate
|
|
104
|
+
handleSelect(newTab.id);
|
|
105
|
+
tabRefs.current.get(newTab.id)?.focus();
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
// Manual: move focus only
|
|
109
|
+
setFocusedId(newTab.id);
|
|
110
|
+
tabRefs.current.get(newTab.id)?.focus();
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}, [items, orientation, activationMode, handleSelect]);
|
|
115
|
+
const selectedTab = items.find((item) => item.id === selectedId);
|
|
116
|
+
return (_jsxs("div", { className: `tabs tabs--${orientation}`, children: [_jsx("div", { className: "tabs-list", role: "tablist", "aria-orientation": orientation, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, children: items.map((item, index) => {
|
|
117
|
+
const isSelected = item.id === selectedId;
|
|
118
|
+
const isFocused = item.id === effectiveFocusedId;
|
|
119
|
+
// In manual mode, focused tab should be focusable even if not selected
|
|
120
|
+
// In automatic mode, only selected tab is focusable
|
|
121
|
+
const tabIndex = activationMode === 'manual'
|
|
122
|
+
? (isFocused ? 0 : -1)
|
|
123
|
+
: (isSelected ? 0 : -1);
|
|
124
|
+
return (_jsx("button", { ref: (el) => {
|
|
125
|
+
if (el) {
|
|
126
|
+
tabRefs.current.set(item.id, el);
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
tabRefs.current.delete(item.id);
|
|
130
|
+
}
|
|
131
|
+
}, id: `tab-${item.id}`, role: "tab", "aria-controls": `tabpanel-${item.id}`, "aria-selected": isSelected, tabIndex: tabIndex, disabled: item.disabled, className: `tabs-tab ${isSelected ? 'tabs-tab--selected' : ''} ${item.disabled ? 'tabs-tab--disabled' : ''}`, onClick: () => !item.disabled && handleSelect(item.id), onKeyDown: (e) => handleKeyDown(e, index), onFocus: () => setFocusedId(item.id), ...getCurrentAttributes(isSelected ? 'page' : undefined), children: item.label }, item.id));
|
|
132
|
+
}) }), selectedTab && (_jsx("div", { id: `tabpanel-${selectedTab.id}`, role: "tabpanel", "aria-labelledby": `tab-${selectedTab.id}`, className: "tabs-panel", children: selectedTab.content }))] }));
|
|
133
|
+
};
|
|
134
|
+
Tabs.displayName = 'Tabs';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/Tabs/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAC7B,YAAY,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Tabs } from './Tabs';
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
.toast {
|
|
2
|
+
display: flex;
|
|
3
|
+
align-items: flex-start;
|
|
4
|
+
gap: var(--spacing-3, 0.75rem);
|
|
5
|
+
padding: var(--spacing-4, 1rem);
|
|
6
|
+
min-width: 20rem;
|
|
7
|
+
max-width: 32rem;
|
|
8
|
+
background-color: var(--color-background-default, #ffffff);
|
|
9
|
+
border: 1px solid var(--color-border-default, #bbbbbb);
|
|
10
|
+
border-radius: 0.375rem;
|
|
11
|
+
box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
|
|
12
|
+
animation: toast-slide-in var(--motion-duration-normal, 200ms) var(--motion-easing-ease-out, cubic-bezier(0, 0, 0.2, 1));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/* Respect reduced motion */
|
|
16
|
+
@media (prefers-reduced-motion: reduce) {
|
|
17
|
+
.toast {
|
|
18
|
+
animation: none;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
@keyframes toast-slide-in {
|
|
23
|
+
from {
|
|
24
|
+
opacity: 0;
|
|
25
|
+
transform: translateY(-0.5rem);
|
|
26
|
+
}
|
|
27
|
+
to {
|
|
28
|
+
opacity: 1;
|
|
29
|
+
transform: translateY(0);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.toast-content {
|
|
34
|
+
flex: 1;
|
|
35
|
+
min-width: 0;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.toast-message {
|
|
39
|
+
font-size: var(--font-size-base, 1rem);
|
|
40
|
+
/* WCAG 2.2 1.4.12 Text Spacing: Line height at least 1.5 times font size */
|
|
41
|
+
line-height: var(--line-height-normal, 1.5);
|
|
42
|
+
/* WCAG 2.2 1.4.12 Text Spacing: Letter spacing at least 0.12 times font size */
|
|
43
|
+
letter-spacing: calc(var(--font-size-base, 1rem) * 0.12);
|
|
44
|
+
/* WCAG 2.2 1.4.12 Text Spacing: Word spacing at least 0.16 times font size */
|
|
45
|
+
word-spacing: calc(var(--font-size-base, 1rem) * 0.16);
|
|
46
|
+
color: var(--color-text-primary, #171717);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/* WCAG 2.2 1.4.12 Text Spacing: Spacing following paragraphs at least 2 times font size */
|
|
50
|
+
.toast-message p {
|
|
51
|
+
margin-top: 0;
|
|
52
|
+
margin-bottom: calc(var(--font-size-base, 1rem) * 2);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.toast-message p:last-child {
|
|
56
|
+
margin-bottom: 0;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.toast-dismiss {
|
|
60
|
+
flex-shrink: 0;
|
|
61
|
+
margin-left: auto;
|
|
62
|
+
font-size: var(--font-size-xl, 1.25rem);
|
|
63
|
+
line-height: 1;
|
|
64
|
+
padding: var(--spacing-1, 0.25rem);
|
|
65
|
+
min-width: auto;
|
|
66
|
+
width: 2rem;
|
|
67
|
+
height: 2rem;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/* Toast types */
|
|
71
|
+
.toast--info {
|
|
72
|
+
border-left: 4px solid var(--color-primary-500, #0ea5e9);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
.toast--success {
|
|
76
|
+
border-left: 4px solid var(--color-success-500, #22c55e);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
.toast--warning {
|
|
80
|
+
border-left: 4px solid var(--color-warning-500, #f59e0b);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
.toast--error {
|
|
84
|
+
border-left: 4px solid var(--color-error-500, #ef4444);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/* High contrast mode support */
|
|
88
|
+
@media (prefers-contrast: high) {
|
|
89
|
+
.toast {
|
|
90
|
+
border-width: 2px;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
.toast--info,
|
|
94
|
+
.toast--success,
|
|
95
|
+
.toast--warning,
|
|
96
|
+
.toast--error {
|
|
97
|
+
border-left-width: 6px;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|