Carousel.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace Dcat\Admin\Widgets;
  3. class Carousel extends Widget
  4. {
  5. /**
  6. * @var string
  7. */
  8. protected $view = 'admin::widgets.carousel';
  9. /**
  10. * @var array
  11. */
  12. protected $items;
  13. /**
  14. * @var string
  15. */
  16. protected $title = 'Carousel';
  17. /**
  18. * Carousel constructor.
  19. *
  20. * @param array $items
  21. */
  22. public function __construct($items = [])
  23. {
  24. $this->items = $items;
  25. $this->id('carousel-'.uniqid());
  26. $this->class('carousel slide');
  27. $this->setHtmlAttribute('data-ride', 'carousel');
  28. }
  29. /**
  30. * Set title.
  31. *
  32. * @param string $title
  33. */
  34. public function title($title)
  35. {
  36. $this->title = $title;
  37. }
  38. /**
  39. * Render Carousel.
  40. *
  41. * @return string
  42. */
  43. public function render()
  44. {
  45. $variables = [
  46. 'items' => $this->items,
  47. 'title' => $this->title,
  48. 'attributes' => $this->formatHtmlAttributes(),
  49. 'id' => $this->id,
  50. ];
  51. return view($this->view, $variables)->render();
  52. }
  53. }