Define component props in class for doc discoverability

This commit is contained in:
Elijah 2024-10-16 13:43:50 +00:00
parent 2018be8e08
commit d0fd3bd9f2

View File

@ -411,6 +411,12 @@ class CodeBlock(Component):
# Props passed down to the code tag.
code_tag_props: Var[Dict[str, str]]
# Whether a copy button should appear.
can_copy: Var[Optional[bool]] = False
# A custom copy button to override the default one.
copy_button: Var[Optional[Union[bool, Component]]] = None
def add_imports(self) -> ImportDict:
"""Add imports for the CodeBlock component.
@ -448,16 +454,12 @@ class CodeBlock(Component):
def create(
cls,
*children,
can_copy: Optional[bool] = False,
copy_button: Optional[Union[bool, Component]] = None,
**props,
):
"""Create a text component.
Args:
*children: The children of the component.
can_copy: Whether a copy button should appears.
copy_button: A custom copy button to override the default one.
**props: The props to pass to the component.
Returns:
@ -465,6 +467,8 @@ class CodeBlock(Component):
"""
# This component handles style in a special prop.
custom_style = props.pop("custom_style", {})
can_copy = props.pop("can_copy", False)
copy_button = props.pop("copy_button", None)
if "theme" not in props:
# Default color scheme responds to global color mode.