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

[Feature]: support for shadow dom in Twind v1? #421

Closed
GorvGoyl opened this issue Dec 14, 2022 · 5 comments · Fixed by #417
Closed

[Feature]: support for shadow dom in Twind v1? #421

GorvGoyl opened this issue Dec 14, 2022 · 5 comments · Fixed by #417
Labels
✨ Feature Request Something should be added

Comments

@GorvGoyl
Copy link

Describe the problem

How to add Tailwind classes inside shadow dom?

Describe the proposed solution

There was a nice documentation about adding support for shadow DOM for the beta version https://twind.dev/usage-guides/web-components.html, but the required classes create and cssomSheet are not present in the latest version. This is also not mentioned in the migration guide.

Alternatives considered

No response

Importance

I cannot use Twind without it

Additional Information

No response

@GorvGoyl GorvGoyl added the ✨ Feature Request Something should be added label Dec 14, 2022
@sastan sastan closed this as completed in 1e16652 Dec 14, 2022
@sastan
Copy link
Collaborator

sastan commented Dec 14, 2022

You can view a preview of the docs here: https://next.twind-style.pages.dev/with-web-components. I have added a Lit as well in case you are using that: https://next.twind-style.pages.dev/with-lit

There was a small issue that will be fixed in the next release (#417). Until that is released you can use the pre-release version (for example @twind/core@next or @twind/preset-tailwind@next).

If you have any issues or questions please re-open this issue.

@GorvGoyl
Copy link
Author

@sastan, thanks; it seems to be working for me. I also wrote small guide in case others are looking for the solution https://gourav.io/blog/tailwind-in-shadow-dom

@sastan
Copy link
Collaborator

sastan commented Dec 15, 2022

I have implemented in a new integration: @twind/with-web-components. It supports modern and legacy browsers. Please take a look at the new docs: https://next.twind-style.pages.dev/with-web-components and https://next.twind-style.pages.dev/with-lit

This will be released soon (#417). Until is released you can use the pre-release version (for example @twind/with-web-components@next, @twind/core@next or @twind/preset-tailwind@next).

@sastan
Copy link
Collaborator

sastan commented Dec 15, 2022

@sastan, thanks; it seems to be working for me. I also wrote small guide in case others are looking for the solution gourav.io/blog/tailwind-in-shadow-dom

Nice article. One thing I wonder: the new @twind/with-web-components wouldn't really help when you want to attach to existing normal elements. Would it be helpful to have a dedicated @twind/with-shadow-root package? Something like:

import install from "@twind/with-shadow-root";
import config from "./twind.config"; 

const attach = install(config);

attach(document.querySelector(".my-shadow-root-container"))

I really don't know if there is a use case for this. Are you using such a pattern?

@GorvGoyl
Copy link
Author

GorvGoyl commented Dec 16, 2022

@sastan I'll give you some context... I'm developing a chrome extension and need to show some UI using shadow DOM on web pages so that the styles don't get leaked to the page. You're right that @twind/with-web-components won't be helpful in my case as I'm not using lit or web components. If you could provide @twind/with-shadow-root that abstracts away the code, that'd be nice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ Feature Request Something should be added
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants