|
1 | | -import { useState } from 'react'; |
| 1 | +import { useState, useEffect } from 'react'; |
2 | 2 | import reactLogo from './assets/react.svg'; |
3 | 3 | import viteLogo from '/vite.svg'; |
4 | 4 | import './App.css'; |
| 5 | +import { TwentyFirstToolbar } from '@21st-extension/toolbar-react'; |
5 | 6 |
|
6 | 7 | function App() { |
7 | 8 | const [count, setCount] = useState(0); |
| 9 | + const [isDark, setIsDark] = useState(false); |
8 | 10 |
|
9 | 11 | const handleRuntimeError = () => { |
10 | 12 | throw new Error('This is a runtime error for testing purposes'); |
11 | 13 | }; |
12 | 14 |
|
| 15 | + const toggleTheme = () => { |
| 16 | + if (isDark) { |
| 17 | + document.documentElement.classList.remove('dark'); |
| 18 | + setIsDark(false); |
| 19 | + } else { |
| 20 | + document.documentElement.classList.add('dark'); |
| 21 | + setIsDark(true); |
| 22 | + } |
| 23 | + }; |
| 24 | + |
| 25 | + const getCSSVariable = (varName: string) => { |
| 26 | + const anchor = document.querySelector('stagewise-companion-anchor'); |
| 27 | + if (anchor) { |
| 28 | + return getComputedStyle(anchor).getPropertyValue(varName).trim(); |
| 29 | + } |
| 30 | + return 'not found'; |
| 31 | + }; |
| 32 | + |
| 33 | + const [cssVars, setCssVars] = useState<{ [key: string]: string }>({}); |
| 34 | + |
| 35 | + useEffect(() => { |
| 36 | + const interval = setInterval(() => { |
| 37 | + setCssVars({ |
| 38 | + background: getCSSVariable('--background'), |
| 39 | + foreground: getCSSVariable('--foreground'), |
| 40 | + border: getCSSVariable('--border'), |
| 41 | + }); |
| 42 | + }, 1000); |
| 43 | + |
| 44 | + return () => clearInterval(interval); |
| 45 | + }, []); |
| 46 | + |
13 | 47 | return ( |
14 | 48 | <> |
| 49 | + <TwentyFirstToolbar /> |
15 | 50 | <div> |
16 | | - <a href="https://vite.dev" target="_blank"> |
| 51 | + <a href="https://vitejs.dev" target="_blank"> |
17 | 52 | <img src={viteLogo} className="logo" alt="Vite logo" /> |
18 | 53 | </a> |
19 | 54 | <a href="https://react.dev" target="_blank"> |
20 | 55 | <img src={reactLogo} className="logo react" alt="React logo" /> |
21 | 56 | </a> |
22 | 57 | </div> |
23 | 58 | <h1>Vite + React</h1> |
| 59 | + |
| 60 | + {/* Theme Debug Info */} |
| 61 | + <div |
| 62 | + style={{ |
| 63 | + border: '1px solid #ccc', |
| 64 | + padding: '10px', |
| 65 | + margin: '20px 0', |
| 66 | + backgroundColor: '#f9f9f9', |
| 67 | + }} |
| 68 | + > |
| 69 | + <h3>Theme Debug Info:</h3> |
| 70 | + <p>Current theme: {isDark ? 'Dark' : 'Light'}</p> |
| 71 | + <p>HTML classes: {document.documentElement.className || 'none'}</p> |
| 72 | + <p> |
| 73 | + Toolbar element exists:{' '} |
| 74 | + {document.querySelector('stagewise-companion-anchor') ? 'Yes' : 'No'} |
| 75 | + </p> |
| 76 | + |
| 77 | + <h4>CSS Variables:</h4> |
| 78 | + <ul> |
| 79 | + <li>--background: {cssVars.background || 'loading...'}</li> |
| 80 | + <li>--foreground: {cssVars.foreground || 'loading...'}</li> |
| 81 | + <li>--border: {cssVars.border || 'loading...'}</li> |
| 82 | + </ul> |
| 83 | + |
| 84 | + <button |
| 85 | + type="button" |
| 86 | + onClick={toggleTheme} |
| 87 | + style={{ |
| 88 | + padding: '8px 16px', |
| 89 | + backgroundColor: isDark ? '#333' : '#fff', |
| 90 | + color: isDark ? '#fff' : '#333', |
| 91 | + border: '1px solid #ccc', |
| 92 | + borderRadius: '4px', |
| 93 | + cursor: 'pointer', |
| 94 | + }} |
| 95 | + > |
| 96 | + Toggle Theme (Current: {isDark ? 'Dark' : 'Light'}) |
| 97 | + </button> |
| 98 | + </div> |
| 99 | + |
24 | 100 | <div className="card"> |
25 | 101 | <button type="button" onClick={() => setCount((count) => count + 1)}> |
26 | 102 | count is {count} |
|
0 commit comments