aport-tools 4.2.6 → 4.2.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,10 @@
1
+ import React from "react";
2
+ interface InputAttachProps {
3
+ name: string;
4
+ type?: string[];
5
+ amount?: number;
6
+ disabled?: boolean;
7
+ placeholder?: string;
8
+ }
9
+ declare const InputAttach: React.FC<InputAttachProps>;
10
+ export default InputAttach;
@@ -4,3 +4,4 @@ export { default as TextArea } from './TextArea';
4
4
  export { default as Label } from './Label';
5
5
  export { default as ErrorList } from './ErrorList';
6
6
  export { InputList } from './InputList';
7
+ export { default as InputAttach } from './InputAttach';
package/dist/index.esm.js CHANGED
@@ -1,7 +1,8 @@
1
- /*! aport-tools v4.2.6 | ISC */
1
+ /*! aport-tools v4.2.8 | ISC */
2
2
  import React, { useContext, useState, createContext, useCallback, useMemo } from 'react';
3
- import { StyleSheet, Text as Text$1, View, TextInput, TouchableOpacity, Modal, Pressable, FlatList, Keyboard, ActivityIndicator, Platform } from 'react-native';
3
+ import { StyleSheet, Text as Text$1, View, TextInput, TouchableOpacity, Modal, Pressable, FlatList, Keyboard, Image, Alert, ActivityIndicator, Platform } from 'react-native';
4
4
  import { ThemeContext } from 'aport-themes';
5
+ import * as ImagePicker from 'expo-image-picker';
5
6
 
