Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add storybook #74

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"next/core-web-vitals"
"next/core-web-vitals",
"plugin:storybook/recommended"
],
"rules": {
"react/prop-types": 0,
Expand Down
23 changes: 23 additions & 0 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type { StorybookConfig } from "@storybook/nextjs";

const config: StorybookConfig = {
// Stories and Components location
stories: [
"../components/**/*.mdx",
"../components/**/*.stories.@(js|jsx|mjs|ts|tsx)"
],
addons: [
"@storybook/addon-links",
"@storybook/addon-essentials",
"@storybook/addon-onboarding",
"@storybook/addon-interactions",
],
framework: {
name: "@storybook/nextjs",
options: {},
},
docs: {
autodocs: "tag",
},
};
export default config;
17 changes: 17 additions & 0 deletions .storybook/preview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import type { Preview } from "@storybook/react";
// Add any used css here
import "../styles/globals.css"

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

export default preview;
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@

- Simple form validation with [React Hook Form](https://react-hook-form.com/get-started), designed to be [integrated with Ant Design](https://react-hook-form.com/get-started#IntegratingControlledInputs) and [Zod](https://react-hook-form.com/get-started#SchemaValidation)

- Interactive documentation with [Storybook](https://storybook.js.org/)

- Provide sane defaults for the most common security headers

## Getting Started
Expand All @@ -62,7 +64,7 @@ To display Tailwind CSS IntelliSense in Visual Studio Code, install [the officia

### `components` Folder

Place reusable React components in this folder.
Place reusable React components and Storybook stories in this folder.

It is recommended to develop using [function components](https://reactjs.org/docs/components-and-props.html) with [hooks](https://reactjs.org/docs/hooks-intro.html) instead of class components.

Expand Down Expand Up @@ -91,6 +93,16 @@ Components should be styled with one of these techniques, sorted from the most r

> :warning: Due to the global nature of stylesheets, and to avoid conflicts, they may not be imported from pages / components.

### Making Component's Documentations

Components should be documented by using [Storybook](https://storybook.js.org/) by making a stories for each component.

Run the Storybook with command:

```sh
npm run storybook
```

### `functions` Folder

Place reusable plain JS functions in this folder.
Expand Down
51 changes: 51 additions & 0 deletions components/Buttons.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import {AButton} from './Buttons';

// More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
export default {
// Name of the component for the stories
component: AButton,

// Stories Title
title: 'AButton',

// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/react/writing-docs/autodocs
tags: ['autodocs'],

// Add documentation for each args. More on argTypes: https://storybook.js.org/docs/react/api/argtypes
argTypes: {
text:{
description:"Button Text"
},
type:{
control:"select",
options:["button","submit","reset"],
description:"Button Type"
},
disabled:{
control:"boolean",
description:"Button disabled or not"
},
}
};

// More on writing stories with args: https://storybook.js.org/docs/react/writing-stories/args
export const Default = {
// Args for the component
args:{
text: "Default",
type: "button"
}
};
export const Submit = {
args:{
text: "Submit",
type: "submit"
}
};
export const Reset = {
args:{
text: "Reset",
type: "reset"
}
};

Loading
Loading