@xaui/native 0.0.26 → 0.0.28
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/LICENSE +21 -0
- package/README.md +105 -228
- package/dist/alert/index.cjs +92 -166
- package/dist/alert/index.js +2 -1
- package/dist/app-bar/index.cjs +24 -98
- package/dist/app-bar/index.js +2 -1
- package/dist/autocomplete/index.cjs +192 -281
- package/dist/autocomplete/index.js +36 -48
- package/dist/avatar/index.cjs +59 -133
- package/dist/avatar/index.js +2 -1
- package/dist/badge/index.cjs +26 -99
- package/dist/badge/index.js +2 -1
- package/dist/bottom-sheet/index.cjs +5 -456
- package/dist/bottom-sheet/index.js +4 -363
- package/dist/bottom-tab-bar/index.cjs +93 -167
- package/dist/bottom-tab-bar/index.js +2 -2
- package/dist/button/index.cjs +73 -525
- package/dist/button/index.js +3 -2
- package/dist/card/index.cjs +76 -169
- package/dist/card/index.js +2 -2
- package/dist/carousel/index.cjs +68 -145
- package/dist/carousel/index.js +1 -1
- package/dist/chart/index.cjs +132 -173
- package/dist/checkbox/index.cjs +70 -143
- package/dist/checkbox/index.js +2 -1
- package/dist/chip/index.cjs +89 -164
- package/dist/chip/index.js +2 -1
- package/dist/chunk-BD72HIPR.cjs +75 -0
- package/dist/chunk-DHSTKO3K.cjs +19 -0
- package/dist/{chunk-CZFDZPAS.js → chunk-DXXNBF5P.js} +5 -0
- package/dist/{chunk-UI5L26KD.js → chunk-F7WH4DMG.js} +1 -1
- package/dist/chunk-GBHQCAKW.js +19 -0
- package/dist/chunk-HC2SSHNU.js +368 -0
- package/dist/chunk-HSPTLUFA.cjs +7 -0
- package/dist/chunk-JEGEPGVU.js +287 -0
- package/dist/chunk-KTLGDLCB.cjs +287 -0
- package/dist/{chunk-GHCVNQET.js → chunk-LTKYHG5V.js} +5 -12
- package/dist/{chunk-ULJSCNPE.js → chunk-LUBWRVI2.js} +1 -1
- package/dist/chunk-OQ2BLOOG.cjs +138 -0
- package/dist/chunk-QMYWIWSX.cjs +384 -0
- package/dist/chunk-XFPPR2VB.cjs +368 -0
- package/dist/core/index.cjs +22 -168
- package/dist/core/index.d.cts +1 -1
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.js +5 -3
- package/dist/datepicker/index.cjs +239 -320
- package/dist/datepicker/index.js +2 -1
- package/dist/divider/index.cjs +5 -145
- package/dist/divider/index.js +3 -2
- package/dist/drawer/index.cjs +39 -112
- package/dist/drawer/index.js +2 -1
- package/dist/expansion-panel/index.cjs +91 -230
- package/dist/expansion-panel/index.js +3 -2
- package/dist/fab/index.cjs +6 -722
- package/dist/fab/index.js +4 -3
- package/dist/fab-menu/index.cjs +81 -814
- package/dist/fab-menu/index.js +4 -3
- package/dist/feature-discovery/index.cjs +72 -139
- package/dist/feature-discovery/index.js +2 -2
- package/dist/index.cjs +1 -18
- package/dist/indicator/index.cjs +5 -445
- package/dist/indicator/index.js +3 -2
- package/dist/input/index.cjs +214 -282
- package/dist/input/index.js +2 -2
- package/dist/list/index.cjs +71 -146
- package/dist/list/index.js +2 -1
- package/dist/menu/index.cjs +59 -127
- package/dist/menu/index.js +2 -2
- package/dist/menubox/index.cjs +60 -132
- package/dist/menubox/index.js +2 -1
- package/dist/pager/index.cjs +42 -80
- package/dist/progress/index.cjs +43 -114
- package/dist/progress/index.js +2 -1
- package/dist/radio/index.cjs +82 -154
- package/dist/radio/index.js +2 -1
- package/dist/segment-button/index.cjs +60 -147
- package/dist/segment-button/index.js +2 -2
- package/dist/select/index.cjs +149 -224
- package/dist/select/index.js +10 -22
- package/dist/skeleton/index.cjs +23 -94
- package/dist/skeleton/index.js +2 -2
- package/dist/slider/index.cjs +77 -156
- package/dist/slider/index.js +2 -1
- package/dist/snackbar/index.cjs +420 -0
- package/dist/snackbar/index.d.cts +175 -0
- package/dist/snackbar/index.d.ts +175 -0
- package/dist/snackbar/index.js +420 -0
- package/dist/stepper/index.cjs +121 -195
- package/dist/stepper/index.js +2 -1
- package/dist/switch/index.cjs +48 -121
- package/dist/switch/index.js +2 -1
- package/dist/tabs/index.cjs +67 -151
- package/dist/tabs/index.js +2 -1
- package/dist/timepicker/index.cjs +135 -593
- package/dist/timepicker/index.js +24 -383
- package/dist/toolbar/index.cjs +59 -128
- package/dist/toolbar/index.js +2 -1
- package/dist/typography/index.cjs +37 -92
- package/dist/typography/index.d.cts +1 -1
- package/dist/typography/index.d.ts +1 -1
- package/dist/typography/index.js +20 -1
- package/dist/view/index.cjs +178 -223
- package/package.json +7 -1
- package/dist/chunk-3XSXTM3G.js +0 -661
- package/dist/chunk-4KSZLONZ.js +0 -79
- package/dist/chunk-I4V5Y5GD.js +0 -76
- package/dist/chunk-URBEEDFX.js +0 -79
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }require('../chunk-HSPTLUFA.cjs');
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
var _chunkOQ2BLOOGcjs = require('../chunk-OQ2BLOOG.cjs');
|
|
6
|
+
|
|
7
|
+
// src/components/snackbar/snackbar.tsx
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
var _react = require('react'); var _react2 = _interopRequireDefault(_react);
|
|
16
|
+
var _reactnative = require('react-native');
|
|
17
|
+
|
|
18
|
+
// src/components/snackbar/snackbar.style.ts
|
|
19
|
+
|
|
20
|
+
var SNACKBAR_DEFAULT_DURATION = 4e3;
|
|
21
|
+
var SNACKBAR_DEFAULT_HORIZONTAL_INSET = 16;
|
|
22
|
+
var SNACKBAR_DEFAULT_VERTICAL_INSET = 16;
|
|
23
|
+
var SNACKBAR_DEFAULT_SPACING = 8;
|
|
24
|
+
var SNACKBAR_DEFAULT_MAX_WIDTH = 640;
|
|
25
|
+
var styles = _reactnative.StyleSheet.create({
|
|
26
|
+
stackContainer: {
|
|
27
|
+
position: "absolute",
|
|
28
|
+
left: 0,
|
|
29
|
+
right: 0,
|
|
30
|
+
zIndex: 999
|
|
31
|
+
},
|
|
32
|
+
stackContent: {
|
|
33
|
+
width: "100%",
|
|
34
|
+
alignSelf: "center"
|
|
35
|
+
},
|
|
36
|
+
surface: {
|
|
37
|
+
width: "100%",
|
|
38
|
+
minHeight: 48,
|
|
39
|
+
borderRadius: 4,
|
|
40
|
+
flexDirection: "row",
|
|
41
|
+
alignItems: "center",
|
|
42
|
+
paddingLeft: 16,
|
|
43
|
+
shadowColor: "#000000",
|
|
44
|
+
shadowOffset: { width: 0, height: 1 },
|
|
45
|
+
shadowOpacity: 0.3,
|
|
46
|
+
shadowRadius: 3,
|
|
47
|
+
elevation: 4
|
|
48
|
+
},
|
|
49
|
+
surfaceWithoutActions: {
|
|
50
|
+
paddingRight: 16
|
|
51
|
+
},
|
|
52
|
+
messageWrapper: {
|
|
53
|
+
flex: 1,
|
|
54
|
+
minWidth: 0,
|
|
55
|
+
justifyContent: "center",
|
|
56
|
+
paddingRight: 8
|
|
57
|
+
},
|
|
58
|
+
messageWrapperMultiline: {
|
|
59
|
+
paddingVertical: 14
|
|
60
|
+
},
|
|
61
|
+
messageText: {
|
|
62
|
+
fontSize: 14,
|
|
63
|
+
lineHeight: 20,
|
|
64
|
+
letterSpacing: 0.25,
|
|
65
|
+
fontWeight: "400"
|
|
66
|
+
},
|
|
67
|
+
trailingActions: {
|
|
68
|
+
flexDirection: "row",
|
|
69
|
+
alignItems: "center",
|
|
70
|
+
gap: 4
|
|
71
|
+
},
|
|
72
|
+
actionButton: {
|
|
73
|
+
paddingHorizontal: 12,
|
|
74
|
+
paddingVertical: 10,
|
|
75
|
+
borderRadius: 9999,
|
|
76
|
+
minHeight: 40,
|
|
77
|
+
justifyContent: "center",
|
|
78
|
+
alignItems: "center"
|
|
79
|
+
},
|
|
80
|
+
actionText: {
|
|
81
|
+
fontSize: 14,
|
|
82
|
+
lineHeight: 20,
|
|
83
|
+
letterSpacing: 0.1,
|
|
84
|
+
fontWeight: "500"
|
|
85
|
+
},
|
|
86
|
+
closeButton: {
|
|
87
|
+
width: 48,
|
|
88
|
+
height: 48,
|
|
89
|
+
borderRadius: 9999,
|
|
90
|
+
justifyContent: "center",
|
|
91
|
+
alignItems: "center"
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
// src/components/snackbar/snackbar.hook.ts
|
|
96
|
+
|
|
97
|
+
var _core = require('@xaui/core');
|
|
98
|
+
var M3_LIGHT_INVERSE_SURFACE = "#322F35";
|
|
99
|
+
var M3_LIGHT_INVERSE_ON_SURFACE = "#F5EFF7";
|
|
100
|
+
var M3_LIGHT_INVERSE_PRIMARY = "#D0BCFF";
|
|
101
|
+
var M3_DARK_INVERSE_SURFACE = "#E6E1E5";
|
|
102
|
+
var M3_DARK_INVERSE_ON_SURFACE = "#322F35";
|
|
103
|
+
var M3_DARK_INVERSE_PRIMARY = "#6750A4";
|
|
104
|
+
var useSnackbarColors = (themeColor = "default") => {
|
|
105
|
+
const theme = _chunkOQ2BLOOGcjs.useXUITheme.call(void 0, );
|
|
106
|
+
const safeThemeColor = _core.getSafeThemeColor.call(void 0, themeColor);
|
|
107
|
+
return _react.useMemo.call(void 0, () => {
|
|
108
|
+
if (safeThemeColor === "default") {
|
|
109
|
+
const isDarkMode = theme.mode === "dark";
|
|
110
|
+
const containerColor = isDarkMode ? M3_DARK_INVERSE_SURFACE : M3_LIGHT_INVERSE_SURFACE;
|
|
111
|
+
const textColor = isDarkMode ? M3_DARK_INVERSE_ON_SURFACE : M3_LIGHT_INVERSE_ON_SURFACE;
|
|
112
|
+
const actionColor = isDarkMode ? M3_DARK_INVERSE_PRIMARY : M3_LIGHT_INVERSE_PRIMARY;
|
|
113
|
+
return {
|
|
114
|
+
containerColor,
|
|
115
|
+
textColor,
|
|
116
|
+
actionColor,
|
|
117
|
+
pressedOverlayColor: _core.withOpacity.call(void 0, textColor, 0.16)
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
const colorScheme = theme.colors[safeThemeColor];
|
|
121
|
+
return {
|
|
122
|
+
containerColor: colorScheme.main,
|
|
123
|
+
textColor: colorScheme.foreground,
|
|
124
|
+
actionColor: _core.withOpacity.call(void 0, colorScheme.foreground, 0.82),
|
|
125
|
+
pressedOverlayColor: _core.withOpacity.call(void 0, colorScheme.foreground, 0.16)
|
|
126
|
+
};
|
|
127
|
+
}, [safeThemeColor, theme]);
|
|
128
|
+
};
|
|
129
|
+
var useSnackbarStackPositionStyles = (position, insetHorizontal, insetVertical, maxWidth) => {
|
|
130
|
+
return _react.useMemo.call(void 0,
|
|
131
|
+
() => ({
|
|
132
|
+
container: position === "top" ? {
|
|
133
|
+
top: insetVertical,
|
|
134
|
+
paddingHorizontal: insetHorizontal
|
|
135
|
+
} : {
|
|
136
|
+
bottom: insetVertical,
|
|
137
|
+
paddingHorizontal: insetHorizontal
|
|
138
|
+
},
|
|
139
|
+
content: {
|
|
140
|
+
maxWidth
|
|
141
|
+
}
|
|
142
|
+
}),
|
|
143
|
+
[position, insetHorizontal, insetVertical, maxWidth]
|
|
144
|
+
);
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
// src/components/snackbar/snackbar.tsx
|
|
148
|
+
var _close = require('@xaui/icons/close');
|
|
149
|
+
var ENTER_ANIMATION_DURATION = 220;
|
|
150
|
+
var EXIT_ANIMATION_DURATION = 180;
|
|
151
|
+
var ENTER_INITIAL_SCALE = 0.92;
|
|
152
|
+
var SnackbarSurface = ({ item, duration, onDismiss }) => {
|
|
153
|
+
const {
|
|
154
|
+
id,
|
|
155
|
+
message,
|
|
156
|
+
actionLabel,
|
|
157
|
+
onActionPress,
|
|
158
|
+
closeOnActionPress = true,
|
|
159
|
+
showCloseAffordance = false,
|
|
160
|
+
themeColor = "default",
|
|
161
|
+
numberOfLines = 2,
|
|
162
|
+
customAppearance
|
|
163
|
+
} = item;
|
|
164
|
+
const { containerColor, textColor, actionColor, pressedOverlayColor } = useSnackbarColors(themeColor);
|
|
165
|
+
const opacity = _react.useRef.call(void 0, new _reactnative.Animated.Value(0)).current;
|
|
166
|
+
const scale = _react.useRef.call(void 0, new _reactnative.Animated.Value(ENTER_INITIAL_SCALE)).current;
|
|
167
|
+
const exitAnimationStartedRef = _react.useRef.call(void 0, false);
|
|
168
|
+
const dismissTimeoutRef = _react.useRef.call(void 0, null);
|
|
169
|
+
const clearDismissTimer = _react.useCallback.call(void 0, () => {
|
|
170
|
+
if (!dismissTimeoutRef.current) return;
|
|
171
|
+
clearTimeout(dismissTimeoutRef.current);
|
|
172
|
+
dismissTimeoutRef.current = null;
|
|
173
|
+
}, []);
|
|
174
|
+
const runExitAnimation = _react.useCallback.call(void 0, () => {
|
|
175
|
+
if (exitAnimationStartedRef.current) return;
|
|
176
|
+
exitAnimationStartedRef.current = true;
|
|
177
|
+
clearDismissTimer();
|
|
178
|
+
_reactnative.Animated.parallel([
|
|
179
|
+
_reactnative.Animated.timing(opacity, {
|
|
180
|
+
toValue: 0,
|
|
181
|
+
duration: EXIT_ANIMATION_DURATION,
|
|
182
|
+
easing: _reactnative.Easing.bezier(0.4, 0, 0.2, 1),
|
|
183
|
+
useNativeDriver: true
|
|
184
|
+
}),
|
|
185
|
+
_reactnative.Animated.timing(scale, {
|
|
186
|
+
toValue: ENTER_INITIAL_SCALE,
|
|
187
|
+
duration: EXIT_ANIMATION_DURATION,
|
|
188
|
+
easing: _reactnative.Easing.bezier(0.4, 0, 0.2, 1),
|
|
189
|
+
useNativeDriver: true
|
|
190
|
+
})
|
|
191
|
+
]).start(({ finished }) => {
|
|
192
|
+
if (!finished) return;
|
|
193
|
+
_optionalChain([onDismiss, 'optionalCall', _ => _(id)]);
|
|
194
|
+
});
|
|
195
|
+
}, [clearDismissTimer, id, onDismiss, opacity, scale]);
|
|
196
|
+
_react.useEffect.call(void 0, () => {
|
|
197
|
+
opacity.setValue(0);
|
|
198
|
+
scale.setValue(ENTER_INITIAL_SCALE);
|
|
199
|
+
exitAnimationStartedRef.current = false;
|
|
200
|
+
_reactnative.Animated.parallel([
|
|
201
|
+
_reactnative.Animated.timing(opacity, {
|
|
202
|
+
toValue: 1,
|
|
203
|
+
duration: ENTER_ANIMATION_DURATION,
|
|
204
|
+
easing: _reactnative.Easing.bezier(0.2, 0, 0, 1),
|
|
205
|
+
useNativeDriver: true
|
|
206
|
+
}),
|
|
207
|
+
_reactnative.Animated.timing(scale, {
|
|
208
|
+
toValue: 1,
|
|
209
|
+
duration: ENTER_ANIMATION_DURATION,
|
|
210
|
+
easing: _reactnative.Easing.bezier(0.2, 0, 0, 1),
|
|
211
|
+
useNativeDriver: true
|
|
212
|
+
})
|
|
213
|
+
]).start();
|
|
214
|
+
}, [opacity, scale]);
|
|
215
|
+
_react.useEffect.call(void 0, () => {
|
|
216
|
+
clearDismissTimer();
|
|
217
|
+
if (duration <= 0) return;
|
|
218
|
+
dismissTimeoutRef.current = globalThis.setTimeout(() => {
|
|
219
|
+
runExitAnimation();
|
|
220
|
+
}, duration);
|
|
221
|
+
return clearDismissTimer;
|
|
222
|
+
}, [clearDismissTimer, duration, runExitAnimation]);
|
|
223
|
+
_react.useEffect.call(void 0, () => {
|
|
224
|
+
return () => {
|
|
225
|
+
clearDismissTimer();
|
|
226
|
+
opacity.stopAnimation();
|
|
227
|
+
scale.stopAnimation();
|
|
228
|
+
};
|
|
229
|
+
}, [clearDismissTimer, opacity, scale]);
|
|
230
|
+
const handleDismiss = _react.useCallback.call(void 0, () => {
|
|
231
|
+
runExitAnimation();
|
|
232
|
+
}, [runExitAnimation]);
|
|
233
|
+
const handleActionPress = _react.useCallback.call(void 0, () => {
|
|
234
|
+
_optionalChain([onActionPress, 'optionalCall', _2 => _2()]);
|
|
235
|
+
if (closeOnActionPress) {
|
|
236
|
+
handleDismiss();
|
|
237
|
+
}
|
|
238
|
+
}, [onActionPress, closeOnActionPress, handleDismiss]);
|
|
239
|
+
const messageNode = _react.useMemo.call(void 0, () => {
|
|
240
|
+
if (typeof message === "string" || typeof message === "number") {
|
|
241
|
+
return /* @__PURE__ */ _react2.default.createElement(
|
|
242
|
+
_reactnative.Text,
|
|
243
|
+
{
|
|
244
|
+
style: [styles.messageText, { color: textColor }, _optionalChain([customAppearance, 'optionalAccess', _3 => _3.message])],
|
|
245
|
+
numberOfLines
|
|
246
|
+
},
|
|
247
|
+
message
|
|
248
|
+
);
|
|
249
|
+
}
|
|
250
|
+
return message;
|
|
251
|
+
}, [_optionalChain([customAppearance, 'optionalAccess', _4 => _4.message]), message, numberOfLines, textColor]);
|
|
252
|
+
const actionNode = _react.useMemo.call(void 0, () => {
|
|
253
|
+
if (actionLabel === null || actionLabel === void 0) return null;
|
|
254
|
+
if (typeof actionLabel === "string" || typeof actionLabel === "number") {
|
|
255
|
+
return /* @__PURE__ */ _react2.default.createElement(_reactnative.Text, { style: [styles.actionText, { color: actionColor }, _optionalChain([customAppearance, 'optionalAccess', _5 => _5.action])] }, actionLabel);
|
|
256
|
+
}
|
|
257
|
+
if (_react.isValidElement.call(void 0, actionLabel)) {
|
|
258
|
+
return actionLabel;
|
|
259
|
+
}
|
|
260
|
+
return null;
|
|
261
|
+
}, [actionColor, actionLabel, _optionalChain([customAppearance, 'optionalAccess', _6 => _6.action])]);
|
|
262
|
+
const hasActions = Boolean(actionNode || showCloseAffordance);
|
|
263
|
+
const isMultiline = numberOfLines > 1;
|
|
264
|
+
return /* @__PURE__ */ _react2.default.createElement(
|
|
265
|
+
_reactnative.Animated.View,
|
|
266
|
+
{
|
|
267
|
+
accessibilityRole: "alert",
|
|
268
|
+
style: [
|
|
269
|
+
styles.surface,
|
|
270
|
+
{ backgroundColor: containerColor },
|
|
271
|
+
!hasActions && styles.surfaceWithoutActions,
|
|
272
|
+
_optionalChain([customAppearance, 'optionalAccess', _7 => _7.container]),
|
|
273
|
+
{
|
|
274
|
+
opacity,
|
|
275
|
+
transform: [{ scale }]
|
|
276
|
+
}
|
|
277
|
+
]
|
|
278
|
+
},
|
|
279
|
+
/* @__PURE__ */ _react2.default.createElement(
|
|
280
|
+
_reactnative.View,
|
|
281
|
+
{
|
|
282
|
+
style: [
|
|
283
|
+
styles.messageWrapper,
|
|
284
|
+
isMultiline && styles.messageWrapperMultiline
|
|
285
|
+
]
|
|
286
|
+
},
|
|
287
|
+
messageNode
|
|
288
|
+
),
|
|
289
|
+
hasActions && /* @__PURE__ */ _react2.default.createElement(_reactnative.View, { style: styles.trailingActions }, actionNode && /* @__PURE__ */ _react2.default.createElement(
|
|
290
|
+
_reactnative.Pressable,
|
|
291
|
+
{
|
|
292
|
+
accessibilityRole: "button",
|
|
293
|
+
onPress: handleActionPress,
|
|
294
|
+
style: ({ pressed }) => [
|
|
295
|
+
styles.actionButton,
|
|
296
|
+
pressed && { backgroundColor: pressedOverlayColor }
|
|
297
|
+
]
|
|
298
|
+
},
|
|
299
|
+
actionNode
|
|
300
|
+
), showCloseAffordance && /* @__PURE__ */ _react2.default.createElement(
|
|
301
|
+
_reactnative.Pressable,
|
|
302
|
+
{
|
|
303
|
+
accessibilityRole: "button",
|
|
304
|
+
accessibilityLabel: "Close snackbar",
|
|
305
|
+
onPress: handleDismiss,
|
|
306
|
+
style: ({ pressed }) => [
|
|
307
|
+
styles.closeButton,
|
|
308
|
+
pressed && { backgroundColor: pressedOverlayColor },
|
|
309
|
+
_optionalChain([customAppearance, 'optionalAccess', _8 => _8.closeButton])
|
|
310
|
+
]
|
|
311
|
+
},
|
|
312
|
+
/* @__PURE__ */ _react2.default.createElement(_close.CloseIcon, { size: 20, color: textColor })
|
|
313
|
+
))
|
|
314
|
+
);
|
|
315
|
+
};
|
|
316
|
+
var SnackbarStack = ({
|
|
317
|
+
items,
|
|
318
|
+
onDismiss,
|
|
319
|
+
position = "bottom",
|
|
320
|
+
spacing = SNACKBAR_DEFAULT_SPACING,
|
|
321
|
+
insetHorizontal = SNACKBAR_DEFAULT_HORIZONTAL_INSET,
|
|
322
|
+
insetVertical = SNACKBAR_DEFAULT_VERTICAL_INSET,
|
|
323
|
+
maxWidth = SNACKBAR_DEFAULT_MAX_WIDTH,
|
|
324
|
+
defaultDuration = SNACKBAR_DEFAULT_DURATION,
|
|
325
|
+
usePortal = true,
|
|
326
|
+
customAppearance
|
|
327
|
+
}) => {
|
|
328
|
+
const stackPositionStyles = useSnackbarStackPositionStyles(
|
|
329
|
+
position,
|
|
330
|
+
insetHorizontal,
|
|
331
|
+
insetVertical,
|
|
332
|
+
maxWidth
|
|
333
|
+
);
|
|
334
|
+
if (!items.length) return null;
|
|
335
|
+
const itemsToRender = position === "top" ? [...items].reverse() : items;
|
|
336
|
+
const stackNode = /* @__PURE__ */ _react2.default.createElement(
|
|
337
|
+
_reactnative.View,
|
|
338
|
+
{
|
|
339
|
+
pointerEvents: "box-none",
|
|
340
|
+
style: [
|
|
341
|
+
styles.stackContainer,
|
|
342
|
+
stackPositionStyles.container,
|
|
343
|
+
_optionalChain([customAppearance, 'optionalAccess', _9 => _9.container])
|
|
344
|
+
]
|
|
345
|
+
},
|
|
346
|
+
/* @__PURE__ */ _react2.default.createElement(
|
|
347
|
+
_reactnative.View,
|
|
348
|
+
{
|
|
349
|
+
pointerEvents: "box-none",
|
|
350
|
+
style: [
|
|
351
|
+
styles.stackContent,
|
|
352
|
+
stackPositionStyles.content,
|
|
353
|
+
{ gap: spacing },
|
|
354
|
+
_optionalChain([customAppearance, 'optionalAccess', _10 => _10.content])
|
|
355
|
+
]
|
|
356
|
+
},
|
|
357
|
+
itemsToRender.map((item) => /* @__PURE__ */ _react2.default.createElement(
|
|
358
|
+
SnackbarSurface,
|
|
359
|
+
{
|
|
360
|
+
key: item.id,
|
|
361
|
+
item,
|
|
362
|
+
duration: _nullishCoalesce(item.duration, () => ( defaultDuration)),
|
|
363
|
+
onDismiss
|
|
364
|
+
}
|
|
365
|
+
))
|
|
366
|
+
)
|
|
367
|
+
);
|
|
368
|
+
return usePortal ? /* @__PURE__ */ _react2.default.createElement(_chunkOQ2BLOOGcjs.Portal, null, stackNode) : stackNode;
|
|
369
|
+
};
|
|
370
|
+
var Snackbar = ({
|
|
371
|
+
isVisible,
|
|
372
|
+
duration = SNACKBAR_DEFAULT_DURATION,
|
|
373
|
+
onClose,
|
|
374
|
+
onVisibleChange,
|
|
375
|
+
position = "bottom",
|
|
376
|
+
insetHorizontal = SNACKBAR_DEFAULT_HORIZONTAL_INSET,
|
|
377
|
+
insetVertical = SNACKBAR_DEFAULT_VERTICAL_INSET,
|
|
378
|
+
maxWidth = SNACKBAR_DEFAULT_MAX_WIDTH,
|
|
379
|
+
usePortal = true,
|
|
380
|
+
...itemProps
|
|
381
|
+
}) => {
|
|
382
|
+
const [internalVisible, setInternalVisible] = _react.useState.call(void 0, _nullishCoalesce(isVisible, () => ( true)));
|
|
383
|
+
const isControlled = typeof isVisible === "boolean";
|
|
384
|
+
const visible = isControlled ? isVisible : internalVisible;
|
|
385
|
+
const idRef = _react.useRef.call(void 0, `snackbar-${Date.now()}-${Math.random().toString(16).slice(2)}`);
|
|
386
|
+
const dismiss = _react.useCallback.call(void 0, () => {
|
|
387
|
+
if (!isControlled) {
|
|
388
|
+
setInternalVisible(false);
|
|
389
|
+
}
|
|
390
|
+
_optionalChain([onVisibleChange, 'optionalCall', _11 => _11(false)]);
|
|
391
|
+
_optionalChain([onClose, 'optionalCall', _12 => _12()]);
|
|
392
|
+
}, [isControlled, onClose, onVisibleChange]);
|
|
393
|
+
const items = _react.useMemo.call(void 0,
|
|
394
|
+
() => visible ? [
|
|
395
|
+
{
|
|
396
|
+
id: idRef.current,
|
|
397
|
+
duration,
|
|
398
|
+
...itemProps
|
|
399
|
+
}
|
|
400
|
+
] : [],
|
|
401
|
+
[duration, itemProps, visible]
|
|
402
|
+
);
|
|
403
|
+
return /* @__PURE__ */ _react2.default.createElement(
|
|
404
|
+
SnackbarStack,
|
|
405
|
+
{
|
|
406
|
+
items,
|
|
407
|
+
onDismiss: dismiss,
|
|
408
|
+
position,
|
|
409
|
+
insetHorizontal,
|
|
410
|
+
insetVertical,
|
|
411
|
+
maxWidth,
|
|
412
|
+
defaultDuration: duration,
|
|
413
|
+
usePortal
|
|
414
|
+
}
|
|
415
|
+
);
|
|
416
|
+
};
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
exports.Snackbar = Snackbar; exports.SnackbarStack = SnackbarStack;
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
import { ViewStyle, TextStyle } from 'react-native';
|
|
3
|
+
|
|
4
|
+
type ThemeColor = 'primary' | 'secondary' | 'tertiary' | 'danger' | 'warning' | 'success' | 'default';
|
|
5
|
+
|
|
6
|
+
type SnackbarPosition = 'top' | 'bottom';
|
|
7
|
+
type SnackbarCustomAppearance = {
|
|
8
|
+
/**
|
|
9
|
+
* Custom style for the snackbar surface.
|
|
10
|
+
*/
|
|
11
|
+
container?: ViewStyle;
|
|
12
|
+
/**
|
|
13
|
+
* Custom style for the message text.
|
|
14
|
+
*/
|
|
15
|
+
message?: TextStyle;
|
|
16
|
+
/**
|
|
17
|
+
* Custom style for the action label text.
|
|
18
|
+
*/
|
|
19
|
+
action?: TextStyle;
|
|
20
|
+
/**
|
|
21
|
+
* Custom style for the close affordance button.
|
|
22
|
+
*/
|
|
23
|
+
closeButton?: ViewStyle;
|
|
24
|
+
};
|
|
25
|
+
type SnackbarBaseProps = {
|
|
26
|
+
/**
|
|
27
|
+
* Message content shown inside the snackbar.
|
|
28
|
+
*/
|
|
29
|
+
message: ReactNode;
|
|
30
|
+
/**
|
|
31
|
+
* Action content displayed at the end of the snackbar.
|
|
32
|
+
*/
|
|
33
|
+
actionLabel?: ReactNode;
|
|
34
|
+
/**
|
|
35
|
+
* Callback fired when the action is pressed.
|
|
36
|
+
*/
|
|
37
|
+
onActionPress?: () => void;
|
|
38
|
+
/**
|
|
39
|
+
* If true, pressing the action also dismisses the snackbar.
|
|
40
|
+
* @default true
|
|
41
|
+
*/
|
|
42
|
+
closeOnActionPress?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* If true, shows the close affordance icon button.
|
|
45
|
+
* @default false
|
|
46
|
+
*/
|
|
47
|
+
showCloseAffordance?: boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Theme color for the snackbar. The default uses Material 3 inverse surface styling.
|
|
50
|
+
* @default 'default'
|
|
51
|
+
*/
|
|
52
|
+
themeColor?: ThemeColor;
|
|
53
|
+
/**
|
|
54
|
+
* Number of lines for the message text.
|
|
55
|
+
* @default 2
|
|
56
|
+
*/
|
|
57
|
+
numberOfLines?: number;
|
|
58
|
+
/**
|
|
59
|
+
* Custom appearance styles for snackbar parts.
|
|
60
|
+
*/
|
|
61
|
+
customAppearance?: SnackbarCustomAppearance;
|
|
62
|
+
};
|
|
63
|
+
type SnackbarProps = SnackbarBaseProps & {
|
|
64
|
+
/**
|
|
65
|
+
* Controls snackbar visibility. If omitted, snackbar is shown by default.
|
|
66
|
+
* @default true
|
|
67
|
+
*/
|
|
68
|
+
isVisible?: boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Duration in milliseconds before auto-dismiss. Set to 0 or a negative value to disable.
|
|
71
|
+
* @default 4000
|
|
72
|
+
*/
|
|
73
|
+
duration?: number;
|
|
74
|
+
/**
|
|
75
|
+
* Callback fired when the snackbar is dismissed.
|
|
76
|
+
*/
|
|
77
|
+
onClose?: () => void;
|
|
78
|
+
/**
|
|
79
|
+
* Callback fired when visibility changes.
|
|
80
|
+
*/
|
|
81
|
+
onVisibleChange?: (isVisible: boolean) => void;
|
|
82
|
+
/**
|
|
83
|
+
* Position of the snackbar on screen.
|
|
84
|
+
* @default 'bottom'
|
|
85
|
+
*/
|
|
86
|
+
position?: SnackbarPosition;
|
|
87
|
+
/**
|
|
88
|
+
* Horizontal inset from screen edges.
|
|
89
|
+
* @default 16
|
|
90
|
+
*/
|
|
91
|
+
insetHorizontal?: number;
|
|
92
|
+
/**
|
|
93
|
+
* Vertical inset from screen edge according to position.
|
|
94
|
+
* @default 16
|
|
95
|
+
*/
|
|
96
|
+
insetVertical?: number;
|
|
97
|
+
/**
|
|
98
|
+
* Maximum width of the snackbar surface.
|
|
99
|
+
* @default 640
|
|
100
|
+
*/
|
|
101
|
+
maxWidth?: number;
|
|
102
|
+
/**
|
|
103
|
+
* Render snackbar in a portal overlay.
|
|
104
|
+
* @default true
|
|
105
|
+
*/
|
|
106
|
+
usePortal?: boolean;
|
|
107
|
+
};
|
|
108
|
+
type SnackbarItem = SnackbarBaseProps & {
|
|
109
|
+
/**
|
|
110
|
+
* Unique identifier for the snackbar item in the stack.
|
|
111
|
+
*/
|
|
112
|
+
id: string;
|
|
113
|
+
/**
|
|
114
|
+
* Item-specific auto-dismiss duration in milliseconds.
|
|
115
|
+
* Set to 0 or a negative value to disable.
|
|
116
|
+
*/
|
|
117
|
+
duration?: number;
|
|
118
|
+
};
|
|
119
|
+
type SnackbarStackProps = {
|
|
120
|
+
/**
|
|
121
|
+
* Snackbar items to render in a vertical stack.
|
|
122
|
+
*/
|
|
123
|
+
items: SnackbarItem[];
|
|
124
|
+
/**
|
|
125
|
+
* Called when an item requests dismissal.
|
|
126
|
+
*/
|
|
127
|
+
onDismiss?: (id: string) => void;
|
|
128
|
+
/**
|
|
129
|
+
* Position of the stacked snackbars on screen.
|
|
130
|
+
* @default 'bottom'
|
|
131
|
+
*/
|
|
132
|
+
position?: SnackbarPosition;
|
|
133
|
+
/**
|
|
134
|
+
* Space between stacked snackbars.
|
|
135
|
+
* @default 8
|
|
136
|
+
*/
|
|
137
|
+
spacing?: number;
|
|
138
|
+
/**
|
|
139
|
+
* Horizontal inset from screen edges.
|
|
140
|
+
* @default 16
|
|
141
|
+
*/
|
|
142
|
+
insetHorizontal?: number;
|
|
143
|
+
/**
|
|
144
|
+
* Vertical inset from screen edge according to position.
|
|
145
|
+
* @default 16
|
|
146
|
+
*/
|
|
147
|
+
insetVertical?: number;
|
|
148
|
+
/**
|
|
149
|
+
* Maximum width of each snackbar surface.
|
|
150
|
+
* @default 640
|
|
151
|
+
*/
|
|
152
|
+
maxWidth?: number;
|
|
153
|
+
/**
|
|
154
|
+
* Default auto-dismiss duration for items without `duration`.
|
|
155
|
+
* @default 4000
|
|
156
|
+
*/
|
|
157
|
+
defaultDuration?: number;
|
|
158
|
+
/**
|
|
159
|
+
* Render stack in a portal overlay.
|
|
160
|
+
* @default true
|
|
161
|
+
*/
|
|
162
|
+
usePortal?: boolean;
|
|
163
|
+
/**
|
|
164
|
+
* Custom styles for stack containers.
|
|
165
|
+
*/
|
|
166
|
+
customAppearance?: {
|
|
167
|
+
container?: ViewStyle;
|
|
168
|
+
content?: ViewStyle;
|
|
169
|
+
};
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
declare const SnackbarStack: React.FC<SnackbarStackProps>;
|
|
173
|
+
declare const Snackbar: React.FC<SnackbarProps>;
|
|
174
|
+
|
|
175
|
+
export { Snackbar, type SnackbarItem, type SnackbarPosition, type SnackbarProps, SnackbarStack, type SnackbarStackProps };
|