Skip to content

Commit 6b63563

Browse files
committed
feat: countdown now supports 0 to 999 with dynamic width
1 parent 766aeeb commit 6b63563

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

packages/daisyui/src/components/countdown.css

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,43 @@
55
}
66

77
& > * {
8-
@apply invisible relative inline-block overflow-y-hidden tabular-nums;
8+
@apply invisible relative inline-block overflow-y-hidden;
9+
transition: width 0.4s ease-out 0.2s;
910
height: 1em;
10-
min-width: 2ch;
11-
--value-v: calc(mod(max(0, var(--value)), 100));
12-
--value-1: calc(round(to-zero, var(--value-v) / 10, 1));
11+
--value-v: calc(mod(max(0, var(--value)), 1000));
12+
--value-hundreds: calc(round(to-zero, var(--value-v) / 100, 1));
13+
--value-tens: calc(round(to-zero, mod(var(--value-v), 100) / 10, 1));
14+
--value-ones: calc(mod(var(--value-v), 10));
15+
--show-hundreds: clamp(0, var(--value-hundreds), 1);
16+
--show-tens: clamp(0, var(--value-tens) + var(--show-hundreds), 1);
17+
--first-digits: calc(round(to-zero, var(--value-v) / 10, 1));
18+
width: calc(1ch + var(--show-tens) * 1ch + var(--show-hundreds) * 1ch);
1319

1420
&:before,
1521
&:after {
1622
@apply visible absolute;
17-
content: "0\A 1\A 2\A 3\A 4\A 5\A 6\A 7\A 8\A 9\A 0\A 1\A 2\A 3\A 4\A 5\A 6\A 7\A 8\A 9\A 0\A 1\A 2\A 3\A 4\A 5\A 6\A 7\A 8\A 9\A 0\A 1\A 2\A 3\A 4\A 5\A 6\A 7\A 8\A 9\A 0\A 1\A 2\A 3\A 4\A 5\A 6\A 7\A 8\A 9\A 0\A 1\A 2\A 3\A 4\A 5\A 6\A 7\A 8\A 9\A 0\A 1\A 2\A 3\A 4\A 5\A 6\A 7\A 8\A 9\A 0\A 1\A 2\A 3\A 4\A 5\A 6\A 7\A 8\A 9\A 0\A 1\A 2\A 3\A 4\A 5\A 6\A 7\A 8\A 9\A 0\A 1\A 2\A 3\A 4\A 5\A 6\A 7\A 8\A 9\A";
23+
font-variant-numeric: tabular-nums;
1824
white-space: pre;
1925
text-align: center;
20-
transition: all 1s cubic-bezier(1, 0, 0, 1);
26+
transition:
27+
all 1s cubic-bezier(1, 0, 0, 1),
28+
width 0.2s ease-out 0.2s,
29+
opacity 0.2s ease-out 0.2s;
2130
}
2231

2332
&:before {
24-
top: calc(var(--value-1) * -1em);
33+
content: "0\A 1\A 2\A 3\A 4\A 5\A 6\A 7\A 8\A 9\A 10\A 11\A 12\A 13\A 14\A 15\A 16\A 17\A 18\A 19\A 20\A 21\A 22\A 23\A 24\A 25\A 26\A 27\A 28\A 29\A 30\A 31\A 32\A 33\A 34\A 35\A 36\A 37\A 38\A 39\A 40\A 41\A 42\A 43\A 44\A 45\A 46\A 47\A 48\A 49\A 50\A 51\A 52\A 53\A 54\A 55\A 56\A 57\A 58\A 59\A 60\A 61\A 62\A 63\A 64\A 65\A 66\A 67\A 68\A 69\A 70\A 71\A 72\A 73\A 74\A 75\A 76\A 77\A 78\A 79\A 80\A 81\A 82\A 83\A 84\A 85\A 86\A 87\A 88\A 89\A 90\A 91\A 92\A 93\A 94\A 95\A 96\A 97\A 98\A 99\A";
34+
width: calc(1ch + var(--show-hundreds) * 1ch);
35+
top: calc(var(--first-digits) * -1em);
2536
inset-inline-start: 0;
37+
text-align: end;
38+
opacity: var(--show-tens);
2639
}
2740

2841
&:after {
29-
top: calc(var(--value-v) * -1em);
42+
content: "0\A 1\A 2\A 3\A 4\A 5\A 6\A 7\A 8\A 9\A";
43+
width: 1ch;
44+
top: calc(var(--value-ones) * -1em);
3045
inset-inline-end: 0;
3146
}
3247
}

0 commit comments

Comments
 (0)