-
Hi, so far I've been using the react-aria hooks to build out functionality on top of an existing styled-components component system, but with the hooks functionality falling behind react-aria-components, particularly in terms of the collection stuff, I've just started trying out react-aria-components to see if I could switch things over, starting with Table, where it'd be great to benefit from the batteries-added features in rac. Unfortunately I've stumbled at the first hurdle and I can't figure out what the intended path is for styled-components. I have a TR styled-component that has a The render props approach seems to only give access to these values for the component children, the className render props approach doesn't work with styled-components as far as I can tell. Is there some state hook I can use to get the various render prop parameters? Someone raised something similar with motion here but that thread didn't go anywhere and I couldn't find anything specifically about styled-components. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
I think you can use data attributes to style? See https://react-spectrum.adobe.com/react-aria/Table.html#row-1 for all the available data attributes and their values on table rows |
Beta Was this translation helpful? Give feedback.
-
That'd require going through hundreds of existing styled components in our library and adding react-spectrum-specific selectors which I'm not very keen to do when this functionality already exists nicely parameterized as props. Is there some way instead that I can use the already-supported component props, mapping react-spectrum states like isSelected to the selected prop? |
Beta Was this translation helpful? Give feedback.
Thanks for the context. I think given the constraints I'm working with: (1) keep the existing styled components we have, and (2) use react-aria-components, the only path forward I have is using patch-package to add an
elementType
prop to rac's Table, Cell, Row, Column, etc. components, at which point I pass in my existing Table, TD, TR, TH, etc. styled-components, albeit partially applied so I can apply things like selected props based on the presence ofdata-selected
etc.e.g.
and another to add that prop to Table in the
types.d.ts
then the library wrapper would look something like: