Skip to content

Commit

Permalink
feat: introduce component storybooks (#73)
Browse files Browse the repository at this point in the history
* feat: basic button story

* feat: basic checkbox story

* feat: basic input story

* chore: update settings.json source.fixAll.eslint with latest vscode version

* chore: reduce stories layer

* chore: use render instead of decorator

* fix: next/font in storybook

* chore: remove default addons included in essentials

* chore: set default story sorting to alphabetical

* chore: tsconfig ignore .next

* chore: upgrade storybook to latest

* refactor: button storybook remove unused vars

* refactor: checkbox story add default args

* feat: command story

* feat: corelayout story

* feat: heading story

* feat: input story

* feat: lockctaoverlay story

* feat: logo story

* feat: mobileheader story

* feat: modal story

* feat: popover story

* feat: ratingsection story

* feat: reviewitem story

* feat: sidebar story

* feat: sidebaritem story

* feat: statitem story

* feat: tag story

* feat: reviews combobox story

* chore: yarn clean up

* chore: add chromatic ci action for storybooks

* chore: chromatic action with env vars

* chore: update chromatic ci action options

* refactor: import used as type only

* chore: remove layout stories

* chore: remove unused comments

---------

Co-authored-by: Zachery Ng <zachery.ng@gmail.com>
  • Loading branch information
davidlhw and Aztriltus authored Mar 10, 2024
1 parent 0e57563 commit b4b8a38
Show file tree
Hide file tree
Showing 27 changed files with 9,631 additions and 1,175 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# https://www.prisma.io/docs/reference/database-reference/connection-urls#env
# DATABASE_URL="file:./db.sqlite"
# Connect to Supabase with PgBouncer.
DATABASE_URL="postgres://DB_USER:DB_PASSWORD@DB_URL:DB_PORT/DB_NAME?pgbouncer=true"
DATABASE_URL="postgres://DB_USER:DB_PASSWORD@localhost:6543/DB_NAME?pgbouncer=true"

# Direct connection to the database. Used for migrations.
DIRECT_URL="postgres://DB_USER:DB_PASSWORD@DB_URL:DB_PORT/DB_NAME"
Expand Down
34 changes: 34 additions & 0 deletions .github/workflows/chromatic.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: "Chromatic"

on:
push:
branches:
- 'main'
pull_request:
types: [opened, reopened, synchronize]

jobs:
chromatic:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: copy .env file
run: cp .env.example .env

- name: Install dependencies
run: yarn install --immutable --immutable-cache --check-cache

- name: Publish to Chromatic
uses: chromaui/action@latest
with:
projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
onlyChanged: true
exitOnceUploaded: true
autoAcceptChanges: main
fromCI: true
# Skip running Chromatic on dependabot PRs
skip: dependabot/**
20 changes: 20 additions & 0 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { StorybookConfig } from "@storybook/nextjs";

const config: StorybookConfig = {
stories: ["../src/**/*.mdx", "../src/**/*.stories.@(js|jsx|mjs|ts|tsx)"],
addons: ["@storybook/addon-essentials", "@storybook/addon-themes"],
framework: {
name: "@storybook/nextjs",
options: {},
},
docs: {
autodocs: true,
},
staticDirs: [
{
from: "../public",
to: "public",
},
],
};
export default config;
55 changes: 55 additions & 0 deletions .storybook/preview.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import type { Preview, StoryFn } from "@storybook/react";
import { withThemeByClassName } from "@storybook/addon-themes";
import "../src/common/styles/globals.scss";
import { inter, poppins } from "../src/common/fonts";

const preview: Preview = {
parameters: {
// actions: { argTypesRegex: "^on[A-Z].*" },
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/i,
},
},
layout: "fullscreen",
options: {
storySort: {
method: "alphabetical",
},
},
},
decorators: [
(Story: StoryFn) => (
<>
{/* @ts-ignore */}
<style global jsx>{`
:root {
--font-inter: ${inter.style.fontFamily};
--font-poppins: ${poppins.style.fontFamily};
}
`}</style>
<div
style={{
padding: "3rem",
display: "flex",
alignItems: "center",
justifyContent: "center",
}}
className={`bg-bg-base`}
>
<Story />
</div>
</>
),
withThemeByClassName({
themes: {
light: "light",
dark: "dark",
},
defaultTheme: "light",
}),
],
};

