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 arbitrary variants #546

Merged
merged 1 commit into from
Oct 13, 2021
Merged

Add arbitrary variants #546

merged 1 commit into from
Oct 13, 2021

Conversation

ben-rogerson
Copy link
Owner

This PR adds custom selectors to twin.
These selectors can be added within square brackets using the same syntax as variants:

// Style all child paragraph elements
tw`[div]:block`

// ↓ ↓ ↓ ↓ ↓ ↓

({
  "div": {
    "display": "block"
  }
});

Add scoped styles from a parent

// Prop styling
;<div tw="[p]:(text-white bg-black) [div]:my-4">
    <p>...</p>
	<div>...</div>
</div>

// Styled component
const Component = tw.div`[p]:(text-white bg-black) [div]:my-4`
;<Component>
    <p>...</p>
	<div>...</div>
</Component>

Style all child elements when the parent is hovered

// Prop styling
;<div tw="hover:[*]:bg-black">...</div>

// Styled component
const Component = tw.div`hover:[*]:bg-black`
;<Component>....</Component>

Style an element by its custom className

// Prop styling
const Component = (props) => (
	<div {...props} tw="[&.is-padded]:p-10">...</div>
)
;<Component className="is-padded" />

// Styled component
const StyledComponent = tw.div`[&.is-padded]:p-10`
const Component = (props) => (
	<StyledComponent {...props}>....</StyledComponent>
)
;<Component className="is-padded" />

@ben-rogerson ben-rogerson merged commit 5c5c707 into master Oct 13, 2021
@ben-rogerson ben-rogerson deleted the feature/arbitrary-variants branch October 13, 2021 01:27
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

Successfully merging this pull request may close these issues.

None yet

1 participant