Skip to content

Dark mode theme #4853

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/ui/build/storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = {
addons: [
getAbsolutePath('@storybook/addon-essentials'),
getAbsolutePath('@storybook/addon-webpack5-compiler-babel'),
getAbsolutePath('@storybook/addon-themes'),
],

docs: {
Expand Down
8 changes: 8 additions & 0 deletions packages/ui/build/storybook/preview.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import React from 'react';
import type { Preview } from '@storybook/react';
import { withThemeByClassName } from '@storybook/addon-themes';

import '../../src/css/variables.css';
import '../../src/css/default.css';
import { SvgIcons } from '../../src/assets/icons.svg.jsx';

const preview: Preview = {
decorators: [
withThemeByClassName({
themes: {
light: 'light-theme',
dark: 'dark-theme',
},
defaultTheme: 'light',
}),
(Story) => (
<div>
<Story />
Expand Down
1 change: 1 addition & 0 deletions packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"@babel/preset-react": "7.27.1",
"@babel/preset-typescript": "7.27.1",
"@storybook/addon-essentials": "8.6.12",
"@storybook/addon-themes": "8.6.12",
"@storybook/addon-webpack5-compiler-babel": "3.0.6",
"@storybook/react": "8.6.12",
"@storybook/react-webpack5": "8.6.12",
Expand Down
15 changes: 9 additions & 6 deletions packages/ui/src/app/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { HashRouter, NavLink, Route, Switch, useLocation } from 'react-router-do
import { COMPONENT } from '@bundle-stats/utils';

import { URLS } from '../constants';
import { ThemeProvider } from '../context/theme';
import { BundleAssets } from '../components/bundle-assets';
import { BundleAssetsTotals } from '../components/bundle-assets-totals';
import { BundleModules } from '../components/bundle-modules';
Expand Down Expand Up @@ -205,10 +206,12 @@ AppComponent.propTypes = {
};

export const App = (props) => (
<HashRouter>
<ScrollToTop />
<QueryStateProvider>
<AppComponent {...props} />
</QueryStateProvider>
</HashRouter>
<ThemeProvider>
<HashRouter>
<ScrollToTop />
<QueryStateProvider>
<AppComponent {...props} />
</QueryStateProvider>
</HashRouter>
</ThemeProvider>
);
12 changes: 6 additions & 6 deletions packages/ui/src/app/app.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
}

.empty {
padding-top: var(--space-large);
padding-top: var(--space-8x);
min-height: 80vh;
text-align: center;
}
Expand All @@ -18,13 +18,13 @@
}

.summaryContainer {
padding-top: var(--space-small);
padding-bottom: var(--space-xxsmall);
padding-top: var(--space-4x);
padding-bottom: var(--space-2x);
}

.tabsContainer {
border-bottom: 1px solid var(--color-outline);
background: var(--color-light);
background: var(--color-background);
}

.tabs {
Expand All @@ -40,8 +40,8 @@
}

.tabsContent {
padding-top: var(--space-medium);
padding-bottom: var(--space-medium);
padding-top: var(--space-6x);
padding-bottom: var(--space-6x);
min-height: 480px;
}

Expand Down
20 changes: 2 additions & 18 deletions packages/ui/src/app/header/header.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,7 @@
flex: 0 0 auto;
}

.toolsGitHub {
display: block;
border-radius: 50%;
opacity: 0.8;
color: var(--color-text-ultra-dark);
transition: var(--transition-out);
}

.toolsGitHub:hover,
.toolsGitHub:focus,
.toolsGitHub:active {
opacity: 1;
transition: var(--transition-in);
}

.toolsGitHubIcon {
display: block;
.toolsButton {
}
Comment on lines +9 to 10
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add styles for the theme toggle button.

The .toolsButton class is empty. Since this is part of the dark mode theme implementation, consider adding styles for proper button appearance and interaction.

Here's a suggested implementation:

 .toolsButton {
+  display: flex;
+  align-items: center;
+  padding: var(--space-2x);
+  border-radius: var(--radius-small);
+  transition: opacity 0.2s ease-in-out;
+  cursor: pointer;
 }

Would you like me to suggest additional styles or hover states for better user interaction?

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
.toolsButton {
}
.toolsButton {
display: flex;
align-items: center;
padding: var(--space-2x);
border-radius: var(--radius-small);
transition: opacity 0.2s ease-in-out;
cursor: pointer;
}
🧰 Tools
🪛 Biome (1.9.4)

[error] 9-10: An empty block isn't allowed.

Consider removing the empty block or adding styles inside it.

(lint/suspicious/noEmptyBlock)


@media (min-width: 1140px) {
Expand All @@ -33,6 +17,6 @@
height: var(--header-height);
display: flex;
align-items: center;
padding: 0 var(--space-small);
padding: 0 var(--space-4x);
}
}
66 changes: 47 additions & 19 deletions packages/ui/src/app/header/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,60 @@ import cx from 'classnames';

import config from '../../config.json';
import I18N from '../../i18n';
import { useTheme } from '../../context/theme';
import { Container } from '../../ui/container';
import { Icon } from '../../ui/icon';
import { FlexStack } from '../../layout/flex-stack';
import { JobsHeader } from '../../components/jobs-header';
import css from './header.module.css';
import { Button } from '../../ui/button';

interface HeaderProps {
jobs: React.ComponentProps<typeof JobsHeader>['jobs'];
}

export const Header = ({ className = '', jobs }: HeaderProps & React.ComponentProps<'header'>) => (
<Container as="header" className={cx(css.root, className)}>
<FlexStack space="small" alignItems="center">
<JobsHeader className={css.jobs} jobs={jobs} />
<div className={css.tools}>
<a
href={config.gitHubUrl}
target="_blank"
rel="noopener noreferrer"
title={I18N.GITHUB_LINK_TITLE}
aria-label={I18N.GITHUB_LINK_TITLE}
className={css.toolsGitHub}
>
<Icon glyph={Icon.ICONS.GITHUB} size="large" className={css.toolsGitHubIcon} />
</a>
</div>
</FlexStack>
</Container>
);
export const Header = ({ className = '', jobs }: HeaderProps & React.ComponentProps<'header'>) => {
const theme = useTheme();

return (
<Container as="header" className={cx(css.root, className)}>
<FlexStack space="small" alignItems="center">
<JobsHeader className={css.jobs} jobs={jobs} />
<FlexStack space="xxxsmall" alignItems="center" className={css.tools}>
{theme.name === 'dark' ? (
<Button
size="small"
outline
onClick={() => theme.update('light')}
className={css.toolsButton}
>
<Icon glyph={Icon.ICONS.MOON} />
</Button>
) : (
<Button
size="small"
outline
onClick={() => theme.update('dark')}
className={css.toolsButton}
>
<Icon glyph={Icon.ICONS.SUN} />
</Button>
Comment on lines +27 to +43
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add Accessible Labels to Theme Toggle Buttons

The theme toggle buttons lack accessible labels, which can hinder users relying on screen readers.

To improve accessibility, add aria-label attributes to the buttons:

 <Button
   size="small"
   outline
   onClick={() => theme.update('light')}
   className={css.toolsButton}
+  aria-label="Switch to light theme"
 >
   <Icon glyph={Icon.ICONS.SUN} />
 </Button>
 <Button
   size="small"
   outline
   onClick={() => theme.update('dark')}
   className={css.toolsButton}
+  aria-label="Switch to dark theme"
 >
   <Icon glyph={Icon.ICONS.MOON} />
 </Button>

Committable suggestion skipped: line range outside the PR's diff.

)}
Comment on lines +26 to +44
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Adjust Theme Toggle Icon and Logic for Better UX

The current implementation displays the icon representing the current theme. This might confuse users, as they might expect the icon to represent the theme they can switch to.

Consider updating the logic so that:

  • When the theme is 'dark', display the Sun icon and set onClick to update the theme to 'light'.
  • When the theme is 'light', display the Moon icon and set onClick to update the theme to 'dark'.

This approach aligns with common UX patterns and enhances user intuitiveness.

Apply the following diff to adjust the icon and logic:

 {theme.name === 'dark' ? (
   <Button
     size="small"
     outline
-    onClick={() => theme.update('light')}
+    onClick={() => theme.update('light')}
     className={css.toolsButton}
   >
-    <Icon glyph={Icon.ICONS.MOON} />
+    <Icon glyph={Icon.ICONS.SUN} />
   </Button>
 ) : (
   <Button
     size="small"
     outline
-    onClick={() => theme.update('dark')}
+    onClick={() => theme.update('dark')}
     className={css.toolsButton}
   >
-    <Icon glyph={Icon.ICONS.SUN} />
+    <Icon glyph={Icon.ICONS.MOON} />
   </Button>
 )}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{theme.name === 'dark' ? (
<Button
size="small"
outline
onClick={() => theme.update('light')}
className={css.toolsButton}
>
<Icon glyph={Icon.ICONS.MOON} />
</Button>
) : (
<Button
size="small"
outline
onClick={() => theme.update('dark')}
className={css.toolsButton}
>
<Icon glyph={Icon.ICONS.SUN} />
</Button>
)}
{theme.name === 'dark' ? (
<Button
size="small"
outline
onClick={() => theme.update('light')}
className={css.toolsButton}
>
<Icon glyph={Icon.ICONS.SUN} />
</Button>
) : (
<Button
size="small"
outline
onClick={() => theme.update('dark')}
className={css.toolsButton}
>
<Icon glyph={Icon.ICONS.MOON} />
</Button>
)}

<Button
size="small"
outline
as="a"
href={config.gitHubUrl}
target="_blank"
rel="noopener noreferrer"
title={I18N.GITHUB_LINK_TITLE}
aria-label={I18N.GITHUB_LINK_TITLE}
className={css.toolsButton}
>
<Icon glyph={Icon.ICONS.GITHUB} />
</Button>
</FlexStack>
</FlexStack>
</Container>
);
};
11 changes: 11 additions & 0 deletions packages/ui/src/assets/icons.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading