Add new story for darkmode (#317)

* Add a new story for dark mode

* Reorganize storybook menu

* Fix command menu margins

* Fix tests
This commit is contained in:
Félix Malfait 2023-06-17 14:52:49 +02:00 committed by GitHub
parent 299ca293a8
commit 5ae5f28dcb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 87 additions and 36 deletions

View File

@ -4,7 +4,6 @@ import { ThemeProvider } from '@emotion/react';
import { withThemeFromJSXProvider } from "@storybook/addon-styling";
import { lightTheme, darkTheme } from '../src/modules/ui/layout/styles/themes';
initialize();
const preview: Preview = {

View File

@ -0,0 +1,30 @@
import { Meta } from '@storybook/react';
import { App } from '~/App';
import { graphqlMocks } from '~/testing/graphqlMocks';
import { mockedUserJWT } from '~/testing/mock-data/jwt';
import { Story } from './App.stories';
import { renderWithDarkMode } from './shared';
const meta: Meta<typeof App> = {
title: 'App/App/DarkMode',
component: App,
};
export default meta;
export const DarkMode: Story = {
render: () => renderWithDarkMode(true),
loaders: [
async () => ({
accessTokenStored: window.localStorage.setItem(
'accessToken',
mockedUserJWT,
),
}),
],
parameters: {
msw: graphqlMocks,
},
};

View File

@ -0,0 +1,11 @@
{ /* App.mdx */ }
import { Canvas, Meta } from '@storybook/blocks';
import * as App from './App.stories';
<Meta of={App} />
# App View
<Canvas of={App.Default} />

View File

@ -1,14 +1,10 @@
import { MemoryRouter } from 'react-router-dom';
import { ApolloProvider } from '@apollo/client';
import type { Meta, StoryObj } from '@storybook/react';
import { RecoilRoot } from 'recoil';
import { App } from '~/App';
import { AuthProvider } from '~/providers/AuthProvider';
import { FullHeightStorybookLayout } from '~/testing/FullHeightStorybookLayout';
import { graphqlMocks } from '~/testing/graphqlMocks';
import { mockedUserJWT } from '~/testing/mock-data/jwt';
import { mockedClient } from '~/testing/mockedClient';
import { render } from './shared';
const meta: Meta<typeof App> = {
title: 'App/App',
@ -16,21 +12,7 @@ const meta: Meta<typeof App> = {
};
export default meta;
type Story = StoryObj<typeof App>;
const render = () => (
<RecoilRoot>
<ApolloProvider client={mockedClient}>
<MemoryRouter>
<FullHeightStorybookLayout>
<AuthProvider>
<App />
</AuthProvider>
</FullHeightStorybookLayout>
</MemoryRouter>
</ApolloProvider>
</RecoilRoot>
);
export type Story = StoryObj<typeof App>;
export const Default: Story = {
render,

View File

@ -0,0 +1,36 @@
import { MemoryRouter } from 'react-router-dom';
import { ApolloProvider } from '@apollo/client';
import { ThemeProvider } from '@emotion/react';
import { RecoilRoot } from 'recoil';
import { darkTheme } from '@/ui/layout/styles/themes';
import { App } from '~/App';
import { AuthProvider } from '~/providers/AuthProvider';
import { FullHeightStorybookLayout } from '~/testing/FullHeightStorybookLayout';
import { mockedClient } from '~/testing/mockedClient';
export const render = () => renderWithDarkMode(false);
export const renderWithDarkMode = (forceDarkMode?: boolean) => {
const AppInStoryBook = (
<FullHeightStorybookLayout>
<AuthProvider>
<App />
</AuthProvider>
</FullHeightStorybookLayout>
);
return (
<RecoilRoot>
<ApolloProvider client={mockedClient}>
<MemoryRouter>
{forceDarkMode ? (
<ThemeProvider theme={darkTheme}>{AppInStoryBook}</ThemeProvider>
) : (
AppInStoryBook
)}
</MemoryRouter>
</ApolloProvider>
</RecoilRoot>
);
};

View File

@ -7,7 +7,7 @@ import { CellCommentChip } from '../CellCommentChip';
import { CommentChip } from '../CommentChip';
const meta: Meta<typeof CellCommentChip> = {
title: 'Comments/CellCommentChip',
title: 'Modules/Comments/CellCommentChip',
component: CellCommentChip,
};

View File

@ -9,7 +9,7 @@ import { getRenderWrapperForComponent } from '~/testing/renderWrappers';
import { CommentHeader } from '../CommentHeader';
const meta: Meta<typeof CommentHeader> = {
title: 'Comments/CommentHeader',
title: 'Modules/Comments/CommentHeader',
component: CommentHeader,
};

View File

@ -8,7 +8,7 @@ import { getRenderWrapperForComponent } from '~/testing/renderWrappers';
import { CommentThreadRelationPicker } from '../CommentThreadRelationPicker';
const meta: Meta<typeof CommentThreadRelationPicker> = {
title: 'Comments/CommentThreadRelationPicker',
title: 'Modules/Comments/CommentThreadRelationPicker',
component: CommentThreadRelationPicker,
parameters: {
msw: graphqlMocks,

View File

@ -10,7 +10,6 @@ export const StyledDialog = styled(Command.Dialog)`
max-width: 640px;
overflow: hidden;
padding: 0;
padding: 25px;
position: fixed;
top: 50%;
transform: translate(-50%, -50%);

View File

@ -5,7 +5,7 @@ import { getRenderWrapperForPage } from '~/testing/renderWrappers';
import { CommandMenu } from '../CommandMenu';
const meta: Meta<typeof CommandMenu> = {
title: 'Pages/Search/CommandMenu',
title: 'Modules/Search/CommandMenu',
component: CommandMenu,
};

View File

@ -16,7 +16,7 @@ import { DropdownMenuSelectableItem } from '../DropdownMenuSelectableItem';
import { DropdownMenuSeparator } from '../DropdownMenuSeparator';
const meta: Meta<typeof DropdownMenu> = {
title: 'Components/DropdownMenu',
title: 'UI/Menu/DropdownMenu',
component: DropdownMenu,
};

View File

@ -1,6 +0,0 @@
import { atom } from 'recoil';
export const isThemeEnabledState = atom<boolean>({
key: 'isThemeEnabledState',
default: true,
});

View File

@ -5,7 +5,7 @@ import { getRenderWrapperForComponent } from '~/testing/renderWrappers';
import { Avatar } from '../Avatar';
const meta: Meta<typeof Avatar> = {
title: 'Components/Common/Avatar',
title: 'Modules/Users/Avatar',
component: Avatar,
};

View File

@ -7,7 +7,7 @@ import { SettingsProfile } from '../SettingsProfile';
import { render } from './shared';
const meta: Meta<typeof SettingsProfile> = {
title: 'Pages/SettingsProfile',
title: 'Pages/Settings/SettingsProfile',
component: SettingsProfile,
};