Skip to content

Commit

Permalink
docs(client): added storybook and Button stories
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivo committed May 3, 2023
1 parent da24e51 commit 787bfa3
Show file tree
Hide file tree
Showing 11 changed files with 7,466 additions and 1,219 deletions.
60 changes: 24 additions & 36 deletions apps/client/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,37 @@
module.exports = {
extends: [
"next",
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:react/recommended",
"plugin:react-hooks/recommended",
"plugin:prettier/recommended"
],
extends: ["next", "eslint:recommended", "plugin:@typescript-eslint/recommended", "plugin:react/recommended", "plugin:react-hooks/recommended", "plugin:prettier/recommended", "plugin:storybook/recommended"],
parser: "@typescript-eslint/parser",
root: true,
plugins: ["simple-import-sort"],
rules: {
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/no-var-requires": "off",
"prettier/prettier": ["warn", { usePrettierrc: true }],
"prettier/prettier": ["warn", {
usePrettierrc: true
}],
"react/react-in-jsx-scope": "off",
"react/display-name": "off",
"@typescript-eslint/no-unused-vars": ["warn"],
"react/prop-types": "off",
"react/self-closing-comp": [
"warn",
{
component: true,
html: true
}
],
"react/self-closing-comp": ["warn", {
component: true,
html: true
}],
"simple-import-sort/exports": "warn",
"simple-import-sort/imports": [
"warn",
{
groups: [
// Packages `react` related packages come first.
["^react", "^@?\\w"],
// Internal packages.
["^(@app)(/.*|$)"],
// Side effect imports.
["^\\u0000"],
// Parent imports. Put `..` last.
["^\\.\\.(?!/?$)", "^\\.\\./?$"],
// Other relative imports. Put same-folder imports and `.` last.
["^\\./(?=.*/)(?!/?$)", "^\\.(?!/?$)", "^\\./?$"],
// Style imports.
["^.+\\.?(css)$"]
]
}
]
"simple-import-sort/imports": ["warn", {
groups: [
// Packages `react` related packages come first.
["^react", "^@?\\w"],
// Internal packages.
["^(@app)(/.*|$)"],
// Side effect imports.
["^\\u0000"],
// Parent imports. Put `..` last.
["^\\.\\.(?!/?$)", "^\\.\\./?$"],
// Other relative imports. Put same-folder imports and `.` last.
["^\\./(?=.*/)(?!/?$)", "^\\.(?!/?$)", "^\\./?$"],
// Style imports.
["^.+\\.?(css)$"]]
}]
}
};
};
17 changes: 17 additions & 0 deletions apps/client/.storybook/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import type { StorybookConfig } from "@storybook/nextjs";
const config: StorybookConfig = {
stories: ["../src/**/*.mdx", "../src/**/*.stories.@(js|jsx|ts|tsx)"],
addons: [
"@storybook/addon-links",
"@storybook/addon-essentials",
"@storybook/addon-interactions"
],
framework: {
name: "@storybook/nextjs",
options: {}
},
docs: {
autodocs: "tag"
}
};
export default config;
16 changes: 16 additions & 0 deletions apps/client/.storybook/preview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { Preview } from "@storybook/react";
import "@app/styles/globals.css";

const preview: Preview = {
parameters: {
actions: { argTypesRegex: "^on[A-Z].*" },
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/
}
}
}
};

