πŸ’„ Demo

✨ Motivation

// More Tailwind examples https://tailwindcss.com/components/

import tw from 'tailwind.macro';

// Standalone Tailwind Classes
const Main = tw.div`
  p-6 bg-gray-100 rounded-lg shadow-2xl
`;

// Keep the power of styled-components
const Wrapper = styled.div`
  ${tw`flex items-center justify-center flex-col h-screen`}
  color: ${({ isClicked }) => (isClicked ? 'red' : 'blue')}
`;

// Develop and test with storybook v5
import React from 'react';
import IndexPage from './IndexPage.react';

export default {
  title: 'IndexPage',
};

export const Default = () => <IndexPage />;

πŸ“¦ What's this template solves?

  • Configure Tailwind to work with CSS-in-JS & PostCSS.
  • Configure Gatsby & Tailwind to work with Storybook.
  • Usage Examples (IndexPage component).
  • Deploy ready, either for Storybook.

πŸš€ Quick start

  1. Get the repo with Gatsby CLI or clone from Github

    # Create a new Gatsby site using the gatsby CLI
    gatsby new my-tailwind-styled-starter https://github.com/denvash/gatsby-tailwind-styled-components-storybook-starter
    cd my-tailwind-styled-starter/
    # Clone the repo
    git clone https://github.com/denvash/gatsby-tailwind-styled-components-storybook-starter.git
    cd gatsby-styled-tailwind-storybook-starter
    yarn install
  2. Start Develop

    yarn develop
    yarn storybook

    You must run develop once before storybook.

    Storybook must have access to public folder.

πŸ“• Deploying Storybook to Netlify

Edit the Build Command and the Publish directory at Build & Deploy section.

yarn build-storybook
storybook-static/

Image

🧐 What's inside?

A quick look at the top-level files and directories you'll see in a Gatsby project.

./
  β”œβ”€β”€ gatsby-browser.js
  β”œβ”€β”€ gatsby-config.js
  β”œβ”€β”€ gatsby-node.js
  β”œβ”€β”€ gatsby-ssr.js
  β”œβ”€β”€ jsconfig.json
  β”œβ”€β”€ LICENSE
  β”œβ”€β”€ node_modules
  β”œβ”€β”€ package.json
  β”œβ”€β”€ postcss.config.js
  β”œβ”€β”€ README.md
  β”œβ”€β”€ src
  β”œβ”€β”€ static
  β”œβ”€β”€ tailwind.config.js
  └── yarn.lock
  1. /node_modules: This directory contains all of the modules of code that your project depends on (npm packages) are automatically installed.

  2. /src: This directory will contain all of the code related to what you will see on the front-end of your site (what you see in the browser) such as your site header or a page template. src is a convention for β€œsource code”.

  3. .babelrc: This configuration file allows us to fine-tune Babel's configuration settings. In this starter we are adding the babel-preset-gatsby preset to allow us to customize Babel as needed.

  4. .gitignore: This file tells git which files it should not track / not maintain a version history for.

  5. .prettierignore: This file allows us to specifiy files that we want to exclude from formatting with Prettier.

  6. .prettierrc: This is a configuration file for Prettier. Prettier is a tool to help keep the formatting of your code consistent.

  7. gatsby-browser.js: This file is where Gatsby expects to find any usage of the Gatsby browser APIs (if any). These allow customization/extension of default Gatsby settings affecting the browser. By default we are injecting Tailwind's base styles into the browser.

  8. gatsby-config.js: This is the main configuration file for a Gatsby site. This is where you can specify information about your site (metadata) like the site title and description, which Gatsby plugins you’d like to include, etc. (Check out the config docs for more detail).

  9. gatsby-node.js: This file is where Gatsby expects to find any usage of the Gatsby Node APIs (if any). These allow customization/extension of default Gatsby settings affecting pieces of the site build process.

  10. gatsby-ssr.js: This file is where Gatsby expects to find any usage of the Gatsby server-side rendering APIs (if any). These allow customization of default Gatsby settings affecting server-side rendering.

  11. LICENSE: Gatsby is licensed under the MIT license.

  12. package-lock.json: (See package.json below, first). This is an automatically generated file based on the exact versions of your npm dependencies that were installed for your project. (You won’t change this file directly).

  13. package.json: A manifest file for Node.js projects, which includes things like metadata (the project’s name, author, etc). This manifest is how npm knows which packages to install for your project.

  14. postcss.config.js: This configuration file allows us to customize our PostCSS settings. PostCSS is used to compile the custom css we write outside of styled-components.

  15. README.md: A text file containing useful reference information about your project.

  16. tailwind.config.js: This is the default Tailwind CSS configuration file.

πŸ’« Deploy Now

Deploy to Netlify