use*_*494 9 antd ant-design-pro css-in-js
我想自定义一些用cssinjs编写的antd组件的样式。
我创建了一个 HOC 组件来访问主题并覆盖一些样式并在定义提供程序后调用它
import { useToken, useStyleRegister } from 'antd/es/theme/internal'
import { prefixCls } from 'Src/constants'
import { ReactNode } from 'react'
import { CSSObject } from '@ant-design/cssinjs'
import { GlobalToken } from 'antd/es/theme/interface'
function getStyleButton(token: GlobalToken): CSSObject {
return {
[`.${prefixCls}-btn`]: {
['&-default']: {
backgroundColor: 'transparent '
}
}
}
}
export const OverloadStyle = (props: { children: ReactNode }) => {
const [theme, token, hashId] = useToken()
useStyleRegister(
{
theme,
token,
hashId,
path: ['OverloadStyle']
},
() => [
getStyleButton(token),
]
)
return <>{props.children}</>
}
Run Code Online (Sandbox Code Playgroud)
但是样式优先级有问题
调用 !important 不是最好的方法
小智 0
尝试添加!important关键字:
return {
[`.ant-btn`]: {
["&-default"]: {
backgroundColor: "red !important"
}
}
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1693 次 |
| 最近记录: |