aport-tools 4.1.23 → 4.1.25

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! aport-tools v4.1.23 | ISC */
1
+ /*! aport-tools v4.1.25 | ISC */
2
2
  'use strict';
3
3
 
4
4
  var React = require('react');
@@ -365,173 +365,60 @@ var styles$6 = reactNative.StyleSheet.create({
365
365
  }
366
366
  });
367
367
 
368
- // src/components/Button.tsx
369
- /**
370
- * Determines the styles based on the button type and whether it is disabled.
371
- *
372
- * @param type - The type of the button ('submit', 'button', 'cancel').
373
- * @param disabled - Whether the button is disabled.
374
- * @param themeColors - The theme colors.
375
- * @returns The computed style for the button.
376
- */
377
- function typeStyles(type, disabled, themeColors) {
378
- switch (type) {
379
- case 'submit':
380
- return {
381
- backgroundColor: "rgba(".concat(themeColors === null || themeColors === void 0 ? void 0 : themeColors.primary.rgb.r, ", ").concat(themeColors === null || themeColors === void 0 ? void 0 : themeColors.primary.rgb.g, ", ").concat(themeColors === null || themeColors === void 0 ? void 0 : themeColors.primary.rgb.b, ", ").concat(disabled ? 0.5 : 1, ")"),
382
- borderWidth: 2,
383
- borderColor: themeColors === null || themeColors === void 0 ? void 0 : themeColors.primary.hex
384
- };
385
- case 'button':
386
- return {
387
- backgroundColor: themeColors === null || themeColors === void 0 ? void 0 : themeColors.primary.hex,
388
- borderColor: themeColors === null || themeColors === void 0 ? void 0 : themeColors.secondary.hex,
389
- opacity: disabled ? 0.5 : 1,
390
- borderWidth: 2
391
- };
392
- case 'cancel':
393
- return {
394
- backgroundColor: themeColors === null || themeColors === void 0 ? void 0 : themeColors.background.hex,
395
- borderWidth: 0
396
- };
397
- default:
398
- return {};
368
+ // src/forms/FormContext.tsx
369
+ var FormContext = /*#__PURE__*/React.createContext(undefined);
370
+ var useFormContext = function useFormContext() {
371
+ var context = React.useContext(FormContext);
372
+ if (!context) {
373
+ throw new Error("useFormContext must be used within a Form");
399
374
  }
400
- }
401
- /**
402
- * Button component that adapts its styles based on the current theme.
403
- * Supports dynamic styling, full-width option, rounded corners, and different types.
404
- *
405
- * @param disabled - If true, the button is disabled and not pressable.
406
- * @param isFullWidth - If true, the button expands to full width of its container.
407
- * @param children - Text content of the button.
408
- * @param onPress - Function to call when the button is pressed.
409
- * @param rounded - If true, the button has rounded corners.
410
- * @param borderRadius - Custom border radius value. Overrides the `rounded` prop if provided.
411
- * @param type - Specifies the button type for styling ('submit', 'button', 'cancel').
412
- */
413
- var Button = function Button(_a) {
414
- var children = _a.children,
415
- _b = _a.disabled,
416
- disabled = _b === void 0 ? false : _b,
417
- _c = _a.type,
418
- type = _c === void 0 ? 'button' : _c,
419
- _d = _a.rounded,
420
- rounded = _d === void 0 ? true : _d,
421
- _e = _a.borderRadius,
422
- borderRadius = _e === void 0 ? 30 : _e,
423
- _f = _a.isFullWidth,
424
- isFullWidth = _f === void 0 ? false : _f,
425
- _g = _a.loading,
426
- loading = _g === void 0 ? false : _g,
427
- onPress = _a.onPress;
428
- var theme = React.useContext(ThemeContext).theme;
429
- var colors = theme.colors;
430
- var computedStyles = React.useMemo(function () {
431
- return reactNative.StyleSheet.flatten([styles$5.button, typeStyles(type, disabled, colors), rounded && {
432
- borderRadius: borderRadius
433
- }, isFullWidth && {
434
- width: '100%'
435
- }, (disabled || loading) && styles$5.disabled]);
436
- }, [type, disabled, loading, rounded, borderRadius, isFullWidth, colors]);
437
- var textColor = React.useMemo(function () {
438
- return {
439
- color: colors.textButton.hex
440
- };
441
- }, [type, colors]);
442
- return /*#__PURE__*/React.createElement(reactNative.TouchableOpacity, {
443
- style: computedStyles,
444
- disabled: disabled || loading,
445
- onPress: onPress,
446
- activeOpacity: 0.7
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, {
454
- style: textColor
455
- }, Array.isArray(children) ? children.join('').toUpperCase() : children === null || children === void 0 ? void 0 : children.toUpperCase())));
375
+ return context;
456
376
  };
457
- var styles$5 = reactNative.StyleSheet.create({
458
- button: {
459
- justifyContent: 'center',
460
- alignItems: 'center',
461
- paddingVertical: 10,
462
- paddingHorizontal: 20
463
- },
464
- disabled: {
465
- opacity: 0.6
466
- }
467
- });
468
-
469
- // src/cards/Card.tsx
470
- /**
471
- * Card component that adapts its styles based on the current theme.
472
- * Supports dynamic styling, shadows, and press animations.
473
- *
474
- * @param children - The content to be displayed inside the Card.
475
- * @param style - Additional styles to apply to the Card.
476
- * @param onPress - Function to execute when the Card is pressed.
477
- * @param pressable - Determines if the Card is pressable. Defaults to false.
478
- * @param borderRadius - Border radius of the Card. Defaults to 12.
479
- * @param elevation - Elevation for Android shadow. Overrides default.
480
- * @param shadowProps - Custom shadow properties for iOS. Overrides defaults.
481
- */
482
- var Card = function Card(_a) {
377
+ var Form = function Form(_a) {
483
378
  var children = _a.children,
484
- style = _a.style,
485
- onPress = _a.onPress,
486
- _b = _a.pressable,
487
- pressable = _b === void 0 ? false : _b,
488
- _c = _a.borderRadius,
489
- borderRadius = _c === void 0 ? 12 : _c,
490
- _d = _a.elevation,
491
- elevation = _d === void 0 ? 4 : _d,
492
- _e = _a.shadowProps,
493
- shadowProps = _e === void 0 ? {} : _e;
494
- var theme = React.useContext(ThemeContext).theme;
495
- var colors = theme.colors;
496
- // Animation state for pressable effect
497
- // Default shadow styles (improved platform-specific handling)
498
- var defaultShadow = reactNative.Platform.select({
499
- ios: {
500
- shadowColor: (shadowProps === null || shadowProps === void 0 ? void 0 : shadowProps.shadowColor) || colors.text.hex,
501
- // Defaulting to theme text color
502
- shadowOffset: (shadowProps === null || shadowProps === void 0 ? void 0 : shadowProps.shadowOffset) || {
503
- width: 0,
504
- height: 2
505
- },
506
- shadowOpacity: (shadowProps === null || shadowProps === void 0 ? void 0 : shadowProps.shadowOpacity) || 0.1,
507
- shadowRadius: (shadowProps === null || shadowProps === void 0 ? void 0 : shadowProps.shadowRadius) || 4
508
- },
509
- android: {
510
- elevation: elevation // Only applies to Android
379
+ onSubmit = _a.onSubmit;
380
+ var _b = React.useState({}),
381
+ formValues = _b[0],
382
+ setFormValues = _b[1];
383
+ var _c = React.useState({}),
384
+ errors = _c[0],
385
+ setErrors = _c[1];
386
+ var setFormValue = function setFormValue(name, value) {
387
+ setFormValues(function (prev) {
388
+ var _a;
389
+ return __assign(__assign({}, prev), (_a = {}, _a[name] = value, _a));
390
+ });
391
+ };
392
+ var handleSubmit = function handleSubmit() {
393
+ return __awaiter(void 0, void 0, void 0, function () {
394
+ var validationErrors;
395
+ return __generator(this, function (_a) {
396
+ switch (_a.label) {
397
+ case 0:
398
+ return [4 /*yield*/, onSubmit(formValues)];
399
+ case 1:
400
+ validationErrors = _a.sent();
401
+ // Set the validation errors in state
402
+ setErrors(validationErrors);
403
+ // Prevent submission if there are any errors
404
+ if (Object.keys(validationErrors).length > 0) {
405
+ return [2 /*return*/]; // Prevent submission
406
+ }
407
+ return [2 /*return*/];
408
+ }
409
+ });
410
+ });
411
+ };
412
+ return /*#__PURE__*/React.createElement(FormContext.Provider, {
413
+ value: {
414
+ formValues: formValues,
415
+ setFormValue: setFormValue,
416
+ errors: errors,
417
+ setErrors: setErrors,
418
+ handleSubmit: handleSubmit
511
419
  }
512
- });
513
- var cardStyles = [styles$4.container, {
514
- borderRadius: borderRadius,
515
- backgroundColor: colors.body.hex
516
- }, defaultShadow,
517
- // Dynamic shadows based on platform
518
- style // External styles
519
- ];
520
- return pressable ? (/*#__PURE__*/React.createElement(reactNative.TouchableOpacity, {
521
- activeOpacity: 0.8,
522
- onPress: onPress,
523
- style: cardStyles
524
- }, children)) : (/*#__PURE__*/React.createElement(reactNative.View, {
525
- style: cardStyles
526
- }, children));
420
+ }, children);
527
421
  };
528
- var styles$4 = reactNative.StyleSheet.create({
529
- container: {
530
- padding: 16,
531
- borderRadius: 12
532
- // Shadows handled dynamically with platform logic
533
- }
534
- });
535
422
 
536
423
  // src/fonts/Text.tsx
537
424
  /**
@@ -597,83 +484,29 @@ reactNative.StyleSheet.create({
597
484
  // Define any default styles if needed
598
485
  });
599
486
 
600
- var FormContext = /*#__PURE__*/React.createContext(undefined);
601
- var useFormContext = function useFormContext() {
602
- var context = React.useContext(FormContext);
603
- if (!context) {
604
- throw new Error("useFormContext must be used within a Form");
605
- }
606
- return context;
607
- };
608
- var Form = function Form(_a) {
609
- var children = _a.children,
610
- onSubmit = _a.onSubmit;
611
- var _b = React.useState({}),
612
- formValues = _b[0],
613
- setFormValues = _b[1];
614
- var _c = React.useState({}),
615
- errors = _c[0],
616
- setErrors = _c[1];
617
- var setFormValue = function setFormValue(name, value) {
618
- setFormValues(function (prev) {
619
- var _a;
620
- return __assign(__assign({}, prev), (_a = {}, _a[name] = value, _a));
621
- });
622
- };
623
- var handleSubmit = function handleSubmit(event) {
624
- return __awaiter(void 0, void 0, void 0, function () {
625
- var validationErrors;
626
- return __generator(this, function (_a) {
627
- switch (_a.label) {
628
- case 0:
629
- event.preventDefault(); // Prevent native submission
630
- return [4 /*yield*/, onSubmit(formValues)];
631
- case 1:
632
- validationErrors = _a.sent();
633
- setErrors(validationErrors);
634
- if (Object.keys(validationErrors).length > 0) {
635
- return [2 /*return*/]; // Do not proceed if there are validation errors
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
- handleSubmit: handleSubmit
648
- }
649
- }, /*#__PURE__*/React.createElement("form", {
650
- onSubmit: handleSubmit
651
- }, children));
652
- };
653
-
654
487
  // src/forms/ErrorList.tsx
655
488
  var ErrorList = function ErrorList(_a) {
656
489
  var errors = _a.errors;
657
490
  var theme = React.useContext(ThemeContext).theme;
658
491
  var colors = theme.colors;
659
492
  return /*#__PURE__*/React.createElement(reactNative.View, {
660
- style: styles$3.container
493
+ style: styles$5.container
661
494
  }, errors.map(function (error, index) {
662
495
  return /*#__PURE__*/React.createElement(reactNative.View, {
663
496
  key: index,
664
- style: styles$3.errorItem
497
+ style: styles$5.errorItem
665
498
  }, /*#__PURE__*/React.createElement(Text, {
666
- style: [styles$3.bullet, {
499
+ style: [styles$5.bullet, {
667
500
  color: colors.error.hex
668
501
  }]
669
502
  }, "\u2022"), /*#__PURE__*/React.createElement(Text, {
670
- style: [styles$3.errorText, {
503
+ style: [styles$5.errorText, {
671
504
  color: colors.error.hex
672
505
  }]
673
506
  }, error));
674
507
  }));
675
508
  };
676
- var styles$3 = reactNative.StyleSheet.create({
509
+ var styles$5 = reactNative.StyleSheet.create({
677
510
  container: {
678
511
  marginTop: 4
679
512
  },
@@ -708,13 +541,13 @@ var Input = function Input(_a) {
708
541
  setFormValue(name, text);
709
542
  };
710
543
  return /*#__PURE__*/React.createElement(reactNative.View, {
711
- style: styles$2.container
544
+ style: styles$4.container
712
545
  }, /*#__PURE__*/React.createElement(Text, {
713
- style: [styles$2.label, {
546
+ style: [styles$4.label, {
714
547
  color: colors.text.hex
715
548
  }]
716
549
  }, label), /*#__PURE__*/React.createElement(reactNative.TextInput, __assign({
717
- style: [styles$2.input, {
550
+ style: [styles$4.input, {
718
551
  backgroundColor: colors.body.hex,
719
552
  borderColor: formErrors[name] ? colors.error.hex : '#CCC',
720
553
  color: colors.text.hex
@@ -727,7 +560,7 @@ var Input = function Input(_a) {
727
560
  errors: formErrors[name]
728
561
  })));
729
562
  };
730
- var styles$2 = reactNative.StyleSheet.create({
563
+ var styles$4 = reactNative.StyleSheet.create({
731
564
  container: {
732
565
  marginBottom: 16
733
566
  },
@@ -758,11 +591,11 @@ var TextArea = function TextArea(_a) {
758
591
  setFormValue(name, text);
759
592
  };
760
593
  return /*#__PURE__*/React.createElement(reactNative.View, {
761
- style: styles$1.container
594
+ style: styles$3.container
762
595
  }, /*#__PURE__*/React.createElement(Text, {
763
- style: styles$1.label
596
+ style: styles$3.label
764
597
  }, label), /*#__PURE__*/React.createElement(reactNative.TextInput, __assign({
765
- style: [styles$1.textArea, style],
598
+ style: [styles$3.textArea, style],
766
599
  value: formValues[name] || '',
767
600
  onChangeText: handleChange,
768
601
  placeholder: label,
@@ -775,7 +608,7 @@ var TextArea = function TextArea(_a) {
775
608
  errors: formErrors[name]
776
609
  })));
777
610
  };
778
- var styles$1 = reactNative.StyleSheet.create({
611
+ var styles$3 = reactNative.StyleSheet.create({
779
612
  container: {
780
613
  marginBottom: 16
781
614
  },
@@ -804,18 +637,194 @@ var Label = function Label(_a) {
804
637
  var theme = React.useContext(ThemeContext).theme;
805
638
  var colors = theme.colors;
806
639
  return /*#__PURE__*/React.createElement(Text, {
807
- style: [styles.label, style, {
640
+ style: [styles$2.label, style, {
808
641
  color: colors.text.hex
809
642
  }]
810
643
  }, text);
811
644
  };
812
- var styles = reactNative.StyleSheet.create({
645
+ var styles$2 = reactNative.StyleSheet.create({
813
646
  label: {
814
647
  marginBottom: 4,
815
648
  fontWeight: '500'
816
649
  }
817
650
  });
818
651
 
652
+ // src/components/Button.tsx
653
+ /**
654
+ * Determines the styles based on the button type and whether it is disabled.
655
+ *
656
+ * @param type - The type of the button ('submit', 'button', 'cancel').
657
+ * @param disabled - Whether the button is disabled.
658
+ * @param themeColors - The theme colors.
659
+ * @returns The computed style for the button.
660
+ */
661
+ function typeStyles(type, disabled, themeColors) {
662
+ switch (type) {
663
+ case 'submit':
664
+ return {
665
+ backgroundColor: "rgba(".concat(themeColors === null || themeColors === void 0 ? void 0 : themeColors.primary.rgb.r, ", ").concat(themeColors === null || themeColors === void 0 ? void 0 : themeColors.primary.rgb.g, ", ").concat(themeColors === null || themeColors === void 0 ? void 0 : themeColors.primary.rgb.b, ", ").concat(disabled ? 0.5 : 1, ")"),
666
+ borderWidth: 2,
667
+ borderColor: themeColors === null || themeColors === void 0 ? void 0 : themeColors.primary.hex
668
+ };
669
+ case 'button':
670
+ return {
671
+ backgroundColor: themeColors === null || themeColors === void 0 ? void 0 : themeColors.primary.hex,
672
+ borderColor: themeColors === null || themeColors === void 0 ? void 0 : themeColors.secondary.hex,
673
+ opacity: disabled ? 0.5 : 1,
674
+ borderWidth: 2
675
+ };
676
+ case 'cancel':
677
+ return {
678
+ backgroundColor: themeColors === null || themeColors === void 0 ? void 0 : themeColors.background.hex,
679
+ borderWidth: 0
680
+ };
681
+ default:
682
+ return {};
683
+ }
684
+ }
685
+ /**
686
+ * Button component that adapts its styles based on the current theme.
687
+ * Supports dynamic styling, full-width option, rounded corners, and different types.
688
+ *
689
+ * @param disabled - If true, the button is disabled and not pressable.
690
+ * @param isFullWidth - If true, the button expands to full width of its container.
691
+ * @param children - Text content of the button.
692
+ * @param onPress - Function to call when the button is pressed.
693
+ * @param rounded - If true, the button has rounded corners.
694
+ * @param borderRadius - Custom border radius value. Overrides the `rounded` prop if provided.
695
+ * @param type - Specifies the button type for styling ('submit', 'button', 'cancel').
696
+ */
697
+ var Button = function Button(_a) {
698
+ var children = _a.children,
699
+ _b = _a.disabled,
700
+ disabled = _b === void 0 ? false : _b,
701
+ _c = _a.type,
702
+ type = _c === void 0 ? 'button' : _c,
703
+ _d = _a.rounded,
704
+ rounded = _d === void 0 ? true : _d,
705
+ _e = _a.borderRadius,
706
+ borderRadius = _e === void 0 ? 30 : _e,
707
+ _f = _a.isFullWidth,
708
+ isFullWidth = _f === void 0 ? false : _f,
709
+ _g = _a.loading,
710
+ loading = _g === void 0 ? false : _g,
711
+ onPress = _a.onPress;
712
+ var theme = React.useContext(ThemeContext).theme;
713
+ var colors = theme.colors;
714
+ var handleSubmit = useFormContext().handleSubmit;
715
+ var computedStyles = React.useMemo(function () {
716
+ return reactNative.StyleSheet.flatten([styles$1.button, typeStyles(type, disabled, colors), rounded && {
717
+ borderRadius: borderRadius
718
+ }, isFullWidth && {
719
+ width: '100%'
720
+ }, (disabled || loading) && styles$1.disabled]);
721
+ }, [type, disabled, loading, rounded, borderRadius, isFullWidth, colors]);
722
+ var textColor = React.useMemo(function () {
723
+ return {
724
+ color: colors.textButton.hex
725
+ };
726
+ }, [type, colors]);
727
+ var handlePress = function handlePress() {
728
+ if (type === 'submit') {
729
+ handleSubmit(); // Call the form's submit handler
730
+ } else if (onPress) {
731
+ onPress(); // Call a custom handler if needed
732
+ }
733
+ };
734
+ return /*#__PURE__*/React.createElement(reactNative.TouchableOpacity, {
735
+ style: computedStyles,
736
+ disabled: disabled || loading,
737
+ onPress: handlePress,
738
+ activeOpacity: 0.7
739
+ }, loading ? (
740
+ /*#__PURE__*/
741
+ // Show loading spinner if loading
742
+ React.createElement(reactNative.ActivityIndicator, {
743
+ size: "small",
744
+ color: colors.textButton.hex
745
+ })) : (/*#__PURE__*/React.createElement(reactNative.Text, {
746
+ style: textColor
747
+ }, Array.isArray(children) ? children.join('').toUpperCase() : children === null || children === void 0 ? void 0 : children.toUpperCase())));
748
+ };
749
+ var styles$1 = reactNative.StyleSheet.create({
750
+ button: {
751
+ justifyContent: 'center',
752
+ alignItems: 'center',
753
+ paddingVertical: 10,
754
+ paddingHorizontal: 20
755
+ },
756
+ disabled: {
757
+ opacity: 0.6
758
+ }
759
+ });
760
+
761
+ // src/cards/Card.tsx
762
+ /**
763
+ * Card component that adapts its styles based on the current theme.
764
+ * Supports dynamic styling, shadows, and press animations.
765
+ *
766
+ * @param children - The content to be displayed inside the Card.
767
+ * @param style - Additional styles to apply to the Card.
768
+ * @param onPress - Function to execute when the Card is pressed.
769
+ * @param pressable - Determines if the Card is pressable. Defaults to false.
770
+ * @param borderRadius - Border radius of the Card. Defaults to 12.
771
+ * @param elevation - Elevation for Android shadow. Overrides default.
772
+ * @param shadowProps - Custom shadow properties for iOS. Overrides defaults.
773
+ */
774
+ var Card = function Card(_a) {
775
+ var children = _a.children,
776
+ style = _a.style,
777
+ onPress = _a.onPress,
778
+ _b = _a.pressable,
779
+ pressable = _b === void 0 ? false : _b,
780
+ _c = _a.borderRadius,
781
+ borderRadius = _c === void 0 ? 12 : _c,
782
+ _d = _a.elevation,
783
+ elevation = _d === void 0 ? 4 : _d,
784
+ _e = _a.shadowProps,
785
+ shadowProps = _e === void 0 ? {} : _e;
786
+ var theme = React.useContext(ThemeContext).theme;
787
+ var colors = theme.colors;
788
+ // Animation state for pressable effect
789
+ // Default shadow styles (improved platform-specific handling)
790
+ var defaultShadow = reactNative.Platform.select({
791
+ ios: {
792
+ shadowColor: (shadowProps === null || shadowProps === void 0 ? void 0 : shadowProps.shadowColor) || colors.text.hex,
793
+ // Defaulting to theme text color
794
+ shadowOffset: (shadowProps === null || shadowProps === void 0 ? void 0 : shadowProps.shadowOffset) || {
795
+ width: 0,
796
+ height: 2
797
+ },
798
+ shadowOpacity: (shadowProps === null || shadowProps === void 0 ? void 0 : shadowProps.shadowOpacity) || 0.1,
799
+ shadowRadius: (shadowProps === null || shadowProps === void 0 ? void 0 : shadowProps.shadowRadius) || 4
800
+ },
801
+ android: {
802
+ elevation: elevation // Only applies to Android
803
+ }
804
+ });
805
+ var cardStyles = [styles.container, {
806
+ borderRadius: borderRadius,
807
+ backgroundColor: colors.body.hex
808
+ }, defaultShadow,
809
+ // Dynamic shadows based on platform
810
+ style // External styles
811
+ ];
812
+ return pressable ? (/*#__PURE__*/React.createElement(reactNative.TouchableOpacity, {
813
+ activeOpacity: 0.8,
814
+ onPress: onPress,
815
+ style: cardStyles
816
+ }, children)) : (/*#__PURE__*/React.createElement(reactNative.View, {
817
+ style: cardStyles
818
+ }, children));
819
+ };
820
+ var styles = reactNative.StyleSheet.create({
821
+ container: {
822
+ padding: 16,
823
+ borderRadius: 12
824
+ // Shadows handled dynamically with platform logic
825
+ }
826
+ });
827
+
819
828
  exports.Button = Button;
820
829
  exports.Card = Card;
821
830
  exports.ErrorList = ErrorList;