-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a Twig component to display flash messages
- Loading branch information
1 parent
150e6cb
commit f0c9bd2
Showing
5 changed files
with
56 additions
and
3 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace EasyCorp\Bundle\EasyAdminBundle\Config\Enum; | ||
|
||
enum BannerVariant: string | ||
{ | ||
case Primary = 'primary'; | ||
case Secondary = 'secondary'; | ||
case Success = 'success'; | ||
case Danger = 'danger'; | ||
case Warning = 'warning'; | ||
case Info = 'info'; | ||
case Light = 'light'; | ||
case Dark = 'dark'; | ||
|
||
public function asCssClass(): string | ||
{ | ||
return $this->value; | ||
} | ||
} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace EasyCorp\Bundle\EasyAdminBundle\Twig\Component; | ||
|
||
use EasyCorp\Bundle\EasyAdminBundle\Config\Enum\BannerVariant; | ||
|
||
class Banner | ||
{ | ||
public BannerVariant|string $variant = BannerVariant::Info; | ||
public bool $withDismissButton = false; | ||
|
||
public function getVariantCssClass(): string | ||
{ | ||
return \is_string($this->variant) ? $this->variant : $this->variant->asCssClass(); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{% set css_class = html_classes({ | ||
'alert': true, | ||
'alert-dismissible': withDismissButton, | ||
}) %} | ||
{% set css_class = css_class ~ ' alert-' ~ this.getVariantCssClass() %} | ||
|
||
<div {{ attributes.defaults({class: css_class, role: 'alert'}) }}> | ||
<twig:block name="content"></twig:block> | ||
|
||
{% if withDismissButton %} | ||
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button> | ||
{% endif %} | ||
</div> |
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