Skip to main content

Overview

Lyger’s component system provides a flexible foundation for building reusable, reactive UI components. Components can be used standalone or integrated with Livewire for enhanced reactivity.
The component system in Lyger\Components is designed to work alongside Livewire components, providing additional UI building blocks and patterns.

Basic Components

Creating a Component

Extend the Lyger\Components\Component base class:

Component Registration

Register components with the ComponentManager:

Component Lifecycle

1

Construction

Component is instantiated with new or ComponentManager::make().
2

Mount

The mount() method is called to initialize component state.
3

Before Render

The beforeRender() method is called before rendering (optional).
4

Render

The component is rendered using render() which calls renderView() or renderInline().

Lifecycle Methods

Views and Templates

Using External Views

Create the view file at resources/views/components/user-card.php:

Inline Rendering

Override renderInline() for simple components:

Properties and Data

Setting Properties

Magic Methods

Components support magic getters and setters:

Method Calling

Components can expose methods that can be called dynamically:

Error Handling

Built-in Components

FormComponent

Create forms with validation and error handling:
Display modal dialogs:
Modal component includes built-in backdrop and animation support. The size property controls the modal width.

Table Component

Create sortable data tables:

Table Actions

Add action buttons to table rows:

Sorting

Alert Component

Display notifications and messages:

Events and Communication

Emitting Events

Event Data Structure

Validation

Components support data validation:

AJAX Handler

Components can handle AJAX requests:

Slots

Components support slot-based content injection:

Best Practices

1

Component Composition

Build complex UIs by composing smaller, focused components rather than creating monolithic ones.
2

Separate Concerns

Keep presentation logic in components and business logic in services or models.
3

Reusability

Design components to be reusable across different contexts by using properties and configuration.
4

Type Safety

Use PHP type declarations for component properties and method parameters.
5

Documentation

Document component properties, methods, and usage examples for your team.

API Reference

Component Methods

ComponentManager Methods

FormComponent Methods

Table Methods