@stokr/components-library 2.3.73 → 2.3.75

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.
@@ -108,7 +108,7 @@ const ConfirmModalComponent = _ref => {
108
108
  style: {
109
109
  marginTop: '16px'
110
110
  }
111
- }, content)), renderFooter ? /*#__PURE__*/_react.default.createElement(_ComponentWrapper.ComponentWrapper, null, renderFooter({
111
+ }, content)), renderFooter ? /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, renderFooter({
112
112
  onConfirm: handleConfirm,
113
113
  onCancel: handleCancel
114
114
  })) : /*#__PURE__*/_react.default.createElement(_ComponentWrapper.ComponentWrapper, {
@@ -28,7 +28,7 @@ const VARIANTS = {
28
28
  const Container = _styledComponents.default.div.withConfig({
29
29
  displayName: "InfoBox__Container",
30
30
  componentId: "sc-fb6dfq-0"
31
- })(["position:relative;display:flex;overflow:hidden;align-items:flex-start;align-items:center;gap:12px;padding:12px 20px 12px 16px;background:", ";border:1px solid ", ";border-radius:8px;font-size:12px;line-height:18px;letter-spacing:0.6px;font-weight:400;color:", ";&:before{content:'';display:block;width:4px;position:absolute;height:100%;left:0px;background:", ";}"], props => props.$bg, props => props.$border, _colors.default.black, props => props.$border);
31
+ })(["position:relative;display:flex;overflow:hidden;align-items:flex-start;align-items:center;gap:12px;padding:12px 20px 12px 16px;background:", ";border:1px solid ", ";border-radius:8px;font-size:12px;line-height:18px;letter-spacing:0.6px;font-weight:400;color:", ";", ""], props => props.$bg, props => props.$border, _colors.default.black, props => !props.$noLeftBorder && "\n &:before {\n content: '';\n display: block;\n width: 4px;\n position: absolute;\n height: 100%;\n left: 0px;\n background: ".concat(props.$border, ";\n }\n "));
32
32
  const DefaultIcon = _styledComponents.default.i.attrs({
33
33
  className: 'ion ion-md-information-circle-outline'
34
34
  }).withConfig({
@@ -59,7 +59,8 @@ const InfoBox = _ref => {
59
59
  children,
60
60
  icon,
61
61
  style,
62
- className
62
+ className,
63
+ noLeftBorder
63
64
  } = _ref;
64
65
  const theme = VARIANTS[variant] || VARIANTS.warning;
65
66
  const renderIcon = () => {
@@ -72,6 +73,7 @@ const InfoBox = _ref => {
72
73
  };
73
74
  return /*#__PURE__*/_react.default.createElement(Container, {
74
75
  $bg: theme.background,
76
+ $noLeftBorder: noLeftBorder,
75
77
  $border: theme.border,
76
78
  style: style,
77
79
  className: className
@@ -13,6 +13,21 @@ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r
13
13
  function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
14
14
  function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
15
15
  function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
16
+ function findScrolledElement() {
17
+ let best = null;
18
+ function walk(el) {
19
+ if (!el || el.nodeType !== 1) return;
20
+ const s = getComputedStyle(el);
21
+ const scrollable = (s.overflowY === 'auto' || s.overflowY === 'scroll' || s.overflow === 'auto' || s.overflow === 'scroll') && el.scrollHeight > el.clientHeight && el.scrollTop > 0;
22
+ if (scrollable && (!best || el.scrollTop > best.scrollTop)) best = {
23
+ el,
24
+ scrollTop: el.scrollTop
25
+ };
26
+ for (let i = 0; i < el.children.length; i++) walk(el.children[i]);
27
+ }
28
+ walk(document.body);
29
+ return best;
30
+ }
16
31
  const SideModal = _ref => {
17
32
  let {
18
33
  children,
@@ -27,60 +42,50 @@ const SideModal = _ref => {
27
42
  } = _ref,
28
43
  props = _objectWithoutProperties(_ref, _excluded);
29
44
  const [isVisible, setIsVisible] = (0, _react.useState)(false);
45
+ const savedScroll = (0, _react.useRef)(null);
30
46
  (0, _react.useEffect)(() => {
31
- // Disable scroll on background when modal is open
32
47
  if (isOpen) {
33
- // Calculate scrollbar width before hiding it
48
+ const found = findScrolledElement();
49
+ if (found) savedScroll.current = found;else if (window.scrollY > 0) savedScroll.current = {
50
+ type: 'window',
51
+ y: window.scrollY
52
+ };else savedScroll.current = null;
34
53
  const scrollbarWidth = window.innerWidth - document.documentElement.clientWidth;
35
-
36
- // Store current scroll position
37
- const scrollY = window.scrollY;
38
-
39
- // Apply styles to prevent layout shift
40
- document.body.style.position = 'fixed';
41
- document.body.style.top = "-".concat(scrollY, "px");
42
- document.body.style.left = '0';
43
- document.body.style.right = '0';
54
+ document.documentElement.style.overflow = 'hidden';
44
55
  document.body.style.overflow = 'hidden';
45
56
  document.body.style.paddingRight = "".concat(scrollbarWidth, "px");
46
-
47
- // Set CSS variable for fixed elements (like headers)
48
57
  document.documentElement.style.setProperty('--scrollbar-compensation', "".concat(scrollbarWidth, "px"));
49
-
50
- // Store scroll position for restoration
51
- document.body.dataset.scrollY = scrollY;
52
-
53
- // Small delay to trigger animation
54
58
  setTimeout(() => setIsVisible(true), 10);
55
59
  } else {
56
- // Restore scroll position
57
- const scrollY = document.body.dataset.scrollY || '0';
58
-
59
- // Reset all body styles
60
- document.body.style.position = '';
61
- document.body.style.top = '';
62
- document.body.style.left = '';
63
- document.body.style.right = '';
60
+ const saved = savedScroll.current;
61
+ savedScroll.current = null;
62
+ document.documentElement.style.overflow = '';
64
63
  document.body.style.overflow = '';
65
64
  document.body.style.paddingRight = '';
66
-
67
- // Reset CSS variable
68
65
  document.documentElement.style.setProperty('--scrollbar-compensation', '0px');
69
-
70
- // Restore scroll position
71
- window.scrollTo(0, parseInt(scrollY));
72
66
  setIsVisible(false);
67
+ if (saved) {
68
+ requestAnimationFrame(() => {
69
+ if (saved.type === 'window') window.scrollTo(0, saved.y);else if (saved.el && document.contains(saved.el)) saved.el.scrollTop = saved.scrollTop;
70
+ });
71
+ }
73
72
  }
74
73
  return () => {
75
- const scrollY = document.body.dataset.scrollY || '0';
76
- document.body.style.position = '';
77
- document.body.style.top = '';
78
- document.body.style.left = '';
79
- document.body.style.right = '';
74
+ const saved = savedScroll.current;
75
+ savedScroll.current = null;
76
+ document.documentElement.style.overflow = '';
80
77
  document.body.style.overflow = '';
81
78
  document.body.style.paddingRight = '';
82
79
  document.documentElement.style.setProperty('--scrollbar-compensation', '0px');
83
- window.scrollTo(0, parseInt(scrollY));
80
+ if (saved && saved.el && document.contains(saved.el)) {
81
+ requestAnimationFrame(() => {
82
+ saved.el.scrollTop = saved.scrollTop;
83
+ });
84
+ } else if (saved && saved.type === 'window') {
85
+ requestAnimationFrame(() => {
86
+ window.scrollTo(0, saved.y);
87
+ });
88
+ }
84
89
  };
85
90
  }, [isOpen]);
86
91
 
@@ -39,7 +39,7 @@ const AmountDisplay = _styledComponents.default.div.withConfig({
39
39
  const AmountLeft = _styledComponents.default.div.withConfig({
40
40
  displayName: "PaymentDetailsCard__AmountLeft",
41
41
  componentId: "sc-e830fo-6"
42
- })(["display:flex;align-items:center;gap:16px;flex:1;min-width:0;"]);
42
+ })(["display:flex;align-items:center;gap:12px;flex:1;min-width:0;"]);
43
43
  const CurrencyTicker = _styledComponents.default.div.withConfig({
44
44
  displayName: "PaymentDetailsCard__CurrencyTicker",
45
45
  componentId: "sc-e830fo-7"
@@ -75,7 +75,7 @@ const SectionHeader = _styledComponents.default.div.withConfig({
75
75
  const DetailsSection = _styledComponents.default.div.withConfig({
76
76
  displayName: "PaymentDetailsCard__DetailsSection",
77
77
  componentId: "sc-e830fo-15"
78
- })(["margin-bottom:", ";"], props => props.noMargin ? '0' : '20px');
78
+ })(["margin-bottom:", ";"], props => props.noMargin ? '0' : '24px');
79
79
  const DetailRow = _styledComponents.default.div.withConfig({
80
80
  displayName: "PaymentDetailsCard__DetailRow",
81
81
  componentId: "sc-e830fo-16"
@@ -189,7 +189,7 @@ const AmountBlock = _ref2 => {
189
189
  }
190
190
  return /*#__PURE__*/_react.default.createElement(CurrencyLogo, {
191
191
  color: logoColor
192
- }, currency ? currency.charAt(0).toUpperCase() : '');
192
+ });
193
193
  };
194
194
  return /*#__PURE__*/_react.default.createElement(AmountSection, null, /*#__PURE__*/_react.default.createElement(AmountLabel, {
195
195
  hasSubtitle: !!subtitle
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useTransactionPolling = exports.default = void 0;
7
+ var _react = _interopRequireWildcard(require("react"));
8
+ 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); }
9
+ /**
10
+ * Generic polling hook. Calls fetcher (with optional payload) until isSuccess(response)
11
+ * is true or maxAttempts is reached.
12
+ *
13
+ * @param {Object} options
14
+ * @param {function(payload?: any): Promise<any>} options.fetcher - Required. Async function called each poll. Receives options.payload if provided.
15
+ * @param {any} [options.payload] - Optional. Passed to fetcher each poll. Omit when fetcher needs no args. For objects, use a stable reference (e.g. useMemo) to avoid restarting every render.
16
+ * @param {boolean} [options.enabled=true] - When false, polling does not start. Use to gate on e.g. having an id.
17
+ * @param {function(any): boolean} [options.isSuccess] - Predicate to treat response as success. Default: truthy check.
18
+ * @param {number} [options.pollingInterval=5000] - Ms between polls.
19
+ * @param {number} [options.maxAttempts=360] - Max poll attempts (~30 min at 5s).
20
+ * @param {number} [options.delayBeforeStart=2000] - Ms before first poll.
21
+ * @param {function(any)} [options.onSuccess] - Called with response when isSuccess(response) is true.
22
+ * @param {function(Error)} [options.onError] - Called on fetcher error.
23
+ * @param {function()} [options.onMaxAttemptsReached] - Called when attempts reach maxAttempts.
24
+ * @returns {{ isLoading: boolean, error: Error|null, attempts: number, isPolling: boolean, maxAttempts: number }}
25
+ */
26
+ const useTransactionPolling = function () {
27
+ let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
28
+ const {
29
+ fetcher,
30
+ payload,
31
+ enabled = true,
32
+ isSuccess = response => Boolean(response),
33
+ pollingInterval = 5000,
34
+ maxAttempts = 360,
35
+ delayBeforeStart = 2000,
36
+ onSuccess,
37
+ onError,
38
+ onMaxAttemptsReached
39
+ } = options;
40
+ if (typeof fetcher !== 'function') {
41
+ throw new Error('useTransactionPolling: options.fetcher is required and must be a function');
42
+ }
43
+ const [isLoading, setIsLoading] = (0, _react.useState)(false);
44
+ const [error, setError] = (0, _react.useState)(null);
45
+ const [attempts, setAttempts] = (0, _react.useState)(0);
46
+ const [isPolling, setIsPolling] = (0, _react.useState)(false);
47
+ const intervalRef = (0, _react.useRef)(null);
48
+ const timeoutRef = (0, _react.useRef)(null);
49
+ const completedRef = (0, _react.useRef)(false);
50
+ const pollRef = (0, _react.useRef)(null);
51
+ const poll = (0, _react.useCallback)(async () => {
52
+ if (!enabled || attempts >= maxAttempts || completedRef.current) {
53
+ return;
54
+ }
55
+ setIsLoading(true);
56
+ setError(null);
57
+ try {
58
+ const response = await fetcher(payload);
59
+ if (isSuccess(response)) {
60
+ completedRef.current = true;
61
+ setIsPolling(false);
62
+ setIsLoading(false);
63
+ onSuccess === null || onSuccess === void 0 || onSuccess(response);
64
+ return;
65
+ }
66
+ } catch (err) {
67
+ console.error('Transaction polling error:', err);
68
+ setError(err);
69
+ onError === null || onError === void 0 || onError(err);
70
+ } finally {
71
+ setIsLoading(false);
72
+ setAttempts(prev => prev + 1);
73
+ }
74
+ }, [enabled, attempts, maxAttempts, fetcher, payload, isSuccess, onSuccess, onError]);
75
+ pollRef.current = poll;
76
+ (0, _react.useEffect)(() => {
77
+ if (!enabled) return;
78
+ setIsPolling(true);
79
+ setAttempts(0);
80
+ completedRef.current = false;
81
+ setError(null);
82
+ const runPoll = () => {
83
+ var _pollRef$current;
84
+ return (_pollRef$current = pollRef.current) === null || _pollRef$current === void 0 ? void 0 : _pollRef$current.call(pollRef);
85
+ };
86
+ timeoutRef.current = setTimeout(() => {
87
+ intervalRef.current = setInterval(runPoll, pollingInterval);
88
+ runPoll();
89
+ }, delayBeforeStart);
90
+ return () => {
91
+ if (intervalRef.current) {
92
+ clearInterval(intervalRef.current);
93
+ }
94
+ if (timeoutRef.current) {
95
+ clearTimeout(timeoutRef.current);
96
+ }
97
+ setIsPolling(false);
98
+ };
99
+ }, [enabled, payload, pollingInterval, delayBeforeStart, maxAttempts]);
100
+ (0, _react.useEffect)(() => {
101
+ if (attempts >= maxAttempts && isPolling) {
102
+ if (intervalRef.current) {
103
+ clearInterval(intervalRef.current);
104
+ }
105
+ setIsPolling(false);
106
+ onMaxAttemptsReached === null || onMaxAttemptsReached === void 0 || onMaxAttemptsReached();
107
+ }
108
+ }, [attempts, maxAttempts, isPolling, onMaxAttemptsReached]);
109
+ return {
110
+ isLoading,
111
+ error,
112
+ attempts,
113
+ isPolling,
114
+ maxAttempts
115
+ };
116
+ };
117
+ exports.useTransactionPolling = useTransactionPolling;
118
+ var _default = exports.default = useTransactionPolling;
package/dist/index.js CHANGED
@@ -1466,6 +1466,17 @@ Object.keys(_useTimer).forEach(function (key) {
1466
1466
  }
1467
1467
  });
1468
1468
  });
1469
+ var _useTransactionPolling = require("./hooks/useTransactionPolling");
1470
+ Object.keys(_useTransactionPolling).forEach(function (key) {
1471
+ if (key === "default" || key === "__esModule") return;
1472
+ if (key in exports && exports[key] === _useTransactionPolling[key]) return;
1473
+ Object.defineProperty(exports, key, {
1474
+ enumerable: true,
1475
+ get: function () {
1476
+ return _useTransactionPolling[key];
1477
+ }
1478
+ });
1479
+ });
1469
1480
  var _PaymentDisplay = require("./components/Payment/PaymentDisplay");
1470
1481
  Object.keys(_PaymentDisplay).forEach(function (key) {
1471
1482
  if (key === "default" || key === "__esModule") return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stokr/components-library",
3
- "version": "2.3.73",
3
+ "version": "2.3.75",
4
4
  "description": "STOKR - Components Library",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",