Banner
Banner component.
The banner component is a component intended to display text at the top of the page. It has two usage approaches: static usage to display fixed or random messages or Livewire integration to display messages that comes from the backend to the frontend. An example of the banner component is the banner at the top of the documentation.
To use the component you must add it to your application layout, within the body
tag:
<html> <body> <x-banner /> <!-- ... --> </body></html>
text
attribute with the message you want to display.
<html> <body> <x-banner text="Welcome to the TallStackUI!" /> </body></html>
You can also set random messages to be displayed:
<html> <body> <!-- Plain array --> <x-banner :text="[ 'Welcome to the TallStackUI!', 'This is the TallStackUI' ]" /> <!-- Collection --> <x-banner :text="collect([ 'Welcome to the TallStackUI!', 'This is the TallStackUI' ])" /> </body></html>
<html> <body> <x-banner text="Welcome to the TallStackUI!"> <x-slot:left> <x-icon name="check" /> </x-slot:left> </x-banner> </body></html>
<html> <body> <x-banner text="Welcome to the TallStackUI!" close /> </body></html>
<html> <body> <!-- Default: entering in 3 seconds --> <x-banner text="Welcome to the TallStackUI!" animated /> <!-- Entering in 2 seconds, leaving in 5 seconds --> <x-banner text="Welcome to the TallStackUI!" animated :enter="2" :leave="5" /> <!-- Only leaving effect --> <x-banner text="Welcome to the TallStackUI!" animated :enter="null" :leave="5" /> </body></html>
An option to control the final date to display the banner.
<html> <body> <x-banner text="Welcome to the TallStackUI!" until="2023-12-31" /> </body></html>
<html> <body> <!-- Allowed: sm, md, lg --> <x-banner text="Welcome to the TallStackUI!" size="lg" /> </body></html>
<html> <body> <!-- All TailwindCSS colors --> <x-banner text="Welcome to the TallStackUI!" color="primary" /> <x-banner text="Welcome to the TallStackUI!" color="secondary" /> <!-- Light variation --> <x-banner text="Welcome to the TallStackUI!" color="primary" light /> <x-banner text="Welcome to the TallStackUI!" color="secondary" light /> <!-- Hexadecimal colors using TailwindCSS arbitrary colors --> <x-banner text="Welcome to the TallStackUI!" :color="[ 'background' => 'bg-[#fde68a]', 'text' => 'text-[#1f2937]', ]" /> </body></html>
use Illuminate\Http\Request;use TallStackUi\Traits\Interactions; class PaymentController extends Controller{ use Interactions; public function index() { return view('payment.index', [ // ]); } public function update(Request $request) { // ... $this->banner() ->success('...') ->close() ->enter(seconds: 3) ->leave(seconds: 10) ->send(); }}
One of the benefits of the banner component is that it can be integrated with Livewire to send messages from the backend to the frontend -
similar to the concept of using things like Toast or Dialog. When choosing to use the banner in this way, the only configurable attribute
is the size
, since all other things will be configured through the Livewire integration. Preparing the component is simple,
just define the wire
attribute in the component so that TallStackUI identifies the usage format integrated with Livewire:
<html> <body> <x-banner wire /> <!-- or --> <!-- Allowed: sm, md, lg --> <x-banner wire size="lg" /> </body></html>
-
Use the Interactions trait in your Livewire component.
use TallStackUi\Traits\Interactions;class CreateUser extends Component{use Interactions;// ...}
-
Dispatch the Banner from a method.
public function save(): void{$this->banner()->success('...')->send();$this->banner()->error('...')->send();$this->banner()->warning('...')->send();$this->banner()->info('...')->send();}
This is an example. You can not dispatch all at the same time.
public function save(): void{ $this->banner() ->close() // Add the close button ->success('...') ->send(); $this->banner() ->enter(seconds: 3) // Enter in 3 seconds ->leave(seconds: 10) // Leave in 10 seconds ->success('...') ->send(); $this->banner() ->leave(seconds: 10) // Controlling only the seconds to leave ->success('...') ->send();}
When using flash()
method, the banner will not be displayed in the current
request, but yes stored temporarily in the session and displayed in the next request when you
redirect to another page.
use Illuminate\Contracts\View\View;use Livewire\Component;use TallStackUi\Traits\Interactions; class Payment extends Component{ use Interactions; public function render(): View { return view('livewire.livewire'); } public function save() { $this->banner() ->success('Done!', 'Your money has been sent!') ->flash() ->send(); return $this->redirect(route('dashboard')); }}