|
| 1 | +import { useRef, useState } from 'react'; |
| 2 | +import { CI360Viewer, CI360ViewerRef } from 'js-cloudimage-360-view/react'; |
| 3 | +import 'js-cloudimage-360-view/css'; |
| 4 | + |
| 5 | +// Example 1: Basic viewer with autoplay |
| 6 | +function BasicExample() { |
| 7 | + return ( |
| 8 | + <div className="example"> |
| 9 | + <h2>Basic Example with Autoplay</h2> |
| 10 | + <CI360Viewer |
| 11 | + folder="https://scaleflex.cloudimg.io/v7/demo/suv-orange-car-360/" |
| 12 | + filenameX="orange-{index}.jpg" |
| 13 | + amountX={73} |
| 14 | + autoplay |
| 15 | + fullscreen |
| 16 | + bottomCircle |
| 17 | + hints |
| 18 | + style={{ width: '100%', height: 400 }} |
| 19 | + /> |
| 20 | + <div className="features"> |
| 21 | + <span className="feature-tag">Autoplay</span> |
| 22 | + <span className="feature-tag">Fullscreen</span> |
| 23 | + <span className="feature-tag">73 Frames</span> |
| 24 | + </div> |
| 25 | + </div> |
| 26 | + ); |
| 27 | +} |
| 28 | + |
| 29 | +// Example 2: Ref control with buttons |
| 30 | +function RefControlExample() { |
| 31 | + const viewerRef = useRef<CI360ViewerRef>(null); |
| 32 | + const [currentFrame, setCurrentFrame] = useState(0); |
| 33 | + |
| 34 | + return ( |
| 35 | + <div className="example"> |
| 36 | + <h2>Programmatic Control via Ref</h2> |
| 37 | + <CI360Viewer |
| 38 | + ref={viewerRef} |
| 39 | + folder="https://scaleflex.cloudimg.io/v7/demo/suv-orange-car-360/" |
| 40 | + filenameX="orange-{index}.jpg" |
| 41 | + amountX={73} |
| 42 | + fullscreen |
| 43 | + inertia |
| 44 | + onSpin={(data) => setCurrentFrame(data.activeImageX)} |
| 45 | + style={{ width: '100%', height: 400 }} |
| 46 | + /> |
| 47 | + <div className="frame-indicator">Current Frame: {currentFrame + 1} / 73</div> |
| 48 | + <div className="controls"> |
| 49 | + <button onClick={() => viewerRef.current?.play()}>Play</button> |
| 50 | + <button onClick={() => viewerRef.current?.stop()}>Stop</button> |
| 51 | + <button onClick={() => viewerRef.current?.moveLeft(5)}>Rotate Left</button> |
| 52 | + <button onClick={() => viewerRef.current?.moveRight(5)}>Rotate Right</button> |
| 53 | + <button onClick={() => viewerRef.current?.goToFrame(0)}>Go to Start</button> |
| 54 | + <button onClick={() => viewerRef.current?.goToFrame(36)}>Go to Middle</button> |
| 55 | + </div> |
| 56 | + <div className="features"> |
| 57 | + <span className="feature-tag">Ref Control</span> |
| 58 | + <span className="feature-tag">Inertia</span> |
| 59 | + <span className="feature-tag">onSpin Event</span> |
| 60 | + </div> |
| 61 | + </div> |
| 62 | + ); |
| 63 | +} |
| 64 | + |
| 65 | +// Example 3: Zoom features |
| 66 | +function ZoomExample() { |
| 67 | + return ( |
| 68 | + <div className="example"> |
| 69 | + <h2>Zoom & Magnifier</h2> |
| 70 | + <CI360Viewer |
| 71 | + folder="https://scaleflex.cloudimg.io/v7/demo/earbuds/" |
| 72 | + filenameX="earbuds-{index}.jpg" |
| 73 | + amountX={233} |
| 74 | + pointerZoom={3} |
| 75 | + fullscreen |
| 76 | + speed={50} |
| 77 | + style={{ width: '100%', height: 400 }} |
| 78 | + /> |
| 79 | + <div className="features"> |
| 80 | + <span className="feature-tag">Pointer Zoom (3x)</span> |
| 81 | + <span className="feature-tag">233 Frames</span> |
| 82 | + <span className="feature-tag">Click to zoom</span> |
| 83 | + </div> |
| 84 | + </div> |
| 85 | + ); |
| 86 | +} |
| 87 | + |
| 88 | +// Example 4: Event callbacks |
| 89 | +function EventsExample() { |
| 90 | + const [events, setEvents] = useState<string[]>([]); |
| 91 | + |
| 92 | + const addEvent = (event: string) => { |
| 93 | + setEvents((prev) => [...prev.slice(-4), event]); |
| 94 | + }; |
| 95 | + |
| 96 | + return ( |
| 97 | + <div className="example"> |
| 98 | + <h2>Event Callbacks</h2> |
| 99 | + <CI360Viewer |
| 100 | + folder="https://scaleflex.cloudimg.io/v7/demo/suv-orange-car-360/" |
| 101 | + filenameX="orange-{index}.jpg" |
| 102 | + amountX={73} |
| 103 | + fullscreen |
| 104 | + onReady={() => addEvent('onReady')} |
| 105 | + onLoad={() => addEvent('onLoad')} |
| 106 | + onAutoplayStart={() => addEvent('onAutoplayStart')} |
| 107 | + onAutoplayStop={() => addEvent('onAutoplayStop')} |
| 108 | + onDragStart={() => addEvent('onDragStart')} |
| 109 | + onDragEnd={() => addEvent('onDragEnd')} |
| 110 | + onZoomIn={() => addEvent('onZoomIn')} |
| 111 | + onZoomOut={() => addEvent('onZoomOut')} |
| 112 | + style={{ width: '100%', height: 400 }} |
| 113 | + /> |
| 114 | + <div className="event-log"> |
| 115 | + <strong>Events:</strong> {events.length > 0 ? events.join(' → ') : 'Interact to see events'} |
| 116 | + </div> |
| 117 | + <div className="features"> |
| 118 | + <span className="feature-tag">onReady</span> |
| 119 | + <span className="feature-tag">onLoad</span> |
| 120 | + <span className="feature-tag">onDragStart/End</span> |
| 121 | + <span className="feature-tag">onZoom</span> |
| 122 | + </div> |
| 123 | + </div> |
| 124 | + ); |
| 125 | +} |
| 126 | + |
| 127 | +// Example 5: Theme toggle |
| 128 | +function ThemeExample() { |
| 129 | + const [theme, setTheme] = useState<'light' | 'dark'>('light'); |
| 130 | + |
| 131 | + return ( |
| 132 | + <div className="example"> |
| 133 | + <h2>Theme Toggle</h2> |
| 134 | + <CI360Viewer |
| 135 | + folder="https://scaleflex.cloudimg.io/v7/demo/suv-orange-car-360/" |
| 136 | + filenameX="orange-{index}.jpg" |
| 137 | + amountX={73} |
| 138 | + fullscreen |
| 139 | + theme={theme} |
| 140 | + style={{ width: '100%', height: 400 }} |
| 141 | + /> |
| 142 | + <div className="controls"> |
| 143 | + <button |
| 144 | + className={theme === 'light' ? 'active' : ''} |
| 145 | + onClick={() => setTheme('light')} |
| 146 | + > |
| 147 | + Light Theme |
| 148 | + </button> |
| 149 | + <button |
| 150 | + className={theme === 'dark' ? 'active' : ''} |
| 151 | + onClick={() => setTheme('dark')} |
| 152 | + > |
| 153 | + Dark Theme |
| 154 | + </button> |
| 155 | + </div> |
| 156 | + <div className="features"> |
| 157 | + <span className="feature-tag">Light Theme</span> |
| 158 | + <span className="feature-tag">Dark Theme</span> |
| 159 | + <span className="feature-tag">Dynamic Switch</span> |
| 160 | + </div> |
| 161 | + </div> |
| 162 | + ); |
| 163 | +} |
| 164 | + |
| 165 | +export default function App() { |
| 166 | + return ( |
| 167 | + <div className="app"> |
| 168 | + <header> |
| 169 | + <h1>CloudImage 360 View - React</h1> |
| 170 | + <p>Interactive 360-degree product viewer - Version 4.1.0</p> |
| 171 | + </header> |
| 172 | + |
| 173 | + <main> |
| 174 | + <BasicExample /> |
| 175 | + <RefControlExample /> |
| 176 | + <ZoomExample /> |
| 177 | + <EventsExample /> |
| 178 | + <ThemeExample /> |
| 179 | + </main> |
| 180 | + |
| 181 | + <footer> |
| 182 | + <a |
| 183 | + href="https://github.com/niceplayer/js-cloudimage-360-view" |
| 184 | + target="_blank" |
| 185 | + rel="noopener noreferrer" |
| 186 | + > |
| 187 | + GitHub Repository |
| 188 | + </a> |
| 189 | + <span>|</span> |
| 190 | + <a |
| 191 | + href="https://scaleflex.github.io/js-cloudimage-360-view/" |
| 192 | + target="_blank" |
| 193 | + rel="noopener noreferrer" |
| 194 | + > |
| 195 | + Documentation |
| 196 | + </a> |
| 197 | + </footer> |
| 198 | + </div> |
| 199 | + ); |
| 200 | +} |
0 commit comments