Migrate to Netlify Today

Netlify announces the next evolution of Gatsby Cloud. Learn more

ContactSign Up
Community Plugin
View plugin on GitHub

@teste-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 @teste-ui/gatsby-plugin @teste-ui/react @emotion/react @emotion/styled framer-motion

# or

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

Usage

  1. Add @teste-ui/gatsby-plugin as a plugin in your Gatsby config.
// gatsby-config.js
module.exports = {
  plugins: ["@teste-ui/gatsby-plugin"],
}
  1. Use Chakra ⚡
// src/pages/index.js
import React from "react"
import { Box, Text } from "@teste-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: "@teste-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/@teste-ui/gatsby-plugin/theme.js file with your own theme:

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

export default extendTheme(theme)

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.