Callout.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <?php
  2. namespace Dcat\Admin\Widgets;
  3. use Illuminate\Contracts\Support\Renderable;
  4. class Callout extends Widget
  5. {
  6. /**
  7. * @var string
  8. */
  9. protected $view = 'admin::widgets.alert';
  10. /**
  11. * @var string
  12. */
  13. protected $title;
  14. /**
  15. * @var string
  16. */
  17. protected $content;
  18. /**
  19. * @var string
  20. */
  21. protected $style = 'default';
  22. /**
  23. * @var bool
  24. */
  25. protected $showCloseBtn = false;
  26. /**
  27. * Alert constructor.
  28. *
  29. * @param mixed $content
  30. * @param string $title
  31. * @param string $style
  32. */
  33. public function __construct($content = '', ?string $title = null, ?string $style = null)
  34. {
  35. $this->content($content);
  36. $this->title($title);
  37. $this->style($style);
  38. }
  39. /**
  40. * Set title.
  41. *
  42. * @param string $title
  43. *
  44. * @return $this
  45. */
  46. public function title(?string $title)
  47. {
  48. $this->title = $title;
  49. return $this;
  50. }
  51. /**
  52. * Set contents.
  53. *
  54. * @param string|\Closure|Renderable $content
  55. *
  56. * @return $this
  57. */
  58. public function content($content)
  59. {
  60. $this->content = $this->toString($content);
  61. return $this;
  62. }
  63. /**
  64. * Set light style.
  65. *
  66. * @return $this
  67. */
  68. public function light()
  69. {
  70. return $this->style('light');
  71. }
  72. /**
  73. * Set primary style.
  74. *
  75. * @return $this
  76. */
  77. public function primary()
  78. {
  79. return $this->style('primary');
  80. }
  81. /**
  82. * Set info style.
  83. *
  84. * @return $this
  85. */
  86. public function info()
  87. {
  88. return $this->style('info');
  89. }
  90. /**
  91. * Set success style.
  92. *
  93. * @return $this
  94. */
  95. public function success()
  96. {
  97. return $this->style('success');
  98. }
  99. /**
  100. * Set warning style.
  101. *
  102. * @return $this
  103. */
  104. public function warning()
  105. {
  106. return $this->style('warning');
  107. }
  108. /**
  109. * Set warning style.
  110. *
  111. * @return $this
  112. */
  113. public function danger()
  114. {
  115. return $this->style('danger');
  116. }
  117. /**
  118. * Show close button.
  119. *
  120. * @param bool $value
  121. *
  122. * @return $this
  123. */
  124. public function removable(bool $value = true)
  125. {
  126. $this->showCloseBtn = $value;
  127. return $this;
  128. }
  129. /**
  130. * Add style.
  131. *
  132. * @param string $style
  133. *
  134. * @return $this
  135. */
  136. public function style(?string $style = 'info')
  137. {
  138. $this->style = $style;
  139. return $this;
  140. }
  141. /**
  142. * @return array
  143. */
  144. public function variables()
  145. {
  146. $this->class("callout callout-{$this->style} alert alert-dismissable");
  147. return [
  148. 'title' => $this->title,
  149. 'content' => $this->content,
  150. 'attributes' => $this->formatHtmlAttributes(),
  151. 'showCloseBtn' => $this->showCloseBtn,
  152. ];
  153. }
  154. }