ngp-accessibility 1.0.5 โ†’ 1.0.7

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 CHANGED
@@ -1,17 +1,17 @@
1
1
  # NGP Accessibility
2
2
 
3
- React accessibility package with translation, text sizing, contrast modes, and voice commands.
3
+ React accessibility package with translation, text sizing, contrast modes, and more.
4
4
 
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
11
12
  - ๐Ÿ’ก Light background mode
12
13
  - ๐Ÿ”— Links underline toggle
13
14
  - ๐Ÿ“– Readable font mode
14
- - ๐ŸŽค Voice command support
15
15
  - โœ… TypeScript & JavaScript compatible
16
16
  - ๐Ÿ“ฆ Zero dependencies (peer: React)
17
17
 
@@ -31,9 +31,11 @@ import "ngp-accessibility/dist/styles.css";
31
31
 
32
32
  function App() {
33
33
  return (
34
- <AccessibilityProvider>
34
+ <AccessibilityProvider googleTranslateTargetSelector="main">
35
35
  <AccessibilityToolbar />
36
- <YourContent />
36
+ <main>
37
+ <YourContent />
38
+ </main>
37
39
  </AccessibilityProvider>
38
40
  );
39
41
  }
@@ -50,47 +52,128 @@ import "ngp-accessibility/dist/styles.css";
50
52
 
51
53
  function App() {
52
54
  return (
53
- <AccessibilityProvider>
55
+ <AccessibilityProvider googleTranslateTargetSelector="#page-content">
54
56
  <div style={{ textAlign: "right", padding: "10px" }}>
55
57
  <AccessibilityDropdown />
56
58
  </div>
57
- <YourContent />
59
+ <section id="page-content">
60
+ <YourContent />
61
+ </section>
58
62
  </AccessibilityProvider>
59
63
  );
60
64
  }
