├── .gitignore ├── .storybook ├── main.js ├── preview-head.html └── preview.js ├── README.md ├── components ├── Button.stories.tsx ├── Button.tsx ├── Github.stories.tsx ├── Github.tsx └── Logo.tsx ├── next-env.d.ts ├── package-lock.json ├── package.json ├── pages ├── _app.tsx └── index.tsx ├── postcss.config.js ├── public ├── favicon.ico ├── storybook │ └── tailwind.storybook.css └── vercel.svg ├── styles └── tailwind.css ├── tailwind.config.js └── tsconfig.json /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # next.js 12 | /.next/ 13 | /out/ 14 | 15 | # production 16 | /build 17 | 18 | # misc 19 | .DS_Store 20 | *.pem 21 | 22 | # debug 23 | npm-debug.log* 24 | yarn-debug.log* 25 | yarn-error.log* 26 | 27 | # local env files 28 | .env.local 29 | .env.development.local 30 | .env.test.local 31 | .env.production.local 32 | 33 | # vercel 34 | .vercel 35 | 36 | # storybook build 37 | /storybook-static 38 | # generated on build 39 | tailwind.storybook.css -------------------------------------------------------------------------------- /.storybook/main.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | stories: ['../components/**/*.stories.@(js|jsx|ts|tsx)'], 3 | addons: ['@storybook/addon-links', '@storybook/addon-essentials'], 4 | features: { 5 | postcss: false, 6 | }, 7 | // webpackFinal is modified by nextjs/storybook-plugin to include node-modules and nextjs/babel 8 | typescript: { 9 | reactDocgen: 'react-docgen', 10 | }, 11 | } 12 | -------------------------------------------------------------------------------- /.storybook/preview-head.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.storybook/preview.js: -------------------------------------------------------------------------------- 1 | export const parameters = { 2 | actions: { argTypesRegex: "^on[A-Z].*" }, 3 | } 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## nextjs-tailwindcss-storybook-typescript 2 | 3 | This package aims to be a flexible starting point if you want to use Nextjs, TailwindCSS, Storybook and TypeScript. 4 | 5 | ### TailwindCSS 6 | 7 | Instead of using Storybook's own webpack, this repo uses nextjs build pipeline and then includes the generated CSS independently in Storybook. 8 | The only caveat is that you have to place the generated CSS somewhere that can be accessed by storybook webserver. 9 | 10 | Please review `package.json` and make changes according to your needs 11 | 12 | ```json 13 | "tailwind-storybook": "tailwind build ./styles/tailwind.css -o ./public/storybook/tailwind.storybook.css", 14 | "tailwind-storybook-build": "NODE_ENV=production tailwind build ./styles/tailwind.css -o ./storybook-static/storybook/tailwind.storybook.css", 15 | "storybook": "npm run tailwind-storybook && start-storybook -s ./public -p 6006", 16 | "build-storybook": "build-storybook && tailwind-storybook-build" 17 | ``` 18 | 19 | ## NextJS default Readme... 20 | 21 | This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app). 22 | 23 | ## Getting Started 24 | 25 | First, run the development server: 26 | 27 | ```bash 28 | npm run dev 29 | # or 30 | yarn dev 31 | ``` 32 | 33 | Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. 34 | 35 | You can start editing the page by modifying `pages/index.js`. The page auto-updates as you edit the file. 36 | 37 | ## Learn More 38 | 39 | To learn more about Next.js, take a look at the following resources: 40 | 41 | - [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API. 42 | - [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial. 43 | 44 | You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome! 45 | 46 | ## Deploy on Vercel 47 | 48 | The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/import?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js. 49 | 50 | Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details. 51 | -------------------------------------------------------------------------------- /components/Button.stories.tsx: -------------------------------------------------------------------------------- 1 | import { Button } from './Button' 2 | 3 | import type { ButtonProps } from './Button' 4 | import type { Story, Meta } from '@storybook/react/types-6-0' 5 | 6 | export default { 7 | title: 'Brand/Button', 8 | component: Button, 9 | } as Meta 10 | 11 | const Template: Story = (args) => 12 | 13 | export const Primary: Story = Template.bind({}) 14 | 15 | export const Variant: Story = Template.bind({}) 16 | 17 | Variant.args = { 18 | isVariant: true, 19 | } 20 | -------------------------------------------------------------------------------- /components/Button.tsx: -------------------------------------------------------------------------------- 1 | import type { HTMLAttributes } from 'react' 2 | import cn from 'classnames' 3 | 4 | export interface ButtonProps extends HTMLAttributes { 5 | isVariant?: boolean 6 | } 7 | 8 | export const Button: React.FC = ({ children, isVariant, ...rest }) => { 9 | return ( 10 |
11 | 20 |
21 | ) 22 | } 23 | -------------------------------------------------------------------------------- /components/Github.stories.tsx: -------------------------------------------------------------------------------- 1 | import { Github } from './Github' 2 | import type { GithubProps } from './Github' 3 | import type { Story, Meta } from '@storybook/react/types-6-0' 4 | 5 | export default { 6 | title: 'Misc/Github', 7 | component: Github, 8 | } as Meta 9 | 10 | const Template: Story = (args) => 11 | 12 | export const Primary: Story = Template.bind({}) 13 | -------------------------------------------------------------------------------- /components/Github.tsx: -------------------------------------------------------------------------------- 1 | import type { AnchorHTMLAttributes } from 'react' 2 | 3 | export interface GithubProps extends AnchorHTMLAttributes {} 4 | 5 | // https://tholman.com/github-corners/ 6 | export const Github: React.FC = (props) => { 7 | return ( 8 | 13 | 40 | 59 | 60 | ) 61 | } 62 | -------------------------------------------------------------------------------- /components/Logo.tsx: -------------------------------------------------------------------------------- 1 | import Link from 'next/link' 2 | import type { LinkProps } from 'next/link' 3 | 4 | import cn from 'classnames' 5 | import Image from 'next/image' 6 | 7 | export interface LogoProps extends LinkProps { 8 | itHovers: boolean 9 | } 10 | 11 | export const Logo: React.FC = ({ itHovers = false, ...rest }) => { 12 | return ( 13 | 14 | 19 | Vercel Logo 20 | 21 | 22 | ) 23 | } 24 | -------------------------------------------------------------------------------- /next-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | /// 4 | 5 | // NOTE: This file should not be edited 6 | // see https://nextjs.org/docs/basic-features/typescript for more information. 7 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nextjs-tailwindcss-typescript-storybook", 3 | "version": "0.1.0", 4 | "private": true, 5 | "scripts": { 6 | "dev": "next dev", 7 | "build": "next build", 8 | "start": "next start", 9 | "tailwind-storybook": "postcss ./styles/tailwind.css -o ./public/storybook/tailwind.storybook.css", 10 | "tailwind-storybook-build": "NODE_ENV=production postcss ./styles/tailwind.css -o ./storybook-static/storybook/tailwind.storybook.css", 11 | "storybook": "npm run tailwind-storybook && start-storybook -s ./public -p 6006", 12 | "build-storybook": "build-storybook && npm run tailwind-storybook-build" 13 | }, 14 | "dependencies": { 15 | "next": "^12.0.4", 16 | "react": "^17.0.2", 17 | "react-dom": "^17.0.2" 18 | }, 19 | "devDependencies": { 20 | "@next/plugin-storybook": "^12.0.4", 21 | "@storybook/addon-actions": "^6.2.9", 22 | "@storybook/addon-essentials": "^6.2.9", 23 | "@storybook/addon-links": "^6.2.9", 24 | "@storybook/react": "^6.2.9", 25 | "@types/react": "^17.0.11", 26 | "autoprefixer": "^10.2.6", 27 | "classnames": "^2.3.1", 28 | "postcss": "^8.3.5", 29 | "postcss-cli": "^9.0.2", 30 | "react-is": "^17.0.2", 31 | "tailwindcss": "^2.2.0", 32 | "typescript": "^4.3.4" 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /pages/_app.tsx: -------------------------------------------------------------------------------- 1 | import "../styles/tailwind.css" 2 | import type { AppProps /*, AppContext */ } from "next/app" 3 | 4 | function MyApp({ Component, pageProps }: AppProps) { 5 | return 6 | } 7 | 8 | export default MyApp 9 | -------------------------------------------------------------------------------- /pages/index.tsx: -------------------------------------------------------------------------------- 1 | import { Logo } from "components/Logo" 2 | import { Button } from "components/Button" 3 | import { Github } from "components/Github" 4 | 5 | export default function Home() { 6 | return ( 7 |
8 | 9 |
10 |
11 | 12 |
13 |
14 |

