【发布时间】:2021-12-09 08:41:58
【问题描述】:
我有默认样式的全局 ReactSelect。我只需要覆盖样式的一个属性。将以下内容视为可重用的 CustomReactSelect 组件。
custom-react-select.tsx
export const CustomReactSelect = (props) => {
const defaultStyle = {
control: (provided, state) => ({
...
backgroundColor: (state.isDisabled) ? '--theia-editorGroupHeader-tabsBackground' : 'var(--theia-input-background)',
fontSize: 'var(--theia-ui-font-size1)',
...
}),
}
...
return <Select
...
styles = {...defaultStyle,...props.style}
...
/>
}
考虑一种情况,我只需要以类似的方式覆盖控件样式的背景。
const overrideControlStyle = {
backgroundColor: (state.isFocused) ? 'red' : 'black'
}
我只需要覆盖backgroundColor,最后应该发送到React Select的props应该如下,
Sent Props...
{
control: (provided, state) => ({
...
backgroundColor: (state.isFocused) ? 'red' : 'black',
fontSize: 'var(--theia-ui-font-size1)',
...
}),
}
【问题讨论】:
标签: javascript css reactjs typescript react-select