61
65
  ```
62
66
 
63
- ## Voice Commands
64
-
65
- When voice command is enabled, you can use:
66
-
67
- - "increase text" / "palakihin"
68
- - "decrease text" / "paliitin"
69
- - "high contrast" / "mataas"
70
- - "negative contrast" / "negatibo"
71
- - "light background" / "maliwanag"
72
- - "underline" / "guhit"
73
- - "readable font" / "madaling"
74
-
75
67
  ## API
76
68
 
77
69
  ### AccessibilityProvider
78
70
 
79
71
  Wrap your app with this provider.
80
72
 
73
+ Props:
74
+
75
+ - `translations`: Manual translations for your own keyed content through `t()`.
76
+ - `googleTranslateTargetSelector`: CSS selector for the DOM subtree that should be eligible for Google auto-translation. Defaults to `main`.
77
+
78
+ Example:
79
+
80
+ ```tsx
81
+ <AccessibilityProvider googleTranslateTargetSelector="#article-content">
82
+ <Header />
83
+ <AccessibilityDropdown />
84
+ <div id="article-content">
85
+ <ArticlePage />
86
+ </div>
87
+ </AccessibilityProvider>
88
+ ```
89
+
90
+ Only the subtree matched by `googleTranslateTargetSelector` should contain the content you want Google to translate. Elements outside that path are marked as `notranslate`.
91
+
92
+ ### Language Behavior
93
+
94
+ `setLanguage(lang)` updates the current language state once, and the package applies that language in 3 different ways:
95
+
96
+ 1. Toolbar and dropdown UI labels use `translate(key)`.
97
+ 2. Your app's keyed content uses `t(key)`.
98
+ 3. Google Translate auto-translates the subtree matched by `googleTranslateTargetSelector`.
99
+
100
+ This means the package now supports 2 language modes:
101
+
102
+ - Manual UI language: If the selected language exists in the built-in package dictionary, the accessibility controls use those manual labels.
103
+ - 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.
104
+
105
+ Example:
106
+
107
+ - `tl`: package UI uses manual Tagalog labels, and page content can also be translated.
108
+ - `ja`: package UI falls back to English unless you add manual Japanese labels, while Google translates the selected page subtree to Japanese.
109
+
110
+ ### Manual Translation For Specific Content
111
+
112
+ Yes, this setup is more flexible when you want manual translations only for specific components or content.
113
+
114
+ 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.
115
+
116
+ Example:
117
+
118
+ ```tsx
119
+ const myTranslations = {
120
+ en: {
121
+ heroTitle: "Welcome",
122
+ heroBody: "This section is manually translated.",
123
+ },
124
+ ja: {
125
+ heroTitle: "ใ‚ˆใ†ใ“ใ",
126
+ heroBody: "ใ“ใฎใ‚ปใ‚ฏใ‚ทใƒงใƒณใฏๆ‰‹ๅ‹•ใง็ฟป่จณใ•ใ‚Œใฆใ„ใพใ™ใ€‚",
127
+ },
128
+ };
129
+
130
+ function Hero() {
131
+ const { t } = useAccessibility();
132
+
133
+ return (
134
+ <section>
135
+ <h1>{t("heroTitle")}</h1>
136
+ <p>{t("heroBody")}</p>
137
+ </section>
138
+ );
139
+ }
140
+
141
+ function App() {
142
+ return (
143
+ <AccessibilityProvider
144
+ translations={myTranslations}
145
+ googleTranslateTargetSelector="main"
146
+ >
147
+ <AccessibilityDropdown />
148
+ <main>
149
+ <Hero />
150
+ <OtherPageContent />
151
+ </main>
152
+ </AccessibilityProvider>
153
+ );
154
+ }
155
+ ```
156
+
157
+ In that setup:
158
+
159
+ - `Hero` can use your manual translations through `t(key)`.
160
+ - other content inside `main` can still be translated by Google.
161
+ - the accessibility toolbar/dropdown uses built-in package labels when available, otherwise English fallback.
162
+
81
163
  ### useAccessibility()
82
164
 
83
165
  Hook that returns:
84
166
 
85
167
  - `language`, `setLanguage(lang)`
168
+ - `hasManualTranslations`
86
169
  - `textSize`, `increaseText()`, `decreaseText()`
87
170
  - `highContrast`, `toggleHighContrast()`
88
171
  - `negativeContrast`, `toggleNegativeContrast()`
89
172
  - `lightBackground`, `toggleLightBackground()`
90
173
  - `underlineLinks`, `toggleUnderlineLinks()`
91
174
  - `readableFont`, `toggleReadableFont()`
92
- - `voiceEnabled`, `toggleVoice()`
93
- - `translate(key)` - Get translated text
175
+ - `translate(key)` - Get translated package UI text with English fallback
176
+ - `t(key)` - Get your app-specific manual text for the current language, then fall back to English, then the raw key
94
177
 
95
178
  ### AccessibilityToolbar
96
179
 
@@ -1,5 +1,6 @@
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;
@@ -12,7 +13,9 @@ interface AccessibilityState {
12
13
  underlineLinks: boolean;
13
14
  highlightTitles: boolean;
14
15
  readableFont: boolean;
15
- voiceEnabled: boolean;
16
+ readAloud: boolean;
17
+ colorBlindMode: ColorBlindMode;
18
+ focusIndicator: boolean;
16
19
  }
17
20
  interface AccessibilityContextType extends AccessibilityState {
18
21
  setLanguage: (lang: Language) => void;
@@ -27,13 +30,19 @@ interface AccessibilityContextType extends AccessibilityState {
27
30
  toggleUnderlineLinks: () => void;
28
31
  toggleHighlightTitles: () => void;
29
32
  toggleReadableFont: () => void;
30
- toggleVoice: () => void;
33
+ toggleReadAloud: () => void;
34
+ setColorBlindMode: (mode: ColorBlindMode) => void;
35
+ toggleFocusIndicator: () => void;
36
+ hasManualTranslations: boolean;
31
37
  translate: (key: TranslationKey) => string;
32
38
  t: (key: string) => string;
33
39
  }
34
- interface AccessibilityProviderProps {
40
+ export interface AccessibilityProviderProps {
35
41
  children: ReactNode;
36
42
  translations?: Partial<Record<Language, Record<string, string>>>;
43
+ googleTranslateTargetSelector?: string;
44
+ /** @deprecated Use googleTranslateTargetSelector instead. */
45
+ translationTargetSelector?: string;
37
46
  }
38
47
  export declare const AccessibilityProvider: React.FC<AccessibilityProviderProps>;
39
48
  export declare const useAccessibility: () => AccessibilityContextType;
@@ -1,4 +1,28 @@
1
1
  import React from "react";
2
+ export interface AccessibilityDropdownClasses {
3
+ root?: string;
4
+ title?: string;
5
+ trigger?: string;
6
+ panel?: string;
7
+ toggle?: string;
8
+ section?: string;
9
+ sectionHeader?: string;
10
+ button?: string;
11
+ activeButton?: string;
12
+ select?: string;
13
+ menu?: string;
14
+ }
15
+ export interface AccessibilityDropdownProps {
16
+ className?: string;
17
+ style?: React.CSSProperties;
18
+ classes?: AccessibilityDropdownClasses;
19
+ triggerLabel?: string;
20
+ renderTrigger?: (props: {
21
+ isOpen: boolean;
22
+ toggle: () => void;
23
+ className: string;
24
+ }) => React.ReactNode;
25
+ }
2
26
  export interface AccessibilityDropdownClasses {
3
27
  root?: string;
4
28
  trigger?: string;
@@ -4,7 +4,6 @@ export interface AccessibilityToolbarClasses {
4
4
  select?: string;
5
5
  button?: string;
6
6
  activeButton?: string;
7
- voiceButton?: string;
8
7
  }
9
8
  export interface AccessibilityToolbarProps {
10
9
  className?: string;
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";