|
| 1 | +import * as marquee from "@zag-js/marquee" |
| 2 | +import { normalizeProps, useMachine } from "@zag-js/react" |
| 3 | +import { marqueeControls, marqueeData } from "@zag-js/shared" |
| 4 | +import { useId } from "react" |
| 5 | +import { StateVisualizer } from "../components/state-visualizer" |
| 6 | +import { Toolbar } from "../components/toolbar" |
| 7 | +import { useControls } from "../hooks/use-controls" |
| 8 | + |
| 9 | +export default function Page() { |
| 10 | + const controls = useControls(marqueeControls) |
| 11 | + |
| 12 | + const service = useMachine(marquee.machine, { |
| 13 | + id: useId(), |
| 14 | + spacing: "2rem", |
| 15 | + ...controls.context, |
| 16 | + }) |
| 17 | + |
| 18 | + const api = marquee.connect(service, normalizeProps) |
| 19 | + |
| 20 | + return ( |
| 21 | + <> |
| 22 | + <main className="marquee"> |
| 23 | + <div {...api.getRootProps()}> |
| 24 | + <div {...api.getEdgeProps({ side: "start" })} /> |
| 25 | + |
| 26 | + <div {...api.getViewportProps()}> |
| 27 | + {Array.from({ length: api.contentCount }).map((_, index) => ( |
| 28 | + <div key={index} {...api.getContentProps({ index })}> |
| 29 | + {marqueeData.map((item, i) => ( |
| 30 | + <div key={i} className="marquee-item"> |
| 31 | + <span className="marquee-logo">{item.logo}</span> |
| 32 | + <span className="marquee-name">{item.name}</span> |
| 33 | + </div> |
| 34 | + ))} |
| 35 | + </div> |
| 36 | + ))} |
| 37 | + </div> |
| 38 | + |
| 39 | + <div {...api.getEdgeProps({ side: "end" })} /> |
| 40 | + </div> |
| 41 | + |
| 42 | + <div className="controls"> |
| 43 | + <button onClick={() => api.pause()}>Pause</button> |
| 44 | + <button onClick={() => api.resume()}>Resume</button> |
| 45 | + <button onClick={() => api.togglePause()}>Toggle</button> |
| 46 | + <span>Status: {api.paused ? "Paused" : "Playing"}</span> |
| 47 | + </div> |
| 48 | + </main> |
| 49 | + |
| 50 | + <Toolbar controls={controls.ui}> |
| 51 | + <StateVisualizer state={service} /> |
| 52 | + </Toolbar> |
| 53 | + </> |
| 54 | + ) |
| 55 | +} |
0 commit comments