@xaui/native 0.0.17 → 0.0.19
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.js +2 -2
- package/dist/alert/index.js +352 -4
- package/dist/autocomplete/index.js +1121 -5
- package/dist/avatar/index.js +276 -5
- package/dist/badge/index.js +193 -4
- package/dist/bottom-sheet/index.js +364 -4
- package/dist/button/index.js +2 -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.js +377 -3
- package/dist/checkbox/index.js +1 -1
- package/dist/chip/index.js +497 -6
- package/dist/{chunk-VUVE6PK7.js → chunk-F7WH4DMG.js} +1 -1
- package/dist/{chunk-TJ2FPLLZ.js → chunk-JEGEPGVU.js} +2 -2
- package/dist/{chunk-MZL77KV5.js → chunk-LTKYHG5V.js} +1 -1
- package/dist/{chunk-RIVFFZRO.js → chunk-LUBWRVI2.js} +1 -1
- package/dist/core/index.cjs +1 -1
- package/dist/core/index.js +1 -1
- package/dist/datepicker/index.js +1623 -4
- package/dist/divider/index.js +2 -2
- package/dist/fab/index.js +3 -3
- package/dist/fab-menu/index.js +324 -6
- package/dist/index.cjs +0 -6446
- package/dist/index.d.cts +2 -19
- package/dist/index.d.ts +2 -19
- package/dist/index.js +0 -73
- package/dist/indicator/index.js +2 -2
- package/dist/menu/index.js +1 -1
- package/dist/progress/index.js +1 -1
- package/dist/segment-button/index.cjs +2 -2
- package/dist/segment-button/index.js +400 -5
- package/dist/select/index.js +1 -1
- package/dist/skeleton/index.cjs +160 -0
- package/dist/skeleton/index.d.cts +45 -0
- package/dist/skeleton/index.d.ts +45 -0
- package/dist/skeleton/index.js +89 -0
- package/dist/switch/index.js +1 -1
- package/dist/typography/index.js +146 -4
- package/package.json +11 -1
- package/dist/chunk-6PXMB5CH.js +0 -503
- package/dist/chunk-DBKVHMSA.js +0 -329
- package/dist/chunk-EW5YLICE.js +0 -382
- package/dist/chunk-JJOVGRNI.js +0 -1627
- package/dist/chunk-K2HSVISE.js +0 -281
- package/dist/chunk-OXVIVNIJ.js +0 -356
- package/dist/chunk-PWCUULAL.js +0 -150
- package/dist/chunk-S3MGBM3G.js +0 -368
- package/dist/chunk-STUNTRKJ.js +0 -405
- package/dist/chunk-UGDGCMGC.js +0 -197
- package/dist/chunk-XUYIAA3A.js +0 -1127
package/dist/index.d.cts
CHANGED
|
@@ -1,19 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export {
|
|
3
|
-
export { Avatar, AvatarGroup } from './avatar/index.cjs';
|
|
4
|
-
export { Badge } from './badge/index.cjs';
|
|
5
|
-
export { Alert } from './alert/index.cjs';
|
|
6
|
-
export { Autocomplete, AutocompleteItem } from './autocomplete/index.cjs';
|
|
7
|
-
export { DatePicker } from './datepicker/index.cjs';
|
|
8
|
-
export { Typography } from './typography/index.cjs';
|
|
9
|
-
export { Carousel } from './carousel/index.cjs';
|
|
10
|
-
export { SegmentButton, SegmentButtonItem } from './segment-button/index.cjs';
|
|
11
|
-
export { Chip, ChipGroup, ChipItem } from './chip/index.cjs';
|
|
12
|
-
export { BottomSheet } from './bottom-sheet/index.cjs';
|
|
13
|
-
export { Fab } from './fab/index.cjs';
|
|
14
|
-
export { FabMenu, FabMenuItem } from './fab-menu/index.cjs';
|
|
15
|
-
import 'react';
|
|
16
|
-
import './index-BOw6tbkc.cjs';
|
|
17
|
-
import 'react-native';
|
|
18
|
-
import './fab.type-U09H8B7D.cjs';
|
|
19
|
-
import './button.type-ikaWzhIg.cjs';
|
|
1
|
+
|
|
2
|
+
export { }
|
package/dist/index.d.ts
CHANGED
|
@@ -1,19 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export {
|
|
3
|
-
export { Avatar, AvatarGroup } from './avatar/index.js';
|
|
4
|
-
export { Badge } from './badge/index.js';
|
|
5
|
-
export { Alert } from './alert/index.js';
|
|
6
|
-
export { Autocomplete, AutocompleteItem } from './autocomplete/index.js';
|
|
7
|
-
export { DatePicker } from './datepicker/index.js';
|
|
8
|
-
export { Typography } from './typography/index.js';
|
|
9
|
-
export { Carousel } from './carousel/index.js';
|
|
10
|
-
export { SegmentButton, SegmentButtonItem } from './segment-button/index.js';
|
|
11
|
-
export { Chip, ChipGroup, ChipItem } from './chip/index.js';
|
|
12
|
-
export { BottomSheet } from './bottom-sheet/index.js';
|
|
13
|
-
export { Fab } from './fab/index.js';
|
|
14
|
-
export { FabMenu, FabMenuItem } from './fab-menu/index.js';
|
|
15
|
-
import 'react';
|
|
16
|
-
import './index-BOw6tbkc.js';
|
|
17
|
-
import 'react-native';
|
|
18
|
-
import './fab.type-Ba0QMprb.js';
|
|
19
|
-
import './button.type-D8tzEBo7.js';
|
|
1
|
+
|
|
2
|
+
export { }
|
package/dist/index.js
CHANGED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Chip,
|
|
3
|
-
ChipGroup,
|
|
4
|
-
ChipItem
|
|
5
|
-
} from "./chunk-6PXMB5CH.js";
|
|
6
|
-
import {
|
|
7
|
-
BottomSheet
|
|
8
|
-
} from "./chunk-S3MGBM3G.js";
|
|
9
|
-
import {
|
|
10
|
-
FabMenu,
|
|
11
|
-
FabMenuItem
|
|
12
|
-
} from "./chunk-DBKVHMSA.js";
|
|
13
|
-
import {
|
|
14
|
-
Fab
|
|
15
|
-
} from "./chunk-TJ2FPLLZ.js";
|
|
16
|
-
import {
|
|
17
|
-
SegmentButton,
|
|
18
|
-
SegmentButtonItem
|
|
19
|
-
} from "./chunk-STUNTRKJ.js";
|
|
20
|
-
import {
|
|
21
|
-
Carousel
|
|
22
|
-
} from "./chunk-EW5YLICE.js";
|
|
23
|
-
import {
|
|
24
|
-
Avatar,
|
|
25
|
-
AvatarGroup
|
|
26
|
-
} from "./chunk-K2HSVISE.js";
|
|
27
|
-
import {
|
|
28
|
-
Badge
|
|
29
|
-
} from "./chunk-UGDGCMGC.js";
|
|
30
|
-
import {
|
|
31
|
-
Alert
|
|
32
|
-
} from "./chunk-OXVIVNIJ.js";
|
|
33
|
-
import {
|
|
34
|
-
Autocomplete,
|
|
35
|
-
AutocompleteItem
|
|
36
|
-
} from "./chunk-XUYIAA3A.js";
|
|
37
|
-
import "./chunk-GBHQCAKW.js";
|
|
38
|
-
import {
|
|
39
|
-
DatePicker
|
|
40
|
-
} from "./chunk-JJOVGRNI.js";
|
|
41
|
-
import {
|
|
42
|
-
Typography
|
|
43
|
-
} from "./chunk-PWCUULAL.js";
|
|
44
|
-
import {
|
|
45
|
-
Divider
|
|
46
|
-
} from "./chunk-RIVFFZRO.js";
|
|
47
|
-
import {
|
|
48
|
-
ActivityIndicator
|
|
49
|
-
} from "./chunk-VUVE6PK7.js";
|
|
50
|
-
import "./chunk-DXXNBF5P.js";
|
|
51
|
-
import "./chunk-MZL77KV5.js";
|
|
52
|
-
export {
|
|
53
|
-
ActivityIndicator,
|
|
54
|
-
Alert,
|
|
55
|
-
Autocomplete,
|
|
56
|
-
AutocompleteItem,
|
|
57
|
-
Avatar,
|
|
58
|
-
AvatarGroup,
|
|
59
|
-
Badge,
|
|
60
|
-
BottomSheet,
|
|
61
|
-
Carousel,
|
|
62
|
-
Chip,
|
|
63
|
-
ChipGroup,
|
|
64
|
-
ChipItem,
|
|
65
|
-
DatePicker,
|
|
66
|
-
Divider,
|
|
67
|
-
Fab,
|
|
68
|
-
FabMenu,
|
|
69
|
-
FabMenuItem,
|
|
70
|
-
SegmentButton,
|
|
71
|
-
SegmentButtonItem,
|
|
72
|
-
Typography
|
|
73
|
-
};
|
package/dist/indicator/index.js
CHANGED
package/dist/menu/index.js
CHANGED
package/dist/progress/index.js
CHANGED
|
@@ -183,7 +183,7 @@ function useSegmentVariantStyles(themeColor, variant, elevation = 0) {
|
|
|
183
183
|
const variants = {
|
|
184
184
|
outlined: {
|
|
185
185
|
containerBackground: "transparent",
|
|
186
|
-
containerBorderWidth: theme.borderWidth.
|
|
186
|
+
containerBorderWidth: theme.borderWidth.md,
|
|
187
187
|
containerBorderColor: colorScheme.main,
|
|
188
188
|
selectedBackground: selectedBackgroundColor,
|
|
189
189
|
unselectedBackground: "transparent",
|
|
@@ -210,7 +210,7 @@ function useSegmentVariantStyles(themeColor, variant, elevation = 0) {
|
|
|
210
210
|
},
|
|
211
211
|
faded: {
|
|
212
212
|
containerBackground: `${colorScheme.background}95`,
|
|
213
|
-
containerBorderWidth: theme.borderWidth.
|
|
213
|
+
containerBorderWidth: theme.borderWidth.md,
|
|
214
214
|
containerBorderColor: `${colorScheme.main}90`,
|
|
215
215
|
selectedBackground: selectedBackgroundColor,
|
|
216
216
|
unselectedBackground: "transparent",
|
|
@@ -1,9 +1,404 @@
|
|
|
1
|
-
import {
|
|
2
|
-
SegmentButton,
|
|
3
|
-
SegmentButtonItem
|
|
4
|
-
} from "../chunk-STUNTRKJ.js";
|
|
5
1
|
import "../chunk-DXXNBF5P.js";
|
|
6
|
-
import
|
|
2
|
+
import {
|
|
3
|
+
useBorderRadiusStyles,
|
|
4
|
+
useXUITheme
|
|
5
|
+
} from "../chunk-LTKYHG5V.js";
|
|
6
|
+
|
|
7
|
+
// src/components/segment-button/segment-button.tsx
|
|
8
|
+
import React, { useCallback, useMemo as useMemo2, useState } from "react";
|
|
9
|
+
import { View } from "react-native";
|
|
10
|
+
|
|
11
|
+
// src/components/segment-button/segment-button.style.ts
|
|
12
|
+
import { StyleSheet } from "react-native";
|
|
13
|
+
var styles = StyleSheet.create({
|
|
14
|
+
container: {
|
|
15
|
+
flexDirection: "row",
|
|
16
|
+
alignItems: "stretch",
|
|
17
|
+
overflow: "hidden",
|
|
18
|
+
alignSelf: "flex-start"
|
|
19
|
+
},
|
|
20
|
+
fullWidth: {
|
|
21
|
+
width: "100%",
|
|
22
|
+
alignSelf: "stretch"
|
|
23
|
+
},
|
|
24
|
+
segment: {
|
|
25
|
+
flex: 1
|
|
26
|
+
},
|
|
27
|
+
segmentInner: {
|
|
28
|
+
flex: 1,
|
|
29
|
+
flexDirection: "row",
|
|
30
|
+
alignItems: "center",
|
|
31
|
+
justifyContent: "center"
|
|
32
|
+
},
|
|
33
|
+
segmentContent: {
|
|
34
|
+
flexDirection: "row",
|
|
35
|
+
alignItems: "center",
|
|
36
|
+
justifyContent: "center",
|
|
37
|
+
gap: 4
|
|
38
|
+
},
|
|
39
|
+
segmentText: {
|
|
40
|
+
fontWeight: "500",
|
|
41
|
+
textAlign: "center"
|
|
42
|
+
},
|
|
43
|
+
disabled: {
|
|
44
|
+
opacity: 0.5
|
|
45
|
+
},
|
|
46
|
+
divider: {
|
|
47
|
+
width: 1,
|
|
48
|
+
alignSelf: "stretch"
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
// src/components/segment-button/segment-button.hook.ts
|
|
53
|
+
import { useMemo } from "react";
|
|
54
|
+
import { getSafeThemeColor, withPaletteNumber } from "@xaui/core";
|
|
55
|
+
function useSegmentSizeStyles(size) {
|
|
56
|
+
const theme = useXUITheme();
|
|
57
|
+
return useMemo(() => {
|
|
58
|
+
const sizes = {
|
|
59
|
+
xs: {
|
|
60
|
+
paddingHorizontal: theme.spacing.sm,
|
|
61
|
+
paddingVertical: theme.spacing.xs,
|
|
62
|
+
minHeight: 32,
|
|
63
|
+
fontSize: theme.fontSizes.xs,
|
|
64
|
+
iconSize: 14
|
|
65
|
+
},
|
|
66
|
+
sm: {
|
|
67
|
+
paddingHorizontal: theme.spacing.md,
|
|
68
|
+
paddingVertical: theme.spacing.xs,
|
|
69
|
+
minHeight: 36,
|
|
70
|
+
fontSize: theme.fontSizes.sm,
|
|
71
|
+
iconSize: 16
|
|
72
|
+
},
|
|
73
|
+
md: {
|
|
74
|
+
paddingHorizontal: theme.spacing.md,
|
|
75
|
+
paddingVertical: theme.spacing.sm,
|
|
76
|
+
minHeight: 40,
|
|
77
|
+
fontSize: theme.fontSizes.md,
|
|
78
|
+
iconSize: 18
|
|
79
|
+
},
|
|
80
|
+
lg: {
|
|
81
|
+
paddingHorizontal: theme.spacing.lg,
|
|
82
|
+
paddingVertical: theme.spacing.md,
|
|
83
|
+
minHeight: 48,
|
|
84
|
+
fontSize: theme.fontSizes.lg,
|
|
85
|
+
iconSize: 20
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
return sizes[size];
|
|
89
|
+
}, [size, theme]);
|
|
90
|
+
}
|
|
91
|
+
function useSegmentVariantStyles(themeColor, variant, elevation = 0) {
|
|
92
|
+
const theme = useXUITheme();
|
|
93
|
+
const safeThemeColor = getSafeThemeColor(themeColor);
|
|
94
|
+
const colorScheme = theme.colors[safeThemeColor];
|
|
95
|
+
const selectedBackgroundColor = withPaletteNumber(colorScheme.main, 400);
|
|
96
|
+
return useMemo(() => {
|
|
97
|
+
const variants = {
|
|
98
|
+
outlined: {
|
|
99
|
+
containerBackground: "transparent",
|
|
100
|
+
containerBorderWidth: theme.borderWidth.md,
|
|
101
|
+
containerBorderColor: colorScheme.main,
|
|
102
|
+
selectedBackground: selectedBackgroundColor,
|
|
103
|
+
unselectedBackground: "transparent",
|
|
104
|
+
selectedTextColor: colorScheme.foreground,
|
|
105
|
+
unselectedTextColor: colorScheme.main
|
|
106
|
+
},
|
|
107
|
+
flat: {
|
|
108
|
+
containerBackground: colorScheme.background,
|
|
109
|
+
containerBorderWidth: 0,
|
|
110
|
+
containerBorderColor: "transparent",
|
|
111
|
+
selectedBackground: selectedBackgroundColor,
|
|
112
|
+
unselectedBackground: "transparent",
|
|
113
|
+
selectedTextColor: colorScheme.foreground,
|
|
114
|
+
unselectedTextColor: colorScheme.main
|
|
115
|
+
},
|
|
116
|
+
light: {
|
|
117
|
+
containerBackground: "transparent",
|
|
118
|
+
containerBorderWidth: 0,
|
|
119
|
+
containerBorderColor: "transparent",
|
|
120
|
+
selectedBackground: selectedBackgroundColor,
|
|
121
|
+
unselectedBackground: "transparent",
|
|
122
|
+
selectedTextColor: colorScheme.foreground,
|
|
123
|
+
unselectedTextColor: colorScheme.main
|
|
124
|
+
},
|
|
125
|
+
faded: {
|
|
126
|
+
containerBackground: `${colorScheme.background}95`,
|
|
127
|
+
containerBorderWidth: theme.borderWidth.md,
|
|
128
|
+
containerBorderColor: `${colorScheme.main}90`,
|
|
129
|
+
selectedBackground: selectedBackgroundColor,
|
|
130
|
+
unselectedBackground: "transparent",
|
|
131
|
+
selectedTextColor: colorScheme.foreground,
|
|
132
|
+
unselectedTextColor: colorScheme.main
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
const baseStyle = variants[variant] ?? variants.outlined;
|
|
136
|
+
const shouldApplyElevation = variant !== "outlined" && variant !== "light";
|
|
137
|
+
const shadowStyles = elevation === 0 ? {} : elevation === 1 ? theme.shadows.sm : elevation === 2 ? theme.shadows.md : elevation === 3 ? theme.shadows.lg : theme.shadows.xl;
|
|
138
|
+
return {
|
|
139
|
+
...baseStyle,
|
|
140
|
+
containerShadow: shouldApplyElevation && elevation > 0 ? shadowStyles : baseStyle.containerShadow
|
|
141
|
+
};
|
|
142
|
+
}, [variant, colorScheme, theme, elevation]);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// src/components/segment-button/segment-button-context.ts
|
|
146
|
+
import { createContext, useContext } from "react";
|
|
147
|
+
var SegmentButtonContext = createContext(void 0);
|
|
148
|
+
var useSegmentButtonContext = () => {
|
|
149
|
+
const context = useContext(SegmentButtonContext);
|
|
150
|
+
if (!context) {
|
|
151
|
+
throw new Error(
|
|
152
|
+
"SegmentButtonItem must be used within a SegmentButton component"
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
return context;
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
// src/components/segment-button/segment-button.tsx
|
|
159
|
+
var SegmentButton = ({
|
|
160
|
+
children,
|
|
161
|
+
selected: controlledSelected,
|
|
162
|
+
defaultSelected,
|
|
163
|
+
onSelectionChange,
|
|
164
|
+
selectionMode = "single",
|
|
165
|
+
themeColor = "primary",
|
|
166
|
+
variant = "outlined",
|
|
167
|
+
size = "md",
|
|
168
|
+
radius = "full",
|
|
169
|
+
fullWidth = false,
|
|
170
|
+
isDisabled = false,
|
|
171
|
+
showCheckmark = true,
|
|
172
|
+
elevation = 0,
|
|
173
|
+
customAppearance
|
|
174
|
+
}) => {
|
|
175
|
+
const isControlled = controlledSelected !== void 0;
|
|
176
|
+
const [internalSelected, setInternalSelected] = useState(
|
|
177
|
+
() => defaultSelected ?? ""
|
|
178
|
+
);
|
|
179
|
+
const selected = isControlled ? controlledSelected : internalSelected;
|
|
180
|
+
const selectedKeys = useMemo2(() => {
|
|
181
|
+
if (Array.isArray(selected)) return selected;
|
|
182
|
+
return selected ? [selected] : [];
|
|
183
|
+
}, [selected]);
|
|
184
|
+
const variantStyles = useSegmentVariantStyles(themeColor, variant, elevation);
|
|
185
|
+
const radiusStyles = useBorderRadiusStyles(radius);
|
|
186
|
+
const toggleItem = useCallback(
|
|
187
|
+
(key) => {
|
|
188
|
+
let nextSelected;
|
|
189
|
+
if (selectionMode === "single") {
|
|
190
|
+
nextSelected = key;
|
|
191
|
+
} else {
|
|
192
|
+
const isCurrentlySelected = selectedKeys.includes(key);
|
|
193
|
+
if (isCurrentlySelected && selectedKeys.length > 1) {
|
|
194
|
+
nextSelected = selectedKeys.filter((k) => k !== key);
|
|
195
|
+
} else if (!isCurrentlySelected) {
|
|
196
|
+
nextSelected = [...selectedKeys, key];
|
|
197
|
+
} else {
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
if (!isControlled) {
|
|
202
|
+
setInternalSelected(nextSelected);
|
|
203
|
+
}
|
|
204
|
+
onSelectionChange?.(nextSelected);
|
|
205
|
+
},
|
|
206
|
+
[selectionMode, selectedKeys, onSelectionChange, isControlled]
|
|
207
|
+
);
|
|
208
|
+
const contextValue = useMemo2(
|
|
209
|
+
() => ({
|
|
210
|
+
selectedKeys,
|
|
211
|
+
toggleItem,
|
|
212
|
+
themeColor,
|
|
213
|
+
variant,
|
|
214
|
+
size,
|
|
215
|
+
elevation,
|
|
216
|
+
isDisabled,
|
|
217
|
+
showCheckmark
|
|
218
|
+
}),
|
|
219
|
+
[
|
|
220
|
+
selectedKeys,
|
|
221
|
+
toggleItem,
|
|
222
|
+
themeColor,
|
|
223
|
+
variant,
|
|
224
|
+
size,
|
|
225
|
+
elevation,
|
|
226
|
+
isDisabled,
|
|
227
|
+
showCheckmark
|
|
228
|
+
]
|
|
229
|
+
);
|
|
230
|
+
const showDivider = variant === "outlined" || variant === "faded";
|
|
231
|
+
const childrenArray = React.Children.toArray(children);
|
|
232
|
+
const getItemKey = (child) => {
|
|
233
|
+
if (!React.isValidElement(child)) {
|
|
234
|
+
return void 0;
|
|
235
|
+
}
|
|
236
|
+
return child.props.itemKey;
|
|
237
|
+
};
|
|
238
|
+
return /* @__PURE__ */ React.createElement(SegmentButtonContext.Provider, { value: contextValue }, /* @__PURE__ */ React.createElement(
|
|
239
|
+
View,
|
|
240
|
+
{
|
|
241
|
+
style: [
|
|
242
|
+
styles.container,
|
|
243
|
+
{
|
|
244
|
+
backgroundColor: variantStyles.containerBackground,
|
|
245
|
+
borderWidth: variantStyles.containerBorderWidth,
|
|
246
|
+
borderColor: variantStyles.containerBorderColor,
|
|
247
|
+
borderRadius: radiusStyles.borderRadius,
|
|
248
|
+
...variantStyles.containerShadow
|
|
249
|
+
},
|
|
250
|
+
fullWidth && styles.fullWidth,
|
|
251
|
+
customAppearance?.container
|
|
252
|
+
]
|
|
253
|
+
},
|
|
254
|
+
childrenArray.map((child, index) => {
|
|
255
|
+
const isLast = index === childrenArray.length - 1;
|
|
256
|
+
const childItemKey = getItemKey(child);
|
|
257
|
+
const childKey = childItemKey ?? index;
|
|
258
|
+
const isSelected = selectedKeys.includes(String(childKey));
|
|
259
|
+
const nextChildKey = !isLast ? getItemKey(childrenArray[index + 1]) : void 0;
|
|
260
|
+
const nextSelected = nextChildKey ? selectedKeys.includes(String(nextChildKey)) : false;
|
|
261
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, { key: childKey }, child, showDivider && !isLast && !isSelected && !nextSelected && /* @__PURE__ */ React.createElement(
|
|
262
|
+
View,
|
|
263
|
+
{
|
|
264
|
+
style: [
|
|
265
|
+
styles.divider,
|
|
266
|
+
{
|
|
267
|
+
backgroundColor: variantStyles.containerBorderColor
|
|
268
|
+
}
|
|
269
|
+
]
|
|
270
|
+
}
|
|
271
|
+
));
|
|
272
|
+
})
|
|
273
|
+
));
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
// src/components/segment-button/segment-button-item.tsx
|
|
277
|
+
import React2, { useEffect, useRef } from "react";
|
|
278
|
+
import { Pressable, Text, View as View2, Animated as Animated2 } from "react-native";
|
|
279
|
+
import Svg, { Path } from "react-native-svg";
|
|
280
|
+
|
|
281
|
+
// src/components/segment-button/segment-button.animation.ts
|
|
282
|
+
import { Animated } from "react-native";
|
|
283
|
+
var runCheckmarkEnterAnimation = (animatedValue) => {
|
|
284
|
+
animatedValue.setValue(0);
|
|
285
|
+
Animated.timing(animatedValue, {
|
|
286
|
+
toValue: 1,
|
|
287
|
+
duration: 200,
|
|
288
|
+
useNativeDriver: true
|
|
289
|
+
}).start();
|
|
290
|
+
};
|
|
291
|
+
var runCheckmarkExitAnimation = (animatedValue) => {
|
|
292
|
+
Animated.timing(animatedValue, {
|
|
293
|
+
toValue: 0,
|
|
294
|
+
duration: 150,
|
|
295
|
+
useNativeDriver: true
|
|
296
|
+
}).start();
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
// src/components/segment-button/segment-button-item.tsx
|
|
300
|
+
var CheckIcon = ({ size, color }) => /* @__PURE__ */ React2.createElement(Svg, { width: size, height: size, viewBox: "0 0 24 24", fill: "none" }, /* @__PURE__ */ React2.createElement(
|
|
301
|
+
Path,
|
|
302
|
+
{
|
|
303
|
+
d: "M20 6L9 17l-5-5",
|
|
304
|
+
stroke: color,
|
|
305
|
+
strokeWidth: 2.5,
|
|
306
|
+
strokeLinecap: "round",
|
|
307
|
+
strokeLinejoin: "round"
|
|
308
|
+
}
|
|
309
|
+
));
|
|
310
|
+
var SegmentButtonItem = ({
|
|
311
|
+
itemKey,
|
|
312
|
+
label,
|
|
313
|
+
startContent,
|
|
314
|
+
icon,
|
|
315
|
+
endContent,
|
|
316
|
+
checkIndicator,
|
|
317
|
+
isDisabled: itemDisabled = false,
|
|
318
|
+
customAppearance
|
|
319
|
+
}) => {
|
|
320
|
+
const {
|
|
321
|
+
selectedKeys,
|
|
322
|
+
toggleItem,
|
|
323
|
+
themeColor,
|
|
324
|
+
variant,
|
|
325
|
+
size,
|
|
326
|
+
elevation,
|
|
327
|
+
isDisabled: groupDisabled,
|
|
328
|
+
showCheckmark
|
|
329
|
+
} = useSegmentButtonContext();
|
|
330
|
+
const isSelected = selectedKeys.includes(itemKey);
|
|
331
|
+
const disabled = groupDisabled || itemDisabled;
|
|
332
|
+
const checkmarkAnim = useRef(new Animated2.Value(isSelected ? 1 : 0)).current;
|
|
333
|
+
const prevSelected = useRef(isSelected);
|
|
334
|
+
useEffect(() => {
|
|
335
|
+
if (isSelected && !prevSelected.current) {
|
|
336
|
+
runCheckmarkEnterAnimation(checkmarkAnim);
|
|
337
|
+
} else if (!isSelected && prevSelected.current) {
|
|
338
|
+
runCheckmarkExitAnimation(checkmarkAnim);
|
|
339
|
+
}
|
|
340
|
+
prevSelected.current = isSelected;
|
|
341
|
+
}, [isSelected, checkmarkAnim]);
|
|
342
|
+
const sizeStyles = useSegmentSizeStyles(size);
|
|
343
|
+
const variantStyles = useSegmentVariantStyles(themeColor, variant, elevation);
|
|
344
|
+
const handlePress = () => {
|
|
345
|
+
if (!disabled) {
|
|
346
|
+
toggleItem(itemKey);
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
const backgroundColor = isSelected ? variantStyles.selectedBackground : variantStyles.unselectedBackground;
|
|
350
|
+
const textColor = isSelected ? variantStyles.selectedTextColor : variantStyles.unselectedTextColor;
|
|
351
|
+
const showCheck = isSelected && showCheckmark;
|
|
352
|
+
const startNode = showCheck ? checkIndicator ?? /* @__PURE__ */ React2.createElement(CheckIcon, { size: sizeStyles.iconSize, color: textColor }) : startContent ?? icon;
|
|
353
|
+
return /* @__PURE__ */ React2.createElement(
|
|
354
|
+
Pressable,
|
|
355
|
+
{
|
|
356
|
+
style: [styles.segment, disabled && styles.disabled],
|
|
357
|
+
onPress: handlePress,
|
|
358
|
+
disabled
|
|
359
|
+
},
|
|
360
|
+
/* @__PURE__ */ React2.createElement(
|
|
361
|
+
View2,
|
|
362
|
+
{
|
|
363
|
+
style: [
|
|
364
|
+
styles.segmentInner,
|
|
365
|
+
{
|
|
366
|
+
paddingHorizontal: sizeStyles.paddingHorizontal,
|
|
367
|
+
paddingVertical: sizeStyles.paddingVertical,
|
|
368
|
+
minHeight: sizeStyles.minHeight,
|
|
369
|
+
backgroundColor
|
|
370
|
+
},
|
|
371
|
+
isSelected ? customAppearance?.selectedSegment : customAppearance?.segment
|
|
372
|
+
]
|
|
373
|
+
},
|
|
374
|
+
/* @__PURE__ */ React2.createElement(View2, { style: styles.segmentContent }, startNode && /* @__PURE__ */ React2.createElement(
|
|
375
|
+
Animated2.View,
|
|
376
|
+
{
|
|
377
|
+
style: {
|
|
378
|
+
opacity: showCheck ? checkmarkAnim : 1,
|
|
379
|
+
transform: [{ scale: showCheck ? checkmarkAnim : 1 }]
|
|
380
|
+
}
|
|
381
|
+
},
|
|
382
|
+
startNode
|
|
383
|
+
), /* @__PURE__ */ React2.createElement(
|
|
384
|
+
Text,
|
|
385
|
+
{
|
|
386
|
+
numberOfLines: 1,
|
|
387
|
+
style: [
|
|
388
|
+
styles.segmentText,
|
|
389
|
+
{
|
|
390
|
+
fontSize: sizeStyles.fontSize,
|
|
391
|
+
color: textColor
|
|
392
|
+
},
|
|
393
|
+
isSelected ? customAppearance?.selectedText : customAppearance?.text
|
|
394
|
+
]
|
|
395
|
+
},
|
|
396
|
+
label
|
|
397
|
+
), endContent)
|
|
398
|
+
)
|
|
399
|
+
);
|
|
400
|
+
};
|
|
401
|
+
SegmentButtonItem.displayName = "SegmentButtonItem";
|
|
7
402
|
export {
|
|
8
403
|
SegmentButton,
|
|
9
404
|
SegmentButtonItem
|
package/dist/select/index.js
CHANGED