Skip to content

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

Open
@andrew-pledge-io

Description

@andrew-pledge-io

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions