-
Notifications
You must be signed in to change notification settings - Fork 130
/
Copy pathindex.tsx
60 lines (54 loc) · 1.91 KB
/
index.tsx
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
import { createActiveElement, focus } from "../src/index.js";
import { Component, createSignal, Index, onMount, ParentComponent } from "solid-js";
import { genNodeList } from "./utils.js";
// prevent tree-shaking
focus;
const Node: ParentComponent<{ x: number; y: number; size: number }> = props => {
const [isFocused, setIsFocused] = createSignal(false);
return (
<button
use:focus={setIsFocused}
class="fixed left-0 top-0 h-48 w-48 cursor-pointer rounded-full border-none bg-orange-700 text-4xl font-extrabold text-gray-900 hover:bg-orange-600"
classList={{
"!bg-indigo-700 !hover:bg-indigo-600": isFocused(),
}}
style={{
transform: `translate(${props.x}px, ${props.y}px) scale(${props.size})`,
transition: "transform 500ms, background 200ms",
}}
>
{props.children}
</button>
);
};
const Client: Component = () => {
const [list, setList] = createSignal(genNodeList());
const shuffle = () => setList(genNodeList());
const activeEl = createActiveElement();
return (
<div class="box-border h-screen w-full overflow-hidden bg-gray-900 text-white">
<Index each={list()}>
{item => (
<Node x={item().x} y={item().y} size={item().size}>
{item().id}
</Node>
)}
</Index>
<button
class="fixed left-1/2 top-1/2 -ml-32 -mt-8 h-16 w-64 cursor-pointer rounded-lg border-none bg-transparent text-5xl font-extrabold text-white hover:text-yellow-200"
onclick={shuffle}
>
Shuffle!
</button>
<div class="absolute left-6 top-6 text-4xl font-extrabold">
Active Element:{" "}
{activeEl() && activeEl()?.tagName !== "BODY" ? activeEl()?.textContent : "null"}
</div>
</div>
);
};
export default function App() {
const [mounted, setMounted] = createSignal(false);
onMount(() => setMounted(true));
return <>{mounted() && <Client />}</>;
}