use Bjanczak\FilamentFlexFields\Filament\Forms\Components\FlexMatrixTable;
use Bjanczak\FilamentFlexFields\Filament\Forms\Components\SelectField;
use Bjanczak\FilamentFlexFields\Filament\Forms\Components\FlexTextInput;
use Bjanczak\FilamentFlexFields\Filament\Forms\Components\SwitchField;
use Filament\Forms\Components\Component;
FlexMatrixTable::make('car_config')
->label('Car Configuration')
->rows([
'engine_power' => ['label' => 'Engine Power', 'suffix' => 'HP'],
'top_speed' => ['label' => 'Top Speed', 'suffix' => 'km/h'],
'acceleration' => ['label' => '0-100 km/h', 'suffix' => 's'],
])
->columnWidths([
'importance' => '1.5fr',
'value' => '1fr',
'enabled' => 'max-content',
])
->schema([
SelectField::make('importance')
->label('Importance')
->options([
'high' => 'High',
'medium' => 'Medium',
'low' => 'Low',
])
->size('sm')
->inlineFieldLabel(false)
->hiddenLabel(),
FlexTextInput::make('value')
->label('Value')
->numeric()
->size('sm')
->hiddenLabel()
->suffix(function (Component $component) {
// Read row definition to assign dynamic suffixes per row
$statePathParts = explode('.', $component->getStatePath());
$rowKey = $statePathParts[count($statePathParts) - 2] ?? null;
$matrix = $component->getContainer()->getParentComponent();
$rows = $matrix->getNormalizedRows();
return $rows[$rowKey]['suffix'] ?? null;
}),
SwitchField::make('enabled')
->label('Enabled')
->size('sm')
->inline()
->hiddenLabel(),
]);