Lint storybook sample code

This commit is contained in:
Alex Gleason 2023-02-02 20:23:47 -06:00
parent b6df6149f4
commit 398bfa879e
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
8 changed files with 38 additions and 32 deletions

View File

@ -1,5 +1,5 @@
import React from 'react';
import { ComponentStory, ComponentMeta } from '@storybook/react'; import { ComponentStory, ComponentMeta } from '@storybook/react';
import React from 'react';
import { Button } from './Button'; import { Button } from './Button';

View File

@ -37,7 +37,7 @@ export const Button = ({
const mode = primary ? 'storybook-button--primary' : 'storybook-button--secondary'; const mode = primary ? 'storybook-button--primary' : 'storybook-button--secondary';
return ( return (
<button <button
type="button" type='button'
className={['storybook-button', `storybook-button--${size}`, mode].join(' ')} className={['storybook-button', `storybook-button--${size}`, mode].join(' ')}
style={{ backgroundColor }} style={{ backgroundColor }}
{...props} {...props}

View File

@ -1,5 +1,5 @@
import React from 'react';
import { ComponentStory, ComponentMeta } from '@storybook/react'; import { ComponentStory, ComponentMeta } from '@storybook/react';
import React from 'react';
import { Header } from './Header'; import { Header } from './Header';

View File

@ -16,21 +16,21 @@ interface HeaderProps {
export const Header = ({ user, onLogin, onLogout, onCreateAccount }: HeaderProps) => ( export const Header = ({ user, onLogin, onLogout, onCreateAccount }: HeaderProps) => (
<header> <header>
<div className="wrapper"> <div className='wrapper'>
<div> <div>
<svg width="32" height="32" viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg"> <svg width='32' height='32' viewBox='0 0 32 32' xmlns='http://www.w3.org/2000/svg'>
<g fill="none" fillRule="evenodd"> <g fill='none' fillRule='evenodd'>
<path <path
d="M10 0h12a10 10 0 0110 10v12a10 10 0 01-10 10H10A10 10 0 010 22V10A10 10 0 0110 0z" d='M10 0h12a10 10 0 0110 10v12a10 10 0 01-10 10H10A10 10 0 010 22V10A10 10 0 0110 0z'
fill="#FFF" fill='#FFF'
/> />
<path <path
d="M5.3 10.6l10.4 6v11.1l-10.4-6v-11zm11.4-6.2l9.7 5.5-9.7 5.6V4.4z" 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" fill='#555AB9'
/> />
<path <path
d="M27.2 10.6v11.2l-10.5 6V16.5l10.5-6zM15.7 4.4v11L6 10l9.7-5.5z" d='M27.2 10.6v11.2l-10.5 6V16.5l10.5-6zM15.7 4.4v11L6 10l9.7-5.5z'
fill="#91BAF8" fill='#91BAF8'
/> />
</g> </g>
</svg> </svg>
@ -39,15 +39,15 @@ export const Header = ({ user, onLogin, onLogout, onCreateAccount }: HeaderProps
<div> <div>
{user ? ( {user ? (
<> <>
<span className="welcome"> <span className='welcome'>
Welcome, <b>{user.name}</b>! Welcome, <b>{user.name}</b>!
</span> </span>
<Button size="small" onClick={onLogout} label="Log out" /> <Button size='small' onClick={onLogout} label='Log out' />
</> </>
) : ( ) : (
<> <>
<Button size="small" onClick={onLogin} label="Log in" /> <Button size='small' onClick={onLogin} label='Log in' />
<Button primary size="small" onClick={onCreateAccount} label="Sign up" /> <Button primary size='small' onClick={onCreateAccount} label='Sign up' />
</> </>
)} )}
</div> </div>

View File

@ -1,6 +1,7 @@
import React from 'react';
import { ComponentStory, ComponentMeta } from '@storybook/react'; import { ComponentStory, ComponentMeta } from '@storybook/react';
import { within, userEvent } from '@storybook/testing-library'; import { within, userEvent } from '@storybook/testing-library';
import React from 'react';
import { Page } from './Page'; import { Page } from './Page';
export default { export default {

View File

@ -7,7 +7,7 @@ type User = {
name: string; name: string;
}; };
export const Page: React.VFC = () => { export const Page: React.FC = () => {
const [user, setUser] = React.useState<User>(); const [user, setUser] = React.useState<User>();
return ( return (
@ -23,7 +23,7 @@ export const Page: React.VFC = () => {
<h2>Pages in Storybook</h2> <h2>Pages in Storybook</h2>
<p> <p>
We recommend building UIs with a{' '} We recommend building UIs with a{' '}
<a href="https://componentdriven.org" target="_blank" rel="noopener noreferrer"> <a href='https://componentdriven.org' target='_blank' rel='noopener noreferrer'>
<strong>component-driven</strong> <strong>component-driven</strong>
</a>{' '} </a>{' '}
process starting with atomic components and ending with pages. process starting with atomic components and ending with pages.
@ -45,23 +45,23 @@ export const Page: React.VFC = () => {
</ul> </ul>
<p> <p>
Get a guided tutorial on component-driven development at{' '} Get a guided tutorial on component-driven development at{' '}
<a href="https://storybook.js.org/tutorials/" target="_blank" rel="noopener noreferrer"> <a href='https://storybook.js.org/tutorials/' target='_blank' rel='noopener noreferrer'>
Storybook tutorials Storybook tutorials
</a> </a>
. Read more in the{' '} . Read more in the{' '}
<a href="https://storybook.js.org/docs" target="_blank" rel="noopener noreferrer"> <a href='https://storybook.js.org/docs' target='_blank' rel='noopener noreferrer'>
docs docs
</a> </a>
. .
</p> </p>
<div className="tip-wrapper"> <div className='tip-wrapper'>
<span className="tip">Tip</span> Adjust the width of the canvas with the{' '} <span className='tip'>Tip</span> Adjust the width of the canvas with the{' '}
<svg width="10" height="10" viewBox="0 0 12 12" xmlns="http://www.w3.org/2000/svg"> <svg width='10' height='10' viewBox='0 0 12 12' xmlns='http://www.w3.org/2000/svg'>
<g fill="none" fillRule="evenodd"> <g fill='none' fillRule='evenodd'>
<path <path
d="M1.5 5.2h4.8c.3 0 .5.2.5.4v5.1c-.1.2-.3.3-.4.3H1.4a.5.5 0 01-.5-.4V5.7c0-.3.2-.5.5-.5zm0-2.1h6.9c.3 0 .5.2.5.4v7a.5.5 0 01-1 0V4H1.5a.5.5 0 010-1zm0-2.1h9c.3 0 .5.2.5.4v9.1a.5.5 0 01-1 0V2H1.5a.5.5 0 010-1zm4.3 5.2H2V10h3.8V6.2z" d='M1.5 5.2h4.8c.3 0 .5.2.5.4v5.1c-.1.2-.3.3-.4.3H1.4a.5.5 0 01-.5-.4V5.7c0-.3.2-.5.5-.5zm0-2.1h6.9c.3 0 .5.2.5.4v7a.5.5 0 01-1 0V4H1.5a.5.5 0 010-1zm0-2.1h9c.3 0 .5.2.5.4v9.1a.5.5 0 01-1 0V2H1.5a.5.5 0 010-1zm4.3 5.2H2V10h3.8V6.2z'
id="a" id='a'
fill="#999" fill='#999'
/> />
</g> </g>
</svg> </svg>

View File

@ -7,23 +7,28 @@
display: inline-block; display: inline-block;
line-height: 1; line-height: 1;
} }
.storybook-button--primary { .storybook-button--primary {
color: white; color: white;
background-color: #1ea7fd; background-color: #1ea7fd;
} }
.storybook-button--secondary { .storybook-button--secondary {
color: #333; color: #333;
background-color: transparent; background-color: transparent;
box-shadow: rgba(0, 0, 0, 0.15) 0px 0px 0px 1px inset; box-shadow: rgba(0, 0, 0, 0.15) 0px 0px 0px 1px inset;
} }
.storybook-button--small { .storybook-button--small {
font-size: 12px; font-size: 12px;
padding: 10px 16px; padding: 10px 16px;
} }
.storybook-button--medium { .storybook-button--medium {
font-size: 14px; font-size: 14px;
padding: 11px 20px; padding: 11px 20px;
} }
.storybook-button--large { .storybook-button--large {
font-size: 16px; font-size: 16px;
padding: 12px 24px; padding: 12px 24px;