AuthProvider
Authentication state management and hooks.
Theming#
The AuthProvider
component is a multipart component. The styling needs to be
applied to each part specifically.
To learn more about styling multipart components, visit the Chakra UI Component Style page.
Anatomy#
container
inner
main
Theming utilities#
createMultiStyleConfigHelpers
: a function that returns a set of utilities for creating style configs for a multipart component (definePartsStyle
anddefineMultiStyleConfig
).definePartsStyle
: a function used to create multipart style objects.defineMultiStyleConfig
: a function used to define the style configuration for a multipart component.
import { authProviderAnatomy } from '@saas-ui/theme/anatomy'import { createMultiStyleConfigHelpers } from '@chakra-ui/react'const { definePartsStyle, defineMultiStyleConfig } =createMultiStyleConfigHelpers(authProviderAnatomy.keys)
Customizing the default theme#
import { authProviderAnatomy } from '@saas-ui/theme/anatomy'import { createMultiStyleConfigHelpers } from '@chakra-ui/react'const { definePartsStyle, defineMultiStyleConfig } =createMultiStyleConfigHelpers(authProviderAnatomy.keys)const baseStyle = definePartsStyle({// define the part you're going to stylecontainer: {bg: 'red.200', // change the backgroundColor of the container},})export const authProviderTheme = defineMultiStyleConfig({ baseStyle })
After customizing the app shell theme, we can import it in our theme file and
add it in the components
property:
import { extendTheme } from '@chakra-ui/react'import { authProviderAnatomy } from './components/auth-provider'export const theme = extendTheme({components: { SuiAuthProvider: authProviderAnatomy },})
Saas UI components are prefixed with
Sui
to avoid conflicts with Chakra UI. This is a crucial step to make sure that any changes that we make to the app shell theme are applied.
Adding a custom size#
Let's assume we want to include an extra large app shell icon size. Here's how we can do that:
import { authProviderAnatomy } from '@saas-ui/theme/anatomy'import { createMultiStyleConfigHelpers, defineStyle } from '@chakra-ui/react'const { definePartsStyle, defineMultiStyleConfig } =createMultiStyleConfigHelpers(authProviderAnatomy.keys)const xl = definePartsStyle({container: {height: '1000px'}})const sizes = {xl,}export const app shellTheme = defineMultiStyleConfig({ sizes })// Now we can use the new `xl` size<AuthProvider size="xl"> ... </AuthProvider>
Every time you're adding anything new to the theme, you'd need to run the CLI command to get proper autocomplete in your IDE. You can learn more about the CLI tool here.
Adding a custom variant#
Let's assume we want to include a custom pill variant. Here's how we can do that:
import { authProviderAnatomy } from '@saas-ui/theme/anatomy'import { createMultiStyleConfigHelpers, defineStyle } from '@chakra-ui/react'const { definePartsStyle, defineMultiStyleConfig } =createMultiStyleConfigHelpers(authProviderAnatomy.keys)const custom = definePartsStyle({container: {border: '1px solid',borderColor: 'gray.200',background: 'gray.50',borderRadius: 'full',// Let's also provide dark mode alternatives_dark: {borderColor: 'gray.600',background: 'gray.800',},},main: {border: '1px solid',borderColor: 'gray.200',background: 'gray.200',color: 'gray.500',_dark: {borderColor: 'gray.600',background: 'gray.600',color: 'gray.400',},},})export const authProviderTheme = defineMultiStyleConfig({variants: { custom },})// Now we can use the new `custom` variant<AuthProvider variant="custom"> ... </AuthProvider>
Changing the default properties#
Let's assume we want to change the default size and variant of every app shell in our app. Here's how we can do that:
import { authProviderAnatomy } from '@saas-ui/theme/anatomy'import { createMultiStyleConfigHelpers, defineStyle } from '@chakra-ui/react'const { defineMultiStyleConfig } = createMultiStyleConfigHelpers(authProviderAnatomy.keys,)export const authProviderTheme = defineMultiStyleConfig({defaultProps: {variant: 'custom',},})// This saves you time, instead of manually setting the size and// variant every time you use an app shell:<AuthProvider variant="custom"> ... </AuthProvider>
Was this helpful?