aport-tools 4.1.1 → 4.1.21

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.1 | ISC */
1
+ /*! aport-tools v4.1.21 | 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',
@@ -399,16 +422,18 @@ var Button = function Button(_a) {
399
422
  borderRadius = _e === void 0 ? 30 : _e,
400
423
  _f = _a.isFullWidth,
401
424
  isFullWidth = _f === void 0 ? false : _f,
425
+ _g = _a.loading,
426
+ loading = _g === void 0 ? false : _g,
402
427
  onPress = _a.onPress;
403
428
  var theme = React.useContext(ThemeContext).theme;
404
429
  var colors = theme.colors;
405
430
  var computedStyles = React.useMemo(function () {
406
- 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 && {
407
432
  borderRadius: borderRadius
408
433
  }, isFullWidth && {
409
434
  width: '100%'
410
- }, disabled && styles$1.disabled]);
411
- }, [type, disabled, rounded, borderRadius, isFullWidth, colors]);
435
+ }, (disabled || loading) && styles$5.disabled]);
436
+ }, [type, disabled, loading, rounded, borderRadius, isFullWidth, colors]);
412
437
  var textColor = React.useMemo(function () {
413
438
  return {
414
439
  color: colors.textButton.hex
@@ -416,14 +441,20 @@ var Button = function Button(_a) {
416
441
  }, [type, colors]);
417
442
  return /*#__PURE__*/React.createElement(reactNative.TouchableOpacity, {
418
443
  style: computedStyles,
419
- disabled: disabled,
444
+ disabled: disabled || loading,
420
445
  onPress: onPress,
421
446
  activeOpacity: 0.7
422
- }, /*#__PURE__*/React.createElement(reactNative.Text, {
447
+ }, loading ? (
448
+ /*#__PURE__*/
449
+ // Show loading spinner if loading
450
+ React.createElement(reactNative.ActivityIndicator, {
451
+ size: "small",
452
+ color: colors.textButton.hex
453
+ })) : (/*#__PURE__*/React.createElement(reactNative.Text, {
423
454
  style: textColor
424
- }, Array.isArray(children) ? children.join('').toUpperCase() : children === null || children === void 0 ? void 0 : children.toUpperCase()));
455
+ }, Array.isArray(children) ? children.join('').toUpperCase() : children === null || children === void 0 ? void 0 : children.toUpperCase())));
425
456
  };
