@xaui/native 0.0.14 → 0.0.15
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/chip/index.cjs +584 -0
- package/dist/chip/index.d.cts +195 -0
- package/dist/chip/index.d.ts +195 -0
- package/dist/chip/index.js +11 -0
- package/dist/chunk-QLEQYKG5.js +509 -0
- package/dist/index.cjs +559 -53
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +8 -0
- package/package.json +6 -1
package/dist/index.cjs
CHANGED
|
@@ -38,6 +38,9 @@ __export(src_exports, {
|
|
|
38
38
|
AvatarGroup: () => AvatarGroup,
|
|
39
39
|
Badge: () => Badge,
|
|
40
40
|
BottomSheet: () => BottomSheet,
|
|
41
|
+
Chip: () => Chip,
|
|
42
|
+
ChipGroup: () => ChipGroup,
|
|
43
|
+
ChipItem: () => ChipItem,
|
|
41
44
|
DatePicker: () => DatePicker,
|
|
42
45
|
Divider: () => Divider,
|
|
43
46
|
Typography: () => Typography
|
|
@@ -1442,7 +1445,7 @@ var useAutocompleteVariantStyles = (themeColor, variant, isInvalid) => {
|
|
|
1442
1445
|
if ((variant === "outlined" || variant === "faded") && themeColor === "default") {
|
|
1443
1446
|
borderColor = import_palette2.colors.gray[300];
|
|
1444
1447
|
}
|
|
1445
|
-
const
|
|
1448
|
+
const styles14 = {
|
|
1446
1449
|
outlined: {
|
|
1447
1450
|
backgroundColor: "transparent",
|
|
1448
1451
|
borderWidth: theme.borderWidth.md,
|
|
@@ -1467,7 +1470,7 @@ var useAutocompleteVariantStyles = (themeColor, variant, isInvalid) => {
|
|
|
1467
1470
|
borderColor
|
|
1468
1471
|
}
|
|
1469
1472
|
};
|
|
1470
|
-
return
|
|
1473
|
+
return styles14[variant];
|
|
1471
1474
|
}, [variant, theme, colorScheme, isInvalid, themeColor]);
|
|
1472
1475
|
};
|
|
1473
1476
|
var useAutocompleteLabelStyle = (themeColor, isInvalid, labelSize) => {
|
|
@@ -4134,7 +4137,7 @@ var useTypographyVariantStyles = (variant) => {
|
|
|
4134
4137
|
fontWeight: theme.fontWeights.normal
|
|
4135
4138
|
};
|
|
4136
4139
|
}
|
|
4137
|
-
const
|
|
4140
|
+
const styles14 = {
|
|
4138
4141
|
caption: {
|
|
4139
4142
|
fontFamily: theme.fontFamilies.body,
|
|
4140
4143
|
fontSize: theme.fontSizes.xs,
|
|
@@ -4186,7 +4189,7 @@ var useTypographyVariantStyles = (variant) => {
|
|
|
4186
4189
|
fontWeight: theme.fontWeights.normal
|
|
4187
4190
|
}
|
|
4188
4191
|
};
|
|
4189
|
-
return
|
|
4192
|
+
return styles14[variant];
|
|
4190
4193
|
}, [theme, variant]);
|
|
4191
4194
|
return variantStyles;
|
|
4192
4195
|
};
|
|
@@ -4226,17 +4229,517 @@ var Typography = ({
|
|
|
4226
4229
|
);
|
|
4227
4230
|
};
|
|
4228
4231
|
|
|
4229
|
-
// src/components/
|
|
4232
|
+
// src/components/chip/chip.tsx
|
|
4230
4233
|
var import_react44 = __toESM(require("react"), 1);
|
|
4231
|
-
var
|
|
4234
|
+
var import_react_native39 = require("react-native");
|
|
4232
4235
|
|
|
4233
|
-
// src/components/
|
|
4236
|
+
// src/components/chip/chip.style.ts
|
|
4237
|
+
var import_react_native38 = require("react-native");
|
|
4238
|
+
var styles12 = import_react_native38.StyleSheet.create({
|
|
4239
|
+
chip: {
|
|
4240
|
+
flexDirection: "row",
|
|
4241
|
+
alignItems: "center",
|
|
4242
|
+
alignSelf: "flex-start"
|
|
4243
|
+
},
|
|
4244
|
+
text: {
|
|
4245
|
+
fontWeight: "500",
|
|
4246
|
+
includeFontPadding: false,
|
|
4247
|
+
textAlignVertical: "center"
|
|
4248
|
+
},
|
|
4249
|
+
disabled: {
|
|
4250
|
+
opacity: 0.5
|
|
4251
|
+
},
|
|
4252
|
+
avatar: {
|
|
4253
|
+
marginRight: 4
|
|
4254
|
+
},
|
|
4255
|
+
startContent: {
|
|
4256
|
+
marginRight: 4
|
|
4257
|
+
},
|
|
4258
|
+
endContent: {
|
|
4259
|
+
marginLeft: 4
|
|
4260
|
+
},
|
|
4261
|
+
closeButton: {
|
|
4262
|
+
marginLeft: 4,
|
|
4263
|
+
alignItems: "center",
|
|
4264
|
+
justifyContent: "center"
|
|
4265
|
+
},
|
|
4266
|
+
dot: {
|
|
4267
|
+
borderRadius: 9999,
|
|
4268
|
+
marginRight: 6
|
|
4269
|
+
},
|
|
4270
|
+
groupContainer: {
|
|
4271
|
+
flexDirection: "row",
|
|
4272
|
+
flexWrap: "wrap"
|
|
4273
|
+
}
|
|
4274
|
+
});
|
|
4275
|
+
|
|
4276
|
+
// src/components/chip/chip.hook.ts
|
|
4234
4277
|
var import_react43 = require("react");
|
|
4235
|
-
var
|
|
4236
|
-
var
|
|
4278
|
+
var import_core31 = require("@xaui/core");
|
|
4279
|
+
var sizeMap3 = {
|
|
4280
|
+
sm: { height: 32, paddingH: 12, fontSize: 13 },
|
|
4281
|
+
md: { height: 40, paddingH: 16, fontSize: 15 },
|
|
4282
|
+
lg: { height: 44, paddingH: 18, fontSize: 17 }
|
|
4283
|
+
};
|
|
4284
|
+
var dotSizeMap = {
|
|
4285
|
+
sm: 8,
|
|
4286
|
+
md: 10,
|
|
4287
|
+
lg: 11
|
|
4288
|
+
};
|
|
4289
|
+
var closeSizeMap = {
|
|
4290
|
+
sm: 14,
|
|
4291
|
+
md: 16,
|
|
4292
|
+
lg: 17
|
|
4293
|
+
};
|
|
4294
|
+
function useChipSizeStyles(size) {
|
|
4295
|
+
return (0, import_react43.useMemo)(() => {
|
|
4296
|
+
const { height, paddingH, fontSize } = sizeMap3[size];
|
|
4297
|
+
return { height, paddingHorizontal: paddingH, fontSize };
|
|
4298
|
+
}, [size]);
|
|
4299
|
+
}
|
|
4300
|
+
function useChipDotSize(size) {
|
|
4301
|
+
return (0, import_react43.useMemo)(() => dotSizeMap[size], [size]);
|
|
4302
|
+
}
|
|
4303
|
+
function useChipCloseSize(size) {
|
|
4304
|
+
return (0, import_react43.useMemo)(() => closeSizeMap[size], [size]);
|
|
4305
|
+
}
|
|
4306
|
+
function useChipRadiusStyles(radius, height) {
|
|
4307
|
+
const theme = useXUITheme();
|
|
4308
|
+
return (0, import_react43.useMemo)(() => {
|
|
4309
|
+
if (radius === "full") {
|
|
4310
|
+
return { borderRadius: height / 2 };
|
|
4311
|
+
}
|
|
4312
|
+
return { borderRadius: theme.borderRadius[radius] };
|
|
4313
|
+
}, [height, radius, theme.borderRadius]);
|
|
4314
|
+
}
|
|
4315
|
+
function useChipVariantStyles(themeColor, variant) {
|
|
4316
|
+
const theme = useXUITheme();
|
|
4317
|
+
const safeColor = (0, import_core31.getSafeThemeColor)(themeColor);
|
|
4318
|
+
const colorScheme = theme.colors[safeColor];
|
|
4319
|
+
return (0, import_react43.useMemo)(() => {
|
|
4320
|
+
switch (variant) {
|
|
4321
|
+
case "bordered":
|
|
4322
|
+
return {
|
|
4323
|
+
backgroundColor: "transparent",
|
|
4324
|
+
color: colorScheme.main,
|
|
4325
|
+
borderWidth: 2,
|
|
4326
|
+
borderColor: colorScheme.main
|
|
4327
|
+
};
|
|
4328
|
+
case "light":
|
|
4329
|
+
return {
|
|
4330
|
+
backgroundColor: "transparent",
|
|
4331
|
+
color: colorScheme.main
|
|
4332
|
+
};
|
|
4333
|
+
case "flat":
|
|
4334
|
+
return {
|
|
4335
|
+
backgroundColor: colorScheme.background,
|
|
4336
|
+
color: colorScheme.main
|
|
4337
|
+
};
|
|
4338
|
+
case "faded":
|
|
4339
|
+
return {
|
|
4340
|
+
backgroundColor: (0, import_core31.withOpacity)(colorScheme.background, 0.7),
|
|
4341
|
+
color: colorScheme.main,
|
|
4342
|
+
borderWidth: 1,
|
|
4343
|
+
borderColor: (0, import_core31.withOpacity)(colorScheme.main, 0.3)
|
|
4344
|
+
};
|
|
4345
|
+
case "shadow":
|
|
4346
|
+
return {
|
|
4347
|
+
backgroundColor: colorScheme.main,
|
|
4348
|
+
color: colorScheme.foreground,
|
|
4349
|
+
shadow: theme.shadows.sm
|
|
4350
|
+
};
|
|
4351
|
+
case "dot":
|
|
4352
|
+
return {
|
|
4353
|
+
backgroundColor: colorScheme.background,
|
|
4354
|
+
color: colorScheme.main,
|
|
4355
|
+
dotColor: colorScheme.main
|
|
4356
|
+
};
|
|
4357
|
+
case "solid":
|
|
4358
|
+
default:
|
|
4359
|
+
return {
|
|
4360
|
+
backgroundColor: colorScheme.main,
|
|
4361
|
+
color: colorScheme.foreground
|
|
4362
|
+
};
|
|
4363
|
+
}
|
|
4364
|
+
}, [colorScheme, theme, variant]);
|
|
4365
|
+
}
|
|
4366
|
+
|
|
4367
|
+
// src/components/chip/chip.tsx
|
|
4368
|
+
var Chip = ({
|
|
4369
|
+
children,
|
|
4370
|
+
variant = "solid",
|
|
4371
|
+
themeColor = "default",
|
|
4372
|
+
size = "md",
|
|
4373
|
+
radius = "full",
|
|
4374
|
+
avatar,
|
|
4375
|
+
startContent,
|
|
4376
|
+
endContent,
|
|
4377
|
+
isDisabled = false,
|
|
4378
|
+
customAppearance,
|
|
4379
|
+
onClose,
|
|
4380
|
+
onPress
|
|
4381
|
+
}) => {
|
|
4382
|
+
const [isClosed, setIsClosed] = import_react44.default.useState(false);
|
|
4383
|
+
const [isClosing, setIsClosing] = import_react44.default.useState(false);
|
|
4384
|
+
const sizeStyles = useChipSizeStyles(size);
|
|
4385
|
+
const radiusStyles = useChipRadiusStyles(radius, sizeStyles.height);
|
|
4386
|
+
const variantStyles = useChipVariantStyles(themeColor, variant);
|
|
4387
|
+
const dotSize = useChipDotSize(size);
|
|
4388
|
+
const closeSize = useChipCloseSize(size);
|
|
4389
|
+
const isDotVariant = variant === "dot";
|
|
4390
|
+
const hasClose = onClose !== void 0;
|
|
4391
|
+
const isInteractive = onPress !== void 0 || hasClose;
|
|
4392
|
+
const scale = import_react44.default.useRef(new import_react_native39.Animated.Value(1)).current;
|
|
4393
|
+
const opacity = import_react44.default.useRef(new import_react_native39.Animated.Value(1)).current;
|
|
4394
|
+
const isClosingRef = import_react44.default.useRef(false);
|
|
4395
|
+
const colorProgress = import_react44.default.useRef(new import_react_native39.Animated.Value(1)).current;
|
|
4396
|
+
const targetBackgroundColor = variantStyles.backgroundColor ?? "transparent";
|
|
4397
|
+
const targetBorderColor = variantStyles.borderColor ?? "transparent";
|
|
4398
|
+
const targetTextColor = variantStyles.color ?? "#000000";
|
|
4399
|
+
const targetDotColor = variantStyles.dotColor ?? targetTextColor;
|
|
4400
|
+
const previousColorsRef = import_react44.default.useRef({
|
|
4401
|
+
backgroundColor: targetBackgroundColor,
|
|
4402
|
+
borderColor: targetBorderColor,
|
|
4403
|
+
textColor: targetTextColor,
|
|
4404
|
+
dotColor: targetDotColor
|
|
4405
|
+
});
|
|
4406
|
+
import_react44.default.useEffect(() => {
|
|
4407
|
+
if (previousColorsRef.current.backgroundColor === targetBackgroundColor && previousColorsRef.current.borderColor === targetBorderColor && previousColorsRef.current.textColor === targetTextColor && previousColorsRef.current.dotColor === targetDotColor) {
|
|
4408
|
+
return;
|
|
4409
|
+
}
|
|
4410
|
+
colorProgress.setValue(0);
|
|
4411
|
+
import_react_native39.Animated.timing(colorProgress, {
|
|
4412
|
+
toValue: 1,
|
|
4413
|
+
duration: 180,
|
|
4414
|
+
easing: import_react_native39.Easing.out(import_react_native39.Easing.cubic),
|
|
4415
|
+
useNativeDriver: false
|
|
4416
|
+
}).start(() => {
|
|
4417
|
+
previousColorsRef.current = {
|
|
4418
|
+
backgroundColor: targetBackgroundColor,
|
|
4419
|
+
borderColor: targetBorderColor,
|
|
4420
|
+
textColor: targetTextColor,
|
|
4421
|
+
dotColor: targetDotColor
|
|
4422
|
+
};
|
|
4423
|
+
});
|
|
4424
|
+
}, [
|
|
4425
|
+
colorProgress,
|
|
4426
|
+
targetBackgroundColor,
|
|
4427
|
+
targetBorderColor,
|
|
4428
|
+
targetTextColor,
|
|
4429
|
+
targetDotColor
|
|
4430
|
+
]);
|
|
4431
|
+
const animatedBackgroundColor = colorProgress.interpolate({
|
|
4432
|
+
inputRange: [0, 1],
|
|
4433
|
+
outputRange: [
|
|
4434
|
+
previousColorsRef.current.backgroundColor,
|
|
4435
|
+
targetBackgroundColor
|
|
4436
|
+
]
|
|
4437
|
+
});
|
|
4438
|
+
const animatedBorderColor = colorProgress.interpolate({
|
|
4439
|
+
inputRange: [0, 1],
|
|
4440
|
+
outputRange: [previousColorsRef.current.borderColor, targetBorderColor]
|
|
4441
|
+
});
|
|
4442
|
+
const animatedTextColor = colorProgress.interpolate({
|
|
4443
|
+
inputRange: [0, 1],
|
|
4444
|
+
outputRange: [previousColorsRef.current.textColor, targetTextColor]
|
|
4445
|
+
});
|
|
4446
|
+
const animatedDotColor = colorProgress.interpolate({
|
|
4447
|
+
inputRange: [0, 1],
|
|
4448
|
+
outputRange: [previousColorsRef.current.dotColor, targetDotColor]
|
|
4449
|
+
});
|
|
4450
|
+
const handlePressIn = import_react44.default.useCallback(() => {
|
|
4451
|
+
if (!isInteractive || isDisabled || isClosing || hasClose) return;
|
|
4452
|
+
import_react_native39.Animated.timing(scale, {
|
|
4453
|
+
toValue: 0.97,
|
|
4454
|
+
duration: 90,
|
|
4455
|
+
easing: import_react_native39.Easing.out(import_react_native39.Easing.cubic),
|
|
4456
|
+
useNativeDriver: true
|
|
4457
|
+
}).start();
|
|
4458
|
+
}, [hasClose, isInteractive, isClosing, isDisabled, scale]);
|
|
4459
|
+
const handlePressOut = import_react44.default.useCallback(() => {
|
|
4460
|
+
if (!isInteractive || isDisabled || isClosing || hasClose) return;
|
|
4461
|
+
import_react_native39.Animated.timing(scale, {
|
|
4462
|
+
toValue: 1,
|
|
4463
|
+
duration: 120,
|
|
4464
|
+
easing: import_react_native39.Easing.out(import_react_native39.Easing.cubic),
|
|
4465
|
+
useNativeDriver: true
|
|
4466
|
+
}).start();
|
|
4467
|
+
}, [hasClose, isInteractive, isClosing, isDisabled, scale]);
|
|
4468
|
+
const handleChipPress = import_react44.default.useCallback(() => {
|
|
4469
|
+
if (isDisabled || isClosing || isClosingRef.current) return;
|
|
4470
|
+
if (hasClose && onClose) {
|
|
4471
|
+
isClosingRef.current = true;
|
|
4472
|
+
setIsClosing(true);
|
|
4473
|
+
import_react_native39.Animated.parallel([
|
|
4474
|
+
import_react_native39.Animated.timing(opacity, {
|
|
4475
|
+
toValue: 0,
|
|
4476
|
+
duration: 180,
|
|
4477
|
+
easing: import_react_native39.Easing.in(import_react_native39.Easing.quad),
|
|
4478
|
+
useNativeDriver: true
|
|
4479
|
+
}),
|
|
4480
|
+
import_react_native39.Animated.timing(scale, {
|
|
4481
|
+
toValue: 0.88,
|
|
4482
|
+
duration: 180,
|
|
4483
|
+
easing: import_react_native39.Easing.in(import_react_native39.Easing.quad),
|
|
4484
|
+
useNativeDriver: true
|
|
4485
|
+
})
|
|
4486
|
+
]).start(() => {
|
|
4487
|
+
setIsClosed(true);
|
|
4488
|
+
onClose();
|
|
4489
|
+
setIsClosing(false);
|
|
4490
|
+
isClosingRef.current = false;
|
|
4491
|
+
});
|
|
4492
|
+
return;
|
|
4493
|
+
}
|
|
4494
|
+
onPress?.();
|
|
4495
|
+
}, [hasClose, isClosing, isDisabled, onClose, onPress, opacity, scale]);
|
|
4496
|
+
if (isClosed) {
|
|
4497
|
+
return null;
|
|
4498
|
+
}
|
|
4499
|
+
const chipContent = /* @__PURE__ */ import_react44.default.createElement(import_react_native39.Animated.View, { style: { transform: [{ scale }], opacity } }, /* @__PURE__ */ import_react44.default.createElement(
|
|
4500
|
+
import_react_native39.Animated.View,
|
|
4501
|
+
{
|
|
4502
|
+
style: [
|
|
4503
|
+
styles12.chip,
|
|
4504
|
+
{
|
|
4505
|
+
height: sizeStyles.height,
|
|
4506
|
+
paddingHorizontal: sizeStyles.paddingHorizontal,
|
|
4507
|
+
backgroundColor: animatedBackgroundColor,
|
|
4508
|
+
borderWidth: variantStyles.borderWidth,
|
|
4509
|
+
borderColor: animatedBorderColor
|
|
4510
|
+
},
|
|
4511
|
+
radiusStyles,
|
|
4512
|
+
variantStyles.shadow,
|
|
4513
|
+
isDisabled && styles12.disabled,
|
|
4514
|
+
customAppearance?.container
|
|
4515
|
+
],
|
|
4516
|
+
accessible: true,
|
|
4517
|
+
accessibilityRole: "text"
|
|
4518
|
+
},
|
|
4519
|
+
isDotVariant && /* @__PURE__ */ import_react44.default.createElement(
|
|
4520
|
+
import_react_native39.Animated.View,
|
|
4521
|
+
{
|
|
4522
|
+
style: [
|
|
4523
|
+
styles12.dot,
|
|
4524
|
+
{
|
|
4525
|
+
width: dotSize,
|
|
4526
|
+
height: dotSize,
|
|
4527
|
+
backgroundColor: animatedDotColor
|
|
4528
|
+
},
|
|
4529
|
+
customAppearance?.dot
|
|
4530
|
+
]
|
|
4531
|
+
}
|
|
4532
|
+
),
|
|
4533
|
+
avatar && /* @__PURE__ */ import_react44.default.createElement(import_react_native39.View, { style: styles12.avatar }, avatar),
|
|
4534
|
+
startContent && !avatar && /* @__PURE__ */ import_react44.default.createElement(import_react_native39.View, { style: styles12.startContent }, startContent),
|
|
4535
|
+
/* @__PURE__ */ import_react44.default.createElement(
|
|
4536
|
+
import_react_native39.Animated.Text,
|
|
4537
|
+
{
|
|
4538
|
+
style: [
|
|
4539
|
+
styles12.text,
|
|
4540
|
+
{ fontSize: sizeStyles.fontSize, color: animatedTextColor },
|
|
4541
|
+
customAppearance?.text
|
|
4542
|
+
]
|
|
4543
|
+
},
|
|
4544
|
+
children
|
|
4545
|
+
),
|
|
4546
|
+
endContent && !hasClose && /* @__PURE__ */ import_react44.default.createElement(import_react_native39.View, { style: styles12.endContent }, endContent),
|
|
4547
|
+
hasClose && /* @__PURE__ */ import_react44.default.createElement(
|
|
4548
|
+
import_react_native39.View,
|
|
4549
|
+
{
|
|
4550
|
+
style: [
|
|
4551
|
+
styles12.closeButton,
|
|
4552
|
+
{ width: closeSize, height: closeSize },
|
|
4553
|
+
customAppearance?.closeButton
|
|
4554
|
+
]
|
|
4555
|
+
},
|
|
4556
|
+
/* @__PURE__ */ import_react44.default.createElement(
|
|
4557
|
+
import_react_native39.Animated.Text,
|
|
4558
|
+
{
|
|
4559
|
+
style: {
|
|
4560
|
+
fontSize: closeSize - 2,
|
|
4561
|
+
color: animatedTextColor,
|
|
4562
|
+
lineHeight: closeSize
|
|
4563
|
+
}
|
|
4564
|
+
},
|
|
4565
|
+
"\u2715"
|
|
4566
|
+
)
|
|
4567
|
+
)
|
|
4568
|
+
));
|
|
4569
|
+
if (isInteractive) {
|
|
4570
|
+
return /* @__PURE__ */ import_react44.default.createElement(
|
|
4571
|
+
import_react_native39.Pressable,
|
|
4572
|
+
{
|
|
4573
|
+
onPress: isDisabled || isClosing ? void 0 : handleChipPress,
|
|
4574
|
+
onPressIn: handlePressIn,
|
|
4575
|
+
onPressOut: handlePressOut,
|
|
4576
|
+
disabled: isDisabled || isClosing
|
|
4577
|
+
},
|
|
4578
|
+
chipContent
|
|
4579
|
+
);
|
|
4580
|
+
}
|
|
4581
|
+
return chipContent;
|
|
4582
|
+
};
|
|
4583
|
+
|
|
4584
|
+
// src/components/chip/chip-group.tsx
|
|
4585
|
+
var import_react47 = __toESM(require("react"), 1);
|
|
4586
|
+
var import_react_native40 = require("react-native");
|
|
4587
|
+
|
|
4588
|
+
// src/components/chip/chip-context.ts
|
|
4589
|
+
var import_react45 = require("react");
|
|
4590
|
+
var ChipGroupContext = (0, import_react45.createContext)(null);
|
|
4591
|
+
|
|
4592
|
+
// src/components/chip/chip-group.hook.ts
|
|
4593
|
+
var import_react46 = require("react");
|
|
4594
|
+
function useChipGroupSelection(selectMode, selectedValues, defaultSelectedValues, onSelectionChange) {
|
|
4595
|
+
const [internalValues, setInternalValues] = (0, import_react46.useState)(
|
|
4596
|
+
defaultSelectedValues ?? []
|
|
4597
|
+
);
|
|
4598
|
+
const isControlled = selectedValues !== void 0;
|
|
4599
|
+
const currentValues = isControlled ? selectedValues : internalValues;
|
|
4600
|
+
const onToggle = (0, import_react46.useCallback)(
|
|
4601
|
+
(value) => {
|
|
4602
|
+
const isSelected = currentValues.includes(value);
|
|
4603
|
+
let nextValues;
|
|
4604
|
+
if (selectMode === "single") {
|
|
4605
|
+
nextValues = isSelected ? [] : [value];
|
|
4606
|
+
} else {
|
|
4607
|
+
nextValues = isSelected ? currentValues.filter((v) => v !== value) : [...currentValues, value];
|
|
4608
|
+
}
|
|
4609
|
+
if (!isControlled) {
|
|
4610
|
+
setInternalValues(nextValues);
|
|
4611
|
+
}
|
|
4612
|
+
onSelectionChange?.(nextValues);
|
|
4613
|
+
},
|
|
4614
|
+
[currentValues, isControlled, onSelectionChange, selectMode]
|
|
4615
|
+
);
|
|
4616
|
+
return (0, import_react46.useMemo)(
|
|
4617
|
+
() => ({ currentValues, onToggle }),
|
|
4618
|
+
[currentValues, onToggle]
|
|
4619
|
+
);
|
|
4620
|
+
}
|
|
4621
|
+
|
|
4622
|
+
// src/components/chip/chip-group.tsx
|
|
4623
|
+
var ChipGroup = ({
|
|
4624
|
+
children,
|
|
4625
|
+
isSelectable = false,
|
|
4626
|
+
selectMode = "single",
|
|
4627
|
+
variant = "solid",
|
|
4628
|
+
themeColor = "default",
|
|
4629
|
+
size = "md",
|
|
4630
|
+
radius = "full",
|
|
4631
|
+
isDisabled = false,
|
|
4632
|
+
selectedValues,
|
|
4633
|
+
defaultSelectedValues,
|
|
4634
|
+
onSelectionChange,
|
|
4635
|
+
spacing = 8,
|
|
4636
|
+
customAppearance
|
|
4637
|
+
}) => {
|
|
4638
|
+
const { currentValues, onToggle } = useChipGroupSelection(
|
|
4639
|
+
selectMode,
|
|
4640
|
+
selectedValues,
|
|
4641
|
+
defaultSelectedValues,
|
|
4642
|
+
onSelectionChange
|
|
4643
|
+
);
|
|
4644
|
+
const contextValue = import_react47.default.useMemo(
|
|
4645
|
+
() => ({
|
|
4646
|
+
variant,
|
|
4647
|
+
themeColor,
|
|
4648
|
+
size,
|
|
4649
|
+
radius,
|
|
4650
|
+
isDisabled,
|
|
4651
|
+
isSelectable,
|
|
4652
|
+
selectMode,
|
|
4653
|
+
selectedValues: currentValues,
|
|
4654
|
+
onToggle
|
|
4655
|
+
}),
|
|
4656
|
+
[
|
|
4657
|
+
variant,
|
|
4658
|
+
themeColor,
|
|
4659
|
+
size,
|
|
4660
|
+
radius,
|
|
4661
|
+
isDisabled,
|
|
4662
|
+
isSelectable,
|
|
4663
|
+
selectMode,
|
|
4664
|
+
currentValues,
|
|
4665
|
+
onToggle
|
|
4666
|
+
]
|
|
4667
|
+
);
|
|
4668
|
+
return /* @__PURE__ */ import_react47.default.createElement(ChipGroupContext.Provider, { value: contextValue }, /* @__PURE__ */ import_react47.default.createElement(
|
|
4669
|
+
import_react_native40.View,
|
|
4670
|
+
{
|
|
4671
|
+
style: [
|
|
4672
|
+
styles12.groupContainer,
|
|
4673
|
+
{ gap: spacing },
|
|
4674
|
+
customAppearance?.container
|
|
4675
|
+
],
|
|
4676
|
+
accessible: true
|
|
4677
|
+
},
|
|
4678
|
+
children
|
|
4679
|
+
));
|
|
4680
|
+
};
|
|
4681
|
+
|
|
4682
|
+
// src/components/chip/chip-item.tsx
|
|
4683
|
+
var import_react48 = __toESM(require("react"), 1);
|
|
4684
|
+
function getSelectableVariant(baseVariant, isSelected) {
|
|
4685
|
+
if (isSelected) {
|
|
4686
|
+
return baseVariant;
|
|
4687
|
+
}
|
|
4688
|
+
if (baseVariant === "solid" || baseVariant === "shadow") {
|
|
4689
|
+
return "bordered";
|
|
4690
|
+
}
|
|
4691
|
+
return "light";
|
|
4692
|
+
}
|
|
4693
|
+
var ChipItem = ({
|
|
4694
|
+
value,
|
|
4695
|
+
children,
|
|
4696
|
+
variant,
|
|
4697
|
+
themeColor,
|
|
4698
|
+
avatar,
|
|
4699
|
+
startContent,
|
|
4700
|
+
endContent,
|
|
4701
|
+
isDisabled,
|
|
4702
|
+
customAppearance
|
|
4703
|
+
}) => {
|
|
4704
|
+
const groupContext = (0, import_react48.useContext)(ChipGroupContext);
|
|
4705
|
+
if (!groupContext) {
|
|
4706
|
+
return null;
|
|
4707
|
+
}
|
|
4708
|
+
const resolvedVariant = variant ?? groupContext.variant;
|
|
4709
|
+
const resolvedColor = themeColor ?? groupContext.themeColor;
|
|
4710
|
+
const resolvedDisabled = isDisabled ?? groupContext.isDisabled;
|
|
4711
|
+
const isSelected = groupContext.selectedValues.includes(value);
|
|
4712
|
+
const chipVariant = groupContext.isSelectable ? getSelectableVariant(resolvedVariant, isSelected) : resolvedVariant;
|
|
4713
|
+
const handlePress = groupContext.isSelectable ? () => groupContext.onToggle(value) : void 0;
|
|
4714
|
+
return /* @__PURE__ */ import_react48.default.createElement(
|
|
4715
|
+
Chip,
|
|
4716
|
+
{
|
|
4717
|
+
variant: chipVariant,
|
|
4718
|
+
themeColor: resolvedColor,
|
|
4719
|
+
size: groupContext.size,
|
|
4720
|
+
radius: groupContext.radius,
|
|
4721
|
+
isDisabled: resolvedDisabled,
|
|
4722
|
+
avatar,
|
|
4723
|
+
startContent,
|
|
4724
|
+
endContent,
|
|
4725
|
+
customAppearance,
|
|
4726
|
+
onPress: handlePress
|
|
4727
|
+
},
|
|
4728
|
+
children
|
|
4729
|
+
);
|
|
4730
|
+
};
|
|
4731
|
+
|
|
4732
|
+
// src/components/bottom-sheet/bottom-sheet.tsx
|
|
4733
|
+
var import_react50 = __toESM(require("react"), 1);
|
|
4734
|
+
var import_react_native44 = require("react-native");
|
|
4735
|
+
|
|
4736
|
+
// src/components/bottom-sheet/bottom-sheet.hook.ts
|
|
4737
|
+
var import_react49 = require("react");
|
|
4738
|
+
var import_react_native42 = require("react-native");
|
|
4739
|
+
var import_core34 = require("@xaui/core");
|
|
4237
4740
|
|
|
4238
4741
|
// src/components/bottom-sheet/bottom-sheet.animation.ts
|
|
4239
|
-
var
|
|
4742
|
+
var import_react_native41 = require("react-native");
|
|
4240
4743
|
var SPRING_CONFIG = {
|
|
4241
4744
|
useNativeDriver: true,
|
|
4242
4745
|
speed: 14,
|
|
@@ -4244,16 +4747,16 @@ var SPRING_CONFIG = {
|
|
|
4244
4747
|
};
|
|
4245
4748
|
var TIMING_CONFIG = {
|
|
4246
4749
|
duration: 280,
|
|
4247
|
-
easing:
|
|
4750
|
+
easing: import_react_native41.Easing.bezier(0.2, 0, 0, 1),
|
|
4248
4751
|
useNativeDriver: true
|
|
4249
4752
|
};
|
|
4250
4753
|
var runOpenAnimation = (translateY, backdropOpacity, targetTranslateY) => {
|
|
4251
|
-
const animation =
|
|
4252
|
-
|
|
4754
|
+
const animation = import_react_native41.Animated.parallel([
|
|
4755
|
+
import_react_native41.Animated.spring(translateY, {
|
|
4253
4756
|
...SPRING_CONFIG,
|
|
4254
4757
|
toValue: targetTranslateY
|
|
4255
4758
|
}),
|
|
4256
|
-
|
|
4759
|
+
import_react_native41.Animated.timing(backdropOpacity, {
|
|
4257
4760
|
...TIMING_CONFIG,
|
|
4258
4761
|
toValue: 1
|
|
4259
4762
|
})
|
|
@@ -4262,12 +4765,12 @@ var runOpenAnimation = (translateY, backdropOpacity, targetTranslateY) => {
|
|
|
4262
4765
|
return animation;
|
|
4263
4766
|
};
|
|
4264
4767
|
var runCloseAnimation = (translateY, backdropOpacity, screenHeight, onComplete) => {
|
|
4265
|
-
const animation =
|
|
4266
|
-
|
|
4768
|
+
const animation = import_react_native41.Animated.parallel([
|
|
4769
|
+
import_react_native41.Animated.timing(translateY, {
|
|
4267
4770
|
...TIMING_CONFIG,
|
|
4268
4771
|
toValue: screenHeight
|
|
4269
4772
|
}),
|
|
4270
|
-
|
|
4773
|
+
import_react_native41.Animated.timing(backdropOpacity, {
|
|
4271
4774
|
...TIMING_CONFIG,
|
|
4272
4775
|
toValue: 0
|
|
4273
4776
|
})
|
|
@@ -4280,7 +4783,7 @@ var runCloseAnimation = (translateY, backdropOpacity, screenHeight, onComplete)
|
|
|
4280
4783
|
return animation;
|
|
4281
4784
|
};
|
|
4282
4785
|
var runSnapAnimation = (translateY, targetTranslateY) => {
|
|
4283
|
-
const animation =
|
|
4786
|
+
const animation = import_react_native41.Animated.spring(translateY, {
|
|
4284
4787
|
...SPRING_CONFIG,
|
|
4285
4788
|
toValue: targetTranslateY
|
|
4286
4789
|
});
|
|
@@ -4291,7 +4794,7 @@ var runSnapAnimation = (translateY, targetTranslateY) => {
|
|
|
4291
4794
|
// src/components/bottom-sheet/bottom-sheet.hook.ts
|
|
4292
4795
|
var DISMISS_VELOCITY_THRESHOLD = 0.5;
|
|
4293
4796
|
var DISMISS_DISTANCE_FRACTION = 0.3;
|
|
4294
|
-
var SCREEN_HEIGHT =
|
|
4797
|
+
var SCREEN_HEIGHT = import_react_native42.Dimensions.get("window").height;
|
|
4295
4798
|
var getTranslateYForSnap = (snapFraction) => SCREEN_HEIGHT * (1 - snapFraction);
|
|
4296
4799
|
var useBottomSheetAnimation = ({
|
|
4297
4800
|
isOpen,
|
|
@@ -4302,20 +4805,20 @@ var useBottomSheetAnimation = ({
|
|
|
4302
4805
|
onClose,
|
|
4303
4806
|
onSnapChange
|
|
4304
4807
|
}) => {
|
|
4305
|
-
const [shouldRender, setShouldRender] = (0,
|
|
4306
|
-
const currentSnapIndex = (0,
|
|
4307
|
-
const animationRef = (0,
|
|
4308
|
-
const translateY = (0,
|
|
4309
|
-
const backdropOpacity = (0,
|
|
4310
|
-
const sortedSnapPoints = (0,
|
|
4808
|
+
const [shouldRender, setShouldRender] = (0, import_react49.useState)(false);
|
|
4809
|
+
const currentSnapIndex = (0, import_react49.useRef)(initialSnapIndex);
|
|
4810
|
+
const animationRef = (0, import_react49.useRef)(null);
|
|
4811
|
+
const translateY = (0, import_react49.useRef)(new import_react_native42.Animated.Value(SCREEN_HEIGHT)).current;
|
|
4812
|
+
const backdropOpacity = (0, import_react49.useRef)(new import_react_native42.Animated.Value(0)).current;
|
|
4813
|
+
const sortedSnapPoints = (0, import_react49.useMemo)(
|
|
4311
4814
|
() => [...snapPoints].sort((a, b) => a - b),
|
|
4312
4815
|
[snapPoints]
|
|
4313
4816
|
);
|
|
4314
|
-
const snapTranslateValues = (0,
|
|
4817
|
+
const snapTranslateValues = (0, import_react49.useMemo)(
|
|
4315
4818
|
() => sortedSnapPoints.map(getTranslateYForSnap),
|
|
4316
4819
|
[sortedSnapPoints]
|
|
4317
4820
|
);
|
|
4318
|
-
const open = (0,
|
|
4821
|
+
const open = (0, import_react49.useCallback)(() => {
|
|
4319
4822
|
setShouldRender(true);
|
|
4320
4823
|
const targetIndex = Math.min(initialSnapIndex, sortedSnapPoints.length - 1);
|
|
4321
4824
|
currentSnapIndex.current = targetIndex;
|
|
@@ -4340,7 +4843,7 @@ var useBottomSheetAnimation = ({
|
|
|
4340
4843
|
translateY,
|
|
4341
4844
|
backdropOpacity
|
|
4342
4845
|
]);
|
|
4343
|
-
const close = (0,
|
|
4846
|
+
const close = (0, import_react49.useCallback)(() => {
|
|
4344
4847
|
if (disableAnimation) {
|
|
4345
4848
|
translateY.setValue(SCREEN_HEIGHT);
|
|
4346
4849
|
backdropOpacity.setValue(0);
|
|
@@ -4359,7 +4862,7 @@ var useBottomSheetAnimation = ({
|
|
|
4359
4862
|
}
|
|
4360
4863
|
);
|
|
4361
4864
|
}, [disableAnimation, translateY, backdropOpacity, onClose]);
|
|
4362
|
-
const snapTo = (0,
|
|
4865
|
+
const snapTo = (0, import_react49.useCallback)(
|
|
4363
4866
|
(index) => {
|
|
4364
4867
|
const clampedIndex = Math.max(0, Math.min(index, sortedSnapPoints.length - 1));
|
|
4365
4868
|
currentSnapIndex.current = clampedIndex;
|
|
@@ -4376,15 +4879,15 @@ var useBottomSheetAnimation = ({
|
|
|
4376
4879
|
},
|
|
4377
4880
|
[sortedSnapPoints, snapTranslateValues, disableAnimation, translateY, onSnapChange]
|
|
4378
4881
|
);
|
|
4379
|
-
(0,
|
|
4882
|
+
(0, import_react49.useEffect)(() => {
|
|
4380
4883
|
if (isOpen) {
|
|
4381
4884
|
open();
|
|
4382
4885
|
} else if (shouldRender) {
|
|
4383
4886
|
close();
|
|
4384
4887
|
}
|
|
4385
4888
|
}, [isOpen]);
|
|
4386
|
-
const panResponder = (0,
|
|
4387
|
-
() =>
|
|
4889
|
+
const panResponder = (0, import_react49.useMemo)(
|
|
4890
|
+
() => import_react_native42.PanResponder.create({
|
|
4388
4891
|
onStartShouldSetPanResponder: () => true,
|
|
4389
4892
|
onMoveShouldSetPanResponder: (_, gestureState) => Math.abs(gestureState.dy) > 5,
|
|
4390
4893
|
onPanResponderMove: (_, gestureState) => {
|
|
@@ -4451,9 +4954,9 @@ var useBottomSheetAnimation = ({
|
|
|
4451
4954
|
};
|
|
4452
4955
|
var useBottomSheetStyles = (themeColor, radius) => {
|
|
4453
4956
|
const theme = useXUITheme();
|
|
4454
|
-
const safeThemeColor = (0,
|
|
4957
|
+
const safeThemeColor = (0, import_core34.getSafeThemeColor)(themeColor);
|
|
4455
4958
|
const colorScheme = theme.colors[safeThemeColor];
|
|
4456
|
-
const sheetStyles = (0,
|
|
4959
|
+
const sheetStyles = (0, import_react49.useMemo)(
|
|
4457
4960
|
() => ({
|
|
4458
4961
|
backgroundColor: colorScheme.background ?? theme.colors.background ?? "#ffffff",
|
|
4459
4962
|
borderTopLeftRadius: theme.borderRadius[radius],
|
|
@@ -4461,7 +4964,7 @@ var useBottomSheetStyles = (themeColor, radius) => {
|
|
|
4461
4964
|
}),
|
|
4462
4965
|
[theme, colorScheme, radius]
|
|
4463
4966
|
);
|
|
4464
|
-
const handleIndicatorColor = (0,
|
|
4967
|
+
const handleIndicatorColor = (0, import_react49.useMemo)(
|
|
4465
4968
|
() => theme.mode === "dark" ? `${colorScheme.main}60` : `${colorScheme.main}40`,
|
|
4466
4969
|
[theme, colorScheme]
|
|
4467
4970
|
);
|
|
@@ -4469,8 +4972,8 @@ var useBottomSheetStyles = (themeColor, radius) => {
|
|
|
4469
4972
|
};
|
|
4470
4973
|
|
|
4471
4974
|
// src/components/bottom-sheet/bottom-sheet.style.ts
|
|
4472
|
-
var
|
|
4473
|
-
var
|
|
4975
|
+
var import_react_native43 = require("react-native");
|
|
4976
|
+
var styles13 = import_react_native43.StyleSheet.create({
|
|
4474
4977
|
backdrop: {
|
|
4475
4978
|
position: "absolute",
|
|
4476
4979
|
top: 0,
|
|
@@ -4549,50 +5052,50 @@ var BottomSheet = ({
|
|
|
4549
5052
|
close();
|
|
4550
5053
|
}
|
|
4551
5054
|
};
|
|
4552
|
-
return /* @__PURE__ */
|
|
4553
|
-
|
|
5055
|
+
return /* @__PURE__ */ import_react50.default.createElement(Portal, null, showBackdrop && /* @__PURE__ */ import_react50.default.createElement(
|
|
5056
|
+
import_react_native44.Animated.View,
|
|
4554
5057
|
{
|
|
4555
|
-
style: [
|
|
5058
|
+
style: [styles13.backdrop, { opacity: backdropOpacity }]
|
|
4556
5059
|
},
|
|
4557
|
-
/* @__PURE__ */
|
|
4558
|
-
|
|
5060
|
+
/* @__PURE__ */ import_react50.default.createElement(
|
|
5061
|
+
import_react_native44.Pressable,
|
|
4559
5062
|
{
|
|
4560
|
-
style:
|
|
5063
|
+
style: styles13.backdrop,
|
|
4561
5064
|
onPress: handleBackdropPress
|
|
4562
5065
|
}
|
|
4563
5066
|
)
|
|
4564
|
-
), /* @__PURE__ */
|
|
4565
|
-
|
|
5067
|
+
), /* @__PURE__ */ import_react50.default.createElement(
|
|
5068
|
+
import_react_native44.Animated.View,
|
|
4566
5069
|
{
|
|
4567
5070
|
style: [
|
|
4568
|
-
|
|
5071
|
+
styles13.container,
|
|
4569
5072
|
{
|
|
4570
5073
|
height: screenHeight,
|
|
4571
5074
|
transform: [{ translateY }]
|
|
4572
5075
|
}
|
|
4573
5076
|
]
|
|
4574
5077
|
},
|
|
4575
|
-
/* @__PURE__ */
|
|
4576
|
-
|
|
5078
|
+
/* @__PURE__ */ import_react50.default.createElement(
|
|
5079
|
+
import_react_native44.View,
|
|
4577
5080
|
{
|
|
4578
5081
|
style: [
|
|
4579
|
-
|
|
5082
|
+
styles13.sheet,
|
|
4580
5083
|
{ height: screenHeight },
|
|
4581
5084
|
sheetStyles,
|
|
4582
5085
|
style
|
|
4583
5086
|
],
|
|
4584
5087
|
...panResponder.panHandlers
|
|
4585
5088
|
},
|
|
4586
|
-
showHandle && /* @__PURE__ */
|
|
4587
|
-
|
|
5089
|
+
showHandle && /* @__PURE__ */ import_react50.default.createElement(import_react_native44.View, { style: styles13.handle }, handleContent ?? /* @__PURE__ */ import_react50.default.createElement(
|
|
5090
|
+
import_react_native44.View,
|
|
4588
5091
|
{
|
|
4589
5092
|
style: [
|
|
4590
|
-
|
|
5093
|
+
styles13.handleIndicator,
|
|
4591
5094
|
{ backgroundColor: handleIndicatorColor }
|
|
4592
5095
|
]
|
|
4593
5096
|
}
|
|
4594
5097
|
)),
|
|
4595
|
-
/* @__PURE__ */
|
|
5098
|
+
/* @__PURE__ */ import_react50.default.createElement(import_react_native44.View, { style: styles13.content }, children)
|
|
4596
5099
|
)
|
|
4597
5100
|
));
|
|
4598
5101
|
};
|
|
@@ -4606,6 +5109,9 @@ var BottomSheet = ({
|
|
|
4606
5109
|
AvatarGroup,
|
|
4607
5110
|
Badge,
|
|
4608
5111
|
BottomSheet,
|
|
5112
|
+
Chip,
|
|
5113
|
+
ChipGroup,
|
|
5114
|
+
ChipItem,
|
|
4609
5115
|
DatePicker,
|
|
4610
5116
|
Divider,
|
|
4611
5117
|
Typography
|