Skip to content

Commit 540caf0

Browse files
committed
added light/dark mode toggle
1 parent 56b146f commit 540caf0

File tree

4 files changed

+157
-84
lines changed

4 files changed

+157
-84
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"@fortawesome/react-fontawesome": "^0.2.2",
5252
"@mdx-js/node-loader": "^3.0.0",
5353
"@mdx-js/react": "^3.0.0",
54+
"@mui/icons-material": "^6.3.1",
5455
"@mui/lab": "^5.0.0-alpha.108",
5556
"@mui/material": "^5.16.7",
5657
"@mui/system": "^5.16.7",

src/css/sumo.scss

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -227,12 +227,7 @@ html[data-theme='light'] {
227227
min-width: 100px;
228228
}
229229

230-
/* Berry CSS override to force global styles back to normal */
231-
body, .MuiTypography-root, button, input, select, textarea {
232-
font-family: 'Lab Grotesque', sans-serif !important;
233-
}
234-
235-
/* Berry chatbot */
230+
/* Berry chatbot inline height */
236231
#inline-berry-chatbot-container iframe {
237232
height: 600px !important;
238233
}

src/pages/index.tsx

Lines changed: 147 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
import React, { useState, useEffect } from 'react';
22
import Layout from '@theme/Layout';
3-
import { Box, Button, Container, Grid, Stack, Tab, Tabs, Typography } from '@mui/material';
3+
import {
4+
Box,
5+
Button,
6+
Container,
7+
Grid,
8+
Stack,
9+
Tab,
10+
Tabs,
11+
Typography,
12+
Switch
13+
} from '@mui/material';
414
import { TabContext, TabPanel } from '@mui/lab';
15+
import { LightMode, DarkMode } from '@mui/icons-material'; // <-- Icons
516
import bgImage from '../../static/img/hero-secondary-background.webp';
617
import heroImage from '../../static/img/hero-secondary-graphic.webp';
718
import SumoLogicDocsLogo from '../../static/img/sumo-logic-docs.svg';
@@ -12,6 +23,9 @@ import ErrorBoundary from '../components/ErrorBoundary';
1223
export const Home = () => {
1324
const [tab, setTab] = useState('0');
1425

26+
// Track whether we're in dark mode:
27+
const [isDark, setIsDark] = useState(false);
28+
1529
const questions = [
1630
'✨ timestamps',
1731
'✨ how do you write a log search query?',
@@ -41,13 +55,16 @@ export const Home = () => {
4155
botUrlPath: 'nova',
4256
showNewChat: true,
4357
parentElementId: 'inline-berry-chatbot-container',
58+
// If you want to start in dark mode by default, uncomment:
59+
// colorMode: 'dark',
4460
});
4561
};
4662

4763
script.onerror = () => console.error('Failed to load Berry widget script');
4864
}
4965
}, []);
5066

67+
// Send a question to Berry:
5168
const handleQuestionClick = (question) => {
5269
if (window.Berry) {
5370
if (window.Berry.sendMessage) {
@@ -59,68 +76,125 @@ export const Home = () => {
5976
}
6077
};
6178

79+
// Toggle Berry's theme on switch change:
80+
const handleToggle = (event) => {
81+
const newValue = event.target.checked; // true = dark mode, false = light mode
82+
setIsDark(newValue);
83+
84+
if (window.Berry && window.Berry.update) {
85+
window.Berry.update({
86+
colorMode: newValue ? 'dark' : 'light'
87+
});
88+
}
89+
};
90+
6291
return (
6392
<ErrorBoundary>
6493
<Layout
6594
description='Sumo Logic docs - real-time alerting, security, dashboards, and machine-learning-powered analytics for all three types of telemetry — logs, metrics, and traces.'
6695
title='Home'
6796
>
68-
69-
7097
{/* Suggested Questions */}
7198
<Box sx={{ width: '100%', background: '#2a2a2a', color: '#fff', py: 4 }}>
72-
7399
<Container maxWidth="md" sx={{ textAlign: 'center' }}>
74-
<Typography variant="h4" fontWeight={600} mt={1} mb={3}>
75-
Sumo Logic Documentation
76-
</Typography>
77-
<Typography variant="h5" fontFamily="Lab Grotesque" fontWeight={300} mb={2} sx={{ background: 'linear-gradient(90deg, #9900ED, #C04CF4, #00C8E0)', WebkitBackgroundClip: 'text', WebkitTextFillColor: 'transparent' }}>
100+
<Box
101+
component={SumoLogicDocsLogo}
102+
alt="Sumo Logic Docs logo"
103+
role="<img>"
104+
aria-hidden="true"
105+
height={{
106+
md: 30,
107+
xs: 22,
108+
}}
109+
width='100%'
110+
/>
111+
<Typography
112+
fontFamily="Lab Grotesque"
113+
variant='h3'
114+
fontSize={32}
115+
fontWeight={700}
116+
mt={2}
117+
mb={2}
118+
sx={{
119+
background: 'linear-gradient(90deg, #9900ED, #C04CF4, #00C8E0)',
120+
WebkitBackgroundClip: 'text',
121+
WebkitTextFillColor: 'transparent'
122+
}}
123+
>
78124
Our Docs Assistant is here to help!
79125
</Typography>
80-
<Typography fontFamily="Lab Grotesque" fontSize={13} fontWeight={300} mb={2}>
126+
<Typography
127+
fontFamily="Lab Grotesque"
128+
fontSize={13}
129+
fontWeight={300}
130+
mb={2}
131+
>
81132
Ask me anything! You can type full questions, sentences, or just keywords, and I'll help you find the information you need. Try these to get started:
82133
</Typography>
83134
<Stack
84-
direction="row"
85-
spacing={1} // Reduced horizontal spacing between buttons
86-
justifyContent="center"
87-
flexWrap="wrap"
88-
rowGap={1} // Reduced vertical spacing between rows
135+
direction="row"
136+
spacing={1}
137+
justifyContent="center"
138+
flexWrap="wrap"
139+
rowGap={1}
89140
>
90-
91-
{questions.map((question, index) => (
92-
<Button
93-
key={index}
94-
onClick={() => handleQuestionClick(question)}
95-
variant="outlined"
96-
sx={{
97-
bgcolor: 'transparent',
98-
color: '#DDDDDD',
99-
fontFamily: 'Lab Grotesque',
100-
borderColor: '#808080',
101-
borderRadius: '5px',
102-
textTransform: 'lowercase',
103-
fontSize: '12px',
104-
fontWeight: '300',
105-
padding: '4px 6px',
106-
minWidth: 'auto',
107-
'&:hover': {
108-
bgcolor: '#2a2a2a',
109-
color: '#DDDDDD',
110-
},
111-
}}
112-
>
113-
{question}
114-
</Button>
115-
))}
116-
</Stack>
141+
{questions.map((question, index) => (
142+
<Button
143+
key={index}
144+
onClick={() => handleQuestionClick(question)}
145+
variant="outlined"
146+
sx={{
147+
bgcolor: 'transparent',
148+
color: '#DDDDDD',
149+
fontFamily: 'Lab Grotesque',
150+
borderColor: '#808080',
151+
borderRadius: '5px',
152+
textTransform: 'lowercase',
153+
fontSize: '12px',
154+
fontWeight: '300',
155+
padding: '4px 6px',
156+
minWidth: 'auto',
157+
'&:hover': {
158+
bgcolor: '#2a2a2a',
159+
color: '#DDDDDD',
160+
},
161+
}}
162+
>
163+
{question}
164+
</Button>
165+
))}
166+
</Stack>
117167

118168
{/* Inline Chatbot Container */}
119-
<Box id="inline-berry-chatbot-container" sx={{ my: 4, p: 2, margin: '0 auto', textAlign: 'center' }}>
120-
{/* The chatbot will render here */}
169+
<Box
170+
id="inline-berry-chatbot-container"
171+
sx={{ my: 4, p: 2, margin: '0 auto', textAlign: 'center' }}
172+
>
173+
{/* Berry chatbot will render here */}
121174
</Box>
175+
176+
{/* Light/Dark Toggle Switch with icons */}
177+
<Stack direction="row" spacing={1} alignItems="center" justifyContent="center">
178+
{/* Label: Light */}
179+
<Typography variant="body2" color="#fff">
180+
Light
181+
</Typography>
182+
<Switch
183+
checked={isDark}
184+
onChange={handleToggle}
185+
color="default"
186+
// Sun icon when off (light), moon icon when on (dark)
187+
icon={<LightMode />} // Unchecked icon
188+
checkedIcon={<DarkMode />} // Checked icon
189+
/>
190+
{/* Label: Dark */}
191+
<Typography variant="body2" color="#fff">
192+
Dark
193+
</Typography>
194+
</Stack>
122195
</Container>
123196
</Box>
197+
124198
{/* Hero */}
125199
<Stack
126200
sx={{
@@ -158,10 +232,7 @@ export const Home = () => {
158232
}}
159233
height='100%'
160234
>
161-
<Grid
162-
item
163-
md={6}
164-
>
235+
<Grid item md={6}>
165236
<Stack
166237
alignItems={{
167238
md: 'flex-start',
@@ -258,7 +329,6 @@ export const Home = () => {
258329

259330
{/* Main */}
260331
<Container maxWidth='xl'>
261-
262332
{/* Product Guides */}
263333
<Stack
264334
alignItems='center'
@@ -335,7 +405,7 @@ export const Home = () => {
335405
{
336406
label: 'Other Solutions',
337407
},
338-
].map(({ label, ...rest }, index) => (
408+
].map(({ label }, index) => (
339409
<Tab
340410
key={label}
341411
label={label}
@@ -345,40 +415,40 @@ export const Home = () => {
345415
fontWeight: 'bold',
346416
}}
347417
value={String(index)}
348-
{...rest}
349418
/>
350419
))}
351420
</Tabs>
352-
{features.map((feature, index) => tab === String(index) && (
353-
<Grid
354-
component={TabPanel}
355-
container
356-
direction='row'
357-
justifyContent='center'
358-
key={index}
359-
py={6}
360-
spacing={4}
361-
value={String(index)}
362-
>
363-
{feature.map((config) => (
364-
<Grid
365-
item
366-
key={config.link}
367-
lg={4}
368-
md={6}
369-
xs={12}
370-
>
371-
<Feature
372-
length={feature.length}
373-
{...config}
374-
/>
375-
</Grid>
376-
))}
377-
</Grid>
421+
{features.map((feature, index) => (
422+
tab === String(index) && (
423+
<Grid
424+
component={TabPanel}
425+
container
426+
direction='row'
427+
justifyContent='center'
428+
key={index}
429+
py={6}
430+
spacing={4}
431+
value={String(index)}
432+
>
433+
{feature.map((config) => (
434+
<Grid
435+
item
436+
key={config.link}
437+
lg={4}
438+
md={6}
439+
xs={12}
440+
>
441+
<Feature
442+
length={feature.length}
443+
{...config}
444+
/>
445+
</Grid>
446+
))}
447+
</Grid>
448+
)
378449
))}
379450
</TabContext>
380451
</Stack>
381-
382452
</Container>
383453
</Layout>
384454
</ErrorBoundary>

yarn.lock

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1038,7 +1038,7 @@
10381038
core-js-pure "^3.30.2"
10391039
regenerator-runtime "^0.14.0"
10401040

1041-
"@babel/runtime@^7.1.2", "@babel/runtime@^7.10.3", "@babel/runtime@^7.12.13", "@babel/runtime@^7.12.5", "@babel/runtime@^7.25.9", "@babel/runtime@^7.8.4":
1041+
"@babel/runtime@^7.1.2", "@babel/runtime@^7.10.3", "@babel/runtime@^7.12.13", "@babel/runtime@^7.12.5", "@babel/runtime@^7.25.9", "@babel/runtime@^7.26.0", "@babel/runtime@^7.8.4":
10421042
version "7.26.0"
10431043
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.26.0.tgz#8600c2f595f277c60815256418b85356a65173c1"
10441044
integrity sha512-FDSOghenHTiToteC/QRlv2q3DhPZ/oOXTBoirfWNx1Cx3TMVcGWQtMMmQcSvb/JjpNeGzx8Pq/b4fKEJuWm1sw==
@@ -2370,6 +2370,13 @@
23702370
resolved "https://registry.yarnpkg.com/@mui/core-downloads-tracker/-/core-downloads-tracker-5.16.7.tgz#182a325a520f7ebd75de051fceabfc0314cfd004"
23712371
integrity sha512-RtsCt4Geed2/v74sbihWzzRs+HsIQCfclHeORh5Ynu2fS4icIKozcSubwuG7vtzq2uW3fOR1zITSP84TNt2GoQ==
23722372

2373+
"@mui/icons-material@^6.3.1":
2374+
version "6.3.1"
2375+
resolved "https://registry.yarnpkg.com/@mui/icons-material/-/icons-material-6.3.1.tgz#f28b5ecc3a4d8e8be389f9e9e5738759c7a98240"
2376+
integrity sha512-nJmWj1PBlwS3t1PnoqcixIsftE+7xrW3Su7f0yrjPw4tVjYrgkhU0hrRp+OlURfZ3ptdSkoBkalee9Bhf1Erfw==
2377+
dependencies:
2378+
"@babel/runtime" "^7.26.0"
2379+
23732380
"@mui/lab@^5.0.0-alpha.108":
23742381
version "5.0.0-alpha.170"
23752382
resolved "https://registry.yarnpkg.com/@mui/lab/-/lab-5.0.0-alpha.170.tgz#4519dfc8d1c51ca54fb9d8b91b95a3733d07be16"

0 commit comments

Comments
 (0)