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: move generated ':root' element to themeLayer's first #48

Merged
merged 4 commits into from
Aug 1, 2023

Conversation

GavinXue
Copy link
Contributor

With last version, When we put class="dark"(or other themes) in html root element, It will not change the theme, because the dark theme will covered by :root vars. Just like under image display.

move root first img

Maybe moving the :root element to first make more sense (also changed the test case). if there is any problem I didn't care about, please let me know.

@vercel
Copy link

vercel bot commented Jul 31, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
unocss-preset-theme ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 1, 2023 2:39am

@Dunqing
Copy link
Member

Dunqing commented Jul 31, 2023

Hello, Thank you for your contribution.

The selector option is able to change the :root to anything, so this will cause the sort function not to work, so do we need to have the option to re-order all themes in order, e.g. a themeSort option?

The option looks like this

{
  themeSort: {
     light: 0,
     dark: 1,
     other: 2
  }
}

Do you think this is ok?

@GavinXue
Copy link
Contributor Author

Hi,in my opinion,Add a theme sort maybe make the preset a bit more complicated. Because two themes will not used at same time in most of circumstances. Except the root.
Someone who want to use multi themes at same time, should manage this themselves by their code sorts.
If we offer this option,developer will care about the settings (if we have many, we should set carefully) and their code class sort. Maybe giving a option at the time someone needed will be better.
anyway, if we want, I can try to make it.
Waiting for your reply. Thanks😄

@Dunqing
Copy link
Member

Dunqing commented Jul 31, 2023

Hi,in my opinion,Add a theme sort maybe make the preset a bit more complicated. Because two themes will not used at same time in most of circumstances. Except the root. Someone who want to use multi themes at same time, should manage this themselves by their code sorts. If we offer this option,developer will care about the settings (if we have many, we should set carefully) and their code class sort. Maybe giving a option at the time someone needed will be better. anyway, if we want, I can try to make it. Waiting for your reply. Thanks😄

Yes, I agree with you. That's what I'm worried about. It'll make it complicated.

src/index.ts Outdated Show resolved Hide resolved
src/index.ts Outdated
@@ -167,6 +167,10 @@ export function presetTheme<T extends Record<string, any>>(options: PresetThemeO
line = line.replace(/\..*?\s(.*\{)/, '$1')
}
return line
}).sort((a, b) => {
if (a.match(/^:root|^@media|^\}/)?.length)
return b.match(/^:root|^@media|^\}/)?.length ? 0 : -1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here two lines of code use the same RegExp, So we should store the RegExp to a new variable and then use it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I'll make it clean.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix it, please have a check.

@Dunqing
Copy link
Member

Dunqing commented Aug 1, 2023

Thank you for your great work, I will merge it and publish a new version later

@Dunqing Dunqing merged commit f05e13c into unocss-community:main Aug 1, 2023
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.

2 participants