Navbar.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace Dcat\Admin\Layout;
  3. use Dcat\Admin\Support\Helper;
  4. use Dcat\Admin\Traits\HasBuilderEvents;
  5. use Dcat\Admin\Widgets\DarkModeSwitcher;
  6. use Illuminate\Contracts\Support\Htmlable;
  7. use Illuminate\Contracts\Support\Renderable;
  8. class Navbar implements Renderable
  9. {
  10. use HasBuilderEvents;
  11. /**
  12. * @var array
  13. */
  14. protected $elements = [];
  15. /**
  16. * Navbar constructor.
  17. */
  18. public function __construct()
  19. {
  20. $this->elements = [
  21. 'left' => collect(),
  22. 'right' => collect(),
  23. ];
  24. $this->callResolving();
  25. }
  26. /**
  27. * @param string|\Closure|Renderable|Htmlable $element
  28. *
  29. * @return $this
  30. */
  31. public function left($element)
  32. {
  33. $this->elements['left']->push($element);
  34. return $this;
  35. }
  36. /**
  37. * @param string|\Closure|Renderable|Htmlable $element
  38. *
  39. * @return $this
  40. */
  41. public function right($element)
  42. {
  43. $this->elements['right']->push($element);
  44. return $this;
  45. }
  46. /**
  47. * @param string $part
  48. *
  49. * @return mixed
  50. */
  51. public function render($part = 'right')
  52. {
  53. $this->callComposing($part);
  54. if (! isset($this->elements[$part]) || $this->elements[$part]->isEmpty()) {
  55. return '';
  56. }
  57. return $this->elements[$part]->map([Helper::class, 'render'])->implode('');
  58. }
  59. }