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

New example: /with-storybook-styled-jsx-scss #18570

Merged
merged 35 commits into from
Jan 4, 2021
Merged
Show file tree
Hide file tree
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 Oct 31, 2020
f98e593
Add with-storybook-styled-jsx-scss example app
justinphilpott Oct 31, 2020
1d0f727
Add in missing newlines
justinphilpott Oct 31, 2020
ac876fe
Another missing newline
justinphilpott Oct 31, 2020
25df573
Fix incorrect link in README
justinphilpott Oct 31, 2020
188eb85
Add newlines to eof for .svg files
justinphilpott Nov 4, 2020
fcdd297
Merge branch 'canary' into with-storybook-styled-jsx-scss
justinphilpott Nov 4, 2020
76f61b6
Merge branch 'canary' into with-storybook-styled-jsx-scss
justinphilpott Nov 4, 2020
992c4ff
Merge branch 'canary' into with-storybook-styled-jsx-scss
justinphilpott Nov 5, 2020
547aad3
Merge branch 'canary' into with-storybook-styled-jsx-scss
justinphilpott Nov 6, 2020
20b5d3d
Merge branch 'canary' into with-storybook-styled-jsx-scss
justinphilpott Nov 8, 2020
7e4ccea
Merge branch 'canary' into with-storybook-styled-jsx-scss
justinphilpott Nov 12, 2020
340a4d8
Merge branch 'canary' into with-storybook-styled-jsx-scss
justinphilpott Nov 14, 2020
d9eb78c
Merge branch 'canary' into with-storybook-styled-jsx-scss
justinphilpott Nov 24, 2020
e6aea71
Merge branch 'canary' into with-storybook-styled-jsx-scss
justinphilpott Nov 24, 2020
e7092c8
Merge branch 'canary' into with-storybook-styled-jsx-scss
justinphilpott Nov 26, 2020
26619d8
Merge branch 'canary' into with-storybook-styled-jsx-scss
justinphilpott Nov 28, 2020
d5d8d6d
Merge branch 'canary' into with-storybook-styled-jsx-scss
justinphilpott Dec 11, 2020
1700025
Updated with-storybook readme
lfades Dec 11, 2020
e9debaa
Updated gitignore
lfades Dec 11, 2020
3e35819
Updated readme to mention Storybook steps
lfades Dec 11, 2020
73b27b2
Moved _app.js to TS
lfades Dec 11, 2020
8b1c463
Merge branch 'with-storybook-styled-jsx-scss' of https://github.com/j…
lfades Dec 11, 2020
047b29a
Remove .babelrc
lfades Dec 11, 2020
a36cab1
Update storybook and remove unwanted tsconf includes
justinphilpott Dec 12, 2020
6994635
Merge branch 'canary' into with-storybook-styled-jsx-scss
justinphilpott Dec 12, 2020
1c014c9
Update description in page.tsx
justinphilpott Dec 15, 2020
2e5c292
Merge branch 'with-storybook-styled-jsx-scss' of github.com:justinphi…
justinphilpott Dec 15, 2020
cf28825
Merge branch 'canary' into with-storybook-styled-jsx-scss
justinphilpott Dec 15, 2020
a3f8a79
Merge branch 'canary' into with-storybook-styled-jsx-scss
justinphilpott Dec 23, 2020
2af3813
Merge branch 'canary' into with-storybook-styled-jsx-scss
justinphilpott Dec 31, 2020
f2fd813
Merge branch 'canary' into with-storybook-styled-jsx-scss
justinphilpott Jan 2, 2021
59dd23d
Merge branch 'canary' into with-storybook-styled-jsx-scss
justinphilpott Jan 4, 2021
42a26cd
Merge branch 'canary' into with-storybook-styled-jsx-scss
justinphilpott Jan 4, 2021
a6df557
Merge branch 'canary' into with-storybook-styled-jsx-scss
kodiakhq[bot] Jan 4, 2021
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
12 changes: 12 additions & 0 deletions examples/with-storybook-styled-jsx-scss/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"presets": [
[
"next/babel",
{
"styled-jsx": {
"plugins": ["styled-jsx-plugin-sass"]
}
}
]
]
}
34 changes: 34 additions & 0 deletions examples/with-storybook-styled-jsx-scss/.gitignore
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 examples/with-storybook-styled-jsx-scss/.storybook/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"presets": [
[
"next/babel",
{
"styled-jsx": {
"plugins": ["styled-jsx-plugin-sass"]
}
}
]
]
}
Copy link
Member

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 🤔

Copy link
Contributor Author

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

Copy link
Contributor Author

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...

Copy link
Member

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?

Copy link
Contributor Author

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

Copy link
Member

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? 🙏

Copy link
Member

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 🤔

Copy link
Contributor Author

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...

7 changes: 7 additions & 0 deletions examples/with-storybook-styled-jsx-scss/.storybook/main.js
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 examples/with-storybook-styled-jsx-scss/.storybook/preview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const parameters = {
actions: { argTypesRegex: '^on[A-Z].*' },
}
29 changes: 29 additions & 0 deletions examples/with-storybook-styled-jsx-scss/README.md
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 examples/with-storybook-styled-jsx-scss/components/Button.tsx
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 examples/with-storybook-styled-jsx-scss/components/Header.tsx
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>
</>
)
Loading