aport-tools 4.1.29 → 4.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
1
- import { ThemeColors } from 'aport-themes';
1
+ import { ThemeColors, ThemeFonts } from 'aport-themes';
2
2
  import React from 'react';
3
3
  import { TextProps, TextStyle } from 'react-native';
4
4
  interface CustomTextProps extends TextProps {
@@ -31,6 +31,11 @@ interface CustomTextProps extends TextProps {
31
31
  * This restricts type to known color keys like 'primary', 'error', etc.
32
32
  */
33
33
  type?: keyof ThemeColors;
34
+ /**
35
+ * Text font type. Defaults to 'body'. Should match the keys in ThemeFonts.
36
+ * This restricts type to known fonts keys like 'primary', 'secundary', etc.
37
+ */
38
+ typeFont?: keyof ThemeFonts;
34
39
  /**
35
40
  * Header level. Accepts 0 (none), 1, 2, or 3. Defaults to 0.
36
41
  */
@@ -48,6 +53,8 @@ interface CustomTextProps extends TextProps {
48
53
  * @param size - Size of the text. Defaults to 'medium'.
49
54
  * @param b - If true, applies bold styling.
50
55
  * @param i - If true, applies italic styling.
56
+ * @param type - Type of Text component. Defaults to 'text'.
57
+ * @param typeFont - Type of Font component. Defaults to 'body'.
51
58
  * @param u - If true, applies underline styling.
52
59
  * @param align - Paragraph alignment. Defaults to 'left'.
53
60
  * @param h - Header level. Accepts 0 (none), 1, 2, or 3. Defaults to 0.
package/dist/index.esm.js CHANGED
@@ -1,6 +1,7 @@
1
- /*! aport-tools v4.1.29 | ISC */
1
+ /*! aport-tools v4.2.0 | ISC */
2
2
  import React, { useContext, useState, createContext, useMemo } from 'react';
3
- import require$$1, { StyleSheet, Text as Text$1, View, TextInput, TouchableOpacity, ActivityIndicator, Platform } from 'react-native';
3
+ import { StyleSheet, Text as Text$1, View, TextInput, TouchableOpacity, ActivityIndicator, Platform } from 'react-native';
4
+ import { ThemeContext } from 'aport-themes';
4
5
 
5
6
  /******************************************************************************
6
7
  Copyright (c) Microsoft Corporation.
@@ -140,302 +141,6 @@ var Form = function Form(_a) {
140
141
  }, children);
141
142
  };
142
143
 
143
- var dist = {};
144
-
145
- /*! aport-themes v1.0.1 | ISC */
146
-
147
- var hasRequiredDist;
148
-
149
- function requireDist () {
150
- if (hasRequiredDist) return dist;
151
- hasRequiredDist = 1;
152
-
153
- var React$1 = React;
154
- var reactNative = require$$1;
155
-
156
- // src/styles/colors.ts
157
- var lightTheme = {
158
- primary: {
159
- hex: "#1A73E8",
160
- rgb: {
161
- r: 26,
162
- g: 115,
163
- b: 232
164
- }
165
- },
166
- secondary: {
167
- hex: "#F0F6FF",
168
- rgb: {
169
- r: 240,
170
- g: 246,
171
- b: 255
172
- }
173
- },
174
- background: {
175
- hex: "#FFFFFF",
176
- rgb: {
177
- r: 255,
178
- g: 255,
179
- b: 255
180
- }
181
- },
182
- text: {
183
- hex: "#000000",
184
- rgb: {
185
- r: 0,
186
- g: 0,
187
- b: 0
188
- }
189
- },
190
- textButton: {
191
- hex: "#FFFFFF",
192
- rgb: {
193
- r: 255,
194
- g: 255,
195
- b: 255
196
- }
197
- },
198
- error: {
199
- hex: "#FF5252",
200
- rgb: {
201
- r: 255,
202
- g: 82,
203
- b: 82
204
- }
205
- },
206
- success: {
207
- hex: "#4CAF50",
208
- rgb: {
209
- r: 76,
210
- g: 175,
211
- b: 80
212
- }
213
- },
214
- warning: {
215
- hex: "#FFC107",
216
- rgb: {
217
- r: 255,
218
- g: 193,
219
- b: 7
220
- }
221
- },
222
- body: {
223
- hex: '#F5F5F5',
224
- rgb: {
225
- r: 245,
226
- g: 245,
227
- b: 245
228
- }
229
- },
230
- placeHolder: {
231
- hex: '#A8A8A8',
232
- rgb: {
233
- r: 168,
234
- g: 168,
235
- b: 168
236
- }
237
- }
238
- };
239
- var darkTheme = {
240
- primary: {
241
- hex: "#BB86FC",
242
- rgb: {
243
- r: 187,
244
- g: 134,
245
- b: 252
246
- }
247
- },
248
- secondary: {
249
- hex: "#03DAC6",
250
- rgb: {
251
- r: 3,
252
- g: 218,
253
- b: 198
254
- }
255
- },
256
- background: {
257
- hex: "#121212",
258
- rgb: {
259
- r: 18,
260
- g: 18,
261
- b: 18
262
- }
263
- },
264
- text: {
265
- hex: "#FFFFFF",
266
- rgb: {
267
- r: 255,
268
- g: 255,
269
- b: 255
270
- }
271
- },
272
- textButton: {
273
- hex: "#FFFFFF",
274
- rgb: {
275
- r: 255,
276
- g: 255,
277
- b: 255
278
- }
279
- },
280
- error: {
281
- hex: "#CF6679",
282
- rgb: {
283
- r: 207,
284
- g: 102,
285
- b: 121
286
- }
287
- },
288
- success: {
289
- hex: "#03DAC6",
290
- rgb: {
291
- r: 3,
292
- g: 218,
293
- b: 198
294
- }
295
- },
296
- warning: {
297
- hex: "#FFB74D",
298
- rgb: {
299
- r: 255,
300
- g: 183,
301
- b: 77
302
- }
303
- },
304
- body: {
305
- hex: '#1C1C1E',
306
- rgb: {
307
- r: 28,
308
- g: 28,
309
- b: 30
310
- }
311
- },
312
- placeHolder: {
313
- hex: '#6C6C6E',
314
- rgb: {
315
- r: 108,
316
- g: 108,
317
- b: 110
318
- }
319
- }
320
- };
321
-
322
- // Utility to detect if running on React Native
323
- var isReactNative = typeof navigator !== 'undefined' && navigator.product === 'ReactNative';
324
- // Platform-specific imports
325
- var Appearance = isReactNative ? require$$1.Appearance : null;
326
- /**
327
- * React context for managing theme-related data and functions.
328
- */
329
- var ThemeContext = /*#__PURE__*/React$1.createContext({
330
- theme: {
331
- colors: lightTheme
332
- },
333
- toggleTheme: function toggleTheme() {}
334
- });
335
- /**
336
- * ThemeProvider component that manages and provides theme data to its children.
337
- *
338
- * @param children - The child components that will consume the theme context.
339
- * @param initialTheme - Optional prop to set the initial theme.
340
- */
341
- var ThemeProvider = function ThemeProvider(_a) {
342
- var children = _a.children,
343
- initialTheme = _a.initialTheme;
344
- var _b = React$1.useState(initialTheme || null),
345
- colorScheme = _b[0],
346
- setColorScheme = _b[1];
347
- React$1.useEffect(function () {
348
- var loadTheme = function loadTheme() {
349
- if (initialTheme) {
350
- setColorScheme(initialTheme);
351
- } else {
352
- if (isReactNative) {
353
- var systemTheme = Appearance.getColorScheme();
354
- setColorScheme(systemTheme);
355
- } else {
356
- var systemTheme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
357
- setColorScheme(systemTheme);
358
- }
359
- }
360
- };
361
- loadTheme();
362
- if (isReactNative) {
363
- var subscription_1 = Appearance.addChangeListener(function (_a) {
364
- var colorScheme = _a.colorScheme;
365
- setColorScheme(colorScheme);
366
- });
367
- return function () {
368
- return subscription_1.remove();
369
- };
370
- } else {
371
- var mediaQuery_1 = window.matchMedia('(prefers-color-scheme: dark)');
372
- var mediaChangeHandler_1 = function mediaChangeHandler_1(e) {
373
- setColorScheme(e.matches ? 'dark' : 'light');
374
- };
375
- mediaQuery_1.addEventListener('change', mediaChangeHandler_1);
376
- return function () {
377
- return mediaQuery_1.removeEventListener('change', mediaChangeHandler_1);
378
- };
379
- }
380
- }, [initialTheme]);
381
- var toggleTheme = function toggleTheme() {
382
- setColorScheme(function (prevScheme) {
383
- return prevScheme === 'dark' ? 'light' : 'dark';
384
- });
385
- };
386
- var theme = {
387
- colors: colorScheme === 'dark' ? darkTheme : lightTheme
388
- };
389
- return /*#__PURE__*/React$1.createElement(ThemeContext.Provider, {
390
- value: {
391
- theme: theme,
392
- toggleTheme: toggleTheme
393
- }
394
- }, children);
395
- };
396
-
397
- var ThemeToggle = function ThemeToggle() {
398
- var _a = React$1.useContext(ThemeContext),
399
- theme = _a.theme,
400
- toggleTheme = _a.toggleTheme;
401
- var isDarkMode = theme.colors === darkTheme;
402
- return /*#__PURE__*/React$1.createElement(reactNative.View, {
403
- style: styles.container
404
- }, /*#__PURE__*/React$1.createElement(reactNative.Text, {
405
- style: [styles.text, {
406
- color: theme.colors.text.hex
407
- }]
408
- }, "Dark Mode"), /*#__PURE__*/React$1.createElement(reactNative.Switch, {
409
- value: isDarkMode,
410
- onValueChange: toggleTheme,
411
- trackColor: {
412
- "false": lightTheme.secondary.hex,
413
- "true": darkTheme.primary.hex
414
- },
415
- thumbColor: isDarkMode ? darkTheme.secondary.hex : lightTheme.primary.hex
416
- }));
417
- };
418
- var styles = reactNative.StyleSheet.create({
419
- container: {
420
- marginTop: 20,
421
- flexDirection: 'row',
422
- alignItems: 'center'
423
- },
424
- text: {
425
- marginRight: 10,
426
- fontSize: 16
427
- }
428
- });
429
-
430
- dist.ThemeContext = ThemeContext;
431
- dist.ThemeProvider = ThemeProvider;
432
- dist.ThemeToggle = ThemeToggle;
433
-
434
- return dist;
435
- }
436
-
437
- var distExports = requireDist();
438
-
439
144
  // src/fonts/Text.tsx
440
145
  /**
441
146
  * A dynamic Text component that supports HTML-like formatting.
@@ -445,6 +150,8 @@ var distExports = requireDist();
445
150
  * @param size - Size of the text. Defaults to 'medium'.
446
151
  * @param b - If true, applies bold styling.
447
152
  * @param i - If true, applies italic styling.
153
+ * @param type - Type of Text component. Defaults to 'text'.
154
+ * @param typeFont - Type of Font component. Defaults to 'body'.
448
155
  * @param u - If true, applies underline styling.
449
156
  * @param align - Paragraph alignment. Defaults to 'left'.
450
157
  * @param h - Header level. Accepts 0 (none), 1, 2, or 3. Defaults to 0.
@@ -465,16 +172,22 @@ var Text = function Text(_a) {
465
172
  align = _g === void 0 ? 'left' : _g,
466
173
  _h = _a.type,
467
174
  type = _h === void 0 ? 'text' : _h,
468
- _j = _a.h,
469
- h = _j === void 0 ? 0 : _j,
175
+ _j = _a.typeFont,
176
+ typeFont = _j === void 0 ? 'body' : _j,
177
+ _k = _a.h,
178
+ h = _k === void 0 ? 0 : _k,
470
179
  style = _a.style;
471
- var theme = useContext(distExports.ThemeContext).theme;
472
- var colors = theme.colors;
180
+ var theme = useContext(ThemeContext).theme;
181
+ var colors = theme.colors,
182
+ fonts = theme.fonts;
183
+ // Determine font family and size based on 'typeFont'
184
+ var fontSettings = fonts[typeFont] || fonts.body;
185
+ var fontFamily = fontSettings.fontFamily;
186
+ var fontSize = fontSettings.fontSize || size;
473
187
  // Calculate header size based on 'h' prop
474
- var fontSize = size;
475
188
  if (h === 1) fontSize = 32;else if (h === 2) fontSize = 24;else if (h === 3) fontSize = 18;
476
189
  // Define font weight based on bold prop
477
- var fontWeight = b ? '700' : '400';
190
+ var fontWeight = b ? '700' : fontSettings.fontWeight || '400';
478
191
  // Define font style based on italic prop
479
192
  var fontStyle = i ? 'italic' : 'normal';
480
193
  // Define text decoration based on underline prop
@@ -487,6 +200,7 @@ var Text = function Text(_a) {
487
200
  var textStyles = {
488
201
  fontSize: fontSize,
489
202
  fontWeight: fontWeight,
203
+ fontFamily: fontFamily,
490
204
  fontStyle: fontStyle,
491
205
  textDecorationLine: textDecorationLine,
492
206
  textAlign: textAlign,
@@ -503,7 +217,7 @@ StyleSheet.create({
503
217
  // src/forms/ErrorList.tsx
504
218
  var ErrorList = function ErrorList(_a) {
505
219
  var errors = _a.errors;
506
- var theme = useContext(distExports.ThemeContext).theme;
220
+ var theme = useContext(ThemeContext).theme;
507
221
  var colors = theme.colors;
508
222
  return /*#__PURE__*/React.createElement(View, {
509
223
  style: styles$5.container
@@ -566,7 +280,7 @@ var Input = function Input(_a) {
566
280
  formValues = _b.formValues,
567
281
  setFormValue = _b.setFormValue,
568
282
  formErrors = _b.errors;
569
- var theme = useContext(distExports.ThemeContext).theme;
283
+ var theme = useContext(ThemeContext).theme;
570
284
  var colors = theme.colors;
571
285
  /**
572
286
  * Handles text changes in the input field, applying formatting based on the inputType.
@@ -693,7 +407,7 @@ var styles$3 = StyleSheet.create({
693
407
  var Label = function Label(_a) {
694
408
  var text = _a.text,
695
409
  style = _a.style;
696
- var theme = useContext(distExports.ThemeContext).theme;
410
+ var theme = useContext(ThemeContext).theme;
697
411
  var colors = theme.colors;
698
412
  return /*#__PURE__*/React.createElement(Text, {
699
413
  style: [styles$2.label, style, {
@@ -768,7 +482,7 @@ var Button = function Button(_a) {
768
482
  _g = _a.loading,
769
483
  loading = _g === void 0 ? false : _g,
770
484
  onPress = _a.onPress;
771
- var theme = useContext(distExports.ThemeContext).theme;
485
+ var theme = useContext(ThemeContext).theme;
772
486
  var colors = theme.colors;
773
487
  var handleSubmit = useFormContext().handleSubmit;
774
488
  var computedStyles = useMemo(function () {
@@ -844,7 +558,7 @@ var Card = function Card(_a) {
844
558
  elevation = _d === void 0 ? 4 : _d,
845
559
  _e = _a.shadowProps,
846
560
  shadowProps = _e === void 0 ? {} : _e;
847
- var theme = useContext(distExports.ThemeContext).theme;
561
+ var theme = useContext(ThemeContext).theme;
848
562
  var colors = theme.colors;
849
563
  // Animation state for pressable effect
850
564
  // Default shadow styles (improved platform-specific handling)