-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update storybook example to use CSF * Update README
- Loading branch information
1 parent
d3247b5
commit 7413893
Showing
13 changed files
with
4,004 additions
and
2,088 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,4 @@ | ||
module.exports = { | ||
stories: ['../src/**/*.stories.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'], | ||
addons: ['@storybook/addon-links', '@storybook/addon-essentials'], | ||
}; |
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,45 @@ | ||
import { useEffect, Suspense } from 'react'; | ||
import { I18nextProvider } from 'react-i18next'; | ||
|
||
import i18n from '../src/i18n'; | ||
|
||
// Create a global variable called locale in storybook | ||
// and add a dropdown in the toolbar to change your locale | ||
export const globalTypes = { | ||
locale: { | ||
name: 'Locale', | ||
description: 'Internationalization locale', | ||
toolbar: { | ||
icon: 'globe', | ||
items: [ | ||
{ value: 'en', right: '🇺🇸', title: 'English' }, | ||
{ value: 'de', right: '🇩🇪', title: 'Deutsch' }, | ||
], | ||
showName: true, | ||
}, | ||
}, | ||
}; | ||
|
||
// Wrap your stories in the I18nextProvider component | ||
const i18nextStoryDecorator = (Story, context) => { | ||
const { locale } = context.globals; | ||
|
||
// When the locale global changes | ||
// Set the new locale in i18n | ||
useEffect(() => { | ||
i18n.changeLanguage(locale); | ||
}, [locale]); | ||
|
||
return ( | ||
// here catches the suspense from components not yet ready (still loading translations) | ||
// alternative set useSuspense false on i18next.options.react when initializing i18next | ||
<Suspense fallback={<div>loading translations...</div>}> | ||
<I18nextProvider i18n={i18n}> | ||
<Story /> | ||
</I18nextProvider> | ||
</Suspense> | ||
); | ||
}; | ||
|
||
// export decorators for storybook to wrap your stories in | ||
export const decorators = [i18nextStoryDecorator]; |
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,68 +1,19 @@ | ||
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). | ||
# react-i18next in Storybook | ||
|
||
## Available Scripts | ||
This is an example application using `react-i18next` in Storybook including a menu in the toolbar to change the | ||
locale of your stories. | ||
|
||
In the project directory, you can run: | ||
![Storybook example](./docs/storybook-example.gif) | ||
|
||
### `npm start` | ||
## 🏁 Getting started | ||
|
||
Runs the app in the development mode.<br> | ||
Open [https://localhost:3000](https://localhost:3000) to view it in the browser. | ||
```bash | ||
# Install dependencies | ||
yarn install | ||
|
||
The page will reload if you make edits.<br> | ||
You will also see any lint errors in the console. | ||
# Start the React app | ||
yarn start | ||
|
||
### `npm test` | ||
|
||
Launches the test runner in the interactive watch mode.<br> | ||
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. | ||
|
||
### `npm run build` | ||
|
||
Builds the app for production to the `build` folder.<br> | ||
It correctly bundles React in production mode and optimizes the build for the best performance. | ||
|
||
The build is minified and the filenames include the hashes.<br> | ||
Your app is ready to be deployed! | ||
|
||
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. | ||
|
||
### `npm run eject` | ||
|
||
**Note: this is a one-way operation. Once you `eject`, you can’t go back!** | ||
|
||
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. | ||
|
||
Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. | ||
|
||
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. | ||
|
||
## Learn More | ||
|
||
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). | ||
|
||
To learn React, check out the [React documentation](https://reactjs.org/). | ||
|
||
### Code Splitting | ||
|
||
This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting | ||
|
||
### Analyzing the Bundle Size | ||
|
||
This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size | ||
|
||
### Making a Progressive Web App | ||
|
||
This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app | ||
|
||
### Advanced Configuration | ||
|
||
This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration | ||
|
||
### Deployment | ||
|
||
This section has moved here: https://facebook.github.io/create-react-app/docs/deployment | ||
|
||
### `npm run build` fails to minify | ||
|
||
This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify | ||
# Start Storybook | ||
yarn storybook | ||
``` |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.