Collapse.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace Encore\Admin\Widgets;
  3. use Illuminate\Contracts\Support\Renderable;
  4. class Collapse extends Widget implements Renderable
  5. {
  6. /**
  7. * @var string
  8. */
  9. protected $view = 'admin::widgets.collapse';
  10. /**
  11. * @var array
  12. */
  13. protected $items = [];
  14. /**
  15. * Collapse constructor.
  16. */
  17. public function __construct()
  18. {
  19. $this->id('accordion-'.uniqid());
  20. $this->class('box-group');
  21. $this->style('margin-bottom: 20px');
  22. }
  23. /**
  24. * Add item.
  25. *
  26. * @param string $title
  27. * @param string $content
  28. *
  29. * @return $this
  30. */
  31. public function add($title, $content)
  32. {
  33. $this->items[] = [
  34. 'title' => $title,
  35. 'content' => $content,
  36. ];
  37. return $this;
  38. }
  39. protected function variables()
  40. {
  41. return [
  42. 'id' => $this->id,
  43. 'items' => $this->items,
  44. 'attributes' => $this->formatAttributes(),
  45. ];
  46. }
  47. /**
  48. * Render Collapse.
  49. *
  50. * @return string
  51. */
  52. public function render()
  53. {
  54. return view($this->view, $this->variables())->render();
  55. }
  56. }