-
-
Notifications
You must be signed in to change notification settings - Fork 780
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: support extendTheme
return to override
#2258
Conversation
✅ Deploy Preview for unocss ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site settings. |
ba7e61f
to
4bff5c6
Compare
489b6c3
to
3d439c8
Compare
packages/core/src/config.ts
Outdated
let theme = [ | ||
...sortedPresets.map(p => p.theme), | ||
config.theme, | ||
].reverse().find(Boolean) as Theme | ||
theme = (mergePresets('extendTheme') as ThemeExtender<Theme>[]) | ||
.reduce((mergedTheme, extendTheme) => mergeDeep(mergedTheme, extendTheme(mergedTheme) || {}), theme) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the logic here is wrong, you need to consider the existence of other preset theme configurations.
And I switched to your branch and did a simple test and found that none of the results were what I wanted.Dunqing#1.
And you'd better add more test case for it, thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your review.
In my opinion the result what i wanted. Because i think preset
should respect this rule. most presets should not set theme
, but rather use extendTheme
to expand the theme.
I will add test cases later to show the intent of this change.
Considering some theme key may require proper ordering (see container), whats the cons of being able to provide callback in theme object? |
This doesn't quite close #2242, the desire of which is to disable the colors emanated by |
In your case, you can use extendTheme(theme) {
theme.colors = {}
} |
For theme keys that depend on order, you can use extendTheme to replace the whole theme key. |
No, I don't think this breaking change is worth it. It's how it works by design from the beginning. It's a trade-off between two usages, this reverts the prioritizes, which to me, makes no difference from the current behavior (deep-merge over overrides, or overrides over deep-merge). I would suggest we introduce a new option, say: defineConfig({
theme: {
colors: { ... }
},
themeResolved(mergedTheme) {
// by default
return mergedTheme
// completely ignore the theme, override with a custom one
return { ... }
// partially overrides, with reference to the resolved theme
return {
...mergeTheme,
colors: { ... } // override colors, but keep the rest of the theme,
breakpoints: {
large: mergeTheme.breakpoints.xl,
small: mergeTheme.breakpoints.xl
}
}
}
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes requested
themeResolved
option
Do we need to support |
Let's say you have 3 presets, Perhaps a configuration option for all presets like:
with defaulting to just include all true?
or
or
all working how you might expect |
packages/postcss/package.json
Outdated
@@ -42,6 +42,7 @@ | |||
"dependencies": { | |||
"@unocss/config": "workspace:*", | |||
"@unocss/core": "workspace:*", | |||
"@unocss/preset-mini": "workspace:*", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should avoid introducing this, as well as in the transformer directives
0a98702
to
b266f33
Compare
themeResolved
optionextendTheme
return to override
Thanks! Pushed a change to merge those two APIs into |
This PR aims to be shipped with next minor |
close: #2242
Currently
theme
andextendTheme
have the same effect. I think this behavior is not correct.In fact, we should allow
theme
to override the preset's theme, and if we want to add configuration to the originaltheme
, we should useextendTheme
. This improvement is similar to the wayTailwind
is handled.So I have made some changes.
theme
configuration is not merged, if we providetheme
, we only use it.extendTheme
will be mergeduserConfig.theme.breakpoints
exists or not, just useconfig.theme.breakpoints
instead.