我使用Chakra,我的应用程序中有几个Toast组件。默认情况下,它们有一个蓝色的背景色,因为它们有status="info"
。
如何用status="info"
改变所有祝酒词的背景色?我想保留所有其他默认样式(宽度、位置等),只需要更改颜色。
发布于 2021-12-16 11:46:13
Alert
配色方案的支柱.这个配色方案是在主题定义中使用来定义背景色。
默认情况下,status="info"
映射到blue
,并使用subtle
变量。
因此,您需要在您的主题定义中添加这样的覆盖
import { theme as origTheme, extendTheme } from "@chakra-ui/react"
const theme = extendTheme({
components: {
Alert: {
variants: {
subtle: (props) => { // only applies to `subtle` variant
const { colorScheme: c } = props
if (c !== "blue") {
// use original definition for all color schemes except "blue"
return origTheme.components.Alert.variants.subtle(props)
}
return {
container: {
bg: `${c}.500`, // or literal color, e.g. "#0984ff"
},
}
}
}
}
}
})
像blue.500
这样的颜色变量是从颜色定义中读取的。
https://stackoverflow.com/questions/69531448
复制相似问题