Replies: 2 comments 2 replies
-
For those following along,
So this is working. Would like a solution that works as well as classname does out of the box, we will see if they want to work on it. Updated my repo but have no rebuilt the package related to it. Calling it a night. |
Beta Was this translation helpful? Give feedback.
-
I take that back, now I'm calling it a night. Here is the new method. <RACButton
{...props}
className={(renderProps: ButtonRenderProps) => stylex.props(
buttonStyle.base,
variantStyles,
renderProps.isFocusVisible && styleXFocusRing.base,
props.isDisabled && disabled.base,
).className || ''}
style={(renderProps: ButtonRenderProps) => stylex.props(
buttonStyle.base,
variantStyles,
renderProps.isFocusVisible && styleXFocusRing.base,
props.isDisabled && disabled.base,
).style || {}}
/> This is working so far. Would love to know if anyone think there could be bad side effects by not spreading in the |
Beta Was this translation helpful? Give feedback.
-
-Edit- Hi Naman, if you get to this one feel free to jump down to this comment That where I was hoping to get your feedback. Thank you very much!
I was working on the last thing (ha! My to-do lists never end!) on my to-do list:
Figure a way to get the React Aria Component render props into the Stylex spread function.
If you search for "The states, selectors, and render props" on this page you will see a list of the states I have been trying to access. It also lists the data-attributes you can use. However, relying on the data-attributes is not as reliable, and kinda makes Stylex style objects messy and complicated. Much better to be able to use style objects conditionally.
Additionally in the same link you can see all the props you can access for styling. Props we can access easily, but the states, selectors, and render props has been the issue.
What I discovered as a solution is to use React Aria's hooks for the state. For example:
import {useFocusVisible} from 'react-aria';
and
const { isFocusVisible } = useFocusVisible();
And now you can use isFocusVisible in your Stylex spread function.
It is a bit of a shame that RAC Button component is already using
useFocusVisible
, among others, but does not expose it. So it feels like repeating work. They do have some functions in their utils file that help with making this easier when you just use classname. For example:It would be nice to have a similar reusable function so that you wouldn't have to do the above work for every component. I have started a discussion over in their GitHub.
Beta Was this translation helpful? Give feedback.
All reactions