aport-tools 4.1.2 → 4.1.22
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/dist/index.d.ts +1 -0
- package/dist/index.esm.js +250 -11
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +254 -9
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
package/dist/index.esm.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
/*! aport-tools v4.1.
|
1
|
+
/*! aport-tools v4.1.22 | ISC */
|
2
2
|
import React, { createContext, useState, useEffect, useContext, useMemo } from 'react';
|
3
|
-
import { Appearance, StyleSheet, View, Text as Text$1, Switch, TouchableOpacity, ActivityIndicator, Platform } from 'react-native';
|
3
|
+
import { Appearance, StyleSheet, View, Text as Text$1, Switch, TouchableOpacity, ActivityIndicator, Platform, TextInput } from 'react-native';
|
4
4
|
import { useAsyncStorage } from '@react-native-async-storage/async-storage';
|
5
5
|
|
6
6
|
/******************************************************************************
|
@@ -20,6 +20,29 @@ PERFORMANCE OF THIS SOFTWARE.
|
|
20
20
|
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
21
21
|
|
22
22
|
|
23
|
+
var __assign = function() {
|
24
|
+
__assign = Object.assign || function __assign(t) {
|
25
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
26
|
+
s = arguments[i];
|
27
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
28
|
+
}
|
29
|
+
return t;
|
30
|
+
};
|
31
|
+
return __assign.apply(this, arguments);
|
32
|
+
};
|
33
|
+
|
34
|
+
function __rest(s, e) {
|
35
|
+
var t = {};
|
36
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
37
|
+
t[p] = s[p];
|
38
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
39
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
40
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
41
|
+
t[p[i]] = s[p[i]];
|
42
|
+
}
|
43
|
+
return t;
|
44
|
+
}
|
45
|
+
|
23
46
|
function __awaiter(thisArg, _arguments, P, generator) {
|
24
47
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
25
48
|
return new (P || (P = Promise))(function (resolve, reject) {
|
@@ -313,9 +336,9 @@ var ThemeToggle = function ThemeToggle() {
|
|
313
336
|
toggleTheme = _a.toggleTheme;
|
314
337
|
var isDarkMode = theme.colors === darkTheme;
|
315
338
|
return /*#__PURE__*/React.createElement(View, {
|
316
|
-
style: styles$
|
339
|
+
style: styles$6.container
|
317
340
|
}, /*#__PURE__*/React.createElement(Text$1, {
|
318
|
-
style: [styles$
|
341
|
+
style: [styles$6.text, {
|
319
342
|
color: theme.colors.text.hex
|
320
343
|
}]
|
321
344
|
}, "Dark Mode"), /*#__PURE__*/React.createElement(Switch, {
|
@@ -328,7 +351,7 @@ var ThemeToggle = function ThemeToggle() {
|
|
328
351
|
thumbColor: isDarkMode ? darkTheme.secondary.hex : lightTheme.primary.hex
|
329
352
|
}));
|
330
353
|
};
|
331
|
-
var styles$
|
354
|
+
var styles$6 = StyleSheet.create({
|
332
355
|
container: {
|
333
356
|
marginTop: 20,
|
334
357
|
flexDirection: 'row',
|
@@ -403,11 +426,11 @@ var Button = function Button(_a) {
|
|
403
426
|
var theme = useContext(ThemeContext).theme;
|
404
427
|
var colors = theme.colors;
|
405
428
|
var computedStyles = useMemo(function () {
|
406
|
-
return StyleSheet.flatten([styles$
|
429
|
+
return StyleSheet.flatten([styles$5.button, typeStyles(type, disabled, colors), rounded && {
|
407
430
|
borderRadius: borderRadius
|
408
431
|
}, isFullWidth && {
|
409
432
|
width: '100%'
|
410
|
-
}, (disabled || loading) && styles$
|
433
|
+
}, (disabled || loading) && styles$5.disabled]);
|
411
434
|
}, [type, disabled, loading, rounded, borderRadius, isFullWidth, colors]);
|
412
435
|
var textColor = useMemo(function () {
|
413
436
|
return {
|
@@ -429,7 +452,7 @@ var Button = function Button(_a) {
|
|
429
452
|
style: textColor
|
430
453
|
}, Array.isArray(children) ? children.join('').toUpperCase() : children === null || children === void 0 ? void 0 : children.toUpperCase())));
|
431
454
|
};
|
432
|
-
var styles$
|
455
|
+
var styles$5 = StyleSheet.create({
|
433
456
|
button: {
|
434
457
|
justifyContent: 'center',
|
435
458
|
alignItems: 'center',
|
@@ -485,7 +508,7 @@ var Card = function Card(_a) {
|
|
485
508
|
elevation: elevation // Only applies to Android
|
486
509
|
}
|
487
510
|
});
|
488
|
-
var cardStyles = [styles.container, {
|
511
|
+
var cardStyles = [styles$4.container, {
|
489
512
|
borderRadius: borderRadius,
|
490
513
|
backgroundColor: colors.body.hex
|
491
514
|
}, defaultShadow,
|
@@ -500,7 +523,7 @@ var Card = function Card(_a) {
|
|
500
523
|
style: cardStyles
|
501
524
|
}, children));
|
502
525
|
};
|
503
|
-
var styles = StyleSheet.create({
|
526
|
+
var styles$4 = StyleSheet.create({
|
504
527
|
container: {
|
505
528
|
padding: 16,
|
506
529
|
borderRadius: 12
|
@@ -572,5 +595,221 @@ StyleSheet.create({
|
|
572
595
|
// Define any default styles if needed
|
573
596
|
});
|
574
597
|
|
575
|
-
|
598
|
+
// src/forms/FormContext.tsx
|
599
|
+
var FormContext = /*#__PURE__*/createContext(undefined);
|
600
|
+
var useFormContext = function useFormContext() {
|
601
|
+
var context = useContext(FormContext);
|
602
|
+
if (!context) {
|
603
|
+
throw new Error("useFormContext must be used within a Form");
|
604
|
+
}
|
605
|
+
return context;
|
606
|
+
};
|
607
|
+
var Form = function Form(_a) {
|
608
|
+
var children = _a.children,
|
609
|
+
onSubmit = _a.onSubmit;
|
610
|
+
var _b = useState({}),
|
611
|
+
formValues = _b[0],
|
612
|
+
setFormValues = _b[1];
|
613
|
+
var _c = useState({}),
|
614
|
+
errors = _c[0],
|
615
|
+
setErrors = _c[1];
|
616
|
+
var setFormValue = function setFormValue(name, value) {
|
617
|
+
setFormValues(function (prev) {
|
618
|
+
var _a;
|
619
|
+
return __assign(__assign({}, prev), (_a = {}, _a[name] = value, _a));
|
620
|
+
});
|
621
|
+
};
|
622
|
+
var handleSubmit = function handleSubmit() {
|
623
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
624
|
+
var validationErrors;
|
625
|
+
return __generator(this, function (_a) {
|
626
|
+
switch (_a.label) {
|
627
|
+
case 0:
|
628
|
+
return [4 /*yield*/, onSubmit(formValues)];
|
629
|
+
case 1:
|
630
|
+
validationErrors = _a.sent();
|
631
|
+
// Set the validation errors in state
|
632
|
+
setErrors(validationErrors);
|
633
|
+
// Prevent submission if there are any errors
|
634
|
+
if (Object.keys(validationErrors).length > 0) {
|
635
|
+
return [2 /*return*/]; // Prevent submission
|
636
|
+
}
|
637
|
+
return [2 /*return*/];
|
638
|
+
}
|
639
|
+
});
|
640
|
+
});
|
641
|
+
};
|
642
|
+
return /*#__PURE__*/React.createElement(FormContext.Provider, {
|
643
|
+
value: {
|
644
|
+
formValues: formValues,
|
645
|
+
setFormValue: setFormValue,
|
646
|
+
errors: errors,
|
647
|
+
setErrors: setErrors,
|
648
|
+
handleSubmit: handleSubmit
|
649
|
+
}
|
650
|
+
}, children);
|
651
|
+
};
|
652
|
+
|
653
|
+
// src/forms/ErrorList.tsx
|
654
|
+
var ErrorList = function ErrorList(_a) {
|
655
|
+
var errors = _a.errors;
|
656
|
+
return /*#__PURE__*/React.createElement(View, {
|
657
|
+
style: styles$3.container
|
658
|
+
}, errors.map(function (error, index) {
|
659
|
+
return /*#__PURE__*/React.createElement(View, {
|
660
|
+
key: index,
|
661
|
+
style: styles$3.errorItem
|
662
|
+
}, /*#__PURE__*/React.createElement(Text, {
|
663
|
+
style: styles$3.bullet
|
664
|
+
}, "\u2022"), /*#__PURE__*/React.createElement(Text, {
|
665
|
+
style: styles$3.errorText
|
666
|
+
}, error));
|
667
|
+
}));
|
668
|
+
};
|
669
|
+
var styles$3 = StyleSheet.create({
|
670
|
+
container: {
|
671
|
+
marginTop: 4
|
672
|
+
},
|
673
|
+
errorItem: {
|
674
|
+
flexDirection: 'row',
|
675
|
+
alignItems: 'flex-start',
|
676
|
+
marginBottom: 2
|
677
|
+
},
|
678
|
+
bullet: {
|
679
|
+
marginRight: 4,
|
680
|
+
color: '#FF5252',
|
681
|
+
// Should use 'error' color from theme
|
682
|
+
fontSize: 12
|
683
|
+
},
|
684
|
+
errorText: {
|
685
|
+
flex: 1,
|
686
|
+
color: '#FF5252',
|
687
|
+
// Should use 'error' color from theme
|
688
|
+
fontSize: 12
|
689
|
+
}
|
690
|
+
});
|
691
|
+
|
692
|
+
// src/forms/Input.tsx
|
693
|
+
var Input = function Input(_a) {
|
694
|
+
var name = _a.name,
|
695
|
+
label = _a.label,
|
696
|
+
style = _a.style,
|
697
|
+
rest = __rest(_a, ["name", "label", "style"]);
|
698
|
+
var _b = useFormContext(),
|
699
|
+
formValues = _b.formValues,
|
700
|
+
setFormValue = _b.setFormValue,
|
701
|
+
formErrors = _b.errors;
|
702
|
+
var theme = useContext(ThemeContext).theme;
|
703
|
+
var colors = theme.colors;
|
704
|
+
var handleChange = function handleChange(text) {
|
705
|
+
setFormValue(name, text);
|
706
|
+
};
|
707
|
+
return /*#__PURE__*/React.createElement(View, {
|
708
|
+
style: styles$2.container
|
709
|
+
}, /*#__PURE__*/React.createElement(Text, {
|
710
|
+
style: [styles$2.label, {
|
711
|
+
color: colors.text.hex
|
712
|
+
}]
|
713
|
+
}, label), /*#__PURE__*/React.createElement(TextInput, __assign({
|
714
|
+
style: [styles$2.input, {
|
715
|
+
backgroundColor: colors.body.hex,
|
716
|
+
borderColor: formErrors[name] ? colors.error.hex : '#CCC',
|
717
|
+
color: colors.text.hex
|
718
|
+
}, style],
|
719
|
+
value: formValues[name] || '',
|
720
|
+
onChangeText: handleChange,
|
721
|
+
placeholder: label,
|
722
|
+
placeholderTextColor: colors.text.hex
|
723
|
+
}, rest)), formErrors[name] && formErrors[name].length > 0 && (/*#__PURE__*/React.createElement(ErrorList, {
|
724
|
+
errors: formErrors[name]
|
725
|
+
})));
|
726
|
+
};
|
727
|
+
var styles$2 = StyleSheet.create({
|
728
|
+
container: {
|
729
|
+
marginBottom: 16
|
730
|
+
},
|
731
|
+
label: {
|
732
|
+
marginBottom: 4,
|
733
|
+
fontSize: 14
|
734
|
+
},
|
735
|
+
input: {
|
736
|
+
height: 40,
|
737
|
+
borderWidth: 1,
|
738
|
+
borderRadius: 4,
|
739
|
+
paddingHorizontal: 8
|
740
|
+
}
|
741
|
+
});
|
742
|
+
|
743
|
+
// src/forms/TextArea.tsx
|
744
|
+
var TextArea = function TextArea(_a) {
|
745
|
+
var name = _a.name,
|
746
|
+
label = _a.label;
|
747
|
+
_a.errors;
|
748
|
+
var style = _a.style,
|
749
|
+
rest = __rest(_a, ["name", "label", "errors", "style"]);
|
750
|
+
var _b = useFormContext(),
|
751
|
+
formValues = _b.formValues,
|
752
|
+
setFormValue = _b.setFormValue,
|
753
|
+
formErrors = _b.errors;
|
754
|
+
var handleChange = function handleChange(text) {
|
755
|
+
setFormValue(name, text);
|
756
|
+
};
|
757
|
+
return /*#__PURE__*/React.createElement(View, {
|
758
|
+
style: styles$1.container
|
759
|
+
}, /*#__PURE__*/React.createElement(Text, {
|
760
|
+
style: styles$1.label
|
761
|
+
}, label), /*#__PURE__*/React.createElement(TextInput, __assign({
|
762
|
+
style: [styles$1.textArea, style],
|
763
|
+
value: formValues[name] || '',
|
764
|
+
onChangeText: handleChange,
|
765
|
+
placeholder: label,
|
766
|
+
placeholderTextColor: "#888" // Can be themed if needed
|
767
|
+
,
|
768
|
+
multiline: true,
|
769
|
+
numberOfLines: 4,
|
770
|
+
textAlignVertical: "top"
|
771
|
+
}, rest)), formErrors[name] && formErrors[name].length > 0 && (/*#__PURE__*/React.createElement(ErrorList, {
|
772
|
+
errors: formErrors[name]
|
773
|
+
})));
|
774
|
+
};
|
775
|
+
var styles$1 = StyleSheet.create({
|
776
|
+
container: {
|
777
|
+
marginBottom: 16
|
778
|
+
},
|
779
|
+
label: {
|
780
|
+
marginBottom: 4,
|
781
|
+
color: '#000' // Should be themed
|
782
|
+
},
|
783
|
+
textArea: {
|
784
|
+
height: 100,
|
785
|
+
borderColor: '#CCC',
|
786
|
+
// Should be themed
|
787
|
+
borderWidth: 1,
|
788
|
+
borderRadius: 4,
|
789
|
+
paddingHorizontal: 8,
|
790
|
+
paddingVertical: 8,
|
791
|
+
backgroundColor: '#FFFFFF',
|
792
|
+
// Should use 'body' color from theme
|
793
|
+
color: '#000' // Should use 'text' color from theme
|
794
|
+
}
|
795
|
+
});
|
796
|
+
|
797
|
+
// src/forms/Label.tsx
|
798
|
+
var Label = function Label(_a) {
|
799
|
+
var text = _a.text,
|
800
|
+
style = _a.style;
|
801
|
+
return /*#__PURE__*/React.createElement(Text, {
|
802
|
+
style: [styles.label, style]
|
803
|
+
}, text);
|
804
|
+
};
|
805
|
+
var styles = StyleSheet.create({
|
806
|
+
label: {
|
807
|
+
marginBottom: 4,
|
808
|
+
color: '#000',
|
809
|
+
// Should be themed
|
810
|
+
fontWeight: '500'
|
811
|
+
}
|
812
|
+
});
|
813
|
+
|
814
|
+
export { Button, Card, ErrorList, Form, Input, Label, Text, TextArea, ThemeContext, ThemeProvider, ThemeToggle, useFormContext };
|
576
815
|
//# sourceMappingURL=index.esm.js.map
|