export default preview;
13 changes: 12 additions & 1 deletion apps/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
"prettier:check": "prettier --check --ignore-unknown .",
"lint:multi": "prettier:check && pnpm lint",
"postinstall": "npx contentlayer build",
"postbuild": "next-sitemap"
"postbuild": "next-sitemap",
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build"
},
"dependencies": {
"@hookform/resolvers": "^3.1.0",
Expand Down Expand Up @@ -56,6 +58,13 @@
"zod": "^3.21.4"
},
"devDependencies": {
"@storybook/addon-essentials": "^7.0.8",
"@storybook/addon-interactions": "^7.0.8",
"@storybook/addon-links": "^7.0.8",
"@storybook/blocks": "^7.0.8",
"@storybook/nextjs": "^7.0.8",
"@storybook/react": "^7.0.8",
"@storybook/testing-library": "^0.0.14-next.2",
"@types/node": "18.11.9",
"@types/nodemailer": "^6.4.7",
"@types/react": "18.0.25",
Expand All @@ -71,6 +80,7 @@
"eslint-plugin-react": "7.32.2",
"eslint-plugin-react-hooks": "4.6.0",
"eslint-plugin-simple-import-sort": "10.0.0",
"eslint-plugin-storybook": "^0.6.12",
"postcss": "^8.4.19",
"prettier": "^2.8.4",
"prettier-plugin-tailwindcss": "^0.2.7",
Expand All @@ -79,6 +89,7 @@
"rehype-slug": "^5.1.0",
"remark-breaks": "^3.0.2",
"remark-gfm": "^3.0.1",
"storybook": "^7.0.8",
"tailwindcss": "^3.3.1",
"typescript": "4.9.3"
}
Expand Down
60 changes: 60 additions & 0 deletions apps/client/src/components/Button/Button.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import type { Meta, StoryObj } from "@storybook/react";
import { ArrowRight, Home } from "lucide-react";

import { Button } from "@app/components/Button";

const variants = [
"bg-primary-500 enabled:hover:bg-primary-600",
"bg-zinc-500 enabled:hover:bg-zinc-600",
"bg-red-500 enabled:hover:bg-red-600",
"bg-amber-500 enabled:hover:bg-amber-600",
"bg-emerald-500 enabled:hover:bg-emerald-600",
"bg-sky-500 enabled:hover:bg-sky-600",
"bg-blue-500 enabled:hover:bg-blue-600",
"bg-purple-500 enabled:hover:bg-purple-600",
"bg-pink-500 enabled:hover:bg-pink-600",
"bg-rose-500 enabled:hover:bg-rose-600"
];

// More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction
const meta: Meta<typeof Button> = {
title: "Components/Button/Base",
component: Button,
tags: ["autodocs"],
argTypes: {},
render: (args) => (
<div className="flex flex-wrap gap-2">
{variants.map((variant) => (
<Button
{...args}
key={variant}
className={`${variant}`}
/>
))}
</div>
)
};

export default meta;
type Story = StoryObj<typeof Button>;

// More on writing stories with args: https://storybook.js.org/docs/react/writing-stories/args
export const NoIcon: Story = {
args: {
children: "Button"
}
};

export const WithLeftIcon: Story = {
args: {
children: "Home",
LeftIcon: Home
}
};

export const WithRightIcon: Story = {
args: {
children: "Continue",
RightIcon: ArrowRight
}
};
55 changes: 55 additions & 0 deletions apps/client/src/components/Button/Status.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import type { Meta, StoryObj } from "@storybook/react";
import { ArrowRight, Home } from "lucide-react";

import { StatusButton } from "@app/components/Button/Status";

const variants: ("queued" | "canceled" | "finished" | "running" | "error")[] = [
"queued",
"canceled",
"finished",
"running",
"error"
];

// More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction
const meta: Meta<typeof StatusButton> = {
title: "Components/Button/Status",
component: StatusButton,
tags: ["autodocs"],
argTypes: {},
render: (args) => (
<div className="flex flex-wrap gap-2">
{variants.map((variant) => (
<StatusButton
{...args}
key={variant}
status={variant}
/>
))}
</div>
)
};

export default meta;
type Story = StoryObj<typeof StatusButton>;

// More on writing stories with args: https://storybook.js.org/docs/react/writing-stories/args
export const NoIcon: Story = {
args: {
children: "Button"
}
};

export const WithLeftIcon: Story = {
args: {
children: "Home",
LeftIcon: Home
}
};

export const WithRightIcon: Story = {
args: {
children: "Continue",
RightIcon: ArrowRight
}
};
60 changes: 60 additions & 0 deletions apps/client/src/components/Button/Text.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import type { Meta, StoryObj } from "@storybook/react";
import { ArrowRight, Home } from "lucide-react";