6
7
  /******************************************************************************
7
8
  Copyright (c) Microsoft Corporation.
@@ -230,23 +231,23 @@ var ErrorList = function ErrorList(_a) {
230
231
  var theme = useContext(ThemeContext).theme;
231
232
  var colors = theme.colors;
232
233
  return /*#__PURE__*/React.createElement(View, {
233
- style: styles$6.container
234
+ style: styles$7.container
234
235
  }, errors.map(function (error, index) {
235
236
  return /*#__PURE__*/React.createElement(View, {
236
237
  key: index,
237
- style: styles$6.errorItem
238
+ style: styles$7.errorItem
238
239
  }, /*#__PURE__*/React.createElement(Text, {
239
- style: [styles$6.bullet, {
240
+ style: [styles$7.bullet, {
240
241
  color: colors.error.hex
241
242
  }]
242
243
  }, "\u2022"), /*#__PURE__*/React.createElement(Text, {
243
- style: [styles$6.errorText, {
244
+ style: [styles$7.errorText, {
244
245
  color: colors.error.hex
245
246
  }]
246
247
  }, error));
247
248
  }));
248
249
  };
249
- var styles$6 = StyleSheet.create({
250
+ var styles$7 = StyleSheet.create({
250
251
  container: {
251
252
  marginTop: 4
252
253
  },
@@ -324,13 +325,13 @@ var Input = function Input(_a) {
324
325
  setFormValue(name, formattedText);
325
326
  };
326
327
  return /*#__PURE__*/React.createElement(View, {
327
- style: styles$5.container
328
+ style: styles$6.container
328
329
  }, /*#__PURE__*/React.createElement(Text, {
329
- style: [styles$5.label, {
330
+ style: [styles$6.label, {
330
331
  color: colors.text.hex
331
332
  }]
332
333
  }, label), /*#__PURE__*/React.createElement(TextInput, __assign({
333
- style: [styles$5.input, {
334
+ style: [styles$6.input, {
334
335
  backgroundColor: colors.body.hex,
335
336
  borderColor: formErrors[name] ? colors.error.hex : "#CCC",
336
337
  color: colors.text.hex
@@ -343,7 +344,7 @@ var Input = function Input(_a) {
343
344
  errors: formErrors[name]
344
345
  })));
345
346
  };
346
- var styles$5 = StyleSheet.create({
347
+ var styles$6 = StyleSheet.create({
347
348
  container: {
348
349
  marginBottom: 16
349
350
  },
@@ -374,11 +375,11 @@ var TextArea = function TextArea(_a) {
374
375
  setFormValue(name, text);
375
376
  };
376
377
  return /*#__PURE__*/React.createElement(View, {
377
- style: styles$4.container
378
+ style: styles$5.container
378
379
  }, /*#__PURE__*/React.createElement(Text, {
379
- style: styles$4.label
380
+ style: styles$5.label
380
381
  }, label), /*#__PURE__*/React.createElement(TextInput, __assign({
381
- style: [styles$4.textArea, style],
382
+ style: [styles$5.textArea, style],
382
383
  value: formValues[name] || '',
383
384
  onChangeText: handleChange,
384
385
  placeholder: label,
@@ -391,7 +392,7 @@ var TextArea = function TextArea(_a) {
391
392
  errors: formErrors[name]
392
393
  })));
393
394
  };
394
- var styles$4 = StyleSheet.create({
395
+ var styles$5 = StyleSheet.create({
395
396
  container: {
396
397
  marginBottom: 16
397
398
  },
@@ -420,12 +421,12 @@ var Label = function Label(_a) {
420
421
  var theme = useContext(ThemeContext).theme;
421
422
  var colors = theme.colors;
422
423
  return /*#__PURE__*/React.createElement(Text, {
423
- style: [styles$3.label, style, {
424
+ style: [styles$4.label, style, {
424
425
  color: colors.text.hex
425
426
  }]
426
427
  }, text);
427
428
  };
428
- var styles$3 = StyleSheet.create({
429
+ var styles$4 = StyleSheet.create({
429
430
  label: {
430
431
  marginBottom: 4,
431
432
  fontWeight: '500'
@@ -538,9 +539,9 @@ var InputList = function InputList(_a) {
538
539
  });
539
540
  };
540
541
  return /*#__PURE__*/React.createElement(View, {
541
- style: [styles$2.container, style]
542
+ style: [styles$3.container, style]
542
543
  }, /*#__PURE__*/React.createElement(TouchableOpacity, {
543
- style: styles$2.inputContainer,
544
+ style: styles$3.inputContainer,
544
545
  onPress: toggleDropdown,
545
546
  disabled: disabled
546
547
  }, /*#__PURE__*/React.createElement(Text$1, {
@@ -552,10 +553,10 @@ var InputList = function InputList(_a) {
552
553
  transparent: true,
553
554
  animationType: "fade"
554
555
  }, /*#__PURE__*/React.createElement(Pressable, {
555
- style: styles$2.overlay,
556
+ style: styles$3.overlay,
556
557
  onPress: handleCloseDropdown
557
558
  }), /*#__PURE__*/React.createElement(View, {
558
- style: [styles$2.dropdownContainer, {
559
+ style: [styles$3.dropdownContainer, {
559
560
  backgroundColor: colors.body.hex
560
561
  }]
561
562
  }, /*#__PURE__*/React.createElement(FlatList, {
@@ -573,7 +574,7 @@ var InputList = function InputList(_a) {
573
574
  onPress: function onPress() {
574
575
  return handleSelectOption(item);
575
576
  },
576
- style: [styles$2.optionItem, isSelected ? {
577
+ style: [styles$3.optionItem, isSelected ? {
577
578
  backgroundColor: colors.primary.hex
578
579
  } : {}, isDisabled ? {
579
580
  backgroundColor: colors.placeHolder.hex
@@ -584,18 +585,18 @@ var InputList = function InputList(_a) {
584
585
  color: colors.background.hex
585
586
  } : {
586
587
  color: colors.text.hex
587
- }, isDisabled ? styles$2.disabledText : {}]
588
+ }, isDisabled ? styles$3.disabledText : {}]
588
589
  }, item.label));
589
590
  },
590
591
  ItemSeparatorComponent: function ItemSeparatorComponent() {
591
592
  return separator ? /*#__PURE__*/React.createElement(View, {
592
- style: styles$2.separator
593
+ style: styles$3.separator
593
594
  }) : null;
594
595
  },
595
596
  scrollEnabled: !closeOnScroll
596
597
  }))));
597
598
  };
598
- var styles$2 = StyleSheet.create({
599
+ var styles$3 = StyleSheet.create({
599
600
  container: {
600
601
  padding: 8
601
602
  },
@@ -633,6 +634,181 @@ var styles$2 = StyleSheet.create({
633
634
  }
634
635
  });
635
636
 
637
+ // src/components/InputAttach.tsx
638
+ var InputAttach = function InputAttach(_a) {
639
+ var name = _a.name,
640
+ _b = _a.type,
641
+ type = _b === void 0 ? ["png", "jpg", "jpeg"] : _b,
642
+ _c = _a.amount,
643
+ amount = _c === void 0 ? 1 : _c,
644
+ _d = _a.disabled,
645
+ disabled = _d === void 0 ? false : _d,
646
+ _e = _a.placeholder,
647
+ placeholder = _e === void 0 ? "Upload an image" : _e;
648
+ var _f = useFormContext(),
649
+ setFormValue = _f.setFormValue;
650
+ _f.formValues;
651
+ var errors = _f.errors;
652
+ var _g = useState([]),
653
+ selectedFiles = _g[0],
654
+ setSelectedFiles = _g[1];
655
+ var theme = useContext(ThemeContext).theme;
656
+ var colors = theme.colors;
657
+ var pickImage = function pickImage() {
658
+ return __awaiter(void 0, void 0, void 0, function () {
659
+ var permissionResult, result, selectedAssets, newFiles, invalidFiles, updatedFiles;
660
+ return __generator(this, function (_a) {
661
+ switch (_a.label) {
662
+ case 0:
663
+ if (disabled) return [2 /*return*/];
664
+ return [4 /*yield*/, ImagePicker.requestMediaLibraryPermissionsAsync()];
665
+ case 1:
666
+ permissionResult = _a.sent();
667
+ if (!permissionResult.granted) {
668
+ Alert.alert("Permission Required", "We need access to your photos to upload images.");
669
+ return [2 /*return*/];
670
+ }
671
+ return [4 /*yield*/, ImagePicker.launchImageLibraryAsync({
672
+ mediaTypes: ImagePicker.MediaTypeOptions.Images,
673
+ allowsMultipleSelection: amount > 1,
674
+ quality: 1
675
+ })];
676
+ case 2:
677
+ result = _a.sent();
678
+ if (!result.canceled) {
679
+ selectedAssets = result.assets || [result];
680
+ newFiles = selectedAssets.map(function (asset) {
681
+ return {
682
+ uri: asset.uri,
683
+ name: asset.fileName || "unknown.jpg",
684
+ type: asset.mimeType || "image/jpeg"
685
+ };
686
+ });
687
+ invalidFiles = newFiles.filter(function (file) {
688
+ return !type.some(function (ext) {
689
+ return file.name.toLowerCase().endsWith(ext);
690
+ });
691
+ });
692
+ if (invalidFiles.length > 0) {
693
+ Alert.alert("Invalid File Type", "Please upload files of type: ".concat(type.join(", ")));
694
+ return [2 /*return*/];
695
+ }
696
+ // Check max amount
697
+ if (selectedFiles.length + newFiles.length > amount) {
698
+ Alert.alert("Limit Exceeded", "You can upload up to ".concat(amount, " files."));
699
+ return [2 /*return*/];
700
+ }
701
+ updatedFiles = __spreadArray(__spreadArray([], selectedFiles, true), newFiles, true).slice(0, amount);
702
+ setSelectedFiles(updatedFiles);
703
+ setFormValue(name, updatedFiles); // Update form context
704
+ }
705
+ return [2 /*return*/];
706
+ }
707
+ });
708
+ });
709
+ };
710
+ var removeFile = function removeFile(index) {
711
+ var updatedFiles = selectedFiles.filter(function (_, i) {
712
+ return i !== index;
713
+ });
714
+ setSelectedFiles(updatedFiles);
715
+ setFormValue(name, updatedFiles); // Update form context
716
+ };
717
+ return /*#__PURE__*/React.createElement(View, {
718
+ style: styles$2.container
719
+ }, /*#__PURE__*/React.createElement(Text, {
720
+ style: [styles$2.label, {
721
+ color: colors.text.hex
722
+ }]
723
+ }, placeholder), /*#__PURE__*/React.createElement(View, {
724
+ style: styles$2.fileContainer
725
+ }, selectedFiles.map(function (file, index) {
726
+ return /*#__PURE__*/React.createElement(View, {
727
+ key: index,
728
+ style: styles$2.fileItem
729
+ }, /*#__PURE__*/React.createElement(Image, {
730
+ source: {
731
+ uri: file.uri
732
+ },
733
+ style: styles$2.imagePreview
734
+ }), /*#__PURE__*/React.createElement(TouchableOpacity, {
735
+ onPress: function onPress() {
736
+ return removeFile(index);
737
+ },
738
+ style: [styles$2.removeButton, {
739
+ backgroundColor: colors.error.hex
740
+ }]
741
+ }, /*#__PURE__*/React.createElement(Text, {
742
+ style: styles$2.removeButtonText
743
+ }, "X")));
744
+ }), selectedFiles.length < amount && (/*#__PURE__*/React.createElement(TouchableOpacity, {
745
+ onPress: pickImage,
746
+ style: [styles$2.addButton, {
747
+ backgroundColor: colors.body.hex
748
+ }],
749
+ disabled: disabled
750
+ }, /*#__PURE__*/React.createElement(Text, {
751
+ style: [styles$2.addButtonText, {
752
+ color: colors.placeHolder.hex
753
+ }]
754
+ }, "+")))), errors[name] && /*#__PURE__*/React.createElement(Text, {
755
+ style: [styles$2.error, {
756
+ color: colors.error.hex
757
+ }]
758
+ }, errors[name].join(", ")));
759
+ };
760
+ var styles$2 = StyleSheet.create({
761
+ container: {
762
+ marginVertical: 10
763
+ },
764
+ label: {
765
+ marginBottom: 5
766
+ },
767
+ fileContainer: {
768
+ flexDirection: "row",
769
+ flexWrap: "wrap",
770
+ gap: 10
771
+ },
772
+ fileItem: {
773
+ position: "relative",
774
+ width: 100,
775
+ height: 100,
776
+ marginRight: 10
777
+ },
778
+ imagePreview: {
779
+ width: "100%",
780
+ height: "100%",
781
+ borderRadius: 5
782
+ },
783
+ removeButton: {
784
+ position: "absolute",
785
+ top: 0,
786
+ right: 0,
787
+ width: 20,
788
+ height: 20,
789
+ justifyContent: "center",
790
+ alignItems: "center",
791
+ borderRadius: 10
792
+ },
793
+ removeButtonText: {
794
+ color: "#fff",
795
+ fontWeight: "bold"
796
+ },
797
+ addButton: {
798
+ width: 100,
799
+ height: 100,
800
+ justifyContent: "center",
801
+ alignItems: "center",
802
+ borderRadius: 5
803
+ },
804
+ addButtonText: {
805
+ fontSize: 24
806
+ },
807
+ error: {
808
+ marginTop: 5
809
+ }
810
+ });
811
+
636
812
  // src/components/Button.tsx
637
813
  /**
638
814
  * Determines the styles based on the button type and whether it is disabled.
@@ -811,5 +987,5 @@ var styles = StyleSheet.create({
811
987
  }
812
988
  });
813
989
 
814
- export { Button, Card, ErrorList, Form, Input, InputList, Label, Text, TextArea, useFormContext };
990
+ export { Button, Card, ErrorList, Form, Input, InputAttach, InputList, Label, Text, TextArea, useFormContext };
815
991
  //# sourceMappingURL=index.esm.js.map