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

feat: storybook setup, chromatic setup and typography stories #3015

Merged
merged 31 commits into from
Jul 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
b918193
installed storybook
devilkiller-ag May 30, 2024
a111d63
removed bolierplate storybook code
devilkiller-ag May 31, 2024
9d73b60
added stories for headings
devilkiller-ag May 31, 2024
08f4cfd
setup autodocs with custom template
devilkiller-ag May 31, 2024
1fca89c
added chromatic workflow
devilkiller-ag Jun 1, 2024
06683d8
added stories for paragraph
devilkiller-ag Jun 1, 2024
fbd3fac
Merge branch 'master' into master
devilkiller-ag Jun 1, 2024
5d1eeb6
added color pallete
devilkiller-ag Jun 2, 2024
2dd1848
Merge branch 'asyncapi:master' into master
devilkiller-ag Jun 4, 2024
397b277
Merge branch 'master' of https://github.com/devilkiller-ag/asyncapi-w…
devilkiller-ag Jun 4, 2024
b819469
added suggusted changes
devilkiller-ag Jun 4, 2024
1ca5032
Experimenting chromatic workflow
devilkiller-ag Jun 4, 2024
b4b240c
added suggusted changes
devilkiller-ag Jun 4, 2024
4d71250
removed error causing design token
devilkiller-ag Jun 4, 2024
96e466f
changed storybook build script name
devilkiller-ag Jun 4, 2024
ae10eb7
updated chromatic workflow trigger action
devilkiller-ag Jun 4, 2024
4aa483e
added suggested changes
devilkiller-ag Jun 8, 2024
1ded72b
updated headings jsdoc according to the requirements of storybook
devilkiller-ag Jun 10, 2024
91a3c5b
retified tailwind css
devilkiller-ag Jun 10, 2024
828d4bb
fix eslint issues and removed chromatic
devilkiller-ag Jun 11, 2024
e1e5a2f
Merge remote-tracking branch 'upstream/master'
devilkiller-ag Jun 11, 2024
36766ed
Merge branch 'master' into master
devilkiller-ag Jun 11, 2024
4373a18
removed chromatic related code
devilkiller-ag Jun 15, 2024
fa87688
Merge branch 'master' into master
devilkiller-ag Jun 15, 2024
0d29b55
Update .storybook/main.ts
akshatnema Jun 16, 2024
aee9ad8
Updated readme file withstorybook commands
devilkiller-ag Jun 16, 2024
3cf06f8
Merge branch 'master' of https://github.com/devilkiller-ag/asyncapi-w…
devilkiller-ag Jun 16, 2024
e8c54e1
Merge branch 'master' into master
devilkiller-ag Jun 17, 2024
569dc20
Merge branch 'master' into master
devilkiller-ag Jun 22, 2024
9359a2d
resolved merge conflicts
devilkiller-ag Jun 29, 2024
50c7ee6
Merge branch 'master' into master
devilkiller-ag Jul 6, 2024
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
27 changes: 20 additions & 7 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"airbnb-base",
"next/core-web-vitals",
"eslint:recommended",
"plugin:prettier/recommended"
"plugin:prettier/recommended",
"plugin:storybook/recommended"
],
"env": {
"browser": true,
Expand Down Expand Up @@ -52,7 +53,11 @@
"overrides": [
// Configuration for TypeScript files
{
"files": ["**/*.ts", "**/*.tsx", "netlify/*.ts"],
"files": [
"**/*.ts",
"**/*.tsx",
"netlify/*.ts"
],
"plugins": [
"@typescript-eslint",
"tailwindcss",
Expand All @@ -63,7 +68,8 @@
"plugin:tailwindcss/recommended",
"airbnb-typescript",
"next/core-web-vitals",
"plugin:prettier/recommended"
"plugin:prettier/recommended",
"plugin:storybook/recommended"
],
"parserOptions": {
"project": "./tsconfig.json"
Expand Down Expand Up @@ -93,7 +99,9 @@
"unused-imports/no-unused-imports": "error",
"unused-imports/no-unused-vars": [
"error",
{ "argsIgnorePattern": "^_" }
{
"argsIgnorePattern": "^_"
}
],
// Variables
"init-declarations": "off",
Expand Down Expand Up @@ -192,7 +200,10 @@
"ignoreChainWithDepth": 4
}
],
"newline-after-var": ["error", "always"],
"newline-after-var": [
"error",
"always"
],
"no-array-constructor": "error",
"no-lonely-if": "error",
"no-mixed-operators": "off",
Expand Down Expand Up @@ -294,10 +305,12 @@
}
},
{
"files": ["components/logos/*"],
"files": [
"components/logos/*"
],
"rules": {
"max-len": "off"
}
}
]
}
}
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ cypress/screenshots
cypress/videos
/config/finance/json-data/*
*.mdx
coverage
*storybook.log
/storybook-static/
coverage
22 changes: 22 additions & 0 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import type { StorybookConfig } from "@storybook/nextjs";

const config: StorybookConfig = {
stories: [
"../components/**/*.stories.@(js|jsx|mjs|ts|tsx)",
],
addons: [
"@storybook/addon-onboarding",
"@storybook/addon-links",
"@storybook/addon-essentials",
"@storybook/addon-interactions",
],
docs: {
defaultName: 'Documentation',
},
framework: {
name: "@storybook/nextjs",
options: {},
},
staticDirs: ["../public"],
};
export default config;
40 changes: 40 additions & 0 deletions .storybook/preview.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React from "react";
import "../styles/globals.css";
import type { Preview } from "@storybook/react";
import {
Title,
Subtitle,
Description,
Primary,
Controls,
Stories,
} from '@storybook/blocks';