import { TextButton } from "@app/components/Button/Text";

const variants = [
"text-primary-600 enabled:hover:text-primary-700",
"text-zinc-600 enabled:hover:text-zinc-700",
"text-red-600 enabled:hover:text-red-700",
"text-amber-600 enabled:hover:text-amber-700",
"text-emerald-600 enabled:hover:text-emerald-700",
"text-sky-600 enabled:hover:text-sky-700",
"text-blue-600 enabled:hover:text-blue-700",
"text-purple-600 enabled:hover:text-purple-700",
"text-pink-600 enabled:hover:text-pink-700",
"text-rose-600 enabled:hover:text-rose-700"
];

// More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction
const meta: Meta<typeof TextButton> = {
title: "Components/Button/Text",
component: TextButton,
tags: ["autodocs"],
argTypes: {},
render: (args) => (
<div className="flex flex-wrap gap-2">
{variants.map((variant) => (
<TextButton
{...args}
key={variant}
className={variant}
/>
))}
</div>
)
};

export default meta;
type Story = StoryObj<typeof TextButton>;

// More on writing stories with args: https://storybook.js.org/docs/react/writing-stories/args
export const NoIcon: Story = {
args: {
children: "Button"
}
};

export const WithLeftIcon: Story = {
args: {
children: "Home",
LeftIcon: Home
}
};

export const WithRightIcon: Story = {
args: {
children: "Continue",
RightIcon: ArrowRight
}
};
6 changes: 5 additions & 1 deletion apps/client/src/components/Button/Text.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ButtonHTMLAttributes, FC } from "react";
import clsx from "clsx";
import { LucideIcon } from "lucide-react";

interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
Expand All @@ -17,7 +18,10 @@ export const TextButton: FC<ButtonProps> = ({
}) => {
return (
<button
className={`group flex items-center justify-center gap-x-1 rounded-lg p-2 font-medium text-primary-600 outline-none transition-all duration-150 focus:ring-2 focus:ring-primary-400 focus:ring-offset-2 focus:ring-offset-gray-200 enabled:hover:text-primary-700 disabled:opacity-60 dark:focus:ring-offset-gray-900 ${className}`}
className={clsx(
`group flex items-center justify-center gap-x-1 rounded-lg p-2 font-medium text-primary-600 outline-none transition-all duration-150 focus:ring-2 focus:ring-primary-400 focus:ring-offset-2 focus:ring-offset-gray-200 enabled:hover:text-primary-700 disabled:opacity-60 dark:focus:ring-offset-gray-900`,
className
)}
{...rest}
>
{LeftIcon ? <LeftIcon className={`h-4 w-4 ${iconClassName}`} /> : null}
Expand Down
6 changes: 5 additions & 1 deletion apps/client/src/components/Button/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ButtonHTMLAttributes, FC } from "react";
import clsx from "clsx";
import { LucideIcon } from "lucide-react";

interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
Expand All @@ -17,7 +18,10 @@ export const Button: FC<ButtonProps> = ({
}) => {
return (
<button
className={`group flex items-center justify-center gap-x-1 rounded-lg bg-primary-600 p-2 font-medium text-white outline-none transition-all duration-150 focus:ring-2 focus:ring-primary-400 focus:ring-offset-2 focus:ring-offset-gray-200 enabled:hover:bg-primary-700 disabled:opacity-60 dark:focus:ring-offset-gray-900 ${className}`}
className={clsx(
`group flex items-center justify-center gap-x-1 rounded-lg bg-primary-600 p-2 font-medium text-white outline-none transition-all duration-150 focus:ring-2 focus:ring-primary-400 focus:ring-offset-2 focus:ring-offset-gray-200 enabled:hover:bg-primary-700 disabled:opacity-60 dark:focus:ring-offset-gray-900`,
className
)}
{...rest}
>
{LeftIcon ? <LeftIcon className={`h-4 w-4 ${iconClassName}`} /> : null}
Expand Down

0 comments on commit 787bfa3

Please sign in to comment.