Expand description
Template system for building HTML-like user interfaces.
This crate provides a declarative template syntax via the container! macro,
along with rendering traits and DSL functions for building dynamic UIs.
§Main Features
- Template Syntax - Use the
container!macro to write HTML-like templates - Rendering - Implement
RenderContainerto convert custom types to containers - Actions DSL - Define interactive behaviors with the
fxfunction - Styling - Use
calcfor calculations and color functions likergb()/rgba() - Viewport Units - Create responsive layouts with
vw(),vh(),dvw(),dvh()
§Basic Usage
use hyperchad_template::{container, to_html};
// Create a simple template
let containers = container! {
div {
h1 { "Hello, World!" }
div { "Welcome to HyperChad templates." }
}
};
// Convert to HTML string
let html = to_html(&containers);§Styling with Attributes
use hyperchad_template::container;
let containers = container! {
div width=100% height=vh(100) background=rgb(240, 240, 240) {
h1 color=rgb(0, 120, 200) { "Styled Header" }
}
};§Interactive Actions
use hyperchad_template::container;
let containers = container! {
button fx-click=fx { show("modal") } {
"Open Modal"
}
div id="modal" hidden {
"Modal Content"
}
};§Custom Components
Implement RenderContainer to create reusable components:
use hyperchad_template::{container, Containers, RenderContainer};
use core::convert::Infallible;
struct Alert {
message: String,
level: AlertLevel,
}
enum AlertLevel {
Info,
Warning,
}
impl RenderContainer for Alert {
type Error = Infallible;
fn render_to(&self, containers: &mut Containers) -> Result<(), Self::Error> {
let class = match self.level {
AlertLevel::Info => "alert-info",
AlertLevel::Warning => "alert-warning",
};
*containers = container! {
div class=(class) {
(self.message.clone())
}
};
Ok(())
}
}Re-exports§
pub use hyperchad_actions as actions;pub use hyperchad_color as color;pub use hyperchad_template_actions_dsl as template_actions_dsl;pub use hyperchad_transformer as transformer;pub use hyperchad_transformer_models as transformer_models;
Modules§
- calc
- Helper module for
calc()expressions and mathematical operations on Number types - color_
functions - Helper module for color functions
- prelude
- Prelude module that re-exports commonly used traits.
- unit_
functions - Helper functions for creating viewport unit values.
Macros§
- container
- The main template macro for creating HTML-like containers.
Structs§
- Container
- The core container type that represents a single UI element.
- Container
List - A wrapper around
Vec<Container>that provides convenient methods without requiring trait imports. - IfExpression
- Re-export logic types for responsive and conditional rendering (requires
logicfeature). - Parse
Selector Error - Re-export all transformer model types for convenience.
Enums§
- Align
Items - Re-export all transformer model types for convenience.
- Cursor
- Re-export all transformer model types for convenience.
- Element
Target - Re-export all transformer model types for convenience.
- Font
Weight - Re-export all transformer model types for convenience.
- Image
Fit - Re-export all transformer model types for convenience.
- Image
Loading - Re-export all transformer model types for convenience.
- Justify
Content - Re-export all transformer model types for convenience.
- Layout
Direction - Re-export all transformer model types for convenience.
- Layout
Overflow - Re-export all transformer model types for convenience.
- Link
Target - Re-export all transformer model types for convenience.
- Overflow
Wrap - Re-export all transformer model types for convenience.
- Position
- Re-export all transformer model types for convenience.
- Responsive
- Re-export logic types for responsive and conditional rendering (requires
logicfeature). - Route
- Re-export all transformer model types for convenience.
- Selector
- Re-export all transformer model types for convenience.
- Swap
Strategy - Re-export all transformer model types for convenience.
- Target
- Re-export all transformer model types for convenience.
- Text
Align - Re-export all transformer model types for convenience.
- Text
Decoration Line - Re-export all transformer model types for convenience.
- Text
Decoration Style - Re-export all transformer model types for convenience.
- Text
Overflow - Re-export all transformer model types for convenience.
- User
Select - Re-export all transformer model types for convenience.
- Visibility
- Re-export all transformer model types for convenience.
- White
Space - Re-export all transformer model types for convenience.
Traits§
- Container
VecExt - Extension trait to add missing methods to
Vec<Container> - Container
VecMethods - Extension methods for
Vec<Container>that are automatically available. - Into
Action Effect - Trait for converting various types to
ActionEffect. - Into
Border - Trait for converting various types to border tuples
(Color, Number). - Render
Container - Represents a type that can be rendered as a Container.
- ToBool
- Trait for converting values to
bool.
Functions§
- fx
- FX DSL function for template actions
- if_
responsive - Re-export logic types for responsive and conditional rendering (requires
logicfeature). - into_
html - Convert a
Vec<Container>to an HTML string, consuming the vector. - to_html
- Convert a
Vec<Container>to an HTML string without requiring trait imports.
Type Aliases§
- Containers
- The result type for the container! macro.