Skip to content

Commit

Permalink
docs: add dark mode (#409)
Browse files Browse the repository at this point in the history
* chore: update storybook

Signed-off-by: Nikolai Lopin <[email protected]>

* chore: remove git flavour markdown

Signed-off-by: Nikolai Lopin <[email protected]>

* docs: adds dark/light schema switch

Signed-off-by: Nikolai Lopin <[email protected]>

* fix: `LightScheme` component doesn't work

Signed-off-by: Nikolai Lopin <[email protected]>

* docs: reflect scheme preferences in the code highlighting

Signed-off-by: Nikolai Lopin <[email protected]>

* docs: support dark mode

Signed-off-by: Nikolai Lopin <[email protected]>

* chore: update package-lock

Signed-off-by: Nikolai Lopin <[email protected]>

* docs: fix color page

Signed-off-by: Nikolai Lopin <[email protected]>

* 2.0.0-alpha.3

* refactor: clean imports

Signed-off-by: Nikolai Lopin <[email protected]>

---------

Signed-off-by: Nikolai Lopin <[email protected]>
  • Loading branch information
Nikolai Lopin authored Jan 24, 2024
1 parent 3c52b92 commit b6d32c2
Show file tree
Hide file tree
Showing 24 changed files with 1,311 additions and 1,075 deletions.
21 changes: 15 additions & 6 deletions .storybook/FreenowTheme.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
// .storybook/FreenowTheme.ts
import { create } from '@storybook/theming/create';

export default create({
base: 'light',

// Typography
const baseVars = {
fontBase: '"Open Sans", sans-serif',
fontCode: 'monospace',

brandTitle: 'FREENOW',
brandUrl: 'https://wave.free-now.com/',
brandImage: 'https://wave.free-now.com/freenow-logo.svg',
brandTarget: '_self',
brandTarget: '_self'
};

export const LightTheme = create({
base: 'light',
...baseVars,

//
colorPrimary: '#CA0928',
colorSecondary: '#585C6D',

Expand All @@ -38,3 +39,11 @@ export default create({
inputTextColor: '#10162F',
inputBorderRadius: 2
});

export const DarkTheme = create({
base: 'dark',
appContentBg: 'hsl(0deg, 0%, 5%)',
appPreviewBg: '#222425',
inputTextColor: 'blue',
...baseVars
});
3 changes: 2 additions & 1 deletion .storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ const config: StorybookConfig = {
'@storybook/addon-links',
'@storybook/addon-essentials',
'@storybook/addon-interactions',
'@storybook/addon-viewport'
'@storybook/addon-viewport',
'storybook-dark-mode'
],
framework: {
name: '@storybook/react-webpack5',
Expand Down
7 changes: 0 additions & 7 deletions .storybook/manager.ts

This file was deleted.

53 changes: 41 additions & 12 deletions .storybook/preview.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import React from 'react';
import { Preview } from '@storybook/react';
import { themes } from '@storybook/theming';
import { DocsContainer } from '@storybook/addon-docs';
import { useDarkMode } from 'storybook-dark-mode';

import { GlobalStyle as ClassicColors } from '../src/essentials/Colors/Colors';
import { GlobalStyle as ModernColors } from '../src/essentials/Colors/ModernColors';
import { getSemanticValue } from '../src/utils/cssVariables';
import { DarkScheme, LightScheme } from '../src/components/ColorScheme';

import { LightTheme, DarkTheme } from './FreenowTheme';

const THEMES = {
classic: ClassicColors,
Expand All @@ -15,16 +20,34 @@ export const withTheme = (Story, context) => {
return (
<>
<Theme />
<div className="wave">
<Story {...context} />
</div>
<Story {...context} />
</>
);
};

export const withColorScheme = (Story, context) => {
const SchemeWrapper = useDarkMode() ? DarkScheme : LightScheme;

return (
<SchemeWrapper>
<Story {...context} />
</SchemeWrapper>
);
};

export const preview: Preview = {
decorators: [withTheme],
decorators: [withTheme, withColorScheme],
parameters: {
darkMode: {
dark: { ...themes.dark, ...DarkTheme },
light: {
...themes.normal,
...LightTheme
},
lightClass: ['wave', 'light-scheme'],
darkClass: ['wave', 'dark-scheme'],
stylePreview: true
},
actions: { argTypesRegex: '^on[A-Z].*' },
viewMode: 'docs',
controls: {
Expand All @@ -40,18 +63,24 @@ export const preview: Preview = {
}
},
docs: {
theme: themes.light,
container: props => {
const scheme = useDarkMode() ? DarkTheme : LightTheme;
const globals = props.context.store.globals.get();
const WaveTheme = THEMES[globals.theme];

return (
<>
<WaveTheme />
<DocsContainer {...props} theme={scheme} />
</>
);
},
toc: {
headingSelector: 'h2, h3'
}
},
backgrounds: {
default: 'auto',
values: [
{ name: 'auto', value: getSemanticValue('background-page-default') },
{ name: 'light', value: getSemanticValue('background-surface-neutral-default') },
{ name: 'dark', value: getSemanticValue('background-surface-primary-default') }
]
disable: true
},
viewport: {
viewports: {
Expand Down
139 changes: 50 additions & 89 deletions docs/assets/wave-background.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
59 changes: 10 additions & 49 deletions docs/assets/wave-ds-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 0 additions & 38 deletions docs/components/BoxWithSchemeToggle.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion docs/components/migration/CssVariablesMigrationTable.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { Source } from '@storybook/blocks';

import { Source } from '../../../src/docs/Source';
import { Table, TableCell, TableHeaderCell, TableRow } from '../../../src/components/Table';

const codemodsExample = `import styled from 'styled-components';
Expand Down
Loading

0 comments on commit b6d32c2

Please sign in to comment.