@teamnhz/rn-ui-toolkit 1.4.2 → 1.4.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.
@@ -1,93 +1,59 @@
1
- import { I18nManager } from 'react-native';
2
- import { moderateScale } from './scale';
3
- // Usedo english font family
4
- const UE_FONT_LIGHT = 'Rubik-Light';
5
- const UE_FONT_REGULAR = 'Rubik-Regular';
6
- const UE_FONT_BOLD = 'Rubik-Bold';
7
- // Usedo arabic font family
8
- const UA_FONT_LIGHT = 'HelveticaNeueLTArabic-Light';
9
- const UA_FONT_REGULAR = 'HelveticaNeueLTArabic-Roman';
10
- const UA_FONT_BOLD = 'HelveticaNeueLTArabic-Bold';
11
- // sizes
12
- const xSmall = () => ({
13
- fontSize: moderateScale(12),
14
- });
15
- const smallU = () => ({
16
- fontSize: moderateScale(14),
17
- });
18
- const regularU = () => ({
19
- fontSize: moderateScale(16),
20
- });
21
- const mediumU = () => ({
22
- fontSize: moderateScale(18),
23
- });
24
- const largeU = () => ({
25
- fontSize: moderateScale(20),
26
- });
27
- // weights
28
- const lightU = () => ({
29
- fontFamily: I18nManager.isRTL ? UA_FONT_LIGHT : UE_FONT_LIGHT,
30
- });
31
- // comment for testing
32
- const normalU = () => ({
33
- fontFamily: I18nManager.isRTL ? UA_FONT_REGULAR : UE_FONT_REGULAR,
34
- });
35
- const boldU = () => ({
36
- fontFamily: I18nManager.isRTL ? UA_FONT_BOLD : UE_FONT_BOLD,
37
- });
38
- // styles
39
- const header1 = () => ({
40
- ...largeU(), // 20
41
- ...boldU(),
42
- });
43
- const header2 = () => ({
44
- ...largeU(), // 20
45
- ...normalU(),
46
- });
47
- const header3 = () => ({
48
- ...mediumU(), // 18
49
- ...normalU(),
50
- });
51
- const header3Bold = () => ({
52
- ...mediumU(), // 18
53
- ...boldU(),
54
- });
55
- const standardU = () => ({
56
- ...regularU(), // 16
57
- ...normalU(),
58
- });
59
- const standardLight = () => ({
60
- ...regularU(), // 16
61
- ...lightU(),
62
- });
63
- const standardBold = () => ({
64
- ...regularU(), // 16
65
- ...boldU(),
66
- });
67
- const subTextU = () => ({
68
- ...smallU(), // 14
69
- ...normalU(),
70
- });
71
- const subTextBold = () => ({
72
- ...smallU(), // 14
73
- ...boldU(),
74
- });
75
- const subTextLight = () => ({
76
- ...smallU(), // 14
77
- ...lightU(),
78
- });
79
- const smallTextU = () => ({
80
- ...xSmall(), // 12
81
- ...normalU(),
82
- });
83
- const smallTextBold = () => ({
84
- ...xSmall(), // 12
85
- ...boldU(),
86
- });
87
- const smallTextLight = () => ({
88
- ...xSmall(), // 12
89
- ...lightU(),
90
- });
1
+ import { moderateScale } from "./scale";
2
+ import { getFont, getLanguage } from "./appConfig";
3
+ // -------------------------------------
4
+ const lang = getLanguage();
5
+ // -------------------------------------
6
+ const FONT = {
7
+ thin: getFont(lang, "thin"),
8
+ extraLight: getFont(lang, "extraLight"),
9
+ light: getFont(lang, "light"),
10
+ regular: getFont(lang, "regular"),
11
+ medium: getFont(lang, "medium"),
12
+ semiBold: getFont(lang, "semiBold"),
13
+ bold: getFont(lang, "bold"),
14
+ extraBold: getFont(lang, "extraBold"),
15
+ black: getFont(lang, "black"),
16
+ };
17
+ // -------------------------------------
18
+ // SIZES
19
+ // -------------------------------------
20
+ const xSmall = () => ({ fontSize: moderateScale(12) });
21
+ const smallU = () => ({ fontSize: moderateScale(14) });
22
+ const regularU = () => ({ fontSize: moderateScale(16) });
23
+ const mediumU = () => ({ fontSize: moderateScale(18) });
24
+ const largeU = () => ({ fontSize: moderateScale(20) });
25
+ // -------------------------------------
26
+ // WEIGHTS
27
+ // -------------------------------------
28
+ const thin = () => ({ fontFamily: FONT.thin });
29
+ const extraLight = () => ({ fontFamily: FONT.extraLight });
30
+ const lightU = () => ({ fontFamily: FONT.light });
31
+ const normalU = () => ({ fontFamily: FONT.regular });
32
+ const mediumW = () => ({ fontFamily: FONT.medium });
33
+ const semiBold = () => ({ fontFamily: FONT.semiBold });
34
+ const boldU = () => ({ fontFamily: FONT.bold });
35
+ const extraBold = () => ({ fontFamily: FONT.extraBold });
36
+ const black = () => ({ fontFamily: FONT.black });
37
+ // -------------------------------------
38
+ // STYLES
39
+ // -------------------------------------
40
+ const header1 = () => ({ ...largeU(), ...boldU() });
41
+ const header2 = () => ({ ...largeU(), ...normalU() });
42
+ const header3 = () => ({ ...mediumU(), ...normalU() });
43
+ const standardU = () => ({ ...regularU(), ...normalU() });
44
+ const standardBold = () => ({ ...regularU(), ...boldU() });
45
+ const standardLight = () => ({ ...regularU(), ...lightU() });
46
+ // Small text
47
+ const smallTextU = () => ({ ...xSmall(), ...normalU() });
48
+ const smallTextBold = () => ({ ...xSmall(), ...boldU() });
49
+ const smallTextLight = () => ({ ...xSmall(), ...lightU() });
50
+ // Sub text
51
+ const subTextU = () => ({ ...smallU(), ...normalU() });
52
+ const subTextBold = () => ({ ...smallU(), ...boldU() });
53
+ const subTextLight = () => ({ ...smallU(), ...lightU() });
54
+ // -------------------------------------
55
+ // EXPORT
56
+ // -------------------------------------
91
57
  export default {
92
58
  size: {
93
59
  xSmall,
@@ -96,28 +62,388 @@ export default {
96
62
  mediumU,
97
63
  largeU,
98
64
  },
65
+ weights: {
66
+ thin,
67
+ extraLight,
68
+ lightU,
69
+ normalU,
70
+ mediumW,
71
+ semiBold,
72
+ boldU,
73
+ extraBold,
74
+ black,
75
+ },
99
76
  style: {
100
77
  header1,
101
78
  header2,
102
79
  header3,
103
- header3Bold,
104
80
  standardU,
105
- standardLight,
106
81
  standardBold,
107
- subTextU,
108
- subTextBold,
109
- subTextLight,
82
+ standardLight,
110
83
  smallTextU,
111
84
  smallTextBold,
112
85
  smallTextLight,
86
+ subTextU,
87
+ subTextBold,
88
+ subTextLight,
113
89
  },
114
- weights: {
115
- lightU,
116
- boldU,
117
- normalU,
118
- },
119
- fonts: {
120
- en: UE_FONT_REGULAR,
121
- ar: UA_FONT_REGULAR,
122
- },
90
+ fonts: FONT,
123
91
  };
92
+ // // src/styles/typography.ts
93
+ // import { I18nManager } from 'react-native';
94
+ // import { moderateScale } from './scale';
95
+ // // --- Types ---
96
+ // export type Lang = 'en' | 'ar';
97
+ // export type TypographySizes = {
98
+ // xSmall: number;
99
+ // smallU: number;
100
+ // regularU: number;
101
+ // mediumU: number;
102
+ // largeU: number;
103
+ // };
104
+ // export type TypographyFonts = {
105
+ // en: {
106
+ // light?: string;
107
+ // regular?: string;
108
+ // bold?: string;
109
+ // };
110
+ // ar: {
111
+ // light?: string;
112
+ // regular?: string;
113
+ // bold?: string;
114
+ // };
115
+ // };
116
+ // export type TypographyConfig = {
117
+ // fonts?: Partial<TypographyFonts>;
118
+ // sizes?: Partial<TypographySizes>;
119
+ // // optional custom scaling function (receives numeric size and returns scaled value)
120
+ // scaleFn?: (size: number) => number;
121
+ // };
122
+ // // --- Defaults (your original values) ---
123
+ // const DEFAULT_FONTS: TypographyFonts = {
124
+ // en: {
125
+ // light: 'Rubik-Light',
126
+ // regular: 'Rubik-Regular',
127
+ // bold: 'Rubik-Bold',
128
+ // },
129
+ // ar: {
130
+ // light: 'HelveticaNeueLTArabic-Light',
131
+ // regular: 'HelveticaNeueLTArabic-Roman',
132
+ // bold: 'HelveticaNeueLTArabic-Bold',
133
+ // },
134
+ // };
135
+ // const DEFAULT_SIZES: TypographySizes = {
136
+ // xSmall: 12,
137
+ // smallU: 14,
138
+ // regularU: 16,
139
+ // mediumU: 18,
140
+ // largeU: 20,
141
+ // };
142
+ // // --- Internal mutable config (will be mutated by setTypographyConfig) ---
143
+ // let _config: TypographyConfig = {
144
+ // fonts: DEFAULT_FONTS,
145
+ // sizes: DEFAULT_SIZES,
146
+ // scaleFn: moderateScale,
147
+ // };
148
+ // // Helper to merge partial config into _config safely
149
+ // export function setTypographyConfig(cfg: TypographyConfig) {
150
+ // _config = {
151
+ // fonts: {
152
+ // en: {
153
+ // ...DEFAULT_FONTS.en,
154
+ // ...(cfg.fonts && cfg.fonts.en ? cfg.fonts.en : {}),
155
+ // },
156
+ // ar: {
157
+ // ...DEFAULT_FONTS.ar,
158
+ // ...(cfg.fonts && cfg.fonts.ar ? cfg.fonts.ar : {}),
159
+ // },
160
+ // },
161
+ // sizes: {
162
+ // ...DEFAULT_SIZES,
163
+ // ...(cfg.sizes || {}),
164
+ // },
165
+ // scaleFn: cfg.scaleFn || moderateScale,
166
+ // };
167
+ // }
168
+ // // Optional getter if needed
169
+ // export function getTypographyConfig(): TypographyConfig {
170
+ // // return a shallow copy to avoid external mutation
171
+ // return {
172
+ // fonts: JSON.parse(JSON.stringify(_config.fonts)),
173
+ // sizes: { ...( _config.sizes as TypographySizes ) },
174
+ // scaleFn: _config.scaleFn,
175
+ // };
176
+ // }
177
+ // // Utility to pick font by weight and RTL:
178
+ // function fontFor(weight: 'light' | 'regular' | 'bold') {
179
+ // const isRTL = I18nManager.isRTL;
180
+ // const langKey: Lang = isRTL ? 'ar' : 'en';
181
+ // const fonts = _config.fonts as TypographyFonts;
182
+ // return fonts && fonts[langKey] && (fonts[langKey] as any)[weight]
183
+ // ? (fonts[langKey] as any)[weight]
184
+ // : // fallback: regular from en
185
+ // DEFAULT_FONTS.en.regular;
186
+ // }
187
+ // // Scale helper
188
+ // function scale(sizeNumber: number) {
189
+ // const fn = _config.scaleFn || moderateScale;
190
+ // return fn(sizeNumber);
191
+ // }
192
+ // // --- Size helpers (return style objects like your original file) ---
193
+ // const xSmall = () => ({ fontSize: scale((_config.sizes as TypographySizes).xSmall) });
194
+ // const smallU = () => ({ fontSize: scale((_config.sizes as TypographySizes).smallU) });
195
+ // const regularU = () => ({ fontSize: scale((_config.sizes as TypographySizes).regularU) });
196
+ // const mediumU = () => ({ fontSize: scale((_config.sizes as TypographySizes).mediumU) });
197
+ // const largeU = () => ({ fontSize: scale((_config.sizes as TypographySizes).largeU) });
198
+ // // --- Weight helpers ---
199
+ // const lightU = () => ({ fontFamily: fontFor('light') });
200
+ // const normalU = () => ({ fontFamily: fontFor('regular') });
201
+ // const boldU = () => ({ fontFamily: fontFor('bold') });
202
+ // // --- Combined styles (same API as your original) ---
203
+ // const header1 = () => ({ ...largeU(), ...boldU() });
204
+ // const header2 = () => ({ ...largeU(), ...normalU() });
205
+ // const header3 = () => ({ ...mediumU(), ...normalU() });
206
+ // const header3Bold = () => ({ ...mediumU(), ...boldU() });
207
+ // const standardU = () => ({ ...regularU(), ...normalU() });
208
+ // const standardLight = () => ({ ...regularU(), ...lightU() });
209
+ // const standardBold = () => ({ ...regularU(), ...boldU() });
210
+ // const subTextU = () => ({ ...smallU(), ...normalU() });
211
+ // const subTextBold = () => ({ ...smallU(), ...boldU() });
212
+ // const subTextLight = () => ({ ...smallU(), ...lightU() });
213
+ // const smallTextU = () => ({ ...xSmall(), ...normalU() });
214
+ // const smallTextBold = () => ({ ...xSmall(), ...boldU() });
215
+ // const smallTextLight = () => ({ ...xSmall(), ...lightU() });
216
+ // // --- Fonts quick map (expose the currently used regular font per language) ---
217
+ // const currentFonts = () => ({
218
+ // en: (_config.fonts as TypographyFonts).en.regular,
219
+ // ar: (_config.fonts as TypographyFonts).ar.regular,
220
+ // });
221
+ // // --- Exported object (same shape as your original API) ---
222
+ // const Typography = {
223
+ // // size functions
224
+ // size: {
225
+ // xSmall,
226
+ // smallU,
227
+ // regularU,
228
+ // mediumU,
229
+ // largeU,
230
+ // },
231
+ // // styles
232
+ // style: {
233
+ // header1,
234
+ // header2,
235
+ // header3,
236
+ // header3Bold,
237
+ // standardU,
238
+ // standardLight,
239
+ // standardBold,
240
+ // subTextU,
241
+ // subTextBold,
242
+ // subTextLight,
243
+ // smallTextU,
244
+ // smallTextBold,
245
+ // smallTextLight,
246
+ // },
247
+ // // weight helpers
248
+ // weights: {
249
+ // lightU,
250
+ // boldU,
251
+ // normalU,
252
+ // },
253
+ // // quick fonts map
254
+ // fonts: currentFonts,
255
+ // // exposed config helpers
256
+ // __internal: {
257
+ // setTypographyConfig,
258
+ // getTypographyConfig,
259
+ // },
260
+ // };
261
+ // export default Typography;
262
+ // src/styles/typography.ts
263
+ // import { moderateScale } from "./scale";
264
+ // // --- Types ---
265
+ // export type Lang = "en" | "hi";
266
+ // // Allow UNLIMITED font weights
267
+ // export type FontWeightMap = {
268
+ // [weightName: string]: string; // e.g. medium: "Poppins-Medium"
269
+ // };
270
+ // // Accept numeric or named size keys in config
271
+ // export type TypographySizes = {
272
+ // // numeric keys still allowed
273
+ // [key: number]: number;
274
+ // } & {
275
+ // // named keys like "SIZE12": 12
276
+ // [key: string]: number;
277
+ // };
278
+ // export type TypographyFonts = {
279
+ // en: FontWeightMap;
280
+ // hi: FontWeightMap;
281
+ // };
282
+ // // Config for user customization
283
+ // export type TypographyConfig = {
284
+ // fonts?: Partial<TypographyFonts>;
285
+ // // allow either numeric keys or named keys like "SIZE12"
286
+ // sizes?: Partial<TypographySizes>;
287
+ // lang?: Lang; // active language
288
+ // scaleFn?: (size: number) => number;
289
+ // };
290
+ // // --- SizeKey constants ---
291
+ // // Export constants to use in code like Typography.style.size(SizeKey.SIZE16)
292
+ // export const SizeKey = (() => {
293
+ // const map: { [k: string]: string } = {};
294
+ // for (let i = 10; i <= 50; i += 2) {
295
+ // // create keys SIZE10, SIZE12, ... SIZE50
296
+ // map[`SIZE${i}`] = `SIZE${i}`;
297
+ // }
298
+ // return map as { [K in `SIZE${number}`]: `SIZE${number}` };
299
+ // })();
300
+ // // --- DEFAULT FONTS ---
301
+ // const DEFAULT_FONTS: TypographyFonts = {
302
+ // en: {
303
+ // regular: "Poppins-Regular",
304
+ // light: "Poppins-Light", // corrected from Medium
305
+ // semibold: "Poppins-SemiBold",
306
+ // extrabold: "Poppins-ExtraBold",
307
+ // black: "Poppins-Black",
308
+ // bold: "Poppins-Bold",
309
+ // },
310
+ // hi: {
311
+ // regular: "Poppins-Regular",
312
+ // light: "Poppins-Light",
313
+ // semibold: "Poppins-SemiBold",
314
+ // extrabold: "Poppins-ExtraBold",
315
+ // black: "Poppins-Black",
316
+ // bold: "Poppins-Bold",
317
+ // },
318
+ // };
319
+ // // --- DEFAULT_SIZES as numeric map (10..50 step 2) ---
320
+ // const DEFAULT_SIZES: TypographySizes = {};
321
+ // for (let i = 10; i <= 50; i += 2) {
322
+ // DEFAULT_SIZES[i] = i;
323
+ // // also add named keys
324
+ // (DEFAULT_SIZES as any)[`SIZE${i}`] = i;
325
+ // }
326
+ // // --- Internal config (mutable) ---
327
+ // let _config: Required<TypographyConfig> = {
328
+ // fonts: DEFAULT_FONTS,
329
+ // sizes: DEFAULT_SIZES,
330
+ // lang: "en",
331
+ // scaleFn: moderateScale,
332
+ // };
333
+ // // Utility: normalize incoming sizes map (merge numeric and named keys)
334
+ // function normalizeSizes(sizes?: Partial<TypographySizes>) {
335
+ // const out: TypographySizes = { ...(DEFAULT_SIZES as TypographySizes) };
336
+ // if (!sizes) return out;
337
+ // Object.keys(sizes).forEach((k) => {
338
+ // const v = (sizes as any)[k];
339
+ // if (v == null) return;
340
+ // // if key is numeric string like "16" or number-like, coerce to number index AND also keep named if provided
341
+ // const asNumber = Number(k);
342
+ // if (!Number.isNaN(asNumber)) {
343
+ // out[asNumber] = v;
344
+ // // also add corresponding named key for parity (e.g. "SIZE16")
345
+ // out[`SIZE${asNumber}`] = v;
346
+ // } else {
347
+ // // named key (e.g. "SIZE16")
348
+ // out[k] = v;
349
+ // // if it matches SIZE<number>, add numeric index too
350
+ // const m = k.match(/^SIZE(\d+)$/i);
351
+ // if (m) {
352
+ // out[Number(m[1])] = v;
353
+ // }
354
+ // }
355
+ // });
356
+ // return out;
357
+ // }
358
+ // // Update config safely
359
+ // export function setTypographyConfig(cfg: TypographyConfig) {
360
+ // _config = {
361
+ // fonts: {
362
+ // en: { ...DEFAULT_FONTS.en, ...(cfg.fonts?.en || {}) },
363
+ // hi: { ...DEFAULT_FONTS.hi, ...(cfg.fonts?.hi || {}) },
364
+ // },
365
+ // sizes: normalizeSizes(cfg.sizes),
366
+ // lang: cfg.lang || _config.lang,
367
+ // scaleFn: cfg.scaleFn || moderateScale,
368
+ // };
369
+ // }
370
+ // // --- Get config ---
371
+ // export function getTypographyConfig(): TypographyConfig {
372
+ // return JSON.parse(JSON.stringify(_config));
373
+ // }
374
+ // // --- Helpers ---
375
+ // function fontFor(weight: string) {
376
+ // const lang: Lang = _config.lang;
377
+ // const fontSet = _config.fonts[lang];
378
+ // return (fontSet[weight] as string) || fontSet["regular"] || DEFAULT_FONTS.en.regular;
379
+ // }
380
+ // function scale(size: number) {
381
+ // return _config.scaleFn(size);
382
+ // }
383
+ // // --- Style Generator ---
384
+ // // Accept either number or string key (like "SIZE16" or SizeKey.SIZE16)
385
+ // type SizeInput = number | string;
386
+ // function resolveSizeValue(size: SizeInput) {
387
+ // // If number → try direct lookup; if not present use the number
388
+ // if (typeof size === "number") {
389
+ // const v = (_config.sizes as any)[size];
390
+ // return typeof v === "number" ? v : size;
391
+ // }
392
+ // // If string:
393
+ // // - if it's "SIZE16" try named lookup
394
+ // // - if it's numeric string "16" coerce
395
+ // const numeric = Number(size);
396
+ // if (!Number.isNaN(numeric)) {
397
+ // const v = (_config.sizes as any)[numeric];
398
+ // return typeof v === "number" ? v : numeric;
399
+ // }
400
+ // // named like "SIZE16"
401
+ // const named = (_config.sizes as any)[size];
402
+ // if (typeof named === "number") return named;
403
+ // // try pattern SIZExx
404
+ // const m = String(size).match(/^SIZE(\d+)$/i);
405
+ // if (m) {
406
+ // const num = Number(m[1]);
407
+ // const v = (_config.sizes as any)[num] || (_config.sizes as any)[`SIZE${num}`];
408
+ // return typeof v === "number" ? v : num;
409
+ // }
410
+ // // fallback: try parsing any trailing number
411
+ // const m2 = String(size).match(/(\d+)$/);
412
+ // if (m2) {
413
+ // const num = Number(m2[1]);
414
+ // const v = (_config.sizes as any)[num];
415
+ // return typeof v === "number" ? v : num;
416
+ // }
417
+ // // final fallback
418
+ // return 14; // safe default base size
419
+ // }
420
+ // function fontSize(size: SizeInput) {
421
+ // const resolved = resolveSizeValue(size);
422
+ // return { fontSize: scale(resolved) };
423
+ // }
424
+ // function fontWeight(weight: string) {
425
+ // return { fontFamily: fontFor(weight) };
426
+ // }
427
+ // // --- Predefined Style Helpers ---
428
+ // const typographyStyle = {
429
+ // // Generic dynamic size (user can pass any 10–50 or named SizeKey)
430
+ // size: (num: SizeInput) => fontSize(num),
431
+ // // Predefined patterns (use named keys to keep consistency)
432
+ // header1: () => ({ ...fontSize(`SIZE28`), ...fontWeight("bold") }),
433
+ // header2: () => ({ ...fontSize(`SIZE24`), ...fontWeight("regular") }),
434
+ // standardU: () => ({ ...fontSize(`SIZE16`), ...fontWeight("regular") }),
435
+ // standardBold: () => ({ ...fontSize(`SIZE16`), ...fontWeight("bold") }),
436
+ // standardLight: () => ({ ...fontSize(`SIZE16`), ...fontWeight("light") }),
437
+ // small: () => ({ ...fontSize(`SIZE12`), ...fontWeight("regular") }),
438
+ // smallBold: () => ({ ...fontSize(`SIZE12`), ...fontWeight("bold") }),
439
+ // };
440
+ // // Export
441
+ // const Typography = {
442
+ // fontSize, // dynamic 10–50 (or named keys)
443
+ // fontWeight,
444
+ // style: typographyStyle,
445
+ // __internal: { setTypographyConfig, getTypographyConfig },
446
+ // // export SizeKey so consumers can use named keys
447
+ // SizeKey,
448
+ // };
449
+ // export default Typography;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teamnhz/rn-ui-toolkit",
3
- "version": "1.4.2",
3
+ "version": "1.4.4",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [