-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
140 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
import { addons } from '@storybook/manager-api'; | ||
import { theme } from './theme'; | ||
import theme from './theme'; | ||
|
||
addons.setConfig({ | ||
theme: theme, | ||
theme: theme | ||
}); | ||
|
||
export default theme; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import i18n from '../testUtils/i18nextForStorybook'; | ||
import React, { useEffect } from 'react'; | ||
import { ColorMode } from '~/components/ColorModeSwitcher'; | ||
import { StoryContext, StoryFn } from '@storybook/react'; | ||
import '../src/styles/app.css'; | ||
import './storybook.css'; | ||
import { I18nextProvider } from 'react-i18next'; | ||
import theme from './theme'; | ||
|
||
const withAllTheThings = (Story: StoryFn, context: StoryContext) => { | ||
const { colorMode } = context.globals; | ||
|
||
const setMode = (mode: ColorMode) => { | ||
const cl = document.firstElementChild?.classList; | ||
document.body.classList.remove(ColorMode.LIGHT, ColorMode.DARK); | ||
if (cl) { | ||
cl.remove(ColorMode.LIGHT, ColorMode.DARK); | ||
cl.add(mode); | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
setMode(colorMode); | ||
}, [colorMode]); | ||
|
||
return ( | ||
<I18nextProvider i18n={i18n}> | ||
<Story/> | ||
</I18nextProvider> | ||
); | ||
}; | ||
|
||
export const decorators = [ | ||
withAllTheThings | ||
]; | ||
|
||
/** @type { import('@storybook/react').Preview } */ | ||
export const parameters = { | ||
docs: { | ||
theme: theme, | ||
canvas: { | ||
background: false, | ||
className: 'storybook-canvas' | ||
}, | ||
story: { | ||
inline: true | ||
} | ||
}, | ||
actions: { argTypesRegex: '^on[A-Z].*' }, | ||
controls: { | ||
matchers: { | ||
color: /(background|color)$/i, | ||
date: /Date$/ | ||
} | ||
}, | ||
dependencies: { | ||
// display only dependencies/dependents that have a story in storybook | ||
// by default this is false | ||
withStoriesOnly: true, | ||
|
||
// completely hide a dependency/dependents block if it has no elements | ||
// by default this is false | ||
hideEmpty: true | ||
}, | ||
backgrounds: { disable: true }, | ||
locale: 'en', | ||
locales: { | ||
en: 'English' | ||
} | ||
}; | ||
|
||
export const globalTypes = { | ||
colorMode: { | ||
name: 'ColorMode', | ||
description: 'Color Mode', | ||
defaultValue: 'dark', | ||
toolbar: { | ||
items: [ | ||
{ value: 'dark', title: 'Dark', icon: 'moon' }, | ||
{ value: 'light', title: 'Light', icon: 'sun' } | ||
], | ||
showName: true, | ||
dynamicTitle: true | ||
} | ||
} | ||
}; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/** This is necessary to override the default canvas styles */ | ||
.storybook-canvas { | ||
background-color: var(--color-secondary) !important; | ||
color: var(--color-primary) !important; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,9 @@ | ||
import { create } from '@storybook/theming/create'; | ||
|
||
export const theme = create({ | ||
export default create({ | ||
base: 'dark', | ||
brandTitle: 'Storybook', | ||
brandUrl: 'https://storybook.com', | ||
brandImage: 'https://placekitten.com/350/150', | ||
brandTarget: '_self', | ||
colorPrimary: '#ED117D', | ||
brandTarget: '_self' | ||
}); | ||
|
||
export default theme; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import i18n from 'i18next'; | ||
import { initReactI18next } from 'react-i18next'; | ||
import en from '../public/locales/en/translation.json'; | ||
|
||
i18n | ||
.use(initReactI18next) | ||
|
||
.init({ | ||
lng: 'en', | ||
fallbackLng: 'en', | ||
ns: ['translation'], | ||
defaultNS: 'translation', | ||
interpolation: { | ||
escapeValue: false | ||
}, | ||
resources: { | ||
en: { | ||
translation: en // no translations mean we can test and snapshot the translation keys used | ||
} | ||
} | ||
}); | ||
|
||
export default i18n; |