Row.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace Dcat\Admin\Layout;
  3. use Illuminate\Contracts\Support\Renderable;
  4. class Row implements Renderable
  5. {
  6. /**
  7. * @var Column[]
  8. */
  9. protected $columns = [];
  10. /**
  11. * Row constructor.
  12. *
  13. * @param string $content
  14. */
  15. public function __construct($content = '')
  16. {
  17. if (! empty($content)) {
  18. if ($content instanceof Column) {
  19. $this->addColumn($content);
  20. } else {
  21. $this->column(12, $content);
  22. }
  23. }
  24. }
  25. /**
  26. * Add a column.
  27. *
  28. * @param int $width
  29. * @param $content
  30. */
  31. public function column($width, $content)
  32. {
  33. $column = new Column($content, $width);
  34. $this->addColumn($column);
  35. }
  36. /**
  37. * @param Column $column
  38. */
  39. protected function addColumn(Column $column)
  40. {
  41. $this->columns[] = $column;
  42. }
  43. /**
  44. * Build row column.
  45. *
  46. * @return string
  47. */
  48. public function render()
  49. {
  50. $html = $this->startRow();
  51. foreach ($this->columns as $column) {
  52. $html .= $column->render();
  53. }
  54. return $html.$this->endRow();
  55. }
  56. /**
  57. * Start row.
  58. *
  59. * @return string
  60. */
  61. protected function startRow()
  62. {
  63. return '<div class="row">';
  64. }
  65. /**
  66. * End column.
  67. *
  68. * @return string
  69. */
  70. protected function endRow()
  71. {
  72. return '</div>';
  73. }
  74. }