Skip to content
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

Docs: use the nextv12 example from the storybook-addon-next repo as the with-storybook example #33891

Merged
merged 3 commits into from
Feb 6, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions examples/with-storybook/.babelrc

This file was deleted.

4 changes: 2 additions & 2 deletions examples/with-storybook/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ yarn-error.log*
# vercel
.vercel

# Storybook
/storybook-static
# storybook
storybook-static
15 changes: 13 additions & 2 deletions examples/with-storybook/.storybook/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
module.exports = {
stories: ['../stories/*.stories.@(ts|tsx|js|jsx|mdx)'],
addons: ['@storybook/addon-links', '@storybook/addon-essentials'],
stories: [
'../stories/**/*.stories.mdx',
'../stories/**/*.stories.@(js|jsx|ts|tsx)',
],
addons: [
'@storybook/addon-links',
'@storybook/addon-essentials',
'storybook-addon-next',
],
framework: '@storybook/react',
core: {
builder: 'webpack5',
},
}
25 changes: 13 additions & 12 deletions examples/with-storybook/.storybook/preview.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
export const parameters = {
options: {
storySort: (a, b) => {
// We want the Welcome story at the top
if (b[1].kind === 'Welcome') {
return 1
}
import '../styles/globals.css'
import '../styles/globals.scss'

// 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 })
export const parameters = {
actions: { argTypesRegex: '^on[A-Z].*' },
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/,
},
},
nextRouter: {
query: {
foo: 'this-is-a-global-override',
},
},
}
2 changes: 1 addition & 1 deletion examples/with-storybook/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Example app with Storybook

This example shows a default set up of Storybook. Also included in the example is a custom component included in both Storybook and the Next.js application.
This example shows a default set up of Storybook using [storybook-addon-next](https://github.com/RyanClementsHax/storybook-addon-next). Included in this example are stories that demonstrate the ability to use Next.js features in Storybook.
leerob marked this conversation as resolved.
Show resolved Hide resolved

### TypeScript

Expand Down
33 changes: 33 additions & 0 deletions examples/with-storybook/components/Links.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import Link from 'next/link'

export const Links = () => (
<ul>
<li>
<Link href="/">Home</Link>
</li>
<li>
<Link href="/nextjsRouting">Next.js Routing Example</Link>
</li>
<li>
<Link href="/nextjsImages">Next.js Images Example</Link>
</li>
<li>
<Link href="/globalStyleImports">Global Style Imports Example</Link>
</li>
<li>
<Link href="/cssModules">Css Module Example</Link>
</li>
<li>
<Link href="/scssModules">Scss Module Example</Link>
</li>
<li>
<Link href="/styledJsx">Styled JSX Example</Link>
</li>
<li>
<Link href="/absoluteImports">Absolute Import Example</Link>
</li>
<li>
<Link href="/typescript">Typescript Example</Link>
</li>
</ul>
)
2 changes: 2 additions & 0 deletions examples/with-storybook/components/MyComponent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/** @type {import('react').FC} */
export const MyComponent = ({ children }) => <div>{children}</div>
3 changes: 0 additions & 3 deletions examples/with-storybook/components/index.js

This file was deleted.

5 changes: 5 additions & 0 deletions examples/with-storybook/next-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
3 changes: 3 additions & 0 deletions examples/with-storybook/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
reactStrictMode: true,
}
25 changes: 16 additions & 9 deletions examples/with-storybook/package.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
{
"private": true,
"scripts": {
"dev": "next",
"dev": "next dev",
"build": "next build",
"start": "next start",
"storybook": "start-storybook -p 6006",
"build-storybook": "build-storybook -s public/",
"storybook": "start-storybook -p 6006 -s public",
"build-storybook": "build-storybook -s public",
"serve-storybook": "serve storybook-static"
},
"dependencies": {
"next": "latest",
"react": "^17.0.2",
"react-dom": "^17.0.2"
"react-dom": "^17.0.2",
"sass": "^1.49.0"
},
"devDependencies": {
"@storybook/addon-essentials": "6.0.26",
"@storybook/addon-links": "6.0.26",
"@storybook/react": "6.0.26",
"babel-loader": "^8.0.5",
"serve": "11.3.2"
"@babel/core": "^7.16.7",
"@storybook/addon-actions": "^6.4.9",
"@storybook/addon-essentials": "^6.4.9",
"@storybook/addon-links": "^6.4.9",
"@storybook/builder-webpack5": "^6.4.9",
"@storybook/manager-webpack5": "^6.4.9",
"@storybook/react": "^6.4.9",
"babel-loader": "^8.2.3",
"serve": "13.0.2",
"storybook-addon-next": "1.3.1",
"typescript": "4.5.5"
}
}
9 changes: 9 additions & 0 deletions examples/with-storybook/pages/_app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import '../styles/globals.css'
import '../styles/globals.scss'

/** @param {import('next/app').AppProps} props */
function MyApp({ Component, pageProps }) {
return <Component {...pageProps} />
}

export default MyApp
19 changes: 19 additions & 0 deletions examples/with-storybook/pages/absoluteImports.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Links } from 'components/Links'
import { MyComponent } from 'components/MyComponent'
import Head from 'next/head'

