ngp-accessibility 1.0.3 โ 1.0.6
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 +102 -5
- package/dist/AccessibilityContext.d.ts +20 -1
- package/dist/AccessibilityDropdown.d.ts +27 -6
- package/dist/index.d.ts +1 -0
- package/dist/index.esm.js +570 -55
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +570 -55
- package/dist/index.js.map +1 -1
- package/dist/styles.css +532 -1
- package/dist/translations.d.ts +26 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -5,6 +5,7 @@ React accessibility package with translation, text sizing, contrast modes, and v
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
7
|
- ๐ Multi-language support (English, Tagalog, Cebuano/Visayan)
|
|
8
|
+
- ๐ Google auto-translation for page content with manual UI fallback
|
|
8
9
|
- ๐ Text size adjustment (increase/decrease)
|
|
9
10
|
- ๐จ High contrast mode
|
|
10
11
|
- ๐ Negative contrast mode
|
|
@@ -31,9 +32,11 @@ import "ngp-accessibility/dist/styles.css";
|
|
|
31
32
|
|
|
32
33
|
function App() {
|
|
33
34
|
return (
|
|
34
|
-
<AccessibilityProvider>
|
|
35
|
+
<AccessibilityProvider googleTranslateTargetSelector="main">
|
|
35
36
|
<AccessibilityToolbar />
|
|
36
|
-
<
|
|
37
|
+
<main>
|
|
38
|
+
<YourContent />
|
|
39
|
+
</main>
|
|
37
40
|
</AccessibilityProvider>
|
|
38
41
|
);
|
|
39
42
|
}
|
|
@@ -50,11 +53,13 @@ import "ngp-accessibility/dist/styles.css";
|
|
|
50
53
|
|
|
51
54
|
function App() {
|
|
52
55
|
return (
|
|
53
|
-
<AccessibilityProvider>
|
|
56
|
+
<AccessibilityProvider googleTranslateTargetSelector="#page-content">
|
|
54
57
|
<div style={{ textAlign: "right", padding: "10px" }}>
|
|
55
58
|
<AccessibilityDropdown />
|
|
56
59
|
</div>
|
|
57
|
-
<
|
|
60
|
+
<section id="page-content">
|
|
61
|
+
<YourContent />
|
|
62
|
+
</section>
|
|
58
63
|
</AccessibilityProvider>
|
|
59
64
|
);
|
|
60
65
|
}
|
|
@@ -78,11 +83,102 @@ When voice command is enabled, you can use:
|
|
|
78
83
|
|
|
79
84
|
Wrap your app with this provider.
|
|
80
85
|
|
|
86
|
+
Props:
|
|
87
|
+
|
|
88
|
+
- `translations`: Manual translations for your own keyed content through `t()`.
|
|
89
|
+
- `googleTranslateTargetSelector`: CSS selector for the DOM subtree that should be eligible for Google auto-translation. Defaults to `main`.
|
|
90
|
+
|
|
91
|
+
Example:
|
|
92
|
+
|
|
93
|
+
```tsx
|
|
94
|
+
<AccessibilityProvider googleTranslateTargetSelector="#article-content">
|
|
95
|
+
<Header />
|
|
96
|
+
<AccessibilityDropdown />
|
|
97
|
+
<div id="article-content">
|
|
98
|
+
<ArticlePage />
|
|
99
|
+
</div>
|
|
100
|
+
</AccessibilityProvider>
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Only the subtree matched by `googleTranslateTargetSelector` should contain the content you want Google to translate. Elements outside that path are marked as `notranslate`.
|
|
104
|
+
|
|
105
|
+
### Language Behavior
|
|
106
|
+
|
|
107
|
+
`setLanguage(lang)` updates the current language state once, and the package applies that language in 3 different ways:
|
|
108
|
+
|
|
109
|
+
1. Toolbar and dropdown UI labels use `translate(key)`.
|
|
110
|
+
2. Your app's keyed content uses `t(key)`.
|
|
111
|
+
3. Google Translate auto-translates the subtree matched by `googleTranslateTargetSelector`.
|
|
112
|
+
|
|
113
|
+
This means the package now supports 2 language modes:
|
|
114
|
+
|
|
115
|
+
- Manual UI language: If the selected language exists in the built-in package dictionary, the accessibility controls use those manual labels.
|
|
116
|
+
- Google-only language: If the selected language does not have a built-in package dictionary, the accessibility controls fall back to English while Google still translates the page content.
|
|
117
|
+
|
|
118
|
+
Example:
|
|
119
|
+
|
|
120
|
+
- `tl`: package UI uses manual Tagalog labels, and page content can also be translated.
|
|
121
|
+
- `ja`: package UI falls back to English unless you add manual Japanese labels, while Google translates the selected page subtree to Japanese.
|
|
122
|
+
|
|
123
|
+
### Manual Translation For Specific Content
|
|
124
|
+
|
|
125
|
+
Yes, this setup is more flexible when you want manual translations only for specific components or content.
|
|
126
|
+
|
|
127
|
+
Use `translations` plus `t(key)` when you want full control over exact wording in your own app content. Use Google Translate for the rest of the page content inside your translation target.
|
|
128
|
+
|
|
129
|
+
Example:
|
|
130
|
+
|
|
131
|
+
```tsx
|
|
132
|
+
const myTranslations = {
|
|
133
|
+
en: {
|
|
134
|
+
heroTitle: "Welcome",
|
|
135
|
+
heroBody: "This section is manually translated.",
|
|
136
|
+
},
|
|
137
|
+
ja: {
|
|
138
|
+
heroTitle: "ใใใใ",
|
|
139
|
+
heroBody: "ใใฎใปใฏใทใงใณใฏๆๅใง็ฟป่จณใใใฆใใพใใ",
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
function Hero() {
|
|
144
|
+
const { t } = useAccessibility();
|
|
145
|
+
|
|
146
|
+
return (
|
|
147
|
+
<section>
|
|
148
|
+
<h1>{t("heroTitle")}</h1>
|
|
149
|
+
<p>{t("heroBody")}</p>
|
|
150
|
+
</section>
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function App() {
|
|
155
|
+
return (
|
|
156
|
+
<AccessibilityProvider
|
|
157
|
+
translations={myTranslations}
|
|
158
|
+
googleTranslateTargetSelector="main"
|
|
159
|
+
>
|
|
160
|
+
<AccessibilityDropdown />
|
|
161
|
+
<main>
|
|
162
|
+
<Hero />
|
|
163
|
+
<OtherPageContent />
|
|
164
|
+
</main>
|
|
165
|
+
</AccessibilityProvider>
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
In that setup:
|
|
171
|
+
|
|
172
|
+
- `Hero` can use your manual translations through `t(key)`.
|
|
173
|
+
- other content inside `main` can still be translated by Google.
|
|
174
|
+
- the accessibility toolbar/dropdown uses built-in package labels when available, otherwise English fallback.
|
|
175
|
+
|
|
81
176
|
### useAccessibility()
|
|
82
177
|
|
|
83
178
|
Hook that returns:
|
|
84
179
|
|
|
85
180
|
- `language`, `setLanguage(lang)`
|
|
181
|
+
- `hasManualTranslations`
|
|
86
182
|
- `textSize`, `increaseText()`, `decreaseText()`
|
|
87
183
|
- `highContrast`, `toggleHighContrast()`
|
|
88
184
|
- `negativeContrast`, `toggleNegativeContrast()`
|
|
@@ -90,7 +186,8 @@ Hook that returns:
|
|
|
90
186
|
- `underlineLinks`, `toggleUnderlineLinks()`
|
|
91
187
|
- `readableFont`, `toggleReadableFont()`
|
|
92
188
|
- `voiceEnabled`, `toggleVoice()`
|
|
93
|
-
- `translate(key)` - Get translated text
|
|
189
|
+
- `translate(key)` - Get translated package UI text with English fallback
|
|
190
|
+
- `t(key)` - Get your app-specific manual text for the current language, then fall back to English, then the raw key
|
|
94
191
|
|
|
95
192
|
### AccessibilityToolbar
|
|
96
193
|
|
|
@@ -1,31 +1,50 @@
|
|
|
1
1
|
import React, { ReactNode } from "react";
|
|
2
2
|
import { Language, TranslationKey } from "./translations";
|
|
3
|
+
export type ColorBlindMode = "none" | "protanopia" | "deuteranopia" | "tritanopia";
|
|
3
4
|
interface AccessibilityState {
|
|
4
5
|
language: Language;
|
|
5
6
|
textSize: number;
|
|
7
|
+
textMagnifier: boolean;
|
|
8
|
+
pauseAnimations: boolean;
|
|
9
|
+
readingGuide: boolean;
|
|
6
10
|
highContrast: boolean;
|
|
7
11
|
negativeContrast: boolean;
|
|
8
12
|
lightBackground: boolean;
|
|
9
13
|
underlineLinks: boolean;
|
|
14
|
+
highlightTitles: boolean;
|
|
10
15
|
readableFont: boolean;
|
|
11
16
|
voiceEnabled: boolean;
|
|
17
|
+
readAloud: boolean;
|
|
18
|
+
colorBlindMode: ColorBlindMode;
|
|
19
|
+
focusIndicator: boolean;
|
|
12
20
|
}
|
|
13
21
|
interface AccessibilityContextType extends AccessibilityState {
|
|
14
22
|
setLanguage: (lang: Language) => void;
|
|
15
23
|
increaseText: () => void;
|
|
16
24
|
decreaseText: () => void;
|
|
25
|
+
toggleTextMagnifier: () => void;
|
|
26
|
+
togglePauseAnimations: () => void;
|
|
27
|
+
toggleReadingGuide: () => void;
|
|
17
28
|
toggleHighContrast: () => void;
|
|
18
29
|
toggleNegativeContrast: () => void;
|
|
19
30
|
toggleLightBackground: () => void;
|
|
20
31
|
toggleUnderlineLinks: () => void;
|
|
32
|
+
toggleHighlightTitles: () => void;
|
|
21
33
|
toggleReadableFont: () => void;
|
|
22
34
|
toggleVoice: () => void;
|
|
35
|
+
toggleReadAloud: () => void;
|
|
36
|
+
setColorBlindMode: (mode: ColorBlindMode) => void;
|
|
37
|
+
toggleFocusIndicator: () => void;
|
|
38
|
+
hasManualTranslations: boolean;
|
|
23
39
|
translate: (key: TranslationKey) => string;
|
|
24
40
|
t: (key: string) => string;
|
|
25
41
|
}
|
|
26
|
-
interface AccessibilityProviderProps {
|
|
42
|
+
export interface AccessibilityProviderProps {
|
|
27
43
|
children: ReactNode;
|
|
28
44
|
translations?: Partial<Record<Language, Record<string, string>>>;
|
|
45
|
+
googleTranslateTargetSelector?: string;
|
|
46
|
+
/** @deprecated Use googleTranslateTargetSelector instead. */
|
|
47
|
+
translationTargetSelector?: string;
|
|
29
48
|
}
|
|
30
49
|
export declare const AccessibilityProvider: React.FC<AccessibilityProviderProps>;
|
|
31
50
|
export declare const useAccessibility: () => AccessibilityContextType;
|
|
@@ -1,24 +1,45 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
export interface AccessibilityDropdownClasses {
|
|
3
3
|
root?: string;
|
|
4
|
+
title?: string;
|
|
5
|
+
trigger?: string;
|
|
6
|
+
panel?: string;
|
|
4
7
|
toggle?: string;
|
|
5
|
-
menu?: string;
|
|
6
8
|
section?: string;
|
|
7
|
-
|
|
8
|
-
select?: string;
|
|
9
|
+
sectionHeader?: string;
|
|
9
10
|
button?: string;
|
|
10
11
|
activeButton?: string;
|
|
11
|
-
|
|
12
|
+
select?: string;
|
|
13
|
+
menu?: string;
|
|
12
14
|
}
|
|
13
15
|
export interface AccessibilityDropdownProps {
|
|
14
16
|
className?: string;
|
|
15
17
|
style?: React.CSSProperties;
|
|
16
18
|
classes?: AccessibilityDropdownClasses;
|
|
17
|
-
triggerLabel?:
|
|
18
|
-
renderTrigger?: (
|
|
19
|
+
triggerLabel?: string;
|
|
20
|
+
renderTrigger?: (props: {
|
|
19
21
|
isOpen: boolean;
|
|
20
22
|
toggle: () => void;
|
|
21
23
|
className: string;
|
|
22
24
|
}) => React.ReactNode;
|
|
23
25
|
}
|
|
26
|
+
export interface AccessibilityDropdownClasses {
|
|
27
|
+
root?: string;
|
|
28
|
+
trigger?: string;
|
|
29
|
+
panel?: string;
|
|
30
|
+
panelHeader?: string;
|
|
31
|
+
closeButton?: string;
|
|
32
|
+
}
|
|
33
|
+
export interface AccessibilityDropdownRenderTriggerProps {
|
|
34
|
+
isOpen: boolean;
|
|
35
|
+
toggle: () => void;
|
|
36
|
+
className: string;
|
|
37
|
+
}
|
|
38
|
+
export interface AccessibilityDropdownProps {
|
|
39
|
+
className?: string;
|
|
40
|
+
style?: React.CSSProperties;
|
|
41
|
+
classes?: AccessibilityDropdownClasses;
|
|
42
|
+
triggerLabel?: string;
|
|
43
|
+
renderTrigger?: (props: AccessibilityDropdownRenderTriggerProps) => React.ReactNode;
|
|
44
|
+
}
|
|
24
45
|
export declare const AccessibilityDropdown: React.FC<AccessibilityDropdownProps>;
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export { AccessibilityToolbar } from "./AccessibilityToolbar";
|
|
|
3
3
|
export { AccessibilityDropdown } from "./AccessibilityDropdown";
|
|
4
4
|
export { T } from "./T";
|
|
5
5
|
export { translations, type Language, type TranslationKey, } from "./translations";
|
|
6
|
+
export type { AccessibilityProviderProps } from "./AccessibilityContext";
|
|
6
7
|
export type { AccessibilityToolbarProps, AccessibilityToolbarClasses, } from "./AccessibilityToolbar";
|
|
7
8
|
export type { AccessibilityDropdownProps, AccessibilityDropdownClasses, } from "./AccessibilityDropdown";
|
|
8
9
|
export type { default as React } from "react";
|