Skip to content

Commit

Permalink
Merge pull request #3 from tallstackui/dropdown
Browse files Browse the repository at this point in the history
Feature: Dropdown of Useful Links
  • Loading branch information
devajmeireles authored Sep 17, 2024
2 parents 4767cfb + 83f1738 commit c69e3a5
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 1 deletion.
10 changes: 10 additions & 0 deletions config/envbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,16 @@
'timeout' => env('ENVBAR_CLOSABLE_TIMEOUT'),
],

/*
|--------------------------------------------------------------------------
| Useful Links
|--------------------------------------------------------------------------
|
| Allows you to set useful links to be displayed in a dropdown on the EnvBar.
|
*/
'links' => explode(',', (string) env('ENVBAR_LINKS')),

/*
|--------------------------------------------------------------------------
| Environments
Expand Down
2 changes: 1 addition & 1 deletion dist/app.css

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions lang/en/messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
'environment' => 'Environment:',
'branch' => 'Branch:',
'release' => 'Latest <b>:Source</b> Release:',
'select' => '- Useful Links:',
];
1 change: 1 addition & 0 deletions lang/pt_BR/messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
'environment' => 'Ambiente:',
'branch' => 'Branch:',
'release' => 'Última Release do <b>:Source:</b>',
'select' => '- Links Úteis:',
];
20 changes: 20 additions & 0 deletions resources/views/components/envbar.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@
@endif
{{-- Right Side --}}
<div class="eb-flex eb-items-center eb-absolute eb-right-2">
@if ($configuration['links'] !== null)
<div class="eb-items-center eb-gap-1">
<select id="envbar-dropdown" class="eb-w-full eb-rounded-md eb-border-0 eb-py-0.5 eb-pl-3 eb-pr-10 eb-text-gray-900 eb-ring-1 eb-ring-inset eb-ring-gray-300 focus:eb-outline-none focus:eb-ring-1 eb-ring-gray-300 focus:eb-ring-gray-300">
<option value="">@lang('envbar::messages.select')</option>
@foreach ($configuration['links'] as $link)
<option value="{{ $link['url'] }}">{{ $link['name'] }}</option>
@endforeach
</select>
</div>
@endif
@if ($configuration['tailwind_breaking_points'])
<div class="eb-items-center eb-gap-1">
<x-envbar::badge :size="$configuration['size']"><span id="envbar-resolution"></span></x-envbar::badge>
Expand All @@ -61,5 +71,15 @@
(function() {
window.hide = () => window.$envbar(@js($configuration)).close();
@if ($configuration['links'] !== null)
const dropdown = document.getElementById('envbar-dropdown');
dropdown.addEventListener('change', () => {
window.open(dropdown.value, '_blank');
dropdown.value = '';
});
@endif
})();
</script>
23 changes: 23 additions & 0 deletions src/Compilers/EnvBarComponentCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function __invoke(): array
foreach ([
'size',
'fixed',
'links',
'closable',
'warning_message',
'tailwind_breaking_points',
Expand Down Expand Up @@ -75,4 +76,26 @@ private function tailwind_breaking_points(): bool
{
return file_exists(base_path('tailwind.config.js')) && config('envbar.tailwind_breaking_points');
}

/**
* Format the links what will be displayed on the dropdown.
*/
private function links(): ?array
{
$links = collect(config('envbar.links'))->filter();

if ($links->isEmpty()) {
return null;
}

return $links->map(function (string $link) {
if (str_contains($link, '|')) {
[$name, $url] = explode('|', $link);

return ['name' => $name, 'url' => $url];
}

return ['name' => $link, 'url' => $link];
})->toArray();
}
}
14 changes: 14 additions & 0 deletions tests/Browser/EnvBar/IndexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,18 @@ public function closable_works_successfully(): void
->assertDontSee('testing');
});
}

#[Test]
public function dropdown_works_successfully(): void
{
$this->beforeServingApplication(fn ($app, Repository $config) => $config->set('envbar.links', 'https://google.com'));

$this->browse(function (Browser $browser): void {
$browser->visit('/')
->waitForText('Environment')
->assertSee('Environment')
->assertSee('testing')
->assertSee('- Useful Links');
});
}
}

0 comments on commit c69e3a5

Please sign in to comment.