@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
|
@@ -0,0 +1,584 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/components/chip/index.ts
|
|
31
|
+
var chip_exports = {};
|
|
32
|
+
__export(chip_exports, {
|
|
33
|
+
Chip: () => Chip,
|
|
34
|
+
ChipGroup: () => ChipGroup,
|
|
35
|
+
ChipItem: () => ChipItem
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(chip_exports);
|
|
38
|
+
|
|
39
|
+
// src/components/chip/chip.tsx
|
|
40
|
+
var import_react7 = __toESM(require("react"), 1);
|
|
41
|
+
var import_react_native5 = require("react-native");
|
|
42
|
+
|
|
43
|
+
// src/components/chip/chip.style.ts
|
|
44
|
+
var import_react_native = require("react-native");
|
|
45
|
+
var styles = import_react_native.StyleSheet.create({
|
|
46
|
+
chip: {
|
|
47
|
+
flexDirection: "row",
|
|
48
|
+
alignItems: "center",
|
|
49
|
+
alignSelf: "flex-start"
|
|
50
|
+
},
|
|
51
|
+
text: {
|
|
52
|
+
fontWeight: "500",
|
|
53
|
+
includeFontPadding: false,
|
|
54
|
+
textAlignVertical: "center"
|
|
55
|
+
},
|
|
56
|
+
disabled: {
|
|
57
|
+
opacity: 0.5
|
|
58
|
+
},
|
|
59
|
+
avatar: {
|
|
60
|
+
marginRight: 4
|
|
61
|
+
},
|
|
62
|
+
startContent: {
|
|
63
|
+
marginRight: 4
|
|
64
|
+
},
|
|
65
|
+
endContent: {
|
|
66
|
+
marginLeft: 4
|
|
67
|
+
},
|
|
68
|
+
closeButton: {
|
|
69
|
+
marginLeft: 4,
|
|
70
|
+
alignItems: "center",
|
|
71
|
+
justifyContent: "center"
|
|
72
|
+
},
|
|
73
|
+
dot: {
|
|
74
|
+
borderRadius: 9999,
|
|
75
|
+
marginRight: 6
|
|
76
|
+
},
|
|
77
|
+
groupContainer: {
|
|
78
|
+
flexDirection: "row",
|
|
79
|
+
flexWrap: "wrap"
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
// src/components/chip/chip.hook.ts
|
|
84
|
+
var import_react6 = require("react");
|
|
85
|
+
var import_core = require("@xaui/core");
|
|
86
|
+
|
|
87
|
+
// src/core/theme-context.tsx
|
|
88
|
+
var import_react4 = __toESM(require("react"), 1);
|
|
89
|
+
var import_react_native3 = require("react-native");
|
|
90
|
+
var import_theme = require("@xaui/core/theme");
|
|
91
|
+
var import_palette = require("@xaui/core/palette");
|
|
92
|
+
|
|
93
|
+
// src/core/portal/portal.tsx
|
|
94
|
+
var import_react2 = require("react");
|
|
95
|
+
|
|
96
|
+
// src/core/portal/portal-context.ts
|
|
97
|
+
var import_react = require("react");
|
|
98
|
+
var PortalContext = (0, import_react.createContext)(null);
|
|
99
|
+
|
|
100
|
+
// src/core/portal/portal-host.tsx
|
|
101
|
+
var import_react3 = __toESM(require("react"), 1);
|
|
102
|
+
var import_react_native2 = require("react-native");
|
|
103
|
+
var hostStyles = import_react_native2.StyleSheet.create({
|
|
104
|
+
container: {
|
|
105
|
+
flex: 1
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
// src/core/theme-context.tsx
|
|
110
|
+
var XUIThemeContext = (0, import_react4.createContext)(null);
|
|
111
|
+
|
|
112
|
+
// src/core/theme-hooks.ts
|
|
113
|
+
var import_react5 = require("react");
|
|
114
|
+
var import_react_native4 = require("react-native");
|
|
115
|
+
function useXUITheme() {
|
|
116
|
+
const theme = (0, import_react5.useContext)(XUIThemeContext);
|
|
117
|
+
if (!theme) {
|
|
118
|
+
throw new Error("useXUITheme must be used within XUIProvider");
|
|
119
|
+
}
|
|
120
|
+
return theme;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// src/core/index.ts
|
|
124
|
+
var import_theme2 = require("@xaui/core/theme");
|
|
125
|
+
|
|
126
|
+
// src/components/chip/chip.hook.ts
|
|
127
|
+
var sizeMap = {
|
|
128
|
+
sm: { height: 32, paddingH: 12, fontSize: 13 },
|
|
129
|
+
md: { height: 40, paddingH: 16, fontSize: 15 },
|
|
130
|
+
lg: { height: 44, paddingH: 18, fontSize: 17 }
|
|
131
|
+
};
|
|
132
|
+
var dotSizeMap = {
|
|
133
|
+
sm: 8,
|
|
134
|
+
md: 10,
|
|
135
|
+
lg: 11
|
|
136
|
+
};
|
|
137
|
+
var closeSizeMap = {
|
|
138
|
+
sm: 14,
|
|
139
|
+
md: 16,
|
|
140
|
+
lg: 17
|
|
141
|
+
};
|
|
142
|
+
function useChipSizeStyles(size) {
|
|
143
|
+
return (0, import_react6.useMemo)(() => {
|
|
144
|
+
const { height, paddingH, fontSize } = sizeMap[size];
|
|
145
|
+
return { height, paddingHorizontal: paddingH, fontSize };
|
|
146
|
+
}, [size]);
|
|
147
|
+
}
|
|
148
|
+
function useChipDotSize(size) {
|
|
149
|
+
return (0, import_react6.useMemo)(() => dotSizeMap[size], [size]);
|
|
150
|
+
}
|
|
151
|
+
function useChipCloseSize(size) {
|
|
152
|
+
return (0, import_react6.useMemo)(() => closeSizeMap[size], [size]);
|
|
153
|
+
}
|
|
154
|
+
function useChipRadiusStyles(radius, height) {
|
|
155
|
+
const theme = useXUITheme();
|
|
156
|
+
return (0, import_react6.useMemo)(() => {
|
|
157
|
+
if (radius === "full") {
|
|
158
|
+
return { borderRadius: height / 2 };
|
|
159
|
+
}
|
|
160
|
+
return { borderRadius: theme.borderRadius[radius] };
|
|
161
|
+
}, [height, radius, theme.borderRadius]);
|
|
162
|
+
}
|
|
163
|
+
function useChipVariantStyles(themeColor, variant) {
|
|
164
|
+
const theme = useXUITheme();
|
|
165
|
+
const safeColor = (0, import_core.getSafeThemeColor)(themeColor);
|
|
166
|
+
const colorScheme = theme.colors[safeColor];
|
|
167
|
+
return (0, import_react6.useMemo)(() => {
|
|
168
|
+
switch (variant) {
|
|
169
|
+
case "bordered":
|
|
170
|
+
return {
|
|
171
|
+
backgroundColor: "transparent",
|
|
172
|
+
color: colorScheme.main,
|
|
173
|
+
borderWidth: 2,
|
|
174
|
+
borderColor: colorScheme.main
|
|
175
|
+
};
|
|
176
|
+
case "light":
|
|
177
|
+
return {
|
|
178
|
+
backgroundColor: "transparent",
|
|
179
|
+
color: colorScheme.main
|
|
180
|
+
};
|
|
181
|
+
case "flat":
|
|
182
|
+
return {
|
|
183
|
+
backgroundColor: colorScheme.background,
|
|
184
|
+
color: colorScheme.main
|
|
185
|
+
};
|
|
186
|
+
case "faded":
|
|
187
|
+
return {
|
|
188
|
+
backgroundColor: (0, import_core.withOpacity)(colorScheme.background, 0.7),
|
|
189
|
+
color: colorScheme.main,
|
|
190
|
+
borderWidth: 1,
|
|
191
|
+
borderColor: (0, import_core.withOpacity)(colorScheme.main, 0.3)
|
|
192
|
+
};
|
|
193
|
+
case "shadow":
|
|
194
|
+
return {
|
|
195
|
+
backgroundColor: colorScheme.main,
|
|
196
|
+
color: colorScheme.foreground,
|
|
197
|
+
shadow: theme.shadows.sm
|
|
198
|
+
};
|
|
199
|
+
case "dot":
|
|
200
|
+
return {
|
|
201
|
+
backgroundColor: colorScheme.background,
|
|
202
|
+
color: colorScheme.main,
|
|
203
|
+
dotColor: colorScheme.main
|
|
204
|
+
};
|
|
205
|
+
case "solid":
|
|
206
|
+
default:
|
|
207
|
+
return {
|
|
208
|
+
backgroundColor: colorScheme.main,
|
|
209
|
+
color: colorScheme.foreground
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
}, [colorScheme, theme, variant]);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// src/components/chip/chip.tsx
|
|
216
|
+
var Chip = ({
|
|
217
|
+
children,
|
|
218
|
+
variant = "solid",
|
|
219
|
+
themeColor = "default",
|
|
220
|
+
size = "md",
|
|
221
|
+
radius = "full",
|
|
222
|
+
avatar,
|
|
223
|
+
startContent,
|
|
224
|
+
endContent,
|
|
225
|
+
isDisabled = false,
|
|
226
|
+
customAppearance,
|
|
227
|
+
onClose,
|
|
228
|
+
onPress
|
|
229
|
+
}) => {
|
|
230
|
+
const [isClosed, setIsClosed] = import_react7.default.useState(false);
|
|
231
|
+
const [isClosing, setIsClosing] = import_react7.default.useState(false);
|
|
232
|
+
const sizeStyles = useChipSizeStyles(size);
|
|
233
|
+
const radiusStyles = useChipRadiusStyles(radius, sizeStyles.height);
|
|
234
|
+
const variantStyles = useChipVariantStyles(themeColor, variant);
|
|
235
|
+
const dotSize = useChipDotSize(size);
|
|
236
|
+
const closeSize = useChipCloseSize(size);
|
|
237
|
+
const isDotVariant = variant === "dot";
|
|
238
|
+
const hasClose = onClose !== void 0;
|
|
239
|
+
const isInteractive = onPress !== void 0 || hasClose;
|
|
240
|
+
const scale = import_react7.default.useRef(new import_react_native5.Animated.Value(1)).current;
|
|
241
|
+
const opacity = import_react7.default.useRef(new import_react_native5.Animated.Value(1)).current;
|
|
242
|
+
const isClosingRef = import_react7.default.useRef(false);
|
|
243
|
+
const colorProgress = import_react7.default.useRef(new import_react_native5.Animated.Value(1)).current;
|
|
244
|
+
const targetBackgroundColor = variantStyles.backgroundColor ?? "transparent";
|
|
245
|
+
const targetBorderColor = variantStyles.borderColor ?? "transparent";
|
|
246
|
+
const targetTextColor = variantStyles.color ?? "#000000";
|
|
247
|
+
const targetDotColor = variantStyles.dotColor ?? targetTextColor;
|
|
248
|
+
const previousColorsRef = import_react7.default.useRef({
|
|
249
|
+
backgroundColor: targetBackgroundColor,
|
|
250
|
+
borderColor: targetBorderColor,
|
|
251
|
+
textColor: targetTextColor,
|
|
252
|
+
dotColor: targetDotColor
|
|
253
|
+
});
|
|
254
|
+
import_react7.default.useEffect(() => {
|
|
255
|
+
if (previousColorsRef.current.backgroundColor === targetBackgroundColor && previousColorsRef.current.borderColor === targetBorderColor && previousColorsRef.current.textColor === targetTextColor && previousColorsRef.current.dotColor === targetDotColor) {
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
colorProgress.setValue(0);
|
|
259
|
+
import_react_native5.Animated.timing(colorProgress, {
|
|
260
|
+
toValue: 1,
|
|
261
|
+
duration: 180,
|
|
262
|
+
easing: import_react_native5.Easing.out(import_react_native5.Easing.cubic),
|
|
263
|
+
useNativeDriver: false
|
|
264
|
+
}).start(() => {
|
|
265
|
+
previousColorsRef.current = {
|
|
266
|
+
backgroundColor: targetBackgroundColor,
|
|
267
|
+
borderColor: targetBorderColor,
|
|
268
|
+
textColor: targetTextColor,
|
|
269
|
+
dotColor: targetDotColor
|
|
270
|
+
};
|
|
271
|
+
});
|
|
272
|
+
}, [
|
|
273
|
+
colorProgress,
|
|
274
|
+
targetBackgroundColor,
|
|
275
|
+
targetBorderColor,
|
|
276
|
+
targetTextColor,
|
|
277
|
+
targetDotColor
|
|
278
|
+
]);
|
|
279
|
+
const animatedBackgroundColor = colorProgress.interpolate({
|
|
280
|
+
inputRange: [0, 1],
|
|
281
|
+
outputRange: [
|
|
282
|
+
previousColorsRef.current.backgroundColor,
|
|
283
|
+
targetBackgroundColor
|
|
284
|
+
]
|
|
285
|
+
});
|
|
286
|
+
const animatedBorderColor = colorProgress.interpolate({
|
|
287
|
+
inputRange: [0, 1],
|
|
288
|
+
outputRange: [previousColorsRef.current.borderColor, targetBorderColor]
|
|
289
|
+
});
|
|
290
|
+
const animatedTextColor = colorProgress.interpolate({
|
|
291
|
+
inputRange: [0, 1],
|
|
292
|
+
outputRange: [previousColorsRef.current.textColor, targetTextColor]
|
|
293
|
+
});
|
|
294
|
+
const animatedDotColor = colorProgress.interpolate({
|
|
295
|
+
inputRange: [0, 1],
|
|
296
|
+
outputRange: [previousColorsRef.current.dotColor, targetDotColor]
|
|
297
|
+
});
|
|
298
|
+
const handlePressIn = import_react7.default.useCallback(() => {
|
|
299
|
+
if (!isInteractive || isDisabled || isClosing || hasClose) return;
|
|
300
|
+
import_react_native5.Animated.timing(scale, {
|
|
301
|
+
toValue: 0.97,
|
|
302
|
+
duration: 90,
|
|
303
|
+
easing: import_react_native5.Easing.out(import_react_native5.Easing.cubic),
|
|
304
|
+
useNativeDriver: true
|
|
305
|
+
}).start();
|
|
306
|
+
}, [hasClose, isInteractive, isClosing, isDisabled, scale]);
|
|
307
|
+
const handlePressOut = import_react7.default.useCallback(() => {
|
|
308
|
+
if (!isInteractive || isDisabled || isClosing || hasClose) return;
|
|
309
|
+
import_react_native5.Animated.timing(scale, {
|
|
310
|
+
toValue: 1,
|
|
311
|
+
duration: 120,
|
|
312
|
+
easing: import_react_native5.Easing.out(import_react_native5.Easing.cubic),
|
|
313
|
+
useNativeDriver: true
|
|
314
|
+
}).start();
|
|
315
|
+
}, [hasClose, isInteractive, isClosing, isDisabled, scale]);
|
|
316
|
+
const handleChipPress = import_react7.default.useCallback(() => {
|
|
317
|
+
if (isDisabled || isClosing || isClosingRef.current) return;
|
|
318
|
+
if (hasClose && onClose) {
|
|
319
|
+
isClosingRef.current = true;
|
|
320
|
+
setIsClosing(true);
|
|
321
|
+
import_react_native5.Animated.parallel([
|
|
322
|
+
import_react_native5.Animated.timing(opacity, {
|
|
323
|
+
toValue: 0,
|
|
324
|
+
duration: 180,
|
|
325
|
+
easing: import_react_native5.Easing.in(import_react_native5.Easing.quad),
|
|
326
|
+
useNativeDriver: true
|
|
327
|
+
}),
|
|
328
|
+
import_react_native5.Animated.timing(scale, {
|
|
329
|
+
toValue: 0.88,
|
|
330
|
+
duration: 180,
|
|
331
|
+
easing: import_react_native5.Easing.in(import_react_native5.Easing.quad),
|
|
332
|
+
useNativeDriver: true
|
|
333
|
+
})
|
|
334
|
+
]).start(() => {
|
|
335
|
+
setIsClosed(true);
|
|
336
|
+
onClose();
|
|
337
|
+
setIsClosing(false);
|
|
338
|
+
isClosingRef.current = false;
|
|
339
|
+
});
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
onPress?.();
|
|
343
|
+
}, [hasClose, isClosing, isDisabled, onClose, onPress, opacity, scale]);
|
|
344
|
+
if (isClosed) {
|
|
345
|
+
return null;
|
|
346
|
+
}
|
|
347
|
+
const chipContent = /* @__PURE__ */ import_react7.default.createElement(import_react_native5.Animated.View, { style: { transform: [{ scale }], opacity } }, /* @__PURE__ */ import_react7.default.createElement(
|
|
348
|
+
import_react_native5.Animated.View,
|
|
349
|
+
{
|
|
350
|
+
style: [
|
|
351
|
+
styles.chip,
|
|
352
|
+
{
|
|
353
|
+
height: sizeStyles.height,
|
|
354
|
+
paddingHorizontal: sizeStyles.paddingHorizontal,
|
|
355
|
+
backgroundColor: animatedBackgroundColor,
|
|
356
|
+
borderWidth: variantStyles.borderWidth,
|
|
357
|
+
borderColor: animatedBorderColor
|
|
358
|
+
},
|
|
359
|
+
radiusStyles,
|
|
360
|
+
variantStyles.shadow,
|
|
361
|
+
isDisabled && styles.disabled,
|
|
362
|
+
customAppearance?.container
|
|
363
|
+
],
|
|
364
|
+
accessible: true,
|
|
365
|
+
accessibilityRole: "text"
|
|
366
|
+
},
|
|
367
|
+
isDotVariant && /* @__PURE__ */ import_react7.default.createElement(
|
|
368
|
+
import_react_native5.Animated.View,
|
|
369
|
+
{
|
|
370
|
+
style: [
|
|
371
|
+
styles.dot,
|
|
372
|
+
{
|
|
373
|
+
width: dotSize,
|
|
374
|
+
height: dotSize,
|
|
375
|
+
backgroundColor: animatedDotColor
|
|
376
|
+
},
|
|
377
|
+
customAppearance?.dot
|
|
378
|
+
]
|
|
379
|
+
}
|
|
380
|
+
),
|
|
381
|
+
avatar && /* @__PURE__ */ import_react7.default.createElement(import_react_native5.View, { style: styles.avatar }, avatar),
|
|
382
|
+
startContent && !avatar && /* @__PURE__ */ import_react7.default.createElement(import_react_native5.View, { style: styles.startContent }, startContent),
|
|
383
|
+
/* @__PURE__ */ import_react7.default.createElement(
|
|
384
|
+
import_react_native5.Animated.Text,
|
|
385
|
+
{
|
|
386
|
+
style: [
|
|
387
|
+
styles.text,
|
|
388
|
+
{ fontSize: sizeStyles.fontSize, color: animatedTextColor },
|
|
389
|
+
customAppearance?.text
|
|
390
|
+
]
|
|
391
|
+
},
|
|
392
|
+
children
|
|
393
|
+
),
|
|
394
|
+
endContent && !hasClose && /* @__PURE__ */ import_react7.default.createElement(import_react_native5.View, { style: styles.endContent }, endContent),
|
|
395
|
+
hasClose && /* @__PURE__ */ import_react7.default.createElement(
|
|
396
|
+
import_react_native5.View,
|
|
397
|
+
{
|
|
398
|
+
style: [
|
|
399
|
+
styles.closeButton,
|
|
400
|
+
{ width: closeSize, height: closeSize },
|
|
401
|
+
customAppearance?.closeButton
|
|
402
|
+
]
|
|
403
|
+
},
|
|
404
|
+
/* @__PURE__ */ import_react7.default.createElement(
|
|
405
|
+
import_react_native5.Animated.Text,
|
|
406
|
+
{
|
|
407
|
+
style: {
|
|
408
|
+
fontSize: closeSize - 2,
|
|
409
|
+
color: animatedTextColor,
|
|
410
|
+
lineHeight: closeSize
|
|
411
|
+
}
|
|
412
|
+
},
|
|
413
|
+
"\u2715"
|
|
414
|
+
)
|
|
415
|
+
)
|
|
416
|
+
));
|
|
417
|
+
if (isInteractive) {
|
|
418
|
+
return /* @__PURE__ */ import_react7.default.createElement(
|
|
419
|
+
import_react_native5.Pressable,
|
|
420
|
+
{
|
|
421
|
+
onPress: isDisabled || isClosing ? void 0 : handleChipPress,
|
|
422
|
+
onPressIn: handlePressIn,
|
|
423
|
+
onPressOut: handlePressOut,
|
|
424
|
+
disabled: isDisabled || isClosing
|
|
425
|
+
},
|
|
426
|
+
chipContent
|
|
427
|
+
);
|
|
428
|
+
}
|
|
429
|
+
return chipContent;
|
|
430
|
+
};
|
|
431
|
+
|
|
432
|
+
// src/components/chip/chip-group.tsx
|
|
433
|
+
var import_react10 = __toESM(require("react"), 1);
|
|
434
|
+
var import_react_native6 = require("react-native");
|
|
435
|
+
|
|
436
|
+
// src/components/chip/chip-context.ts
|
|
437
|
+
var import_react8 = require("react");
|
|
438
|
+
var ChipGroupContext = (0, import_react8.createContext)(null);
|
|
439
|
+
|
|
440
|
+
// src/components/chip/chip-group.hook.ts
|
|
441
|
+
var import_react9 = require("react");
|
|
442
|
+
function useChipGroupSelection(selectMode, selectedValues, defaultSelectedValues, onSelectionChange) {
|
|
443
|
+
const [internalValues, setInternalValues] = (0, import_react9.useState)(
|
|
444
|
+
defaultSelectedValues ?? []
|
|
445
|
+
);
|
|
446
|
+
const isControlled = selectedValues !== void 0;
|
|
447
|
+
const currentValues = isControlled ? selectedValues : internalValues;
|
|
448
|
+
const onToggle = (0, import_react9.useCallback)(
|
|
449
|
+
(value) => {
|
|
450
|
+
const isSelected = currentValues.includes(value);
|
|
451
|
+
let nextValues;
|
|
452
|
+
if (selectMode === "single") {
|
|
453
|
+
nextValues = isSelected ? [] : [value];
|
|
454
|
+
} else {
|
|
455
|
+
nextValues = isSelected ? currentValues.filter((v) => v !== value) : [...currentValues, value];
|
|
456
|
+
}
|
|
457
|
+
if (!isControlled) {
|
|
458
|
+
setInternalValues(nextValues);
|
|
459
|
+
}
|
|
460
|
+
onSelectionChange?.(nextValues);
|
|
461
|
+
},
|
|
462
|
+
[currentValues, isControlled, onSelectionChange, selectMode]
|
|
463
|
+
);
|
|
464
|
+
return (0, import_react9.useMemo)(
|
|
465
|
+
() => ({ currentValues, onToggle }),
|
|
466
|
+
[currentValues, onToggle]
|
|
467
|
+
);
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
// src/components/chip/chip-group.tsx
|
|
471
|
+
var ChipGroup = ({
|
|
472
|
+
children,
|
|
473
|
+
isSelectable = false,
|
|
474
|
+
selectMode = "single",
|
|
475
|
+
variant = "solid",
|
|
476
|
+
themeColor = "default",
|
|
477
|
+
size = "md",
|
|
478
|
+
radius = "full",
|
|
479
|
+
isDisabled = false,
|
|
480
|
+
selectedValues,
|
|
481
|
+
defaultSelectedValues,
|
|
482
|
+
onSelectionChange,
|
|
483
|
+
spacing = 8,
|
|
484
|
+
customAppearance
|
|
485
|
+
}) => {
|
|
486
|
+
const { currentValues, onToggle } = useChipGroupSelection(
|
|
487
|
+
selectMode,
|
|
488
|
+
selectedValues,
|
|
489
|
+
defaultSelectedValues,
|
|
490
|
+
onSelectionChange
|
|
491
|
+
);
|
|
492
|
+
const contextValue = import_react10.default.useMemo(
|
|
493
|
+
() => ({
|
|
494
|
+
variant,
|
|
495
|
+
themeColor,
|
|
496
|
+
size,
|
|
497
|
+
radius,
|
|
498
|
+
isDisabled,
|
|
499
|
+
isSelectable,
|
|
500
|
+
selectMode,
|
|
501
|
+
selectedValues: currentValues,
|
|
502
|
+
onToggle
|
|
503
|
+
}),
|
|
504
|
+
[
|
|
505
|
+
variant,
|
|
506
|
+
themeColor,
|
|
507
|
+
size,
|
|
508
|
+
radius,
|
|
509
|
+
isDisabled,
|
|
510
|
+
isSelectable,
|
|
511
|
+
selectMode,
|
|
512
|
+
currentValues,
|
|
513
|
+
onToggle
|
|
514
|
+
]
|
|
515
|
+
);
|
|
516
|
+
return /* @__PURE__ */ import_react10.default.createElement(ChipGroupContext.Provider, { value: contextValue }, /* @__PURE__ */ import_react10.default.createElement(
|
|
517
|
+
import_react_native6.View,
|
|
518
|
+
{
|
|
519
|
+
style: [
|
|
520
|
+
styles.groupContainer,
|
|
521
|
+
{ gap: spacing },
|
|
522
|
+
customAppearance?.container
|
|
523
|
+
],
|
|
524
|
+
accessible: true
|
|
525
|
+
},
|
|
526
|
+
children
|
|
527
|
+
));
|
|
528
|
+
};
|
|
529
|
+
|
|
530
|
+
// src/components/chip/chip-item.tsx
|
|
531
|
+
var import_react11 = __toESM(require("react"), 1);
|
|
532
|
+
function getSelectableVariant(baseVariant, isSelected) {
|
|
533
|
+
if (isSelected) {
|
|
534
|
+
return baseVariant;
|
|
535
|
+
}
|
|
536
|
+
if (baseVariant === "solid" || baseVariant === "shadow") {
|
|
537
|
+
return "bordered";
|
|
538
|
+
}
|
|
539
|
+
return "light";
|
|
540
|
+
}
|
|
541
|
+
var ChipItem = ({
|
|
542
|
+
value,
|
|
543
|
+
children,
|
|
544
|
+
variant,
|
|
545
|
+
themeColor,
|
|
546
|
+
avatar,
|
|
547
|
+
startContent,
|
|
548
|
+
endContent,
|
|
549
|
+
isDisabled,
|
|
550
|
+
customAppearance
|
|
551
|
+
}) => {
|
|
552
|
+
const groupContext = (0, import_react11.useContext)(ChipGroupContext);
|
|
553
|
+
if (!groupContext) {
|
|
554
|
+
return null;
|
|
555
|
+
}
|
|
556
|
+
const resolvedVariant = variant ?? groupContext.variant;
|
|
557
|
+
const resolvedColor = themeColor ?? groupContext.themeColor;
|
|
558
|
+
const resolvedDisabled = isDisabled ?? groupContext.isDisabled;
|
|
559
|
+
const isSelected = groupContext.selectedValues.includes(value);
|
|
560
|
+
const chipVariant = groupContext.isSelectable ? getSelectableVariant(resolvedVariant, isSelected) : resolvedVariant;
|
|
561
|
+
const handlePress = groupContext.isSelectable ? () => groupContext.onToggle(value) : void 0;
|
|
562
|
+
return /* @__PURE__ */ import_react11.default.createElement(
|
|
563
|
+
Chip,
|
|
564
|
+
{
|
|
565
|
+
variant: chipVariant,
|
|
566
|
+
themeColor: resolvedColor,
|
|
567
|
+
size: groupContext.size,
|
|
568
|
+
radius: groupContext.radius,
|
|
569
|
+
isDisabled: resolvedDisabled,
|
|
570
|
+
avatar,
|
|
571
|
+
startContent,
|
|
572
|
+
endContent,
|
|
573
|
+
customAppearance,
|
|
574
|
+
onPress: handlePress
|
|
575
|
+
},
|
|
576
|
+
children
|
|
577
|
+
);
|
|
578
|
+
};
|
|
579
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
580
|
+
0 && (module.exports = {
|
|
581
|
+
Chip,
|
|
582
|
+
ChipGroup,
|
|
583
|
+
ChipItem
|
|
584
|
+
});
|