rsnext/examples/with-storybook-styled-jsx-scss/components/Button.tsx
Justin Philpott 2a4887c30a
New example: /with-storybook-styled-jsx-scss (#18570)
Hi, 

I'm submitting this PR for consideration as a new example app showing Styled JSX with SCSS working inside and outside storybook with example components.

Only known issue: I noticed that when running this example with:

`$ yarn next ./examples/with-storybook-styled-jsx-scss`

I receive the following error:

```
error - ./pages/_app.js
Error: [BABEL] .../next.js/examples/with-storybook-styled-jsx-scss/pages/_app.js: Cannot find module 'styled-jsx-plugin-sass' (While processing: ".../next.js/node_modules/next/babel.js")
```

However I notice that this same missing module error is triggered when running this existing example app "with-styled-jsx-scss".

Any changes/tweaks needed?

Thanks!
2021-01-04 20:46:34 +00:00

86 lines
1.9 KiB
TypeScript

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>
</>
)
}