Skip to content

Commit 5de0e90

Browse files
authored
Merge pull request #23 from rangle/stephanie/demo-update-toggles
feat: add toggles to the demo page
2 parents d7633cd + 7514937 commit 5de0e90

File tree

9 files changed

+2768
-3904
lines changed

9 files changed

+2768
-3904
lines changed

apps/demo/src/App.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@
3535

3636
.card {
3737
padding: 2em;
38+
display: flex;
39+
flex-direction: row;
40+
justify-content: center;
41+
align-items: center;
42+
gap: 1em;
3843
}
3944

4045
.read-the-docs {

apps/demo/src/App.tsx

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,56 @@
11
import './App.css'
22
import { Button } from '@repo/ui'
3+
import "@repo/foundations/styles";
4+
import { useTheme } from './ThemeProvider';
5+
6+
const LightModeIcon = () => (<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" className="lucide lucide-sun"><circle cx="12" cy="12" r="4"/><path d="M12 2v2"/><path d="M12 20v2"/><path d="m4.93 4.93 1.41 1.41"/><path d="m17.66 17.66 1.41 1.41"/><path d="M2 12h2"/><path d="M20 12h2"/><path d="m6.34 17.66-1.41 1.41"/><path d="m19.07 4.93-1.41 1.41"/></svg>
7+
)
8+
9+
const DarkModeIcon = () => (<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" className="lucide lucide-moon"><path d="M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z"/></svg>)
10+
11+
const DesktopIcon = () => (<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" className="lucide lucide-monitor-check"><path d="m9 10 2 2 4-4"/><rect width="20" height="14" x="2" y="3" rx="2"/><path d="M12 17v4"/><path d="M8 21h8"/></svg>)
12+
13+
const MobileIcon = () => (<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" className="lucide lucide-tablet-smartphone"><rect width="10" height="14" x="3" y="8" rx="2"/><path d="M5 4a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2v16a2 2 0 0 1-2 2h-2.4"/><path d="M8 18h.01"/></svg>)
14+
15+
const DefaultBrandIcon = () => (<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" className="lucide lucide-star"><path d="M11.525 2.295a.53.53 0 0 1 .95 0l2.31 4.679a2.123 2.123 0 0 0 1.595 1.16l5.166.756a.53.53 0 0 1 .294.904l-3.736 3.638a2.123 2.123 0 0 0-.611 1.878l.882 5.14a.53.53 0 0 1-.771.56l-4.618-2.428a2.122 2.122 0 0 0-1.973 0L6.396 21.01a.53.53 0 0 1-.77-.56l.881-5.139a2.122 2.122 0 0 0-.611-1.879L2.16 9.795a.53.53 0 0 1 .294-.906l5.165-.755a2.122 2.122 0 0 0 1.597-1.16z"/></svg>)
16+
17+
const SecondaryBrandIcon = () => (<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" className="lucide lucide-star-off"><path d="M8.34 8.34 2 9.27l5 4.87L5.82 21 12 17.77 18.18 21l-.59-3.43"/><path d="M18.42 12.76 22 9.27l-6.91-1L12 2l-1.44 2.91"/><line x1="2" x2="22" y1="2" y2="22"/></svg>)
18+
319

420
function App() {
21+
const {
22+
brand,
23+
mode,
24+
breakpoint,
25+
setBrand,
26+
setMode,
27+
setBreakpoint
28+
} = useTheme();
29+
530

631
return (
7-
<>
32+
<main>
833
<div>
934
Radius Token Tango demo
1035
</div>
36+
<div></div>
1137
<h1>Kitchen Sink</h1>
12-
<div className="card">
13-
<Button label="Click me" />
38+
<div className='control'>
39+
<button title={mode === 'dark' ? 'Switch to light mode' : 'Switch to dark mode'} onClick={() => setMode(mode === 'dark' ? 'light' : 'dark')}>
40+
{mode === 'dark' ? <LightModeIcon /> : <DarkModeIcon />}
41+
</button>
42+
<button title={breakpoint === 'desktop' ? 'Switch to mobile view' : 'Switch to desktop view'} onClick={() => setBreakpoint(breakpoint === 'desktop' ? 'mobile' : 'desktop')}>
43+
{breakpoint === 'desktop' ? <MobileIcon /> : <DesktopIcon />}
44+
</button>
45+
<button title={brand === 'brand-1' ? 'Switch to hot brand' : 'Switch to default brand'} onClick={() => setBrand(brand === 'brand-1' ? 'hot-brand' : 'brand-1')}>
46+
{brand === 'brand-1' ? <SecondaryBrandIcon/> : <DefaultBrandIcon/>}
47+
</button>
48+
</div>
49+
<div className='card'>
50+
<Button label="Primary" variant='primary' />
51+
<Button label="Secondary" variant='secondary' />
1452
</div>
15-
</>
53+
</main>
1654
)
1755
}
1856

apps/demo/src/ThemeProvider.tsx

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import React, { createContext, useState, ReactNode, useEffect, useContext } from 'react';
2+
3+
type Brand = 'brand-1' | 'hot-brand';
4+
type Mode = 'light' | 'dark';
5+
type Breakpoint = 'desktop' | 'mobile';
6+
type Density = 'default' | 'compact';
7+
8+
interface ThemeContextType {
9+
brand: Brand;
10+
mode: Mode;
11+
breakpoint: Breakpoint;
12+
density: Density;
13+
setBrand: (brand: Brand) => void;
14+
setMode: (mode: Mode) => void;
15+
setBreakpoint: (breakpoint: Breakpoint) => void;
16+
setDensity: (density: Density) => void;
17+
bodyClasses: string;
18+
}
19+
20+
const ThemeContext = createContext<ThemeContextType | undefined>(undefined);
21+
22+
export const ThemeProvider: React.FC<{ children: ReactNode }> = ({ children }) => {
23+
const [brand, setBrand] = useState<Brand>('brand-1');
24+
const [mode, setMode] = useState<Mode>('light');
25+
const [breakpoint, setBreakpoint] = useState<Breakpoint>('desktop');
26+
const [density, setDensity] = useState<Density>('default');
27+
28+
const bodyClasses = [brand, mode, density, breakpoint].join(" ");
29+
30+
useEffect(() => {
31+
document.body.className = bodyClasses;
32+
}, [bodyClasses]);
33+
34+
const contextValue: ThemeContextType = {
35+
brand,
36+
mode,
37+
breakpoint,
38+
density,
39+
setBrand,
40+
setMode,
41+
setBreakpoint,
42+
setDensity,
43+
bodyClasses
44+
};
45+
46+
return (
47+
<ThemeContext.Provider value={contextValue}>
48+
{children}
49+
</ThemeContext.Provider>
50+
);
51+
};
52+
53+
export const useTheme = () => {
54+
const context = useContext(ThemeContext);
55+
if (context === undefined) {
56+
throw new Error('useTheme must be used within a ThemeProvider');
57+
}
58+
return context;
59+
};

apps/demo/src/index.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,14 @@ body {
2828
place-items: center;
2929
min-width: 320px;
3030
min-height: 100vh;
31+
background-color: var(--semantic-static-background-color-default);
32+
color: var(--semantic-static-text-color-default);
3133
}
3234

3335
h1 {
3436
font-size: 3.2em;
3537
line-height: 1.1;
38+
color: var(--semantic-static-text-color-default);
3639
}
3740

3841
button {
@@ -54,6 +57,11 @@ button:focus-visible {
5457
outline: 4px auto -webkit-focus-ring-color;
5558
}
5659

60+
.control {
61+
display: flex;
62+
justify-content: center;
63+
gap: 0.5em;
64+
}
5765
@media (prefers-color-scheme: light) {
5866
:root {
5967
color: #213547;

apps/demo/src/main.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ import { StrictMode } from 'react'
22
import { createRoot } from 'react-dom/client'
33
import App from './App.tsx'
44
import './index.css'
5+
import { ThemeProvider } from './ThemeProvider.tsx'
56

67
createRoot(document.getElementById('root')!).render(
78
<StrictMode>
8-
<App />
9+
<ThemeProvider>
10+
<App />
11+
</ThemeProvider>
912
</StrictMode>,
1013
)

packages/foundations/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
"./styles": "./index.css"
99
},
1010
"scripts": {
11-
"build": "radius-toolkit generate tokens.json -o styles/index.css"
11+
"build": "radius-toolkit generate tokens.json -o styles/index.css",
12+
"build:custom": "radius-toolkit generate tokens.json -c myCustomTemplate -T ./templates -o styles/vector.json",
13+
"build:tailwind": "radius-toolkit generate tokens.json -t tailwind"
1214
},
1315
"keywords": [],
1416
"author": "",

0 commit comments

Comments
 (0)