### StateFusionRadio Component Setup in Filament Form Source: https://context7.com/a909m/filament-statefusion/llms.txt Demonstrates how to integrate the StateFusionRadio component into a Filament form schema. This component allows for radio buttons with descriptions, enhancing user clarity when selecting states. It supports basic usage and inline layouts with column configurations. ```php schema([ // Radio buttons with descriptions from state classes StateFusionRadio::make('status') ->label('Order Status') ->required(), // Inline layout for compact forms StateFusionRadio::make('priority_level') ->attribute('priority_level') ->inline() ->columns(3), ]); } ``` -------------------------------- ### Filament TextEntry Badge Styling (PHP) Source: https://context7.com/a909m/filament-statefusion/llms.txt Renders an infolist entry with automatic badge styling. Similar to table columns, the `badge()` method on `TextEntry` allows states to be displayed as colored badges. This example configures `status` and `approval_status` entries within an infolist schema. ```php schema([ TextEntry::make('status') ->badge(), TextEntry::make('approval_status') ->badge() ->label('Approval Status'), ]); } ``` -------------------------------- ### Utilize StateFusion Form Components Source: https://github.com/a909m/filament-statefusion/blob/main/README.md This snippet showcases various form components provided by Filament StateFusion for managing states within forms. It includes examples for dropdown select, radio buttons, and toggle buttons, allowing for interactive state selection. ```php use A909M\FilamentStateFusion\Forms\Components\StateFusionSelect; use A909M\FilamentStateFusion\Forms\Components\StateFusionRadio; use A909M\FilamentStateFusion\Forms\Components\StateFusionToggleButtons; // Dropdown select StateFusionSelect::make('status'), // Radio buttons with descriptions StateFusionRadio::make('status'), // Toggle buttons with colors and icons StateFusionToggleButtons::make('status'), ``` -------------------------------- ### Integrate StateFusion Components in Filament Tables Source: https://github.com/a909m/filament-statefusion/blob/main/README.md This snippet illustrates how to use Filament StateFusion components within your Filament resource's table definition. It includes examples for displaying state information using StateFusionSelectColumn and filtering records by state using StateFusionSelectFilter. ```php // app/Filament/Resources/OrderResource.php use A909M\FilamentStateFusion\Tables\Columns\StateFusionSelectColumn; use A909M\FilamentStateFusion\Tables\Filters\StateFusionSelectFilter; use Filament\Forms\Form; use Filament\Resources\Resource; use Filament\Tables\Table; class OrderResource extends Resource { // ... public static function table(Table $table): Table { return $table ->columns([ StateFusionSelectColumn::make('status'), ]) ->filters([ StateFusionSelectFilter::make('status'), ]); } } ``` -------------------------------- ### Filament TextColumn Badge Styling (PHP) Source: https://context7.com/a909m/filament-statefusion/llms.txt Renders a table column with automatic badge styling. The `badge()` method enables the display of states as colored badges with icons, assuming the underlying data implements HasLabel, HasColor, and HasIcon. This example shows configuring `status` and `approval_status` columns. ```php columns([ // Automatically displays as colored badge with icon TextColumn::make('status') ->badge(), TextColumn::make('approval_status') ->badge() ->sortable(), ]); } ``` -------------------------------- ### Edit Order Page with Header Actions using StateFusion Source: https://context7.com/a909m/filament-statefusion/llms.txt This PHP code defines the EditOrder page for the Order resource, extending Filament's EditRecord. It demonstrates how to add custom header actions, specifically utilizing StateFusionAction, to trigger state transitions directly from the edit page header. This example includes actions to transition to 'processing' and 'shipped' states. ```php // Edit page with header actions namespace App\Filament\Resources\OrderResource\Pages; use A909M\FilamentStateFusion\Actions\StateFusionAction; use App\States\{ProcessingState, ShippedState}; use Filament\Resources\Pages\EditRecord; class EditOrder extends EditRecord { protected static string $resource = OrderResource::class; protected function getHeaderActions(): array { return [ ``` -------------------------------- ### Setting Up State Classes with StateFusionInfo Trait (PHP) Source: https://context7.com/a909m/filament-statefusion/llms.txt Demonstrates how to set up abstract and concrete state classes using the StateFusionInfo trait and HasFilamentStateFusion interface. This enables automatic extraction of visual metadata like labels, colors, icons, and descriptions for states, as well as defining state transitions and default states within a model. ```php default(PendingState::class) ->allowTransition(PendingState::class, ProcessingState::class) ->allowTransition(ProcessingState::class, ShippedState::class) ->allowTransition([PendingState::class, ProcessingState::class], CancelledState::class); } } // Concrete state implementations with visual metadata final class PendingState extends OrderState implements HasLabel, HasColor, HasIcon, HasDescription { public function getLabel(): string { return 'Pending Payment'; } public function getColor(): string|array { return Color::Yellow; } public function getIcon(): string { return 'heroicon-o-clock'; } public function getDescription(): ?string { return 'Awaiting customer payment confirmation'; } } final class ProcessingState extends OrderState implements HasLabel, HasColor, HasIcon { public function getLabel(): string { return 'Processing'; } public function getColor(): string|array { return Color::Blue; } public function getIcon(): string { return 'heroicon-o-cog-6-tooth'; } } final class ShippedState extends OrderState implements HasLabel, HasColor, HasIcon { public function getLabel(): string { return 'Shipped'; } public function getColor(): string|array { return Color::Purple; } public function getIcon(): string { return 'heroicon-o-truck'; } } final class CancelledState extends OrderState implements HasLabel, HasColor, HasIcon { public function getLabel(): string { return 'Cancelled'; } public function getColor(): string|array { return Color::Red; } public function getIcon(): string { return 'heroicon-o-x-circle'; } } // Model configuration use Illuminate\Database\Eloquent\Model; use Spatie\ModelStates\HasStates; class Order extends Model { use HasStates; protected $casts = [ 'status' => OrderState::class, ]; } ``` -------------------------------- ### Run Project Tests Source: https://github.com/a909m/filament-statefusion/blob/main/README.md Command to execute the test suite for the project using Composer. This is a standard practice for verifying code integrity and functionality. ```bash composer test ``` -------------------------------- ### Customize UI for Concrete State Classes in PHP Source: https://github.com/a909m/filament-statefusion/blob/main/README.md Shows how to implement interfaces like `HasLabel`, `HasDescription`, `HasColor`, and `HasIcon` on concrete state classes to control their appearance in the UI. This allows for custom labels, descriptions, colors, and icons for each state. ```php use Filament\Support\Colors\Color; use Filament\Support\Contracts\HasColor; use Filament\Support\Contracts\HasDescription; use Filament\Support\Contracts\HasIcon; use Filament\Support\Contracts\HasLabel; final class CancelledState extends OrderState implements HasDescription, HasColor, HasIcon, HasLabel { public function getLabel(): string { return __('Order Cancelled'); } public function getColor(): array { return Color::Red; } public function getIcon(): string { return 'heroicon-o-x-circle'; } public function getDescription(): ?string { return 'Order cancelled, transaction reversed.'; } } ``` -------------------------------- ### Create Page Actions for State Transitions Source: https://github.com/a909m/filament-statefusion/blob/main/README.md This snippet shows how to create page-level actions using StateFusionAction to transition between states. This allows for state changes initiated from a specific page. ```php use A909M\FilamentStateFusion\Actions\StateFusionAction; StateFusionAction::make('approve') ->transitionTo(ApprovedState::class), ``` -------------------------------- ### Complete Order Resource with StateFusion Source: https://context7.com/a909m/filament-statefusion/llms.txt This PHP code defines a Filament resource for an Order model, integrating StateFusion components for status management. It includes form configurations for order details and status selection using StateFusionToggleButtons, table configurations with StateFusionSelectColumn and filters, and defines row-level and bulk actions for state transitions. It requires the Order model and state classes (e.g., PendingState, ProcessingState). ```php schema([ Section::make('Order Details') ->schema([ TextInput::make('order_number') ->disabled() ->dehydrated(false), TextInput::make('customer_name') ->required() ->maxLength(255), DatePicker::make('order_date') ->required() ->default(now()), ]), Section::make('Status Management') ->schema([ // Form component - dropdown or toggle buttons StateFusionToggleButtons::make('status') ->grouped() ->inline(), // Alternative: dropdown select // StateFusionSelect::make('status')->required(), ]) ->columns(1), ]); } public static function table(Table $table): Table { return $table ->columns([ TextColumn::make('order_number') ->searchable() ->sortable(), TextColumn::make('customer_name') ->searchable() ->sortable(), // Inline editable state column StateFusionSelectColumn::make('status') ->sortable(), // Or static badge display // TextColumn::make('status')->badge(), TextColumn::make('total') ->money('usd') ->sortable(), TextColumn::make('created_at') ->dateTime() ->sortable() ->toggleable(isToggledHiddenByDefault: true), ]) ->filters([ // State filter with multi-select StateFusionSelectFilter::make('status') ->multiple(), ]) ->actions([ // Row-level transition actions StateFusionTableAction::make('start-processing') ->transitionTo(ProcessingState::class), StateFusionTableAction::make('ship') ->transitionTo(ShippedState::class), StateFusionTableAction::make('deliver') ->transitionTo(DeliveredState::class), StateFusionTableAction::make('cancel') ->transitionTo(CancelledState::class), ]) ->bulkActions([ // Bulk state transitions StateFusionBulkAction::make('bulk-process') ->transition(PendingState::class, ProcessingState::class), StateFusionBulkAction::make('bulk-cancel') ->transition(PendingState::class, CancelledState::class) ->requiresConfirmation() ->modalHeading('Cancel Selected Orders') ->modalDescription('This will cancel all selected pending orders.'), ]) ->defaultSort('created_at', 'desc'); } public static function getPages(): array { return [ 'index' => Pages\ListOrders::route('/'), 'create' => Pages\CreateOrder::route('/create'), 'edit' => Pages\EditOrder::route('/{record}/edit'), ]; } } ``` -------------------------------- ### Customize UI for Transitions in PHP Source: https://github.com/a909m/filament-statefusion/blob/main/README.md Explains how to customize the UI representation of transitions by implementing `HasLabel`, `HasColor`, and `HasIcon` interfaces on transition classes. This allows for custom labels, colors, and icons for actions that trigger state changes. ```php use Filament\Support\Colors\Color; use Filament\Support\Contracts\HasColor; use Filament\Support\Contracts\HasIcon; use Filament\Support\Contracts\HasLabel; use Spatie\ModelStates\Transition; final class ToCancelled extends Transition implements HasLabel, HasColor, HasIcon { public function getLabel(): string { return __('Mark as Cancelled'); } public function getColor(): array { return Color::Red; } public function getIcon(): string { return 'heroicon-o-x-circle'; } } ``` -------------------------------- ### Implement Forms for Custom Transitions in PHP Source: https://github.com/a909m/filament-statefusion/blob/main/README.md Illustrates how to collect additional user input during state transitions by adding a `form()` method to custom transition classes. The collected data is automatically passed to the transition's `handle()` method. ```php order->state = new CancelledState($this->order); $this->order->cancellation_reason = $this->data['reason']; $this->order->cancelled_at = now(); $this->order->save(); return $this->order; } public function form(): array { return [ Textarea::make('reason') ->label('Cancellation Reason') ->placeholder('Why are you cancelling this order?') ->required() ->maxLength(500), ]; } public function getLabel(): string { return 'Cancel Order'; } public function getColor(): string | array { return Color::Red; } public function getIcon(): string { return 'heroicon-o-x-circle'; } } ``` -------------------------------- ### StateFusionToggleButtons Component Configuration Source: https://context7.com/a909m/filament-statefusion/llms.txt Shows the implementation of the StateFusionToggleButtons component for visually appealing state selection. This component supports icons, colors, inline display, grouping, and multi-column layouts, providing a rich user interface for state management. ```php schema([ // Toggle buttons with icons and colors StateFusionToggleButtons::make('status') ->inline() ->grouped(), // Multi-column layout for many states StateFusionToggleButtons::make('workflow_stage') ->attribute('workflow_stage') ->columns(4) ->gridDirection('row'), ]); } ``` -------------------------------- ### Implement HasFilamentStateFusion and StateFusionInfo in Abstract State Class Source: https://github.com/a909m/filament-statefusion/blob/main/README.md This snippet demonstrates how to prepare your abstract state class by implementing the HasFilamentStateFusion interface and using the StateFusionInfo trait. It also shows how to configure state transitions using Spatie Laravel Model States. ```php default(PendingState::class) ->allowTransition(PendingState::class, ProcessingState::class) ->allowTransition(ProcessingState::class, ShippedState::class) ->allowTransition(ShippedState::class, DeliveredState::class) ->allowTransition([PendingState::class, ProcessingState::class], CancelledState::class); } } ``` -------------------------------- ### Bulk State Transitions with FilamentStateFusion Source: https://context7.com/a909m/filament-statefusion/llms.txt Defines bulk actions for transitioning multiple records between states. It utilizes StateFusionBulkAction to configure transitions, optionally requiring confirmation or specifying custom attributes. This is useful for batch operations on tables. ```php bulkActions([ // Bulk transition from Pending to Processing StateFusionBulkAction::make('start-processing') ->transition(PendingState::class, ProcessingState::class), // Bulk approve all pending items StateFusionBulkAction::make('bulk-approve') ->transition(PendingState::class, ApprovedState::class) ->requiresConfirmation() ->modalHeading('Approve Selected Orders') ->modalDescription('Are you sure you want to approve all selected orders?'), // Bulk cancel with custom attribute StateFusionBulkAction::make('cancel-orders') ->attribute('status') ->transition(ProcessingState::class, CancelledState::class), ]); } ``` -------------------------------- ### Display State as Badge in Infolists Source: https://github.com/a909m/filament-statefusion/blob/main/README.md This snippet illustrates how to use the standard Filament TextEntry in infolists to display the model's state as a badge. Similar to table columns, it leverages state interfaces for automatic styling. ```php use Filament\Infolists\Components\TextEntry; TextEntry::make('status') ->badge(), ``` -------------------------------- ### Implement Bulk State Transition Actions Source: https://github.com/a909m/filament-statefusion/blob/main/README.md This snippet demonstrates how to perform bulk state transitions on multiple records using StateFusionBulkAction. This is useful for updating the status of several items simultaneously. ```php use A909M\FilamentStateFusion\Tables\Actions\StateFusionBulkAction; StateFusionBulkAction::make('approve') ->transition(PendingState::class,ApprovedState::class), ``` -------------------------------- ### Page-Level State Transitions with FilamentStateFusion Source: https://context7.com/a909m/filament-statefusion/llms.txt Implements page-level actions for state transitions on Filament edit and view pages. StateFusionAction allows defining actions directly in the header, with options to control visibility based on record data. This enables state changes for individual records through UI buttons. ```php transitionTo(ApprovedState::class), StateFusionAction::make('ship') ->transitionTo(ShippedState::class) ->visible(fn ($record) => $record->payment_confirmed), // Custom attribute support StateFusionAction::make('mark-verified') ->attribute('verification_status') ->transitionTo(VerifiedState::class), ]; } } ``` -------------------------------- ### Custom State Transitions with Form Data Collection Source: https://context7.com/a909m/filament-statefusion/llms.txt Demonstrates creating custom transition classes that include a `form()` method to collect additional data during state changes. Filament automatically renders a modal with these form components when the transition is triggered. This allows for more complex state updates requiring user input. ```php order->state = new CancelledState($this->order); $this->order->cancellation_reason = $this->data['reason']; $this->order->cancelled_by_user_id = $this->data['cancelled_by']; $this->order->cancelled_at = now(); $this->order->save(); // Send notification email $this->order->customer->notify(new OrderCancelledNotification($this->order)); return $this->order; } // Form components for modal dialog public function form(): array { return [ Select::make('reason') ->label('Cancellation Reason') ->options([ 'customer_request' => 'Customer Requested', 'payment_failed' => 'Payment Failed', 'out_of_stock' => 'Out of Stock', 'fraud_suspected' => 'Fraud Suspected', 'other' => 'Other', ]) ->required(), Textarea::make('notes') ->label('Additional Notes') ->placeholder('Enter any additional details...') ->rows(3) ->maxLength(500), ]; } public function getLabel(): string { return 'Cancel Order'; } public function getColor(): string|array { return Color::Red; } public function getIcon(): string { return 'heroicon-o-x-circle'; } } // Usage in Filament resource with automatic form modal use A909M\FilamentStateFusion\Tables\Actions\StateFusionTableAction; StateFusionTableAction::make('cancel') ->transitionTo(CancelledState::class); // Automatically detects CancelOrder transition class ``` -------------------------------- ### Display State as Badge using TextColumn Source: https://github.com/a909m/filament-statefusion/blob/main/README.md This snippet demonstrates using the standard Filament TextColumn to display the model's state as a badge. If the state class implements HasLabel, HasColor, and HasIcon interfaces, the badge will automatically render with the correct appearance. ```php use Filament\Tables\Columns\TextColumn; TextColumn::make('status') ->badge(), ``` -------------------------------- ### Define Page-Level State Transition Actions in PHP Source: https://context7.com/a909m/filament-statefusion/llms.txt This snippet demonstrates how to define page-level actions for state transitions using `StateFusionAction`. These actions are used to trigger changes in the model's state, such as moving from one status to another. It requires the `StateFusionAction` class and the target state classes. ```php transitionTo(ProcessingState::class), StateFusionAction::make('mark-shipped') ->transitionTo(ShippedState::class), ]; } } ``` -------------------------------- ### Add State Transition Actions to Table Rows Source: https://github.com/a909m/filament-statefusion/blob/main/README.md This snippet shows how to implement state transition actions directly within table rows using StateFusionTableAction. This allows for quick state changes for individual records. ```php use A909M\FilamentStateFusion\Tables\Actions\StateFusionTableAction; StateFusionTableAction::make('approve') ->transitionTo(ApprovedState::class), ``` -------------------------------- ### StateFusionSelect Form Component for States (PHP) Source: https://context7.com/a909m/filament-statefusion/llms.txt Illustrates the usage of the StateFusionSelect component within a Filament form. This dropdown automatically populates with available states and their associated labels, allowing for configuration of the attribute name, making it required, disabling it conditionally, and adding helper text. ```php schema([ // Basic usage - automatically detects 'status' attribute from model StateFusionSelect::make('status'), // Custom attribute name for models with multiple states StateFusionSelect::make('approval_status') ->attribute('approval_status') ->required(), // Combined with standard Filament methods StateFusionSelect::make('status') ->required() ->disabled(fn ($record) => $record?->is_locked) ->helperText('Current order state in the fulfillment pipeline'), ]); } ``` -------------------------------- ### Create Multi-State Table Columns in PHP Source: https://context7.com/a909m/filament-statefusion/llms.txt This PHP code defines table column components for displaying multiple states in a Filament table. It uses `StateFusionSelectColumn` to render the current state for each attribute, associating it with the respective model attribute for clear visualization within the table. ```php columns([ StateFusionSelectColumn::make('publication_status') ->attribute('publication_status'), StateFusionSelectColumn::make('review_status') ->attribute('review_status'), StateFusionSelectColumn::make('moderation_status') ->attribute('moderation_status'), ]); } ``` -------------------------------- ### Create Multi-State Form Components in PHP Source: https://context7.com/a909m/filament-statefusion/llms.txt This PHP snippet defines form schema components for managing multiple states within a Filament form. It utilizes `StateFusionSelect` to provide user-friendly dropdowns for each state attribute, linking them to the corresponding model attribute and setting custom labels. ```php schema([ StateFusionSelect::make('publication_status') ->attribute('publication_status') ->label('Publication Status'), StateFusionSelect::make('review_status') ->attribute('review_status') ->label('Review Status'), StateFusionSelect::make('moderation_status') ->attribute('moderation_status') ->label('Moderation Status'), ]); } ``` -------------------------------- ### StateFusionTableAction for Row-Level State Transitions Source: https://context7.com/a909m/filament-statefusion/llms.txt Details the usage of StateFusionTableAction to add state transition buttons to table rows. These actions automatically control visibility based on allowed transitions and can be configured with custom attributes or grouped into dropdowns for complex workflows. ```php actions([ // Simple transition action - automatically hidden if transition not allowed StateFusionTableAction::make('approve') ->transitionTo(ApprovedState::class), StateFusionTableAction::make('ship') ->transitionTo(ShippedState::class), // Custom attribute and action button StateFusionTableAction::make('mark-reviewed') ->attribute('review_status') ->transitionTo(ReviewedState::class), // Multiple transition actions in dropdown ActionGroup::make([ StateFusionTableAction::make('approve') ->transitionTo(ApprovedState::class), StateFusionTableAction::make('reject') ->transitionTo(RejectedState::class), ])->label('Review Actions'), ]); } ``` -------------------------------- ### StateFusionSelectFilter for Table State Filtering Source: https://context7.com/a909m/filament-statefusion/llms.txt Demonstrates how to implement StateFusionSelectFilter to filter table records by specific states. This filter automatically resolves state labels and supports multiple selections and search functionality for extensive state options. ```php filters([ // Basic state filter StateFusionSelectFilter::make('status'), // Multi-select filter for multiple states StateFusionSelectFilter::make('status') ->multiple() ->label('Filter by Status'), // Searchable filter for models with many states StateFusionSelectFilter::make('workflow_stage') ->attribute('workflow_stage') ->searchable() ->multiple(), ]); } ``` -------------------------------- ### Configure Multi-State Model Attributes in PHP Source: https://context7.com/a909m/filament-statefusion/llms.txt This PHP code configures an Eloquent model to handle multiple state attributes using custom attribute mapping. The `$casts` property is used to associate state classes with specific model attributes, enabling independent state management for each attribute. ```php PublicationState::class, 'review_status' => ReviewState::class, 'moderation_status' => ModerationState::class, ]; } ``` -------------------------------- ### StateFusionSelectColumn for Inline Table Editing Source: https://context7.com/a909m/filament-statefusion/llms.txt Illustrates the use of StateFusionSelectColumn within a Filament table for inline editing of state transitions. This column automatically validates allowed transitions, ensuring data integrity. It supports custom attributes and conditional visibility. ```php columns([ TextColumn::make('order_number') ->searchable(), // Inline editable state column - only shows valid transitions StateFusionSelectColumn::make('status'), // Custom attribute with conditional display StateFusionSelectColumn::make('approval_status') ->attribute('approval_status') ->visible(fn ($record) => $record->requires_approval), TextColumn::make('created_at') ->dateTime(), ]); } ``` -------------------------------- ### Configure Eloquent Model with State Casting Source: https://github.com/a909m/filament-statefusion/blob/main/README.md This snippet shows how to add the state attribute to your Eloquent model by using the 'casts' property. This ensures that the 'status' attribute is correctly handled as an instance of your custom state class. ```php OrderState::class, ]; } ``` -------------------------------- ### Set Custom State Attribute in Filament Source: https://github.com/a909m/filament-statefusion/blob/main/README.md Demonstrates how to specify a different model attribute for state components using the `attribute()` method. This is useful when your model has multiple state attributes or for component reusability. ```php StateFusionSelect::make('approval_status') ->attribute('approval_status'), StateFusionAction::make('transition') ->attribute('state') ->transitionTo(ApprovedState::class); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.