@rehagro/ui 1.0.30 → 1.0.31

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/native.mjs CHANGED
@@ -1,6 +1,6 @@
1
- import { createContext, forwardRef, useState, useCallback, useMemo, useContext } from 'react';
1
+ import { createContext, forwardRef, useState, useCallback, useMemo, useRef, useContext } from 'react';
2
2
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
3
- import { Pressable, ActivityIndicator, View, Text, TextInput as TextInput$1, Image } from 'react-native';
3
+ import { Pressable, ActivityIndicator, View, Text, TextInput as TextInput$1, Image, Modal, FlatList } from 'react-native';
4
4
 
5
5
  // src/provider/RehagroNativeProvider.tsx
6
6
 
@@ -935,7 +935,352 @@ var Card2 = Object.assign(CardRoot, {
935
935
  Content: CardContent,
936
936
  Footer: CardFooter
937
937
  });
938
+ var ChevronIcon = ({ size, color, open }) => /* @__PURE__ */ jsx(
939
+ View,
940
+ {
941
+ style: {
942
+ width: size,
943
+ height: size,
944
+ alignItems: "center",
945
+ justifyContent: "center"
946
+ },
947
+ children: /* @__PURE__ */ jsx(
948
+ View,
949
+ {
950
+ style: {
951
+ width: size * 0.5,
952
+ height: size * 0.5,
953
+ borderRightWidth: 2,
954
+ borderBottomWidth: 2,
955
+ borderColor: color,
956
+ transform: [
957
+ { rotate: open ? "225deg" : "45deg" },
958
+ { translateY: open ? size * 0.1 : -size * 0.1 }
959
+ ]
960
+ }
961
+ }
962
+ )
963
+ }
964
+ );
965
+ var CheckIcon2 = ({ size, color }) => /* @__PURE__ */ jsx(
966
+ View,
967
+ {
968
+ style: {
969
+ width: size,
970
+ height: size,
971
+ alignItems: "center",
972
+ justifyContent: "center"
973
+ },
974
+ children: /* @__PURE__ */ jsx(
975
+ View,
976
+ {
977
+ style: {
978
+ position: "absolute",
979
+ width: size * 0.55,
980
+ height: size * 0.3,
981
+ borderLeftWidth: 2,
982
+ borderBottomWidth: 2,
983
+ borderColor: color,
984
+ transform: [{ rotate: "-45deg" }, { translateY: -size * 0.05 }]
985
+ }
986
+ }
987
+ )
988
+ }
989
+ );
990
+ var Select = forwardRef(function Select2(props, ref) {
991
+ const {
992
+ options,
993
+ label,
994
+ subtitle,
995
+ placeholder = "Selecione",
996
+ status = "default",
997
+ size = "md",
998
+ radius = "xs",
999
+ helperText,
1000
+ disabled = false,
1001
+ style,
1002
+ wrapperStyle,
1003
+ accessibilityLabel,
1004
+ multiple = false
1005
+ } = props;
1006
+ const theme = useRehagroTheme();
1007
+ const triggerRef = useRef(null);
1008
+ const [isOpen, setIsOpen] = useState(false);
1009
+ const [triggerLayout, setTriggerLayout] = useState(null);
1010
+ const [internalValue, setInternalValue] = useState(() => {
1011
+ if (props.defaultValue !== void 0) {
1012
+ return Array.isArray(props.defaultValue) ? props.defaultValue : [props.defaultValue];
1013
+ }
1014
+ return [];
1015
+ });
1016
+ const isControlled = props.value !== void 0;
1017
+ const selectedValues = isControlled ? Array.isArray(props.value) ? props.value : props.value !== void 0 ? [props.value] : [] : internalValue;
1018
+ const heightMap = {
1019
+ sm: theme.inputHeightSm ?? 36,
1020
+ md: theme.inputHeightMd ?? 44,
1021
+ lg: theme.inputHeightLg ?? 52
1022
+ };
1023
+ const paddingMap2 = {
1024
+ sm: 12,
1025
+ md: 14,
1026
+ lg: 16
1027
+ };
1028
+ const fontSizeMap = {
1029
+ sm: 14,
1030
+ md: 14,
1031
+ lg: 16
1032
+ };
1033
+ const optionPaddingMap = {
1034
+ sm: 8,
1035
+ md: 10,
1036
+ lg: 12
1037
+ };
1038
+ const radiusMap2 = {
1039
+ none: 0,
1040
+ xxs: theme.radiusXxs ?? 4,
1041
+ xs: theme.radiusXs ?? 8,
1042
+ sm: theme.radiusSm ?? 12,
1043
+ md: theme.radiusMd ?? 16,
1044
+ lg: theme.radiusLg ?? 24,
1045
+ xl: theme.radiusXl ?? 32,
1046
+ full: 9999
1047
+ };
1048
+ const dropdownRadiusMap = {
1049
+ none: 0,
1050
+ xxs: theme.radiusXxs ?? 4,
1051
+ xs: theme.radiusXs ?? 8,
1052
+ sm: theme.radiusXs ?? 8,
1053
+ md: theme.radiusXs ?? 8,
1054
+ lg: theme.radiusXs ?? 8,
1055
+ xl: theme.radiusXs ?? 8,
1056
+ full: theme.radiusXs ?? 8
1057
+ };
1058
+ const hasError = status === "error";
1059
+ const borderColor = hasError ? theme.danger : isOpen ? theme.primary : theme.border;
1060
+ const containerStyle = {
1061
+ height: heightMap[size],
1062
+ paddingHorizontal: paddingMap2[size],
1063
+ borderRadius: radiusMap2[radius],
1064
+ borderWidth: theme.borderWidthSm,
1065
+ borderColor,
1066
+ backgroundColor: disabled ? theme.background : theme.surface,
1067
+ flexDirection: "row",
1068
+ alignItems: "center",
1069
+ justifyContent: "space-between",
1070
+ gap: 8,
1071
+ opacity: disabled ? 0.5 : 1
1072
+ };
1073
+ const displayText = useMemo(() => {
1074
+ if (selectedValues.length === 0) return null;
1075
+ if (!multiple) {
1076
+ return options.find((o) => o.value === selectedValues[0])?.label ?? null;
1077
+ }
1078
+ const selectedLabels = selectedValues.map((v) => options.find((o) => o.value === v)?.label).filter(Boolean);
1079
+ if (selectedLabels.length === 0) return null;
1080
+ if (selectedLabels.length === 1) return selectedLabels[0];
1081
+ return `${selectedLabels.length} selecionados`;
1082
+ }, [selectedValues, options, multiple]);
1083
+ const handleSelect = useCallback(
1084
+ (optionValue) => {
1085
+ if (multiple) {
1086
+ const next = selectedValues.includes(optionValue) ? selectedValues.filter((v) => v !== optionValue) : [...selectedValues, optionValue];
1087
+ if (!isControlled) setInternalValue(next);
1088
+ props.onChange?.(next);
1089
+ } else {
1090
+ const next = [optionValue];
1091
+ if (!isControlled) setInternalValue(next);
1092
+ props.onChange?.(optionValue);
1093
+ setIsOpen(false);
1094
+ }
1095
+ },
1096
+ [multiple, selectedValues, isControlled, props]
1097
+ );
1098
+ const openDropdown = useCallback(() => {
1099
+ if (disabled) return;
1100
+ triggerRef.current?.measureInWindow((x, y, width, height) => {
1101
+ setTriggerLayout({ x, y, width, height });
1102
+ setIsOpen(true);
1103
+ });
1104
+ }, [disabled]);
1105
+ const closeDropdown = useCallback(() => {
1106
+ setIsOpen(false);
1107
+ }, []);
1108
+ const handleTriggerLayout = (_e) => {
1109
+ if (isOpen) {
1110
+ triggerRef.current?.measureInWindow((x, y, width, height) => {
1111
+ setTriggerLayout({ x, y, width, height });
1112
+ });
1113
+ }
1114
+ };
1115
+ return /* @__PURE__ */ jsxs(View, { style: [{ gap: 4 }, wrapperStyle], children: [
1116
+ label && /* @__PURE__ */ jsxs(View, { style: { flexDirection: "row", alignItems: "baseline", gap: 4 }, children: [
1117
+ /* @__PURE__ */ jsx(
1118
+ Text,
1119
+ {
1120
+ style: {
1121
+ fontSize: 14,
1122
+ fontWeight: "500",
1123
+ color: theme.text,
1124
+ ...theme.fontFamilyBody ? { fontFamily: theme.fontFamilyBody } : {}
1125
+ },
1126
+ children: label
1127
+ }
1128
+ ),
1129
+ subtitle && /* @__PURE__ */ jsx(
1130
+ Text,
1131
+ {
1132
+ style: {
1133
+ fontSize: 14,
1134
+ color: theme.textMuted,
1135
+ ...theme.fontFamilyBody ? { fontFamily: theme.fontFamilyBody } : {}
1136
+ },
1137
+ children: subtitle
1138
+ }
1139
+ )
1140
+ ] }),
1141
+ /* @__PURE__ */ jsxs(
1142
+ Pressable,
1143
+ {
1144
+ ref: (node) => {
1145
+ triggerRef.current = node;
1146
+ if (typeof ref === "function") ref(node);
1147
+ else if (ref) ref.current = node;
1148
+ },
1149
+ onPress: openDropdown,
1150
+ onLayout: handleTriggerLayout,
1151
+ disabled,
1152
+ accessibilityRole: "combobox",
1153
+ accessibilityState: { disabled, expanded: isOpen },
1154
+ accessibilityLabel: accessibilityLabel ?? label,
1155
+ style: [containerStyle, style],
1156
+ children: [
1157
+ /* @__PURE__ */ jsx(
1158
+ Text,
1159
+ {
1160
+ numberOfLines: 1,
1161
+ style: {
1162
+ flex: 1,
1163
+ fontSize: fontSizeMap[size],
1164
+ color: displayText ? theme.text : theme.textMuted,
1165
+ ...theme.fontFamilyBody ? { fontFamily: theme.fontFamilyBody } : {}
1166
+ },
1167
+ children: displayText ?? placeholder
1168
+ }
1169
+ ),
1170
+ /* @__PURE__ */ jsx(ChevronIcon, { size: 18, color: theme.textMuted ?? "#6b7280", open: isOpen })
1171
+ ]
1172
+ }
1173
+ ),
1174
+ helperText && /* @__PURE__ */ jsx(
1175
+ Text,
1176
+ {
1177
+ style: {
1178
+ fontSize: 12,
1179
+ color: hasError ? theme.danger : theme.textMuted,
1180
+ ...theme.fontFamilyBody ? { fontFamily: theme.fontFamilyBody } : {}
1181
+ },
1182
+ children: helperText
1183
+ }
1184
+ ),
1185
+ /* @__PURE__ */ jsx(
1186
+ Modal,
1187
+ {
1188
+ visible: isOpen,
1189
+ transparent: true,
1190
+ animationType: "fade",
1191
+ onRequestClose: closeDropdown,
1192
+ statusBarTranslucent: true,
1193
+ children: /* @__PURE__ */ jsx(Pressable, { style: { flex: 1, backgroundColor: "transparent" }, onPress: closeDropdown, children: triggerLayout && /* @__PURE__ */ jsx(
1194
+ View,
1195
+ {
1196
+ style: {
1197
+ position: "absolute",
1198
+ top: triggerLayout.y + triggerLayout.height + 36,
1199
+ left: triggerLayout.x,
1200
+ width: triggerLayout.width,
1201
+ maxHeight: 240,
1202
+ borderRadius: dropdownRadiusMap[radius],
1203
+ borderWidth: theme.borderWidthSm,
1204
+ borderColor: theme.border,
1205
+ backgroundColor: theme.surface,
1206
+ shadowColor: "#000",
1207
+ shadowOffset: { width: 0, height: 2 },
1208
+ shadowOpacity: 0.1,
1209
+ shadowRadius: 8,
1210
+ elevation: 4,
1211
+ overflow: "hidden"
1212
+ },
1213
+ children: /* @__PURE__ */ jsx(
1214
+ FlatList,
1215
+ {
1216
+ data: options,
1217
+ keyExtractor: (item) => item.value,
1218
+ keyboardShouldPersistTaps: "handled",
1219
+ renderItem: ({ item }) => {
1220
+ const isSelected = selectedValues.includes(item.value);
1221
+ const isDisabled = !!item.disabled;
1222
+ return /* @__PURE__ */ jsxs(
1223
+ Pressable,
1224
+ {
1225
+ onPress: () => {
1226
+ if (!isDisabled) handleSelect(item.value);
1227
+ },
1228
+ disabled: isDisabled,
1229
+ accessibilityRole: "menuitem",
1230
+ accessibilityState: { selected: isSelected, disabled: isDisabled },
1231
+ style: ({ pressed }) => ({
1232
+ paddingHorizontal: paddingMap2[size],
1233
+ paddingVertical: optionPaddingMap[size],
1234
+ flexDirection: "row",
1235
+ alignItems: "center",
1236
+ justifyContent: "space-between",
1237
+ gap: 8,
1238
+ backgroundColor: pressed && !isDisabled ? theme.background : "transparent",
1239
+ opacity: isDisabled ? 0.5 : 1
1240
+ }),
1241
+ children: [
1242
+ /* @__PURE__ */ jsx(
1243
+ Text,
1244
+ {
1245
+ numberOfLines: 1,
1246
+ style: {
1247
+ flex: 1,
1248
+ fontSize: fontSizeMap[size],
1249
+ color: theme.text,
1250
+ ...theme.fontFamilyBody ? { fontFamily: theme.fontFamilyBody } : {}
1251
+ },
1252
+ children: item.label
1253
+ }
1254
+ ),
1255
+ multiple ? /* @__PURE__ */ jsx(
1256
+ View,
1257
+ {
1258
+ style: {
1259
+ width: 18,
1260
+ height: 18,
1261
+ borderRadius: theme.radiusXxs,
1262
+ borderWidth: theme.borderWidthSm,
1263
+ borderColor: isSelected ? theme.primary : theme.border,
1264
+ backgroundColor: isSelected ? theme.primary : theme.surface,
1265
+ alignItems: "center",
1266
+ justifyContent: "center"
1267
+ },
1268
+ children: isSelected && /* @__PURE__ */ jsx(CheckIcon2, { size: 12, color: theme.surface ?? "#ffffff" })
1269
+ }
1270
+ ) : isSelected && /* @__PURE__ */ jsx(CheckIcon2, { size: 14, color: theme.primary ?? "#16a34a" })
1271
+ ]
1272
+ }
1273
+ );
1274
+ }
1275
+ }
1276
+ )
1277
+ }
1278
+ ) })
1279
+ }
1280
+ )
1281
+ ] });
1282
+ });
938
1283
 
939
- export { ActivityIndicator3 as ActivityIndicator, Avatar, Button, Card2 as Card, CardContent, CardFooter, CardHeader, Checkbox, IconButton, RehagroNativeProvider, Tag, Text5 as Text, TextInput, useRehagroTheme };
1284
+ export { ActivityIndicator3 as ActivityIndicator, Avatar, Button, Card2 as Card, CardContent, CardFooter, CardHeader, Checkbox, IconButton, RehagroNativeProvider, Select, Tag, Text5 as Text, TextInput, useRehagroTheme };
940
1285
  //# sourceMappingURL=native.mjs.map
941
1286
  //# sourceMappingURL=native.mjs.map