File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed
Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -160,3 +160,43 @@ print(
160160 )
161161)
162162```
163+
164+ ### Components with children
165+
166+ When building their own set of components, some prefer to make their own
167+ components accept children nodes in the same way as the HTML elements provided
168+ by htpy.
169+
170+ Making this work correctly in all cases can be tricky, so htpy provides a
171+ decorator called ` @with_children ` .
172+
173+ With the ` @with_children ` decorator you can to convert a component like this:
174+
175+ ``` py
176+ from htpy import Element, Node
177+
178+ def my_component (* , title : str , children : Node) -> Element:
179+ ...
180+ ```
181+
182+ That is used like this:
183+
184+ ``` py
185+ my_component(title = " My title" , children = h.div[" My content" ])
186+ ```
187+
188+ Into a component that is defined like this:
189+
190+ ``` py
191+ from htpy import Element, Node, with_children
192+
193+ @with_children
194+ def my_component (children : Node, * , title : str ) -> Element:
195+ ...
196+ ```
197+
198+ And that is used like this, just like any HTML element:
199+
200+ ``` py
201+ my_component(title = " My title" )[h.div[" My content" ]]
202+ ```
You can’t perform that action at this time.
0 commit comments