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: add storybook to nextjs-app #5432

Open
wants to merge 6 commits into
base: main
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: 1 addition & 2 deletions apps/nextjs-app/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ module.exports = {
'@your-org/eslint-config-bases/react',
'@your-org/eslint-config-bases/tailwind',
'@your-org/eslint-config-bases/rtl',
// Add specific rules for nextjs
'@your-org/eslint-config-bases/storybook',
'plugin:@next/next/core-web-vitals',
// Apply prettier and disable incompatible rules
'@your-org/eslint-config-bases/prettier-plugin',
],
rules: {
Expand Down
2 changes: 2 additions & 0 deletions apps/nextjs-app/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ yarn-error.log*

# Sentry
.sentryclirc

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

import { join, dirname } from 'path';

/**
* This function is used to resolve the absolute path of a package.
* It is needed in projects that use Yarn PnP or are set up within a monorepo.
*/
function getAbsolutePath(value: string): any {
return dirname(require.resolve(join(value, 'package.json')));
}
const config: StorybookConfig = {
stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
addons: [
getAbsolutePath('@storybook/addon-onboarding'),
getAbsolutePath('@storybook/addon-links'),
getAbsolutePath('@storybook/addon-essentials'),
getAbsolutePath('@chromatic-com/storybook'),
getAbsolutePath('@storybook/addon-interactions'),
],
framework: {
name: getAbsolutePath('@storybook/nextjs'),
options: {},
},
docs: {
autodocs: 'tag',
},
staticDirs: ['../public'],
};
export default config;
14 changes: 14 additions & 0 deletions apps/nextjs-app/.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 changes: 15 additions & 4 deletions apps/nextjs-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,17 @@
"check-size": "size-limit --highlight-less",
"clean": "rimraf ./.next ./.out ./coverage ./tsconfig.tsbuildinfo ./node_modules/.cache",
"dev": "next",
"fix-all-files": "eslint . --ext .ts,.tsx,.js,.jsx,.cjs,.mjs,.mdx,.graphql --fix",
"fix-all-files": "eslint . --ext .ts,.tsx,.js,.jsx,.cjs,.mjs,.graphql --fix",
"flamegraph-home": "npx 0x --output-dir './.debug/flamegraph/{pid}.0x' --on-port 'autocannon http://localhost:$PORT --duration 20' -- node ../../node_modules/.bin/next start",
"lint": "eslint . --ext .ts,.tsx,.js,.jsx,.cjs,.mjs,.mdx,.graphql --cache --cache-location ../../.cache/eslint/nextjs-app.eslintcache",
"lint": "eslint . --ext .ts,.tsx,.js,.jsx,.cjs,.mjs,.graphql --cache --cache-location ../../.cache/eslint/nextjs-app.eslintcache",
"start": "next start",
"test": "yarn test-unit",
"test-e2e": "cross-env E2E_WEBSERVER_MODE=BUILD_AND_START playwright test",
"test-unit": "vitest run",
"test-unit-watch": "vitest watch --ui",
"typecheck": "tsc --project ./tsconfig.json --noEmit"
"typecheck": "tsc --project ./tsconfig.json --noEmit",
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build"
},
"browserslist": {
"production": [
Expand Down Expand Up @@ -118,6 +120,14 @@
"@playwright/test": "1.43.1",
"@prisma/nextjs-monorepo-workaround-plugin": "5.13.0",
"@size-limit/file": "11.1.2",
"@storybook/addon-essentials": "8.0.9",
"@storybook/addon-interactions": "8.0.9",
"@storybook/addon-links": "8.0.9",
"@storybook/addon-onboarding": "8.0.9",
"@storybook/blocks": "8.0.9",
"@storybook/nextjs": "8.0.9",
"@storybook/react": "8.0.9",
"@storybook/test": "8.0.9",
"@svgr/webpack": "8.1.0",
"@tailwindcss/forms": "0.5.7",
"@tailwindcss/typography": "0.5.13",
Expand All @@ -142,8 +152,8 @@
"eslint": "8.57.0",
"eslint-config-next": "14.2.3",
"eslint-plugin-tailwindcss": "3.15.1",
"happy-dom": "14.7.1",
"is-ci": "3.0.1",
"jsdom": "24.0.0",
"npm-run-all2": "6.1.2",
"postcss": "8.4.38",
"postcss-flexbugs-fixes": "5.0.2",
Expand All @@ -152,6 +162,7 @@
"react-test-renderer": "18.3.1",
"rimraf": "5.0.5",
"size-limit": "11.1.2",
"storybook": "8.0.9",
"tailwindcss": "3.4.3",
"typescript": "5.4.5",
"vite": "5.2.11",
Expand Down
52 changes: 52 additions & 0 deletions apps/nextjs-app/src/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',
},
};
55 changes: 55 additions & 0 deletions apps/nextjs-app/src/stories/Button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
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>{`
button {
background-color: ${backgroundColor};
}
`}</style>
</button>
);
};
171 changes: 171 additions & 0 deletions apps/nextjs-app/src/stories/Configure.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
import { Meta } from '@storybook/blocks';

