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,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _reactNative = require("react-native");
|
|
9
|
+
var _reactNativeReanimated = _interopRequireWildcard(require("react-native-reanimated"));
|
|
10
|
+
var _figmaVariablesResolver = require("../../design-tokens/figma-variables-resolver");
|
|
11
|
+
var _useToast = require("./useToast");
|
|
12
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
13
|
+
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); }
|
|
14
|
+
const ANIMATION_DURATION = 250;
|
|
15
|
+
function Toast({
|
|
16
|
+
id,
|
|
17
|
+
title,
|
|
18
|
+
timeout = 4000,
|
|
19
|
+
onClose,
|
|
20
|
+
modes = {},
|
|
21
|
+
placement = 'bottom',
|
|
22
|
+
style
|
|
23
|
+
}) {
|
|
24
|
+
const timerRef = (0, _react.useRef)(null);
|
|
25
|
+
(0, _react.useEffect)(() => {
|
|
26
|
+
if (timeout <= 0) return;
|
|
27
|
+
timerRef.current = setTimeout(() => (0, _useToast.closeToast)(id), timeout);
|
|
28
|
+
return () => {
|
|
29
|
+
if (timerRef.current) clearTimeout(timerRef.current);
|
|
30
|
+
};
|
|
31
|
+
}, [id, timeout]);
|
|
32
|
+
const backgroundColor = (0, _figmaVariablesResolver.getVariableByName)('toast/background', modes) || '#303338';
|
|
33
|
+
const foreground = (0, _figmaVariablesResolver.getVariableByName)('toast/foreground', modes) || '#ffffff';
|
|
34
|
+
const fontSize = (0, _figmaVariablesResolver.getVariableByName)('toast/fontSize', modes) || 14;
|
|
35
|
+
const fontFamily = (0, _figmaVariablesResolver.getVariableByName)('toast/fontFamily', modes) || undefined;
|
|
36
|
+
const fontWeight = (0, _figmaVariablesResolver.getVariableByName)('toast/fontWeight', modes) || '500';
|
|
37
|
+
const lineHeight = (0, _figmaVariablesResolver.getVariableByName)('toast/lineHeight', modes) || 18;
|
|
38
|
+
const radius = (0, _figmaVariablesResolver.getVariableByName)('toast/radius', modes) || 14;
|
|
39
|
+
const paddingHorizontal = (0, _figmaVariablesResolver.getVariableByName)('toast/padding/horizontal', modes) || 16;
|
|
40
|
+
const paddingVertical = (0, _figmaVariablesResolver.getVariableByName)('toast/padding/vertical', modes) || 14;
|
|
41
|
+
const gap = (0, _figmaVariablesResolver.getVariableByName)('toast/gap', modes) || 8;
|
|
42
|
+
const borderWidth = (0, _figmaVariablesResolver.getVariableByName)('toast/border/size', modes) || 1;
|
|
43
|
+
const borderColor = (0, _figmaVariablesResolver.getVariableByName)('toast/border/color', modes) || 'rgba(255,255,255,0.1)';
|
|
44
|
+
const shadowBlurPrimary = (0, _figmaVariablesResolver.getVariableByName)('toast/shadow/primary/blur', modes) || 48;
|
|
45
|
+
const shadowOffsetYPrimary = (0, _figmaVariablesResolver.getVariableByName)('toast/shadow/primary/offsetY', modes) || 16;
|
|
46
|
+
const shadowColorPrimary = (0, _figmaVariablesResolver.getVariableByName)('toast/shadow/primary/color', modes) || 'rgba(13,13,15,0.16)';
|
|
47
|
+
const enterAnimation = placement === 'top' ? _reactNativeReanimated.SlideInUp.duration(ANIMATION_DURATION) : _reactNativeReanimated.SlideInDown.duration(ANIMATION_DURATION);
|
|
48
|
+
const containerStyle = {
|
|
49
|
+
backgroundColor,
|
|
50
|
+
borderRadius: radius,
|
|
51
|
+
paddingHorizontal,
|
|
52
|
+
paddingVertical,
|
|
53
|
+
gap,
|
|
54
|
+
borderWidth,
|
|
55
|
+
borderColor,
|
|
56
|
+
shadowColor: shadowColorPrimary,
|
|
57
|
+
shadowOffset: {
|
|
58
|
+
width: 0,
|
|
59
|
+
height: shadowOffsetYPrimary
|
|
60
|
+
},
|
|
61
|
+
shadowOpacity: 1,
|
|
62
|
+
shadowRadius: shadowBlurPrimary / 2,
|
|
63
|
+
elevation: 8
|
|
64
|
+
};
|
|
65
|
+
const textStyle = {
|
|
66
|
+
color: foreground,
|
|
67
|
+
fontSize,
|
|
68
|
+
fontFamily,
|
|
69
|
+
fontWeight: String(fontWeight),
|
|
70
|
+
lineHeight
|
|
71
|
+
};
|
|
72
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeReanimated.default.View, {
|
|
73
|
+
entering: enterAnimation,
|
|
74
|
+
exiting: _reactNativeReanimated.FadeOut.duration(ANIMATION_DURATION),
|
|
75
|
+
style: [styles.toast, containerStyle, style],
|
|
76
|
+
accessibilityRole: "alert",
|
|
77
|
+
accessibilityLiveRegion: "assertive",
|
|
78
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
|
|
79
|
+
style: textStyle,
|
|
80
|
+
numberOfLines: 2,
|
|
81
|
+
children: title
|
|
82
|
+
})
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
const styles = _reactNative.StyleSheet.create({
|
|
86
|
+
toast: {
|
|
87
|
+
alignSelf: 'center',
|
|
88
|
+
maxWidth: '90%',
|
|
89
|
+
minWidth: 200,
|
|
90
|
+
overflow: 'hidden'
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
var _default = exports.default = Toast;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _reactNative = require("react-native");
|
|
9
|
+
var _reactNativeSafeAreaContext = require("react-native-safe-area-context");
|
|
10
|
+
var _useToast = require("./useToast");
|
|
11
|
+
var _Toast = _interopRequireDefault(require("./Toast"));
|
|
12
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
13
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
|
+
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); }
|
|
15
|
+
function ToastProvider({
|
|
16
|
+
children,
|
|
17
|
+
maxVisibleToasts = 3,
|
|
18
|
+
placement = 'bottom',
|
|
19
|
+
modes
|
|
20
|
+
}) {
|
|
21
|
+
const {
|
|
22
|
+
toasts
|
|
23
|
+
} = (0, _useToast.useToast)();
|
|
24
|
+
const insets = (0, _reactNativeSafeAreaContext.useSafeAreaInsets)();
|
|
25
|
+
const visibleToasts = (0, _react.useMemo)(() => toasts.slice(-maxVisibleToasts), [toasts, maxVisibleToasts]);
|
|
26
|
+
const regionStyle = (0, _react.useMemo)(() => [styles.region, placement === 'top' ? {
|
|
27
|
+
top: insets.top + 8
|
|
28
|
+
} : {
|
|
29
|
+
bottom: insets.bottom + 8
|
|
30
|
+
}], [placement, insets.top, insets.bottom]);
|
|
31
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
|
|
32
|
+
style: styles.container,
|
|
33
|
+
children: [children, visibleToasts.length > 0 && /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
|
|
34
|
+
style: regionStyle,
|
|
35
|
+
pointerEvents: "box-none",
|
|
36
|
+
children: visibleToasts.map(entry => /*#__PURE__*/(0, _jsxRuntime.jsx)(_Toast.default, {
|
|
37
|
+
id: entry.id,
|
|
38
|
+
title: entry.title,
|
|
39
|
+
timeout: entry.timeout,
|
|
40
|
+
onClose: entry.onClose,
|
|
41
|
+
modes: entry.modes ?? modes,
|
|
42
|
+
placement: placement
|
|
43
|
+
}, entry.id))
|
|
44
|
+
})]
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
const styles = _reactNative.StyleSheet.create({
|
|
48
|
+
container: {
|
|
49
|
+
flex: 1
|
|
50
|
+
},
|
|
51
|
+
region: {
|
|
52
|
+
position: 'absolute',
|
|
53
|
+
left: 0,
|
|
54
|
+
right: 0,
|
|
55
|
+
alignItems: 'center',
|
|
56
|
+
gap: 8,
|
|
57
|
+
zIndex: 9999,
|
|
58
|
+
pointerEvents: 'box-none'
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
var _default = exports.default = ToastProvider;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.addToast = addToast;
|
|
7
|
+
exports.closeAll = closeAll;
|
|
8
|
+
exports.closeToast = closeToast;
|
|
9
|
+
exports.useToast = useToast;
|
|
10
|
+
var _react = require("react");
|
|
11
|
+
let idCounter = 0;
|
|
12
|
+
let toasts = [];
|
|
13
|
+
const listeners = new Set();
|
|
14
|
+
function emit() {
|
|
15
|
+
for (const listener of listeners) {
|
|
16
|
+
listener();
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function getSnapshot() {
|
|
20
|
+
return toasts;
|
|
21
|
+
}
|
|
22
|
+
function subscribe(listener) {
|
|
23
|
+
listeners.add(listener);
|
|
24
|
+
return () => {
|
|
25
|
+
listeners.delete(listener);
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function addToast(options) {
|
|
29
|
+
const id = `toast-${++idCounter}`;
|
|
30
|
+
const entry = {
|
|
31
|
+
id,
|
|
32
|
+
title: options.title,
|
|
33
|
+
timeout: options.timeout ?? 4000,
|
|
34
|
+
onClose: options.onClose,
|
|
35
|
+
modes: options.modes
|
|
36
|
+
};
|
|
37
|
+
toasts = [...toasts, entry];
|
|
38
|
+
emit();
|
|
39
|
+
return id;
|
|
40
|
+
}
|
|
41
|
+
function closeToast(id) {
|
|
42
|
+
const entry = toasts.find(t => t.id === id);
|
|
43
|
+
toasts = toasts.filter(t => t.id !== id);
|
|
44
|
+
emit();
|
|
45
|
+
entry?.onClose?.();
|
|
46
|
+
}
|
|
47
|
+
function closeAll() {
|
|
48
|
+
const prev = toasts;
|
|
49
|
+
toasts = [];
|
|
50
|
+
emit();
|
|
51
|
+
prev.forEach(t => t.onClose?.());
|
|
52
|
+
}
|
|
53
|
+
function useToast() {
|
|
54
|
+
const queue = (0, _react.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
|
|
55
|
+
return {
|
|
56
|
+
toasts: queue,
|
|
57
|
+
addToast: (0, _react.useCallback)(addToast, []),
|
|
58
|
+
closeToast: (0, _react.useCallback)(closeToast, []),
|
|
59
|
+
closeAll: (0, _react.useCallback)(closeAll, [])
|
|
60
|
+
};
|
|
61
|
+
}
|
|
@@ -279,6 +279,18 @@ Object.defineProperty(exports, "ThreadHero", {
|
|
|
279
279
|
return _ThreadHero.default;
|
|
280
280
|
}
|
|
281
281
|
});
|
|
282
|
+
Object.defineProperty(exports, "Toast", {
|
|
283
|
+
enumerable: true,
|
|
284
|
+
get: function () {
|
|
285
|
+
return _Toast.default;
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
Object.defineProperty(exports, "ToastProvider", {
|
|
289
|
+
enumerable: true,
|
|
290
|
+
get: function () {
|
|
291
|
+
return _ToastProvider.default;
|
|
292
|
+
}
|
|
293
|
+
});
|
|
282
294
|
Object.defineProperty(exports, "Tooltip", {
|
|
283
295
|
enumerable: true,
|
|
284
296
|
get: function () {
|
|
@@ -309,12 +321,36 @@ Object.defineProperty(exports, "VStack", {
|
|
|
309
321
|
return _VStack.default;
|
|
310
322
|
}
|
|
311
323
|
});
|
|
324
|
+
Object.defineProperty(exports, "addToast", {
|
|
325
|
+
enumerable: true,
|
|
326
|
+
get: function () {
|
|
327
|
+
return _useToast.addToast;
|
|
328
|
+
}
|
|
329
|
+
});
|
|
330
|
+
Object.defineProperty(exports, "closeAll", {
|
|
331
|
+
enumerable: true,
|
|
332
|
+
get: function () {
|
|
333
|
+
return _useToast.closeAll;
|
|
334
|
+
}
|
|
335
|
+
});
|
|
336
|
+
Object.defineProperty(exports, "closeToast", {
|
|
337
|
+
enumerable: true,
|
|
338
|
+
get: function () {
|
|
339
|
+
return _useToast.closeToast;
|
|
340
|
+
}
|
|
341
|
+
});
|
|
312
342
|
Object.defineProperty(exports, "useFormContext", {
|
|
313
343
|
enumerable: true,
|
|
314
344
|
get: function () {
|
|
315
345
|
return _Form.useFormContext;
|
|
316
346
|
}
|
|
317
347
|
});
|
|
348
|
+
Object.defineProperty(exports, "useToast", {
|
|
349
|
+
enumerable: true,
|
|
350
|
+
get: function () {
|
|
351
|
+
return _useToast.useToast;
|
|
352
|
+
}
|
|
353
|
+
});
|
|
318
354
|
var _ActionFooter = _interopRequireDefault(require("./ActionFooter/ActionFooter"));
|
|
319
355
|
var _AppBar = _interopRequireDefault(require("./AppBar/AppBar"));
|
|
320
356
|
var _Avatar = _interopRequireDefault(require("./Avatar/Avatar"));
|
|
@@ -366,5 +402,8 @@ var _InputSearch = _interopRequireDefault(require("./InputSearch/InputSearch"));
|
|
|
366
402
|
var _SupportText = _interopRequireDefault(require("./SupportText/SupportText"));
|
|
367
403
|
var _SupportTextIcon = _interopRequireDefault(require("./SupportText/SupportTextIcon"));
|
|
368
404
|
var _RadioButton = _interopRequireDefault(require("./RadioButton/RadioButton"));
|
|
405
|
+
var _Toast = _interopRequireDefault(require("./Toast/Toast"));
|
|
406
|
+
var _ToastProvider = _interopRequireDefault(require("./Toast/ToastProvider"));
|
|
407
|
+
var _useToast = require("./Toast/useToast");
|
|
369
408
|
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); }
|
|
370
409
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|