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

feat(transformer-compile-class): support for custom class names #2577

Merged
merged 9 commits into from May 23, 2023
Merged

feat(transformer-compile-class): support for custom class names #2577

merged 9 commits into from May 23, 2023

Conversation

Techassi
Copy link
Contributor

@Techassi Techassi commented May 5, 2023

This PR adds support for custom compile class names. The current behavior looks like this:

<div class=":uno: font-bold text-white">Foo</div>

Which generates something like this:

.uno-hpseh7{font-weight:700;--un-text-opacity:1;color:rgba(255,255,255,var(--un-text-opacity));}

The PR adds support to customize the compiled class name. It is still possible to customize the trigger (:<TRIGGER>:) and the prefix (default uno-). The new trigger syntax is: :<TRIGGER>(-NAME):. This allows the following behavior:

<div class=":uno-foo: font-bold text-white">Foo</div>
.uno-foo{font-weight:700;--un-text-opacity:1;color:rgba(255,255,255,var(--un-text-opacity));}

The custom compiled class name is added to the tokens set. If a duplicate is encountered, an error is thrown.

Note

Unrelated to this PR, but still worth a mention: the playground doesn't pass tokens in the UnocssPluginContext. It is undefined and results in errors when trying to run the compile class transformer. (I guess this also applies to other transformers)

@netlify
Copy link

netlify bot commented May 5, 2023

Deploy Preview for unocss ready!

Name Link
🔨 Latest commit 8e41906
🔍 Latest deploy log https://app.netlify.com/sites/unocss/deploys/646cb0ec742ddf0007c78cfe
😎 Deploy Preview https://deploy-preview-2577--unocss.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@Techassi
Copy link
Contributor Author

Techassi commented May 8, 2023

Added test. PR should now be ready for review.

@Techassi Techassi marked this pull request as ready for review May 8, 2023 15:47
@Techassi Techassi requested a review from antfu as a code owner May 8, 2023 15:47
@Techassi Techassi changed the title Add support for custom class name in compile class transformer feat(transformer-compile-class): support for custom class names May 8, 2023
packages/transformer-compile-class/src/index.ts Outdated Show resolved Hide resolved
test/transformer-compile-class.test.ts Outdated Show resolved Hide resolved
@zyyv zyyv linked an issue May 10, 2023 that may be closed by this pull request
4 tasks
@Techassi Techassi requested a review from antfu May 11, 2023 14:11
@antfu antfu marked this pull request as draft May 15, 2023 07:23
@antfu
Copy link
Member

antfu commented May 15, 2023

Converting to draft for now, let me know when you think are ready. Thanks!

@Techassi Techassi marked this pull request as ready for review May 22, 2023 14:29
@antfu
Copy link
Member

antfu commented May 22, 2023

Can we have some tests for it, as well as the custom regex? Thanks

@Techassi
Copy link
Contributor Author

Added tests in abc2bac.

@Techassi Techassi requested a review from antfu May 23, 2023 08:05
@antfu antfu enabled auto-merge (squash) May 23, 2023 12:26
@antfu antfu merged commit ef5db97 into unocss:main May 23, 2023
10 checks passed
@Techassi Techassi deleted the feat/compile-custom-name branch May 23, 2023 12:46
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.

[Playground][transformer-compile-class] TypeError: tokens is undefined
2 participants