@@ -24,6 +24,8 @@ final class GridComponent extends Control
2424 */
2525 private ?Html $ column = null ;
2626
27+ private ?string $ incrementSequencePrefix = null ;
28+
2729 private int $ columnNumber = 1 ;
2830
2931 public function __construct (Component $ component )
@@ -42,14 +44,25 @@ public function setRow(?Html $row): void
4244 /**
4345 * @phpstan-param Html<int, Html|string>|null $column
4446 */
45- public function setColumn (?Html $ column ): void
47+ public function setColumn (?Html $ column ): self
4648 {
4749 $ this ->column = $ column ;
50+
51+ return $ this ;
4852 }
4953
50- public function setColumnNumber (int $ columnNumber ): void
54+ public function setColumnNumber (int $ columnNumber ): self
5155 {
5256 $ this ->columnNumber = max (1 , $ columnNumber );
57+
58+ return $ this ;
59+ }
60+
61+ public function setIncrementSequence (string $ prefix ): self
62+ {
63+ $ this ->incrementSequencePrefix = $ prefix ;
64+
65+ return $ this ;
5366 }
5467
5568 public function render (): void
@@ -60,17 +73,54 @@ public function render(): void
6073 assert ($ component instanceof Component);
6174 assert ($ template instanceof Template);
6275
63- $ controls = iterator_to_array ($ component ->getComponents (true , IRenderable::class));
76+ $ controls = iterator_to_array ($ component ->getComponents (false , IRenderable::class));
6477
6578 if (!$ controls ) {
6679 return ;
6780 }
6881
82+ // column functions
83+ $ template ->getLatte ()->addFunction ('startColumn ' , function (int $ counter ): ?string {
84+ if (!$ this ->column ) {
85+ return null ;
86+ }
87+
88+ $ col = $ this ->column ;
89+ if ($ this ->incrementSequencePrefix ) {
90+ $ col = clone $ this ->column ;
91+ $ col ->appendAttribute ('class ' , $ this ->incrementSequencePrefix . $ counter );
92+ }
93+
94+ return $ col ->startTag ();
95+ });
96+ $ template ->getLatte ()->addFunction ('endColumn ' , function (): ?string {
97+ if (!$ this ->column ) {
98+ return null ;
99+ }
100+
101+ return $ this ->column ->endTag ();
102+ });
103+
104+ // row functions
105+ $ template ->getLatte ()->addFunction ('startRow ' , function (int $ counter ): ?string {
106+ if (!$ this ->row ) {
107+ return null ;
108+ }
109+
110+ return $ this ->row ->startTag ();
111+ });
112+ $ template ->getLatte ()->addFunction ('endRow ' , function (): ?string {
113+ if (!$ this ->row ) {
114+ return null ;
115+ }
116+
117+ return $ this ->row ->endTag ();
118+ });
119+
120+
69121 $ template ->render (__DIR__ . '/templates/grid.latte ' , [
70122 'controls ' => $ controls ,
71123 'calculate ' => (bool ) $ this ->row ,
72- 'row ' => $ this ->row ,
73- 'column ' => $ this ->column ,
74124 'number ' => $ this ->columnNumber ,
75125 ]);
76126 }
0 commit comments