@crystin001/theme-settings-lib 1.0.0 → 1.2.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/README.md +402 -368
- package/dist/components/ThemeShowcase.d.ts +10 -0
- package/dist/components/ThemeShowcase.d.ts.map +1 -0
- package/dist/components/ThemeShowcase.js +357 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/settings-context.d.ts.map +1 -1
- package/dist/settings-context.js +5 -3
- package/dist/stories/ThemeStories.d.ts +6 -0
- package/dist/stories/ThemeStories.d.ts.map +1 -0
- package/dist/stories/ThemeStories.js +285 -0
- package/dist/stories/index.d.ts +2 -0
- package/dist/stories/index.d.ts.map +1 -0
- package/dist/stories/index.js +4 -0
- package/dist/theme-validation.d.ts +27 -0
- package/dist/theme-validation.d.ts.map +1 -0
- package/dist/theme-validation.js +114 -0
- package/dist/theme.d.ts +16 -1
- package/dist/theme.d.ts.map +1 -1
- package/dist/theme.js +628 -334
- package/package.json +69 -56
package/README.md
CHANGED
|
@@ -1,368 +1,402 @@
|
|
|
1
|
-
# Theme & Settings Library
|
|
2
|
-
|
|
3
|
-
A reusable library for theme management, settings, and internationalization that can be shared across multiple React Native applications.
|
|
4
|
-
|
|
5
|
-
## Features
|
|
6
|
-
|
|
7
|
-
- 🎨 **Multiple Theme Families** - 8 theme families with light and dark variants
|
|
8
|
-
- 🌍 **Internationalization** - Built-in i18n support with extensible translations
|
|
9
|
-
- 💾 **Persistent Settings** - Theme and language preferences saved automatically
|
|
10
|
-
- ♿ **Accessibility** - WCAG-compliant contrast utilities
|
|
11
|
-
- 🔧 **Type-Safe** - Full TypeScript support with declaration files
|
|
12
|
-
|
|
13
|
-
## Installation
|
|
14
|
-
|
|
15
|
-
### Option A: Git Repository (Recommended)
|
|
16
|
-
|
|
17
|
-
Add to your `package.json`:
|
|
18
|
-
|
|
19
|
-
```json
|
|
20
|
-
{
|
|
21
|
-
"dependencies": {
|
|
22
|
-
"@crystin001/theme-settings-lib": "git+https://github.com/trial-and-code/theme-settings-lib.git"
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
Then run `npm install`.
|
|
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
|
-
|
|
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
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
- **
|
|
198
|
-
- **
|
|
199
|
-
- **
|
|
200
|
-
- **
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
- `
|
|
260
|
-
- `
|
|
261
|
-
- `
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
```
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
```
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
```
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
```
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
1
|
+
# Theme & Settings Library
|
|
2
|
+
|
|
3
|
+
A reusable library for theme management, settings, and internationalization that can be shared across multiple React Native applications.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🎨 **Multiple Theme Families** - 8 theme families with light and dark variants
|
|
8
|
+
- 🌍 **Internationalization** - Built-in i18n support with extensible translations
|
|
9
|
+
- 💾 **Persistent Settings** - Theme and language preferences saved automatically
|
|
10
|
+
- ♿ **Accessibility** - WCAG-compliant contrast utilities
|
|
11
|
+
- 🔧 **Type-Safe** - Full TypeScript support with declaration files
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
### Option A: Git Repository (Recommended)
|
|
16
|
+
|
|
17
|
+
Add to your `package.json`:
|
|
18
|
+
|
|
19
|
+
```json
|
|
20
|
+
{
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@crystin001/theme-settings-lib": "git+https://github.com/trial-and-code/theme-settings-lib.git"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Then run `npm install`. The library will automatically build during installation.
|
|
28
|
+
|
|
29
|
+
**Note:** The library requires TypeScript to build. It will be installed automatically as a dev dependency and the build will run during `npm install`.
|
|
30
|
+
|
|
31
|
+
To install a specific version or branch:
|
|
32
|
+
|
|
33
|
+
```json
|
|
34
|
+
{
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@crystin001/theme-settings-lib": "git+https://github.com/trial-and-code/theme-settings-lib.git#v1.0.0"
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Option B: Local Package (Development)
|
|
42
|
+
|
|
43
|
+
For local development, you can use a file path to link the library directly:
|
|
44
|
+
|
|
45
|
+
```json
|
|
46
|
+
{
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"@crystin001/theme-settings-lib": "file:../theme-settings-lib"
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
**Note:** Make sure to run `npm run build` in the library directory after making changes.
|
|
54
|
+
|
|
55
|
+
### Option C: npm Package (Future)
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
npm install @crystin001/theme-settings-lib
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Usage
|
|
62
|
+
|
|
63
|
+
### 1. Wrap Your App with SettingsProvider
|
|
64
|
+
|
|
65
|
+
Wrap your root component with `SettingsProvider` to enable theme and settings management:
|
|
66
|
+
|
|
67
|
+
```tsx
|
|
68
|
+
// app/_layout.tsx or App.tsx
|
|
69
|
+
import { SettingsProvider } from '@crystin001/theme-settings-lib';
|
|
70
|
+
import { Stack } from 'expo-router';
|
|
71
|
+
|
|
72
|
+
export default function RootLayout() {
|
|
73
|
+
return (
|
|
74
|
+
<SettingsProvider>
|
|
75
|
+
<Stack>
|
|
76
|
+
{/* Your app screens */}
|
|
77
|
+
</Stack>
|
|
78
|
+
</SettingsProvider>
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### 2. Use Theme Hooks in Your Components
|
|
84
|
+
|
|
85
|
+
Access theme colors and settings in your components:
|
|
86
|
+
|
|
87
|
+
```tsx
|
|
88
|
+
import { View, Text, Button } from 'react-native';
|
|
89
|
+
import { useTheme, useSettings } from '@crystin001/theme-settings-lib';
|
|
90
|
+
|
|
91
|
+
function MyComponent() {
|
|
92
|
+
const colors = useTheme();
|
|
93
|
+
const { setThemeFamily } = useSettings();
|
|
94
|
+
|
|
95
|
+
return (
|
|
96
|
+
<View style={{ backgroundColor: colors.background }}>
|
|
97
|
+
<Text style={{ color: colors.text }}>Hello World</Text>
|
|
98
|
+
<Button
|
|
99
|
+
onPress={() => setThemeFamily('neon-surf')}
|
|
100
|
+
title="Change to Neon Surf"
|
|
101
|
+
/>
|
|
102
|
+
</View>
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### 3. Use Translations
|
|
108
|
+
|
|
109
|
+
Access translations using the `useTranslation` hook:
|
|
110
|
+
|
|
111
|
+
```tsx
|
|
112
|
+
import { Text } from 'react-native';
|
|
113
|
+
import { useTranslation } from '@crystin001/theme-settings-lib';
|
|
114
|
+
|
|
115
|
+
function MyComponent() {
|
|
116
|
+
const { t } = useTranslation();
|
|
117
|
+
|
|
118
|
+
return (
|
|
119
|
+
<Text>{t('common.welcome')}</Text>
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### 4. Get Specific Theme Colors
|
|
125
|
+
|
|
126
|
+
Use `useThemeColor` to get specific colors from the current theme:
|
|
127
|
+
|
|
128
|
+
```tsx
|
|
129
|
+
import { View, Text } from 'react-native';
|
|
130
|
+
import { useThemeColor } from '@crystin001/theme-settings-lib';
|
|
131
|
+
|
|
132
|
+
function MyComponent() {
|
|
133
|
+
const backgroundColor = useThemeColor({}, 'background');
|
|
134
|
+
const textColor = useThemeColor({}, 'text');
|
|
135
|
+
const primaryColor = useThemeColor({}, 'primary');
|
|
136
|
+
|
|
137
|
+
return (
|
|
138
|
+
<View style={{ backgroundColor }}>
|
|
139
|
+
<Text style={{ color: textColor }}>Primary: {primaryColor}</Text>
|
|
140
|
+
</View>
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### 5. Extend Translations
|
|
146
|
+
|
|
147
|
+
Add app-specific translations by extending the i18n instance:
|
|
148
|
+
|
|
149
|
+
```tsx
|
|
150
|
+
import { i18n } from '@crystin001/theme-settings-lib';
|
|
151
|
+
|
|
152
|
+
// Add custom translations
|
|
153
|
+
i18n.addResourceBundle('en-US', 'translation', {
|
|
154
|
+
myFeature: {
|
|
155
|
+
title: 'My Feature',
|
|
156
|
+
description: 'This is my feature',
|
|
157
|
+
},
|
|
158
|
+
}, true, true);
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### 6. Complete Example: Integration with React Navigation
|
|
162
|
+
|
|
163
|
+
Here's a complete example showing integration with React Navigation:
|
|
164
|
+
|
|
165
|
+
```tsx
|
|
166
|
+
// app/_layout.tsx
|
|
167
|
+
import { Stack } from 'expo-router';
|
|
168
|
+
import { StatusBar } from 'expo-status-bar';
|
|
169
|
+
import { DarkTheme, DefaultTheme, ThemeProvider } from '@react-navigation/native';
|
|
170
|
+
import { SettingsProvider, useSettings } from '@crystin001/theme-settings-lib';
|
|
171
|
+
|
|
172
|
+
function RootLayoutNav() {
|
|
173
|
+
const { currentTheme } = useSettings();
|
|
174
|
+
const isDarkTheme = currentTheme.endsWith('-dark');
|
|
175
|
+
|
|
176
|
+
return (
|
|
177
|
+
<ThemeProvider value={isDarkTheme ? DarkTheme : DefaultTheme}>
|
|
178
|
+
<Stack>
|
|
179
|
+
<Stack.Screen name="(tabs)" options={{ headerShown: false }} />
|
|
180
|
+
</Stack>
|
|
181
|
+
<StatusBar style={isDarkTheme ? 'light' : 'dark'} />
|
|
182
|
+
</ThemeProvider>
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export default function RootLayout() {
|
|
187
|
+
return (
|
|
188
|
+
<SettingsProvider>
|
|
189
|
+
<RootLayoutNav />
|
|
190
|
+
</SettingsProvider>
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
## Available Theme Families
|
|
196
|
+
|
|
197
|
+
- **System** - Follows device theme preference (default)
|
|
198
|
+
- **Neon Surf** - Vibrant neon colors (hot pink, cyan, yellow, orange)
|
|
199
|
+
- **Pink & Purple** - Soft purple and pink tones
|
|
200
|
+
- **Pastel** - Gentle pastel colors
|
|
201
|
+
- **GitHub** - GitHub-inspired theme
|
|
202
|
+
- **High Contrast** - Maximum contrast for accessibility
|
|
203
|
+
- **Solarized** - Solarized color scheme
|
|
204
|
+
- **Dark Plus** - Dark theme with blue accents
|
|
205
|
+
|
|
206
|
+
Each theme family has both light and dark variants that automatically switch based on device settings.
|
|
207
|
+
|
|
208
|
+
## API Reference
|
|
209
|
+
|
|
210
|
+
### Hooks
|
|
211
|
+
|
|
212
|
+
#### `useTheme()`
|
|
213
|
+
|
|
214
|
+
Returns all colors from the current theme.
|
|
215
|
+
|
|
216
|
+
```tsx
|
|
217
|
+
const colors = useTheme();
|
|
218
|
+
// Returns: { text, background, tint, icon, ... }
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
#### `useThemeColor(props?, colorName?)`
|
|
222
|
+
|
|
223
|
+
Get a specific color from the current theme.
|
|
224
|
+
|
|
225
|
+
```tsx
|
|
226
|
+
const backgroundColor = useThemeColor({}, 'background');
|
|
227
|
+
const textColor = useThemeColor({ light: '#000', dark: '#fff' }, 'text');
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
#### `useSettings()`
|
|
231
|
+
|
|
232
|
+
Access theme and language settings.
|
|
233
|
+
|
|
234
|
+
```tsx
|
|
235
|
+
const {
|
|
236
|
+
selectedThemeFamily,
|
|
237
|
+
currentTheme,
|
|
238
|
+
setThemeFamily,
|
|
239
|
+
language,
|
|
240
|
+
setLanguage,
|
|
241
|
+
availableThemeFamilies,
|
|
242
|
+
availableLanguages
|
|
243
|
+
} = useSettings();
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
#### `useTranslation()`
|
|
247
|
+
|
|
248
|
+
Get the translation function.
|
|
249
|
+
|
|
250
|
+
```tsx
|
|
251
|
+
const { t } = useTranslation();
|
|
252
|
+
const welcomeText = t('common.welcome');
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
### Settings Context
|
|
256
|
+
|
|
257
|
+
The `useSettings()` hook returns:
|
|
258
|
+
|
|
259
|
+
- `selectedThemeFamily` - Currently selected theme family (e.g., `'neon-surf'`)
|
|
260
|
+
- `currentTheme` - Effective theme being used (includes variant, e.g., `'neon-surf-light'`)
|
|
261
|
+
- `setThemeFamily(family)` - Change theme family
|
|
262
|
+
- `language` - Current language code (e.g., `'en-US'`)
|
|
263
|
+
- `setLanguage(lang)` - Change language
|
|
264
|
+
- `availableThemeFamilies` - Array of all available theme families with metadata
|
|
265
|
+
- `availableLanguages` - Array of all available languages
|
|
266
|
+
|
|
267
|
+
### Color Utilities
|
|
268
|
+
|
|
269
|
+
#### `getContrastRatio(color1, color2)`
|
|
270
|
+
|
|
271
|
+
Calculate the contrast ratio between two colors (returns 1-21).
|
|
272
|
+
|
|
273
|
+
```tsx
|
|
274
|
+
import { getContrastRatio } from '@crystin001/theme-settings-lib';
|
|
275
|
+
|
|
276
|
+
const ratio = getContrastRatio('#000000', '#FFFFFF'); // Returns ~21
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
#### `getContrastTextColor(backgroundColor, lightColor?, darkColor?, minContrast?)`
|
|
280
|
+
|
|
281
|
+
Get a readable text color for a given background.
|
|
282
|
+
|
|
283
|
+
```tsx
|
|
284
|
+
import { getContrastTextColor } from '@crystin001/theme-settings-lib';
|
|
285
|
+
|
|
286
|
+
const textColor = getContrastTextColor('#000000'); // Returns '#FFFFFF'
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
#### `meetsContrastRequirement(foreground, background, level?)`
|
|
290
|
+
|
|
291
|
+
Check if a color combination meets WCAG contrast requirements.
|
|
292
|
+
|
|
293
|
+
```tsx
|
|
294
|
+
import { meetsContrastRequirement } from '@crystin001/theme-settings-lib';
|
|
295
|
+
|
|
296
|
+
const isAccessible = meetsContrastRequirement('#000000', '#FFFFFF', 'AA'); // Returns true
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
#### `ensureContrast(foreground, background, level?)`
|
|
300
|
+
|
|
301
|
+
Ensure a color combination has readable contrast, adjusting if needed.
|
|
302
|
+
|
|
303
|
+
```tsx
|
|
304
|
+
import { ensureContrast } from '@crystin001/theme-settings-lib';
|
|
305
|
+
|
|
306
|
+
const readableColor = ensureContrast('#888888', '#FFFFFF', 'AA');
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
## Contributing / Development
|
|
310
|
+
|
|
311
|
+
For information about developing the library, including:
|
|
312
|
+
- Building the library
|
|
313
|
+
- Running the example app for visual theme development
|
|
314
|
+
- Project structure
|
|
315
|
+
- Development workflow
|
|
316
|
+
|
|
317
|
+
See [SETUP.md](./SETUP.md) in the repository.
|
|
318
|
+
|
|
319
|
+
## Versioning
|
|
320
|
+
|
|
321
|
+
The library follows [Semantic Versioning](https://semver.org/):
|
|
322
|
+
|
|
323
|
+
- **Major** (x.0.0) - Breaking API changes
|
|
324
|
+
- **Minor** (0.x.0) - New themes, features, or languages
|
|
325
|
+
- **Patch** (0.0.x) - Bug fixes and theme adjustments
|
|
326
|
+
|
|
327
|
+
## Troubleshooting
|
|
328
|
+
|
|
329
|
+
### "Unable to resolve path to module" Error
|
|
330
|
+
|
|
331
|
+
If you get an error like `Unable to resolve path to module '@crystin001/theme-settings-lib'`, try these steps:
|
|
332
|
+
|
|
333
|
+
1. **The library should build automatically during installation.** If you're using a local file path and made changes, rebuild:
|
|
334
|
+
```bash
|
|
335
|
+
cd theme-settings-lib
|
|
336
|
+
npm run build
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
**Note:** When installing from git, the library builds automatically via the `prepare` script. You only need to manually build if using a local `file:` path and making changes.
|
|
340
|
+
|
|
341
|
+
2. **Clear Metro cache and restart:**
|
|
342
|
+
```bash
|
|
343
|
+
# In your app directory
|
|
344
|
+
npx react-native start --reset-cache
|
|
345
|
+
# Or for Expo:
|
|
346
|
+
npx expo start --clear
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
3. **Reinstall dependencies:**
|
|
350
|
+
```bash
|
|
351
|
+
# In your app directory
|
|
352
|
+
rm -rf node_modules
|
|
353
|
+
npm install
|
|
354
|
+
# Or if using yarn:
|
|
355
|
+
rm -rf node_modules
|
|
356
|
+
yarn install
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
4. **If using local file path, verify the path is correct:**
|
|
360
|
+
```json
|
|
361
|
+
{
|
|
362
|
+
"dependencies": {
|
|
363
|
+
"@crystin001/theme-settings-lib": "file:../theme-settings-lib"
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
```
|
|
367
|
+
Make sure the relative path from your app's `package.json` to the library is correct.
|
|
368
|
+
|
|
369
|
+
5. **For Expo projects, you may need to restart the development server completely:**
|
|
370
|
+
```bash
|
|
371
|
+
# Stop the server, then:
|
|
372
|
+
npx expo start --clear
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
6. **Check that `dist/` folder exists and contains compiled files:**
|
|
376
|
+
The library must be built before it can be used. Run `npm run build` in the library directory.
|
|
377
|
+
|
|
378
|
+
## Peer Dependencies
|
|
379
|
+
|
|
380
|
+
This library requires the following peer dependencies (installed by your app):
|
|
381
|
+
|
|
382
|
+
- `react` - React library
|
|
383
|
+
- `react-native` - React Native framework
|
|
384
|
+
- `i18next` - Internationalization framework
|
|
385
|
+
- `react-i18next` - React bindings for i18next
|
|
386
|
+
- `expo-localization` - Expo localization utilities
|
|
387
|
+
- `@react-native-async-storage/async-storage` - Async storage for persistence
|
|
388
|
+
- `color` (optional) - Color manipulation library
|
|
389
|
+
|
|
390
|
+
## License
|
|
391
|
+
|
|
392
|
+
MIT
|
|
393
|
+
|
|
394
|
+
## Repository
|
|
395
|
+
|
|
396
|
+
[https://github.com/trial-and-code/theme-settings-lib](https://github.com/trial-and-code/theme-settings-lib)
|
|
397
|
+
|
|
398
|
+
---
|
|
399
|
+
|
|
400
|
+
**For developers:** See [SETUP.md](./SETUP.md) for development setup, building the library, and running the example app.
|
|
401
|
+
|
|
402
|
+
|