-
I wanted to follow up about a post that’s already been closed. It is in regards to React Aria Components library and how they use state as a way to style components, as well as data-attributes. Another page where they talk about it. I mentioned that I would attempt the easy path of using I found that this would not work destructive: {
backgroundColor: {
default: '#B91C1C',
':hover': '#991B1B',
':is([data-pressed])': '#7F1D1D', // does not work
},
color: 'white',
}, I had to nest it inside of the destructive: {
backgroundColor: {
default: '#B91C1C',
':hover': {
default: '#991B1B',
':is([data-pressed])': '#7F1D1D',
},
},
color: 'white',
}, Neither of these options worked well for me either backgroundColor: {
default: '#F3F4F6',
':hover': {
default: 'rgba(0, 0, 0, 0.05)',
[DARK]: 'rgba(255, 255, 255, 0.1)',
':is(data-pressed)': { // is not working
default: 'rgba(0, 0, 0, 0.1)',
[DARK]: 'rgba(255, 255, 255, 0.2)',
},
},
':disabled': 'transparent', // confusing
}, backgroundColor: {
default: '#F3F4F6',
':hover': {
default: 'rgba(0, 0, 0, 0.05)',
':is(data-pressed)':'rgba(0, 0, 0, 0.1)',
[DARK]: {
default: 'rgba(255, 255, 255, 0.1)',
':is(data-pressed)': 'rgba(255, 255, 255, 0.2)',
},
},
':disabled': 'transparent', // confusing
}, This pattern did work backgroundColor: {
default: '#F3F4F6',
':hover': {
default: 'rgba(0, 0, 0, 0.05)',
':is(data-pressed)': 'rgba(0, 0, 0, 0.1)',
},
':disabled': 'transparent', // confusing
},
[DARK]: {
backgroundColor: {
':hover': {
default: 'rgba(255, 255, 255, 0.1)',
':is([data-pressed])': 'rgba(255, 255, 255, 0.2)',
},
},
}, I’m sure I am making the maintainers cringe as they say “this is exactly what we don’t want people doing” My next attempt is to try to use the helper function from that original post. That way I don’t have to use these By the way, this is in the code above |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 10 replies
-
Noticed something else interesting. First, I have removed all the confusing {...stylex.props(
buttonStyle.base,
props.isDisabled && disabled.base,
)} In order to not have a hover style I need to override it in the disabled style object. I try to set it to null like this const disabled = stylex.create({
base: {
backgroundColor: { default: '#F3F4F6', [DARK]: {default: '#27272A', ':hover': null}},
... but it does not work. The hover style in buttonStyle.base still shows up. If I copy the same pattern that the buttonStyle.base is using, and group all the [DARK] styles together, then it does work const disabled = stylex.create({
base: {
backgroundColor: '#F3F4F6',
[DARK]: {
backgroundColor: {
default: '#27272A',
':hover': {
default: null,
},
},
},
} |
Beta Was this translation helpful? Give feedback.
-
I noticed a few examples use Another thing is that you should probably not be using |
Beta Was this translation helpful? Give feedback.
-
For those following along, I got HorusGoul vite plugin working. The solution will prob work with nonzzz as well, but haven't tested it out yet.
I am not using any other config option (no build rollup option, no optimizeDeps options). It is importing the css twice when I look in the browser inspector, but I'll deal with that for now, just happy to get it working. Build is still working too, at least the CSS is compiled and no errors. I haven't confirmed this does anything more than initially work, but I'm happy I got that far at least. |
Beta Was this translation helpful? Give feedback.
-
Hmmm seems my React-Aria-Components (which my component library is built on) is no longer working now though. I tested in a branch that doesn't have StyleX (pre implementing it) and even added the other change
And RAC continues to work. I still render markup, but things like the JS (data-attributes being added on hover and forcus for example) no longer work. Not able to tell yet, but it seems that when the StyleX plugin runs on my @acme/component-library it breaks RAC, but only in this setup where the plugin is running on a node_modules ES build. In the component library repo eveything works fine with RAC and StyleX. I think I just need to quit on this until someone with more knowledge than I can provide an implementation that works. |
Beta Was this translation helpful? Give feedback.
-
Still reading all your later comments, but you were using media queries wrong. ALL conditions for applying styles should be nested within the property value. Here's the fixed code: https://stackblitz.com/edit/stylex-next-mucdgf?file=app%2Fpage.tsx This is the code you need: const buttonStyle = stylex.create({
base: {
padding: '1em',
borderRadius: '12px',
backgroundColor: {
default: 'yellow',
':hover': 'darkred',
[LIGHT]: {
default: null,
':hover': 'red',
},
},
},
});
const working = stylex.create({
base: {
backgroundColor: {
default: 'green',
[LIGHT]: 'lightgreen',
},
},
}); Another important thing that may have tripped you up: |
Beta Was this translation helpful? Give feedback.
Still reading all your later comments, but you were using media queries wrong. ALL conditions for applying styles should be nested within the property value.
Here's the fixed code: https://stackblitz.com/edit/stylex-next-mucdgf?file=app%2Fpage.tsx
This is the code you need:
Another important thing that ma…