User Card Component - Showcasing Props, Events, State & Lifecycle
What is this demo?
This interactive demo showcases the happel() function from PeRyL, which creates reusable web components using the HApp framework.
username, avatar, role, online)This example shows a single <happ-user-card> component with controls to change its attributes dynamically.
Try it: Change the inputs below and click "Update Card" to see the component react to attribute changes.
This example demonstrates a parent component (<happ-user-demo>) managing multiple child components (<happ-user-card>).
Try it: Click on any user card, expand them, toggle their status, or use the Add/Remove buttons. Watch the event statistics update!
Web components in PeRyL are created using the happel() function:
happel<UserCardState, UserCardActions>({
state: userCardState, // Initial state function
view: userCardView, // Render function
dispatcher: userCardDispatcher, // Action handler
id: "happ-user-card", // Custom element tag name
debug: true // Enable console logging
});
<happ-user-card
username="Alice"
avatar="👩"
role="admin"
online="true">
</happ-user-card>
document.querySelector('happ-user-card')
.addEventListener('action', (event) => {
console.log('Event received:', event.detail);
});
demo/hsml-appel-usercard_demo.ts - Component implementation (state, view, dispatcher)src/hsml-app.ts - HApp framework and happel() functionsrc/hsml.ts - HSML type definitionsArchitecture: PeRyL uses a Flux-inspired architecture with unidirectional data flow:
State → View → User Actions → Dispatcher → State Mutations → Re-render