@phillips/seldon 1.255.0 → 1.256.0
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/components/Countdown/Countdown.cjs +1 -1
- package/dist/components/Countdown/Countdown.d.ts +4 -0
- package/dist/components/Countdown/Countdown.js +37 -35
- package/dist/components/Countdown/Countdown.stories.d.ts +3 -0
- package/dist/scss/components/Countdown/_countdown.scss +17 -8
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const o=require("react/jsx-runtime"),f=require("react"),
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const o=require("react/jsx-runtime"),f=require("react"),z=require("../../utils/index.cjs"),H=require("../../_virtual/index.cjs"),P=require("../../types/commonTypes.cjs"),i=require("./types.cjs"),m=require("./Duration.cjs"),x=require("../Text/types.cjs"),R=require("../Text/Text.cjs"),U=require("../../node_modules/date-fns/locale/zh-CN.cjs"),E=require("../../node_modules/date-fns/locale/en-US.cjs"),I=require("../../node_modules/date-fns/differenceInSeconds.cjs"),y=require("../../node_modules/date-fns/differenceInMinutes.cjs"),p=require("../../node_modules/date-fns/differenceInHours.cjs"),C=require("../../node_modules/date-fns/differenceInDays.cjs"),F=require("../../node_modules/date-fns/differenceInMilliseconds.cjs"),j=f.forwardRef(({endDateTime:e,formatDurationStr:a,label:h="Lots Close in",intervalDescription:g,className:M,locale:$="en",showBottomBorder:N=!0,variant:l=i.CountdownVariants.default,getCurrentDateTime:c=()=>new Date,centerAlign:V=!1,...q},b)=>{const{className:r,...S}=z.getCommonProps(q,"Countdown"),[s,_]=f.useState(c()||new Date),d=$===P.SupportedLanguages.zh?U.zhCN:E.enUS,n={days:C.differenceInDays(e,s)>0?C.differenceInDays(e,s):0,hours:p.differenceInHours(e,s)>0?p.differenceInHours(e,s)%24:0,minutes:y.differenceInMinutes(e,s)>0?y.differenceInMinutes(e,s)%60:0,seconds:(I.differenceInSeconds(e,s)>0?I.differenceInSeconds(e,s)%60:0)%60};f.useEffect(()=>{const t=setInterval(()=>{_(c()||new Date)},1e3);return()=>clearInterval(t)},[e,c]);const v=f.useMemo(()=>{const t=c();return!!t&&new Date(e).getTime()>t.getTime()},[e,c]),L=F.differenceInMilliseconds(e,s)<=180*1e3,u=l===i.CountdownVariants.sm?x.TextVariants.labelSmall:x.TextVariants.labelMedium,w=[n.days>0?o.jsx(m.Duration,{duration:n,unit:"days",locale:d,formatDurationStr:a,textVariant:u},"days"):null,n.days>0||n.hours>0?o.jsx(m.Duration,{duration:n,unit:"hours",locale:d,formatDurationStr:a,textVariant:u},"hours"):null,n.days===0?o.jsx(m.Duration,{duration:n,unit:"minutes",locale:d,formatDurationStr:a,textVariant:u},"minutes"):null,n.days===0&&n.hours===0?o.jsx(m.Duration,{duration:n,unit:"seconds",locale:d,formatDurationStr:a,textVariant:u},"seconds"):null].filter(t=>t!=null);return v?o.jsxs("div",{"data-chromatic":"ignore",...S,className:H.default(r,M,{[`${r}--compact`]:l===i.CountdownVariants.compact,[`${r}--sm`]:l===i.CountdownVariants.sm,[`${r}--show-bottom-border`]:N,[`${r}--closing-lot`]:L,[`${r}--center-align`]:V}),...q,ref:b,children:[o.jsxs("div",{className:`${r}__countdown-container`,role:"timer","aria-label":h,children:[o.jsx(R.default,{variant:u,children:h}),w.length>0?o.jsx("div",{className:`${r}__duration-group`,children:w}):null]}),l===i.CountdownVariants.default?o.jsx("span",{children:g}):null]}):null});j.displayName="Countdown";exports.default=j;
|
|
@@ -34,6 +34,10 @@ export interface CountdownProps extends ComponentProps<'div'> {
|
|
|
34
34
|
* Function to get the current date time
|
|
35
35
|
*/
|
|
36
36
|
getCurrentDateTime?: () => Date | null;
|
|
37
|
+
/**
|
|
38
|
+
* Centers label and durationwithin the countdown row
|
|
39
|
+
*/
|
|
40
|
+
centerAlign?: boolean;
|
|
37
41
|
}
|
|
38
42
|
/**
|
|
39
43
|
* ## Overview
|
|
@@ -1,55 +1,56 @@
|
|
|
1
1
|
import { jsx as t, jsxs as w } from "react/jsx-runtime";
|
|
2
|
-
import { forwardRef as
|
|
3
|
-
import { getCommonProps as
|
|
4
|
-
import
|
|
5
|
-
import { SupportedLanguages as
|
|
6
|
-
import { CountdownVariants as
|
|
2
|
+
import { forwardRef as P, useState as S, useEffect as E, useMemo as F } from "react";
|
|
3
|
+
import { getCommonProps as G } from "../../utils/index.js";
|
|
4
|
+
import H from "../../_virtual/index.js";
|
|
5
|
+
import { SupportedLanguages as R } from "../../types/commonTypes.js";
|
|
6
|
+
import { CountdownVariants as a } from "./types.js";
|
|
7
7
|
import { Duration as d } from "./Duration.js";
|
|
8
8
|
import { TextVariants as y } from "../Text/types.js";
|
|
9
|
-
import
|
|
10
|
-
import { zhCN as
|
|
11
|
-
import { enUS as
|
|
9
|
+
import U from "../Text/Text.js";
|
|
10
|
+
import { zhCN as k } from "../../node_modules/date-fns/locale/zh-CN.js";
|
|
11
|
+
import { enUS as q } from "../../node_modules/date-fns/locale/en-US.js";
|
|
12
12
|
import { differenceInSeconds as g } from "../../node_modules/date-fns/differenceInSeconds.js";
|
|
13
13
|
import { differenceInMinutes as C } from "../../node_modules/date-fns/differenceInMinutes.js";
|
|
14
14
|
import { differenceInHours as I } from "../../node_modules/date-fns/differenceInHours.js";
|
|
15
15
|
import { differenceInDays as N } from "../../node_modules/date-fns/differenceInDays.js";
|
|
16
|
-
import { differenceInMilliseconds as
|
|
17
|
-
const
|
|
16
|
+
import { differenceInMilliseconds as A } from "../../node_modules/date-fns/differenceInMilliseconds.js";
|
|
17
|
+
const B = P(
|
|
18
18
|
({
|
|
19
19
|
endDateTime: o,
|
|
20
|
-
formatDurationStr:
|
|
20
|
+
formatDurationStr: i,
|
|
21
21
|
label: f = "Lots Close in",
|
|
22
|
-
intervalDescription:
|
|
23
|
-
className:
|
|
22
|
+
intervalDescription: $,
|
|
23
|
+
className: x,
|
|
24
24
|
locale: b = "en",
|
|
25
25
|
showBottomBorder: L = !0,
|
|
26
|
-
variant: m =
|
|
26
|
+
variant: m = a.default,
|
|
27
27
|
getCurrentDateTime: l = () => /* @__PURE__ */ new Date(),
|
|
28
|
+
centerAlign: M = !1,
|
|
28
29
|
...p
|
|
29
|
-
},
|
|
30
|
-
const { className: r, ...
|
|
30
|
+
}, _) => {
|
|
31
|
+
const { className: r, ...v } = G(p, "Countdown"), [n, V] = S(l() || /* @__PURE__ */ new Date()), u = b === R.zh ? k : q, s = {
|
|
31
32
|
days: N(o, n) > 0 ? N(o, n) : 0,
|
|
32
33
|
hours: I(o, n) > 0 ? I(o, n) % 24 : 0,
|
|
33
34
|
minutes: C(o, n) > 0 ? C(o, n) % 60 : 0,
|
|
34
35
|
seconds: (g(o, n) > 0 ? g(o, n) % 60 : 0) % 60
|
|
35
36
|
};
|
|
36
|
-
|
|
37
|
+
E(() => {
|
|
37
38
|
const e = setInterval(() => {
|
|
38
|
-
|
|
39
|
+
V(l() || /* @__PURE__ */ new Date());
|
|
39
40
|
}, 1e3);
|
|
40
41
|
return () => clearInterval(e);
|
|
41
42
|
}, [o, l]);
|
|
42
|
-
const
|
|
43
|
+
const j = F(() => {
|
|
43
44
|
const e = l();
|
|
44
45
|
return !!e && new Date(o).getTime() > e.getTime();
|
|
45
|
-
}, [o, l]),
|
|
46
|
+
}, [o, l]), z = A(o, n) <= 180 * 1e3, c = m === a.sm ? y.labelSmall : y.labelMedium, h = [
|
|
46
47
|
s.days > 0 ? /* @__PURE__ */ t(
|
|
47
48
|
d,
|
|
48
49
|
{
|
|
49
50
|
duration: s,
|
|
50
51
|
unit: "days",
|
|
51
52
|
locale: u,
|
|
52
|
-
formatDurationStr:
|
|
53
|
+
formatDurationStr: i,
|
|
53
54
|
textVariant: c
|
|
54
55
|
},
|
|
55
56
|
"days"
|
|
@@ -60,7 +61,7 @@ const A = z(
|
|
|
60
61
|
duration: s,
|
|
61
62
|
unit: "hours",
|
|
62
63
|
locale: u,
|
|
63
|
-
formatDurationStr:
|
|
64
|
+
formatDurationStr: i,
|
|
64
65
|
textVariant: c
|
|
65
66
|
},
|
|
66
67
|
"hours"
|
|
@@ -71,7 +72,7 @@ const A = z(
|
|
|
71
72
|
duration: s,
|
|
72
73
|
unit: "minutes",
|
|
73
74
|
locale: u,
|
|
74
|
-
formatDurationStr:
|
|
75
|
+
formatDurationStr: i,
|
|
75
76
|
textVariant: c
|
|
76
77
|
},
|
|
77
78
|
"minutes"
|
|
@@ -82,37 +83,38 @@ const A = z(
|
|
|
82
83
|
duration: s,
|
|
83
84
|
unit: "seconds",
|
|
84
85
|
locale: u,
|
|
85
|
-
formatDurationStr:
|
|
86
|
+
formatDurationStr: i,
|
|
86
87
|
textVariant: c
|
|
87
88
|
},
|
|
88
89
|
"seconds"
|
|
89
90
|
) : null
|
|
90
91
|
].filter((e) => e != null);
|
|
91
|
-
return
|
|
92
|
+
return j ? /* @__PURE__ */ w(
|
|
92
93
|
"div",
|
|
93
94
|
{
|
|
94
95
|
"data-chromatic": "ignore",
|
|
95
|
-
...
|
|
96
|
-
className:
|
|
97
|
-
[`${r}--compact`]: m ===
|
|
98
|
-
[`${r}--sm`]: m ===
|
|
96
|
+
...v,
|
|
97
|
+
className: H(r, x, {
|
|
98
|
+
[`${r}--compact`]: m === a.compact,
|
|
99
|
+
[`${r}--sm`]: m === a.sm,
|
|
99
100
|
[`${r}--show-bottom-border`]: L,
|
|
100
|
-
[`${r}--closing-lot`]:
|
|
101
|
+
[`${r}--closing-lot`]: z,
|
|
102
|
+
[`${r}--center-align`]: M
|
|
101
103
|
}),
|
|
102
104
|
...p,
|
|
103
|
-
ref:
|
|
105
|
+
ref: _,
|
|
104
106
|
children: [
|
|
105
107
|
/* @__PURE__ */ w("div", { className: `${r}__countdown-container`, role: "timer", "aria-label": f, children: [
|
|
106
|
-
/* @__PURE__ */ t(
|
|
108
|
+
/* @__PURE__ */ t(U, { variant: c, children: f }),
|
|
107
109
|
h.length > 0 ? /* @__PURE__ */ t("div", { className: `${r}__duration-group`, children: h }) : null
|
|
108
110
|
] }),
|
|
109
|
-
m ===
|
|
111
|
+
m === a.default ? /* @__PURE__ */ t("span", { children: $ }) : null
|
|
110
112
|
]
|
|
111
113
|
}
|
|
112
114
|
) : null;
|
|
113
115
|
}
|
|
114
116
|
);
|
|
115
|
-
|
|
117
|
+
B.displayName = "Countdown";
|
|
116
118
|
export {
|
|
117
|
-
|
|
119
|
+
B as default
|
|
118
120
|
};
|
|
@@ -25,28 +25,37 @@
|
|
|
25
25
|
|
|
26
26
|
&__countdown-container {
|
|
27
27
|
align-items: flex-start;
|
|
28
|
-
|
|
28
|
+
gap: $spacing-micro $spacing-sm;
|
|
29
29
|
display: flex;
|
|
30
|
-
flex-
|
|
31
|
-
flex-wrap: wrap;
|
|
30
|
+
flex-flow: row wrap;
|
|
32
31
|
justify-content: flex-start;
|
|
33
|
-
row-gap: $spacing-micro;
|
|
34
32
|
text-transform: inherit;
|
|
35
33
|
width: 100%;
|
|
36
34
|
|
|
37
35
|
> .#{$px}-text {
|
|
38
36
|
flex-shrink: 0;
|
|
37
|
+
font-variation-settings: 'wght' 600;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
&--center-align {
|
|
42
|
+
.#{$px}-countdown__countdown-container {
|
|
43
|
+
align-items: center;
|
|
44
|
+
justify-content: center;
|
|
45
|
+
text-align: center;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.#{$px}-countdown__duration-group {
|
|
49
|
+
justify-content: center;
|
|
39
50
|
}
|
|
40
51
|
}
|
|
41
52
|
|
|
42
53
|
&__duration-group {
|
|
43
54
|
align-items: center;
|
|
44
|
-
|
|
55
|
+
gap: 0 $spacing-sm;
|
|
45
56
|
display: flex;
|
|
46
|
-
flex-
|
|
47
|
-
flex-wrap: wrap;
|
|
57
|
+
flex-flow: row wrap;
|
|
48
58
|
justify-content: flex-start;
|
|
49
|
-
row-gap: 0;
|
|
50
59
|
}
|
|
51
60
|
|
|
52
61
|
&--compact {
|