426
- var styles$1 = reactNative.StyleSheet.create({
457
+ var styles$5 = reactNative.StyleSheet.create({
427
458
  button: {
428
459
  justifyContent: 'center',
429
460
  alignItems: 'center',
@@ -479,7 +510,7 @@ var Card = function Card(_a) {
479
510
  elevation: elevation // Only applies to Android
480
511
  }
481
512
  });
482
- var cardStyles = [styles.container, {
513
+ var cardStyles = [styles$4.container, {
483
514
  borderRadius: borderRadius,
484
515
  backgroundColor: colors.body.hex
485
516
  }, defaultShadow,
@@ -494,7 +525,7 @@ var Card = function Card(_a) {
494
525
  style: cardStyles
495
526
  }, children));
496
527
  };
497
- var styles = reactNative.StyleSheet.create({
528
+ var styles$4 = reactNative.StyleSheet.create({
498
529
  container: {
499
530
  padding: 16,
500
531
  borderRadius: 12
@@ -566,10 +597,227 @@ reactNative.StyleSheet.create({
566
597
  // Define any default styles if needed
567
598
  });
568
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
+ setErrors(validationErrors);
634
+ return [2 /*return*/];
635
+ }
636
+ });
637
+ });
638
+ };
639
+ return /*#__PURE__*/React.createElement(FormContext.Provider, {
640
+ value: {
641
+ formValues: formValues,
642
+ setFormValue: setFormValue,
643
+ errors: errors,
644
+ setErrors: setErrors,
645
+ handleSubmit: handleSubmit
646
+ }
647
+ }, children);
648
+ };
649
+
650
+ // src/forms/ErrorList.tsx
651
+ var ErrorList = function ErrorList(_a) {
652
+ var errors = _a.errors;
653
+ return /*#__PURE__*/React.createElement(reactNative.View, {
654
+ style: styles$3.container
655
+ }, errors.map(function (error, index) {
656
+ return /*#__PURE__*/React.createElement(reactNative.View, {
657
+ key: index,
658
+ style: styles$3.errorItem
659
+ }, /*#__PURE__*/React.createElement(Text, {
660
+ style: styles$3.bullet
661
+ }, "\u2022"), /*#__PURE__*/React.createElement(Text, {
662
+ style: styles$3.errorText
663
+ }, error));
664
+ }));
665
+ };
666
+ var styles$3 = reactNative.StyleSheet.create({
667
+ container: {
668
+ marginTop: 4
669
+ },
670
+ errorItem: {
671
+ flexDirection: 'row',
672
+ alignItems: 'flex-start',
673
+ marginBottom: 2
674
+ },
675
+ bullet: {
676
+ marginRight: 4,
677
+ color: '#FF5252',
678
+ // Should use 'error' color from theme
679
+ fontSize: 12
680
+ },
681
+ errorText: {
682
+ flex: 1,
683
+ color: '#FF5252',
684
+ // Should use 'error' color from theme
685
+ fontSize: 12
686
+ }
687
+ });
688
+
689
+ // src/forms/Input.tsx
690
+ var Input = function Input(_a) {
691
+ var name = _a.name,
692
+ label = _a.label,
693
+ style = _a.style,
694
+ rest = __rest(_a, ["name", "label", "style"]);
695
+ var _b = useFormContext(),
696
+ formValues = _b.formValues,
697
+ setFormValue = _b.setFormValue,
698
+ formErrors = _b.errors;
699
+ var theme = React.useContext(ThemeContext).theme;
700
+ var colors = theme.colors;
701
+ var handleChange = function handleChange(text) {
702
+ setFormValue(name, text);
703
+ };
704
+ return /*#__PURE__*/React.createElement(reactNative.View, {
705
+ style: styles$2.container
706
+ }, /*#__PURE__*/React.createElement(Text, {
707
+ style: [styles$2.label, {
708
+ color: colors.text.hex
709
+ }]
710
+ }, label), /*#__PURE__*/React.createElement(reactNative.TextInput, __assign({
711
+ style: [styles$2.input, {
712
+ backgroundColor: colors.body.hex,
713
+ borderColor: formErrors[name] ? colors.error.hex : '#CCC',
714
+ color: colors.text.hex
715
+ }, style],
716
+ value: formValues[name] || '',
717
+ onChangeText: handleChange,
718
+ placeholder: label,
719
+ placeholderTextColor: colors.text.hex
720
+ }, rest)), formErrors[name] && formErrors[name].length > 0 && (/*#__PURE__*/React.createElement(ErrorList, {
721
+ errors: formErrors[name]
722
+ })));
723
+ };
724
+ var styles$2 = reactNative.StyleSheet.create({
725
+ container: {
726
+ marginBottom: 16
727
+ },
728
+ label: {
729
+ marginBottom: 4,
730
+ fontSize: 14
731
+ },
732
+ input: {
733
+ height: 40,
734
+ borderWidth: 1,
735
+ borderRadius: 4,
736
+ paddingHorizontal: 8
737
+ }
738
+ });
739
+
740
+ // src/forms/TextArea.tsx
741
+ var TextArea = function TextArea(_a) {
742
+ var name = _a.name,
743
+ label = _a.label;
744
+ _a.errors;
745
+ var style = _a.style,
746
+ rest = __rest(_a, ["name", "label", "errors", "style"]);
747
+ var _b = useFormContext(),
748
+ formValues = _b.formValues,
749
+ setFormValue = _b.setFormValue,
750
+ formErrors = _b.errors;
751
+ var handleChange = function handleChange(text) {
752
+ setFormValue(name, text);
753
+ };
754
+ return /*#__PURE__*/React.createElement(reactNative.View, {
755
+ style: styles$1.container
756
+ }, /*#__PURE__*/React.createElement(Text, {
757
+ style: styles$1.label
758
+ }, label), /*#__PURE__*/React.createElement(reactNative.TextInput, __assign({
759
+ style: [styles$1.textArea, style],
760
+ value: formValues[name] || '',
761
+ onChangeText: handleChange,
762
+ placeholder: label,
763
+ placeholderTextColor: "#888" // Can be themed if needed
764
+ ,
765
+ multiline: true,
766
+ numberOfLines: 4,
767
+ textAlignVertical: "top"
768
+ }, rest)), formErrors[name] && formErrors[name].length > 0 && (/*#__PURE__*/React.createElement(ErrorList, {
769
+ errors: formErrors[name]
770
+ })));
771
+ };
772
+ var styles$1 = reactNative.StyleSheet.create({
773
+ container: {
774
+ marginBottom: 16
775
+ },
776
+ label: {
777
+ marginBottom: 4,
778
+ color: '#000' // Should be themed
779
+ },
780
+ textArea: {
781
+ height: 100,
782
+ borderColor: '#CCC',
783
+ // Should be themed
784
+ borderWidth: 1,
785
+ borderRadius: 4,
786
+ paddingHorizontal: 8,
787
+ paddingVertical: 8,
788
+ backgroundColor: '#FFFFFF',
789
+ // Should use 'body' color from theme
790
+ color: '#000' // Should use 'text' color from theme
791
+ }
792
+ });
793
+
794
+ // src/forms/Label.tsx
795
+ var Label = function Label(_a) {
796
+ var text = _a.text,
797
+ style = _a.style;
798
+ return /*#__PURE__*/React.createElement(Text, {
799
+ style: [styles.label, style]
800
+ }, text);
801
+ };
802
+ var styles = reactNative.StyleSheet.create({
803
+ label: {
804
+ marginBottom: 4,
805
+ color: '#000',
806
+ // Should be themed
807
+ fontWeight: '500'
808
+ }
809
+ });
810
+
569
811
  exports.Button = Button;
570
812
  exports.Card = Card;
813
+ exports.ErrorList = ErrorList;
814
+ exports.Form = Form;
815
+ exports.Input = Input;
816
+ exports.Label = Label;
571
817
  exports.Text = Text;
818
+ exports.TextArea = TextArea;
572
819
  exports.ThemeContext = ThemeContext;
573
820
  exports.ThemeProvider = ThemeProvider;
574
821
  exports.ThemeToggle = ThemeToggle;
822
+ exports.useFormContext = useFormContext;
575
823
  //# sourceMappingURL=index.js.map