//! Example integration of tailwind-rs-core with Leptos components. use leptos::prelude::*; use tailwind_rs_core::*; /// Example button component using tailwind-rs-core for type-safe styling. #[component] pub fn EnhancedButton( #[prop(optional)] variant: Option, #[prop(optional)] size: Option, #[prop(optional)] disabled: Option, #[prop(optional)] children: Option, ) -> impl IntoView { let variant = variant.unwrap_or(ButtonVariant::Primary); let size = size.unwrap_or(ButtonSize::Md); let disabled = disabled.unwrap_or(false); // Create reactive class signal using tailwind-rs-core let classes = create_class_signal(variant, size, disabled); view! { } } /// Button variant enum for type-safe styling. #[derive(Debug, Clone, PartialEq, Eq)] pub enum ButtonVariant { Primary, Secondary, Success, Warning, Error, Outline, Ghost, Link, Destructive, } /// Button size enum for type-safe styling. #[derive(Debug, Clone, PartialEq, Eq)] pub enum ButtonSize { Xs, Sm, Md, Lg, Xl, } /// Create a reactive class signal for button styling. fn create_class_signal(variant: ButtonVariant, size: ButtonSize, disabled: bool) -> ClassSignal { let base_classes = "inline-flex items-center justify-center rounded-md font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50"; let variant_classes = match variant { ButtonVariant::Primary => "bg-primary text-primary-foreground hover:bg-primary/90", ButtonVariant::Secondary => "bg-secondary text-secondary-foreground hover:bg-secondary/80", ButtonVariant::Success => "bg-green-600 text-white hover:bg-green-700", ButtonVariant::Warning => "bg-yellow-600 text-white hover:bg-yellow-700", ButtonVariant::Error => "bg-red-600 text-white hover:bg-red-700", ButtonVariant::Outline => "border border-input bg-background hover:bg-accent hover:text-accent-foreground", ButtonVariant::Ghost => "hover:bg-accent hover:text-accent-foreground", ButtonVariant::Link => "text-primary underline-offset-4 hover:underline", ButtonVariant::Destructive => "bg-destructive text-destructive-foreground hover:bg-destructive/90", }; let size_classes = match size { ButtonSize::Xs => "h-8 px-2 text-xs", ButtonSize::Sm => "h-9 px-3 text-sm", ButtonSize::Md => "h-10 px-4 py-2", ButtonSize::Lg => "h-11 px-8 text-lg", ButtonSize::Xl => "h-12 px-10 text-xl", }; let disabled_classes = if disabled { "opacity-50 cursor-not-allowed" } else { "" }; let all_classes = format!("{} {} {} {}", base_classes, variant_classes, size_classes, disabled_classes); ClassSignal::new(all_classes) } /// Example card component using tailwind-rs-core for responsive design. #[component] pub fn ResponsiveCard( #[prop(optional)] title: Option, #[prop(optional)] children: Option, ) -> impl IntoView { // Create responsive classes using tailwind-rs-core let responsive_classes = Responsive::new() .sm("p-4") .md("p-6") .lg("p-8") .xl("p-10"); let card_classes = format!("rounded-lg border bg-card text-card-foreground shadow-sm {}", responsive_classes.to_string()); view! {
{title.map(|t| view! {

{t}

})}
{children.map(|c| c()).unwrap_or_else(|| "Card content".into())}
} } /// Example theme-aware component using tailwind-rs-core. #[component] pub fn ThemedComponent( #[prop(optional)] theme: Option, #[prop(optional)] children: Option, ) -> impl IntoView { // Create theme manager let theme_manager = ReactiveThemeManager::new(); // Get theme classes let primary_classes = theme_manager.get_classes_signal(&Variant::Primary, &Size::Md); let secondary_classes = theme_manager.get_classes_signal(&Variant::Secondary, &Size::Md); view! {
"Primary themed content"
"Secondary themed content"
{children.map(|c| c()).unwrap_or_else(|| "Themed content".into())}
} } /// Example color system component using tailwind-rs-core. #[component] pub fn ColorSystemComponent() -> impl IntoView { // Create reactive color system let color_system = ReactiveColor::new(Color::Blue); // Get color signals let background_signal = color_system.background_signal(600); let text_signal = color_system.text_signal(900); let hover_signal = color_system.hover_signal(700); view! {
"Dynamic color system"
} } /// Example form component using tailwind-rs-core for validation styling. #[component] pub fn ValidatedForm() -> impl IntoView { let (email, set_email) = create_signal(String::new()); let (is_valid, set_is_valid) = create_signal(false); // Create validation classes let input_classes = create_memo(move |_| { if is_valid.get() { "flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 border-green-500" } else { "flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 border-red-500" } }); view! {
} } /// Example responsive grid component using tailwind-rs-core. #[component] pub fn ResponsiveGrid( #[prop(optional)] items: Option>, ) -> impl IntoView { let items = items.unwrap_or_else(|| vec![ "Item 1".to_string(), "Item 2".to_string(), "Item 3".to_string(), "Item 4".to_string(), "Item 5".to_string(), "Item 6".to_string(), ]); // Create responsive grid classes let grid_classes = Responsive::new() .sm("grid-cols-1") .md("grid-cols-2") .lg("grid-cols-3") .xl("grid-cols-4"); let container_classes = format!("grid gap-4 {}", grid_classes.to_string()); view! {
{items.into_iter().map(|item| view! {
{item}
}).collect::>()}
} } /// Example component showcasing all tailwind-rs-core features. #[component] pub fn TailwindRsCoreDemo() -> impl IntoView { view! {

"Tailwind-RS-Core Integration Demo"

"Enhanced Button Component"

"Primary Button" "Secondary Button" "Success Button" "Error Button"

"Responsive Card Component"

"This card adapts to different screen sizes using tailwind-rs-core responsive utilities."

"Theme-Aware Component"

"This component uses the theme system for consistent styling."

"Color System Component"

"Validated Form Component"

"Responsive Grid Component"

} }