Skip to content

Commit a735698

Browse files
committed
fix: Cleanup mag-cursor exp
1 parent 72594ef commit a735698

File tree

13 files changed

+317
-148
lines changed

13 files changed

+317
-148
lines changed

svelte-app/src/components/experiments/gol.svelte

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -120,25 +120,9 @@
120120
<Divider />
121121
</header>
122122

123-
<figure class="relative w-full overflow-clip rounded-md">
124-
<div class="grid w-fit gap-0.5" style="grid-template-columns: repeat({cols}, 12px);">
125-
{#each grid as row, rowIndex}
126-
{#each row as cell, colIndex}
127-
<!-- svelte-ignore a11y-no-static-element-interactions a11y-click-events-have-key-events -->
128-
<div
129-
class="h-3 w-3 rounded-sm shadow-lg {cell
130-
? 'bg-violet-500/60 shadow-violet-500/30 dark:shadow-violet-500/10'
131-
: 'bg-transparent shadow-transparent'}"
132-
on:click={() => !running && toggleCell(rowIndex, colIndex)}
133-
/>
134-
{/each}
135-
{/each}
136-
</div>
137-
</figure>
138-
139123
<Tooltip text={running ? 'Pause' : 'Resume'}>
140124
<button
141-
class="focus-outline absolute right-4 top-4 rounded-md p-1"
125+
class="focus-outline absolute right-4 top-4 rounded-md p-2"
142126
on:click={running ? stopGame : startGame}
143127
>
144128
{#if running}
@@ -162,4 +146,20 @@
162146
{/if}
163147
</button>
164148
</Tooltip>
149+
150+
<figure class="relative w-full overflow-clip rounded-md">
151+
<div class="grid w-fit gap-0.5" style="grid-template-columns: repeat({cols}, 12px);">
152+
{#each grid as row, rowIndex}
153+
{#each row as cell, colIndex}
154+
<!-- svelte-ignore a11y-no-static-element-interactions a11y-click-events-have-key-events -->
155+
<div
156+
class="h-3 w-3 rounded-sm shadow-lg {cell
157+
? 'bg-violet-500/60 shadow-violet-500/30 dark:shadow-violet-500/10'
158+
: 'bg-transparent shadow-transparent'}"
159+
on:click={() => !running && toggleCell(rowIndex, colIndex)}
160+
/>
161+
{/each}
162+
{/each}
163+
</div>
164+
</figure>
165165
</article>
Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
<script lang="ts">
2-
import Divider from '$components/divider.svelte';
3-
import MagButton from '$components/experiments/mag-cursor/button.svelte';
4-
import MagCursor from '$components/experiments/mag-cursor/cursor.svelte';
2+
import { BASE_GIT_URL } from '$lib/consts';
53
6-
let container: HTMLElement,
7-
containerRect: DOMRect,
8-
targets: HTMLElement[] = [],
9-
activeIdx: number | undefined = undefined;
4+
import Divider from '$components/divider.svelte';
5+
import Cursor from '$components/experiments/mag-cursor/cursor.svelte';
6+
import CursorTarget from '$components/experiments/mag-cursor/target.svelte';
7+
import Icon from '$components/icon.svelte';
8+
import Link from '$components/link.svelte';
109
11-
const register = (element: HTMLElement) => targets.push(element);
10+
let container: HTMLElement, containerRect: DOMRect;
1211
1312
const buttons = ['Button One', 'Button Two', 'Button Three'];
1413
</script>
1514

1615
<svelte:window on:resize={() => (containerRect = container?.getBoundingClientRect())} />
1716

18-
<!-- svelte-ignore a11y-mouse-events-have-key-events a11y-no-static-element-interactions -->
19-
<div
17+
<!-- svelte-ignore a11y-mouse-events-have-key-events -->
18+
<article
2019
class="relative my-6 block cursor-none rounded-lg bg-dark/5 px-7 py-6 shadow-2xl shadow-dark/5 transition-shadow focus-within:shadow-dark/10 hover:shadow-dark/10 dark:bg-light/5 dark:shadow-light/5"
2120
on:mouseover={() => (containerRect = container?.getBoundingClientRect())}
2221
bind:this={container}
@@ -26,13 +25,44 @@
2625
<p>A simple magnetic cursor effect. Hover over the buttons to try it out.</p>
2726
<Divider />
2827
</header>
28+
29+
<CursorTarget distance={38} let:active let:offset>
30+
<Link
31+
href="{BASE_GIT_URL}/blob/main/svelte-app/src/components/experiments/mag-cursor.svelte"
32+
class="focus-outline absolute right-4 top-4 z-10 cursor-none rounded-sm p-2"
33+
tooltipDelay={150}
34+
tooltipText="View source"
35+
newtab
36+
style="transform: translate({offset?.[0]}px, {offset?.[1]}px)"
37+
>
38+
<Icon
39+
name="ExternalLink"
40+
size={21}
41+
class="hover:text-accent-light/90 focus-visible:text-accent-light/90 hover:dark:text-accent-dark/90 focus-visible:dark:text-accent-dark/90 {active
42+
? 'text-accent-light/90 dark:text-accent-dark/90'
43+
: 'text-dark/90 dark:text-light/90'}"
44+
/>
45+
</Link>
46+
</CursorTarget>
47+
2948
<figure class="h-fit w-full overflow-hidden">
30-
<div class="flex w-full flex-row items-center justify-center pb-6 pt-5">
31-
{#each buttons as label, i}
32-
<MagButton {label} {register} active={i === activeIdx} />
49+
<div class="flex w-full flex-row items-center justify-center gap-2 pb-10 pt-8">
50+
{#each buttons as label}
51+
<CursorTarget let:active let:offset
52+
><button
53+
class="focus-outline-sm cursor-none select-none rounded-lg px-3 py-2 font-code text-base transition-colors active:text-accent-light/80 dark:active:text-accent-dark/80 {active
54+
? ' text-accent-light dark:text-accent-dark'
55+
: ''}"
56+
tabindex="0"
57+
>
58+
<div style="transform: translate({offset?.[0]}px, {offset?.[1]}px)">
59+
{label}
60+
</div></button
61+
></CursorTarget
62+
>
3363
{/each}
3464
</div>
3565

36-
<MagCursor {targets} {containerRect} bind:activeTarget={activeIdx} />
66+
<Cursor {containerRect} />
3767
</figure>
38-
</div>
68+
</article>

svelte-app/src/components/experiments/mag-cursor/button.svelte

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)