<Meta title="Configure your project" />

<div className="sb-container">
<div className='sb-section-title'>
# Configure your project

Because Storybook works separately from your app, you'll need to configure it for your specific stack and setup. Below, explore guides for configuring Storybook with popular frameworks and tools. If you get stuck, learn how you can ask for help from our community.

</div>

</div>

<style>
{`
.sb-container {
margin-bottom: 48px;
}

.sb-section {
width: 100%;
display: flex;
flex-direction: row;
gap: 20px;
}

img {
object-fit: cover;
}

.sb-section-title {
margin-bottom: 32px;
}

.sb-section a:not(h1 a, h2 a, h3 a) {
font-size: 14px;
}

.sb-section-item, .sb-grid-item {
flex: 1;
display: flex;
flex-direction: column;
}

.sb-section-item-heading {
padding-top: 20px !important;
padding-bottom: 5px !important;
margin: 0 !important;
}
.sb-section-item-paragraph {
margin: 0;
padding-bottom: 10px;
}

.sb-chevron {
margin-left: 5px;
}

.sb-features-grid {
display: grid;
grid-template-columns: repeat(2, 1fr);
grid-gap: 32px 20px;
}

.sb-socials {
display: grid;
grid-template-columns: repeat(4, 1fr);
}

.sb-socials p {
margin-bottom: 10px;
}

.sb-explore-image {
max-height: 32px;
align-self: flex-start;
}

.sb-addon {
width: 100%;
display: flex;
align-items: center;
position: relative;
background-color: #EEF3F8;
border-radius: 5px;
border: 1px solid rgba(0, 0, 0, 0.05);
background: #EEF3F8;
height: 180px;
margin-bottom: 48px;
overflow: hidden;
}

.sb-addon-text {
padding-left: 48px;
max-width: 240px;
}

.sb-addon-text h4 {
padding-top: 0px;
}

.sb-addon-img {
position: absolute;
left: 345px;
top: 0;
height: 100%;
width: 200%;
overflow: hidden;
}

.sb-addon-img img {
width: 650px;
transform: rotate(-15deg);
margin-left: 40px;
margin-top: -72px;
box-shadow: 0 0 1px rgba(255, 255, 255, 0);
backface-visibility: hidden;
}

@media screen and (max-width: 800px) {
.sb-addon-img {
left: 300px;
}
}

@media screen and (max-width: 600px) {
.sb-section {
flex-direction: column;
}

.sb-features-grid {
grid-template-columns: repeat(1, 1fr);
}

.sb-socials {
grid-template-columns: repeat(2, 1fr);
}

.sb-addon {
height: 280px;
align-items: flex-start;
padding-top: 32px;
overflow: hidden;
}

.sb-addon-text {
padding-left: 24px;
}

.sb-addon-img {
right: 0;
left: 0;
top: 130px;
bottom: 0;
overflow: hidden;
height: auto;
width: 124%;
}

.sb-addon-img img {
width: 1200px;
transform: rotate(-12deg);
margin-left: 0;
margin-top: 48px;
margin-bottom: -40px;
margin-left: -24px;
}
}
`}
</style>
Loading
Loading