Accordion.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace Dcat\Admin\Widgets;
  3. use Illuminate\Support\Str;
  4. class Accordion extends Widget
  5. {
  6. /**
  7. * @var string
  8. */
  9. protected $view = 'admin::widgets.accordion';
  10. /**
  11. * @var array
  12. */
  13. protected $items = [];
  14. /**
  15. * @var string
  16. */
  17. protected $panelStyle = 'panel-default';
  18. /**
  19. * Collapse constructor.
  20. */
  21. public function __construct()
  22. {
  23. $this->class('panel-group');
  24. $this->id('accordion-'.Str::random(8));
  25. }
  26. /**
  27. * @return $this
  28. */
  29. public function white()
  30. {
  31. return $this->panelStyle('white');
  32. }
  33. /**
  34. * @return $this
  35. */
  36. public function panelStyle(string $style)
  37. {
  38. $this->panelStyle = 'panel-'.$style;
  39. return $this;
  40. }
  41. /**
  42. * Add item.
  43. *
  44. * @param string $title
  45. * @param string $content
  46. *
  47. * @return $this
  48. */
  49. public function add($title, $content, bool $expand = false)
  50. {
  51. $this->items[] = [
  52. 'id' => 'accordion-'.Str::random(12),
  53. 'title' => $title,
  54. 'content' => $this->toString($content),
  55. 'expand' => $expand,
  56. ];
  57. return $this;
  58. }
  59. public function variables()
  60. {
  61. return [
  62. 'id' => $this->getHtmlAttribute('id'),
  63. 'items' => $this->items,
  64. 'panelStyle' => $this->panelStyle,
  65. 'attributes' => $this->formatHtmlAttributes(),
  66. ];
  67. }
  68. }