export default function AbsoluteImports() {
return (
<div>
<Head>
<title>Absolute Imports</title>
<link rel="icon" href="/favicon.ico" />
</Head>
<Links />
<main>
This uses an absolute import:{' '}
<MyComponent>Im absolutely imported</MyComponent>
</main>
</div>
)
}
18 changes: 18 additions & 0 deletions examples/with-storybook/pages/cssModules.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Links } from 'components/Links'
import Head from 'next/head'
import styles from '../styles/CssModules.module.css'

export default function CssModules() {
return (
<div>
<Head>
<title>CSS Modules</title>
<link rel="icon" href="/favicon.ico" />
</Head>
<Links />
<main className={styles.main}>
<span>This is styled using CSS Modules</span>
</main>
</div>
)
}
19 changes: 19 additions & 0 deletions examples/with-storybook/pages/globalStyleImports.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Links } from 'components/Links'
import Head from 'next/head'

export default function CssModules() {
return (
<div>
<Head>
<title>Global style imports</title>
<link rel="icon" href="/favicon.ico" />
</Head>
<Links />
<main>
The background of this page is set by "styles/globals.scss" and this
text size is set by "styles/globals.css". All global style imports need
to be done in ".storybook/preview.js" for storybook.
</main>
</div>
)
}
16 changes: 13 additions & 3 deletions examples/with-storybook/pages/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
import HelloWorld from '../components'
import { Links } from 'components/Links'
import Head from 'next/head'

export default function Home() {
return (
<div>
<h1>Simple Storybook Example</h1>
<HelloWorld />
<Head>
<title>Storybook with Next</title>
<meta name="description" content="Generated by create next app" />
<link rel="icon" href="/favicon.ico" />
</Head>
<main>
<h1>
Click on any one of these links to see supported features in action
</h1>
<Links />
</main>
</div>
)
}
29 changes: 29 additions & 0 deletions examples/with-storybook/pages/nextjsImages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Links } from 'components/Links'
import Image from 'next/image'
import Head from 'next/head'
import nyanCatImgSrc from 'public/nyan-cat.png'

export default function NextjsImages() {
return (
<div>
<Head>
<title>Nextjs Images</title>
<link rel="icon" href="/favicon.ico" />
</Head>
<Links />
<main>
<h2>This image uses a remote image</h2>
<Image src="/vercel.svg" alt="Vercel Logo" width={200} height={200} />
<h2>This image uses a static import with a "placeholder="blur"</h2>
<Image
src={nyanCatImgSrc}
layout="responsive"
objectFit="cover"
objectPosition="center"
placeholder="blur"
alt="Nyan Cat"
/>
</main>
</div>
)
}
30 changes: 30 additions & 0 deletions examples/with-storybook/pages/nextjsRouting.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Links } from 'components/Links'
import Head from 'next/head'
import { useRouter } from 'next/router'

export default function NextjsRouting() {
const router = useRouter()
console.log('this is the router NextjsRouting received 👉', router)
return (
<div>
<Head>
<title>Nextjs Routing</title>
<link rel="icon" href="/favicon.ico" />
</Head>
<Links />
<main>
<p>
Interact with any of the links and look at the "Actions" tab below (if
in storybook)
</p>
<p>
This is the router read by this page (functions not serialized; check
the console for the full object):
</p>
<pre>
<code>{JSON.stringify(router, null, 2)}</code>
</pre>
</main>
</div>
)
}
18 changes: 18 additions & 0 deletions examples/with-storybook/pages/scssModules.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Links } from 'components/Links'
import Head from 'next/head'
import styles from '../styles/ScssModules.module.scss'

export default function ScssModules() {
return (
<div>
<Head>
<title>SCSS Modules</title>
<link rel="icon" href="/favicon.ico" />
</Head>
<Links />
<main className={styles.main}>
<span>This is styled using SCSS Modules</span>
</main>
</div>
)
}
31 changes: 31 additions & 0 deletions examples/with-storybook/pages/styledJsx.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Links } from 'components/Links'
import Head from 'next/head'

export default function StyledJsx() {
return (
<div>
<Head>
<title>Styled JSX</title>
<link rel="icon" href="/favicon.ico" />
</Head>
<Links />
<style jsx>{`
.main {
padding: 4rem 0;
flex: 1;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}

.main span {
color: blue;
}
`}</style>
<main className="main">
<span>This is styled using Styled JSX</span>
</main>
</div>
)
}
15 changes: 15 additions & 0 deletions examples/with-storybook/pages/typescript.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Links } from 'components/Links'
import Head from 'next/head'

export default function Typescript() {
return (
<div>
<Head>
<title>Typescript</title>
<link rel="icon" href="/favicon.ico" />
</Head>
<Links />
<main>This is a page using typescript</main>
</div>
)
}
Binary file added examples/with-storybook/public/favicon.ico
Binary file not shown.
Binary file added examples/with-storybook/public/nyan-cat.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion examples/with-storybook/public/serve.json

This file was deleted.

4 changes: 4 additions & 0 deletions examples/with-storybook/public/vercel.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading