-
Notifications
You must be signed in to change notification settings - Fork 27k
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
New example: /with-storybook-styled-jsx-scss #18570
Merged
kodiakhq
merged 35 commits into
vercel:canary
from
justinphilpott:with-storybook-styled-jsx-scss
Jan 4, 2021
Merged
Changes from 18 commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
d2330b4
Merge pull request #1 from vercel/canary
justinphilpott f98e593
Add with-storybook-styled-jsx-scss example app
justinphilpott 1d0f727
Add in missing newlines
justinphilpott ac876fe
Another missing newline
justinphilpott 25df573
Fix incorrect link in README
justinphilpott 188eb85
Add newlines to eof for .svg files
justinphilpott fcdd297
Merge branch 'canary' into with-storybook-styled-jsx-scss
justinphilpott 76f61b6
Merge branch 'canary' into with-storybook-styled-jsx-scss
justinphilpott 992c4ff
Merge branch 'canary' into with-storybook-styled-jsx-scss
justinphilpott 547aad3
Merge branch 'canary' into with-storybook-styled-jsx-scss
justinphilpott 20b5d3d
Merge branch 'canary' into with-storybook-styled-jsx-scss
justinphilpott 7e4ccea
Merge branch 'canary' into with-storybook-styled-jsx-scss
justinphilpott 340a4d8
Merge branch 'canary' into with-storybook-styled-jsx-scss
justinphilpott d9eb78c
Merge branch 'canary' into with-storybook-styled-jsx-scss
justinphilpott e6aea71
Merge branch 'canary' into with-storybook-styled-jsx-scss
justinphilpott e7092c8
Merge branch 'canary' into with-storybook-styled-jsx-scss
justinphilpott 26619d8
Merge branch 'canary' into with-storybook-styled-jsx-scss
justinphilpott d5d8d6d
Merge branch 'canary' into with-storybook-styled-jsx-scss
justinphilpott 1700025
Updated with-storybook readme
lfades e9debaa
Updated gitignore
lfades 3e35819
Updated readme to mention Storybook steps
lfades 73b27b2
Moved _app.js to TS
lfades 8b1c463
Merge branch 'with-storybook-styled-jsx-scss' of https://github.com/j…
lfades 047b29a
Remove .babelrc
lfades a36cab1
Update storybook and remove unwanted tsconf includes
justinphilpott 6994635
Merge branch 'canary' into with-storybook-styled-jsx-scss
justinphilpott 1c014c9
Update description in page.tsx
justinphilpott 2e5c292
Merge branch 'with-storybook-styled-jsx-scss' of github.com:justinphi…
justinphilpott cf28825
Merge branch 'canary' into with-storybook-styled-jsx-scss
justinphilpott a3f8a79
Merge branch 'canary' into with-storybook-styled-jsx-scss
justinphilpott 2af3813
Merge branch 'canary' into with-storybook-styled-jsx-scss
justinphilpott f2fd813
Merge branch 'canary' into with-storybook-styled-jsx-scss
justinphilpott 59dd23d
Merge branch 'canary' into with-storybook-styled-jsx-scss
justinphilpott 42a26cd
Merge branch 'canary' into with-storybook-styled-jsx-scss
justinphilpott a6df557
Merge branch 'canary' into with-storybook-styled-jsx-scss
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,12 @@ | ||
{ | ||
"presets": [ | ||
[ | ||
"next/babel", | ||
{ | ||
"styled-jsx": { | ||
"plugins": ["styled-jsx-plugin-sass"] | ||
} | ||
} | ||
] | ||
] | ||
} |
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,34 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
/.pnp | ||
.pnp.js | ||
|
||
# testing | ||
/coverage | ||
|
||
# next.js | ||
/.next/ | ||
/out/ | ||
|
||
# production | ||
/build | ||
|
||
# misc | ||
.DS_Store | ||
*.pem | ||
|
||
# debug | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# local env files | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
|
||
# vercel | ||
.vercel |
12 changes: 12 additions & 0 deletions
12
examples/with-storybook-styled-jsx-scss/.storybook/.babelrc
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,12 @@ | ||
{ | ||
"presets": [ | ||
[ | ||
"next/babel", | ||
{ | ||
"styled-jsx": { | ||
"plugins": ["styled-jsx-plugin-sass"] | ||
} | ||
} | ||
] | ||
] | ||
} | ||
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 @@ | ||
module.exports = { | ||
stories: [ | ||
'../stories/**/*.stories.mdx', | ||
'../stories/**/*.stories.@(js|jsx|ts|tsx)', | ||
], | ||
addons: ['@storybook/addon-links', '@storybook/addon-essentials'], | ||
} |
3 changes: 3 additions & 0 deletions
3
examples/with-storybook-styled-jsx-scss/.storybook/preview.js
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 @@ | ||
export const parameters = { | ||
actions: { argTypesRegex: '^on[A-Z].*' }, | ||
} |
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,29 @@ | ||
# Example app with Storybook setup for SCSS in Styled-jsx | ||
|
||
This example shows Styled-jsx (with SCSS) working for components written in TypeScript rendered both inside and outside of Storybook. | ||
|
||
## Deploy your own | ||
|
||
Deploy the example using [Vercel](https://vercel.com/now): | ||
|
||
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/import/project?template=https://github.com/vercel/next.js/tree/canary/examples/with-storybook-styled-jsx-scss) | ||
|
||
## How to use | ||
|
||
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-styled-jsx-scss with-storybook-styled-jsx-scss-app | ||
# or | ||
yarn create next-app --example with-storybook-styled-jsx-scss with-storybook-styled-jsx-scss-app | ||
``` | ||
|
||
Deploy it to the cloud with [Vercel](https://vercel.com/import?filter=next.js&utm_source=github&utm_medium=readme&utm_campaign=next-example) ([Documentation](https://nextjs.org/docs/deployment)). | ||
|
||
## Notes | ||
|
||
This example combines the following examples, with some required extra config added: | ||
|
||
- [with-storybook](https://github.com/vercel/next.js/tree/canary/examples/with-storybook) | ||
- [with-styled-jsx-scss](https://github.com/vercel/next.js/tree/canary/examples/with-styled-jsx-scss) | ||
- [with-typescript](https://github.com/vercel/next.js/tree/canary/examples/with-typescript) |
86 changes: 86 additions & 0 deletions
86
examples/with-storybook-styled-jsx-scss/components/Button.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,86 @@ | ||
import React from 'react' | ||
|
||
export interface ButtonProps { | ||
/** | ||
* Is this the principal call to action on the page? | ||
*/ | ||
primary?: boolean | ||
/** | ||
* What background color to use | ||
*/ | ||
backgroundColor?: string | ||
/** | ||
* How large should the button be? | ||
*/ | ||
size?: 'small' | 'medium' | 'large' | ||
/** | ||
* Button contents | ||
*/ | ||
label: string | ||
/** | ||
* Optional click handler | ||
*/ | ||
onClick?: () => void | ||
} | ||
|
||
/** | ||
* Primary UI component for user interaction | ||
*/ | ||
export const Button: React.FC<ButtonProps> = ({ | ||
primary = false, | ||
size = 'medium', | ||
backgroundColor, | ||
label, | ||
...props | ||
}) => { | ||
const mode = primary | ||
? 'storybook-button--primary' | ||
: 'storybook-button--secondary' | ||
return ( | ||
<> | ||
<button | ||
type="button" | ||
className={['storybook-button', `storybook-button--${size}`, mode].join( | ||
' ' | ||
)} | ||
style={{ backgroundColor }} | ||
{...props} | ||
> | ||
{label} | ||
</button> | ||
<style jsx>{` | ||
.storybook-button { | ||
font-family: 'Nunito Sans', 'Helvetica Neue', Helvetica, Arial, | ||
sans-serif; | ||
font-weight: 700; | ||
border: 0; | ||
border-radius: 3em; | ||
cursor: pointer; | ||
display: inline-block; | ||
line-height: 1; | ||
} | ||
.storybook-button--primary { | ||
color: white; | ||
background-color: #1ea7fd; | ||
} | ||
.storybook-button--secondary { | ||
color: #333; | ||
background-color: transparent; | ||
box-shadow: rgba(0, 0, 0, 0.15) 0px 0px 0px 1px inset; | ||
} | ||
.storybook-button--small { | ||
font-size: 12px; | ||
padding: 10px 16px; | ||
} | ||
.storybook-button--medium { | ||
font-size: 14px; | ||
padding: 11px 20px; | ||
} | ||
.storybook-button--large { | ||
font-size: 16px; | ||
padding: 12px 24px; | ||
} | ||
`}</style> | ||
</> | ||
) | ||
} |
89 changes: 89 additions & 0 deletions
89
examples/with-storybook-styled-jsx-scss/components/Header.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,89 @@ | ||
import React from 'react' | ||
|
||
import { Button } from './Button' | ||
|
||
export interface HeaderProps { | ||
user?: {} | ||
onLogin: () => void | ||
onLogout: () => void | ||
onCreateAccount: () => void | ||
} | ||
|
||
export const Header: React.FC<HeaderProps> = ({ | ||
user, | ||
onLogin, | ||
onLogout, | ||
onCreateAccount, | ||
}) => ( | ||
<> | ||
<header> | ||
<div className="wrapper"> | ||
<div> | ||
<svg | ||
width="32" | ||
height="32" | ||
viewBox="0 0 32 32" | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<g fill="none" fillRule="evenodd"> | ||
<path | ||
d="M10 0h12a10 10 0 0110 10v12a10 10 0 01-10 10H10A10 10 0 010 22V10A10 10 0 0110 0z" | ||
fill="#FFF" | ||
/> | ||
<path | ||
d="M5.3 10.6l10.4 6v11.1l-10.4-6v-11zm11.4-6.2l9.7 5.5-9.7 5.6V4.4z" | ||
fill="#555AB9" | ||
/> | ||
<path | ||
d="M27.2 10.6v11.2l-10.5 6V16.5l10.5-6zM15.7 4.4v11L6 10l9.7-5.5z" | ||
fill="#91BAF8" | ||
/> | ||
</g> | ||
</svg> | ||
<h1>Acme</h1> | ||
</div> | ||
<div> | ||
{user ? ( | ||
<Button size="small" onClick={onLogout} label="Log out" /> | ||
) : ( | ||
<> | ||
<Button size="small" onClick={onLogin} label="Log in" /> | ||
<Button | ||
primary | ||
size="small" | ||
onClick={onCreateAccount} | ||
label="Sign up" | ||
/> | ||
</> | ||
)} | ||
</div> | ||
</div> | ||
</header> | ||
<style jsx>{` | ||
.wrapper { | ||
font-family: 'Nunito Sans', 'Helvetica Neue', Helvetica, Arial, | ||
sans-serif; | ||
border-bottom: 1px solid rgba(0, 0, 0, 0.1); | ||
padding: 15px 20px; | ||
display: flex; | ||
align-items: center; | ||
justify-content: space-between; | ||
} | ||
svg { | ||
display: inline-block; | ||
vertical-align: top; | ||
} | ||
h1 { | ||
font-weight: 900; | ||
font-size: 20px; | ||
line-height: 1; | ||
margin: 6px 0 6px 10px; | ||
display: inline-block; | ||
vertical-align: top; | ||
} | ||
button + button { | ||
margin-left: 10px; | ||
} | ||
`}</style> | ||
</> | ||
) |
Oops, something went wrong.
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.
Can we remove this file? our current storybook example doesn't seem to need one 🤔
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.
this is necessary to be able to style the actual components inside storybook with styled-jsx and sass
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.
otherwise they won't style...
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.
I mean, this is the same
.babelrc
in the root folder, do we need it twice?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.
Yea, I don't yet know how to get Storybook to use the default .babelrc file, perhaps there is a way
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.
I removed the file and it worked, can you try it again by removing the file and see if it works for you too? 🙏
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.
I've removed this file as everything seems to be working fine without it 🤔
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.
this is odd, but preferable!!! I have checked and it works...