Banner

Banners are used to communicate accouncements and important information.

Theming#

The Feedback 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

Default theme#

import { transparentize } from '@chakra-ui/theme-tools'
import { createMultiStyleConfigHelpers } from '@chakra-ui/styled-system'
import { bannerAnatomy } from '../../anatomy'
const { definePartsStyle, defineMultiStyleConfig } =
createMultiStyleConfigHelpers(bannerAnatomy.keys)
const baseStyle = definePartsStyle({
container: {
px: 4,
py: 3,
},
content: {
display: 'flex',
flex: 1,
flexDirection: ['column', null, 'row'],
},
title: {
fontWeight: 'bold',
lineHeight: 6,
marginEnd: 2,
},
description: {
lineHeight: 6,
marginEnd: 2,
},
actions: {
marginEnd: 2,
},
icon: {
flexShrink: 0,
marginEnd: 3,
w: 5,
h: 6,
},
})
const variantSubtle = definePartsStyle((props) => {
const { theme, colorScheme: c } = props
return {
container: {
bg: `${c}.100`,
_dark: { bg: transparentize(`${c}.200`, 0.16)(theme) },
},
icon: { color: `${c}.500`, _dark: { color: `${c}.200` } },
}
})
const variantSolid = definePartsStyle((props) => {
const { colorScheme: c } = props
return {
container: {
bg: `${c}.500`,
color: 'white',
},
}
})
export const bannerTheme = defineMultiStyleConfig({
baseStyle,
variants: {
subtle: variantSubtle,
solid: variantSolid,
},
defaultProps: {
variant: 'subtle',
colorScheme: 'blue',
},
})

Theming utilities#

  • createMultiStyleConfigHelpers: a function that returns a set of utilities for creating style configs for a multipart component (definePartsStyle and defineMultiStyleConfig).
  • definePartsStyle: a function used to create multipart style objects.
  • defineMultiStyleConfig: a function used to define the style configuration for a multipart component.
import { feedbackAnatomy } from '@saas-ui/theme/anatomy'
import { createMultiStyleConfigHelpers } from '@chakra-ui/react'
const { definePartsStyle, defineMultiStyleConfig } =
createMultiStyleConfigHelpers(feedbackAnatomy.keys)

Customizing the default theme#

import { feedbackAnatomy } from '@saas-ui/theme/anatomy'
import { createMultiStyleConfigHelpers } from '@chakra-ui/react'
const { definePartsStyle, defineMultiStyleConfig } =
createMultiStyleConfigHelpers(feedbackAnatomy.keys)
const baseStyle = definePartsStyle({
// define the part you're going to style
container: {
bg: 'red.200', // change the backgroundColor of the container
},
})
export const feedbackTheme = 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 { feedbackAnatomy } from './components/feedback'
export const theme = extendTheme({
components: { SuiFeedback: feedbackAnatomy },
})

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 { feedbackAnatomy } from '@saas-ui/theme/anatomy'
import { createMultiStyleConfigHelpers, defineStyle } from '@chakra-ui/react'
const { definePartsStyle, defineMultiStyleConfig } =
createMultiStyleConfigHelpers(feedbackAnatomy.keys)
const xl = definePartsStyle({
container: {
height: '1000px'
}
})
const sizes = {
xl,
}
export const app shellTheme = defineMultiStyleConfig({ sizes })
// Now we can use the new `xl` size
<Feedback size="xl"> ... </Feedback>

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 { feedbackAnatomy } from '@saas-ui/theme/anatomy'
import { createMultiStyleConfigHelpers, defineStyle } from '@chakra-ui/react'
const { definePartsStyle, defineMultiStyleConfig } =
createMultiStyleConfigHelpers(feedbackAnatomy.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 feedbackTheme = defineMultiStyleConfig({
variants: { custom },
})
// Now we can use the new `custom` variant
<Feedback variant="custom"> ... </Feedback>

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 { feedbackAnatomy } from '@saas-ui/theme/anatomy'
import { createMultiStyleConfigHelpers, defineStyle } from '@chakra-ui/react'
const { defineMultiStyleConfig } = createMultiStyleConfigHelpers(
feedbackAnatomy.keys,
)
export const feedbackTheme = defineMultiStyleConfig({
defaultProps: {
variant: 'custom',
},
})
// This saves you time, instead of manually setting the size and
// variant every time you use an app shell:
<Feedback variant="custom"> ... </Feedback>

Was this helpful?