@rehagro/ui 1.0.30 → 1.0.32

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,558 @@ 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
+ });
1283
+ var RadioGroupContext = createContext(null);
1284
+ var useRadioGroup = () => useContext(RadioGroupContext);
1285
+ var PRESET_COLORS4 = /* @__PURE__ */ new Set([
1286
+ "primary",
1287
+ "secondary",
1288
+ "danger",
1289
+ "warning",
1290
+ "success",
1291
+ "info"
1292
+ ]);
1293
+ var isPresetColor4 = (color) => PRESET_COLORS4.has(color);
1294
+ var resolveColor = (color, theme) => {
1295
+ if (isPresetColor4(color)) {
1296
+ return theme[color] ?? "#16a34a";
1297
+ }
1298
+ return color;
1299
+ };
1300
+ var outerSizeMap = {
1301
+ sm: 16,
1302
+ md: 20,
1303
+ lg: 24
1304
+ };
1305
+ var innerSizeMap = {
1306
+ sm: 8,
1307
+ md: 10,
1308
+ lg: 12
1309
+ };
1310
+ var labelSizeMap = {
1311
+ sm: 14,
1312
+ md: 14,
1313
+ lg: 16
1314
+ };
1315
+ var descriptionSizeMap = {
1316
+ sm: 12,
1317
+ md: 12,
1318
+ lg: 14
1319
+ };
1320
+ var gapMap = {
1321
+ sm: 8,
1322
+ md: 12,
1323
+ lg: 16
1324
+ };
1325
+ var Radio = forwardRef(function Radio2({
1326
+ size = "md",
1327
+ label,
1328
+ description,
1329
+ color = "primary",
1330
+ disabled,
1331
+ checked: controlledChecked,
1332
+ defaultChecked = false,
1333
+ onChange,
1334
+ style,
1335
+ accessibilityLabel,
1336
+ ...rest
1337
+ }, ref) {
1338
+ const theme = useRehagroTheme();
1339
+ const isControlled = controlledChecked !== void 0;
1340
+ const [internalChecked, setInternalChecked] = useState(defaultChecked);
1341
+ const isChecked = isControlled ? controlledChecked : internalChecked;
1342
+ const resolvedColor = resolveColor(color, theme);
1343
+ const handlePress = useCallback(() => {
1344
+ if (disabled) return;
1345
+ if (!isControlled) setInternalChecked(true);
1346
+ onChange?.(true);
1347
+ }, [disabled, isControlled, onChange]);
1348
+ const outerSize = outerSizeMap[size];
1349
+ const innerSize = innerSizeMap[size];
1350
+ const outerStyle = {
1351
+ width: outerSize,
1352
+ height: outerSize,
1353
+ borderRadius: outerSize / 2,
1354
+ borderWidth: theme.borderWidthSm ?? 1,
1355
+ borderColor: isChecked ? resolvedColor : theme.border ?? "#d1d5db",
1356
+ backgroundColor: theme.surface ?? "#ffffff",
1357
+ alignItems: "center",
1358
+ justifyContent: "center"
1359
+ };
1360
+ const innerStyle = {
1361
+ width: innerSize,
1362
+ height: innerSize,
1363
+ borderRadius: innerSize / 2,
1364
+ backgroundColor: resolvedColor
1365
+ };
1366
+ const accessibilityText = accessibilityLabel ?? (typeof label === "string" ? label : void 0);
1367
+ return /* @__PURE__ */ jsxs(
1368
+ Pressable,
1369
+ {
1370
+ ref,
1371
+ onPress: handlePress,
1372
+ disabled,
1373
+ accessibilityRole: "radio",
1374
+ accessibilityState: { checked: isChecked, disabled: !!disabled },
1375
+ accessibilityLabel: accessibilityText,
1376
+ style: [
1377
+ {
1378
+ flexDirection: "row",
1379
+ alignItems: "flex-start",
1380
+ gap: 8,
1381
+ opacity: disabled ? 0.5 : 1
1382
+ },
1383
+ style
1384
+ ],
1385
+ ...rest,
1386
+ children: [
1387
+ /* @__PURE__ */ jsx(View, { style: outerStyle, children: isChecked && /* @__PURE__ */ jsx(View, { style: innerStyle }) }),
1388
+ (label || description) && /* @__PURE__ */ jsxs(View, { style: { flex: 1, gap: 2 }, children: [
1389
+ label && /* @__PURE__ */ jsx(
1390
+ Text,
1391
+ {
1392
+ style: {
1393
+ fontSize: labelSizeMap[size],
1394
+ color: theme.text,
1395
+ ...theme.fontFamilyBody ? { fontFamily: theme.fontFamilyBody } : {}
1396
+ },
1397
+ children: label
1398
+ }
1399
+ ),
1400
+ description && /* @__PURE__ */ jsx(
1401
+ Text,
1402
+ {
1403
+ style: {
1404
+ fontSize: descriptionSizeMap[size],
1405
+ color: theme.textMuted,
1406
+ ...theme.fontFamilyBody ? { fontFamily: theme.fontFamilyBody } : {}
1407
+ },
1408
+ children: description
1409
+ }
1410
+ )
1411
+ ] })
1412
+ ]
1413
+ }
1414
+ );
1415
+ });
1416
+ var RadioOption = forwardRef(function RadioOption2({ value, size, color, disabled, ...rest }, ref) {
1417
+ const group = useRadioGroup();
1418
+ const mergedSize = size ?? group?.size ?? "md";
1419
+ const mergedColor = color ?? group?.color ?? "primary";
1420
+ const mergedDisabled = disabled ?? group?.disabled ?? false;
1421
+ const isChecked = group?.value === value;
1422
+ const handleChange = () => {
1423
+ group?.onChange?.(value);
1424
+ };
1425
+ return /* @__PURE__ */ jsx(
1426
+ Radio,
1427
+ {
1428
+ ref,
1429
+ size: mergedSize,
1430
+ color: mergedColor,
1431
+ disabled: mergedDisabled,
1432
+ checked: isChecked,
1433
+ onChange: handleChange,
1434
+ ...rest
1435
+ }
1436
+ );
1437
+ });
1438
+ var RadioGroup = forwardRef(function RadioGroup2({
1439
+ children,
1440
+ value,
1441
+ defaultValue,
1442
+ onChange,
1443
+ size = "md",
1444
+ orientation = "vertical",
1445
+ color = "primary",
1446
+ disabled = false,
1447
+ gap = "md",
1448
+ style
1449
+ }, ref) {
1450
+ const [internalValue, setInternalValue] = useState(defaultValue);
1451
+ const isControlled = value !== void 0;
1452
+ const currentValue = isControlled ? value : internalValue;
1453
+ const handleChange = useCallback(
1454
+ (newValue) => {
1455
+ if (!isControlled) setInternalValue(newValue);
1456
+ onChange?.(newValue);
1457
+ },
1458
+ [isControlled, onChange]
1459
+ );
1460
+ return /* @__PURE__ */ jsx(
1461
+ RadioGroupContext.Provider,
1462
+ {
1463
+ value: {
1464
+ value: currentValue,
1465
+ onChange: handleChange,
1466
+ size,
1467
+ color,
1468
+ disabled
1469
+ },
1470
+ children: /* @__PURE__ */ jsx(
1471
+ View,
1472
+ {
1473
+ ref,
1474
+ accessibilityRole: "radiogroup",
1475
+ style: [
1476
+ {
1477
+ flexDirection: orientation === "vertical" ? "column" : "row",
1478
+ flexWrap: orientation === "horizontal" ? "wrap" : "nowrap",
1479
+ gap: gapMap[gap]
1480
+ },
1481
+ style
1482
+ ],
1483
+ children
1484
+ }
1485
+ )
1486
+ }
1487
+ );
1488
+ });
938
1489
 
939
- export { ActivityIndicator3 as ActivityIndicator, Avatar, Button, Card2 as Card, CardContent, CardFooter, CardHeader, Checkbox, IconButton, RehagroNativeProvider, Tag, Text5 as Text, TextInput, useRehagroTheme };
1490
+ export { ActivityIndicator3 as ActivityIndicator, Avatar, Button, Card2 as Card, CardContent, CardFooter, CardHeader, Checkbox, IconButton, Radio, RadioGroup, RadioOption, RehagroNativeProvider, Select, Tag, Text5 as Text, TextInput, useRehagroTheme };
940
1491
  //# sourceMappingURL=native.mjs.map
941
1492
  //# sourceMappingURL=native.mjs.map