JSFiddle - React, Tailwind, and code Playground
HTML
<div id="root"></div>
CSS
body {
margin: 0;
overflow: hidden;
cursor: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB4AAAAeCAYAAAA7MK6iAAAACXBIWXMAAHUwAAB1MAHdM3LNAAABC0lEQVRIicXXMWoCQRiG4cfpIkRQrITcIHiLiLmBncdInVOIR/AEEXILyQUkYiMINkmZFJnBsCAZjbvzwlft7rz7bbHzT0seN3jEA+5xh168tsc73vCKF3xmrnuSLp6xxldm1vGZ7qXSKTZnCKvZxDXOYvYPYTWzXOniitKURZNNs5tPapSmTKrSWxwaEB+iS4jiJ3ROfYor0oku0MbuwgaXZId2wAj9OmtW6GMUMG5QmhgHDAuIhwGDAuJBcNxlmqQX/r6nHoKf/bRp9gHbAuJtwKqAeBWwLCBeUvCX+YF57R2PzKMTBbbF3xQZBBJFRp9EkWGvjubZ421iqsBAn6jtCNPKfIGrH9q+AR1lbyolkfH7AAAAAElFTkSuQmCC"),
auto;
}
div#root {
position: absolute;
width: 100%;
height: 100%;
}
JavaScript
import htm from "https://esm.sh/htm";
import React, { useRef, useState } from "https://esm.sh/react@18.2.0";
import { createRoot } from "https://esm.sh/react-dom@18.2.0/client";
import { Canvas, useFrame } from "https://esm.sh/@react-three/fiber@8.16.0";
const html = htm.bind(React.createElement);
function App(props) {
return html`<${Canvas}>
<ambientLight intensity=${0.5} />
<pointLight intensity=${20} position=${[10, 10, 10]} />
<${Box} position=${[-1.2, 0, 0]} />
<${Box} position=${[1.2, 0, 0]} />
</${Canvas}>`;
}
function Box(props) {
const meshRef = useRef();
const [hovered, setHover] = useState(false);
const [active, setActive] = useState(false);
useFrame(
() => (meshRef.current.rotation.x = meshRef.current.rotation.y += 0.01)
);
return html`<mesh
...${props}
ref=${meshRef}
scale=${active ? 1 : 1.5}
onClick=${() => setActive(!active)}
onPointerOver=${() => setHover(true)}
onPointerOut=${() => setHover(false)}
>
<boxGeometry args=${[1, 1, 1]} />
<meshStandardMaterial color=${hovered ? "grey" : "white"} />
</mesh>`;
}
createRoot(document.getElementById("root")).render(html`<${App} />`);