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

Improve arbitrary value support #648

Merged
merged 1 commit into from
Mar 25, 2022

Conversation

ben-rogerson
Copy link
Owner

This PR adds improved and wider support for arbitrary values over a variety of classes.

For example, here some of the hints we can now use on bg which will force the matching property to be used for the output:

tw`bg-[url:url('/img/hero-pattern.svg')]`
tw`bg-[position:200px 100px]`
tw`bg-[image:custom]`

Typehint suggestions

Twin will suggest a list of all the possible typehinted classes if you get one wrong, eg:

tw`bg-[asd:url('/img/hero-pattern.svg')]`

// ↓ ↓ ↓ ↓ ↓ ↓

✕ Bad: `bg-[asd:url('/img/hero.svg')]` < The coerced value of “asd” isn’t available
✓ Good: Try one of these coerced classes:

`bg-[color:url('/img/hero.svg')]` to use `backgroundColor`
`bg-[url:url('/img/hero.svg')]` to use `backgroundImage`
`bg-[image:url('/img/hero.svg')]` to use `backgroundImage`
`bg-[position:url('/img/hero.svg')]` to use `backgroundPosition`
`bg-[length:url('/img/hero.svg')]` to use `backgroundSize`
`bg-[percentage:url('/img/hero.svg')]` to use `backgroundPosition`

Plain arbitrary values

Values without typehints (eg: bg-[200px]) will be validated against each of the possible typehints defined on the class in order to guess the correct property to use.
For example: bg-[200px] will use the backgroundPosition property and bg[url(...)] will use backgroundImage.

Notes

@ben-rogerson ben-rogerson force-pushed the feature/improve-arbitrary-value-support branch from 0264744 to 4cd09bb Compare March 24, 2022 20:15
@ben-rogerson ben-rogerson merged commit 1fe7475 into master Mar 25, 2022
@ben-rogerson ben-rogerson deleted the feature/improve-arbitrary-value-support branch March 25, 2022 23:02
@ben-rogerson ben-rogerson mentioned this pull request Apr 22, 2022
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.

1 participant