-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Isolated class names or Prefix class names for VitePress default theme #199
Comments
Thanks for the feedback! Good point. I was also thinking that we should "scope" styles. However, it might not be that super easy doing that inside markdown content. Since the docs are generated from markdown, the tags will be generic So in your case, if you were to add Vue Component inside markdown, it will get affected by those generic tag styles 🤔 I don't think it would make sense to add custom VitePress class to those generated tags like That's being said, we should scope or even prefix generic "classes" such as |
In In order to stop affecting custom Vue Component rendered inside markdown, is another topic. This one is not that easy to solve. We could add special class something like It would be really cool if we have any neet idea to overcome this issue 🤔 |
Hi team 👋🏻 What if we add Change from: .vp-doc h1,
.vp-doc h2,
.vp-doc h3,
.vp-doc h4,
.vp-doc h5,
.vp-doc h6 {
position: relative;
font-weight: 600;
outline: none;
} to .vp-doc:not(.not-vp-doc) h1,
.vp-doc:not(.not-vp-doc) h2,
.vp-doc:not(.not-vp-doc) h3,
.vp-doc:not(.not-vp-doc) h4,
.vp-doc:not(.not-vp-doc) h5,
.vp-doc:not(.not-vp-doc) h6 {
position: relative;
font-weight: 600;
outline: none;
} Now if I have doc content like beow:
it should work. This is same as the typography preset of UnoCSS where This will definetely resolve the issue where we need to isolate the vp-doc styles to content only (don't apply them to demo container). Moreover, I suggest writing SCSS instead of CSS so we can use nesting and don't have to write |
I like the idea. Maybe name it
I never used SCSS so no, but, maybe it's time to consider adding postcss support with nesting plugin 😅 |
Do you want me to make a PR on this or have you already started working on it? @kiaking |
Not yet! Please feel free to work on it 🙌 |
|
Hi @brc-dd Sorry for ping but I am refactoring CSS to SCSS and I don't know what to do with Should I keep that file as it is (and just change the extension to |
Keep it as it is. But I don't think Kia wanted refactoring styles to SCSS. |
I asked him. Let me know if I should continue on it |
IG he was saying to use this one: https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-nesting. /cc @kiaking |
Oops. Actually, I worked on it and I am almost there with this PR: #850 |
Regarding (according to best of my knowledge and my research) SCSS It's tricky to add However, if we can use PostCSS with SCSS (maybe this can help), we can modify the selectors somehow to automatically add PostCSS As said above we can automatically add Complete IsolationAnother thing I suggest is allowing
@kiaking Please let me know your thoughts on this & PR |
If we have nesting, why don't we just nest everything? .vp-doc:not(.vp-raw) {
h1,
h2,
h3,
h4,
h5,
h6 {
position: relative;
font-weight: 600;
outline: none;
}
}
This is another issue indeed. Currently, when styles are imported from |
Providing For this, we need a complex selector like Tailwind does: Playground Hence, we need to append To resolve this we can post-process vp-doc selectors and append the above trick. This is quite complex though. Let me know your thoughts on this. |
Wouldn't just <div class="vp-doc">
...
<div class="vp-raw">
<div class="foo">unstyled</div>
</div>
...
<div class="foo">styled</div>
...
</div> Refer this for space in CSS selectors if you've some doubt: https://stackoverflow.com/a/58681511/11613622 Obviously this won't work if you directly add
We don't have any styles on direct child of |
I am trying various solutions in this pen: https://codepen.io/jd-0001/pen/abqeLyK Unfotunately, this is not simple as we thought.
Right now I am busy with some other stuff but whenever I get time I will try to make another PR using PostCSS. |
Ah right. Something like this should work though: https://play.tailwindcss.com/N2oYh1GHyt?file=css Markup:<div class="vp-doc">
<div>
<h1>Hey there</h1>
<p>Hello world</p>
<div class="vp-something">
<h1>Hey there</h1>
<p>Hello world</p>
</div>
<div class="vp-raw">
<h1>Hey there</h1>
<p>Hello world</p>
<div class="user-something vp-raw">
<h1>Hey there</h1>
<p>Hello world</p>
</div>
</div>
</div>
</div> Styles:h1,
p {
color: tomato;
}
.user-something {
font-size: 1.5em;
}
/* our styles below */
.vp-doc :not(.vp-raw) > h1,
.vp-doc :not(.vp-raw) > p {
color: green;
} Output:The user will have to add |
If I will be tiny PR then 😉 Do you want me to make PR following your changes? |
If you have time then go ahead! |
It will surely have specificity problems 😅. Adding |
I will try my best to avoid side effects. Thanks for the clean solution :) |
Okay, so after some testing, I think the users can themselves add this short code to support // docs/.postcssrc.cjs
module.exports = {
plugins: {
'postcss-prefix-selector': {
prefix: ':not(:where(.vp-raw *))',
includeFiles: [/vp-doc\.css/],
transform(prefix, _selector) {
const [selector, pseudo = ''] = _selector.split(/(:\S*)$/)
return selector + prefix + pseudo
}
}
}
} Here is the complete demo: https://github.com/brc-dd/vp-raw Adding this won't affect the specificity and all. We probably should add support for this in the router alone. Users can have the CSS part if they wish using the above config. This will prevent increasing the bundle size for those who don't need it. |
Yes ❤️ It's working. it's time to close this issue 🥳 What's next then?
|
I think CSS normalization can be left that way. All the selectors there are of lowest specificity, users will be able to override them without any issue. |
I will wait for the update 😊 |
Closing this for now. Will document it while resolving #591. |
Is your feature request related to a problem? Please describe.
I am using VuePress and me generally create documentation for UI components which includes already created templates/components. In this case, when we import template styles it conflicts with VuePress's style.
e.g.
container
class is present in both styles (VuePress & Template/Project Styles) hence create undesired result.Describe the solution you'd like
I guess prefixing class names will do the magic or some kind of isolation so it doesn't affect the user's classes/styles.
So here I am creating issue in VitePress so if possible this can be taken care of from start.
Describe alternatives you've considered
I created my own vuepress theme but it is not as flexible and stable as the default theme.
Additional context
None
The text was updated successfully, but these errors were encountered: