Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RAC] Add support for children to <ColorSwatch> #7262

Open
andrew-pledge-io opened this issue Oct 25, 2024 · 2 comments
Open

[RAC] Add support for children to <ColorSwatch> #7262

andrew-pledge-io opened this issue Oct 25, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@andrew-pledge-io
Copy link

andrew-pledge-io commented Oct 25, 2024

Provide a general summary of the feature here

Add a children prop to <ColorSwatch> that can take a ReactNode or a render prop that is passed the swatch color that returns a ReactNode.

🤔 Expected Behavior?

With a ReactNode

<ColorSwatch>
 <span>Aa</span>
</ColorSwatch>

or with a render prop

<ColorSwatch>
  {({ color }) => (
    <span style={{ color: color.toString('css') }}>
      Aa
    </span>
  )}
</ColorSwatch>

😯 Current Behavior

<ColorSwatch> doesn't render any children.

💁 Possible Solution

I think the starting point is to add children to the render props here:

let renderProps = useRenderProps({
...props,
defaultClassName: 'react-aria-ColorSwatch',
defaultStyle: colorSwatchProps.style,
values: {
color
}
});

I'm not sure what else if anything would be needed.

🔦 Context

I have a swatch that renders some text on top of the selected color in order to demonstrate text contrast, e.g.:

image

This is currently being done with <ColorSwatch> by absolutely positioning the text element on top of the swatch relative to a shared parent.

💻 Examples

No response

🧢 Your Company/Team

No response

🕷 Tracking Issue

No response

@snowystinger
Copy link
Member

Could you use the css property content with a string?
We'd need to enforce some roles if we allowed children, they'd all need to be presentational.

@andrew-pledge-io
Copy link
Author

I'm currently using an absolutely positioned sibling as a workaround.

I'm sure a pseudo element could be made to work but it's a little more difficult to style given the color is coming from JavaScript, especially in Tailwind.

@snowystinger snowystinger added the enhancement New feature or request label Oct 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants