@sonic-equipment/ui 0.0.106 → 0.0.108

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/dist/index.js CHANGED
@@ -2126,7 +2126,7 @@ function nextTick(callback, delay) {
2126
2126
  }
2127
2127
  return setTimeout(callback, delay);
2128
2128
  }
2129
- function now() {
2129
+ function now$1() {
2130
2130
  return Date.now();
2131
2131
  }
2132
2132
  function getComputedStyle$1(el) {
@@ -2829,7 +2829,7 @@ function freeMode(_ref) {
2829
2829
  }
2830
2830
  data.velocities.push({
2831
2831
  position: touches[swiper.isHorizontal() ? 'currentX' : 'currentY'],
2832
- time: now()
2832
+ time: now$1()
2833
2833
  });
2834
2834
  }
2835
2835
  function onTouchEnd(_ref2) {
@@ -2845,7 +2845,7 @@ function freeMode(_ref) {
2845
2845
  touchEventsData: data
2846
2846
  } = swiper;
2847
2847
  // Time diff
2848
- const touchEndTime = now();
2848
+ const touchEndTime = now$1();
2849
2849
  const timeDiff = touchEndTime - data.touchStartTime;
2850
2850
  if (currentPos < -swiper.minTranslate()) {
2851
2851
  swiper.slideTo(swiper.activeIndex);
@@ -2872,7 +2872,7 @@ function freeMode(_ref) {
2872
2872
  }
2873
2873
  // this implies that the user stopped moving a finger then released.
2874
2874
  // There would be no events with distance zero, so the last event is stale.
2875
- if (time > 150 || now() - lastMoveEvent.time > 300) {
2875
+ if (time > 150 || now$1() - lastMoveEvent.time > 300) {
2876
2876
  swiper.velocity = 0;
2877
2877
  }
2878
2878
  } else {
@@ -5254,7 +5254,7 @@ function onTouchStart(event) {
5254
5254
  });
5255
5255
  touches.startX = startX;
5256
5256
  touches.startY = startY;
5257
- data.touchStartTime = now();
5257
+ data.touchStartTime = now$1();
5258
5258
  swiper.allowClick = true;
5259
5259
  swiper.updateSize();
5260
5260
  swiper.swipeDirection = undefined;
@@ -5329,7 +5329,7 @@ function onTouchMove(event) {
5329
5329
  currentX: pageX,
5330
5330
  currentY: pageY
5331
5331
  });
5332
- data.touchStartTime = now();
5332
+ data.touchStartTime = now$1();
5333
5333
  }
5334
5334
  return;
5335
5335
  }
@@ -5590,7 +5590,7 @@ function onTouchEnd(event) {
5590
5590
  }
5591
5591
 
5592
5592
  // Time diff
5593
- const touchEndTime = now();
5593
+ const touchEndTime = now$1();
5594
5594
  const timeDiff = touchEndTime - data.touchStartTime;
5595
5595
 
5596
5596
  // Tap, doubleTap, Click
@@ -5602,7 +5602,7 @@ function onTouchEnd(event) {
5602
5602
  swiper.emit('doubleTap doubleClick', e);
5603
5603
  }
5604
5604
  }
5605
- data.lastClickTime = now();
5605
+ data.lastClickTime = now$1();
5606
5606
  nextTick(() => {
5607
5607
  if (!swiper.destroyed) swiper.allowClick = true;
5608
5608
  });
@@ -8319,16 +8319,22 @@ function Announcement({ announcement: { href, id, text, title, type }, onDismiss
8319
8319
  return (jsxs(RouteLink, { className: clsx(styles$C.announcement, styles$C[type]), href: href, children: [jsxs("div", { className: styles$C.wrapper, children: [jsx("div", { className: styles$C.icon, children: iconMap[type] }), jsxs("div", { className: styles$C.content, children: [jsx("h2", { className: styles$C.title, children: title }), jsxs("p", { className: styles$C.text, children: [text, jsx(GlyphsArrowSemiBoldRightIcon, {})] })] })] }), jsx("div", { className: styles$C.close, children: jsx(IconButton, { color: "current-color", onClick: () => onDismiss?.(id), children: jsx(StrokeCloseboxIcon, {}) }) })] }));
8320
8320
  }
8321
8321
 
8322
+ const now = () => new Date();
8322
8323
  function ConnectedAnnouncement({ announcement: { endDate, startDate, ...announcement }, onDismiss, }) {
8324
+ const [isVisible, setIsVisible] = useState((!startDate || startDate <= now()) && (!endDate || endDate > now()));
8325
+ const getIsVisible = useCallback(() => isVisible, [isVisible]);
8323
8326
  useEffect(() => {
8324
- const interval = setInterval(() => {
8325
- if (endDate && endDate < new Date()) {
8326
- onDismiss?.(announcement.id);
8327
- }
8327
+ if (endDate && now() >= endDate)
8328
+ return;
8329
+ const intervalId = setInterval(() => {
8330
+ const isStillVisible = (!startDate || startDate <= now()) && (!endDate || endDate > now());
8331
+ if (getIsVisible() && !isStillVisible)
8332
+ clearInterval(intervalId);
8333
+ setIsVisible(isStillVisible);
8328
8334
  }, 1 * TIME.MINUTE);
8329
- return () => clearInterval(interval);
8330
- }, [endDate, onDismiss, announcement.id]);
8331
- if (startDate && startDate > new Date())
8335
+ return () => clearInterval(intervalId);
8336
+ }, [endDate, getIsVisible, startDate]);
8337
+ if (!isVisible)
8332
8338
  return null;
8333
8339
  return jsx(Announcement, { announcement: announcement, onDismiss: onDismiss });
8334
8340
  }
@@ -1,4 +1,5 @@
1
1
  import { AnnouncementProps } from './announcement';
2
2
  type ConnectedAnnouncementProps = AnnouncementProps;
3
+ export declare const now: () => Date;
3
4
  export declare function ConnectedAnnouncement({ announcement: { endDate, startDate, ...announcement }, onDismiss, }: ConnectedAnnouncementProps): import("react/jsx-runtime").JSX.Element | null;
4
5
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sonic-equipment/ui",
3
- "version": "0.0.106",
3
+ "version": "0.0.108",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "engines": {