|
1 | 1 | <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'; |
5 | 3 |
|
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'; |
10 | 9 |
|
11 | | - const register = (element: HTMLElement) => targets.push(element); |
| 10 | + let container: HTMLElement, containerRect: DOMRect; |
12 | 11 |
|
13 | 12 | const buttons = ['Button One', 'Button Two', 'Button Three']; |
14 | 13 | </script> |
15 | 14 |
|
16 | 15 | <svelte:window on:resize={() => (containerRect = container?.getBoundingClientRect())} /> |
17 | 16 |
|
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 |
20 | 19 | 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" |
21 | 20 | on:mouseover={() => (containerRect = container?.getBoundingClientRect())} |
22 | 21 | bind:this={container} |
|
26 | 25 | <p>A simple magnetic cursor effect. Hover over the buttons to try it out.</p> |
27 | 26 | <Divider /> |
28 | 27 | </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 | + |
29 | 48 | <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 | + > |
33 | 63 | {/each} |
34 | 64 | </div> |
35 | 65 |
|
36 | | - <MagCursor {targets} {containerRect} bind:activeTarget={activeIdx} /> |
| 66 | + <Cursor {containerRect} /> |
37 | 67 | </figure> |
38 | | -</div> |
| 68 | +</article> |
0 commit comments