From c616556772f32f1573211216ec09e4581f7a8d3a Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Sat, 21 Jan 2023 21:16:11 +0900 Subject: [PATCH] Make storybook work for react native --- front/.storybook/main.js | 37 +++-- front/.storybook/preview.js | 26 ++- front/components/Loading.stories.tsx | 9 ++ front/stories/Button.stories.tsx | 41 ----- front/stories/Button.tsx | 48 ------ front/stories/Header.stories.tsx | 25 --- front/stories/Header.tsx | 56 ------- front/stories/Introduction.stories.mdx | 211 ------------------------- front/stories/Page.stories.tsx | 26 --- front/stories/Page.tsx | 73 --------- front/stories/assets/code-brackets.svg | 1 - front/stories/assets/colors.svg | 1 - front/stories/assets/comments.svg | 1 - front/stories/assets/direction.svg | 1 - front/stories/assets/flow.svg | 1 - front/stories/assets/plugin.svg | 1 - front/stories/assets/repo.svg | 1 - front/stories/assets/stackalt.svg | 1 - front/stories/button.css | 30 ---- front/stories/header.css | 32 ---- front/stories/page.css | 69 -------- 21 files changed, 53 insertions(+), 638 deletions(-) create mode 100644 front/components/Loading.stories.tsx delete mode 100644 front/stories/Button.stories.tsx delete mode 100644 front/stories/Button.tsx delete mode 100644 front/stories/Header.stories.tsx delete mode 100644 front/stories/Header.tsx delete mode 100644 front/stories/Introduction.stories.mdx delete mode 100644 front/stories/Page.stories.tsx delete mode 100644 front/stories/Page.tsx delete mode 100644 front/stories/assets/code-brackets.svg delete mode 100644 front/stories/assets/colors.svg delete mode 100644 front/stories/assets/comments.svg delete mode 100644 front/stories/assets/direction.svg delete mode 100644 front/stories/assets/flow.svg delete mode 100644 front/stories/assets/plugin.svg delete mode 100644 front/stories/assets/repo.svg delete mode 100644 front/stories/assets/stackalt.svg delete mode 100644 front/stories/button.css delete mode 100644 front/stories/header.css delete mode 100644 front/stories/page.css diff --git a/front/.storybook/main.js b/front/.storybook/main.js index c92a4e7..893be49 100644 --- a/front/.storybook/main.js +++ b/front/.storybook/main.js @@ -1,12 +1,27 @@ module.exports = { - "stories": [ - "../stories/**/*.stories.mdx", - "../stories/**/*.stories.@(js|jsx|ts|tsx)" - ], - "addons": [ - "@storybook/addon-links", - "@storybook/addon-essentials", - "@storybook/addon-interactions" - ], - "framework": "@storybook/react" -} \ No newline at end of file + stories: ["../**/*.stories.mdx", "../**/*.stories.@(js|jsx|ts|tsx)"], + addons: [ + "@storybook/addon-links", + "@storybook/addon-essentials", + "@storybook/addon-interactions", + ], + framework: "@storybook/react", + + webpack: (config) => { + config.resolve = { + ...config.resolve, + alias: { + ...config.resolve.alias, + "react-native$": "react-native-web", + }, + extensions: [ + ".web.ts", + ".web.tsx", + ".web.js", + ".web.jsx", + ...config.resolve.extensions, + ], + }; + return config; + }, +}; diff --git a/front/.storybook/preview.js b/front/.storybook/preview.js index 48afd56..1846e44 100644 --- a/front/.storybook/preview.js +++ b/front/.storybook/preview.js @@ -1,9 +1,19 @@ +import { NativeBaseProvider } from "native-base"; +import Theme from '../Theme'; + export const parameters = { - actions: { argTypesRegex: "^on[A-Z].*" }, - controls: { - matchers: { - color: /(background|color)$/i, - date: /Date$/, - }, - }, -} \ No newline at end of file + actions: { argTypesRegex: "^on[A-Z].*" }, + controls: { + matchers: { + color: /(background|color)$/i, + date: /Date$/, + }, + }, +}; +export const decorators = [ + (Story) => ( + + + + ), +]; diff --git a/front/components/Loading.stories.tsx b/front/components/Loading.stories.tsx new file mode 100644 index 0000000..37e1fca --- /dev/null +++ b/front/components/Loading.stories.tsx @@ -0,0 +1,9 @@ +import { ComponentStory, ComponentMeta } from "@storybook/react"; +import Loading from "./Loading"; + +export default { + title: "Loading", + component: Loading, +} as ComponentMeta; + +export const Default: ComponentStory = () => ; diff --git a/front/stories/Button.stories.tsx b/front/stories/Button.stories.tsx deleted file mode 100644 index c331bd4..0000000 --- a/front/stories/Button.stories.tsx +++ /dev/null @@ -1,41 +0,0 @@ -import React from 'react'; -import { ComponentStory, ComponentMeta } from '@storybook/react'; - -import { Button } from './Button'; - -// More on default export: https://storybook.js.org/docs/react/writing-stories/introduction#default-export -export default { - title: 'Example/Button', - component: Button, - // More on argTypes: https://storybook.js.org/docs/react/api/argtypes - argTypes: { - backgroundColor: { control: 'color' }, - }, -} as ComponentMeta; - -// More on component templates: https://storybook.js.org/docs/react/writing-stories/introduction#using-args -const Template: ComponentStory = (args) => - ); -}; diff --git a/front/stories/Header.stories.tsx b/front/stories/Header.stories.tsx deleted file mode 100644 index 7e9283e..0000000 --- a/front/stories/Header.stories.tsx +++ /dev/null @@ -1,25 +0,0 @@ -import React from 'react'; -import { ComponentStory, ComponentMeta } from '@storybook/react'; - -import { Header } from './Header'; - -export default { - title: 'Example/Header', - component: Header, - parameters: { - // More on Story layout: https://storybook.js.org/docs/react/configure/story-layout - layout: 'fullscreen', - }, -} as ComponentMeta; - -const Template: ComponentStory = (args) =>
; - -export const LoggedIn = Template.bind({}); -LoggedIn.args = { - user: { - name: 'Jane Doe', - }, -}; - -export const LoggedOut = Template.bind({}); -LoggedOut.args = {}; diff --git a/front/stories/Header.tsx b/front/stories/Header.tsx deleted file mode 100644 index dc3f3c1..0000000 --- a/front/stories/Header.tsx +++ /dev/null @@ -1,56 +0,0 @@ -import React from 'react'; - -import { Button } from './Button'; -import './header.css'; - -type User = { - name: string; -}; - -interface HeaderProps { - user?: User; - onLogin: () => void; - onLogout: () => void; - onCreateAccount: () => void; -} - -export const Header = ({ user, onLogin, onLogout, onCreateAccount }: HeaderProps) => ( -
-
-
- - - - - - - -

Acme

-
-
- {user ? ( - <> - - Welcome, {user.name}! - -
-
-
-); diff --git a/front/stories/Introduction.stories.mdx b/front/stories/Introduction.stories.mdx deleted file mode 100644 index edc33ed..0000000 --- a/front/stories/Introduction.stories.mdx +++ /dev/null @@ -1,211 +0,0 @@ -import { Meta } from '@storybook/addon-docs'; -import Code from './assets/code-brackets.svg'; -import Colors from './assets/colors.svg'; -import Comments from './assets/comments.svg'; -import Direction from './assets/direction.svg'; -import Flow from './assets/flow.svg'; -import Plugin from './assets/plugin.svg'; -import Repo from './assets/repo.svg'; -import StackAlt from './assets/stackalt.svg'; - - - - - -# Welcome to Storybook - -Storybook helps you build UI components in isolation from your app's business logic, data, and context. -That makes it easy to develop hard-to-reach states. Save these UI states as **stories** to revisit during development, testing, or QA. - -Browse example stories now by navigating to them in the sidebar. -View their code in the `stories` directory to learn how they work. -We recommend building UIs with a [**component-driven**](https://componentdriven.org) process starting with atomic components and ending with pages. - -
Configure
- - - -
Learn
- - - -
- TipEdit the Markdown in{' '} - stories/Introduction.stories.mdx -
diff --git a/front/stories/Page.stories.tsx b/front/stories/Page.stories.tsx deleted file mode 100644 index a0ea79f..0000000 --- a/front/stories/Page.stories.tsx +++ /dev/null @@ -1,26 +0,0 @@ -import React from 'react'; -import { ComponentStory, ComponentMeta } from '@storybook/react'; -import { within, userEvent } from '@storybook/testing-library'; -import { Page } from './Page'; - -export default { - title: 'Example/Page', - component: Page, - parameters: { - // More on Story layout: https://storybook.js.org/docs/react/configure/story-layout - layout: 'fullscreen', - }, -} as ComponentMeta; - -const Template: ComponentStory = (args) => ; - -export const LoggedOut = Template.bind({}); - -export const LoggedIn = Template.bind({}); - -// More on interaction testing: https://storybook.js.org/docs/react/writing-tests/interaction-testing -LoggedIn.play = async ({ canvasElement }) => { - const canvas = within(canvasElement); - const loginButton = await canvas.getByRole('button', { name: /Log in/i }); - await userEvent.click(loginButton); -}; diff --git a/front/stories/Page.tsx b/front/stories/Page.tsx deleted file mode 100644 index 522d342..0000000 --- a/front/stories/Page.tsx +++ /dev/null @@ -1,73 +0,0 @@ -import React from 'react'; - -import { Header } from './Header'; -import './page.css'; - -type User = { - name: string; -}; - -export const Page: React.VFC = () => { - const [user, setUser] = React.useState(); - - return ( -
-
setUser({ name: 'Jane Doe' })} - onLogout={() => setUser(undefined)} - onCreateAccount={() => setUser({ name: 'Jane Doe' })} - /> - -
-

Pages in Storybook

-

- We recommend building UIs with a{' '} - - component-driven - {' '} - process starting with atomic components and ending with pages. -

-

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

-
    -
  • - Use a higher-level connected component. Storybook helps you compose such data from the - "args" of child component stories -
  • -
  • - Assemble data in the page component from your services. You can mock these services out - using Storybook. -
  • -
-

- Get a guided tutorial on component-driven development at{' '} - - Storybook tutorials - - . Read more in the{' '} - - docs - - . -

-
- Tip Adjust the width of the canvas with the{' '} - - - - - - Viewports addon in the toolbar -
-
-
- ); -}; diff --git a/front/stories/assets/code-brackets.svg b/front/stories/assets/code-brackets.svg deleted file mode 100644 index 73de947..0000000 --- a/front/stories/assets/code-brackets.svg +++ /dev/null @@ -1 +0,0 @@ -illustration/code-brackets \ No newline at end of file diff --git a/front/stories/assets/colors.svg b/front/stories/assets/colors.svg deleted file mode 100644 index 17d58d5..0000000 --- a/front/stories/assets/colors.svg +++ /dev/null @@ -1 +0,0 @@ -illustration/colors \ No newline at end of file diff --git a/front/stories/assets/comments.svg b/front/stories/assets/comments.svg deleted file mode 100644 index 6493a13..0000000 --- a/front/stories/assets/comments.svg +++ /dev/null @@ -1 +0,0 @@ -illustration/comments \ No newline at end of file diff --git a/front/stories/assets/direction.svg b/front/stories/assets/direction.svg deleted file mode 100644 index 65676ac..0000000 --- a/front/stories/assets/direction.svg +++ /dev/null @@ -1 +0,0 @@ -illustration/direction \ No newline at end of file diff --git a/front/stories/assets/flow.svg b/front/stories/assets/flow.svg deleted file mode 100644 index 8ac27db..0000000 --- a/front/stories/assets/flow.svg +++ /dev/null @@ -1 +0,0 @@ -illustration/flow \ No newline at end of file diff --git a/front/stories/assets/plugin.svg b/front/stories/assets/plugin.svg deleted file mode 100644 index 29e5c69..0000000 --- a/front/stories/assets/plugin.svg +++ /dev/null @@ -1 +0,0 @@ -illustration/plugin \ No newline at end of file diff --git a/front/stories/assets/repo.svg b/front/stories/assets/repo.svg deleted file mode 100644 index f386ee9..0000000 --- a/front/stories/assets/repo.svg +++ /dev/null @@ -1 +0,0 @@ -illustration/repo \ No newline at end of file diff --git a/front/stories/assets/stackalt.svg b/front/stories/assets/stackalt.svg deleted file mode 100644 index 9b7ad27..0000000 --- a/front/stories/assets/stackalt.svg +++ /dev/null @@ -1 +0,0 @@ -illustration/stackalt \ No newline at end of file diff --git a/front/stories/button.css b/front/stories/button.css deleted file mode 100644 index dc91dc7..0000000 --- a/front/stories/button.css +++ /dev/null @@ -1,30 +0,0 @@ -.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; -} diff --git a/front/stories/header.css b/front/stories/header.css deleted file mode 100644 index 830610e..0000000 --- a/front/stories/header.css +++ /dev/null @@ -1,32 +0,0 @@ -.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; -} - -.welcome { - color: #333; - font-size: 14px; - margin-right: 10px; -} diff --git a/front/stories/page.css b/front/stories/page.css deleted file mode 100644 index fbc32ae..0000000 --- a/front/stories/page.css +++ /dev/null @@ -1,69 +0,0 @@ -section { - font-family: 'Nunito Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif; - font-size: 14px; - line-height: 24px; - padding: 48px 20px; - margin: 0 auto; - max-width: 600px; - color: #333; -} - -section h2 { - font-weight: 900; - font-size: 32px; - line-height: 1; - margin: 0 0 4px; - display: inline-block; - vertical-align: top; -} - -section p { - margin: 1em 0; -} - -section a { - text-decoration: none; - color: #1ea7fd; -} - -section ul { - padding-left: 30px; - margin: 1em 0; -} - -section li { - margin-bottom: 8px; -} - -section .tip { - display: inline-block; - border-radius: 1em; - font-size: 11px; - line-height: 12px; - font-weight: 700; - background: #e7fdd8; - color: #66bf3c; - padding: 4px 12px; - margin-right: 10px; - vertical-align: top; -} - -section .tip-wrapper { - font-size: 13px; - line-height: 20px; - margin-top: 40px; - margin-bottom: 40px; -} - -section .tip-wrapper svg { - display: inline-block; - height: 12px; - width: 12px; - margin-right: 4px; - vertical-align: top; - margin-top: 3px; -} - -section .tip-wrapper svg path { - fill: #1ea7fd; -}