-
Notifications
You must be signed in to change notification settings - Fork 27.2k
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
Add [with-storybook-typescript] example #14398
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c84d7c8
create example/with-storybook-typescript directory
zxzl 7157251
Use typescript for next.js components
zxzl 9e7eda5
bump @storybook/* versions to 5.3.19
zxzl 77b0341
Add typescript config for storybook
zxzl a2a3566
update README.md
zxzl ed5af0e
Fix lint error
zxzl 9680cd5
Merge branch 'canary' into with-storybook-typescript
kodiakhq[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import '@storybook/addon-actions/register' | ||
import '@storybook/addon-links/register' |
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,25 @@ | ||
import { configure, addParameters } from '@storybook/react' | ||
|
||
addParameters({ | ||
options: { | ||
storySort: (a, b) => { | ||
// We want the Welcome story at the top | ||
if (a[1].kind === 'Welcome') { | ||
return -1 | ||
} | ||
|
||
// Sort the other stories by ID | ||
// https://github.com/storybookjs/storybook/issues/548#issuecomment-530305279 | ||
return a[1].kind === b[1].kind | ||
? 0 | ||
: a[1].id.localeCompare(b[1].id, { numeric: true }) | ||
}, | ||
}, | ||
}) | ||
|
||
// automatically import all files ending in *.stories.(ts|tsx) | ||
const req = require.context('../stories', true, /.stories.tsx?$/) | ||
|
||
// the first argument can be an array too, so if you want to load from different locations or | ||
// different extensions, you can do it like this: configure([req1, req2], module) | ||
configure(req, module) |
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,3 @@ | ||
module.exports = { | ||
addons: ['@storybook/preset-typescript'], | ||
} |
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,52 @@ | ||
# Example app with Storybook and TypeScript. | ||
|
||
This example shows a default set up of Storybook plus TypeScript, using [@storybook/preset-typescript](https://github.com/storybookjs/presets/tree/master/packages/preset-typescript). Also included in the example is a custom component included in both Storybook and the Next.js application. | ||
|
||
## How to use | ||
|
||
### Using `create-next-app` | ||
|
||
Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init) or [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) to bootstrap the example: | ||
|
||
```bash | ||
npx create-next-app --example with-storybook-typescript with-storybook-app | ||
# or | ||
yarn create next-app --example with-storybook-typescript with-storybook-app | ||
``` | ||
|
||
### Download manually | ||
|
||
Download the example: | ||
|
||
```bash | ||
curl https://codeload.github.com/vercel/next.js/tar.gz/canary | tar -xz --strip=2 next.js-canary/examples/with-storybook-typescript | ||
cd with-storybook-typescript | ||
``` | ||
|
||
Install it and run: | ||
|
||
```bash | ||
npm install | ||
npm run dev | ||
# or | ||
yarn | ||
yarn dev | ||
``` | ||
|
||
## Run Storybook | ||
|
||
```bash | ||
npm run storybook | ||
# or | ||
yarn storybook | ||
``` | ||
|
||
## Build Static Storybook | ||
|
||
```bash | ||
npm run build-storybook | ||
# or | ||
yarn build-storybook | ||
``` | ||
|
||
You can use [Vercel](https://vercel.com/import?filter=next.js&utm_source=github&utm_medium=readme&utm_campaign=next-example) to deploy Storybook. Specify `storybook-static` as the output directory. |
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 @@ | ||
import React from 'react' | ||
export default function Home() { | ||
return <div>Hello World</div> | ||
} |
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,2 @@ | ||
/// <reference types="next" /> | ||
/// <reference types="next/types/global" /> |
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,31 @@ | ||
{ | ||
"name": "with-storybook", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"scripts": { | ||
"dev": "next", | ||
"build": "next build", | ||
"start": "next start", | ||
"storybook": "start-storybook -p 6006", | ||
"build-storybook": "build-storybook" | ||
}, | ||
"dependencies": { | ||
"next": "latest", | ||
"react": "^16.7.0", | ||
"react-dom": "^16.7.0" | ||
}, | ||
"license": "ISC", | ||
"devDependencies": { | ||
"@storybook/addon-actions": "5.3.19", | ||
"@storybook/addon-links": "5.3.19", | ||
"@storybook/addons": "5.3.19", | ||
"@storybook/preset-typescript": "3.0.0", | ||
"@storybook/react": "5.3.19", | ||
"@types/node": "14.0.13", | ||
"@types/react": "16.9.38", | ||
"babel-loader": "^8.0.5", | ||
"fork-ts-checker-webpack-plugin": "5.0.4", | ||
"ts-loader": "7.0.5", | ||
"typescript": "3.9.5" | ||
} | ||
} |
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,10 @@ | ||
import HelloWorld from '../components' | ||
|
||
export default function Home() { | ||
return ( | ||
<div> | ||
<h1>Simple Storybook Example</h1> | ||
<HelloWorld /> | ||
</div> | ||
) | ||
} |
17 changes: 17 additions & 0 deletions
17
examples/with-storybook-typescript/stories/button.stories.tsx
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,17 @@ | ||
import React from 'react' | ||
import { action } from '@storybook/addon-actions' | ||
import { Button } from '@storybook/react/demo' | ||
|
||
export default { title: 'Button' } | ||
|
||
export const withText = () => ( | ||
<Button onClick={action('clicked')}>Hello Button</Button> | ||
) | ||
|
||
export const withSomeEmoji = () => ( | ||
<Button onClick={action('clicked')}> | ||
<span role="img" aria-label="so cool"> | ||
😀 😎 👍 💯 | ||
</span> | ||
</Button> | ||
) |
6 changes: 6 additions & 0 deletions
6
examples/with-storybook-typescript/stories/helloWorld.stories.tsx
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,6 @@ | ||
import React from 'react' | ||
import HelloWorld from '../components' | ||
|
||
export default { title: 'Hello World' } | ||
|
||
export const simpleComponent = () => <HelloWorld /> |
7 changes: 7 additions & 0 deletions
7
examples/with-storybook-typescript/stories/welcome.stories.tsx
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,7 @@ | ||
import React from 'react' | ||
import { linkTo } from '@storybook/addon-links' | ||
import { Welcome } from '@storybook/react/demo' | ||
|
||
export default { title: 'Welcome' } | ||
|
||
export const toStorybook = () => <Welcome showApp={linkTo('Button')} /> |
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,19 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es5", | ||
"lib": ["dom", "dom.iterable", "esnext"], | ||
"allowJs": true, | ||
"skipLibCheck": true, | ||
"strict": false, | ||
"forceConsistentCasingInFileNames": true, | ||
"noEmit": true, | ||
"esModuleInterop": true, | ||
"module": "esnext", | ||
"moduleResolution": "node", | ||
"resolveJsonModule": true, | ||
"isolatedModules": true, | ||
"jsx": "preserve" | ||
}, | ||
"exclude": ["node_modules"], | ||
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"] | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are these 2 packages added?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was required by @storybook/preset-typescript (https://github.com/storybookjs/presets/tree/master/packages/preset-typescript#installation)