Skip to content

Commit

Permalink
Merge pull request #287 from Maakaf/285-add-storybook
Browse files Browse the repository at this point in the history
Setup storybook
  • Loading branch information
Darkmift authored May 19, 2024
2 parents 54644af + da08c47 commit 1744207
Show file tree
Hide file tree
Showing 32 changed files with 15,610 additions and 4,508 deletions.
8 changes: 6 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{
"extends": ["next/core-web-vitals", "prettier"],
"ignorePatterns": ["node_modules/**/*"]
"extends": [
"next/core-web-vitals",
"prettier",
"plugin:storybook/recommended"
],
"ignorePatterns": ["node_modules/**/*", "stories/**/*"]
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,5 @@ next-env.d.ts
/playwright-report/
/blob-report/
/playwright/.cache/

*storybook.log
21 changes: 21 additions & 0 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import type { StorybookConfig } from '@storybook/nextjs';

const config: StorybookConfig = {
stories: [
'../stories/**/*.mdx',
'../stories/**/*.stories.@(js|jsx|mjs|ts|tsx)',
],
addons: [
'@storybook/addon-onboarding',
'@storybook/addon-links',
'@storybook/addon-essentials',
'@chromatic-com/storybook',
'@storybook/addon-interactions',
],
framework: {
name: '@storybook/nextjs',
options: {},
},
staticDirs: ['../public'],
};
export default config;
14 changes: 14 additions & 0 deletions .storybook/preview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type { Preview } from '@storybook/react';

const preview: Preview = {
parameters: {
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/i,
},
},
},
};

export default preview;
19,137 changes: 14,634 additions & 4,503 deletions package-lock.json

Large diffs are not rendered by default.

19 changes: 16 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
"test": "npx playwright install && npx playwright test",
"prepush": "npm run test",
"test-result": "npx playwright show-report",
"precommit": "lint-staged && npm run lint"
"precommit": "lint-staged && npm run lint",
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build"
},
"lint-staged": {
"*.{js,jsx,ts,tsx,css,md,json,scss}": [
Expand Down Expand Up @@ -50,17 +52,28 @@
"zod": "^3.22.4"
},
"devDependencies": {
"@chromatic-com/storybook": "^1.4.0",
"@playwright/test": "^1.42.1",
"@storybook/addon-essentials": "^8.1.1",
"@storybook/addon-interactions": "^8.1.1",
"@storybook/addon-links": "^8.1.1",
"@storybook/addon-onboarding": "^8.1.1",
"@storybook/blocks": "^8.1.1",
"@storybook/nextjs": "^8.1.1",
"@storybook/react": "^8.1.1",
"@storybook/test": "^8.1.1",
"@svgr/webpack": "^8.1.0",
"@types/node": "^20.6.0",
"@types/react": "^18.2.21",
"@types/react-dom": "^18.2.7",
"eslint-config-next": "^13.4.7",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-storybook": "^0.8.0",
"husky": "^8.0.3",
"lint-staged": "^14.0.1",
"prettier": "^3.0.3",
"prettier-plugin-tailwindcss": "^0.4.1",
"pretty-quick": "^3.1.3"
"pretty-quick": "^3.1.3",
"storybook": "^8.1.1"
}
}
}
52 changes: 52 additions & 0 deletions stories/Button.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import type { Meta, StoryObj } from '@storybook/react';
import { fn } from '@storybook/test';
import { Button } from './Button';

// More on how to set up stories at: https://storybook.js.org/docs/writing-stories#default-export
const meta = {
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' },
},
// 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<typeof Button>;

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

// 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: 'Button',
},
};

export const Large: Story = {
args: {
size: 'large',
label: 'Button',
},
};

export const Small: Story = {
args: {
size: 'small',
label: 'Button',
},
};
56 changes: 56 additions & 0 deletions stories/Button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import React from 'react';
import './button.css';

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 Button = ({
primary = false,
size = 'medium',
backgroundColor,
label,
...props
}: ButtonProps) => {
const mode = primary
? 'storybook-button--primary'
: 'storybook-button--secondary';
return (
<button
type="button"
className={['storybook-button', `storybook-button--${size}`, mode].join(
' '
)}
{...props}
>
{label}
<style jsx>{`
button {
background-color: ${backgroundColor};
}
`}</style>
</button>
);
};
Loading

0 comments on commit 1744207

Please sign in to comment.