mirror of
https://github.com/django-components/django-components.git
synced 2025-11-23 07:45:21 +00:00
Deployed 06d08a7c to 0.143.0 with MkDocs 1.6.1 and mike 2.1.3
This commit is contained in:
parent
720aceb939
commit
14ae96e591
460 changed files with 47230 additions and 3 deletions
32
0.143.0/examples/recursion/component.py
Normal file
32
0.143.0/examples/recursion/component.py
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
from django_components import Component, register, types
|
||||
|
||||
DESCRIPTION = "100 nested components? Not a problem! Handle recursive rendering out of the box."
|
||||
|
||||
|
||||
@register("recursion")
|
||||
class Recursion(Component):
|
||||
class Kwargs:
|
||||
current_depth: int = 0
|
||||
|
||||
def get_template_data(self, args, kwargs: Kwargs, slots, context):
|
||||
current_depth = kwargs.current_depth
|
||||
return {
|
||||
"current_depth": current_depth,
|
||||
"next_depth": current_depth + 1,
|
||||
}
|
||||
|
||||
template: types.django_html = """
|
||||
{% load component_tags %}
|
||||
<div class="py-4 border-l-2 border-gray-300 ml-1">
|
||||
{% if current_depth < 100 %}
|
||||
<p class="text-sm text-gray-600">
|
||||
Recursion depth: {{ current_depth }}
|
||||
</p>
|
||||
{% component "recursion" current_depth=next_depth / %}
|
||||
{% else %}
|
||||
<p class="text-sm font-semibold text-green-600">
|
||||
Reached maximum recursion depth!
|
||||
</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
"""
|
||||
Loading…
Add table
Add a link
Reference in a new issue