Skip to content

Commit

Permalink
Merge pull request #164 from storybookjs/update-stories [skip ci]
Browse files Browse the repository at this point in the history
Update stories
  • Loading branch information
yannbf authored Aug 18, 2022
2 parents ceb3d49 + 54513b8 commit 7aa853e
Show file tree
Hide file tree
Showing 13 changed files with 138 additions and 110 deletions.
Binary file modified __snapshots__/pages-page--logged-in-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified __snapshots__/pages-page--logged-out-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
7 changes: 6 additions & 1 deletion stories/molecules/Header.js → stories/molecules/Header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ export const Header = ({ user, onLogin, onLogout, onCreateAccount }) => (
</div>
<div>
{user ? (
<Button size="small" onClick={onLogout} label="Log out" />
<>
<span className="welcome">
Welcome, <b>{user.name}</b>!
</span>
<Button size="small" onClick={onLogout} label="Log out" />
</>
) : (
<>
<Button size="small" onClick={onLogin} label="Log in" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ import { Header } from './Header';

export default {
component: Header,
play: async () => {},
parameters: {
layout: 'fullscreen',
},
};

const Template = (args) => <Header {...args} />;

export const LoggedIn = Template.bind({});
LoggedIn.args = {
user: {},
user: {
name: 'Jane Doe',
},
};

export const LoggedOut = Template.bind({});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ exports[`Molecules/Header LoggedIn smoke-test 2`] = `
</h1>
</div>
<div>
<span class="welcome">
Welcome,
<b>
Jane Doe
</b>
!
</span>
<button type="button"
class="storybook-button storybook-button--small storybook-button--secondary"
>
Expand Down
6 changes: 6 additions & 0 deletions stories/molecules/header.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,9 @@ h1 {
button + button {
margin-left: 10px;
}

.welcome {
color: #333;
font-size: 14px;
margin-right: 10px;
}
71 changes: 0 additions & 71 deletions stories/pages/Page.js

This file was deleted.

69 changes: 69 additions & 0 deletions stories/pages/Page.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import React from 'react';

import { Header } from '../molecules/Header';
import './page.css';

export const Page = () => {
const [user, setUser] = React.useState();

return (
<article>
<Header
user={user}
onLogin={() => setUser({ name: 'Jane Doe' })}
onLogout={() => setUser(undefined)}
onCreateAccount={() => setUser({ name: 'Jane Doe' })}
/>

<section>
<h2>Pages in Storybook</h2>
<p>
We recommend building UIs with a{' '}
<a href="https://componentdriven.org" target="_blank" rel="noopener noreferrer">
<strong>component-driven</strong>
</a>{' '}
process starting with atomic components and ending with pages.
</p>
<p>
Render pages with mock data. This makes it easy to build and review page states without
needing to navigate to them in your app. Here are some handy patterns for managing page
data in Storybook:
</p>
<ul>
<li>
Use a higher-level connected component. Storybook helps you compose such data from the
"args" of child component stories
</li>
<li>
Assemble data in the page component from your services. You can mock these services out
using Storybook.
</li>
</ul>
<p>
Get a guided tutorial on component-driven development at{' '}
<a href="https://storybook.js.org/tutorials/" target="_blank" rel="noopener noreferrer">
Storybook tutorials
</a>
. Read more in the{' '}
<a href="https://storybook.js.org/docs" target="_blank" rel="noopener noreferrer">
docs
</a>
.
</p>
<div className="tip-wrapper">
<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">
<g fill="none" fillRule="evenodd">
<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"
id="a"
fill="#999"
/>
</g>
</svg>
Viewports addon in the toolbar
</div>
</section>
</article>
);
};
22 changes: 0 additions & 22 deletions stories/pages/Page.stories.js

This file was deleted.

23 changes: 23 additions & 0 deletions stories/pages/Page.stories.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from 'react';
import { within, userEvent } from '@storybook/testing-library';

import { Page } from './Page';

export default {
title: 'Pages/Page',
component: Page,
parameters: {
layout: 'fullscreen',
},
};

const Template = (args) => <Page {...args} />;

export const LoggedOut = Template.bind({});

export const LoggedIn = Template.bind({});
LoggedIn.play = async ({ canvasElement }) => {
const canvas = within(canvasElement);
const loginButton = await canvas.getByRole('button', { name: /Log in/i });
await userEvent.click(loginButton);
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Pages/Page LoggedIn smoke-test 2`] = `
exports[`Pages/Page LoggedIn play-test 2`] = `
<article>
<header>
<div class="wrapper">
Expand Down Expand Up @@ -32,6 +32,13 @@ exports[`Pages/Page LoggedIn smoke-test 2`] = `
</h1>
</div>
<div>
<span class="welcome">
Welcome,
<b>
Jane Doe
</b>
!
</span>
<button type="button"
class="storybook-button storybook-button--small storybook-button--secondary"
>
Expand Down Expand Up @@ -69,11 +76,11 @@ exports[`Pages/Page LoggedIn smoke-test 2`] = `
</ul>
<p>
Get a guided tutorial on component-driven development at
<a href="https://www.learnstorybook.com"
<a href="https://storybook.js.org/tutorials/"
target="_blank"
rel="noopener noreferrer"
>
Learn Storybook
Storybook tutorials
</a>
. Read more in the
<a href="https://storybook.js.org/docs"
Expand Down Expand Up @@ -184,11 +191,11 @@ exports[`Pages/Page LoggedOut smoke-test 2`] = `
</ul>
<p>
Get a guided tutorial on component-driven development at
<a href="https://www.learnstorybook.com"
<a href="https://storybook.js.org/tutorials/"
target="_blank"
rel="noopener noreferrer"
>
Learn Storybook
Storybook tutorials
</a>
. Read more in the
<a href="https://storybook.js.org/docs"
Expand Down
18 changes: 9 additions & 9 deletions stories/pages/page.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ section {
color: #333;
}

h2 {
section h2 {
font-weight: 900;
font-size: 32px;
line-height: 1;
Expand All @@ -17,25 +17,25 @@ h2 {
vertical-align: top;
}

p {
section p {
margin: 1em 0;
}

a {
section a {
text-decoration: none;
color: #1ea7fd;
}

ul {
section ul {
padding-left: 30px;
margin: 1em 0;
}

li {
section li {
margin-bottom: 8px;
}

.tip {
section .tip {
display: inline-block;
border-radius: 1em;
font-size: 11px;
Expand All @@ -48,14 +48,14 @@ li {
vertical-align: top;
}

.tip-wrapper {
section .tip-wrapper {
font-size: 13px;
line-height: 20px;
margin-top: 40px;
margin-bottom: 40px;
}

.tip-wrapper svg {
section .tip-wrapper svg {
display: inline-block;
height: 12px;
width: 12px;
Expand All @@ -64,6 +64,6 @@ li {
margin-top: 3px;
}

.tip-wrapper svg path {
section .tip-wrapper svg path {
fill: #1ea7fd;
}

0 comments on commit 7aa853e

Please sign in to comment.