| Crates.io | hyperchad_actions |
| lib.rs | hyperchad_actions |
| version | 0.1.4 |
| created_at | 2025-05-07 13:45:36.487428+00 |
| updated_at | 2025-07-21 20:03:10.563876+00 |
| description | HyperChad actions package |
| homepage | |
| repository | https://github.com/MoosicBox/MoosicBox |
| max_upload_size | |
| id | 1663871 |
| size | 118,962 |
Interactive action system for HyperChad UI components with triggers and effects.
The HyperChad Actions package provides:
Add this to your Cargo.toml:
[dependencies]
hyperchad_actions = { path = "../hyperchad/actions" }
# Enable additional features
hyperchad_actions = {
path = "../hyperchad/actions",
features = ["logic", "serde", "arb"]
}
use hyperchad_actions::{Action, ActionTrigger, ActionType, ElementTarget};
// Simple click action to hide element
let action = Action {
trigger: ActionTrigger::Click,
action: ActionType::hide_str_id("modal").into(),
};
// Show element on hover
let show_action = Action {
trigger: ActionTrigger::Hover,
action: ActionType::show_str_id("tooltip").into(),
};
use hyperchad_actions::{ActionType, ElementTarget};
use hyperchad_transformer_models::Visibility;
// Target by string ID
let hide_modal = ActionType::hide_str_id("modal");
// Target by class
let show_menu = ActionType::set_display_class(true, "menu");
// Target self
let hide_self = ActionType::hide_self();
// Target last child
let show_last = ActionType::show_last_child();
// Visibility control
let hide_action = ActionType::hide_str_id("element");
let show_action = ActionType::show_str_id("element");
// Display control
let display_action = ActionType::display_str_id("element");
let no_display_action = ActionType::no_display_str_id("element");
// Background control
let set_bg = ActionType::set_background_str_id("red", "element");
let remove_bg = ActionType::remove_background_self();
// Combine multiple actions
let multi_action = ActionType::Multi(vec![
ActionType::hide_str_id("modal"),
ActionType::show_str_id("success"),
ActionType::Log {
message: "Action completed".to_string(),
level: LogLevel::Info,
},
]);
// Chain actions with `and`
let chained = ActionType::hide_str_id("modal")
.and(ActionType::show_str_id("success"));
// Add throttling to prevent rapid firing
let throttled_action = ActionType::hide_str_id("element")
.throttle(500); // 500ms throttle
// Add delay before turning off
let delayed_action = ActionType::show_str_id("tooltip")
.delay_off(2000); // Hide after 2 seconds
// Make action unique (prevent duplicates)
let unique_action = ActionType::display_str_id("notification")
.unique();
// Custom action type
let custom = ActionType::Custom {
action: "my-custom-action".to_string(),
};
// Event-based actions
let event_action = ActionType::on_event("user-login",
ActionType::show_str_id("dashboard")
);
// Navigation
let navigate = ActionType::Navigate {
url: "/dashboard".to_string(),
};
logic feature)use hyperchad_actions::logic::{If, Value, Condition};
// Conditional action based on value
let conditional = ActionType::Logic(If {
condition: Condition::Equals {
left: Value::Variable("user_role".to_string()),
right: Value::String("admin".to_string()),
},
then_action: Box::new(ActionType::show_str_id("admin-panel")),
else_action: Some(Box::new(ActionType::hide_str_id("admin-panel"))),
});
logic: Enable conditional logic and parameterized actionsserde: Enable serialization/deserializationarb: Enable arbitrary data generation for testingThis package is designed for: