Migrate to Netlify Today

Netlify announces the next evolution of Gatsby Cloud. Learn more

ContactSign Up for Free
Community Plugin
View plugin on GitHub

@chakra-ui/gatsby-plugin

Gatsby plugin for adding Chakra UI

Installation

⚡ To use Chakra UI in your Gatsby site, you need to install the plugin and its peer dependencies.

npm i @chakra-ui/gatsby-plugin @chakra-ui/react @emotion/react @emotion/styled framer-motion

# or

yarn add @chakra-ui/gatsby-plugin @chakra-ui/react @emotion/react @emotion/styled framer-motion

Usage

  1. Add @chakra-ui/gatsby-plugin as a plugin in your Gatsby config.
// gatsby-config.js
module.exports = {
  plugins: ["@chakra-ui/gatsby-plugin"],
}
  1. Use Chakra ⚡
// src/pages/index.js
import React from "react"
import { Box, Text } from "@chakra-ui/react"

function IndexPage() {
  return (
    <Box p={8}>
      <Text fontSize="xl">Hello World</Text>
    </Box>
  )
}

export default IndexPage

Plugin options

By default, this plugin adds the main context provider to make all components work correctly.

<ChakraProvider theme={theme} resetCSS={resetCSS} portalZIndex={portalZIndex}>
  {element}
</ChakraProvider>

You can disable either of these with Gatsby options:

// gatsby-config.js
module.exports = {
  plugins: [
    {
      resolve: "@chakra-ui/gatsby-plugin",
      options: {
        /**
         * @property {boolean} [resetCSS=true]
         * if `false`, this plugin will not use `<CSSReset />
         */
        resetCSS: true,
        /**
         * @property {number} [portalZIndex=40]
         * The z-index to apply to all portal nodes. This is useful
         * if your app uses a lot z-index to position elements.
         */
        portalZIndex: 40,
      },
    },
  ],
}

Customizing the theme

To use customize the theme in your Gatsby site, you can shadow the plugin’s src/@chakra-ui/gatsby-plugin/theme.js file with your own theme:

// src/@chakra-ui/gatsby-plugin/theme.js
import { extendTheme } from "@chakra-ui/react"
const theme = {
  colors: {
    primary: "rebeccapurple",
  },
}

export default extendTheme(theme) // or extendBaseTheme

You can learn more about custom theme at Chakra UI’s documentation.

By default, Chakra provides a sensible default theme inspired by Tailwind CSS.

© 2024 Gatsby, Inc.