Features
- Generate smart and efficient code (just like hand written) at compile time. Leaving no runtime overhead.
- Support autocomplete with TailwindCSS IntelliSense.
- Support
clsxobject syntax for conditional applying style. - Support both creation and mutation.
Installation
And add plugin to your app, skip this step if you dont use hover: and focus: classes.
use ;
Configure autocomplete
- Install TailwindCSS IntelliSense
- Create
tailwind.config.jsin your project (recommend in the root folder) and add the following content
module.exports = ;
- Add the following settings to your
settings.jsonin vscode
How does it work?
bevy_tailwind will generate corresponding components for given tailwind classes. For example
tw!;
will generate the following components Node, BackgroundColor, ZIndex, BorderColor
When using object syntax, it will apply priority when generating code. Consider the following example, all flex, block and grid is applied to the display property, but the latter will have higher priority. So the order is grid, block, flex.
tw!;
And here is the generated code
Now consider more complex example. pl has higher priority than px, p and the latter one will overwrite. So the order for padding left is pl-4, pl-3(from px-3 but this will be overwrite by pl-4), pl-2, pl-5(from p-5), pl-1(from p-1).
tw!;
And here is the generated code (for padding left only, other properties are ommitted to reduce code size for this example). You can see the code is for pl-3 from px-3 is not generated because it will always be overwritten by pl-4
The same rules will also be applied for mutation syntax.
tw!;
Troubleshooting
If you encounter weird rendering issues, you can check the generated code by using RustAnalyzer's Expand Macro feature or cargo expand.
Bevy compatibility
bevy_tailwind |
bevy |
|---|---|
| 0.2.0 | 0.15.0 |
TailwindCSS compatibility
Most of TailwindCSS classes that Bevy can render are supported. See all supported classes here