15 | Ready to dive in? 16 |
17 | Start building something amazing. 18 |

19 |
20 | 21 | 24 |
25 |
26 |
27 | ) 28 | } 29 | -------------------------------------------------------------------------------- /postcss.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: { 3 | // this formats supports both next and storybook 4 | tailwindcss: {}, 5 | autoprefixer: {}, 6 | }, 7 | } 8 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dazuaz/nextjs-tailwindcss-storybook-typescript/52bc85622d4701ab147f7799c73130142fbdc863/public/favicon.ico -------------------------------------------------------------------------------- /public/vercel.svg: -------------------------------------------------------------------------------- 1 | 3 | 4 | -------------------------------------------------------------------------------- /styles/tailwind.css: -------------------------------------------------------------------------------- 1 | @tailwind base; 2 | @tailwind components; 3 | @tailwind utilities; 4 | -------------------------------------------------------------------------------- /tailwind.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | purge: ["./pages/**/*.{js,jsx,ts,tsx}", "./components/**/*.{js,jsx,ts,tsx}"], 3 | theme: { 4 | extend: {}, 5 | }, 6 | variants: {}, 7 | } 8 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "lib": [ 5 | "dom", 6 | "dom.iterable", 7 | "esnext" 8 | ], 9 | "allowJs": true, 10 | "skipLibCheck": true, 11 | "strict": false, 12 | "forceConsistentCasingInFileNames": true, 13 | "noEmit": true, 14 | "esModuleInterop": true, 15 | "module": "esnext", 16 | "moduleResolution": "node", 17 | "resolveJsonModule": true, 18 | "isolatedModules": true, 19 | "jsx": "preserve", 20 | "baseUrl": ".", 21 | "incremental": true 22 | }, 23 | "include": [ 24 | "next-env.d.ts", 25 | "**/*.ts", 26 | "**/*.tsx" 27 | ], 28 | "exclude": [ 29 | "node_modules" 30 | ] 31 | } 32 | --------------------------------------------------------------------------------