Add type-safe Tailwind CSS utilities via ironhtml-tailwind crate#34
Add type-safe Tailwind CSS utilities via ironhtml-tailwind crate#34
Conversation
Co-authored-by: dannywillems <6018454+dannywillems@users.noreply.github.com>
Co-authored-by: dannywillems <6018454+dannywillems@users.noreply.github.com>
Co-authored-by: dannywillems <6018454+dannywillems@users.noreply.github.com>
|
@copilot add examples using the macros system. Everyone wants to use the macro system |
|
@copilot for each classes, add a link to the actual doc. |
- Add tailwind_macro.rs example demonstrating usage with html! macro - Add documentation links to Tailwind CSS docs for all utility classes - Update README with macro example and both example commands - Enable macros feature in ironhtml-tailwind dependencies Co-authored-by: dannywillems <6018454+dannywillems@users.noreply.github.com>
Added
Run with: Commit: 1664d1b
Added documentation links to Tailwind CSS official docs for all utility classes. Each enum and module now includes links to the corresponding documentation:
Commit: 1664d1b |
|
@copilot Don;t use plain strings for the classes in the macro example. I want you to have something very close to the html we would write, but get it typed. |
The example now demonstrates three approaches: 1. Simple html! macro with raw string classes (for comparison) 2. Type-safe component functions using .tw() methods 3. Complete page built with type-safe Tailwind utilities This shows how to get type safety while still using familiar HTML-like syntax. Co-authored-by: dannywillems <6018454+dannywillems@users.noreply.github.com>
Updated the
The type-safe approach provides:
Example output shows all utilities generate correct Tailwind classes. Commit: 2010589 |
Raw string classes like
class("px-4 text-center")provide no safety—conflicting utilities silently coexist. This adds a newironhtml-tailwindcrate providing type-safe Tailwind utilities through Rust enums.API
With Typed API and Helper Components
Create type-safe Tailwind components using
.tw()methods:Direct Element Builder API
Extension trait on
Element<E>adds.tw()methods:With html! Macro
The
html!macro can be combined with type-safe helper functions:Utility Coverage
All utilities include links to official Tailwind CSS documentation:
Padding,Marginwith directional variants (X, Y, T, B, L, R, All, Auto)Display,Position,OverflowFontSize,FontWeight,TextAlign,TextColor(22 color families × shades)FlexDirection,JustifyContent,AlignItemsGridCols,GridRows,GapWidth,Height(scaled, fractions, full, screen)BorderWidth,BorderColor,BorderRadiusBackgroundColor(full color palette)Shadow,OpacityResponsive & State Variants
.tw_sm(),.tw_md(),.tw_lg(),.tw_xl(),.tw_2xl().tw_hover(),.tw_focus(),.tw_active(),.tw_disabled()Implementation
Each utility category is a Rust enum implementing
TailwindClasstrait for class string conversion.TailwindElementtrait extendsElement<E>with builder methods. Arbitrary values supported viaArbitraryValuetype (e.g.,Padding::Arbitrary(ArbitraryValue { value: "13px", axis: SpacingAxis::X })).Examples
Two complete examples demonstrate the crate's capabilities:
tailwind_macro.rs- Type-safe Tailwind utilities with helper components (recommended approach)tailwind_demo.rs- Direct type-safe API with.tw()methodsRun with:
cargo run --example tailwind_macroorcargo run --example tailwind_demoThe
tailwind_macroexample shows three approaches:html!macro with raw string classes (for comparison).tw()methodsFully documented with comprehensive README and inline documentation linking to official Tailwind CSS docs.
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.