Skip to content
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

chore: Add darkMode configuration to ui-client storybook #35629

Merged
merged 3 commits into from
Mar 27, 2025
Merged
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
21 changes: 21 additions & 0 deletions packages/ui-client/.storybook/DocsContainer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { DocsContainer as BaseContainer } from '@storybook/blocks';
import { addons } from '@storybook/preview-api';
import { themes } from '@storybook/theming';
import type { ComponentPropsWithoutRef } from 'react';
import { useEffect, useState } from 'react';
import { DARK_MODE_EVENT_NAME } from 'storybook-dark-mode';

const channel = addons.getChannel();

const DocsContainer = (props: ComponentPropsWithoutRef<typeof BaseContainer>) => {
const [isDark, setDark] = useState(false);

useEffect(() => {
channel.on(DARK_MODE_EVENT_NAME, setDark);
return () => channel.removeListener(DARK_MODE_EVENT_NAME, setDark);
}, [setDark]);

return <BaseContainer {...props} theme={isDark ? themes.dark : themes.light} />;
};

export default DocsContainer;
68 changes: 68 additions & 0 deletions packages/ui-client/.storybook/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions packages/ui-client/.storybook/logo.svg.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare const path: string;

export = path;
2 changes: 2 additions & 0 deletions packages/ui-client/.storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import type { StorybookConfig } from '@storybook/react-webpack5';
const config: StorybookConfig = {
stories: ['../src/**/*.stories.@(js|jsx|ts|tsx)'],
addons: [
getAbsolutePath('@storybook/addon-a11y'),
getAbsolutePath('@storybook/addon-essentials'),
getAbsolutePath('storybook-dark-mode'),
getAbsolutePath('@storybook/addon-webpack5-compiler-babel'),
getAbsolutePath('@storybook/addon-styling-webpack'),
],
Expand Down
65 changes: 49 additions & 16 deletions packages/ui-client/.storybook/preview.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,61 @@
import { PaletteStyleTag } from '@rocket.chat/fuselage';
import surface from '@rocket.chat/fuselage-tokens/dist/surface.json';
import type { Decorator, Parameters } from '@storybook/react';
import { themes } from '@storybook/theming';
import { useDarkMode } from 'storybook-dark-mode';

import '../../../apps/meteor/app/theme/client/main.css';
import 'highlight.js/styles/github.css';
import manifest from '../package.json';
import DocsContainer from './DocsContainer';
import logo from './logo.svg';
import '@rocket.chat/fuselage/dist/fuselage.css';
import '@rocket.chat/icons/dist/rocketchat.css';

export const parameters: Parameters = {
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/,
backgrounds: {
grid: {
cellSize: 4,
cellAmount: 4,
opacity: 0.5,
},
},
options: {
storySort: {
method: 'alphabetical',
},
},
layout: 'fullscreen',
docs: {
container: DocsContainer,
},
darkMode: {
dark: {
...themes.dark,
appBg: surface.surface.dark.sidebar,
appContentBg: surface.surface.dark.light,
appPreviewBg: 'transparent',
barBg: surface.surface.dark.light,
brandTitle: manifest.name,
brandImage: logo,
},
light: {
...themes.normal,
appPreviewBg: 'transparent',
brandTitle: manifest.name,
brandImage: logo,
},
},
};

export const decorators: Decorator[] = [
(Story) => (
<div>
<style>{`
body {
background-color: white;
}
`}</style>
<Story />
</div>
),
(Story) => {
const dark = useDarkMode();

return (
<>
<PaletteStyleTag theme={dark ? 'dark' : 'light'} />
<Story />
</>
);
},
];
export const tags = ['autodocs'];
2 changes: 2 additions & 0 deletions packages/ui-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"@rocket.chat/mock-providers": "workspace:^",
"@rocket.chat/ui-avatar": "workspace:~",
"@rocket.chat/ui-contexts": "workspace:~",
"@storybook/addon-a11y": "^8.6.4",
"@storybook/addon-actions": "^8.6.4",
"@storybook/addon-docs": "^8.6.4",
"@storybook/addon-essentials": "^8.6.4",
Expand All @@ -53,6 +54,7 @@
"react-dom": "~18.3.1",
"react-hook-form": "~7.45.4",
"storybook": "^8.6.4",
"storybook-dark-mode": "^4.0.2",
"typescript": "~5.7.2"
},
"peerDependencies": {
Expand Down
2 changes: 2 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9775,6 +9775,7 @@ __metadata:
"@rocket.chat/mock-providers": "workspace:^"
"@rocket.chat/ui-avatar": "workspace:~"
"@rocket.chat/ui-contexts": "workspace:~"
"@storybook/addon-a11y": "npm:^8.6.4"
"@storybook/addon-actions": "npm:^8.6.4"
"@storybook/addon-docs": "npm:^8.6.4"
"@storybook/addon-essentials": "npm:^8.6.4"
Expand All @@ -9801,6 +9802,7 @@ __metadata:
react-dom: "npm:~18.3.1"
react-hook-form: "npm:~7.45.4"
storybook: "npm:^8.6.4"
storybook-dark-mode: "npm:^4.0.2"
typescript: "npm:~5.7.2"
peerDependencies:
"@react-aria/toolbar": "*"
Expand Down
Loading