Skip to content

Commit 5dda8be

Browse files
committed
add: clock movement track
1 parent 6fd0c89 commit 5dda8be

4 files changed

Lines changed: 162 additions & 23 deletions

File tree

public/icons/moon.svg

Lines changed: 41 additions & 4 deletions
Loading

public/icons/sun.svg

Lines changed: 73 additions & 12 deletions
Loading

src/lib/components/Clock.svelte

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
<script lang="ts">
22
import { onDestroy, onMount } from "svelte";
33
import ThemeToggle from "./ThemeToggle.svelte";
4+
import { theme } from "../state/theme.svelte";
5+
6+
let textColour = $derived(
7+
theme.isDark
8+
? "oklch(0.9644 0.0282 74.31)"
9+
: "oklch(0.2316 0.0373 288.04)",
10+
);
411
512
let marker: HTMLDivElement;
613
@@ -44,7 +51,7 @@
4451
}
4552
4653
function updateMarker() {
47-
marker.style.transform = `rotate(${angle}deg)`;
54+
marker.style.transform = `translateX(-32px) rotate(${angle}deg)`;
4855
}
4956
5057
onMount(() => {
@@ -70,16 +77,50 @@
7077
});
7178
</script>
7279

73-
<div bind:this={marker} class="clock -top-1">
74-
<ThemeToggle />
80+
<div class="absolute top-0">
81+
<svg
82+
class="absolute z-[-1] w-auto h-[70vw] -translate-x-1/2 -translate-y-1/2"
83+
viewBox="-0 0 100 100"
84+
>
85+
<circle
86+
cx="50"
87+
cy="100"
88+
r="46"
89+
fill="transparent"
90+
stroke={textColour}
91+
stroke-width="0.5"
92+
stroke-dasharray="1,10,1"
93+
>
94+
<animateTransform
95+
attributeName="transform"
96+
begin="0s"
97+
dur="60s"
98+
type="rotate"
99+
from="0 50 100"
100+
to="360 50 100"
101+
repeatCount="indefinite"
102+
/>
103+
</circle>
104+
<!-- <circle cx="50" cy="100.5" r="1" fill="magenta" /> -->
105+
</svg>
106+
<div bind:this={marker} class="clock">
107+
<ThemeToggle />
108+
<!-- <div -->
109+
<!-- class="absolute h-100 bg-blue-500 rounded-full clock-arm" -->
110+
<!-- ></div> -->
111+
</div>
112+
<!-- <div -->
113+
<!-- class="absolute w-2 h-2 bg-red-500 rounded-full" -->
114+
<!-- style="top: 35vw; left: 50%; transform: translate(-50%, -50%);" -->
115+
<!-- ></div> -->
75116
</div>
76117

77-
78118
<style>
79119
.clock {
80120
position: absolute;
121+
width: max-content;
81122
transform-origin: center 35vw;
82-
transform: rotate(-90deg);
123+
transform: translateX(-32px) rotate(-90deg);
83124
transition: transform 1s ease-in-out;
84125
}
85126
</style>

src/lib/components/ThemeToggle.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@
5454
</script>
5555

5656
<button bind:this={sunButton} onclick={toggleTheme}>
57-
<img src="/icons/sun.svg" width="64" alt="Sun" class="hover-expand" />
57+
<img src="/icons/sun.svg" alt="Sun" class="hover-expand w-[5vw]" />
5858
</button>
5959
<button bind:this={moonButton} onclick={toggleTheme}>
60-
<img src="/icons/moon.svg" width="64" alt="Moon" class="hover-expand" />
60+
<img src="/icons/moon.svg" width="64" alt="Moon" class="hover-expand w-[5vw]" />
6161
</button>
6262

6363
<style>

0 commit comments

Comments
 (0)