-
-
Save ManojKiranA/36dbb1172ef1377246ea91c65da99828 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<x-forms::field-wrapper | |
:id="$getId()" | |
:label="$getLabel()" | |
:label-sr-only="$isLabelHidden()" | |
:helper-text="$getHelperText()" | |
:hint="$getHint()" | |
:hint-icon="$getHintIcon()" | |
:required="$isRequired()" | |
:state-path="$getStatePath()" | |
class="{{ $isLabelHidden() && ! $hasInlineLabel() ? 'h-full flex items-end' : null }}" | |
> | |
<div class="{{ $isLabelHidden() && ! $hasInlineLabel() ? 'relative bottom-0' : null }}"> | |
<x-forms::actions.action | |
:action="$getExecutableAction()" | |
component="forms::button" | |
> | |
@if (! $getExecutableAction()->isLabelHidden()) | |
{{ $getExecutableAction()->getLabel() }} | |
@endif | |
</x-forms::actions.action> | |
</div> | |
</x-forms::field-wrapper> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Forms\Components; | |
use Closure; | |
use Filament\Forms\Components\Actions\Action; | |
use Filament\Forms\Components\Field; | |
class DropInAction extends Field | |
{ | |
protected Action | Closure | null $action = null; | |
protected string $view = 'forms.components.drop-in-action'; | |
protected function setUp(): void | |
{ | |
$this->dehydrated(false); | |
} | |
public function execute(Action | Closure | null $action): static | |
{ | |
$this->action = $action; | |
return $this; | |
} | |
public function getExecutableAction() | |
{ | |
return $this->evaluate($this->action)?->component($this); | |
} | |
public function getActions(): array | |
{ | |
$executableAction = $this->getExecutableAction(); | |
return array_merge( | |
parent::getActions(), | |
$executableAction ? [$executableAction->getName() => $executableAction->component($this)] : [], | |
); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DropInAction::make('test') | |
->disableLabel() | |
->execute(function (Closure $get, Closure $set) { | |
return Action::make('geolocate') | |
->icon('heroicon-o-search') | |
->label('Geocode') | |
->action(function () use ($get, $set) { | |
if (blank($get('street')) || blank($get('city')) || blank($get('state')) || blank($get('zip'))) { | |
Filament::notify('danger', 'Please provide the location\'s complete address before geocoding.'); | |
return; | |
} | |
$address = "{$get('street')} {$get('unit')} {$get('city')} {$get('state')} {$get('zip')}"; | |
try { | |
$mapsData = Http::get(config('services.google_maps.url') . '?key=' . config('services.google_maps.key') . '&address=' . $address . '&sensor=true') | |
->throw() | |
->json(); | |
} catch (RequestException $e) { | |
Filament::notify('danger', 'Unable to geocode for this address.'); | |
return; | |
} | |
$set('latitude', $mapsData['results'][0]['geometry']['location']['lat'] ?? $get('latitude')); | |
$set('longitude', $mapsData['results'][0]['geometry']['location']['lng'] ?? $get('longitude')); | |
}); | |
}), | |
DropInAction::make('birdeye_data') | |
->label('Remote') | |
->execute( | |
Action::make('birdeye_exists') | |
->label('View Data') | |
->color('secondary') | |
->action('showBirdeyeData') | |
->modalHeading(function ($livewire) { | |
return 'Birdeye data for Location ' . $livewire->record->number; | |
}) | |
->modalActions(fn ($action): array => [$action->getModalCancelAction()->label('OK')]) | |
->modalWidth('screen') | |
->modalContent(function ($livewire) { | |
return View::make('forms.components.birdeye-data', ['data' => (new BirdeyeService($livewire->record))->show(), 'id' => $livewire->id]); | |
}) | |
->extraAttributes(['class' => 'w-full']), | |
), |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment