Fix rx.progress to support max prop (#2601)

This commit is contained in:
invrainbow 2024-02-13 14:25:31 -08:00 committed by GitHub
parent 5e9b472d1b
commit fccb73ee70
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 2 deletions

View File

@ -55,6 +55,9 @@ class ProgressIndicator(ProgressComponent):
# The current progress value.
value: Var[Optional[int]]
# The maximum progress value.
max: Var[Optional[int]]
def _apply_theme(self, theme: Component):
self.style = Style(
{
@ -65,7 +68,7 @@ class ProgressIndicator(ProgressComponent):
"&[data_state='loading']": {
"transition": f"transform {DEFAULT_ANIMATION_DURATION}ms linear",
},
"transform": f"translateX(calc(-100% + {self.value}%))", # type: ignore
"transform": f"translateX(calc(-100% + ({self.value} / {self.max} * 100%)))", # type: ignore
"boxShadow": "inset 0 0 0 1px var(--gray-a5)",
}
)
@ -92,7 +95,9 @@ class Progress(SimpleNamespace):
style.update({"width": width})
return ProgressRoot.create(
ProgressIndicator.create(value=props.get("value")),
ProgressIndicator.create(
value=props.get("value"), max=props.get("max", 100)
),
**props,
)

View File

@ -188,6 +188,7 @@ class ProgressIndicator(ProgressComponent):
cls,
*children,
value: Optional[Union[Var[Optional[int]], Optional[int]]] = None,
max: Optional[Union[Var[Optional[int]], Optional[int]]] = None,
as_child: Optional[Union[Var[bool], bool]] = None,
style: Optional[Style] = None,
key: Optional[Any] = None,
@ -247,6 +248,7 @@ class ProgressIndicator(ProgressComponent):
Args:
*children: The children of the component.
value: The current progress value.
max: The maximum progress value.
as_child: Change the default rendered element for the one passed as a child.
style: The style of the component.
key: A unique key for the component.