kupos-ui-components-lib 9.0.6 → 9.0.8

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.
@@ -9,6 +9,9 @@ interface TopAmenitiesProps {
9
9
  buttonColor?: string;
10
10
  boardingIcon?: React.ReactNode;
11
11
  getAnimationIcon: (icon: string) => any;
12
+ countdownSeconds?: number;
13
+ promoText?: string;
14
+ onCountdownEnd?: () => void;
12
15
  }
13
16
 
14
17
  function TopAmenities({
@@ -19,7 +22,36 @@ function TopAmenities({
19
22
  buttonColor,
20
23
  boardingIcon,
21
24
  getAnimationIcon,
25
+ countdownSeconds = 0,
26
+ onCountdownEnd,
22
27
  }: TopAmenitiesProps): React.ReactElement {
28
+ const pad = (n: number) => String(n).padStart(2, "0");
29
+
30
+ const startCountdown = (el: HTMLSpanElement | null) => {
31
+ if (!el || el.dataset.timerStarted) return;
32
+ el.dataset.timerStarted = "true";
33
+ let remaining = countdownSeconds;
34
+
35
+ const update = () => {
36
+ const hrs = Math.floor(remaining / 3600);
37
+ const mins = Math.floor((remaining % 3600) / 60);
38
+ const secs = remaining % 60;
39
+ el.textContent = `${pad(hrs)}:${pad(mins)}:${pad(secs)}`;
40
+ };
41
+
42
+ update();
43
+ const timer = setInterval(() => {
44
+ if (remaining <= 0) {
45
+ clearInterval(timer);
46
+ const promoBar = el.closest("[data-promo-bar]") as HTMLElement;
47
+ if (promoBar) promoBar.style.display = "none";
48
+ if (onCountdownEnd) onCountdownEnd();
49
+ return;
50
+ }
51
+ remaining--;
52
+ update();
53
+ }, 1000);
54
+ };
23
55
  return (
24
56
  <div
25
57
  style={{
@@ -31,6 +63,7 @@ function TopAmenities({
31
63
  >
32
64
  {/* {showPromo && ( */}
33
65
  <div
66
+ data-promo-bar
34
67
  style={{
35
68
  backgroundColor: priceColor,
36
69
  position: "relative",
@@ -43,8 +76,8 @@ function TopAmenities({
43
76
  <div style={{ display: "flex", alignItems: "center" }}>
44
77
  <LottiePlayer
45
78
  animationData={getAnimationIcon("bombAnimation")}
46
- width="14px"
47
- height="14px"
79
+ width="16px"
80
+ height="16px"
48
81
  />
49
82
  <span
50
83
  className="flex items-center py-[10px] pl-[6px] text-white text-[13.33px] z-20"
@@ -52,7 +85,8 @@ function TopAmenities({
52
85
  >
53
86
  <span className="bold-text">kuponazo 20%&nbsp;</span> | Termina
54
87
  en&nbsp;
55
- <span className="bold-text">02:10:30</span>
88
+ <span className="bold-text" ref={startCountdown} />
89
+ {/* <span className="bold-text">02:10:30</span> */}
56
90
  </span>
57
91
  </div>
58
92
  </div>