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