Card.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. namespace Dcat\Admin\Widgets;
  3. use Illuminate\Contracts\Support\Renderable;
  4. class Card extends Widget
  5. {
  6. /**
  7. * @var string
  8. */
  9. protected $view = 'admin::widgets.card';
  10. protected $title;
  11. protected $content;
  12. protected $footer;
  13. /**
  14. * @var array
  15. */
  16. protected $tools = [];
  17. /**
  18. * @var bool
  19. */
  20. protected $divider = false;
  21. public function __construct($title = '', $content = null)
  22. {
  23. if ($content === null) {
  24. $content = $title;
  25. $title = '';
  26. }
  27. if ($title) {
  28. $this->title($title);
  29. }
  30. if ($content) {
  31. $this->content($content);
  32. }
  33. $this->class('card');
  34. }
  35. /**
  36. * @return $this
  37. */
  38. public function withHeaderBorder()
  39. {
  40. $this->divider = true;
  41. return $this;
  42. }
  43. /**
  44. * 设置卡片间距.
  45. *
  46. * @param string $padding
  47. */
  48. public function padding(string $padding)
  49. {
  50. $this->padding = 'padding:'.$padding;
  51. return $this;
  52. }
  53. /**
  54. * @param string $content
  55. *
  56. * @return $this
  57. */
  58. public function content($content)
  59. {
  60. $this->content = $content;
  61. return $this;
  62. }
  63. /**
  64. * @param string $content
  65. *
  66. * @return $this
  67. */
  68. public function footer($content)
  69. {
  70. $this->footer = $content;
  71. return $this;
  72. }
  73. /**
  74. * @param string $title
  75. *
  76. * @return $this
  77. */
  78. public function title($title)
  79. {
  80. $this->title = $title;
  81. return $this;
  82. }
  83. /**
  84. * @param string|Renderable|\Closure $content
  85. *
  86. * @return $this
  87. */
  88. public function tool($content)
  89. {
  90. $this->tools[] = $this->toString($content);
  91. return $this;
  92. }
  93. /**
  94. * Variables in view.
  95. *
  96. * @return array
  97. */
  98. public function variables()
  99. {
  100. return [
  101. 'title' => $this->title,
  102. 'content' => $this->toString($this->content),
  103. 'footer' => $this->toString($this->footer),
  104. 'tools' => $this->tools,
  105. 'attributes' => $this->formatHtmlAttributes(),
  106. 'padding' => $this->padding,
  107. 'divider' => $this->divider,
  108. ];
  109. }
  110. }