To get started with gluestack-ui, check out this quick installation guide. It provides simple steps to help you install and use the library in your projects.
Automatic
Manual
Automatic
Using Template
Coming soon
Manual
If you wish to install @darden/design-system into your existing project, you can proceed with the following steps:
Step 1: Install / Alias dependencies
Install
First, install the dependencies of gluestack-ui in your project. This can be done using the following command:
yarnadd @darden/design-system
OR
npm i @darden/design-system
Alias (Optional)
You can alias your local design system dependency like below.
babel.config.js
const path =require("path")
module.exports=function(api){
api.cache(true)
return{
presets:[["babel-preset-expo"]],
plugins:[
[
"module-resolver",
{
alias:{
"@darden/design-system": path.resolve(
__dirname,
"../../packages/components/src"
),
},
},
],
],
}
}
Step 2: Server-side rendering (SSR)
It's also recommended to set up your server-side rendering (SSR) correctly. To do this, you will need to use the flush() function exported by the @darden/design-system.
Next.js App Routers (which supports React Server Components)
For Next.js App Routers we will create a new registry.tsx file in the root of your project and use the flush function from @darden/design-system:
To use gluestack-ui components with server-side rendering, you need to configure your project to transpile the modules correctly. The easiest way to do this is by using the withGluestackUI Next.js adapter. This adapter adds the necessary configuration to your project to ensure that your gluestack-ui components are transpiled correctly for server-side rendering.
This component returns a GluestackUIProvider component which wraps the children.
After creating providers.tsx file, we need to wrap the exported GluestackUIProvider component around the children in layout.tsx file. The code in layout.tsx file at this point of time will look like this:
import"./globals.css"
import{Inter}from"next/font/google"
import{Providers}from"./providers"
importStyledJsxRegistryfrom"./registry"
const inter =Inter({subsets:["latin"]})
exportconst metadata ={
title:"Create Next App",
description:"Generated by create next app",
}
exportdefaultfunctionRootLayout({
children,
}:{
children:React.ReactNode
}){
return(
<htmllang="en"className="gs gs-light">
<bodyclassName={inter.className}>
<Providers>
<StyledJsxRegistry>{children}</StyledJsxRegistry>
</Providers>
</body>
</html>
)
}
Next.js Page Routers
For Next.js Page Router just add GluestackUIProvider to the root of your app and update _app.tsx as follows: