@a11ypros/a11y-ui-components 1.0.2 → 1.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/README.md +124 -0
- package/dist/components/Link/Link.d.ts.map +1 -1
- package/dist/components/Link/Link.js +1 -1
- package/package.json +5 -14
package/README.md
CHANGED
|
@@ -110,6 +110,130 @@ function App() {
|
|
|
110
110
|
|
|
111
111
|
Browse all components, see live examples, and explore accessibility features in our interactive Storybook documentation.
|
|
112
112
|
|
|
113
|
+
## Customization with Design Tokens
|
|
114
|
+
|
|
115
|
+
The library exports design tokens and utility functions for building custom components while maintaining accessibility standards:
|
|
116
|
+
|
|
117
|
+
```tsx
|
|
118
|
+
import {
|
|
119
|
+
colors,
|
|
120
|
+
spacing,
|
|
121
|
+
typography,
|
|
122
|
+
breakpoints,
|
|
123
|
+
motion
|
|
124
|
+
} from '@a11ypros/a11y-ui-components';
|
|
125
|
+
|
|
126
|
+
// Use tokens in your custom components
|
|
127
|
+
const CustomCard = () => (
|
|
128
|
+
<div style={{
|
|
129
|
+
backgroundColor: colors.neutral[50],
|
|
130
|
+
padding: spacing[4],
|
|
131
|
+
borderRadius: spacing[2],
|
|
132
|
+
fontSize: typography.size.base,
|
|
133
|
+
}}>
|
|
134
|
+
Custom component using design tokens
|
|
135
|
+
</div>
|
|
136
|
+
);
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Available Design Tokens
|
|
140
|
+
|
|
141
|
+
- **colors**: WCAG AA compliant color palettes
|
|
142
|
+
- `primary`, `neutral`, `success`, `warning`, `error`
|
|
143
|
+
- All colors meet 4.5:1 contrast ratio on appropriate backgrounds
|
|
144
|
+
- **spacing**: Consistent spacing scale (4px/8px grid system)
|
|
145
|
+
- **typography**: Font sizes, weights, line heights
|
|
146
|
+
- **breakpoints**: Responsive design breakpoints
|
|
147
|
+
- **motion**: Animation durations (respects `prefers-reduced-motion`)
|
|
148
|
+
|
|
149
|
+
### Accessibility Utilities
|
|
150
|
+
|
|
151
|
+
Import utility functions to enhance your custom components:
|
|
152
|
+
|
|
153
|
+
```tsx
|
|
154
|
+
import {
|
|
155
|
+
announceToScreenReader,
|
|
156
|
+
generateAriaLabel,
|
|
157
|
+
trapFocus,
|
|
158
|
+
restoreFocus,
|
|
159
|
+
generateFocusRing,
|
|
160
|
+
handleEscape,
|
|
161
|
+
handleArrowKeys
|
|
162
|
+
} from '@a11ypros/a11y-ui-components';
|
|
163
|
+
|
|
164
|
+
// Example: Custom modal with focus trap
|
|
165
|
+
const CustomModal = ({ isOpen, onClose }) => {
|
|
166
|
+
const modalRef = useRef(null);
|
|
167
|
+
|
|
168
|
+
useEffect(() => {
|
|
169
|
+
if (isOpen && modalRef.current) {
|
|
170
|
+
trapFocus(modalRef.current);
|
|
171
|
+
announceToScreenReader('Dialog opened');
|
|
172
|
+
}
|
|
173
|
+
}, [isOpen]);
|
|
174
|
+
|
|
175
|
+
return (
|
|
176
|
+
<div ref={modalRef} role="dialog" aria-modal="true">
|
|
177
|
+
{/* Modal content */}
|
|
178
|
+
</div>
|
|
179
|
+
);
|
|
180
|
+
};
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
All utilities maintain WCAG compliance and follow accessibility best practices.
|
|
184
|
+
|
|
185
|
+
### Overriding Design Tokens
|
|
186
|
+
|
|
187
|
+
You can override the default design tokens by customizing CSS custom properties in your application:
|
|
188
|
+
|
|
189
|
+
```css
|
|
190
|
+
/* In your global CSS file */
|
|
191
|
+
:root {
|
|
192
|
+
/* Override primary color */
|
|
193
|
+
--color-primary-500: #your-brand-color;
|
|
194
|
+
--color-primary-600: #your-darker-shade;
|
|
195
|
+
--color-primary-700: #your-darkest-shade;
|
|
196
|
+
|
|
197
|
+
/* Override spacing */
|
|
198
|
+
--spacing-4: 1.5rem; /* default is 1rem */
|
|
199
|
+
|
|
200
|
+
/* Override typography */
|
|
201
|
+
--font-size-base: 1.125rem; /* default is 1rem */
|
|
202
|
+
--font-weight-bold: 600; /* default is 700 */
|
|
203
|
+
|
|
204
|
+
/* Override motion */
|
|
205
|
+
--duration-normal: 250ms; /* default is 200ms */
|
|
206
|
+
}
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
**Important**: When overriding colors, ensure your custom colors maintain WCAG AA contrast ratios:
|
|
210
|
+
- **4.5:1** minimum for normal text
|
|
211
|
+
- **3:1** minimum for large text (18pt+) and UI components
|
|
212
|
+
|
|
213
|
+
You can test contrast ratios using tools like:
|
|
214
|
+
- [WebAIM Contrast Checker](https://webaim.org/resources/contrastchecker/)
|
|
215
|
+
- [Accessible Colors](https://accessible-colors.com/)
|
|
216
|
+
|
|
217
|
+
### Available CSS Custom Properties
|
|
218
|
+
|
|
219
|
+
**Colors:**
|
|
220
|
+
- `--color-primary-[50-900]`
|
|
221
|
+
- `--color-neutral-[50-900]`
|
|
222
|
+
- `--color-success-[500-700]`
|
|
223
|
+
- `--color-warning-[500-700]`
|
|
224
|
+
- `--color-error-[500-700]`
|
|
225
|
+
|
|
226
|
+
**Spacing:**
|
|
227
|
+
- `--spacing-[0,1,2,3,4,5,6,8,10,12,16,20,24,32]`
|
|
228
|
+
|
|
229
|
+
**Typography:**
|
|
230
|
+
- `--font-size-[xs,sm,base,lg,xl,2xl,3xl,4xl]`
|
|
231
|
+
- `--font-weight-[normal,medium,semibold,bold]`
|
|
232
|
+
- `--line-height-[tight,normal,relaxed]`
|
|
233
|
+
|
|
234
|
+
**Motion:**
|
|
235
|
+
- `--duration-[fast,normal,slow]`
|
|
236
|
+
|
|
113
237
|
## Usage Examples
|
|
114
238
|
|
|
115
239
|
### Form with Validation
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Link.d.ts","sourceRoot":"","sources":["../../../src/components/Link/Link.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,YAAY,CAAA;AAEnB,MAAM,WAAW,SAAU,SAAQ,KAAK,CAAC,oBAAoB,CAAC,iBAAiB,CAAC;IAC9E;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAElB;;OAEG;IACH,IAAI,CAAC,EAAE,OAAO,CAAA;IAEd;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB;AAED;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,IAAI,
|
|
1
|
+
{"version":3,"file":"Link.d.ts","sourceRoot":"","sources":["../../../src/components/Link/Link.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,YAAY,CAAA;AAEnB,MAAM,WAAW,SAAU,SAAQ,KAAK,CAAC,oBAAoB,CAAC,iBAAiB,CAAC;IAC9E;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAElB;;OAEG;IACH,IAAI,CAAC,EAAE,OAAO,CAAA;IAEd;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB;AAED;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,IAAI,qFAsEhB,CAAA"}
|
|
@@ -43,6 +43,6 @@ export const Link = React.forwardRef(({ external = false, skip = false, href, re
|
|
|
43
43
|
if (skip && !href) {
|
|
44
44
|
return (_jsx("button", { ref: ref, className: classes, "aria-label": ariaLabel, ...props, children: children }));
|
|
45
45
|
}
|
|
46
|
-
return (_jsxs("a", { ref: ref, href: href, rel: relAttributes || undefined, target: linkTarget, className: classes, "aria-label": ariaLabel, ...props, children: [children, isExternal &&
|
|
46
|
+
return (_jsxs("a", { ref: ref, href: href, rel: relAttributes || undefined, target: linkTarget, className: classes, "aria-label": ariaLabel ? `${ariaLabel} (opens in new tab)` : isExternal && linkTarget === '_blank' ? `${children} (opens in new tab)` : undefined, ...props, children: [children, isExternal && _jsxs("span", { className: "link__external-icon", "aria-hidden": "true", children: [' ', "\u2197"] })] }));
|
|
47
47
|
});
|
|
48
48
|
Link.displayName = 'Link';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@a11ypros/a11y-ui-components",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "An accessibility-first React UI component library built with WCAG 2.1/2.2 compliance",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -47,21 +47,12 @@
|
|
|
47
47
|
"build-storybook": "cd ../.. && npm run build-storybook"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"react": "^18.0.0",
|
|
51
|
-
"react-dom": "^18.0.0"
|
|
50
|
+
"react": "^18.2.0 || ^19.0.0",
|
|
51
|
+
"react-dom": "^18.2.0 || ^19.0.0"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@
|
|
55
|
-
"@
|
|
56
|
-
"@storybook/addon-essentials": "^7.6.17",
|
|
57
|
-
"@storybook/addon-interactions": "^7.6.17",
|
|
58
|
-
"@storybook/addon-links": "^7.6.17",
|
|
59
|
-
"@storybook/blocks": "^7.6.17",
|
|
60
|
-
"@storybook/react": "^7.6.17",
|
|
61
|
-
"@storybook/react-webpack5": "^7.6.17",
|
|
62
|
-
"@storybook/test": "^7.6.17",
|
|
63
|
-
"@types/react": "^18.2.48",
|
|
64
|
-
"@types/react-dom": "^18.2.18",
|
|
54
|
+
"@types/react": "^19.0.0",
|
|
55
|
+
"@types/react-dom": "^19.0.0",
|
|
65
56
|
"typescript": "^5.3.3"
|
|
66
57
|
}
|
|
67
58
|
}
|