Basic
Following is the default implementation of the GluestackUIProvider component without any additional customization. This serves as a starting point for users who are new to this library and want to learn about the basic functionality and appearance of the component.
<GluestackUIProvider config={config}>
<ButtonText>Hello World</ButtonText>
Import
You have to import the Provider from the library at the root level of your application
import { GluestackUIProvider } from "@darden/design-system"
Anatomy
The structure provided below can help you identify and understand a GluestackUIProvider component's various parts.
<GluestackUIProvider config={config}>{children}</GluestackUIProvider>
Advanced
We provide in-depth information on how to customize and extend the component's functionality to meet your needs. Below, we describe how to modify the component to suit your requirements.
We have also exported all the providers separately so that you can use them individually.
GluestackUIStyledProvider
To use only config and styled functionalities, you can use GluestackUIStyledProvider component.
import { GluestackUIStyledProvider } from "@darden/design-system"
import { config } from "@gluestack-ui/config"
;<GluestackUIStyledProvider config={config}>
<ButtonText>Hello World</ButtonText>
</GluestackUIStyledProvider>
OverlayProvider
To use only overlay functionalities, you can use OverlayProvider component.
import { OverlayProvider } from "@gluestack-ui/overlay"
ToastProvider
We have separated ToastProvider and OverlayProvider so that you can use them individually and decide the priority of the provider.
import { ToastProvider } from "@gluestack-ui/toast"
To create your own provider, here is the example of how you can create your own provider.
import React from "react"
import { createProvider } from "@gluestack-ui/provider"
import { StyledProvider } from "@gluestack-style/react"
import { OverlayProvider } from "@gluestack-ui/overlay"
import { ToastProvider } from "@gluestack-ui/toast"
const GluestackUIStyledProvider = createProvider({ StyledProvider })
const GluestackUIProvider = ({ children, ...props }: any) => {
<GluestackUIStyledProvider>
<ToastProvider>{children}</ToastProvider>
</GluestackUIStyledProvider>
Customizing the Provider
We have a function called
createProvider which can be used to create provider with
StyledProvider exported from
@gluestack-style/react. You can pass configuration object which consists theme. You can change the theme object specific to your brand. Refer
gluestack.io/style for more information on how to create a theme.
Usage
import { createProvider } from "@gluestack-ui/provider"
import { config } from "@gluestack-ui/config"
import { StyledProvider } from "@gluestack-style/react"
export const Provider = createProvider({
<Provider config={config}>
You can also create GluestackUIProvider component which can be used to wrap your entire application. This will make sure that all the components are wrapped with the provider with styling and other providers like OverlayProvider and ToastProvider.
import { StyledProvider } from "@gluestack-style/react"
import { OverlayProvider } from "@gluestack-ui/overlay"
import { ToastProvider } from "@gluestack-ui/toast"
const GluestackUIStyledProvider = createProvider({ StyledProvider })
const GluestackUIProvider = ({ children, ...props }: any) => {
<GluestackUIStyledProvider>
<ToastProvider>{children}</ToastProvider>
</GluestackUIStyledProvider>