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

Add styled-component as styling-property (like 'states') #333

Closed
misantronic opened this issue Dec 15, 2021 · 6 comments
Closed

Add styled-component as styling-property (like 'states') #333

misantronic opened this issue Dec 15, 2021 · 6 comments

Comments

@misantronic
Copy link

misantronic commented Dec 15, 2021

🚀 Feature Proposal

Ability to add a styled-component as a styling-property just like we do it in the states of a theme.

Motivation

Sometimes it isn't possible to map a css-context directly to xstyled-system.
A neat addition to the existing states of xstyled would be to add a styled-component (which stringifies to a css-class) to the tree, so it would be possible to specifically style this component.

Example

xstyled workaround:

const Child = styled(x.div)``;

const Parent = styled(x.div)`
  &:hover ${StyledComponent} {
    color: red;
  }
`

how it could be:

const Child = styled(x.div)``;

const Parent = styled(x.div)``

Parent.defaultProps = {
  color: {
    hover: { [Child]: 'red' }
  }
}

Pitch

I think this would be a really great addition to the existing system. I saw issues where this exact problem was solved by various workarounds that don't really fit the system.

@jguddas
Copy link
Contributor

jguddas commented Dec 17, 2021

Example: <x.div color={{ '&:empty': 'red' }}/>

It feels absolutely right to fall back to &:empty when theme.states['&:empty'] is not defined,
just like we use red when theme.colors.red is not defined.

@gregberge I'm happy to give this a try and create a PR if you like this idea.

@gregberge
Copy link
Collaborator

I see the idea, not sure it is easy to implement.

jguddas pushed a commit to jguddas/xstyled that referenced this issue Dec 19, 2021
@misantronic
Copy link
Author

@gregberge can you please link the line in the code, where those default states are applied?

@jguddas
Copy link
Contributor

jguddas commented Jan 5, 2022

gregberge pushed a commit that referenced this issue Apr 15, 2022
@jguddas
Copy link
Contributor

jguddas commented Apr 15, 2022

@misantronic is there anything other than #334 that needs to be done, or can this be closed?

@gregberge
Copy link
Collaborator

It should work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants