diff --git a/.eslintrc.json b/.eslintrc.json index b4ad4c23..05bb6085 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,46 +1,69 @@ -{ - "env": { - "browser": true, - "es2021": true - }, - "extends": [ - "standard-with-typescript", - "plugin:react/recommended", - "prettier", - "prettier/prettier", - "eslint:recommended", - "next" - ], - "parser": "@babel/eslint-parser", - "parserOptions": { - "ecmaVersion": "latest", - "sourceType": "module", - "requireConfigFile": false, - "babelOptions": { - "presets": ["@babel/preset-react"] - } - }, - "plugins": [ - "react", - "eslint-plugin-import", - "eslint-plugin-n", - "eslint-plugin-prettier", - "eslint-plugin-promise", - "eslint-plugin-react", - "eslint-plugin-react-hooks", - "eslint-plugin-tsdoc", - "eslint-plugin-next" - ], - "rules": { - "prettier/prettier": "error", - "react/jsx-filename-extension": [ - "warn", - { "extensions": [".js", ".jsx", ".ts", ".tsx"] } - ], - "import/prefer-default-export": "off", - "jsx-quotes": ["error", "prefer-double"], - "camelcase": "warn", - "complexity": ["warn", 10], - "import/no-unresolved": ["error", { "ignore": ["^@"] }] - } -} +{ + "env": { + "browser": true, + "es2021": true + }, + "extends": [ + "standard-with-typescript", + "plugin:react/recommended", + "prettier", + "prettier/prettier", + "eslint:recommended", + "next", + "plugin:storybook/recommended" + ], + "parser": "@babel/eslint-parser", + "parserOptions": { + "ecmaVersion": "latest", + "sourceType": "module", + "requireConfigFile": false, + "babelOptions": { + "presets": [ + "@babel/preset-react" + ] + } + }, + "plugins": [ + "react", + "eslint-plugin-import", + "eslint-plugin-n", + "eslint-plugin-prettier", + "eslint-plugin-promise", + "eslint-plugin-react", + "eslint-plugin-react-hooks", + "eslint-plugin-tsdoc", + "eslint-plugin-next" + ], + "rules": { + "prettier/prettier": "error", + "react/jsx-filename-extension": [ + "warn", + { + "extensions": [ + ".js", + ".jsx", + ".ts", + ".tsx" + ] + } + ], + "import/prefer-default-export": "off", + "jsx-quotes": [ + "error", + "prefer-double" + ], + "camelcase": "warn", + "complexity": [ + "warn", + 10 + ], + "import/no-unresolved": [ + "error", + { + "ignore": [ + "^@" + ] + } + ] + } +} diff --git a/.storybook/main.ts b/.storybook/main.ts new file mode 100644 index 00000000..0bd61857 --- /dev/null +++ b/.storybook/main.ts @@ -0,0 +1,28 @@ +import { StorybookConfig } from "@storybook/nextjs"; + +const config: StorybookConfig = { + stories: [ + "../stories/**/*.mdx", + "../stories/**/*.stories.@(js|jsx|mjs|ts|tsx)", + ], + addons: [ + "@storybook/addon-links", + "@storybook/addon-essentials", + "@storybook/addon-onboarding", + "@storybook/addon-interactions", + "@storybook/addon-themes", + ], + framework: { + name: "@storybook/nextjs", + options: { + strictMode: true, + fastRefresh: true, + nextConfigPath: "../next.config.js", + }, + }, + docs: { + autodocs: true, + }, +}; + +export default config; diff --git a/.storybook/preview.ts b/.storybook/preview.ts new file mode 100644 index 00000000..eca4b5ee --- /dev/null +++ b/.storybook/preview.ts @@ -0,0 +1,42 @@ +import { Preview } from "@storybook/react"; +import { withThemeFromJSXProvider } from "@storybook/addon-themes"; +import { darkTheme, lightTheme } from "../src/styles/theme/default/index.ts"; +import { ThemeProvider } from "styled-components"; +import { GlobalStyle } from "../src/styles/globals.tsx"; +import { + INITIAL_VIEWPORTS, + MINIMAL_VIEWPORTS, +} from "@storybook/addon-viewport"; + +export const decorators = [ + withThemeFromJSXProvider({ + themes: { + light: lightTheme, + dark: darkTheme, + }, + defaultTheme: "light", + Provider: ThemeProvider, + GlobalStyles: GlobalStyle, + }), +]; + +const preview: Preview = { + parameters: { + layout: "centered", + viewport: { + viewports: { + ...INITIAL_VIEWPORTS, + ...MINIMAL_VIEWPORTS, + }, + }, + actions: { argTypesRegex: "^on[A-Z].*" }, + controls: { + matchers: { + color: /(background|color)$/i, + date: /Date$/i, + }, + }, + }, +}; + +export default preview; diff --git a/package.json b/package.json index 4b379a14..61ce446c 100644 --- a/package.json +++ b/package.json @@ -1,72 +1,88 @@ { - "name": "services", - "version": "0.1.0", - "private": true, - "repository": "https://github.com/welllucky/services.git", - "author": "Wellington Braga ", - "license": "LGPL-3.0-only", - "scripts": { - "dev": "next dev", - "build": "next build", - "start": "next start", - "lint": "next lint && yarn lint:css", - "lint:css": "stylelint './src/**/*.js'", - "e2e:open": "playwright test --ui", - "e2e:run": "playwright test", - "e2e:debug": "playwright test --debug", - "e2e:gen": "playwright codegen", - "test": "playwright test -c playwright-ct.config.ts" - }, - "dependencies": { - "@vercel/analytics": "^1.1.1", - "axios": "^1.4.0", - "next": "14.0.1", - "react": "^18", - "react-dom": "^18", - "sharp": "^0.32.6", - "styled-components": "^6.1.0", - "swr": "^2.2.4", - "usehooks-ts": "^2.9.1" - }, - "devDependencies": { - "@babel/eslint-parser": "^7.23.3", - "@babel/preset-react": "^7.23.3", - "@next/eslint-plugin-next": "^14.0.3", - "@playwright/experimental-ct-react": "^1.39.0", - "@playwright/test": "^1.39.0", - "@types/node": "^20", - "@types/react": "^18", - "@types/react-dom": "^18", - "@typescript-eslint/eslint-plugin": "^6.4.0", - "@typescript-eslint/parser": "^6.11.0", - "dotenv": "^16.3.1", - "eslint": "^8.0.1", - "eslint-config-next": "14.0.1", - "eslint-config-prettier": "^9.0.0", - "eslint-config-standard-with-typescript": "^39.1.1", - "eslint-plugin-import": "^2.25.2", - "eslint-plugin-n": "^15.0.0 || ^16.0.0 ", - "eslint-plugin-prettier": "^5.0.1", - "eslint-plugin-promise": "^6.0.0", - "eslint-plugin-react": "^7.33.2", - "eslint-plugin-react-hooks": "^4.6.0", - "eslint-plugin-tsdoc": "^0.2.17", - "postcss-styled-syntax": "^0.5.0", - "prettier": "^3.1.0", - "stylelint": "^15.11.0", - "stylelint-config-standard": "^34.0.0", - "typescript": "*" - }, - "browserslist": { - "production": [ - ">0.2%", - "not dead", - "not op_mini all" - ], - "development": [ - "last 1 chrome version", - "last 1 firefox version", - "last 1 safari version" - ] - } + "name": "services", + "version": "0.1.0", + "private": true, + "packageManager": "yarn@4.0.2", + "repository": "https://github.com/welllucky/services.git", + "author": "Wellington Braga ", + "license": "LGPL-3.0-only", + "scripts": { + "dev": "next dev", + "build": "next build", + "start": "next start", + "lint": "next lint && stylelint './src/**/*.js'", + "e2e:open": "playwright test --ui", + "e2e:run": "playwright test", + "e2e:debug": "playwright test --debug", + "e2e:gen": "playwright codegen", + "test": "playwright test -c playwright-ct.config.ts", + "storybook": "storybook dev -p 6006", + "build-storybook": "storybook build" + }, + "dependencies": { + "axios": "^1.4.0", + "next": "14.0.1", + "react": "^18", + "react-dom": "^18", + "sharp": "^0.32.6", + "styled-components": "^6.1.0", + "swr": "^2.2.4", + "usehooks-ts": "^2.9.1" + }, + "devDependencies": { + "@babel/eslint-parser": "^7.23.3", + "@babel/preset-react": "^7.23.3", + "@next/eslint-plugin-next": "^14.0.3", + "@playwright/experimental-ct-react": "^1.39.0", + "@playwright/test": "^1.39.0", + "@storybook/addon-essentials": "^7.6.6", + "@storybook/addon-interactions": "^7.6.6", + "@storybook/addon-links": "^7.6.6", + "@storybook/addon-onboarding": "^1.0.10", + "@storybook/addon-themes": "^7.6.6", + "@storybook/blocks": "^7.6.6", + "@storybook/jest": "^0.2.3", + "@storybook/nextjs": "^7.6.6", + "@storybook/react": "^7.6.6", + "@storybook/test": "^7.6.6", + "@storybook/testing-library": "^0.2.2", + "@types/node": "^20", + "@types/react": "^18", + "@types/react-dom": "^18", + "@typescript-eslint/eslint-plugin": "^6.4.0", + "@typescript-eslint/parser": "^6.11.0", + "dotenv": "^16.3.1", + "eslint": "^8.0.1", + "eslint-config-next": "14.0.1", + "eslint-config-prettier": "^9.0.0", + "eslint-config-standard-with-typescript": "^39.1.1", + "eslint-plugin-import": "^2.25.2", + "eslint-plugin-n": "^15.0.0 || ^16.0.0 ", + "eslint-plugin-prettier": "^5.0.1", + "eslint-plugin-promise": "^6.0.0", + "eslint-plugin-react": "^7.33.2", + "eslint-plugin-react-hooks": "^4.6.0", + "eslint-plugin-storybook": "^0.6.15", + "eslint-plugin-tsdoc": "^0.2.17", + "postcss-styled-syntax": "^0.5.0", + "prettier": "^3.1.0", + "react": "^18.2.0", + "react-dom": "^18.2.0", + "storybook": "^7.6.6", + "stylelint": "^15.11.0", + "stylelint-config-standard": "^34.0.0", + "typescript": "*" + }, + "browserslist": { + "production": [ + ">0.2%", + "not dead", + "not op_mini all" + ], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] + } } diff --git a/playwright-ct.config.ts b/playwright-ct.config.ts deleted file mode 100644 index 3f194bd7..00000000 --- a/playwright-ct.config.ts +++ /dev/null @@ -1,48 +0,0 @@ -import { defineConfig, devices } from "@playwright/experimental-ct-react"; - -/** - * See https://playwright.dev/docs/test-configuration. - */ - -require("dotenv").config(); - -export default defineConfig({ - testDir: "./tests/", - testMatch: "**/?(*.)+(spec).[tj]s?(x)", - /* The base directory, relative to the config file, for snapshot files created with toMatchSnapshot and toHaveScreenshot. */ - snapshotDir: "./tests/__snapshots__", - /* Maximum time one test can run for. */ - timeout: 10 * 1000, - /* Run tests in files in parallel */ - fullyParallel: true, - /* Fail the build on CI if you accidentally left test.only in the source code. */ - forbidOnly: !!process.env.CI, - /* Retry on CI only */ - retries: process.env.CI ? 2 : 0, - /* Opt out of parallel tests on CI. */ - workers: process.env.CI ? 1 : undefined, - /* Reporter to use. See https://playwright.dev/docs/test-reporters */ - reporter: [ - ["html", { outputFolder: "./tests/report", host: "localhost", port: 4000 }], - ], - /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ - use: { - /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ - trace: "on-first-retry", - - /* Port to use for Playwright component endpoint. */ - ctPort: 3100, - }, - - /* Configure projects for major browsers */ - projects: [ - { - name: "chromium", - use: { ...devices["Desktop Chrome"] }, - }, - { - name: "firefox", - use: { ...devices["Desktop Firefox"] }, - }, - ], -}); diff --git a/src/components/NavBar/styles.tsx b/src/components/NavBar/styles.tsx index 82c5e06b..3ebd90b4 100644 --- a/src/components/NavBar/styles.tsx +++ b/src/components/NavBar/styles.tsx @@ -43,7 +43,7 @@ export const TextMenu = styled.p` font-size: 12px; font-weight: 600; line-height: 16px; - color: ${({ $isClicked, highlightTextColor }) => - $isClicked ? highlightTextColor || "#7AC143" : "#252728"}; + color: ${({ $isClicked, $highlightTextColor }) => + $isClicked ? $highlightTextColor || "#7AC143" : "#252728"}; list-style: none; `; diff --git a/stories/common/Input.stories.tsx b/stories/common/Input.stories.tsx new file mode 100644 index 00000000..7f2e4ff2 --- /dev/null +++ b/stories/common/Input.stories.tsx @@ -0,0 +1,190 @@ +import { CustomInput } from "@/components"; +import { StoryObj, Meta } from "@storybook/react"; + +// More on how to set up stories at: https://storybook.js.org/docs/writing-stories#default-export +export default { + title: "Common/Input", + component: CustomInput, + // More on argTypes: https://storybook.js.org/docs/api/argtypes + argTypes: { + placeholder: { + description: "Texto do placeholder", + control: "text", + }, + + backgroundColor: { + description: "Cor do input", + control: "color", + table: { + disable: true, + }, + }, + + style: { + description: "Estilo do input", + table: { + disable: true, + }, + }, + + $status: { + description: "Estado do input", + control: { + type: "inline-radio", + options: ["none", "valid", "invalid", "warning"], + }, + name: "status", + }, + + errorText: { + description: "Texto de erro", + control: "text", + if: { + arg: "$status", + eq: "invalid", + }, + }, + + warnText: { + description: "Texto de alerta", + control: "text", + if: { + arg: "$status", + eq: "warning", + }, + }, + + labelText: { + description: "Texto do label", + control: "text", + }, + + height: { + description: "Altura do input", + control: "text", + }, + + width: { + description: "Largura do input", + control: "text", + }, + + type: { + description: "Tipo do input", + control: "select", + }, + + leadingButton: { + description: "Botão à esquerda do input", + control: { type: "file", accept: ".svg" }, + }, + + trailingButton: { + description: "Botão à direita do input", + control: { type: "file", accept: ".svg" }, + }, + + mode: { + description: "Modo do input", + control: { + type: "select", + options: ["filled", "outlined"], + }, + }, + + onChange: { + description: "Função de mudança", + table: { + disable: true, + }, + }, + + value: { + description: "Valor do input", + }, + }, + args: { + placeholder: "Digite um texto", + labelText: "Texto", + $status: "none", + type: "text", + mode: "outlined", + errorText: "Houve um erro, tente novamente!", + }, + id: "input", +} satisfies Meta; + +// More on writing stories with args: https://storybook.js.org/docs/writing-stories/args +export const Filled: StoryObj = { + args: { + placeholder: "Digite um texto", + labelText: "Texto", + $status: "none", + type: "text", + mode: "filled", + errorText: "Houve um erro, tente novamente!", + }, +}; + +export const FilledWithError: StoryObj = { + args: { + placeholder: "Digite um texto", + labelText: "Texto", + $status: "invalid", + value: "Texto inválido", + type: "text", + mode: "filled", + errorText: "Houve um erro, tente novamente!", + }, + name: "Input Filled com erro", +}; + +export const FilledWithValidValue: StoryObj = { + args: { + placeholder: "Digite um texto", + labelText: "Texto", + $status: "valid", + value: "Texto válido", + type: "text", + mode: "filled", + errorText: "Houve um erro, tente novamente!", + }, + name: "Input Filled com valor válido", +}; + +export const OutLined: StoryObj = { + args: { + placeholder: "Digite um texto", + labelText: "Texto", + $status: "none", + type: "text", + mode: "outlined", + errorText: "Houve um erro, tente novamente!", + }, +}; + +export const OutLinedWithError: StoryObj = { + args: { + placeholder: "Digite um texto", + labelText: "Texto", + value: "Texto inválido", + $status: "invalid", + type: "text", + mode: "outlined", + errorText: "Houve um erro, tente novamente!", + }, + name: "Input Outlined com erro", +}; + +export const OutLinedWithValidValue: StoryObj = { + args: { + placeholder: "Digite um texto", + labelText: "Texto", + value: "Texto válido", + $status: "valid", + type: "text", + mode: "outlined", + errorText: "Houve um erro, tente novamente!", + }, + name: "Input Outlined com valor válido", +}; diff --git a/stories/examples/Button.jsx b/stories/examples/Button.jsx new file mode 100644 index 00000000..7c613bbf --- /dev/null +++ b/stories/examples/Button.jsx @@ -0,0 +1,54 @@ +import React from 'react'; +import PropTypes from 'prop-types'; +import './button.css'; + +/** + * Primary UI component for user interaction + */ +export const Button = ({ primary, backgroundColor, size, label, ...props }) => { + const mode = primary ? 'storybook-button--primary' : 'storybook-button--secondary'; + return ( + + ); +}; + +Button.propTypes = { + /** + * Is this the principal call to action on the page? + */ + primary: PropTypes.bool, + /** + * What background color to use + */ + backgroundColor: PropTypes.string, + /** + * How large should the button be? + */ + size: PropTypes.oneOf(['small', 'medium', 'large']), + /** + * Button contents + */ + label: PropTypes.string.isRequired, + /** + * Optional click handler + */ + onClick: PropTypes.func, +}; + +Button.defaultProps = { + backgroundColor: null, + primary: false, + size: 'medium', + onClick: undefined, +}; diff --git a/stories/examples/Button.stories.js b/stories/examples/Button.stories.js new file mode 100644 index 00000000..3a3f67ec --- /dev/null +++ b/stories/examples/Button.stories.js @@ -0,0 +1,45 @@ +import { Button } from './Button'; + +// More on how to set up stories at: https://storybook.js.org/docs/writing-stories#default-export +export default { + title: 'Example/Button', + component: Button, + 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' }, + }, +}; + +// More on writing stories with args: https://storybook.js.org/docs/writing-stories/args +export const Primary = { + args: { + primary: true, + label: 'Button', + }, +}; + +export const Secondary = { + args: { + label: 'Button', + }, +}; + +export const Large = { + args: { + size: 'large', + label: 'Button', + }, +}; + +export const Small = { + args: { + size: 'small', + label: 'Button', + }, +}; diff --git a/stories/examples/Configure.mdx b/stories/examples/Configure.mdx new file mode 100644 index 00000000..055a3c56 --- /dev/null +++ b/stories/examples/Configure.mdx @@ -0,0 +1,446 @@ +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/stories/examples/Header.jsx b/stories/examples/Header.jsx new file mode 100644 index 00000000..39e5226c --- /dev/null +++ b/stories/examples/Header.jsx @@ -0,0 +1,59 @@ +import React from 'react'; +import PropTypes from 'prop-types'; + +import { Button } from './Button'; +import './header.css'; + +export const Header = ({ user, onLogin, onLogout, onCreateAccount }) => ( +
+
+
+ + + + + + + +

Acme

+
+
+ {user ? ( + <> + + Welcome, {user.name}! + +
+
+
+); + +Header.propTypes = { + user: PropTypes.shape({ + name: PropTypes.string.isRequired, + }), + onLogin: PropTypes.func.isRequired, + onLogout: PropTypes.func.isRequired, + onCreateAccount: PropTypes.func.isRequired, +}; + +Header.defaultProps = { + user: null, +}; diff --git a/stories/examples/Header.stories.js b/stories/examples/Header.stories.js new file mode 100644 index 00000000..a1d32b3a --- /dev/null +++ b/stories/examples/Header.stories.js @@ -0,0 +1,23 @@ +import { Header } from './Header'; + +export default { + 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', + }, +}; +export const LoggedIn = { + args: { + user: { + name: 'Jane Doe', + }, + }, +}; + +export const LoggedOut = { + args: {}, +}; diff --git a/stories/examples/Page.jsx b/stories/examples/Page.jsx new file mode 100644 index 00000000..6db1e0ac --- /dev/null +++ b/stories/examples/Page.jsx @@ -0,0 +1,68 @@ +import React from 'react'; + +import { Header } from './Header'; +import './page.css'; + +export const Page = () => { + 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/stories/examples/Page.stories.js b/stories/examples/Page.stories.js new file mode 100644 index 00000000..53362f14 --- /dev/null +++ b/stories/examples/Page.stories.js @@ -0,0 +1,27 @@ +import { within, userEvent, expect } from '@storybook/test'; +import { Page } from './Page'; + +export default { + title: 'Example/Page', + component: Page, + parameters: { + // More on how to position stories at: https://storybook.js.org/docs/configure/story-layout + layout: 'fullscreen', + }, +}; + +export const LoggedOut = {}; + +// More on interaction testing: https://storybook.js.org/docs/writing-tests/interaction-testing +export const LoggedIn = { + 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/stories/examples/assets/accessibility.png b/stories/examples/assets/accessibility.png new file mode 100644 index 00000000..6ffe6fea Binary files /dev/null and b/stories/examples/assets/accessibility.png differ diff --git a/stories/examples/assets/accessibility.svg b/stories/examples/assets/accessibility.svg new file mode 100644 index 00000000..a3288830 --- /dev/null +++ b/stories/examples/assets/accessibility.svg @@ -0,0 +1,5 @@ + + Accessibility + + + \ No newline at end of file diff --git a/stories/examples/assets/addon-library.png b/stories/examples/assets/addon-library.png new file mode 100644 index 00000000..95deb38a Binary files /dev/null and b/stories/examples/assets/addon-library.png differ diff --git a/stories/examples/assets/assets.png b/stories/examples/assets/assets.png new file mode 100644 index 00000000..cfba6817 Binary files /dev/null and b/stories/examples/assets/assets.png differ diff --git a/stories/examples/assets/avif-test-image.avif b/stories/examples/assets/avif-test-image.avif new file mode 100644 index 00000000..530709bc Binary files /dev/null and b/stories/examples/assets/avif-test-image.avif differ diff --git a/stories/examples/assets/context.png b/stories/examples/assets/context.png new file mode 100644 index 00000000..e5cd249a Binary files /dev/null and b/stories/examples/assets/context.png differ diff --git a/stories/examples/assets/discord.svg b/stories/examples/assets/discord.svg new file mode 100644 index 00000000..1204df99 --- /dev/null +++ b/stories/examples/assets/discord.svg @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/stories/examples/assets/docs.png b/stories/examples/assets/docs.png new file mode 100644 index 00000000..a749629d Binary files /dev/null and b/stories/examples/assets/docs.png differ diff --git a/stories/examples/assets/figma-plugin.png b/stories/examples/assets/figma-plugin.png new file mode 100644 index 00000000..8f79b08c Binary files /dev/null and b/stories/examples/assets/figma-plugin.png differ diff --git a/stories/examples/assets/github.svg b/stories/examples/assets/github.svg new file mode 100644 index 00000000..158e0268 --- /dev/null +++ b/stories/examples/assets/github.svg @@ -0,0 +1,3 @@ + + + diff --git a/stories/examples/assets/share.png b/stories/examples/assets/share.png new file mode 100644 index 00000000..8097a370 Binary files /dev/null and b/stories/examples/assets/share.png differ diff --git a/stories/examples/assets/styling.png b/stories/examples/assets/styling.png new file mode 100644 index 00000000..d341e826 Binary files /dev/null and b/stories/examples/assets/styling.png differ diff --git a/stories/examples/assets/testing.png b/stories/examples/assets/testing.png new file mode 100644 index 00000000..d4ac39a0 Binary files /dev/null and b/stories/examples/assets/testing.png differ diff --git a/stories/examples/assets/theming.png b/stories/examples/assets/theming.png new file mode 100644 index 00000000..1535eb9b Binary files /dev/null and b/stories/examples/assets/theming.png differ diff --git a/stories/examples/assets/tutorials.svg b/stories/examples/assets/tutorials.svg new file mode 100644 index 00000000..4b2fc7c4 --- /dev/null +++ b/stories/examples/assets/tutorials.svg @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/stories/examples/assets/youtube.svg b/stories/examples/assets/youtube.svg new file mode 100644 index 00000000..33a3a61f --- /dev/null +++ b/stories/examples/assets/youtube.svg @@ -0,0 +1,4 @@ + + + + diff --git a/stories/examples/button.css b/stories/examples/button.css new file mode 100644 index 00000000..dc91dc76 --- /dev/null +++ b/stories/examples/button.css @@ -0,0 +1,30 @@ +.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/stories/examples/header.css b/stories/examples/header.css new file mode 100644 index 00000000..d9a70528 --- /dev/null +++ b/stories/examples/header.css @@ -0,0 +1,32 @@ +.storybook-header { + 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; +} + +.storybook-header svg { + display: inline-block; + vertical-align: top; +} + +.storybook-header h1 { + font-weight: 700; + font-size: 20px; + line-height: 1; + margin: 6px 0 6px 10px; + display: inline-block; + vertical-align: top; +} + +.storybook-header button + button { + margin-left: 10px; +} + +.storybook-header .welcome { + color: #333; + font-size: 14px; + margin-right: 10px; +} diff --git a/stories/examples/index.tsx b/stories/examples/index.tsx new file mode 100644 index 00000000..3d10bd72 --- /dev/null +++ b/stories/examples/index.tsx @@ -0,0 +1,4 @@ +export * from "./Button.stories"; +export * from "./Header.stories"; +export * from "./Page.stories"; +export { LoggedIn, LoggedOut } from "./Header.stories"; diff --git a/stories/examples/page.css b/stories/examples/page.css new file mode 100644 index 00000000..098dad11 --- /dev/null +++ b/stories/examples/page.css @@ -0,0 +1,69 @@ +.storybook-page { + 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; +} + +.storybook-page h2 { + font-weight: 700; + font-size: 32px; + line-height: 1; + margin: 0 0 4px; + display: inline-block; + vertical-align: top; +} + +.storybook-page p { + margin: 1em 0; +} + +.storybook-page a { + text-decoration: none; + color: #1ea7fd; +} + +.storybook-page ul { + padding-left: 30px; + margin: 1em 0; +} + +.storybook-page li { + margin-bottom: 8px; +} + +.storybook-page .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; +} + +.storybook-page .tip-wrapper { + font-size: 13px; + line-height: 20px; + margin-top: 40px; + margin-bottom: 40px; +} + +.storybook-page .tip-wrapper svg { + display: inline-block; + height: 12px; + width: 12px; + margin-right: 4px; + vertical-align: top; + margin-top: 3px; +} + +.storybook-page .tip-wrapper svg path { + fill: #1ea7fd; +}