Open
Description
Description
I propose the addition of a UTheme component which would allow scoped theming of components to reduce repeated styling that's error prone when refactoring.
Example
The Dashboard template has a bunch of forms that have horizontal form fields (label left, input right).
Before:
<UForm ...>
<UFormField ... class="flex max-sm:flex-col justify-between items-center gap-4">
...
<UFormField>
<UFormField ... class="flex max-sm:flex-col justify-between items-center gap-4">
...
<UFormField>
<UForm/>
After:
<!-- `ui` prop is the same as `app.config.ts` theming config
<UTheme :ui="{
formField: {
slots: {
root: "flex max-sm:flex-col justify-between items-center gap-4",
},
},
}">
<UForm ...>
<UFormField ...>
...
<UFormField>
<UFormField ...>
...
<UFormField>
<UForm/>
</UTheme>
Benefits
- Easily componentized. I could create a
AppForm
component which contains theUTheme
usage with a slot, so now its 1 line to get the exact theming that I want. This makes consistency across the app really easy. - Nestable - If implemented with provide/inject, you could have an infinite number of UTheme's nested and it would take the latest one
Implementation
I'd tentatively be willing to implement this. My approach would be:
- Create
UTheme
, it should have aui
anduiPro
prop, each of which take the same type as theapp.config.ts
provide()
those propsinject()
those props into each component and merge with passed inui
field.- Theme priority order should be:
ui
prop passed to componentui
prop coming from UTheme componentui
config coming fromapp.config.ts
Additional context
No response