123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- <?php
- namespace Dcat\Admin\Widgets;
- use Illuminate\Contracts\Support\Renderable;
- class Alert extends Widget
- {
- /**
- * @var string
- */
- protected $view = 'admin::widgets.alert';
- /**
- * @var string|\Symfony\Component\Translation\TranslatorInterface
- */
- protected $title;
- /**
- * @var string
- */
- protected $content;
- /**
- * @var string
- */
- protected $style = 'light';
- /**
- * @var string
- */
- protected $icon;
- /**
- * @var bool
- */
- protected $showCloseBtn = false;
- /**
- * Alert constructor.
- *
- * @param mixed $content
- * @param string $title
- * @param string $style
- */
- public function __construct($content = '', $title = null, $style = 'danger')
- {
- $this->content($content);
- $this->title($title);
- $this->style($style);
- }
- /**
- * Set title.
- *
- * @param string $title
- *
- * @return $this
- */
- public function title($title)
- {
- $this->title = $title;
- return $this;
- }
- /**
- * Set contents.
- *
- * @param string|\Closure|Renderable $content
- *
- * @return $this
- */
- public function content($content)
- {
- $this->content = $this->toString($content);
- return $this;
- }
- /**
- * Set info style.
- *
- * @return $this
- */
- public function info()
- {
- return $this->style('info')->icon('fa fa-info');
- }
- /**
- * Set success style.
- *
- * @return $this
- */
- public function success()
- {
- return $this->style('success')->icon('fa fa-check');
- }
- /**
- * Set warning style.
- *
- * @return $this
- */
- public function warning()
- {
- return $this->style('warning')->icon('fa fa-warning');
- }
- /**
- * Set warning style.
- *
- * @return $this
- */
- public function danger()
- {
- return $this->style('danger')->icon('fa fa-ban');
- }
- /**
- * Set light style.
- *
- * @return $this
- */
- public function light()
- {
- return $this->style('light');
- }
- /**
- * Show close button.
- *
- * @param bool $value
- *
- * @return $this
- */
- public function removable(bool $value = true)
- {
- $this->showCloseBtn = $value;
- return $this;
- }
- /**
- * Add style.
- *
- * @param string $style
- *
- * @return $this
- */
- public function style($style = 'info')
- {
- $this->style = $style;
- return $this;
- }
- /**
- * Add icon.
- *
- * @param string $icon
- *
- * @return $this
- */
- public function icon($icon)
- {
- $this->icon = $icon;
- return $this;
- }
- /**
- * @return array
- */
- public function variables()
- {
- $this->class("alert alert-{$this->style} alert-dismissable");
- return [
- 'title' => $this->title,
- 'content' => $this->content,
- 'icon' => $this->icon,
- 'attributes' => $this->formatHtmlAttributes(),
- 'showCloseBtn' => $this->showCloseBtn,
- ];
- }
- }
|