@dropi/react-native-design-system 0.3.7 → 0.3.9
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/lib/molecules/Toasts/FeedbackToast/FeedbackToast.d.ts +4 -7
- package/lib/molecules/Toasts/FeedbackToast/FeedbackToast.js +9 -42
- package/lib/molecules/Toasts/ToastProvider/ToastProvider.d.ts +11 -0
- package/lib/molecules/Toasts/ToastProvider/ToastProvider.js +189 -0
- package/lib/molecules/Toasts/ToastProvider/index.d.ts +2 -0
- package/lib/molecules/Toasts/ToastProvider/index.js +19 -0
- package/lib/molecules/Toasts/ToastProvider/useToast.d.ts +3 -0
- package/lib/molecules/Toasts/ToastProvider/useToast.js +16 -0
- package/lib/molecules/Toasts/index.d.ts +2 -0
- package/lib/molecules/Toasts/index.js +22 -0
- package/lib/molecules/Toasts/types.d.ts +11 -0
- package/lib/molecules/Toasts/types.js +5 -0
- package/package.json +1 -1
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
export type
|
|
1
|
+
import type { ToastTypes } from '../types';
|
|
2
|
+
export type FeedbackToastProps = {
|
|
3
3
|
type: ToastTypes;
|
|
4
4
|
title?: string;
|
|
5
5
|
message?: string;
|
|
6
|
-
|
|
6
|
+
onClose: () => void;
|
|
7
7
|
};
|
|
8
|
-
export type
|
|
9
|
-
animateOut: () => void;
|
|
10
|
-
};
|
|
11
|
-
export declare const FeedbackToast: import("react").ForwardRefExoticComponent<ToastConfig & import("react").RefAttributes<ToastRef>>;
|
|
8
|
+
export declare const FeedbackToast: ({ type, title, message, onClose }: FeedbackToastProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -12,48 +12,17 @@ var _constants = require("../../../constants");
|
|
|
12
12
|
var _atoms = require("../../../atoms");
|
|
13
13
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
14
14
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
|
-
const FeedbackToast =
|
|
15
|
+
const FeedbackToast = ({
|
|
16
16
|
type,
|
|
17
17
|
title,
|
|
18
18
|
message,
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
const slideAnim = (0, _react.useRef)(new _reactNative.Animated.Value(-100)).current;
|
|
22
|
-
const [isAnimating, setIsAnimating] = (0, _react.useState)(false);
|
|
19
|
+
onClose
|
|
20
|
+
}) => {
|
|
23
21
|
const animation = (0, _react.useRef)(null);
|
|
24
|
-
const closeToast = () => {
|
|
25
|
-
if (isAnimating) return;
|
|
26
|
-
setIsAnimating(true);
|
|
27
|
-
_reactNative.Animated.timing(slideAnim, {
|
|
28
|
-
toValue: -100,
|
|
29
|
-
duration: 400,
|
|
30
|
-
useNativeDriver: false
|
|
31
|
-
}).start(() => {
|
|
32
|
-
setIsAnimating(false);
|
|
33
|
-
setShowToast(false);
|
|
34
|
-
});
|
|
35
|
-
};
|
|
36
|
-
(0, _react.useEffect)(() => {
|
|
37
|
-
// playSound()
|
|
38
|
-
_reactNative.Animated.sequence([_reactNative.Animated.timing(slideAnim, {
|
|
39
|
-
toValue: _reactNative.Platform.OS === 'ios' ? 100 : 50 + _utils.statusBarHeight,
|
|
40
|
-
duration: 300,
|
|
41
|
-
useNativeDriver: false
|
|
42
|
-
}), _reactNative.Animated.timing(slideAnim, {
|
|
43
|
-
toValue: _reactNative.Platform.OS === 'ios' ? 80 : 30 + _utils.statusBarHeight,
|
|
44
|
-
duration: 120,
|
|
45
|
-
useNativeDriver: false
|
|
46
|
-
})]).start();
|
|
47
|
-
}, []);
|
|
48
|
-
(0, _react.useImperativeHandle)(ref, () => ({
|
|
49
|
-
animateOut: closeToast
|
|
50
|
-
}));
|
|
51
22
|
const lottieFile = type === 'success' ? require('../../../../assets/lottie/afirmacion.json') : type === 'error' ? require('../../../../assets/lottie/buscando.json') : type === 'warning' ? require('../../../../assets/lottie/alerta.json') : require('../../../../assets/lottie/pregunta.json');
|
|
52
23
|
const bandColor = type === 'success' ? _constants.colors['Success-500'].light : type === 'error' ? _constants.colors['Error-500'].light : type === 'warning' ? _constants.colors['Warning-500'].light : _constants.colors['Info-500'].light;
|
|
53
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.
|
|
54
|
-
style:
|
|
55
|
-
top: slideAnim
|
|
56
|
-
}],
|
|
24
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
|
|
25
|
+
style: styles.toastContainer,
|
|
57
26
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
|
|
58
27
|
style: {
|
|
59
28
|
backgroundColor: bandColor,
|
|
@@ -108,15 +77,14 @@ const FeedbackToast = exports.FeedbackToast = /*#__PURE__*/(0, _react.forwardRef
|
|
|
108
77
|
variant: "secondary",
|
|
109
78
|
size: "large",
|
|
110
79
|
postIcon: "close-large",
|
|
111
|
-
onPress:
|
|
80
|
+
onPress: onClose
|
|
112
81
|
})]
|
|
113
82
|
})]
|
|
114
83
|
});
|
|
115
|
-
}
|
|
84
|
+
};
|
|
85
|
+
exports.FeedbackToast = FeedbackToast;
|
|
116
86
|
const styles = _reactNative.StyleSheet.create({
|
|
117
87
|
toastContainer: {
|
|
118
|
-
position: 'absolute',
|
|
119
|
-
zIndex: 99,
|
|
120
88
|
backgroundColor: '#fff',
|
|
121
89
|
width: _utils.windowWidth - 32,
|
|
122
90
|
maxWidth: 700,
|
|
@@ -131,7 +99,6 @@ const styles = _reactNative.StyleSheet.create({
|
|
|
131
99
|
},
|
|
132
100
|
shadowOpacity: 0.25,
|
|
133
101
|
shadowRadius: _constants.radius['border-1'],
|
|
134
|
-
elevation: 5
|
|
135
|
-
alignSelf: 'center'
|
|
102
|
+
elevation: 5
|
|
136
103
|
}
|
|
137
104
|
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ShowToastParams } from '../types';
|
|
3
|
+
type ToastContextValue = {
|
|
4
|
+
showToast: (params: ShowToastParams) => void;
|
|
5
|
+
};
|
|
6
|
+
export declare const ToastContext: React.Context<ToastContextValue | undefined>;
|
|
7
|
+
type ToastProviderProps = {
|
|
8
|
+
children: React.ReactNode;
|
|
9
|
+
};
|
|
10
|
+
export declare const ToastProvider: ({ children }: ToastProviderProps) => import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ToastProvider = exports.ToastContext = void 0;
|
|
7
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _reactNative = require("react-native");
|
|
9
|
+
var _FeedbackToast = require("../FeedbackToast/FeedbackToast");
|
|
10
|
+
var _utils = require("../../../utils");
|
|
11
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
12
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
13
|
+
const ToastContext = exports.ToastContext = /*#__PURE__*/(0, _react.createContext)(undefined);
|
|
14
|
+
const DEFAULT_DURATION = 4000;
|
|
15
|
+
const ToastProvider = ({
|
|
16
|
+
children
|
|
17
|
+
}) => {
|
|
18
|
+
const [currentToast, setCurrentToast] = (0, _react.useState)(null);
|
|
19
|
+
const [queue, setQueue] = (0, _react.useState)([]);
|
|
20
|
+
const [isAnimating, setIsAnimating] = (0, _react.useState)(false);
|
|
21
|
+
const slideAnim = (0, _react.useRef)(new _reactNative.Animated.Value(-200)).current;
|
|
22
|
+
const timeoutRef = (0, _react.useRef)(null);
|
|
23
|
+
const animationRef = (0, _react.useRef)(null);
|
|
24
|
+
const toastIdCounter = (0, _react.useRef)(0);
|
|
25
|
+
|
|
26
|
+
// Cleanup timers on unmount
|
|
27
|
+
(0, _react.useEffect)(() => {
|
|
28
|
+
return () => {
|
|
29
|
+
if (timeoutRef.current) {
|
|
30
|
+
clearTimeout(timeoutRef.current);
|
|
31
|
+
}
|
|
32
|
+
if (animationRef.current) {
|
|
33
|
+
animationRef.current.stop();
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
}, []);
|
|
37
|
+
|
|
38
|
+
// Animate in the toast
|
|
39
|
+
const animateIn = (0, _react.useCallback)(() => {
|
|
40
|
+
if (isAnimating) return;
|
|
41
|
+
setIsAnimating(true);
|
|
42
|
+
slideAnim.setValue(-200); // Reset to initial position
|
|
43
|
+
|
|
44
|
+
animationRef.current = _reactNative.Animated.sequence([_reactNative.Animated.timing(slideAnim, {
|
|
45
|
+
toValue: _reactNative.Platform.OS === 'ios' ? 100 : 50 + _utils.statusBarHeight,
|
|
46
|
+
duration: 300,
|
|
47
|
+
useNativeDriver: true
|
|
48
|
+
}), _reactNative.Animated.timing(slideAnim, {
|
|
49
|
+
toValue: _reactNative.Platform.OS === 'ios' ? 80 : 30 + _utils.statusBarHeight,
|
|
50
|
+
duration: 120,
|
|
51
|
+
useNativeDriver: true
|
|
52
|
+
})]);
|
|
53
|
+
animationRef.current.start(({
|
|
54
|
+
finished
|
|
55
|
+
}) => {
|
|
56
|
+
if (finished) {
|
|
57
|
+
setIsAnimating(false);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}, [slideAnim, isAnimating]);
|
|
61
|
+
|
|
62
|
+
// Animate out the toast
|
|
63
|
+
const animateOut = (0, _react.useCallback)(callback => {
|
|
64
|
+
if (isAnimating && animationRef.current) {
|
|
65
|
+
animationRef.current.stop();
|
|
66
|
+
}
|
|
67
|
+
setIsAnimating(true);
|
|
68
|
+
animationRef.current = _reactNative.Animated.timing(slideAnim, {
|
|
69
|
+
toValue: -200,
|
|
70
|
+
duration: 400,
|
|
71
|
+
useNativeDriver: true
|
|
72
|
+
});
|
|
73
|
+
animationRef.current.start(({
|
|
74
|
+
finished
|
|
75
|
+
}) => {
|
|
76
|
+
if (finished) {
|
|
77
|
+
setIsAnimating(false);
|
|
78
|
+
// Defer state updates to avoid useInsertionEffect error
|
|
79
|
+
requestAnimationFrame(() => {
|
|
80
|
+
setCurrentToast(null);
|
|
81
|
+
if (callback) {
|
|
82
|
+
callback();
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}, [slideAnim, isAnimating]);
|
|
88
|
+
|
|
89
|
+
// Process the next toast in the queue
|
|
90
|
+
const processQueue = (0, _react.useCallback)(() => {
|
|
91
|
+
// Use setTimeout to defer state update
|
|
92
|
+
setTimeout(() => {
|
|
93
|
+
setQueue(prevQueue => {
|
|
94
|
+
if (prevQueue.length === 0) return prevQueue;
|
|
95
|
+
const [nextToast, ...remainingQueue] = prevQueue;
|
|
96
|
+
setCurrentToast(nextToast);
|
|
97
|
+
return remainingQueue;
|
|
98
|
+
});
|
|
99
|
+
}, 0);
|
|
100
|
+
}, []);
|
|
101
|
+
|
|
102
|
+
// Handle auto-dismiss
|
|
103
|
+
(0, _react.useEffect)(() => {
|
|
104
|
+
if (!currentToast) return;
|
|
105
|
+
|
|
106
|
+
// Clear any existing timeout
|
|
107
|
+
if (timeoutRef.current) {
|
|
108
|
+
clearTimeout(timeoutRef.current);
|
|
109
|
+
timeoutRef.current = null;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Animate in
|
|
113
|
+
animateIn();
|
|
114
|
+
|
|
115
|
+
// Set auto-dismiss if duration > 0
|
|
116
|
+
if (currentToast.duration && currentToast.duration > 0) {
|
|
117
|
+
timeoutRef.current = setTimeout(() => {
|
|
118
|
+
animateOut(() => {
|
|
119
|
+
processQueue();
|
|
120
|
+
});
|
|
121
|
+
}, currentToast.duration);
|
|
122
|
+
}
|
|
123
|
+
return () => {
|
|
124
|
+
if (timeoutRef.current) {
|
|
125
|
+
clearTimeout(timeoutRef.current);
|
|
126
|
+
timeoutRef.current = null;
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
}, [currentToast, animateIn, animateOut, processQueue]);
|
|
130
|
+
|
|
131
|
+
// Handle manual close
|
|
132
|
+
const handleClose = (0, _react.useCallback)(() => {
|
|
133
|
+
if (timeoutRef.current) {
|
|
134
|
+
clearTimeout(timeoutRef.current);
|
|
135
|
+
timeoutRef.current = null;
|
|
136
|
+
}
|
|
137
|
+
animateOut(() => {
|
|
138
|
+
processQueue();
|
|
139
|
+
});
|
|
140
|
+
}, [animateOut, processQueue]);
|
|
141
|
+
|
|
142
|
+
// Public API: showToast
|
|
143
|
+
const showToast = (0, _react.useCallback)(params => {
|
|
144
|
+
const newToast = {
|
|
145
|
+
id: `toast-${toastIdCounter.current++}`,
|
|
146
|
+
type: params.type,
|
|
147
|
+
title: params.title,
|
|
148
|
+
message: params.message,
|
|
149
|
+
duration: params.duration ?? DEFAULT_DURATION
|
|
150
|
+
};
|
|
151
|
+
if (!currentToast && !isAnimating) {
|
|
152
|
+
// No toast showing, show immediately
|
|
153
|
+
setCurrentToast(newToast);
|
|
154
|
+
} else {
|
|
155
|
+
// Toast already showing, add to queue
|
|
156
|
+
setQueue(prevQueue => [...prevQueue, newToast]);
|
|
157
|
+
}
|
|
158
|
+
}, [currentToast, isAnimating]);
|
|
159
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(ToastContext.Provider, {
|
|
160
|
+
value: {
|
|
161
|
+
showToast
|
|
162
|
+
},
|
|
163
|
+
children: [children, currentToast && /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Animated.View, {
|
|
164
|
+
style: [styles.toastWrapper, {
|
|
165
|
+
transform: [{
|
|
166
|
+
translateY: slideAnim
|
|
167
|
+
}]
|
|
168
|
+
}],
|
|
169
|
+
pointerEvents: "box-none",
|
|
170
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_FeedbackToast.FeedbackToast, {
|
|
171
|
+
type: currentToast.type,
|
|
172
|
+
title: currentToast.title,
|
|
173
|
+
message: currentToast.message,
|
|
174
|
+
onClose: handleClose
|
|
175
|
+
})
|
|
176
|
+
})]
|
|
177
|
+
});
|
|
178
|
+
};
|
|
179
|
+
exports.ToastProvider = ToastProvider;
|
|
180
|
+
const styles = _reactNative.StyleSheet.create({
|
|
181
|
+
toastWrapper: {
|
|
182
|
+
position: 'absolute',
|
|
183
|
+
top: 0,
|
|
184
|
+
left: 0,
|
|
185
|
+
right: 0,
|
|
186
|
+
zIndex: 9999,
|
|
187
|
+
alignItems: 'center'
|
|
188
|
+
}
|
|
189
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "ToastProvider", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _ToastProvider.ToastProvider;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "useToast", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _useToast.useToast;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
var _ToastProvider = require("./ToastProvider");
|
|
19
|
+
var _useToast = require("./useToast");
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useToast = void 0;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _ToastProvider = require("./ToastProvider");
|
|
9
|
+
const useToast = () => {
|
|
10
|
+
const context = (0, _react.useContext)(_ToastProvider.ToastContext);
|
|
11
|
+
if (context === undefined) {
|
|
12
|
+
throw new Error('useToast must be used within a ToastProvider');
|
|
13
|
+
}
|
|
14
|
+
return context;
|
|
15
|
+
};
|
|
16
|
+
exports.useToast = useToast;
|
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
var _types = require("./types");
|
|
7
|
+
Object.keys(_types).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _types[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return _types[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
6
17
|
var _FeedbackToast = require("./FeedbackToast");
|
|
7
18
|
Object.keys(_FeedbackToast).forEach(function (key) {
|
|
8
19
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -13,4 +24,15 @@ Object.keys(_FeedbackToast).forEach(function (key) {
|
|
|
13
24
|
return _FeedbackToast[key];
|
|
14
25
|
}
|
|
15
26
|
});
|
|
27
|
+
});
|
|
28
|
+
var _ToastProvider = require("./ToastProvider");
|
|
29
|
+
Object.keys(_ToastProvider).forEach(function (key) {
|
|
30
|
+
if (key === "default" || key === "__esModule") return;
|
|
31
|
+
if (key in exports && exports[key] === _ToastProvider[key]) return;
|
|
32
|
+
Object.defineProperty(exports, key, {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function () {
|
|
35
|
+
return _ToastProvider[key];
|
|
36
|
+
}
|
|
37
|
+
});
|
|
16
38
|
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type ToastTypes = 'success' | 'error' | 'warning' | 'info';
|
|
2
|
+
export type ToastConfig = {
|
|
3
|
+
id: string;
|
|
4
|
+
type: ToastTypes;
|
|
5
|
+
title?: string;
|
|
6
|
+
message?: string;
|
|
7
|
+
duration?: number;
|
|
8
|
+
};
|
|
9
|
+
export type ShowToastParams = Omit<ToastConfig, 'id'> & {
|
|
10
|
+
duration?: number;
|
|
11
|
+
};
|