aport-tools 4.1.27 → 4.1.29

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -12,6 +12,12 @@ To install the latest version of aport-tools, run the following command:
12
12
  npm i aport-tools
13
13
  ```
14
14
 
15
+ requires:
16
+
17
+ ```bash
18
+ npm i aport-themes
19
+ ```
20
+
15
21
  Happy to receive help and advice; siixsixer@gmail.com
16
22
 
17
23
  License
@@ -1,6 +1,6 @@
1
+ import { ThemeColors } from 'aport-themes';
1
2
  import React from 'react';
2
3
  import { TextProps, TextStyle } from 'react-native';
3
- import { ThemeColors } from '../styles/colors';
4
4
  interface CustomTextProps extends TextProps {
5
5
  /**
6
6
  * Content to be displayed inside the Text component.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- export * from './theme';
2
1
  export * from './buttons';
3
2
  export * from './cards';
4
3
  export * from './fonts';
package/dist/index.esm.js CHANGED
@@ -1,7 +1,6 @@
1
- /*! aport-tools v4.1.27 | ISC */
2
- import React, { createContext, useState, useEffect, useContext, useMemo } from 'react';
3
- import { Appearance, StyleSheet, View, Text as Text$1, Switch, TextInput, TouchableOpacity, ActivityIndicator, Platform } from 'react-native';
4
- import { useAsyncStorage } from '@react-native-async-storage/async-storage';
1
+ /*! aport-tools v4.1.29 | ISC */
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';
5
4
 
6
5
  /******************************************************************************
7
6
  Copyright (c) Microsoft Corporation.
@@ -86,283 +85,6 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
86
85
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
87
86
  };
88
87
 
89
- // src/styles/colors.ts
90
- var lightTheme = {
91
- primary: {
92
- hex: "#1A73E8",
93
- rgb: {
94
- r: 26,
95
- g: 115,
96
- b: 232
97
- }
98
- },
99
- secondary: {
100
- hex: "#F0F6FF",
101
- rgb: {
102
- r: 240,
103
- g: 246,
104
- b: 255
105
- }
106
- },
107
- background: {
108
- hex: "#FFFFFF",
109
- rgb: {
110
- r: 255,
111
- g: 255,
112
- b: 255
113
- }
114
- },
115
- text: {
116
- hex: "#000000",
117
- rgb: {
118
- r: 0,
119
- g: 0,
120
- b: 0
121
- }
122
- },
123
- textButton: {
124
- hex: "#FFFFFF",
125
- rgb: {
126
- r: 255,
127
- g: 255,
128
- b: 255
129
- }
130
- },
131
- error: {
132
- hex: "#FF5252",
133
- rgb: {
134
- r: 255,
135
- g: 82,
136
- b: 82
137
- }
138
- },
139
- success: {
140
- hex: "#4CAF50",
141
- rgb: {
142
- r: 76,
143
- g: 175,
144
- b: 80
145
- }
146
- },
147
- warning: {
148
- hex: "#FFC107",
149
- rgb: {
150
- r: 255,
151
- g: 193,
152
- b: 7
153
- }
154
- },
155
- body: {
156
- // Body color is the same as background in the light theme
157
- hex: '#FFFFFF',
158
- rgb: {
159
- r: 255,
160
- g: 255,
161
- b: 255
162
- }
163
- }
164
- };
165
- var darkTheme = {
166
- primary: {
167
- hex: "#BB86FC",
168
- rgb: {
169
- r: 187,
170
- g: 134,
171
- b: 252
172
- }
173
- },
174
- secondary: {
175
- hex: "#03DAC6",
176
- rgb: {
177
- r: 3,
178
- g: 218,
179
- b: 198
180
- }
181
- },
182
- background: {
183
- hex: "#121212",
184
- rgb: {
185
- r: 18,
186
- g: 18,
187
- b: 18
188
- }
189
- },
190
- text: {
191
- hex: "#FFFFFF",
192
- rgb: {
193
- r: 255,
194
- g: 255,
195
- b: 255
196
- }
197
- },
198
- textButton: {
199
- hex: "#FFFFFF",
200
- rgb: {
201
- r: 255,
202
- g: 255,
203
- b: 255
204
- }
205
- },
206
- error: {
207
- hex: "#CF6679",
208
- rgb: {
209
- r: 207,
210
- g: 102,
211
- b: 121
212
- }
213
- },
214
- success: {
215
- hex: "#03DAC6",
216
- rgb: {
217
- r: 3,
218
- g: 218,
219
- b: 198
220
- }
221
- },
222
- warning: {
223
- hex: "#FFB74D",
224
- rgb: {
225
- r: 255,
226
- g: 183,
227
- b: 77
228
- }
229
- },
230
- body: {
231
- hex: '#1C1C1E',
232
- rgb: {
233
- r: 28,
234
- g: 28,
235
- b: 30
236
- }
237
- }
238
- };
239
-
240
- /**
241
- * React context for managing theme-related data and functions.
242
- */
243
- var ThemeContext = /*#__PURE__*/createContext({
244
- theme: {
245
- colors: lightTheme
246
- },
247
- toggleTheme: function toggleTheme() {}
248
- });
249
- /**
250
- * ThemeProvider component that manages and provides theme data to its children.
251
- *
252
- * @param children - The child components that will consume the theme context.
253
- * @param initialTheme - Optional prop to set the initial theme.
254
- */
255
- var ThemeProvider = function ThemeProvider(_a) {
256
- var children = _a.children,
257
- initialTheme = _a.initialTheme;
258
- var _b = useState(null),
259
- colorScheme = _b[0],
260
- setColorScheme = _b[1];
261
- // Use useAsyncStorage hook for managing the theme storage
262
- var _c = useAsyncStorage('theme'),
263
- getItem = _c.getItem,
264
- setItem = _c.setItem;
265
- useEffect(function () {
266
- var loadTheme = function loadTheme() {
267
- return __awaiter(void 0, void 0, void 0, function () {
268
- var systemTheme;
269
- return __generator(this, function (_a) {
270
- try {
271
- // const storedTheme = await getItem();
272
- // if (storedTheme === 'dark' || storedTheme === 'light') {
273
- // setColorScheme(storedTheme);
274
- //}
275
- if (initialTheme) {
276
- setColorScheme(initialTheme);
277
- } else {
278
- systemTheme = Appearance.getColorScheme();
279
- setColorScheme(systemTheme);
280
- }
281
- } catch (error) {
282
- console.error('Failed to load theme.', error);
283
- setColorScheme(Appearance.getColorScheme());
284
- }
285
- return [2 /*return*/];
286
- });
287
- });
288
- };
289
- loadTheme();
290
- var subscription = Appearance.addChangeListener(function (_a) {
291
- var colorScheme = _a.colorScheme;
292
- if (!colorScheme) return; // Prevent setting null
293
- setColorScheme(colorScheme);
294
- });
295
- return function () {
296
- return subscription.remove();
297
- };
298
- }, [initialTheme, getItem]);
299
- var toggleTheme = function toggleTheme() {
300
- return __awaiter(void 0, void 0, void 0, function () {
301
- var newTheme, error_1;
302
- return __generator(this, function (_a) {
303
- switch (_a.label) {
304
- case 0:
305
- _a.trys.push([0, 2,, 3]);
306
- newTheme = colorScheme === 'dark' ? 'light' : 'dark';
307
- setColorScheme(newTheme);
308
- return [4 /*yield*/, setItem(newTheme)];
309
- case 1:
310
- _a.sent(); // Use setItem from useAsyncStorage
311
- return [3 /*break*/, 3];
312
- case 2:
313
- error_1 = _a.sent();
314
- console.error('Failed to toggle theme.', error_1);
315
- return [3 /*break*/, 3];
316
- case 3:
317
- return [2 /*return*/];
318
- }
319
- });
320
- });
321
- };
322
- var theme = {
323
- colors: colorScheme === 'dark' ? darkTheme : lightTheme
324
- };
325
- return /*#__PURE__*/React.createElement(ThemeContext.Provider, {
326
- value: {
327
- theme: theme,
328
- toggleTheme: toggleTheme
329
- }
330
- }, children);
331
- };
332
-
333
- var ThemeToggle = function ThemeToggle() {
334
- var _a = useContext(ThemeContext),
335
- theme = _a.theme,
336
- toggleTheme = _a.toggleTheme;
337
- var isDarkMode = theme.colors === darkTheme;
338
- return /*#__PURE__*/React.createElement(View, {
339
- style: styles$6.container
340
- }, /*#__PURE__*/React.createElement(Text$1, {
341
- style: [styles$6.text, {
342
- color: theme.colors.text.hex
343
- }]
344
- }, "Dark Mode"), /*#__PURE__*/React.createElement(Switch, {
345
- value: isDarkMode,
346
- onValueChange: toggleTheme,
347
- trackColor: {
348
- "false": lightTheme.secondary.hex,
349
- "true": darkTheme.primary.hex
350
- },
351
- thumbColor: isDarkMode ? darkTheme.secondary.hex : lightTheme.primary.hex
352
- }));
353
- };
354
- var styles$6 = StyleSheet.create({
355
- container: {
356
- marginTop: 20,
357
- flexDirection: 'row',
358
- alignItems: 'center'
359
- },
360
- text: {
361
- marginRight: 10,
362
- fontSize: 16
363
- }
364
- });
365
-
366
88
  // src/forms/FormContext.tsx
367
89
  var FormContext = /*#__PURE__*/createContext(undefined);
368
90
  var useFormContext = function useFormContext() {
@@ -418,6 +140,302 @@ var Form = function Form(_a) {
418
140
  }, children);
419
141
  };
420
142
 
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
+
421
439
  // src/fonts/Text.tsx
422
440
  /**
423
441
  * A dynamic Text component that supports HTML-like formatting.
@@ -450,7 +468,7 @@ var Text = function Text(_a) {
450
468
  _j = _a.h,
451
469
  h = _j === void 0 ? 0 : _j,
452
470
  style = _a.style;
453
- var theme = useContext(ThemeContext).theme;
471
+ var theme = useContext(distExports.ThemeContext).theme;
454
472
  var colors = theme.colors;
455
473
  // Calculate header size based on 'h' prop
456
474
  var fontSize = size;
@@ -485,7 +503,7 @@ StyleSheet.create({
485
503
  // src/forms/ErrorList.tsx
486
504
  var ErrorList = function ErrorList(_a) {
487
505
  var errors = _a.errors;
488
- var theme = useContext(ThemeContext).theme;
506
+ var theme = useContext(distExports.ThemeContext).theme;
489
507
  var colors = theme.colors;
490
508
  return /*#__PURE__*/React.createElement(View, {
491
509
  style: styles$5.container
@@ -548,7 +566,7 @@ var Input = function Input(_a) {
548
566
  formValues = _b.formValues,
549
567
  setFormValue = _b.setFormValue,
550
568
  formErrors = _b.errors;
551
- var theme = useContext(ThemeContext).theme;
569
+ var theme = useContext(distExports.ThemeContext).theme;
552
570
  var colors = theme.colors;
553
571
  /**
554
572
  * Handles text changes in the input field, applying formatting based on the inputType.
@@ -596,7 +614,7 @@ var Input = function Input(_a) {
596
614
  value: formValues[name] || "",
597
615
  onChangeText: handleChange,
598
616
  placeholder: label,
599
- placeholderTextColor: colors.text.hex
617
+ placeholderTextColor: colors.placeHolder.hex
600
618
  }, rest)), formErrors[name] && formErrors[name].length > 0 && (/*#__PURE__*/React.createElement(ErrorList, {
601
619
  errors: formErrors[name]
602
620
  })));
@@ -675,7 +693,7 @@ var styles$3 = StyleSheet.create({
675
693
  var Label = function Label(_a) {
676
694
  var text = _a.text,
677
695
  style = _a.style;
678
- var theme = useContext(ThemeContext).theme;
696
+ var theme = useContext(distExports.ThemeContext).theme;
679
697
  var colors = theme.colors;
680
698
  return /*#__PURE__*/React.createElement(Text, {
681
699
  style: [styles$2.label, style, {
@@ -750,7 +768,7 @@ var Button = function Button(_a) {
750
768
  _g = _a.loading,
751
769
  loading = _g === void 0 ? false : _g,
752
770
  onPress = _a.onPress;
753
- var theme = useContext(ThemeContext).theme;
771
+ var theme = useContext(distExports.ThemeContext).theme;
754
772
  var colors = theme.colors;
755
773
  var handleSubmit = useFormContext().handleSubmit;
756
774
  var computedStyles = useMemo(function () {
@@ -761,7 +779,9 @@ var Button = function Button(_a) {
761
779
  }, (disabled || loading) && styles$1.disabled]);
762
780
  }, [type, disabled, loading, rounded, borderRadius, isFullWidth, colors]);
763
781
  var textColor = useMemo(function () {
764
- return {
782
+ return type === "cancel" ? {
783
+ color: colors.text.hex
784
+ } : {
765
785
  color: colors.textButton.hex
766
786
  };
767
787
  }, [type, colors]);
@@ -824,7 +844,7 @@ var Card = function Card(_a) {
824
844
  elevation = _d === void 0 ? 4 : _d,
825
845
  _e = _a.shadowProps,
826
846
  shadowProps = _e === void 0 ? {} : _e;
827
- var theme = useContext(ThemeContext).theme;
847
+ var theme = useContext(distExports.ThemeContext).theme;
828
848
  var colors = theme.colors;
829
849
  // Animation state for pressable effect
830
850
  // Default shadow styles (improved platform-specific handling)
@@ -845,7 +865,7 @@ var Card = function Card(_a) {
845
865
  });
846
866
  var cardStyles = [styles.container, {
847
867
  borderRadius: borderRadius,
848
- backgroundColor: colors.body.hex
868
+ backgroundColor: colors.background.hex
849
869
  }, defaultShadow,
850
870
  // Dynamic shadows based on platform
851
871
  style // External styles
@@ -866,5 +886,5 @@ var styles = StyleSheet.create({
866
886
  }
867
887
  });
868
888
 
869
- export { Button, Card, ErrorList, Form, Input, Label, Text, TextArea, ThemeContext, ThemeProvider, ThemeToggle, useFormContext };
889
+ export { Button, Card, ErrorList, Form, Input, Label, Text, TextArea, useFormContext };
870
890
  //# sourceMappingURL=index.esm.js.map