This repository has been archived by the owner on Jan 5, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcountdown.templ
103 lines (93 loc) · 2.3 KB
/
countdown.templ
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package franken
import "time"
import "fmt"
type CountdownData struct {
Time time.Time
TextSize TailwindTextSize
Separator string
Class []string
}
func formatTime(time time.Time) string {
formattedTime := time.Format("2006-01-02T15:04:05-07:00")
return formattedTime
}
templ Countdown(data CountdownData) {
<div uk-countdown={ fmt.Sprint("date: " + formatTime(data.Time)) }>
<span
class={ templ.Classes(map[string]bool {
"uk-countdown-days": true,
"uk-countdown-number": true,
fmt.Sprint(data.TextSize): data.TextSize.Isset(),
}) }
></span>
if data.Separator != "" {
<span
class={ templ.Classes(map[string]bool {
"uk-countdown-separator": true,
fmt.Sprint(data.TextSize): data.TextSize.Isset(),
}) }
>{ data.Separator }</span>
}
<span
class={ templ.Classes(map[string]bool {
"uk-countdown-hours": true,
"uk-countdown-number": true,
fmt.Sprint(data.TextSize): data.TextSize.Isset(),
}) }
></span>
if data.Separator != "" {
<span
class={ templ.Classes(map[string]bool {
"uk-countdown-separator": true,
fmt.Sprint(data.TextSize): data.TextSize.Isset(),
}) }
>{ data.Separator }</span>
}
<span
class={ templ.Classes(map[string]bool {
"uk-countdown-minutes": true,
"uk-countdown-number": true,
fmt.Sprint(data.TextSize): data.TextSize.Isset(),
}) }
></span>
if data.Separator != "" {
<span
class={ templ.Classes(map[string]bool {
"uk-countdown-separator": true,
fmt.Sprint(data.TextSize): data.TextSize.Isset(),
}) }
>{ data.Separator }</span>
}
<span
class={ templ.Classes(map[string]bool {
"uk-countdown-seconds": true,
"uk-countdown-number": true,
fmt.Sprint(data.TextSize): data.TextSize.Isset(),
}) }
></span>
</div>
}
func CountdownBuilder() *CountdownData {
return &CountdownData{
Time: time.Now(),
}
}
func (c *CountdownData) SetTime(time time.Time) *CountdownData {
c.Time = time
return c
}
func (c *CountdownData) SetSeparator(separator string) *CountdownData {
c.Separator = separator
return c
}
func (c *CountdownData) SetTextSize(size TailwindTextSize) *CountdownData {
c.TextSize = size
return c
}
func (c *CountdownData) SetClass(class ...string) *CountdownData {
c.Class = class
return c
}
templ (c CountdownData) Finish() {
@Countdown(c)
}