v0.135ยค
Featยค
- Add defaults for the component inputs with the
Component.Defaults
nested class. Defaults are applied if the argument is not given, or if it set toNone
.
For lists, dictionaries, or other objects, wrap the value in Default()
class to mark it as a factory function:
```python
from django_components import Default
class Table(Component):
class Defaults:
position = "left"
width = "200px"
options = Default(lambda: ["left", "right", "center"])
def get_context_data(self, position, width, options):
return {
"position": position,
"width": width,
"options": options,
}
# `position` is used as given, `"right"`
# `width` uses default because it's `None`
# `options` uses default because it's missing
Table.render(
kwargs={
"position": "right",
"width": None,
}
)
```
-
{% html_attrs %}
now offers a Vue-like granular control overclass
andstyle
HTML attributes, where each class name or style property can be managed separately.{% html_attrs style="text-align: center; background-color: blue;" style={"background-color": "green", "color": None, "width": False} style="position: absolute; height: 12px;" %}
Read more on HTML attributes.