jfs-components 0.0.42 → 0.0.43
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/commonjs/components/Toast/Toast.js +93 -0
- package/lib/commonjs/components/Toast/ToastProvider.js +61 -0
- package/lib/commonjs/components/Toast/useToast.js +61 -0
- package/lib/commonjs/components/index.js +39 -0
- package/lib/commonjs/design-tokens/JFS Variables-variables-full.json +1 -1
- package/lib/commonjs/icons/registry.js +1 -1
- package/lib/module/components/Toast/Toast.js +88 -0
- package/lib/module/components/Toast/ToastProvider.js +55 -0
- package/lib/module/components/Toast/useToast.js +54 -0
- package/lib/module/components/index.js +4 -1
- package/lib/module/design-tokens/JFS Variables-variables-full.json +1 -1
- package/lib/module/icons/registry.js +1 -1
- package/lib/typescript/src/components/Toast/Toast.d.ts +14 -0
- package/lib/typescript/src/components/Toast/ToastProvider.d.ts +11 -0
- package/lib/typescript/src/components/Toast/useToast.d.ts +24 -0
- package/lib/typescript/src/components/index.d.ts +3 -0
- package/lib/typescript/src/icons/registry.d.ts +1 -1
- package/package.json +1 -1
- package/src/components/Toast/Toast.tsx +105 -0
- package/src/components/Toast/ToastProvider.tsx +75 -0
- package/src/components/Toast/useToast.ts +80 -0
- package/src/components/index.ts +3 -0
- package/src/design-tokens/JFS Variables-variables-full.json +1 -1
- package/src/icons/registry.ts +1 -1
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import React, { useEffect, useRef } from 'react';
|
|
4
|
+
import { StyleSheet, Text } from 'react-native';
|
|
5
|
+
import Animated, { FadeOut, SlideInDown, SlideInUp } from 'react-native-reanimated';
|
|
6
|
+
import { getVariableByName } from '../../design-tokens/figma-variables-resolver';
|
|
7
|
+
import { closeToast } from './useToast';
|
|
8
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
9
|
+
const ANIMATION_DURATION = 250;
|
|
10
|
+
function Toast({
|
|
11
|
+
id,
|
|
12
|
+
title,
|
|
13
|
+
timeout = 4000,
|
|
14
|
+
onClose,
|
|
15
|
+
modes = {},
|
|
16
|
+
placement = 'bottom',
|
|
17
|
+
style
|
|
18
|
+
}) {
|
|
19
|
+
const timerRef = useRef(null);
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
if (timeout <= 0) return;
|
|
22
|
+
timerRef.current = setTimeout(() => closeToast(id), timeout);
|
|
23
|
+
return () => {
|
|
24
|
+
if (timerRef.current) clearTimeout(timerRef.current);
|
|
25
|
+
};
|
|
26
|
+
}, [id, timeout]);
|
|
27
|
+
const backgroundColor = getVariableByName('toast/background', modes) || '#303338';
|
|
28
|
+
const foreground = getVariableByName('toast/foreground', modes) || '#ffffff';
|
|
29
|
+
const fontSize = getVariableByName('toast/fontSize', modes) || 14;
|
|
30
|
+
const fontFamily = getVariableByName('toast/fontFamily', modes) || undefined;
|
|
31
|
+
const fontWeight = getVariableByName('toast/fontWeight', modes) || '500';
|
|
32
|
+
const lineHeight = getVariableByName('toast/lineHeight', modes) || 18;
|
|
33
|
+
const radius = getVariableByName('toast/radius', modes) || 14;
|
|
34
|
+
const paddingHorizontal = getVariableByName('toast/padding/horizontal', modes) || 16;
|
|
35
|
+
const paddingVertical = getVariableByName('toast/padding/vertical', modes) || 14;
|
|
36
|
+
const gap = getVariableByName('toast/gap', modes) || 8;
|
|
37
|
+
const borderWidth = getVariableByName('toast/border/size', modes) || 1;
|
|
38
|
+
const borderColor = getVariableByName('toast/border/color', modes) || 'rgba(255,255,255,0.1)';
|
|
39
|
+
const shadowBlurPrimary = getVariableByName('toast/shadow/primary/blur', modes) || 48;
|
|
40
|
+
const shadowOffsetYPrimary = getVariableByName('toast/shadow/primary/offsetY', modes) || 16;
|
|
41
|
+
const shadowColorPrimary = getVariableByName('toast/shadow/primary/color', modes) || 'rgba(13,13,15,0.16)';
|
|
42
|
+
const enterAnimation = placement === 'top' ? SlideInUp.duration(ANIMATION_DURATION) : SlideInDown.duration(ANIMATION_DURATION);
|
|
43
|
+
const containerStyle = {
|
|
44
|
+
backgroundColor,
|
|
45
|
+
borderRadius: radius,
|
|
46
|
+
paddingHorizontal,
|
|
47
|
+
paddingVertical,
|
|
48
|
+
gap,
|
|
49
|
+
borderWidth,
|
|
50
|
+
borderColor,
|
|
51
|
+
shadowColor: shadowColorPrimary,
|
|
52
|
+
shadowOffset: {
|
|
53
|
+
width: 0,
|
|
54
|
+
height: shadowOffsetYPrimary
|
|
55
|
+
},
|
|
56
|
+
shadowOpacity: 1,
|
|
57
|
+
shadowRadius: shadowBlurPrimary / 2,
|
|
58
|
+
elevation: 8
|
|
59
|
+
};
|
|
60
|
+
const textStyle = {
|
|
61
|
+
color: foreground,
|
|
62
|
+
fontSize,
|
|
63
|
+
fontFamily,
|
|
64
|
+
fontWeight: String(fontWeight),
|
|
65
|
+
lineHeight
|
|
66
|
+
};
|
|
67
|
+
return /*#__PURE__*/_jsx(Animated.View, {
|
|
68
|
+
entering: enterAnimation,
|
|
69
|
+
exiting: FadeOut.duration(ANIMATION_DURATION),
|
|
70
|
+
style: [styles.toast, containerStyle, style],
|
|
71
|
+
accessibilityRole: "alert",
|
|
72
|
+
accessibilityLiveRegion: "assertive",
|
|
73
|
+
children: /*#__PURE__*/_jsx(Text, {
|
|
74
|
+
style: textStyle,
|
|
75
|
+
numberOfLines: 2,
|
|
76
|
+
children: title
|
|
77
|
+
})
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
const styles = StyleSheet.create({
|
|
81
|
+
toast: {
|
|
82
|
+
alignSelf: 'center',
|
|
83
|
+
maxWidth: '90%',
|
|
84
|
+
minWidth: 200,
|
|
85
|
+
overflow: 'hidden'
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
export default Toast;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import React, { useMemo } from 'react';
|
|
4
|
+
import { StyleSheet, View } from 'react-native';
|
|
5
|
+
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
6
|
+
import { useToast } from './useToast';
|
|
7
|
+
import Toast from './Toast';
|
|
8
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
9
|
+
function ToastProvider({
|
|
10
|
+
children,
|
|
11
|
+
maxVisibleToasts = 3,
|
|
12
|
+
placement = 'bottom',
|
|
13
|
+
modes
|
|
14
|
+
}) {
|
|
15
|
+
const {
|
|
16
|
+
toasts
|
|
17
|
+
} = useToast();
|
|
18
|
+
const insets = useSafeAreaInsets();
|
|
19
|
+
const visibleToasts = useMemo(() => toasts.slice(-maxVisibleToasts), [toasts, maxVisibleToasts]);
|
|
20
|
+
const regionStyle = useMemo(() => [styles.region, placement === 'top' ? {
|
|
21
|
+
top: insets.top + 8
|
|
22
|
+
} : {
|
|
23
|
+
bottom: insets.bottom + 8
|
|
24
|
+
}], [placement, insets.top, insets.bottom]);
|
|
25
|
+
return /*#__PURE__*/_jsxs(View, {
|
|
26
|
+
style: styles.container,
|
|
27
|
+
children: [children, visibleToasts.length > 0 && /*#__PURE__*/_jsx(View, {
|
|
28
|
+
style: regionStyle,
|
|
29
|
+
pointerEvents: "box-none",
|
|
30
|
+
children: visibleToasts.map(entry => /*#__PURE__*/_jsx(Toast, {
|
|
31
|
+
id: entry.id,
|
|
32
|
+
title: entry.title,
|
|
33
|
+
timeout: entry.timeout,
|
|
34
|
+
onClose: entry.onClose,
|
|
35
|
+
modes: entry.modes ?? modes,
|
|
36
|
+
placement: placement
|
|
37
|
+
}, entry.id))
|
|
38
|
+
})]
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
const styles = StyleSheet.create({
|
|
42
|
+
container: {
|
|
43
|
+
flex: 1
|
|
44
|
+
},
|
|
45
|
+
region: {
|
|
46
|
+
position: 'absolute',
|
|
47
|
+
left: 0,
|
|
48
|
+
right: 0,
|
|
49
|
+
alignItems: 'center',
|
|
50
|
+
gap: 8,
|
|
51
|
+
zIndex: 9999,
|
|
52
|
+
pointerEvents: 'box-none'
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
export default ToastProvider;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { useCallback, useSyncExternalStore } from 'react';
|
|
4
|
+
let idCounter = 0;
|
|
5
|
+
let toasts = [];
|
|
6
|
+
const listeners = new Set();
|
|
7
|
+
function emit() {
|
|
8
|
+
for (const listener of listeners) {
|
|
9
|
+
listener();
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function getSnapshot() {
|
|
13
|
+
return toasts;
|
|
14
|
+
}
|
|
15
|
+
function subscribe(listener) {
|
|
16
|
+
listeners.add(listener);
|
|
17
|
+
return () => {
|
|
18
|
+
listeners.delete(listener);
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export function addToast(options) {
|
|
22
|
+
const id = `toast-${++idCounter}`;
|
|
23
|
+
const entry = {
|
|
24
|
+
id,
|
|
25
|
+
title: options.title,
|
|
26
|
+
timeout: options.timeout ?? 4000,
|
|
27
|
+
onClose: options.onClose,
|
|
28
|
+
modes: options.modes
|
|
29
|
+
};
|
|
30
|
+
toasts = [...toasts, entry];
|
|
31
|
+
emit();
|
|
32
|
+
return id;
|
|
33
|
+
}
|
|
34
|
+
export function closeToast(id) {
|
|
35
|
+
const entry = toasts.find(t => t.id === id);
|
|
36
|
+
toasts = toasts.filter(t => t.id !== id);
|
|
37
|
+
emit();
|
|
38
|
+
entry?.onClose?.();
|
|
39
|
+
}
|
|
40
|
+
export function closeAll() {
|
|
41
|
+
const prev = toasts;
|
|
42
|
+
toasts = [];
|
|
43
|
+
emit();
|
|
44
|
+
prev.forEach(t => t.onClose?.());
|
|
45
|
+
}
|
|
46
|
+
export function useToast() {
|
|
47
|
+
const queue = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
48
|
+
return {
|
|
49
|
+
toasts: queue,
|
|
50
|
+
addToast: useCallback(addToast, []),
|
|
51
|
+
closeToast: useCallback(closeToast, []),
|
|
52
|
+
closeAll: useCallback(closeAll, [])
|
|
53
|
+
};
|
|
54
|
+
}
|
|
@@ -51,4 +51,7 @@ export { default as ChipSelect } from './ChipSelect/ChipSelect';
|
|
|
51
51
|
export { default as InputSearch } from './InputSearch/InputSearch';
|
|
52
52
|
export { default as SupportText } from './SupportText/SupportText';
|
|
53
53
|
export { default as SupportTextIcon } from './SupportText/SupportTextIcon';
|
|
54
|
-
export { default as RadioButton } from './RadioButton/RadioButton';
|
|
54
|
+
export { default as RadioButton } from './RadioButton/RadioButton';
|
|
55
|
+
export { default as Toast } from './Toast/Toast';
|
|
56
|
+
export { default as ToastProvider } from './Toast/ToastProvider';
|
|
57
|
+
export { useToast, addToast, closeToast, closeAll } from './Toast/useToast';
|