@xaui/native 0.0.16 → 0.0.18
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/accordion/index.cjs +1 -1
- package/dist/accordion/index.js +5 -4
- package/dist/alert/index.js +352 -3
- package/dist/autocomplete/index.cjs +5 -11
- package/dist/autocomplete/index.js +1122 -5
- package/dist/avatar/index.js +276 -4
- package/dist/badge/index.js +193 -3
- package/dist/bottom-sheet/index.cjs +9 -20
- package/dist/bottom-sheet/index.js +364 -3
- package/dist/button/index.js +3 -2
- package/dist/card/index.cjs +429 -0
- package/dist/card/index.d.cts +186 -0
- package/dist/card/index.d.ts +186 -0
- package/dist/card/index.js +336 -0
- package/dist/carousel/index.cjs +458 -0
- package/dist/carousel/index.d.cts +147 -0
- package/dist/carousel/index.d.ts +147 -0
- package/dist/carousel/index.js +381 -0
- package/dist/checkbox/index.js +2 -1
- package/dist/chip/index.cjs +2 -8
- package/dist/chip/index.js +497 -5
- package/dist/chunk-DXXNBF5P.js +7 -0
- package/dist/{chunk-MKHBEJLO.js → chunk-F7WH4DMG.js} +1 -1
- package/dist/{chunk-II4QINLG.js → chunk-JEGEPGVU.js} +2 -2
- package/dist/{chunk-NBRASCX4.js → chunk-LTKYHG5V.js} +6 -13
- package/dist/{chunk-GNJIET26.js → chunk-LUBWRVI2.js} +1 -1
- package/dist/core/index.cjs +1 -1
- package/dist/core/index.js +5 -3
- package/dist/datepicker/index.js +1623 -3
- package/dist/divider/index.js +3 -2
- package/dist/fab/index.js +4 -3
- package/dist/fab-menu/index.cjs +4 -13
- package/dist/fab-menu/index.js +325 -6
- package/dist/index.cjs +0 -5709
- package/dist/index.d.cts +2 -17
- package/dist/index.d.ts +2 -17
- package/dist/index.js +0 -62
- package/dist/indicator/index.js +3 -2
- package/dist/menu/index.cjs +8 -7
- package/dist/menu/index.js +15 -9
- package/dist/progress/index.js +2 -1
- package/dist/segment-button/index.cjs +492 -0
- package/dist/segment-button/index.d.cts +141 -0
- package/dist/segment-button/index.d.ts +141 -0
- package/dist/segment-button/index.js +405 -0
- package/dist/select/index.js +2 -1
- package/dist/switch/index.js +2 -1
- package/dist/typography/index.js +146 -3
- package/dist/view/index.cjs +153 -78
- package/dist/view/index.d.cts +77 -1
- package/dist/view/index.d.ts +77 -1
- package/dist/view/index.js +125 -52
- package/package.json +16 -1
- package/dist/chunk-2T6FKPJW.js +0 -356
- package/dist/chunk-4LFRYVSR.js +0 -281
- package/dist/chunk-7OFTYKK4.js +0 -1627
- package/dist/chunk-EI5OMBFE.js +0 -338
- package/dist/chunk-GAOI4KIV.js +0 -379
- package/dist/chunk-NMZUPH3R.js +0 -1133
- package/dist/chunk-QLEQYKG5.js +0 -509
- package/dist/chunk-XJKA22BK.js +0 -197
- package/dist/chunk-ZYTBRHLJ.js +0 -150
|
@@ -0,0 +1,492 @@
|
|
|
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/segment-button/index.ts
|
|
31
|
+
var segment_button_exports = {};
|
|
32
|
+
__export(segment_button_exports, {
|
|
33
|
+
SegmentButton: () => SegmentButton,
|
|
34
|
+
SegmentButtonItem: () => SegmentButtonItem
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(segment_button_exports);
|
|
37
|
+
|
|
38
|
+
// src/components/segment-button/segment-button.tsx
|
|
39
|
+
var import_react8 = __toESM(require("react"), 1);
|
|
40
|
+
var import_react_native5 = require("react-native");
|
|
41
|
+
|
|
42
|
+
// src/components/segment-button/segment-button.style.ts
|
|
43
|
+
var import_react_native = require("react-native");
|
|
44
|
+
var styles = import_react_native.StyleSheet.create({
|
|
45
|
+
container: {
|
|
46
|
+
flexDirection: "row",
|
|
47
|
+
alignItems: "stretch",
|
|
48
|
+
overflow: "hidden",
|
|
49
|
+
alignSelf: "flex-start"
|
|
50
|
+
},
|
|
51
|
+
fullWidth: {
|
|
52
|
+
width: "100%",
|
|
53
|
+
alignSelf: "stretch"
|
|
54
|
+
},
|
|
55
|
+
segment: {
|
|
56
|
+
flex: 1
|
|
57
|
+
},
|
|
58
|
+
segmentInner: {
|
|
59
|
+
flex: 1,
|
|
60
|
+
flexDirection: "row",
|
|
61
|
+
alignItems: "center",
|
|
62
|
+
justifyContent: "center"
|
|
63
|
+
},
|
|
64
|
+
segmentContent: {
|
|
65
|
+
flexDirection: "row",
|
|
66
|
+
alignItems: "center",
|
|
67
|
+
justifyContent: "center",
|
|
68
|
+
gap: 4
|
|
69
|
+
},
|
|
70
|
+
segmentText: {
|
|
71
|
+
fontWeight: "500",
|
|
72
|
+
textAlign: "center"
|
|
73
|
+
},
|
|
74
|
+
disabled: {
|
|
75
|
+
opacity: 0.5
|
|
76
|
+
},
|
|
77
|
+
divider: {
|
|
78
|
+
width: 1,
|
|
79
|
+
alignSelf: "stretch"
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
// src/components/segment-button/segment-button.hook.ts
|
|
84
|
+
var import_react6 = require("react");
|
|
85
|
+
|
|
86
|
+
// src/core/theme-context.tsx
|
|
87
|
+
var import_react4 = __toESM(require("react"), 1);
|
|
88
|
+
var import_react_native3 = require("react-native");
|
|
89
|
+
var import_theme = require("@xaui/core/theme");
|
|
90
|
+
var import_palette = require("@xaui/core/palette");
|
|
91
|
+
|
|
92
|
+
// src/core/portal/portal.tsx
|
|
93
|
+
var import_react2 = require("react");
|
|
94
|
+
|
|
95
|
+
// src/core/portal/portal-context.ts
|
|
96
|
+
var import_react = require("react");
|
|
97
|
+
var PortalContext = (0, import_react.createContext)(null);
|
|
98
|
+
|
|
99
|
+
// src/core/portal/portal-host.tsx
|
|
100
|
+
var import_react3 = __toESM(require("react"), 1);
|
|
101
|
+
var import_react_native2 = require("react-native");
|
|
102
|
+
var hostStyles = import_react_native2.StyleSheet.create({
|
|
103
|
+
container: {
|
|
104
|
+
flex: 1
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
// src/core/theme-context.tsx
|
|
109
|
+
var XUIThemeContext = (0, import_react4.createContext)(null);
|
|
110
|
+
|
|
111
|
+
// src/core/theme-hooks.ts
|
|
112
|
+
var import_react5 = require("react");
|
|
113
|
+
var import_react_native4 = require("react-native");
|
|
114
|
+
function useXUITheme() {
|
|
115
|
+
const theme = (0, import_react5.useContext)(XUIThemeContext);
|
|
116
|
+
if (!theme) {
|
|
117
|
+
throw new Error("useXUITheme must be used within XUIProvider");
|
|
118
|
+
}
|
|
119
|
+
return theme;
|
|
120
|
+
}
|
|
121
|
+
function useBorderRadiusStyles(radius) {
|
|
122
|
+
const theme = useXUITheme();
|
|
123
|
+
const borderRadius = (0, import_react5.useMemo)(() => {
|
|
124
|
+
const radiusMap = {
|
|
125
|
+
none: theme.borderRadius.none,
|
|
126
|
+
sm: theme.borderRadius.sm,
|
|
127
|
+
md: theme.borderRadius.md,
|
|
128
|
+
lg: theme.borderRadius.lg,
|
|
129
|
+
full: theme.borderRadius.full
|
|
130
|
+
};
|
|
131
|
+
return { borderRadius: radiusMap[radius] };
|
|
132
|
+
}, [radius, theme]);
|
|
133
|
+
return borderRadius;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// src/core/index.ts
|
|
137
|
+
var import_theme2 = require("@xaui/core/theme");
|
|
138
|
+
|
|
139
|
+
// src/components/segment-button/segment-button.hook.ts
|
|
140
|
+
var import_core2 = require("@xaui/core");
|
|
141
|
+
function useSegmentSizeStyles(size) {
|
|
142
|
+
const theme = useXUITheme();
|
|
143
|
+
return (0, import_react6.useMemo)(() => {
|
|
144
|
+
const sizes = {
|
|
145
|
+
xs: {
|
|
146
|
+
paddingHorizontal: theme.spacing.sm,
|
|
147
|
+
paddingVertical: theme.spacing.xs,
|
|
148
|
+
minHeight: 32,
|
|
149
|
+
fontSize: theme.fontSizes.xs,
|
|
150
|
+
iconSize: 14
|
|
151
|
+
},
|
|
152
|
+
sm: {
|
|
153
|
+
paddingHorizontal: theme.spacing.md,
|
|
154
|
+
paddingVertical: theme.spacing.xs,
|
|
155
|
+
minHeight: 36,
|
|
156
|
+
fontSize: theme.fontSizes.sm,
|
|
157
|
+
iconSize: 16
|
|
158
|
+
},
|
|
159
|
+
md: {
|
|
160
|
+
paddingHorizontal: theme.spacing.md,
|
|
161
|
+
paddingVertical: theme.spacing.sm,
|
|
162
|
+
minHeight: 40,
|
|
163
|
+
fontSize: theme.fontSizes.md,
|
|
164
|
+
iconSize: 18
|
|
165
|
+
},
|
|
166
|
+
lg: {
|
|
167
|
+
paddingHorizontal: theme.spacing.lg,
|
|
168
|
+
paddingVertical: theme.spacing.md,
|
|
169
|
+
minHeight: 48,
|
|
170
|
+
fontSize: theme.fontSizes.lg,
|
|
171
|
+
iconSize: 20
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
return sizes[size];
|
|
175
|
+
}, [size, theme]);
|
|
176
|
+
}
|
|
177
|
+
function useSegmentVariantStyles(themeColor, variant, elevation = 0) {
|
|
178
|
+
const theme = useXUITheme();
|
|
179
|
+
const safeThemeColor = (0, import_core2.getSafeThemeColor)(themeColor);
|
|
180
|
+
const colorScheme = theme.colors[safeThemeColor];
|
|
181
|
+
const selectedBackgroundColor = (0, import_core2.withPaletteNumber)(colorScheme.main, 400);
|
|
182
|
+
return (0, import_react6.useMemo)(() => {
|
|
183
|
+
const variants = {
|
|
184
|
+
outlined: {
|
|
185
|
+
containerBackground: "transparent",
|
|
186
|
+
containerBorderWidth: theme.borderWidth.sm,
|
|
187
|
+
containerBorderColor: colorScheme.main,
|
|
188
|
+
selectedBackground: selectedBackgroundColor,
|
|
189
|
+
unselectedBackground: "transparent",
|
|
190
|
+
selectedTextColor: colorScheme.foreground,
|
|
191
|
+
unselectedTextColor: colorScheme.main
|
|
192
|
+
},
|
|
193
|
+
flat: {
|
|
194
|
+
containerBackground: colorScheme.background,
|
|
195
|
+
containerBorderWidth: 0,
|
|
196
|
+
containerBorderColor: "transparent",
|
|
197
|
+
selectedBackground: selectedBackgroundColor,
|
|
198
|
+
unselectedBackground: "transparent",
|
|
199
|
+
selectedTextColor: colorScheme.foreground,
|
|
200
|
+
unselectedTextColor: colorScheme.main
|
|
201
|
+
},
|
|
202
|
+
light: {
|
|
203
|
+
containerBackground: "transparent",
|
|
204
|
+
containerBorderWidth: 0,
|
|
205
|
+
containerBorderColor: "transparent",
|
|
206
|
+
selectedBackground: selectedBackgroundColor,
|
|
207
|
+
unselectedBackground: "transparent",
|
|
208
|
+
selectedTextColor: colorScheme.foreground,
|
|
209
|
+
unselectedTextColor: colorScheme.main
|
|
210
|
+
},
|
|
211
|
+
faded: {
|
|
212
|
+
containerBackground: `${colorScheme.background}95`,
|
|
213
|
+
containerBorderWidth: theme.borderWidth.sm,
|
|
214
|
+
containerBorderColor: `${colorScheme.main}90`,
|
|
215
|
+
selectedBackground: selectedBackgroundColor,
|
|
216
|
+
unselectedBackground: "transparent",
|
|
217
|
+
selectedTextColor: colorScheme.foreground,
|
|
218
|
+
unselectedTextColor: colorScheme.main
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
const baseStyle = variants[variant] ?? variants.outlined;
|
|
222
|
+
const shouldApplyElevation = variant !== "outlined" && variant !== "light";
|
|
223
|
+
const shadowStyles = elevation === 0 ? {} : elevation === 1 ? theme.shadows.sm : elevation === 2 ? theme.shadows.md : elevation === 3 ? theme.shadows.lg : theme.shadows.xl;
|
|
224
|
+
return {
|
|
225
|
+
...baseStyle,
|
|
226
|
+
containerShadow: shouldApplyElevation && elevation > 0 ? shadowStyles : baseStyle.containerShadow
|
|
227
|
+
};
|
|
228
|
+
}, [variant, colorScheme, theme, elevation]);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// src/components/segment-button/segment-button-context.ts
|
|
232
|
+
var import_react7 = require("react");
|
|
233
|
+
var SegmentButtonContext = (0, import_react7.createContext)(void 0);
|
|
234
|
+
var useSegmentButtonContext = () => {
|
|
235
|
+
const context = (0, import_react7.useContext)(SegmentButtonContext);
|
|
236
|
+
if (!context) {
|
|
237
|
+
throw new Error(
|
|
238
|
+
"SegmentButtonItem must be used within a SegmentButton component"
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
return context;
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
// src/components/segment-button/segment-button.tsx
|
|
245
|
+
var SegmentButton = ({
|
|
246
|
+
children,
|
|
247
|
+
selected: controlledSelected,
|
|
248
|
+
defaultSelected,
|
|
249
|
+
onSelectionChange,
|
|
250
|
+
selectionMode = "single",
|
|
251
|
+
themeColor = "primary",
|
|
252
|
+
variant = "outlined",
|
|
253
|
+
size = "md",
|
|
254
|
+
radius = "full",
|
|
255
|
+
fullWidth = false,
|
|
256
|
+
isDisabled = false,
|
|
257
|
+
showCheckmark = true,
|
|
258
|
+
elevation = 0,
|
|
259
|
+
customAppearance
|
|
260
|
+
}) => {
|
|
261
|
+
const isControlled = controlledSelected !== void 0;
|
|
262
|
+
const [internalSelected, setInternalSelected] = (0, import_react8.useState)(
|
|
263
|
+
() => defaultSelected ?? ""
|
|
264
|
+
);
|
|
265
|
+
const selected = isControlled ? controlledSelected : internalSelected;
|
|
266
|
+
const selectedKeys = (0, import_react8.useMemo)(() => {
|
|
267
|
+
if (Array.isArray(selected)) return selected;
|
|
268
|
+
return selected ? [selected] : [];
|
|
269
|
+
}, [selected]);
|
|
270
|
+
const variantStyles = useSegmentVariantStyles(themeColor, variant, elevation);
|
|
271
|
+
const radiusStyles = useBorderRadiusStyles(radius);
|
|
272
|
+
const toggleItem = (0, import_react8.useCallback)(
|
|
273
|
+
(key) => {
|
|
274
|
+
let nextSelected;
|
|
275
|
+
if (selectionMode === "single") {
|
|
276
|
+
nextSelected = key;
|
|
277
|
+
} else {
|
|
278
|
+
const isCurrentlySelected = selectedKeys.includes(key);
|
|
279
|
+
if (isCurrentlySelected && selectedKeys.length > 1) {
|
|
280
|
+
nextSelected = selectedKeys.filter((k) => k !== key);
|
|
281
|
+
} else if (!isCurrentlySelected) {
|
|
282
|
+
nextSelected = [...selectedKeys, key];
|
|
283
|
+
} else {
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
if (!isControlled) {
|
|
288
|
+
setInternalSelected(nextSelected);
|
|
289
|
+
}
|
|
290
|
+
onSelectionChange?.(nextSelected);
|
|
291
|
+
},
|
|
292
|
+
[selectionMode, selectedKeys, onSelectionChange, isControlled]
|
|
293
|
+
);
|
|
294
|
+
const contextValue = (0, import_react8.useMemo)(
|
|
295
|
+
() => ({
|
|
296
|
+
selectedKeys,
|
|
297
|
+
toggleItem,
|
|
298
|
+
themeColor,
|
|
299
|
+
variant,
|
|
300
|
+
size,
|
|
301
|
+
elevation,
|
|
302
|
+
isDisabled,
|
|
303
|
+
showCheckmark
|
|
304
|
+
}),
|
|
305
|
+
[
|
|
306
|
+
selectedKeys,
|
|
307
|
+
toggleItem,
|
|
308
|
+
themeColor,
|
|
309
|
+
variant,
|
|
310
|
+
size,
|
|
311
|
+
elevation,
|
|
312
|
+
isDisabled,
|
|
313
|
+
showCheckmark
|
|
314
|
+
]
|
|
315
|
+
);
|
|
316
|
+
const showDivider = variant === "outlined" || variant === "faded";
|
|
317
|
+
const childrenArray = import_react8.default.Children.toArray(children);
|
|
318
|
+
const getItemKey = (child) => {
|
|
319
|
+
if (!import_react8.default.isValidElement(child)) {
|
|
320
|
+
return void 0;
|
|
321
|
+
}
|
|
322
|
+
return child.props.itemKey;
|
|
323
|
+
};
|
|
324
|
+
return /* @__PURE__ */ import_react8.default.createElement(SegmentButtonContext.Provider, { value: contextValue }, /* @__PURE__ */ import_react8.default.createElement(
|
|
325
|
+
import_react_native5.View,
|
|
326
|
+
{
|
|
327
|
+
style: [
|
|
328
|
+
styles.container,
|
|
329
|
+
{
|
|
330
|
+
backgroundColor: variantStyles.containerBackground,
|
|
331
|
+
borderWidth: variantStyles.containerBorderWidth,
|
|
332
|
+
borderColor: variantStyles.containerBorderColor,
|
|
333
|
+
borderRadius: radiusStyles.borderRadius,
|
|
334
|
+
...variantStyles.containerShadow
|
|
335
|
+
},
|
|
336
|
+
fullWidth && styles.fullWidth,
|
|
337
|
+
customAppearance?.container
|
|
338
|
+
]
|
|
339
|
+
},
|
|
340
|
+
childrenArray.map((child, index) => {
|
|
341
|
+
const isLast = index === childrenArray.length - 1;
|
|
342
|
+
const childItemKey = getItemKey(child);
|
|
343
|
+
const childKey = childItemKey ?? index;
|
|
344
|
+
const isSelected = selectedKeys.includes(String(childKey));
|
|
345
|
+
const nextChildKey = !isLast ? getItemKey(childrenArray[index + 1]) : void 0;
|
|
346
|
+
const nextSelected = nextChildKey ? selectedKeys.includes(String(nextChildKey)) : false;
|
|
347
|
+
return /* @__PURE__ */ import_react8.default.createElement(import_react8.default.Fragment, { key: childKey }, child, showDivider && !isLast && !isSelected && !nextSelected && /* @__PURE__ */ import_react8.default.createElement(
|
|
348
|
+
import_react_native5.View,
|
|
349
|
+
{
|
|
350
|
+
style: [
|
|
351
|
+
styles.divider,
|
|
352
|
+
{
|
|
353
|
+
backgroundColor: variantStyles.containerBorderColor
|
|
354
|
+
}
|
|
355
|
+
]
|
|
356
|
+
}
|
|
357
|
+
));
|
|
358
|
+
})
|
|
359
|
+
));
|
|
360
|
+
};
|
|
361
|
+
|
|
362
|
+
// src/components/segment-button/segment-button-item.tsx
|
|
363
|
+
var import_react9 = __toESM(require("react"), 1);
|
|
364
|
+
var import_react_native7 = require("react-native");
|
|
365
|
+
var import_react_native_svg = __toESM(require("react-native-svg"), 1);
|
|
366
|
+
|
|
367
|
+
// src/components/segment-button/segment-button.animation.ts
|
|
368
|
+
var import_react_native6 = require("react-native");
|
|
369
|
+
var runCheckmarkEnterAnimation = (animatedValue) => {
|
|
370
|
+
animatedValue.setValue(0);
|
|
371
|
+
import_react_native6.Animated.timing(animatedValue, {
|
|
372
|
+
toValue: 1,
|
|
373
|
+
duration: 200,
|
|
374
|
+
useNativeDriver: true
|
|
375
|
+
}).start();
|
|
376
|
+
};
|
|
377
|
+
var runCheckmarkExitAnimation = (animatedValue) => {
|
|
378
|
+
import_react_native6.Animated.timing(animatedValue, {
|
|
379
|
+
toValue: 0,
|
|
380
|
+
duration: 150,
|
|
381
|
+
useNativeDriver: true
|
|
382
|
+
}).start();
|
|
383
|
+
};
|
|
384
|
+
|
|
385
|
+
// src/components/segment-button/segment-button-item.tsx
|
|
386
|
+
var CheckIcon = ({ size, color }) => /* @__PURE__ */ import_react9.default.createElement(import_react_native_svg.default, { width: size, height: size, viewBox: "0 0 24 24", fill: "none" }, /* @__PURE__ */ import_react9.default.createElement(
|
|
387
|
+
import_react_native_svg.Path,
|
|
388
|
+
{
|
|
389
|
+
d: "M20 6L9 17l-5-5",
|
|
390
|
+
stroke: color,
|
|
391
|
+
strokeWidth: 2.5,
|
|
392
|
+
strokeLinecap: "round",
|
|
393
|
+
strokeLinejoin: "round"
|
|
394
|
+
}
|
|
395
|
+
));
|
|
396
|
+
var SegmentButtonItem = ({
|
|
397
|
+
itemKey,
|
|
398
|
+
label,
|
|
399
|
+
startContent,
|
|
400
|
+
icon,
|
|
401
|
+
endContent,
|
|
402
|
+
checkIndicator,
|
|
403
|
+
isDisabled: itemDisabled = false,
|
|
404
|
+
customAppearance
|
|
405
|
+
}) => {
|
|
406
|
+
const {
|
|
407
|
+
selectedKeys,
|
|
408
|
+
toggleItem,
|
|
409
|
+
themeColor,
|
|
410
|
+
variant,
|
|
411
|
+
size,
|
|
412
|
+
elevation,
|
|
413
|
+
isDisabled: groupDisabled,
|
|
414
|
+
showCheckmark
|
|
415
|
+
} = useSegmentButtonContext();
|
|
416
|
+
const isSelected = selectedKeys.includes(itemKey);
|
|
417
|
+
const disabled = groupDisabled || itemDisabled;
|
|
418
|
+
const checkmarkAnim = (0, import_react9.useRef)(new import_react_native7.Animated.Value(isSelected ? 1 : 0)).current;
|
|
419
|
+
const prevSelected = (0, import_react9.useRef)(isSelected);
|
|
420
|
+
(0, import_react9.useEffect)(() => {
|
|
421
|
+
if (isSelected && !prevSelected.current) {
|
|
422
|
+
runCheckmarkEnterAnimation(checkmarkAnim);
|
|
423
|
+
} else if (!isSelected && prevSelected.current) {
|
|
424
|
+
runCheckmarkExitAnimation(checkmarkAnim);
|
|
425
|
+
}
|
|
426
|
+
prevSelected.current = isSelected;
|
|
427
|
+
}, [isSelected, checkmarkAnim]);
|
|
428
|
+
const sizeStyles = useSegmentSizeStyles(size);
|
|
429
|
+
const variantStyles = useSegmentVariantStyles(themeColor, variant, elevation);
|
|
430
|
+
const handlePress = () => {
|
|
431
|
+
if (!disabled) {
|
|
432
|
+
toggleItem(itemKey);
|
|
433
|
+
}
|
|
434
|
+
};
|
|
435
|
+
const backgroundColor = isSelected ? variantStyles.selectedBackground : variantStyles.unselectedBackground;
|
|
436
|
+
const textColor = isSelected ? variantStyles.selectedTextColor : variantStyles.unselectedTextColor;
|
|
437
|
+
const showCheck = isSelected && showCheckmark;
|
|
438
|
+
const startNode = showCheck ? checkIndicator ?? /* @__PURE__ */ import_react9.default.createElement(CheckIcon, { size: sizeStyles.iconSize, color: textColor }) : startContent ?? icon;
|
|
439
|
+
return /* @__PURE__ */ import_react9.default.createElement(
|
|
440
|
+
import_react_native7.Pressable,
|
|
441
|
+
{
|
|
442
|
+
style: [styles.segment, disabled && styles.disabled],
|
|
443
|
+
onPress: handlePress,
|
|
444
|
+
disabled
|
|
445
|
+
},
|
|
446
|
+
/* @__PURE__ */ import_react9.default.createElement(
|
|
447
|
+
import_react_native7.View,
|
|
448
|
+
{
|
|
449
|
+
style: [
|
|
450
|
+
styles.segmentInner,
|
|
451
|
+
{
|
|
452
|
+
paddingHorizontal: sizeStyles.paddingHorizontal,
|
|
453
|
+
paddingVertical: sizeStyles.paddingVertical,
|
|
454
|
+
minHeight: sizeStyles.minHeight,
|
|
455
|
+
backgroundColor
|
|
456
|
+
},
|
|
457
|
+
isSelected ? customAppearance?.selectedSegment : customAppearance?.segment
|
|
458
|
+
]
|
|
459
|
+
},
|
|
460
|
+
/* @__PURE__ */ import_react9.default.createElement(import_react_native7.View, { style: styles.segmentContent }, startNode && /* @__PURE__ */ import_react9.default.createElement(
|
|
461
|
+
import_react_native7.Animated.View,
|
|
462
|
+
{
|
|
463
|
+
style: {
|
|
464
|
+
opacity: showCheck ? checkmarkAnim : 1,
|
|
465
|
+
transform: [{ scale: showCheck ? checkmarkAnim : 1 }]
|
|
466
|
+
}
|
|
467
|
+
},
|
|
468
|
+
startNode
|
|
469
|
+
), /* @__PURE__ */ import_react9.default.createElement(
|
|
470
|
+
import_react_native7.Text,
|
|
471
|
+
{
|
|
472
|
+
numberOfLines: 1,
|
|
473
|
+
style: [
|
|
474
|
+
styles.segmentText,
|
|
475
|
+
{
|
|
476
|
+
fontSize: sizeStyles.fontSize,
|
|
477
|
+
color: textColor
|
|
478
|
+
},
|
|
479
|
+
isSelected ? customAppearance?.selectedText : customAppearance?.text
|
|
480
|
+
]
|
|
481
|
+
},
|
|
482
|
+
label
|
|
483
|
+
), endContent)
|
|
484
|
+
)
|
|
485
|
+
);
|
|
486
|
+
};
|
|
487
|
+
SegmentButtonItem.displayName = "SegmentButtonItem";
|
|
488
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
489
|
+
0 && (module.exports = {
|
|
490
|
+
SegmentButton,
|
|
491
|
+
SegmentButtonItem
|
|
492
|
+
});
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
import { ViewStyle, TextStyle } from 'react-native';
|
|
3
|
+
import { T as ThemeColor, S as Size } from '../index-BOw6tbkc.cjs';
|
|
4
|
+
|
|
5
|
+
type SegmentButtonVariant = 'outlined' | 'flat' | 'light' | 'faded';
|
|
6
|
+
type ElevationLevel = 0 | 1 | 2 | 3 | 4;
|
|
7
|
+
type SegmentButtonRadius = 'none' | 'sm' | 'md' | 'lg' | 'full';
|
|
8
|
+
type SegmentButtonSelectionMode = 'single' | 'multiple';
|
|
9
|
+
type SegmentButtonProps = {
|
|
10
|
+
/**
|
|
11
|
+
* SegmentButtonItem children
|
|
12
|
+
*/
|
|
13
|
+
children: ReactNode;
|
|
14
|
+
/**
|
|
15
|
+
* The currently selected key(s) (controlled mode).
|
|
16
|
+
* Use a string for single-select, string array for multi-select.
|
|
17
|
+
*/
|
|
18
|
+
selected?: string | string[];
|
|
19
|
+
/**
|
|
20
|
+
* Default selected key(s) for uncontrolled mode.
|
|
21
|
+
* Use a string for single-select, string array for multi-select.
|
|
22
|
+
*/
|
|
23
|
+
defaultSelected?: string | string[];
|
|
24
|
+
/**
|
|
25
|
+
* Callback fired when selection changes.
|
|
26
|
+
* Returns a string for single-select mode, string array for multi-select.
|
|
27
|
+
*/
|
|
28
|
+
onSelectionChange?: (selected: string | string[]) => void;
|
|
29
|
+
/**
|
|
30
|
+
* Selection mode: single or multiple
|
|
31
|
+
* @default 'single'
|
|
32
|
+
*/
|
|
33
|
+
selectionMode?: SegmentButtonSelectionMode;
|
|
34
|
+
/**
|
|
35
|
+
* The theme color of the segment button
|
|
36
|
+
* @default 'primary'
|
|
37
|
+
*/
|
|
38
|
+
themeColor?: ThemeColor;
|
|
39
|
+
/**
|
|
40
|
+
* The variant of the segment button
|
|
41
|
+
* @default 'outlined'
|
|
42
|
+
*/
|
|
43
|
+
variant?: SegmentButtonVariant;
|
|
44
|
+
/**
|
|
45
|
+
* The size of the segment button
|
|
46
|
+
* @default 'md'
|
|
47
|
+
*/
|
|
48
|
+
size?: Size;
|
|
49
|
+
/**
|
|
50
|
+
* The border radius of the segment button
|
|
51
|
+
* @default 'full'
|
|
52
|
+
*/
|
|
53
|
+
radius?: SegmentButtonRadius;
|
|
54
|
+
/**
|
|
55
|
+
* Whether the segment button should take the full width of its container
|
|
56
|
+
* @default false
|
|
57
|
+
*/
|
|
58
|
+
fullWidth?: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Whether the entire segment button group is disabled
|
|
61
|
+
* @default false
|
|
62
|
+
*/
|
|
63
|
+
isDisabled?: boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Whether to show a checkmark icon on selected segments
|
|
66
|
+
* @default true
|
|
67
|
+
*/
|
|
68
|
+
showCheckmark?: boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Android elevation level from 0 to 4.
|
|
71
|
+
* Does not apply to `outlined` and `light` variants.
|
|
72
|
+
* @default 0
|
|
73
|
+
*/
|
|
74
|
+
elevation?: ElevationLevel;
|
|
75
|
+
/**
|
|
76
|
+
* Custom styles for the outer container
|
|
77
|
+
*/
|
|
78
|
+
customAppearance?: {
|
|
79
|
+
container?: ViewStyle;
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
declare const SegmentButton: React.FC<SegmentButtonProps>;
|
|
84
|
+
|
|
85
|
+
type SegmentButtonItemCustomAppearance = {
|
|
86
|
+
/**
|
|
87
|
+
* Custom styles for the segment container
|
|
88
|
+
*/
|
|
89
|
+
segment?: ViewStyle;
|
|
90
|
+
/**
|
|
91
|
+
* Custom styles for the selected segment
|
|
92
|
+
*/
|
|
93
|
+
selectedSegment?: ViewStyle;
|
|
94
|
+
/**
|
|
95
|
+
* Custom styles for segment label text
|
|
96
|
+
*/
|
|
97
|
+
text?: TextStyle;
|
|
98
|
+
/**
|
|
99
|
+
* Custom styles for selected segment label text
|
|
100
|
+
*/
|
|
101
|
+
selectedText?: TextStyle;
|
|
102
|
+
};
|
|
103
|
+
type SegmentButtonItemProps = {
|
|
104
|
+
/**
|
|
105
|
+
* Unique key for the segment item
|
|
106
|
+
*/
|
|
107
|
+
itemKey: string;
|
|
108
|
+
/**
|
|
109
|
+
* Label text for the segment
|
|
110
|
+
*/
|
|
111
|
+
label: string;
|
|
112
|
+
/**
|
|
113
|
+
* Content to display at the start of the segment item
|
|
114
|
+
*/
|
|
115
|
+
startContent?: ReactNode;
|
|
116
|
+
/**
|
|
117
|
+
* @deprecated Use `startContent` instead
|
|
118
|
+
*/
|
|
119
|
+
icon?: ReactNode;
|
|
120
|
+
/**
|
|
121
|
+
* Content to display at the end of the segment item
|
|
122
|
+
*/
|
|
123
|
+
endContent?: ReactNode;
|
|
124
|
+
/**
|
|
125
|
+
* Custom indicator shown when the segment item is selected
|
|
126
|
+
*/
|
|
127
|
+
checkIndicator?: ReactNode;
|
|
128
|
+
/**
|
|
129
|
+
* Whether the segment item is disabled
|
|
130
|
+
* @default false
|
|
131
|
+
*/
|
|
132
|
+
isDisabled?: boolean;
|
|
133
|
+
/**
|
|
134
|
+
* Custom appearance styles for this segment item
|
|
135
|
+
*/
|
|
136
|
+
customAppearance?: SegmentButtonItemCustomAppearance;
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
declare const SegmentButtonItem: React.FC<SegmentButtonItemProps>;
|
|
140
|
+
|
|
141
|
+
export { type ElevationLevel, SegmentButton, SegmentButtonItem, type SegmentButtonItemProps, type SegmentButtonProps, type SegmentButtonRadius, type SegmentButtonSelectionMode, type SegmentButtonVariant };
|