const preview: Preview = {
tags: ['autodocs'],
parameters: {
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/i,
},
},
docs: {
toc: {
title: 'Table of contents',
},
page: () => (
<>
<Title />
<Subtitle />
<Description />
<Primary />
<Controls />
<Stories />
</>
)
}
}
};

export default preview;
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ This repository contains the sources of AsyncAPI website:

- It's powered by [Next.js](https://nextjs.org/),
- It uses [Tailwind](https://tailwindcss.com/) CSS framework,
- It's build and deployed with [Netlify](https://www.netlify.com/).
- It's build and deployed with [Netlify](https://www.netlify.com/),
- It uses [Storybook](https://storybook.js.org/) as a frontend workshop and for dociuenting UI components.

## Requirements

Expand Down Expand Up @@ -69,6 +70,14 @@ Use the following tools to set up the project:

7. Access the live development server at [localhost:3000](http://localhost:3000).

8. To run the storybook locally:

```bash
npm run dev:storybook
```

9. Access the live storybook development server at [localhost:6006](http://localhost:6006).


## Compose new blog post

Expand All @@ -88,14 +97,22 @@ To spin up a Gitpod codespace, go to http://gitpod.io/#https://github.com/asynca

### Build

To build a production-ready website, run the following command:
1. To build a production-ready website, run the following command:

```bash
npm run build
```

Generated files of the website go to the `.next` folder.

2. To build the production-ready storybook, run the following command:

```bash
npm run build:storybook
```

Generated files of the storybook go to the `storybook-static` folder.

### Run locally using Docker

#### Prerequisites:
Expand Down
76 changes: 76 additions & 0 deletions components/typography/Heading.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import type { Meta, StoryObj } from '@storybook/react';
import React from 'react';

import { HeadingLevel, HeadingTypeStyle } from '@/types/typography/Heading';

import Heading from './Heading';

const meta: Meta<typeof Heading> = {
title: 'Typography/Heading',
component: Heading,
argTypes: {
level: {
options: Object.values(HeadingLevel),
control: { type: 'select' }
},
typeStyle: {
options: Object.values(HeadingTypeStyle),
control: { type: 'select' }
},
children: {
control: { type: 'text' }
},
className: {
control: { type: 'text' }
},
textColor: {
table: {
disable: true
}
},
id: {
table: {
disable: true
}
}
}
};

export default meta;

type Story = StoryObj<typeof Heading>;

export const Headings: Story = {
args: {
level: HeadingLevel.h1,
typeStyle: HeadingTypeStyle.lg,
children: 'Quick brown fox jumps over the lazy dog'
}
};

export const HeadingsLevel = () => (
<>
<Heading level={HeadingLevel.h1}>Heading 1</Heading>
<Heading level={HeadingLevel.h2}>Heading 2</Heading>
<Heading level={HeadingLevel.h3}>Heading 3</Heading>
<Heading level={HeadingLevel.h4}>Heading 4</Heading>
<Heading level={HeadingLevel.h5}>Heading 5</Heading>
<Heading level={HeadingLevel.h6}>Heading 6</Heading>
</>
);

export const HeadingsTypeStyle = () => (
<>
<Heading typeStyle={HeadingTypeStyle.xl}>Heading XL</Heading>
<Heading typeStyle={HeadingTypeStyle.lg}>Heading LG</Heading>
<Heading typeStyle={HeadingTypeStyle.md}>Heading MD</Heading>
<Heading typeStyle={HeadingTypeStyle.mdSemibold}>Heading MD Semibold</Heading>
<Heading typeStyle={HeadingTypeStyle.sm}>Heading SM</Heading>
<Heading typeStyle={HeadingTypeStyle.smSemibold}>Heading SM Semibold</Heading>
<Heading typeStyle={HeadingTypeStyle.xs}>Heading XS</Heading>
<Heading typeStyle={HeadingTypeStyle.xsSemibold}>Heading XS Semibold</Heading>
<Heading typeStyle={HeadingTypeStyle.bodyLg}>Body LG</Heading>
<Heading typeStyle={HeadingTypeStyle.bodyMd}>Body MD</Heading>
<Heading typeStyle={HeadingTypeStyle.bodySm}>Body SM</Heading>
</>
);
21 changes: 14 additions & 7 deletions components/typography/Heading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,29 @@ import React from 'react';
import { HeadingLevel, HeadingTypeStyle } from '@/types/typography/Heading';

export interface HeadingProps {
// eslint-disable-next-line prettier/prettier

/** Contains the type of heading style. HeadingTypeStyle.lg is default */
typeStyle?: HeadingTypeStyle;

/** Contains the level of heading. HeadingLevel.h2 is by default */
level?: HeadingLevel;

/** Contains text color for the heading. 'text-primary-800' is by default */
textColor?: string;

/** Contains additional classes that should be added to the component */
className?: string;

/** Contains all the child elements bounded inside component */
children?: React.ReactNode;

/** Contains an id to be appended on heading */
id?: string;
}

/**
* Heading
* @param {HeadingTypeStyle} props.typeStyle contains the type of heading style. HeadingTypeStyle.lg is default
* @param {HeadingLevel} props.level contains the level of heading. HeadingLevel.h2 is by default
* @param {string} props.textColor contains text color for the heading. 'text-primary-800' is by default
* @param {string} props.className contains additional classes that should be added to the component
* @param {React.ReactNode} props.children contains all the child elements bounded inside component
* @param {string} props.id contains an id to be appended on heading
* Heading component is used to render a heading element with different styles and sizes.
*/
export default function Heading({
typeStyle = HeadingTypeStyle.lg,
Expand Down
41 changes: 41 additions & 0 deletions components/typography/Paragraph.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import type { Meta, StoryObj } from '@storybook/react';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why there are no warnings for ESLint in these files for adding Jsdoc comments?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't get this point, I haven't added any JSDoc in this file.


import { ParagraphTypeStyle } from '@/types/typography/Paragraph';

import Paragraph from './Paragraph';

const meta: Meta<typeof Paragraph> = {
title: 'Typography/Paragraph',
component: Paragraph,
argTypes: {
typeStyle: {
options: Object.values(ParagraphTypeStyle),
control: { type: 'select' }
},
textColor: {
control: { type: 'text' }
},
fontWeight: {
control: { type: 'text' }
},
children: {
control: { type: 'text' }
},
className: {
control: { type: 'text' }
}
}
};

export default meta;

type Story = StoryObj<typeof Paragraph>;

export const Paragraphs: Story = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we using these objects/functions anywhere else? If not, then why are we exporting it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we aren't using it manually. But storybook needs to have stories exported (Resource 1 | Resource 2). If we don't have stories exported they won't show up in the storybook.

args: {
typeStyle: ParagraphTypeStyle.lg,
textColor: 'text-gray-700',
fontWeight: '',
children: 'Quick brown fox jumps over the lazy dog'
}
};
18 changes: 12 additions & 6 deletions components/typography/Paragraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,26 @@ import { twMerge } from 'tailwind-merge';
import { ParagraphTypeStyle } from '@/types/typography/Paragraph';

export interface ParagraphProps {
// eslint-disable-next-line prettier/prettier

/** Contains the type of paragraph style. ParagraphTypeStyle.lg is by default */
typeStyle?: ParagraphTypeStyle;

/** Contains text color for the paragraph. 'text-gray-700' is by default */
textColor?: string;

/** Contains class name for applying font weight in the paragraph */
fontWeight?: string;

/** Contains additional classes that should be added to the component */
className?: string;

/** Contains all the child elements bounded inside component */
children?: React.ReactNode;
}

/**
* Paragraph
* @param {ParagraphTypeStyle} props.typeStyle contains the type of paragraph style. ParagraphTypeStyle.lg is by default
* @param {string} props.textColor contains text color for the paragraph. 'text-gray-700' is by default
* @param {string} props.fontWeight contains class name for applying font weight in the paragraph
* @param {string} props.className contains additional classes that should be added to the component
* @param {React.ReactNode} props.children contains all the child elements bounded inside component
* Paragraph component is used to render a paragraph element with different type of styles.
*/
export default function Paragraph({
typeStyle = ParagraphTypeStyle.lg,
Expand Down
Loading
Loading