aport-tools 4.1.28 → 4.1.31

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.js CHANGED
@@ -1,9 +1,9 @@
1
- /*! aport-tools v4.1.28 | ISC */
1
+ /*! aport-tools v4.1.31 | ISC */
2
2
  'use strict';
3
3
 
4
4
  var React = require('react');
5
5
  var reactNative = require('react-native');
6
- var asyncStorage = require('@react-native-async-storage/async-storage');
6
+ var aportThemes = require('aport-themes');
7
7
 
8
8
  /******************************************************************************
9
9
  Copyright (c) Microsoft Corporation.
@@ -88,283 +88,6 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
88
88
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
89
89
  };
90
90
 
91
- // src/styles/colors.ts
92
- var lightTheme = {
93
- primary: {
94
- hex: "#1A73E8",
95
- rgb: {
96
- r: 26,
97
- g: 115,
98
- b: 232
99
- }
100
- },
101
- secondary: {
102
- hex: "#F0F6FF",
103
- rgb: {
104
- r: 240,
105
- g: 246,
106
- b: 255
107
- }
108
- },
109
- background: {
110
- hex: "#FFFFFF",
111
- rgb: {
112
- r: 255,
113
- g: 255,
114
- b: 255
115
- }
116
- },
117
- text: {
118
- hex: "#000000",
119
- rgb: {
120
- r: 0,
121
- g: 0,
122
- b: 0
123
- }
124
- },
125
- textButton: {
126
- hex: "#FFFFFF",
127
- rgb: {
128
- r: 255,
129
- g: 255,
130
- b: 255
131
- }
132
- },
133
- error: {
134
- hex: "#FF5252",
135
- rgb: {
136
- r: 255,
137
- g: 82,
138
- b: 82
139
- }
140
- },
141
- success: {
142
- hex: "#4CAF50",
143
- rgb: {
144
- r: 76,
145
- g: 175,
146
- b: 80
147
- }
148
- },
149
- warning: {
150
- hex: "#FFC107",
151
- rgb: {
152
- r: 255,
153
- g: 193,
154
- b: 7
155
- }
156
- },
157
- body: {
158
- // Body color is the same as background in the light theme
159
- hex: '#FFFFFF',
160
- rgb: {
161
- r: 255,
162
- g: 255,
163
- b: 255
164
- }
165
- }
166
- };
167
- var darkTheme = {
168
- primary: {
169
- hex: "#BB86FC",
170
- rgb: {
171
- r: 187,
172
- g: 134,
173
- b: 252
174
- }
175
- },
176
- secondary: {
177
- hex: "#03DAC6",
178
- rgb: {
179
- r: 3,
180
- g: 218,
181
- b: 198
182
- }
183
- },
184
- background: {
185
- hex: "#121212",
186
- rgb: {
187
- r: 18,
188
- g: 18,
189
- b: 18
190
- }
191
- },
192
- text: {
193
- hex: "#FFFFFF",
194
- rgb: {
195
- r: 255,
196
- g: 255,
197
- b: 255
198
- }
199
- },
200
- textButton: {
201
- hex: "#FFFFFF",
202
- rgb: {
203
- r: 255,
204
- g: 255,
205
- b: 255
206
- }
207
- },
208
- error: {
209
- hex: "#CF6679",
210
- rgb: {
211
- r: 207,
212
- g: 102,
213
- b: 121
214
- }
215
- },
216
- success: {
217
- hex: "#03DAC6",
218
- rgb: {
219
- r: 3,
220
- g: 218,
221
- b: 198
222
- }
223
- },
224
- warning: {
225
- hex: "#FFB74D",
226
- rgb: {
227
- r: 255,
228
- g: 183,
229
- b: 77
230
- }
231
- },
232
- body: {
233
- hex: '#1C1C1E',
234
- rgb: {
235
- r: 28,
236
- g: 28,
237
- b: 30
238
- }
239
- }
240
- };
241
-
242
- /**
243
- * React context for managing theme-related data and functions.
244
- */
245
- var ThemeContext = /*#__PURE__*/React.createContext({
246
- theme: {
247
- colors: lightTheme
248
- },
249
- toggleTheme: function toggleTheme() {}
250
- });
251
- /**
252
- * ThemeProvider component that manages and provides theme data to its children.
253
- *
254
- * @param children - The child components that will consume the theme context.
255
- * @param initialTheme - Optional prop to set the initial theme.
256
- */
257
- var ThemeProvider = function ThemeProvider(_a) {
258
- var children = _a.children,
259
- initialTheme = _a.initialTheme;
260
- var _b = React.useState(null),
261
- colorScheme = _b[0],
262
- setColorScheme = _b[1];
263
- // Use useAsyncStorage hook for managing the theme storage
264
- var _c = asyncStorage.useAsyncStorage('theme'),
265
- getItem = _c.getItem,
266
- setItem = _c.setItem;
267
- React.useEffect(function () {
268
- var loadTheme = function loadTheme() {
269
- return __awaiter(void 0, void 0, void 0, function () {
270
- var systemTheme;
271
- return __generator(this, function (_a) {
272
- try {
273
- // const storedTheme = await getItem();
274
- // if (storedTheme === 'dark' || storedTheme === 'light') {
275
- // setColorScheme(storedTheme);
276
- //}
277
- if (initialTheme) {
278
- setColorScheme(initialTheme);
279
- } else {
280
- systemTheme = reactNative.Appearance.getColorScheme();
281
- setColorScheme(systemTheme);
282
- }
283
- } catch (error) {
284
- console.error('Failed to load theme.', error);
285
- setColorScheme(reactNative.Appearance.getColorScheme());
286
- }
287
- return [2 /*return*/];
288
- });
289
- });
290
- };
291
- loadTheme();
292
- var subscription = reactNative.Appearance.addChangeListener(function (_a) {
293
- var colorScheme = _a.colorScheme;
294
- if (!colorScheme) return; // Prevent setting null
295
- setColorScheme(colorScheme);
296
- });
297
- return function () {
298
- return subscription.remove();
299
- };
300
- }, [initialTheme, getItem]);
301
- var toggleTheme = function toggleTheme() {
302
- return __awaiter(void 0, void 0, void 0, function () {
303
- var newTheme, error_1;
304
- return __generator(this, function (_a) {
305
- switch (_a.label) {
306
- case 0:
307
- _a.trys.push([0, 2,, 3]);
308
- newTheme = colorScheme === 'dark' ? 'light' : 'dark';
309
- setColorScheme(newTheme);
310
- return [4 /*yield*/, setItem(newTheme)];
311
- case 1:
312
- _a.sent(); // Use setItem from useAsyncStorage
313
- return [3 /*break*/, 3];
314
- case 2:
315
- error_1 = _a.sent();
316
- console.error('Failed to toggle theme.', error_1);
317
- return [3 /*break*/, 3];
318
- case 3:
319
- return [2 /*return*/];
320
- }
321
- });
322
- });
323
- };
324
- var theme = {
325
- colors: colorScheme === 'dark' ? darkTheme : lightTheme
326
- };
327
- return /*#__PURE__*/React.createElement(ThemeContext.Provider, {
328
- value: {
329
- theme: theme,
330
- toggleTheme: toggleTheme
331
- }
332
- }, children);
333
- };
334
-
335
- var ThemeToggle = function ThemeToggle() {
336
- var _a = React.useContext(ThemeContext),
337
- theme = _a.theme,
338
- toggleTheme = _a.toggleTheme;
339
- var isDarkMode = theme.colors === darkTheme;
340
- return /*#__PURE__*/React.createElement(reactNative.View, {
341
- style: styles$6.container
342
- }, /*#__PURE__*/React.createElement(reactNative.Text, {
343
- style: [styles$6.text, {
344
- color: theme.colors.text.hex
345
- }]
346
- }, "Dark Mode"), /*#__PURE__*/React.createElement(reactNative.Switch, {
347
- value: isDarkMode,
348
- onValueChange: toggleTheme,
349
- trackColor: {
350
- "false": lightTheme.secondary.hex,
351
- "true": darkTheme.primary.hex
352
- },
353
- thumbColor: isDarkMode ? darkTheme.secondary.hex : lightTheme.primary.hex
354
- }));
355
- };
356
- var styles$6 = reactNative.StyleSheet.create({
357
- container: {
358
- marginTop: 20,
359
- flexDirection: 'row',
360
- alignItems: 'center'
361
- },
362
- text: {
363
- marginRight: 10,
364
- fontSize: 16
365
- }
366
- });
367
-
368
91
  // src/forms/FormContext.tsx
369
92
  var FormContext = /*#__PURE__*/React.createContext(undefined);
370
93
  var useFormContext = function useFormContext() {
@@ -452,7 +175,7 @@ var Text = function Text(_a) {
452
175
  _j = _a.h,
453
176
  h = _j === void 0 ? 0 : _j,
454
177
  style = _a.style;
455
- var theme = React.useContext(ThemeContext).theme;
178
+ var theme = React.useContext(aportThemes.ThemeContext).theme;
456
179
  var colors = theme.colors;
457
180
  // Calculate header size based on 'h' prop
458
181
  var fontSize = size;
@@ -487,7 +210,7 @@ reactNative.StyleSheet.create({
487
210
  // src/forms/ErrorList.tsx
488
211
  var ErrorList = function ErrorList(_a) {
489
212
  var errors = _a.errors;
490
- var theme = React.useContext(ThemeContext).theme;
213
+ var theme = React.useContext(aportThemes.ThemeContext).theme;
491
214
  var colors = theme.colors;
492
215
  return /*#__PURE__*/React.createElement(reactNative.View, {
493
216
  style: styles$5.container
@@ -550,7 +273,7 @@ var Input = function Input(_a) {
550
273
  formValues = _b.formValues,
551
274
  setFormValue = _b.setFormValue,
552
275
  formErrors = _b.errors;
553
- var theme = React.useContext(ThemeContext).theme;
276
+ var theme = React.useContext(aportThemes.ThemeContext).theme;
554
277
  var colors = theme.colors;
555
278
  /**
556
279
  * Handles text changes in the input field, applying formatting based on the inputType.
@@ -598,7 +321,7 @@ var Input = function Input(_a) {
598
321
  value: formValues[name] || "",
599
322
  onChangeText: handleChange,
600
323
  placeholder: label,
601
- placeholderTextColor: colors.text.hex
324
+ placeholderTextColor: colors.placeHolder.hex
602
325
  }, rest)), formErrors[name] && formErrors[name].length > 0 && (/*#__PURE__*/React.createElement(ErrorList, {
603
326
  errors: formErrors[name]
604
327
  })));
@@ -677,7 +400,7 @@ var styles$3 = reactNative.StyleSheet.create({
677
400
  var Label = function Label(_a) {
678
401
  var text = _a.text,
679
402
  style = _a.style;
680
- var theme = React.useContext(ThemeContext).theme;
403
+ var theme = React.useContext(aportThemes.ThemeContext).theme;
681
404
  var colors = theme.colors;
682
405
  return /*#__PURE__*/React.createElement(Text, {
683
406
  style: [styles$2.label, style, {
@@ -752,7 +475,7 @@ var Button = function Button(_a) {
752
475
  _g = _a.loading,
753
476
  loading = _g === void 0 ? false : _g,
754
477
  onPress = _a.onPress;
755
- var theme = React.useContext(ThemeContext).theme;
478
+ var theme = React.useContext(aportThemes.ThemeContext).theme;
756
479
  var colors = theme.colors;
757
480
  var handleSubmit = useFormContext().handleSubmit;
758
481
  var computedStyles = React.useMemo(function () {
@@ -763,7 +486,9 @@ var Button = function Button(_a) {
763
486
  }, (disabled || loading) && styles$1.disabled]);
764
487
  }, [type, disabled, loading, rounded, borderRadius, isFullWidth, colors]);
765
488
  var textColor = React.useMemo(function () {
766
- return {
489
+ return type === "cancel" ? {
490
+ color: colors.text.hex
491
+ } : {
767
492
  color: colors.textButton.hex
768
493
  };
769
494
  }, [type, colors]);
@@ -826,7 +551,7 @@ var Card = function Card(_a) {
826
551
  elevation = _d === void 0 ? 4 : _d,
827
552
  _e = _a.shadowProps,
828
553
  shadowProps = _e === void 0 ? {} : _e;
829
- var theme = React.useContext(ThemeContext).theme;
554
+ var theme = React.useContext(aportThemes.ThemeContext).theme;
830
555
  var colors = theme.colors;
831
556
  // Animation state for pressable effect
832
557
  // Default shadow styles (improved platform-specific handling)
@@ -847,7 +572,7 @@ var Card = function Card(_a) {
847
572
  });
848
573
  var cardStyles = [styles.container, {
849
574
  borderRadius: borderRadius,
850
- backgroundColor: colors.body.hex
575
+ backgroundColor: colors.background.hex
851
576
  }, defaultShadow,
852
577
  // Dynamic shadows based on platform
853
578
  style // External styles
@@ -876,8 +601,5 @@ exports.Input = Input;
876
601
  exports.Label = Label;
877
602
  exports.Text = Text;
878
603
  exports.TextArea = TextArea;
879
- exports.ThemeContext = ThemeContext;
880
- exports.ThemeProvider = ThemeProvider;
881
- exports.ThemeToggle = ThemeToggle;
882
604
  exports.useFormContext = useFormContext;
883
605
  //# sourceMappingURL=index.js.map