You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ui internally uses tv to flexibly generate component class names. tv internally uses tm to merge classes with the same effect (e.g., p-2 p-4 --> p-4), and finally uses tw to recognize class names and generate style classes.
After examining tv and tm, it became apparent that they don't strongly depend on tw, which opens up the possibility of replacing the final style generation step with uno.
## tw Prefix Attempt (Optional)
Initially, the idea was to limit tw to ui internals and uno for user usage. With tw's prefix feature, the class rules became simpler. However, ui internally (v3.0.0-alpha.10) doesn't yet support passing tw prefix configuration, so let's first make ui support tw prefixes.
Understanding tv Variants
To add prefixes, we need to analyze the data structure that tv accepts.
Regular Variants
import{tv}from'tailwind-variants';tv({variants: {foo: {foo_val: 'px-2',// or ['pxx-2', ...], be the same, class / className},}})({foo: 'foo_val'})
tv({variants: {foo: {foo_val: 'px-2',foo_val2: 'px-2',},bar: {true: 'px-2',false: 'py-2',},},compoundVariants: [{foo: 'foo_val',// or ['foo_val', 'foo_val2', ]bar: true,class: 'text-white',// You can also use "className" as the key}],})({foo: true,})
Responsive Variants (Device screen sizes)
tv({variants: {foo: {foo_val: 'px-2',foo_val2: 'px-4',},}},{responsiveVariants: ['sm','md']// or `true` for all})({foo: {initial: 'foo_val',sm: 'foo_val',md: 'foo_val2',}})
Slot Variants (Combining above variants with slots)
tv({slots: {slot_a: 'mx-2',slot_b: 'mx-2',},compoundSlots: [{slots: ['slot_a','slot_b',],class: '',foo: 'foo_val',// for all slot while variant is missing},],variants: {foo: {foo_val: {slot_a: 'px-2',}},bar: {true: {slot_a: 'mx-2'},false: {slot_a: 'mx-0'},},},compoundVariants: [{foo: 'foo_val',bar: true,class: {slot_a: '',}}],{responsiveVariants: ['sm','md']// or `true` for all}})({foo: {initial: 'foo_val',sm: 'foo_val',md: 'foo_val2',}})// --> { foo_slot, bar_slot, }
Summary
After adding prefix functionality locally (#3009 ) and configuring tw prefix (while installing uno to handle non-prefix classes in the playground for page styling), practical usage revealed some unavoidable conflicts, such as at-rule usage. Additionally, this approach doesn't effectively prevent files from being processed twice (by both tw & uno). Therefore, let's try a different approach: remove tw completely and use UnoCSS for everything!
Modifying ui
Disabling tw Plugin
Remove @tailwindcss/vite installation handling from ui internals.
Remove tw imports and specific configurations from ui playground.
exportdefaultdefineConfig({presets: [presetUno(),],content: {pipeline: {include: [// the default/\.(vue|svelte|[jt]sx|mdx?|astro|elm|php|phtml|html)($|\?)/,// IMPORTANT include @nuxt/ui files/\.nuxt\/ui\//,]}}})
Primitive Variables
uno doesn't generate primitive variables like tw does (e.g., --color-green-500, --text-lg, --radius-md, etc.), but ui internally needs these variables.
For now, we'll directly copy the primitive variables from tw's normal loaded to local.
Rule Inconsistencies
There are must more undiscovered issues
Ring
In uno, the default ring width is 3px, different from tw's 1px.
Solution:
shortcuts: {ring: 'ring-1'},
Color Opacity
tw internally uses color-mix, allowing direct opacity settings for color variables.
Currently, uno doesn't support this directly.
Related #196
ui internally uses tv to flexibly generate component class names. tv internally uses tm to merge classes with the same effect (e.g.,
p-2 p-4
-->p-4
), and finally uses tw to recognize class names and generate style classes.After examining tv and tm, it became apparent that they don't strongly depend on tw, which opens up the possibility of replacing the final style generation step with uno.
## tw Prefix Attempt (Optional)
Initially, the idea was to limit tw to ui internals and uno for user usage. With tw's prefix feature, the class rules became simpler. However, ui internally (v3.0.0-alpha.10) doesn't yet support passing tw prefix configuration, so let's first make ui support tw prefixes.
Understanding tv Variants
To add prefixes, we need to analyze the data structure that tv accepts.
Regular Variants
Boolean Variants (Including true/false keys)
Compound Variants (Intersection between variants)
Responsive Variants (Device screen sizes)
Slot Variants (Combining above variants with slots)
Summary
After adding prefix functionality locally (#3009 ) and configuring tw prefix (while installing uno to handle non-prefix classes in the playground for page styling), practical usage revealed some unavoidable conflicts, such as at-rule usage. Additionally, this approach doesn't effectively prevent files from being processed twice (by both tw & uno). Therefore, let's try a different approach: remove tw completely and use UnoCSS for everything!
Modifying ui
Disabling tw Plugin
Remove
@tailwindcss/vite
installation handling from ui internals.Remove tw imports and specific configurations from ui playground.
Introducing uno
For nuxt | vite
Also, Style Reset can be applied as needed.
IMPORTANT: Include @nuxt/ui files
Primitive Variables
uno doesn't generate primitive variables like tw does (e.g.,
--color-green-500
,--text-lg
,--radius-md
, etc.), but ui internally needs these variables.For now, we'll directly copy the primitive variables from tw's normal loaded to local.
Rule Inconsistencies
There are must more undiscovered issues
Ring
In uno, the default
ring
width is 3px, different from tw's 1px.Solution:
Color Opacity
tw internally uses color-mix, allowing direct opacity settings for color variables.
Currently, uno doesn't support this directly.
tw:
class="bg-[var(--color-primary)]/20"
✓uno:
class="bg-[var(--color-primary)]/20"
✕uno:
class="bg-[rgb(255,5,5)]/20"
✓After observing ui usage, uno rules were added:
uno:
class="bg-[var(--ui-primaey)]/20"
✓uno:
class="hover:bg-[var(--ui-primaey)]/75"
✓Solution:
Now, let's run the playground! ~
Notes
tm's handling of tw and uno exclusive rules yields unexpected results
tw doesn't directly support units (px, em, ...) like
text-Xpx
, requiringtext-[Xpx]
instead.text-md text-[20px]
-->text-[20px]
text-md text-20px
-->text-md text-20px
text-16px text-20px
-->text-20px
text-[16px] text-[20px]
-->text-[20px]
When using ui, it's recommended to pass classes that tw can also parse.
Commits · byronogis/ui
The text was updated successfully, but these errors were encountered: