HyperChad Actions
Interactive action system for HyperChad UI components with triggers and effects.
Overview
The HyperChad Actions package provides:
- Action System: Comprehensive interactive action framework
- Trigger Types: Various event triggers (click, hover, change, etc.)
- Element Targeting: Flexible element targeting system
- Style Actions: Dynamic styling and visibility control
- Logic Integration: Conditional actions and parameterization
- Multi-Actions: Composite action sequences
Features
Action Triggers
- Click: Standard click events
- ClickOutside: Click outside element detection
- MouseDown/Hover: Mouse interaction events
- Change: Form input change events
- Resize: Window/element resize events
- Custom Events: User-defined event triggers
- Immediate: Execute immediately without trigger
Element Targeting
- String ID: Target elements by string identifier
- Numeric ID: Target elements by numeric ID
- Class: Target elements by CSS class
- Child Class: Target child elements by class
- Self Target: Target the current element
- Last Child: Target the last child element
Action Types
- Style Actions: Visibility, display, background control
- Navigation: URL navigation and routing
- Logging: Debug and error logging
- Custom Actions: User-defined action types
- Events: Trigger other actions via events
- Multi-Actions: Execute multiple actions sequentially
Style Control
- Visibility: Show/hide elements with visibility property
- Display: Show/hide elements with display property
- Background: Set/remove background colors and images
- Flexible Targeting: Apply styles to various element targets
Installation
Add this to your Cargo.toml:
[]
= { = "../hyperchad/actions" }
# Enable additional features
= {
path = "../hyperchad/actions",
= ["logic", "serde", "arb"]
}
Usage
Basic Actions
use ;
// Simple click action to hide element
let action = Action ;
// Show element on hover
let show_action = Action ;
Element Targeting
use ;
use Visibility;
// Target by string ID
let hide_modal = hide_str_id;
// Target by class
let show_menu = set_display_class;
// Target self
let hide_self = hide_self;
// Target last child
let show_last = show_last_child;
Style Actions
// Visibility control
let hide_action = hide_str_id;
let show_action = show_str_id;
// Display control
let display_action = display_str_id;
let no_display_action = no_display_str_id;
// Background control
let set_bg = set_background_str_id;
let remove_bg = remove_background_self;
Multi-Actions
// Combine multiple actions
let multi_action = Multi;
// Chain actions with `and`
let chained = hide_str_id
.and;
Action Effects
// Add throttling to prevent rapid firing
let throttled_action = hide_str_id
.throttle; // 500ms throttle
// Add delay before turning off
let delayed_action = show_str_id
.delay_off; // Hide after 2 seconds
// Make action unique (prevent duplicates)
let unique_action = display_str_id
.unique;
Custom Actions
// Custom action type
let custom = Custom ;
// Event-based actions
let event_action = on_event;
// Navigation
let navigate = Navigate ;
Conditional Logic (with logic feature)
use ;
// Conditional action based on value
let conditional = Logic;
Action Structure
Action
- trigger: When the action should be triggered
- action: The effect to execute
ActionEffect
- action: The action type to execute
- delay_off: Optional delay before deactivation
- throttle: Optional throttling to prevent rapid execution
- unique: Whether to prevent duplicate executions
ActionTrigger
- Click/MouseDown/Hover: Mouse events
- Change: Input change events
- Resize: Window resize events
- Event(String): Custom events
- Immediate: Execute immediately
Feature Flags
logic: Enable conditional logic and parameterized actionsserde: Enable serialization/deserializationarb: Enable arbitrary data generation for testing
Dependencies
- HyperChad Transformer Models: UI model types
- Serde: Optional serialization support
Integration
This package is designed for:
- Interactive UIs: Dynamic user interface behaviors
- Event Handling: Comprehensive event response system
- Animation Control: Show/hide and styling animations
- Form Interactions: Form validation and feedback
- Component Libraries: Reusable interactive components