From c533756efab1ea07a3edd40fd102bc3d55591a49 Mon Sep 17 00:00:00 2001 From: Yuhao <16722967+clementinelove@users.noreply.github.com> Date: Sat, 18 Jan 2025 13:40:34 +0000 Subject: [PATCH] Cleanup some example files. --- README.md | 3 +- src/stories/Configure.mdx | 446 ------------------ src/stories/ExampleButton.stories.ts | 60 --- src/stories/ExampleButton.tsx | 41 -- src/stories/Header.stories.ts | 33 -- src/stories/Header.tsx | 56 --- src/stories/Page.stories.ts | 32 -- src/stories/Page.tsx | 97 ---- src/stories/Typography.mdx | 55 --- src/stories/{ => atoms}/Button.stories.tsx | 0 src/stories/{ => atoms}/Button.tsx | 0 src/stories/{ => atoms}/Heading.stories.tsx | 2 +- src/stories/{ => atoms}/Heading.tsx | 0 src/stories/{ => atoms}/Icon.tsx | 0 src/stories/{ => atoms}/Icons.mdx | 0 src/stories/{ => atoms}/Icons.stories.tsx | 2 +- src/stories/button.css | 30 -- src/stories/header.css | 32 -- .../ContentTemplate.stories.tsx} | 6 +- .../ContentTemplate.tsx} | 9 +- src/stories/page.css | 69 --- 21 files changed, 12 insertions(+), 961 deletions(-) delete mode 100644 src/stories/Configure.mdx delete mode 100644 src/stories/ExampleButton.stories.ts delete mode 100644 src/stories/ExampleButton.tsx delete mode 100644 src/stories/Header.stories.ts delete mode 100644 src/stories/Header.tsx delete mode 100644 src/stories/Page.stories.ts delete mode 100644 src/stories/Page.tsx delete mode 100644 src/stories/Typography.mdx rename src/stories/{ => atoms}/Button.stories.tsx (100%) rename src/stories/{ => atoms}/Button.tsx (100%) rename src/stories/{ => atoms}/Heading.stories.tsx (94%) rename src/stories/{ => atoms}/Heading.tsx (100%) rename src/stories/{ => atoms}/Icon.tsx (100%) rename src/stories/{ => atoms}/Icons.mdx (100%) rename src/stories/{ => atoms}/Icons.stories.tsx (87%) delete mode 100644 src/stories/button.css delete mode 100644 src/stories/header.css rename src/stories/{Content.stories.tsx => organisms/ContentTemplate.stories.tsx} (79%) rename src/stories/{Content.tsx => organisms/ContentTemplate.tsx} (71%) delete mode 100644 src/stories/page.css diff --git a/README.md b/README.md index b653a04..b4acbb8 100644 --- a/README.md +++ b/README.md @@ -17,4 +17,5 @@ pnpm run dev We use storybook to smooth our component testing process. -For a newer version of component (for example, a redesign of button and button states), always create stories and component inside the `src/stories` folder. Production ready components should be presented in `src/components`, so move the component file to `src/components` when it becomes production ready. \ No newline at end of file +For a newer version of component (for example, a redesign of button and button states), +always create stories and component inside the `src/stories` folder. \ No newline at end of file diff --git a/src/stories/Configure.mdx b/src/stories/Configure.mdx deleted file mode 100644 index cc32923..0000000 --- a/src/stories/Configure.mdx +++ /dev/null @@ -1,446 +0,0 @@ -import { Meta } from "@storybook/blocks"; -import Image from "next/image"; - -import Github from "./assets/github.svg"; -import Discord from "./assets/discord.svg"; -import Youtube from "./assets/youtube.svg"; -import Tutorials from "./assets/tutorials.svg"; -import Styling from "./assets/styling.png"; -import Context from "./assets/context.png"; -import Assets from "./assets/assets.png"; -import Docs from "./assets/docs.png"; -import Share from "./assets/share.png"; -import FigmaPlugin from "./assets/figma-plugin.png"; -import Testing from "./assets/testing.png"; -import Accessibility from "./assets/accessibility.png"; -import Theming from "./assets/theming.png"; -import AddonLibrary from "./assets/addon-library.png"; - -export const RightArrow = () => - - - - - -
-
- # Configure your project - - Because Storybook works separately from your app, you'll need to configure it for your specific stack and setup. Below, explore guides for configuring Storybook with popular frameworks and tools. If you get stuck, learn how you can ask for help from our community. -
-
-
- A wall of logos representing different styling technologies -

Add styling and CSS

-

Like with web applications, there are many ways to include CSS within Storybook. Learn more about setting up styling within Storybook.

- Learn more -
-
- An abstraction representing the composition of data for a component -

Provide context and mocking

-

Often when a story doesn't render, it's because your component is expecting a specific environment or context (like a theme provider) to be available.

- Learn more -
-
- A representation of typography and image assets -
-

Load assets and resources

-

To link static files (like fonts) to your projects and stories, use the - `staticDirs` configuration option to specify folders to load when - starting Storybook.

- Learn more -
-
-
-
-
-
- # Do more with Storybook - - Now that you know the basics, let's explore other parts of Storybook that will improve your experience. This list is just to get you started. You can customise Storybook in many ways to fit your needs. -
- -
-
-
- A screenshot showing the autodocs tag being set, pointing a docs page being generated -

Autodocs

-

Auto-generate living, - interactive reference documentation from your components and stories.

- Learn more -
-
- A browser window showing a Storybook being published to a chromatic.com URL -

Publish to Chromatic

-

Publish your Storybook to review and collaborate with your entire team.

- Learn more -
-
- Windows showing the Storybook plugin in Figma -

Figma Plugin

-

Embed your stories into Figma to cross-reference the design and live - implementation in one place.

- Learn more -
-
- Screenshot of tests passing and failing -

Testing

-

Use stories to test a component in all its variations, no matter how - complex.

- Learn more -
-
- Screenshot of accessibility tests passing and failing -

Accessibility

-

Automatically test your components for a11y issues as you develop.

- Learn more -
-
- Screenshot of Storybook in light and dark mode -

Theming

-

Theme Storybook's UI to personalize it to your project.

- Learn more -
-
-
-
-
-
-

Addons

-

Integrate your tools with Storybook to connect workflows.

- Discover all addons -
-
- Integrate your tools with Storybook to connect workflows. -
-
- -
-
- Github logo - Join our contributors building the future of UI development. - - Star on GitHub -
-
- Discord logo -
- Get support and chat with frontend developers. - - Join Discord server -
-
-
- Youtube logo -
- Watch tutorials, feature previews and interviews. - - Watch on YouTube -
-
-
- A book -

Follow guided walkthroughs on for key workflows.

- - Discover tutorials -
-
- - diff --git a/src/stories/ExampleButton.stories.ts b/src/stories/ExampleButton.stories.ts deleted file mode 100644 index 35120b5..0000000 --- a/src/stories/ExampleButton.stories.ts +++ /dev/null @@ -1,60 +0,0 @@ -import type { Meta, StoryObj } from '@storybook/react'; -import { fn } from '@storybook/test'; - -import { ExampleButton } from './ExampleButton'; - -// More on how to set up stories at: https://storybook.js.org/docs/writing-stories#default-export -const meta = { - title: 'Example/ExampleButton', - component: ExampleButton, - parameters: { - // Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/configure/story-layout - layout: 'centered', - }, - // This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs - tags: ['autodocs'], - // More on argTypes: https://storybook.js.org/docs/api/argtypes - argTypes: { - backgroundColor: { control: 'color' }, - }, - // Use `fn` to spy on the onClick arg, which will appear in the actions panel once invoked: https://storybook.js.org/docs/essentials/actions#action-args - args: { onClick: fn() }, -} satisfies Meta; - -export default meta; -type Story = StoryObj; - -// More on writing stories with args: https://storybook.js.org/docs/writing-stories/args -export const Primary: Story = { - args: { - primary: true, - label: 'Button', - }, -}; - -export const Secondary: Story = { - args: { - label: "burg", - }, -}; - -export const Large: Story = { - args: { - size: 'large', - label: 'Button', - }, -}; - -export const Small: Story = { - args: { - size: 'small', - label: 'Button', - }, -}; - -export const NonPrimary: Story = { - args: { - primary: false, - label: "Button" - } -}; diff --git a/src/stories/ExampleButton.tsx b/src/stories/ExampleButton.tsx deleted file mode 100644 index 291b40b..0000000 --- a/src/stories/ExampleButton.tsx +++ /dev/null @@ -1,41 +0,0 @@ -import React from 'react'; - -import './button.css'; - -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 ExampleButton: React.FC = ({ - primary = false, - size = 'medium', - backgroundColor, - label, - ...props -}: ButtonProps) => { - const mode = primary ? 'storybook-button--primary' : 'storybook-button--secondary'; - return ( - - ); -}; diff --git a/src/stories/Header.stories.ts b/src/stories/Header.stories.ts deleted file mode 100644 index 80c71d0..0000000 --- a/src/stories/Header.stories.ts +++ /dev/null @@ -1,33 +0,0 @@ -import type { Meta, StoryObj } from '@storybook/react'; -import { fn } from '@storybook/test'; - -import { Header } from './Header'; - -const meta = { - title: 'Example/Header', - component: Header, - // This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs - tags: ['autodocs'], - parameters: { - // More on how to position stories at: https://storybook.js.org/docs/configure/story-layout - layout: 'fullscreen', - }, - args: { - onLogin: fn(), - onLogout: fn(), - onCreateAccount: fn(), - }, -} satisfies Meta; - -export default meta; -type Story = StoryObj; - -export const LoggedIn: Story = { - args: { - user: { - name: 'Jane Doe', - }, - }, -}; - -export const LoggedOut: Story = {}; diff --git a/src/stories/Header.tsx b/src/stories/Header.tsx deleted file mode 100644 index 224aeeb..0000000 --- a/src/stories/Header.tsx +++ /dev/null @@ -1,56 +0,0 @@ -import React from 'react'; - -import { ExampleButton } from "./ExampleButton"; -import './header.css'; - -interface User { - name: string; -}; - -export interface HeaderProps { - user?: User; - onLogin?: () => void; - onLogout?: () => void; - onCreateAccount?: () => void; -} - -export const Header: React.FC = ({ user, onLogin, onLogout, onCreateAccount }: HeaderProps) => ( -
-
-
- - - - - - - -

Acme

-
-
- {user ? ( - <> - - Welcome, {user.name}! - - - - ) : ( - <> - - - - )} -
-
-
-); diff --git a/src/stories/Page.stories.ts b/src/stories/Page.stories.ts deleted file mode 100644 index 53b9f8f..0000000 --- a/src/stories/Page.stories.ts +++ /dev/null @@ -1,32 +0,0 @@ -import type { Meta, StoryObj } from '@storybook/react'; -import { expect, userEvent, within } from '@storybook/test'; - -import { Page } from './Page'; - -const meta = { - title: 'Example/Page', - component: Page, - parameters: { - // More on how to position stories at: https://storybook.js.org/docs/configure/story-layout - layout: 'fullscreen', - }, -} satisfies Meta; - -export default meta; -type Story = StoryObj; - -export const LoggedOut: Story = {}; - -// More on interaction testing: https://storybook.js.org/docs/writing-tests/interaction-testing -export const LoggedIn: Story = { - play: async ({ canvasElement }) => { - const canvas = within(canvasElement); - const loginButton = canvas.getByRole('button', { name: /Log in/i }); - await expect(loginButton).toBeInTheDocument(); - await userEvent.click(loginButton); - await expect(loginButton).not.toBeInTheDocument(); - - const logoutButton = canvas.getByRole('button', { name: /Log out/i }); - await expect(logoutButton).toBeInTheDocument(); - }, -}; diff --git a/src/stories/Page.tsx b/src/stories/Page.tsx deleted file mode 100644 index 4cbd3c5..0000000 --- a/src/stories/Page.tsx +++ /dev/null @@ -1,97 +0,0 @@ -import React from "react"; - -import { Header } from "./Header"; -import "./page.css"; - -interface User { - name: string; -} - -export const Page: React.FC = () => { - 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/src/stories/Typography.mdx b/src/stories/Typography.mdx deleted file mode 100644 index 8f8d66b..0000000 --- a/src/stories/Typography.mdx +++ /dev/null @@ -1,55 +0,0 @@ -import '../app/globals.css'; -import { Meta, Typeset } from '@storybook/blocks'; -import { Button } from "../components/Button"; - - - -export const typography = { - type: { - primary: '"PP Pangram Sans Rounded", "PPPangramSansRounded-Medium"' - }, - weight: { - regular: '400', - bold: '700', - extrabold: '800', - black: '900', - }, - size: { - s1: 12, - s2: 14, - s3: 16, - m1: 20, - m2: 24, - m3: 28, - l1: 32, - l2: 40, - l3: 48, - }, -}; - -export const SampleText = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'; - -# Typography - -**Font:** PP Pangram Sans Rounded - -