export default preview;
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
},
"editor.rulers": [80],
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
"source.fixAll.eslint": "explicit"
},
// Show in vscode "Problems" tab when there are errors
"typescript.tsserver.experimental.enableProjectDiagnostics": true,
Expand Down
29 changes: 26 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"dev": "next dev",
"postinstall": "prisma generate",
"lint": "next lint",
"start": "next start"
"start": "next start",
"storybook": "storybook dev -p 6006 --no-open",
"build-storybook": "storybook build"
},
"dependencies": {
"@ctrl/tinycolor": "^4.0.2",
Expand All @@ -33,7 +35,7 @@
"react": "18.2.0",
"react-dom": "18.2.0",
"react-hook-form": "^7.49.2",
"sass": "^1.66.1",
"sass": "^1.71.0",
"server-only": "^0.0.1",
"superjson": "^2.2.1",
"tailwind-variants": "^0.1.14",
Expand All @@ -42,6 +44,17 @@
"devDependencies": {
"@iconify-icon/react": "^1.0.8",
"@next/eslint-plugin-next": "^14.0.3",
"@storybook/addon-actions": "^7.6.17",
"@storybook/addon-essentials": "^7.6.17",
"@storybook/addon-interactions": "^7.6.17",
"@storybook/addon-links": "^7.6.17",
"@storybook/addon-onboarding": "^1.0.11",
"@storybook/addon-themes": "^7.6.17",
"@storybook/blocks": "^7.6.17",
"@storybook/nextjs": "^7.6.17",
"@storybook/preset-scss": "^1.0.3",
"@storybook/react": "^7.6.17",
"@storybook/test": "^7.6.17",
"@types/eslint": "^8.44.7",
"@types/node": "^18.17.0",
"@types/prettier": "^2.7.2",
Expand All @@ -50,17 +63,27 @@
"@typescript-eslint/eslint-plugin": "^6.11.0",
"@typescript-eslint/parser": "^6.11.0",
"autoprefixer": "^10.4.14",
"chromatic": "^11.0.0",
"css-loader": "^6.10.0",
"eslint": "^8.54.0",
"eslint-config-next": "^14.0.3",
"eslint-plugin-storybook": "^0.8.0",
"postcss": "^8.4.31",
"prettier": "^3.1.0",
"prettier-plugin-tailwindcss": "^0.5.7",
"prisma": "^5.6.0",
"sass-loader": "^14.1.1",
"storybook": "^7.6.17",
"style-loader": "^3.3.4",
"tailwindcss": "^3.4.1",
"tailwindcss-animate": "^1.0.7",
"typescript": "^5.3.2"
"typescript": "^5.3.2",
"webpack": "^5.0.0"
},
"ct3aMetadata": {
"initVersion": "7.15.0"
},
"resolutions": {
"jackspeak": "2.1.1"
}
}
167 changes: 167 additions & 0 deletions src/common/components/Button/Button.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
import type { Meta, StoryObj } from "@storybook/react";

import { Button } from "./Button";
import { StarLineAltIcon } from "@/common/components/CustomIcon";

// More on how to set up stories at: https://storybook.js.org/docs/writing-stories#default-export
const meta = {
title: "Common/Button",
component: Button,
// 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: {
fullWidth: {
control: {
type: "boolean",
},
},
loading: {
control: {
type: "boolean",
},
},
rounded: {
control: {
type: "boolean",
},
},
},
args: {
variant: "primary",
size: "md",
children: "primary",
as: "a",
href: "https://example.com",
external: true,
loading: false,
isResponsive: false,
fullWidth: false,
rounded: false,
},
} satisfies Meta<typeof Button>;

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

export const Default: Story = {};

// More on writing stories with args: https://storybook.js.org/docs/writing-stories/args
const VariantsOfButtonTemplate: Story = {
render: ({ variant }) => (
<div className="flex max-w-[320px] flex-wrap gap-3">
<Button variant={variant}>{variant as string}</Button>
<Button variant={variant} size="sm" iconLeft={<StarLineAltIcon />}>
Small
</Button>
<Button
variant={variant}
aria-label="star"
iconLeft={<StarLineAltIcon />}
/>
<Button
variant={variant}
size="sm"
aria-label="star"
iconLeft={<StarLineAltIcon />}
/>
<Button variant={variant} loading>
{variant as string}
</Button>
<Button
variant={variant}
size="sm"
iconLeft={<StarLineAltIcon />}
loading
>
Small
</Button>
<Button
variant={variant}
aria-label="star"
iconLeft={<StarLineAltIcon />}
loading
/>
<Button
variant={variant}
size="sm"
aria-label="star"
iconLeft={<StarLineAltIcon />}
loading
/>
<Button variant={variant} disabled>
{variant as string}
</Button>
<Button
variant={variant}
size="sm"
iconLeft={<StarLineAltIcon />}
disabled
>
Small
</Button>
<Button
variant={variant}
aria-label="star"
iconLeft={<StarLineAltIcon />}
disabled
/>
<Button
variant={variant}
size="sm"
aria-label="star"
iconLeft={<StarLineAltIcon />}
disabled
/>
</div>
),
};

export const VariantsOfPrimary: Story = {
...VariantsOfButtonTemplate,
args: {
variant: "primary",
},
};

export const VariantsOfSecondary: Story = {
...VariantsOfButtonTemplate,
args: {
variant: "secondary",
},
};

export const VariantsOfTertiary: Story = {
...VariantsOfButtonTemplate,
args: {
variant: "tertiary",
},
};

export const VariantsOfSuccess: Story = {
...VariantsOfButtonTemplate,
args: {
variant: "success",
},
};

export const VariantsOfDanger: Story = {
...VariantsOfButtonTemplate,
args: {
variant: "danger",
},
};

export const VariantsOfGhost: Story = {
...VariantsOfButtonTemplate,
args: {
variant: "ghost",
},
};

export const VariantsOfLink: Story = {
...VariantsOfButtonTemplate,
args: {
variant: "link",
},
};
Loading

0 comments on commit b4b8a38

Please sign in to comment.