exclude props we don't need from compiling.

use regular model fields where necessary
This commit is contained in:
Elijah 2024-10-22 16:40:46 +00:00
parent 11a38adffa
commit 57d2662977
8 changed files with 72 additions and 215 deletions

View File

@ -412,10 +412,10 @@ class CodeBlock(Component):
code_tag_props: Var[Dict[str, str]]
# Whether a copy button should appear.
can_copy: Var[Optional[bool]] = Var.create(False)
can_copy: Optional[bool] = False
# A custom copy button to override the default one.
copy_button: Var[Optional[Union[bool, Component]]] = Var.create(None)
copy_button: Optional[Union[bool, Component]] = None
def add_imports(self) -> ImportDict:
"""Add imports for the CodeBlock component.
@ -540,6 +540,9 @@ class CodeBlock(Component):
return out
def _exclude_props(self) -> list[str]:
return ["can_copy", "copy_button"]
class CodeblockNamespace(ComponentNamespace):
"""Namespace for the CodeBlock component."""

View File

@ -931,10 +931,8 @@ class CodeBlock(Component):
wrap_long_lines: Optional[Union[Var[bool], bool]] = None,
custom_style: Optional[Dict[str, Union[str, Var, Color]]] = None,
code_tag_props: Optional[Union[Dict[str, str], Var[Dict[str, str]]]] = None,
can_copy: Optional[Union[Var[Optional[bool]], bool]] = None,
copy_button: Optional[
Union[Component, Var[Optional[Union[Component, bool]]], bool]
] = None,
can_copy: Optional[bool] = None,
copy_button: Optional[Union[Component, bool]] = None,
style: Optional[Style] = None,
key: Optional[Any] = None,
id: Optional[Any] = None,
@ -1568,10 +1566,8 @@ class CodeblockNamespace(ComponentNamespace):
wrap_long_lines: Optional[Union[Var[bool], bool]] = None,
custom_style: Optional[Dict[str, Union[str, Var, Color]]] = None,
code_tag_props: Optional[Union[Dict[str, str], Var[Dict[str, str]]]] = None,
can_copy: Optional[Union[Var[Optional[bool]], bool]] = None,
copy_button: Optional[
Union[Component, Var[Optional[Union[Component, bool]]], bool]
] = None,
can_copy: Optional[bool] = None,
copy_button: Optional[Union[Component, bool]] = None,
style: Optional[Style] = None,
key: Optional[Any] = None,
id: Optional[Any] = None,

View File

@ -194,10 +194,9 @@ class AccordionItem(AccordionComponent):
disabled: Var[bool]
# The header of the accordion item.
header: Var[Optional[Union[Component, str]]] = Var.create(None)
header: Optional[Union[Component, str, Var[Union[Component, str]]]] = None
# The content of the accordion item.
content: Var[Optional[Union[Component, str]]] = Var.create(None)
content: Optional[Union[Component, str, Var[Union[Component, str]]]] = None
_valid_children: List[str] = [
"AccordionHeader",
@ -296,6 +295,9 @@ class AccordionItem(AccordionComponent):
},
}
def _exclude_props(self) -> list[str]:
return ["header", "content"]
class AccordionHeader(AccordionComponent):
"""An accordion component."""

View File

@ -305,10 +305,10 @@ class AccordionItem(AccordionComponent):
value: Optional[Union[Var[str], str]] = None,
disabled: Optional[Union[Var[bool], bool]] = None,
header: Optional[
Union[Component, Var[Optional[Union[Component, str]]], str]
Union[Component, Union[Component, Var[Union[Component, str]], str], str]
] = None,
content: Optional[
Union[Component, Var[Optional[Union[Component, str]]], str]
Union[Component, Union[Component, Var[Union[Component, str]], str], str]
] = None,
color_scheme: Optional[
Union[

View File

@ -97,10 +97,10 @@ class ColorModeIconButton(IconButton):
"""Icon Button for toggling light / dark mode via toggle_color_mode."""
# The position of the icon button. Follow document flow if None.
position: Var[Optional[LiteralPosition]] = Var.create(None)
position: Optional[LiteralPosition] = None
# Allow picking the "system" value for the color mode.
allow_system: Var[bool] = Var.create(False)
allow_system: bool = False
@classmethod
def create(
@ -166,6 +166,9 @@ class ColorModeIconButton(IconButton):
**props,
)
def _exclude_props(self) -> list[str]:
return ["position", "allow_system"]
class ColorModeSwitch(Switch):
"""Switch for toggling light / dark mode via toggle_color_mode."""

View File

@ -76,16 +76,9 @@ class ColorModeIconButton(IconButton):
cls,
*children,
position: Optional[
Union[
Literal["bottom-left", "bottom-right", "top-left", "top-right"],
Var[
Optional[
Literal["bottom-left", "bottom-right", "top-left", "top-right"]
]
],
]
Literal["bottom-left", "bottom-right", "top-left", "top-right"]
] = None,
allow_system: Optional[Union[Var[bool], bool]] = None,
allow_system: Optional[bool] = None,
as_child: Optional[Union[Var[bool], bool]] = None,
size: Optional[
Union[

View File

@ -42,12 +42,12 @@ class BaseList(Component):
tag = "ul"
# The style of the list. Default to "none".
list_style_type: Var[
Union[LiteralListStyleTypeUnordered, LiteralListStyleTypeOrdered]
] = Var.create("none")
list_style_type: Union[
LiteralListStyleTypeUnordered, LiteralListStyleTypeOrdered
] = "none"
# A list of items to add to the list.
items: Var[Optional[Var[Iterable]]] = Var.create(None)
items: Optional[Union[Iterable, Var[Iterable]]] = None
@classmethod
def create(
@ -91,7 +91,7 @@ class BaseList(Component):
}
def _exclude_props(self) -> list[str]:
return ["items"]
return ["items", "list_style_type"]
class UnorderedList(BaseList, Ul):
@ -100,7 +100,7 @@ class UnorderedList(BaseList, Ul):
tag = "ul"
# The style of the list.
list_style_type: Var[LiteralListStyleTypeOrdered] = Var.create("disc")
list_style_type: LiteralListStyleTypeOrdered = "disc"
@classmethod
def create(
@ -133,7 +133,7 @@ class OrderedList(BaseList, Ol):
tag = "ol"
# The style of the list.
list_style_type: Var[LiteralListStyleTypeOrdered] = Var.create("decimal")
list_style_type: LiteralListStyleTypeOrdered = "decimal"
@classmethod
def create(

View File

@ -35,54 +35,26 @@ class BaseList(Component):
def create( # type: ignore
cls,
*children,
list_style_type: Optional[
Union[
Literal[
"armenian",
"decimal",
"decimal-leading-zero",
"georgian",
"hiragana",
"katakana",
"lower-alpha",
"lower-greek",
"lower-latin",
"lower-roman",
"none",
"upper-alpha",
"upper-latin",
"upper-roman",
],
Literal["circle", "disc", "none", "square"],
Var[
Union[
Literal[
"armenian",
"decimal",
"decimal-leading-zero",
"georgian",
"hiragana",
"katakana",
"lower-alpha",
"lower-greek",
"lower-latin",
"lower-roman",
"none",
"upper-alpha",
"upper-latin",
"upper-roman",
],
Literal["circle", "disc", "none", "square"],
]
],
]
] = None,
items: Optional[
Union[
Union[Iterable, Var[Iterable]],
Var[Optional[Union[Iterable, Var[Iterable]]]],
]
list_style_type: Union[
Literal["circle", "disc", "none", "square"],
Literal[
"armenian",
"decimal",
"decimal-leading-zero",
"georgian",
"hiragana",
"katakana",
"lower-alpha",
"lower-greek",
"lower-latin",
"lower-roman",
"none",
"upper-alpha",
"upper-latin",
"upper-roman",
],
] = None,
items: Optional[Union[Iterable, Union[Iterable, Var[Iterable]]]] = None,
style: Optional[Style] = None,
key: Optional[Any] = None,
id: Optional[Any] = None,
@ -134,50 +106,8 @@ class UnorderedList(BaseList, Ul):
def create( # type: ignore
cls,
*children,
list_style_type: Optional[
Union[
Literal[
"armenian",
"decimal",
"decimal-leading-zero",
"georgian",
"hiragana",
"katakana",
"lower-alpha",
"lower-greek",
"lower-latin",
"lower-roman",
"none",
"upper-alpha",
"upper-latin",
"upper-roman",
],
Var[
Literal[
"armenian",
"decimal",
"decimal-leading-zero",
"georgian",
"hiragana",
"katakana",
"lower-alpha",
"lower-greek",
"lower-latin",
"lower-roman",
"none",
"upper-alpha",
"upper-latin",
"upper-roman",
]
],
]
] = None,
items: Optional[
Union[
Union[Iterable, Var[Iterable]],
Var[Optional[Union[Iterable, Var[Iterable]]]],
]
] = None,
list_style_type: Optional[LiteralListStyleTypeOrdered] = None,
items: Optional[Union[Iterable, Union[Iterable, Var[Iterable]]]] = None,
access_key: Optional[Union[Var[Union[bool, int, str]], bool, int, str]] = None,
auto_capitalize: Optional[
Union[Var[Union[bool, int, str]], bool, int, str]
@ -267,50 +197,8 @@ class OrderedList(BaseList, Ol):
def create( # type: ignore
cls,
*children,
list_style_type: Optional[
Union[
Literal[
"armenian",
"decimal",
"decimal-leading-zero",
"georgian",
"hiragana",
"katakana",
"lower-alpha",
"lower-greek",
"lower-latin",
"lower-roman",
"none",
"upper-alpha",
"upper-latin",
"upper-roman",
],
Var[
Literal[
"armenian",
"decimal",
"decimal-leading-zero",
"georgian",
"hiragana",
"katakana",
"lower-alpha",
"lower-greek",
"lower-latin",
"lower-roman",
"none",
"upper-alpha",
"upper-latin",
"upper-roman",
]
],
]
] = None,
items: Optional[
Union[
Union[Iterable, Var[Iterable]],
Var[Optional[Union[Iterable, Var[Iterable]]]],
]
] = None,
list_style_type: Optional[LiteralListStyleTypeOrdered] = None,
items: Optional[Union[Iterable, Union[Iterable, Var[Iterable]]]] = None,
reversed: Optional[Union[Var[Union[bool, int, str]], bool, int, str]] = None,
start: Optional[Union[Var[Union[bool, int, str]], bool, int, str]] = None,
type: Optional[Union[Var[Union[bool, int, str]], bool, int, str]] = None,
@ -495,54 +383,26 @@ class List(ComponentNamespace):
@staticmethod
def __call__(
*children,
list_style_type: Optional[
Union[
Literal[
"armenian",
"decimal",
"decimal-leading-zero",
"georgian",
"hiragana",
"katakana",
"lower-alpha",
"lower-greek",
"lower-latin",
"lower-roman",
"none",
"upper-alpha",
"upper-latin",
"upper-roman",
],
Literal["circle", "disc", "none", "square"],
Var[
Union[
Literal[
"armenian",
"decimal",
"decimal-leading-zero",
"georgian",
"hiragana",
"katakana",
"lower-alpha",
"lower-greek",
"lower-latin",
"lower-roman",
"none",
"upper-alpha",
"upper-latin",
"upper-roman",
],
Literal["circle", "disc", "none", "square"],
]
],
]
] = None,
items: Optional[
Union[
Union[Iterable, Var[Iterable]],
Var[Optional[Union[Iterable, Var[Iterable]]]],
]
list_style_type: Union[
Literal["circle", "disc", "none", "square"],
Literal[
"armenian",
"decimal",
"decimal-leading-zero",
"georgian",
"hiragana",
"katakana",
"lower-alpha",
"lower-greek",
"lower-latin",
"lower-roman",
"none",
"upper-alpha",
"upper-latin",
"upper-roman",
],
] = None,
items: Optional[Union[Iterable, Union[Iterable, Var[Iterable]]]] = None,
style: Optional[Style] = None,
key: Optional[Any] = None,
id: Optional[Any] = None,