Option 1: Style props + custom component
const unselectedColor = useColorModeValue(unselectedColorLightTheme, unselectedColorDarkTheme);
const selectedColor = useColorModeValue(selectedColorLightTheme, selectedColorDarkTheme);
...
<Tab color={unselectedColor} _selected={{ color: selectedColor }}>
To make this more reusable you can create a custom Tab component
const CustomTab = React.forwardRef((props, ref) => {
const tabProps = useTab({ ...props, ref })
const styles = useMultiStyleConfig('Tabs', tabProps);
const unselectedColor = useColorModeValue(unselectedColorLightTheme, unselectedColorDarkTheme);
const selectedColor = useColorModeValue(selectedColorLightTheme, selectedColorDarkTheme);
// If "__css" doesn't work, use "sx"
return <Button {...tabProps} __css={styles.tab} color={unselectedColor} _selected={{ color: selectedColor }} />
}
Option 2: Customizing single components
const theme = extendTheme({
components: {
Tabs: {
baseStyle: (props) => ({
tab: {
color: mode(unselectedColorLightTheme, unselectedColorDarkTheme)(props);
_selected: {
color: mode(selectedColorLightTheme, selectedColorDarkTheme)(props);
}
},
// Apart from "tab", you can also customize "tabpanels", "tabpanel", and "tablist"
}),
...
}
}
})
Then you can use this normally like this:
<Tabs>
<TabList>
<Tab>One</Tab>
<Tab>Two</Tab>
</TabList>
<TabPanels>
<TabPanel>1</TabPanel>
<TabPanel>2</TabPanel>
</TabPanels>
</Tabs>
useColorModeValue - change color based on color mode
_selected
mode - similar to useColorModeValue. Couldn't find the docs for this, but here's a usage example