@purpurds/countdown 8.8.0 → 8.9.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/LICENSE.txt +2 -2
- package/dist/countdown.cjs.js +1 -9
- package/dist/countdown.cjs.js.map +1 -1
- package/dist/countdown.d.ts.map +1 -1
- package/dist/countdown.es.js +208 -202
- package/dist/countdown.es.js.map +1 -1
- package/dist/countdown.types.d.ts +6 -0
- package/dist/countdown.types.d.ts.map +1 -1
- package/dist/counter.d.ts.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +21 -21
- package/src/countdown.module.scss +45 -6
- package/src/countdown.stories.tsx +7 -4
- package/src/countdown.test.tsx +148 -1
- package/src/countdown.tsx +8 -5
- package/src/countdown.types.ts +6 -5
- package/src/counter.module.scss +39 -10
- package/src/counter.tsx +21 -4
package/src/counter.module.scss
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
@use "@purpurds/tokens/breakpoint/variables" as *;
|
|
1
2
|
@use "@purpurds/heading/src/heading.mixins.scss" as heading;
|
|
2
3
|
@use "@purpurds/paragraph/src/paragraph.mixins.scss" as paragraph;
|
|
3
4
|
|
|
5
|
+
$countdown-container-queries-selector: "[class*=" purpur-countdown--use-container-queries "]";
|
|
6
|
+
$countdown-media-queries-selector: "[class*=" purpur-countdown--use-media-queries "]";
|
|
7
|
+
|
|
4
8
|
$root: ".purpur-countdown-counter";
|
|
5
9
|
|
|
6
10
|
@mixin size {
|
|
@@ -13,24 +17,20 @@ $root: ".purpur-countdown-counter";
|
|
|
13
17
|
}
|
|
14
18
|
|
|
15
19
|
#{$root} {
|
|
16
|
-
@include size();
|
|
17
|
-
|
|
18
20
|
display: grid;
|
|
19
21
|
justify-items: center;
|
|
20
22
|
align-items: center;
|
|
21
|
-
|
|
22
23
|
padding: var(--purpur-spacing-100);
|
|
23
24
|
border-radius: var(--purpur-border-radius-md);
|
|
24
25
|
background-color: var(--bg-color);
|
|
25
26
|
color: var(--text-color);
|
|
26
|
-
|
|
27
27
|
overflow: hidden;
|
|
28
28
|
|
|
29
|
-
&
|
|
30
|
-
|
|
29
|
+
&__number {
|
|
30
|
+
@include size();
|
|
31
31
|
|
|
32
|
+
position: relative;
|
|
32
33
|
width: 100%;
|
|
33
|
-
|
|
34
34
|
color: inherit;
|
|
35
35
|
text-align: center;
|
|
36
36
|
|
|
@@ -45,18 +45,47 @@ $root: ".purpur-countdown-counter";
|
|
|
45
45
|
position: absolute;
|
|
46
46
|
bottom: 100%;
|
|
47
47
|
inset-inline: 0;
|
|
48
|
-
|
|
49
48
|
color: inherit;
|
|
50
|
-
|
|
51
49
|
animation: tick-animation-pseudo 0.25s forwards;
|
|
52
50
|
}
|
|
53
51
|
}
|
|
54
52
|
}
|
|
55
53
|
}
|
|
56
|
-
|
|
54
|
+
|
|
55
|
+
&__label {
|
|
57
56
|
@include paragraph.purpur-additional-100();
|
|
58
57
|
|
|
59
58
|
color: inherit;
|
|
59
|
+
|
|
60
|
+
&--abbr abbr {
|
|
61
|
+
text-decoration: none;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
&--full {
|
|
65
|
+
display: none;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
@at-root #{$countdown-container-queries-selector} & {
|
|
69
|
+
@container countdown (min-width: #{$purpur-breakpoint-md}) {
|
|
70
|
+
&--abbr {
|
|
71
|
+
display: none;
|
|
72
|
+
}
|
|
73
|
+
&--full {
|
|
74
|
+
display: block;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
@at-root #{$countdown-media-queries-selector} & {
|
|
80
|
+
@media (min-width: $purpur-breakpoint-md) {
|
|
81
|
+
&--abbr {
|
|
82
|
+
display: none;
|
|
83
|
+
}
|
|
84
|
+
&--full {
|
|
85
|
+
display: block;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
60
89
|
}
|
|
61
90
|
}
|
|
62
91
|
|
package/src/counter.tsx
CHANGED
|
@@ -23,8 +23,8 @@ export const Counter = ({ tag, size, end, counterLabels }: CounterProps) => {
|
|
|
23
23
|
const ref = useRef<HTMLHeadingElement>(null);
|
|
24
24
|
const id = `${tag}-interval`;
|
|
25
25
|
|
|
26
|
-
const [currentTime, setCurrentTime] = useState(
|
|
27
|
-
const [nextTime, setNextTime] = useState(
|
|
26
|
+
const [currentTime, setCurrentTime] = useState(0);
|
|
27
|
+
const [nextTime, setNextTime] = useState(0);
|
|
28
28
|
const [animationKey, setAnimationKey] = useState(0);
|
|
29
29
|
|
|
30
30
|
const checktime = useCallback(() => {
|
|
@@ -35,6 +35,11 @@ export const Counter = ({ tag, size, end, counterLabels }: CounterProps) => {
|
|
|
35
35
|
setCurrentTime(diffs[tag]);
|
|
36
36
|
}, [end, tag]);
|
|
37
37
|
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
checktime();
|
|
40
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
41
|
+
}, []);
|
|
42
|
+
|
|
38
43
|
useEffect(() => {
|
|
39
44
|
intervals.set(id, setInterval(checktime, inMs.second));
|
|
40
45
|
return () => clearInterval(intervals.get(id)!);
|
|
@@ -45,6 +50,7 @@ export const Counter = ({ tag, size, end, counterLabels }: CounterProps) => {
|
|
|
45
50
|
}, [currentTime]);
|
|
46
51
|
|
|
47
52
|
const counterTag = counterLabels[tag];
|
|
53
|
+
const counterTagAbbr = counterLabels[`${tag}Abbr`];
|
|
48
54
|
|
|
49
55
|
return (
|
|
50
56
|
<div
|
|
@@ -54,14 +60,25 @@ export const Counter = ({ tag, size, end, counterLabels }: CounterProps) => {
|
|
|
54
60
|
data-testid={`counter-${tag}`}
|
|
55
61
|
>
|
|
56
62
|
<Paragraph
|
|
57
|
-
className={cx(`${rootClassName}__number`, `${rootClassName}--size-${size}`)}
|
|
63
|
+
className={cx(`${rootClassName}__number`, `${rootClassName}__number--size-${size}`)}
|
|
58
64
|
ref={ref}
|
|
59
65
|
data-tick={nextTime}
|
|
60
66
|
key={animationKey}
|
|
61
67
|
>
|
|
62
68
|
{currentTime}
|
|
63
69
|
</Paragraph>
|
|
64
|
-
|
|
70
|
+
{counterTagAbbr && (
|
|
71
|
+
<Paragraph className={cx(`${rootClassName}__label`, `${rootClassName}__label--abbr`)}>
|
|
72
|
+
<abbr title={counterTag}>{counterTagAbbr}</abbr>
|
|
73
|
+
</Paragraph>
|
|
74
|
+
)}
|
|
75
|
+
<Paragraph
|
|
76
|
+
className={cx(`${rootClassName}__label`, {
|
|
77
|
+
[`${rootClassName}__label--full`]: !!counterTagAbbr,
|
|
78
|
+
})}
|
|
79
|
+
>
|
|
80
|
+
{counterTag}
|
|
81
|
+
</Paragraph>
|
|
65
82
|
</div>
|
|
66
83
|
);
|
|
67
84
|
};
|