diff --git a/dev/concepts/advanced/authoring_component_libraries/index.html b/dev/concepts/advanced/authoring_component_libraries/index.html index b6a23f19..a587fad9 100644 --- a/dev/concepts/advanced/authoring_component_libraries/index.html +++ b/dev/concepts/advanced/authoring_component_libraries/index.html @@ -38,7 +38,7 @@ {% endcomponent %}
Write your components and register them with your instance of ComponentRegistry
There's one difference when you are writing components that are to be shared, and that's that the components must be explicitly registered with your instance of ComponentRegistry
from the previous step.
For better user experience, you can also define the types for the args, kwargs, slots and data.
It's also a good idea to have a common prefix for your components, so they can be easily distinguished from users' components. In the example below, we use the prefix my_
/ My
.
from typing import Dict, NotRequired, Optional, Tuple, TypedDict
-from django_components import Component, SlotFunc, register, types
+from django_components import Component, SlotContent, register, types
from myapp.templatetags.mytags import comp_registry
@@ -49,7 +49,7 @@
type MyMenuArgs = Tuple[int, str]
class MyMenuSlots(TypedDict):
- default: NotRequired[Optional[SlotFunc[EmptyDict]]]
+ default: NotRequired[Optional[SlotContent[EmptyDict]]]
class MyMenuProps(TypedDict):
vertical: NotRequired[bool]
@@ -59,7 +59,7 @@
# Define the component
# NOTE: Don't forget to set the `registry`!
@register("my_menu", registry=comp_registry)
-class MyMenu(Component[MyMenuArgs, MyMenuProps, MyMenuSlots, Any, Any, Any]):
+class MyMenu(Component[MyMenuArgs, MyMenuProps, MyMenuSlots]):
def get_context_data(
self,
*args,
@@ -115,4 +115,4 @@
And, at last, you can use the components in your own project!