Skip to content

Commit

Permalink
Add individual blade components
Browse files Browse the repository at this point in the history
  • Loading branch information
bilfeldt committed Dec 16, 2022
1 parent 134bcf0 commit 1a79a3b
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/FlashMessageServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
namespace Bilfeldt\LaravelFlashMessage;

use Bilfeldt\LaravelFlashMessage\View\Components\Alert;
use Bilfeldt\LaravelFlashMessage\View\Components\AlertError;
use Bilfeldt\LaravelFlashMessage\View\Components\AlertInfo;
use Bilfeldt\LaravelFlashMessage\View\Components\AlertMessage;
use Bilfeldt\LaravelFlashMessage\View\Components\AlertMessages;
use Bilfeldt\LaravelFlashMessage\View\Components\AlertSuccess;
use Bilfeldt\LaravelFlashMessage\View\Components\AlertWarning;
use Illuminate\Http\RedirectResponse;
use Illuminate\View\Factory;
use Illuminate\View\View;
Expand All @@ -27,8 +32,13 @@ public function configurePackage(Package $package): void
->hasViews() // required for the view component blade files to be registered
->hasViewComponents(
self::VIEW_COMPONENT_NAMESPACE,
AlertMessages::class,
Alert::class,
AlertMessages::class
AlertError::class,
AlertInfo::class,
AlertMessage::class,
AlertSuccess::class,
AlertWarning::class
);
}

Expand Down
21 changes: 21 additions & 0 deletions src/View/Components/AbstractAlert.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Bilfeldt\LaravelFlashMessage\View\Components;

use Illuminate\View\Component;

abstract class AbstractAlert extends Component
{
public string $text;
public string $title;
public array $messages;
public array $links;

public function __construct(string $text, string $title = '', array $messages = [], array $links = [])
{
$this->text = $text;
$this->title = $title;
$this->messages = $messages;
$this->links = $links;
}
}
11 changes: 11 additions & 0 deletions src/View/Components/AlertError.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Bilfeldt\LaravelFlashMessage\View\Components;

class AlertError extends AbstractAlert
{
public function render()
{
return view('flash-message::components.alert-error');
}
}
11 changes: 11 additions & 0 deletions src/View/Components/AlertInfo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Bilfeldt\LaravelFlashMessage\View\Components;

class AlertInfo extends AbstractAlert
{
public function render()
{
return view('flash-message::components.alert-info');
}
}
11 changes: 11 additions & 0 deletions src/View/Components/AlertMessage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Bilfeldt\LaravelFlashMessage\View\Components;

class AlertMessage extends AbstractAlert
{
public function render()
{
return view('flash-message::components.alert-message');
}
}
11 changes: 11 additions & 0 deletions src/View/Components/AlertSuccess.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Bilfeldt\LaravelFlashMessage\View\Components;

class AlertSuccess extends AbstractAlert
{
public function render()
{
return view('flash-message::components.alert-success');
}
}
11 changes: 11 additions & 0 deletions src/View/Components/AlertWarning.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Bilfeldt\LaravelFlashMessage\View\Components;

class AlertWarning extends AbstractAlert
{
public function render()
{
return view('flash-message::components.alert-warning');
}
}

0 comments on commit 1a79a3b

Please sign in to comment.