diff --git a/Cargo.toml b/Cargo.toml index 555458b..d0a16ed 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,6 +14,7 @@ ironhtml-attributes = { path = "crates/ironhtml-attributes" } ironhtml = { path = "crates/ironhtml" } ironhtml-macro = { path = "crates/ironhtml-macro" } ironhtml-bootstrap = { path = "crates/ironhtml-bootstrap" } +ironhtml-tailwind = { path = "crates/ironhtml-tailwind" } proc-macro2 = "1" quote = "1" syn = { version = "2", features = ["full", "parsing", "extra-traits"] } diff --git a/crates/ironhtml-tailwind/Cargo.toml b/crates/ironhtml-tailwind/Cargo.toml new file mode 100644 index 0000000..370a567 --- /dev/null +++ b/crates/ironhtml-tailwind/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "ironhtml-tailwind" +version.workspace = true +edition.workspace = true +license.workspace = true +repository.workspace = true +description = "Type-safe Tailwind CSS utilities for ironhtml with compile-time conflict detection" +keywords = ["html", "tailwind", "css", "type-safe"] +categories = ["web-programming"] + +[lints] +workspace = true + +[dependencies] +ironhtml = { workspace = true, features = ["macros"] } +ironhtml-elements.workspace = true diff --git a/crates/ironhtml-tailwind/README.md b/crates/ironhtml-tailwind/README.md new file mode 100644 index 0000000..e8225d8 --- /dev/null +++ b/crates/ironhtml-tailwind/README.md @@ -0,0 +1,206 @@ +# ironhtml-tailwind + +Type-safe Tailwind CSS utilities for [ironhtml](https://github.com/LeakIX/ironhtml) with ergonomic API and full IDE support. + +## Features + +- **Type-safe**: All Tailwind utilities are strongly typed enums +- **Ergonomic**: Fluent API that integrates seamlessly with ironhtml +- **Responsive**: Built-in support for responsive breakpoints (sm, md, lg, xl, 2xl) +- **State variants**: Support for hover, focus, active, and other pseudo-classes +- **Arbitrary values**: Escape hatch for custom classes +- **No runtime overhead**: All abstractions compile away +- **no_std compatible**: Works in embedded and WASM environments + +## Quick Start + +Add to your `Cargo.toml`: + +```toml +[dependencies] +ironhtml = "1.0" +ironhtml-tailwind = "1.0" +``` + +## Usage + +### With html! Macro (Recommended) + +The html! macro provides the most ergonomic syntax for building HTML with Tailwind: + +```rust +use ironhtml::html; + +let card = html! { + div.class("bg-white rounded-lg shadow-md p-6 hover:shadow-lg") { + h2.class("text-2xl font-bold text-gray-900 mb-2") { + "Welcome" + } + p.class("text-gray-600 mb-4") { + "Type-safe HTML with Tailwind utilities" + } + button.class("bg-blue-500 text-white px-4 py-2 rounded hover:bg-blue-600") { + "Get Started" + } + } +}; +``` + +See the [macro example](examples/tailwind_macro.rs) for a complete demonstration. + +### With Typed API + +For type-safe Tailwind utilities: + +```rust +use ironhtml::typed::Element; +use ironhtml_elements::Div; +use ironhtml_tailwind::*; + +let element = Element::
::new() + .tw(Padding::X(4)) // px-4 + .tw(TextAlign::Center) // text-center + .tw(Display::Flex) // flex + .tw(FontWeight::Bold); // font-bold + +let html = element.render(); +//
+``` + +### Responsive Design + +```rust +use ironhtml::typed::Element; +use ironhtml_elements::Div; +use ironhtml_tailwind::*; + +let element = Element::
::new() + .tw(Padding::X(4)) // Mobile: px-4 + .tw_md(Padding::X(8)) // Tablet: md:px-8 + .tw_lg(Padding::X(12)); // Desktop: lg:px-12 +``` + +### Interactive States + +```rust +use ironhtml::typed::Element; +use ironhtml_elements::Button; +use ironhtml_tailwind::*; + +let button = Element::