aport-tools 4.4.26 → 4.4.28

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.
@@ -1,17 +1,19 @@
1
1
  import React from "react";
2
+ interface InputOption {
3
+ id: string;
4
+ label?: string;
5
+ icon?: string;
6
+ value: string;
7
+ }
2
8
  interface InputCheckProps {
3
9
  name: string;
4
- options: {
5
- id: string;
6
- label: string;
7
- icon?: string;
8
- value: string;
9
- }[];
10
+ options: InputOption[];
10
11
  multi?: boolean;
11
12
  max?: number;
12
13
  rowAmount?: number;
13
14
  iconPosition?: "row" | "column";
14
15
  disabled?: boolean;
16
+ firstValue?: InputOption[];
15
17
  }
16
18
  declare const InputCheck: React.FC<InputCheckProps>;
17
19
  export default InputCheck;
package/dist/index.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! aport-tools v4.4.26 | ISC */
1
+ /*! aport-tools v4.4.28 | ISC */
2
2
  import React, { useContext, useState, createContext, useRef, useEffect, useMemo, useCallback } from 'react';
3
3
  import { StyleSheet, Text as Text$1, Animated, View, TouchableOpacity, Image, TextInput, Modal, Pressable, FlatList, Keyboard, Platform, Alert, ActivityIndicator } from 'react-native';
4
4
  import { ThemeContext } from 'aport-themes';
@@ -1015,19 +1015,34 @@ var InputCheck = function InputCheck(_a) {
1015
1015
  max = _a.max,
1016
1016
  _c = _a.rowAmount,
1017
1017
  rowAmount = _c === void 0 ? 3 : _c,
1018
+ firstValue = _a.firstValue,
1018
1019
  _d = _a.iconPosition,
1019
1020
  iconPosition = _d === void 0 ? "row" : _d,
1020
1021
  _e = _a.disabled,
1021
1022
  disabled = _e === void 0 ? false : _e;
1022
- var _f = useFormContext(),
1023
- formValues = _f.formValues,
1024
- setFormValue = _f.setFormValue,
1023
+ var _f = useFormContext();
1024
+ _f.formValues;
1025
+ var setFormValue = _f.setFormValue,
1025
1026
  formErrors = _f.errors;
1026
- var _g = useState(formValues[name] || []),
1027
+ var _g = useState([]),
1027
1028
  selectedValues = _g[0],
1028
1029
  setSelectedValues = _g[1];
1029
1030
  var theme = useContext(ThemeContext).theme;
1030
1031
  var colors = theme.colors;
1032
+ var isFirstRender = useRef(true);
1033
+ // Initialize selectedValues on first render if firstValue is provided
1034
+ useEffect(function () {
1035
+ if (isFirstRender.current && firstValue) {
1036
+ var initialSelectedValues = options.filter(function (option) {
1037
+ return firstValue.some(function (fv) {
1038
+ return fv.value === option.value;
1039
+ });
1040
+ });
1041
+ setSelectedValues(initialSelectedValues);
1042
+ setFormValue(name, initialSelectedValues); // Update form context
1043
+ isFirstRender.current = false; // Prevent subsequent updates
1044
+ }
1045
+ }, [firstValue, name, options, setFormValue]);
1031
1046
  var handleSelect = function handleSelect(id, value) {
1032
1047
  if (disabled) return;
1033
1048
  var updatedSelection;
@@ -1075,11 +1090,11 @@ var InputCheck = function InputCheck(_a) {
1075
1090
  uri: item.icon
1076
1091
  },
1077
1092
  style: [styles$2.icon, iconPosition === "column" && styles$2.iconColumn]
1078
- })), /*#__PURE__*/React.createElement(Text, {
1093
+ })), item.label && (/*#__PURE__*/React.createElement(Text, {
1079
1094
  style: [styles$2.label, {
1080
1095
  color: isSelected ? colors.textButton.hex : colors.text.hex
1081
1096
  }]
1082
- }, item.label));
1097
+ }, item.label)));
1083
1098
  };
1084
1099
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Text, {
1085
1100
  style: styles$2.title