Row.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. $this->column(12, $content);
  19. }
  20. }
  21. /**
  22. * Add a column.
  23. *
  24. * @param int $width
  25. * @param $content
  26. */
  27. public function column($width, $content)
  28. {
  29. $width = $width < 1 ? round(12 * $width) : $width;
  30. $column = new Column($content, $width);
  31. $this->addColumn($column);
  32. }
  33. /**
  34. * @param Column $column
  35. */
  36. protected function addColumn(Column $column)
  37. {
  38. $this->columns[] = $column;
  39. }
  40. /**
  41. * Build row column.
  42. *
  43. * @return string
  44. */
  45. public function render()
  46. {
  47. $html = $this->startRow();
  48. foreach ($this->columns as $column) {
  49. $html .= $column->render();
  50. }
  51. return $html.$this->endRow();
  52. }
  53. /**
  54. * Start row.
  55. *
  56. * @return string
  57. */
  58. protected function startRow()
  59. {
  60. return '<div class="row">';
  61. }
  62. /**
  63. * End column.
  64. *
  65. * @return string
  66. */
  67. protected function endRow()
  68. {
  69. return '</div>';
  70. }
  71. }