Hover/Conditional Styles
Is there an easy way to define hover styles or general styles that are applied conditionally to a particular variant? I couldn't find any information in the docs.
There are a few examples for some components such as Button
const theme = {
// ...
buttons: {
primary: {
'&:hover': {
bg: 'text'
}
}
}
}
styles that are applied conditionally to a particuliar variant
Not sure what you mean by that, themes are static (and luckily: a dynamic theme could result in unexpected UI behaviours)
But if you are after general style variants, there is nothing preventing you from composing your theme more in-depth:
const hoverStyle = {
'&:hover,&:active': {
textDecoration: 'underline'
}
};
const disabledStyle = {
'&:disabled': {
opacity: 0.65,
cursor: 'not-allowed'
}
};
const theme = {
// ...
buttons: {
primary: {
bg: 'primary',
color: 'text',
...hoverStyle,
...disabledStyle
}
}
}
Thank you!
I came here looking for a solution to conditionally styling an element one way or another, based on a boolean variable.
For future readers, this is what I ended up with:
sx={{
color: selected ? 'accent' : 'primary'
}}
@suaurial @flo-sch I am taking a slightly different approach which some might prefer:
buttons: {
base: {
[ shared button styles ]
'&:disabled': {
variant: 'buttons.disabled'
}
},
disabled: {
[ disabled styles ]
}
primary: {
variant: 'buttons.base',
backgroundColor: 'primary',
[other more specific styles]
}
}
That works too, was there a specific reason to define disabled as a variant itself though?
(Perhaps to apply it on a <a /> which do not have css :disabled selectors?)