| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 | 
							- <?php
 - 
 - namespace App\Filament\Forms\Components;
 - 
 - use Closure;
 - use Filament\Forms\Components\Field;
 - use Filament\Forms\Components\Grid;
 - use Filament\Forms\Components\TextInput;
 - 
 - class AddressFields extends Grid
 - {
 -     protected bool $isSoftRequired = false;
 - 
 -     protected bool | Closure $isCountryDisabled = false;
 - 
 -     protected function setUp(): void
 -     {
 -         parent::setUp();
 - 
 -         $this->schema([
 -             TextInput::make('address_line_1')
 -                 ->label('Address line 1')
 -                 ->required()
 -                 ->maxLength(255),
 -             TextInput::make('address_line_2')
 -                 ->label('Address line 2')
 -                 ->maxLength(255),
 -             CountrySelect::make('country_code')
 -                 ->disabled(fn () => $this->isCountryDisabled())
 -                 ->clearStateField()
 -                 ->required(),
 -             StateSelect::make('state_id'),
 -             TextInput::make('city')
 -                 ->label('City')
 -                 ->required()
 -                 ->maxLength(255),
 -             TextInput::make('postal_code')
 -                 ->label('Postal code')
 -                 ->maxLength(255),
 -         ]);
 -     }
 - 
 -     public function softRequired(bool $condition = true): static
 -     {
 -         $this->setSoftRequired($condition);
 - 
 -         return $this;
 -     }
 - 
 -     protected function setSoftRequired(bool $condition): void
 -     {
 -         $this->isSoftRequired = $condition;
 - 
 -         $childComponents = $this->getChildComponents();
 - 
 -         foreach ($childComponents as $component) {
 -             if ($component instanceof Field && $component->isRequired()) {
 -                 $component->markAsRequired(! $condition);
 -             }
 -         }
 -     }
 - 
 -     public function disabledCountry(bool | Closure $condition = true): static
 -     {
 -         $this->isCountryDisabled = $condition;
 - 
 -         return $this;
 -     }
 - 
 -     public function isCountryDisabled(): bool
 -     {
 -         return $this->evaluate($this->isCountryDisabled);
 -     }
 - }
 
 
  |