RedwoodJS
A guide for installing Saas UI with redwoodjs projects
Installation#
Automatic#
RedwoodJS provides a convenient setup script via its CLI tool to enable Chakra UI in your project with a single command. In your project folder, simply enter:
yarn redwood setup ui chakra-ui
This will make the necessary modifications to your App.tsx (or App.js, respectively)
which are basically the same as outlined in manual installation steps below.
After this you can install Saas UI.
npm i @saas-ui/react
yarn add @saas-ui/react
pnpm add @saas-ui/react
See additional setup (such as including theme customizations and Storybook integration) below.
Manual#
- Inside your
Redwoodjsproject , cd intoweb, then, install Chakra UI by running either of the following:
npm i @saas-ui/react @chakra-ui/react @emotion/react@^11 @emotion/styled@^11 framer-motion@^6
yarn add @saas-ui/react @chakra-ui/react @emotion/react@^11 @emotion/styled@^11 framer-motion@^6
- After installing Saas UI, you need to set up the
SaasProviderat the root of your application. Go toApp.jsand add theSaasProviderlike this:
import { ColorModeScript } from '@chakra-ui/react'import { SaasProvider } from '@saas-ui/react'const App = () => (<FatalErrorBoundary page={FatalErrorPage}><RedwoodProvider titleTemplate="%PageTitle | %AppTitle"><ColorModeScript /><SaasProvider><RedwoodApolloProvider><Routes /></RedwoodApolloProvider></SaasProvider></RedwoodProvider></FatalErrorBoundary>)export default App
Additional setup#
Customize Theme#
If you intend to customize the default theme,
you will need to pass your extended theme object as a prop
to ChakraProvider as follows:
// 1. Import the extendTheme functionimport { extendTheme } from '@chakra-ui/react'// 2. Import the Saas UI themeimport { theme as baseTheme } from '@saas-ui/react'// 3. Extend the theme to include custom colors, fonts, etcconst colors = {brand: {900: '#1a365d',800: '#153e75',700: '#2a69ac',},}const theme = extendTheme({ colors }, baseTheme)// 3. Pass the `theme` prop to the `ChakraProvider`const App = () => (<FatalErrorBoundary page={FatalErrorPage}><RedwoodProvider titleTemplate="%PageTitle | %AppTitle"><ColorModeScript /><SaasProvider theme={theme}><RedwoodApolloProvider><Routes /></RedwoodApolloProvider></SaasProvider></RedwoodProvider></FatalErrorBoundary>)
Storybook Integration#
RedwoodJS ships with Storybook included. To automatically wrap your
your stories with the <ChakraProvider /> and add a color mode toggle, follow
the steps below.
The steps outlined here are semantically identical to our Storybook integration Guide, only the install commands and file locations differ.
-
Install the official Storybook Addon for Chakra UI:
yarn workspace web add -D @chakra-ui/storybook-addonyarn workspace web add @chakra-ui/icons -
Add the addon to your configuration in
web/config/storybook.config.js:module.exports = {addons: [// ...'@chakra-ui/storybook-addon',],} -
Additional configuration:
In case you are using any Theme customizations, you will want to see them applied in Storybook as well. Enable them inweb/config/storybook.preview.jslike this:const theme = require('../path/to/your/theme')export const parameters = {// ...chakra: {theme,},}The
chakraobject accepts the same props asChakraProvider(withoutchildren).
Notes on TypeScript 🚨#
Please note that when adding Chakra UI to a TypeScript project, a minimum
TypeScript version of 4.1.0 is required.
Was this helpful?