Change Strategy Prop to Literal (#3575)
* Better type strategy prop * Add beter description * Pre commit * fix pyi generation * Default prop assignment must be Var to pass type checking * fix script.pyi --------- Co-authored-by: Alek Petuskey <alekpetuskey@Aleks-MacBook-Pro.local> Co-authored-by: Masen Furer <m_github@0x26.net>
This commit is contained in:
parent
d253fc4dcd
commit
1c3d65dd52
@ -5,6 +5,8 @@ https://nextjs.org/docs/app/api-reference/components/script
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Literal
|
||||
|
||||
from reflex.components.component import Component
|
||||
from reflex.event import EventHandler
|
||||
from reflex.vars import Var
|
||||
@ -27,8 +29,10 @@ class Script(Component):
|
||||
# Required unless inline script is used
|
||||
src: Var[str]
|
||||
|
||||
# When the script will execute: afterInteractive | beforeInteractive | lazyOnload
|
||||
strategy: Var[str] = "afterInteractive" # type: ignore
|
||||
# When the script will execute: afterInteractive (defer-like behavior) | beforeInteractive | lazyOnload (async-like behavior)
|
||||
strategy: Var[Literal["afterInteractive", "beforeInteractive", "lazyOnload"]] = (
|
||||
Var.create_safe("afterInteractive", _var_is_string=True)
|
||||
)
|
||||
|
||||
# Triggered when the script is loading
|
||||
on_load: EventHandler[lambda: []]
|
||||
|
@ -8,6 +8,7 @@ import reflex
|
||||
from reflex.vars import Var, BaseVar, ComputedVar
|
||||
from reflex.event import EventChain, EventHandler, EventSpec
|
||||
from reflex.style import Style
|
||||
from typing import Literal
|
||||
from reflex.components.component import Component
|
||||
from reflex.event import EventHandler
|
||||
from reflex.vars import Var
|
||||
@ -19,7 +20,14 @@ class Script(Component):
|
||||
cls,
|
||||
*children,
|
||||
src: Optional[Union[reflex.vars.Var[str], str]] = None,
|
||||
strategy: Optional[Union[reflex.vars.Var[str], str]] = None,
|
||||
strategy: Optional[
|
||||
Union[
|
||||
reflex.vars.Var[
|
||||
Literal["afterInteractive", "beforeInteractive", "lazyOnload"]
|
||||
],
|
||||
Literal["afterInteractive", "beforeInteractive", "lazyOnload"],
|
||||
]
|
||||
] = None,
|
||||
style: Optional[Style] = None,
|
||||
key: Optional[Any] = None,
|
||||
id: Optional[Any] = None,
|
||||
@ -97,7 +105,7 @@ class Script(Component):
|
||||
Args:
|
||||
*children: The children of the component.
|
||||
src: Required unless inline script is used
|
||||
strategy: When the script will execute: afterInteractive | beforeInteractive | lazyOnload
|
||||
strategy: When the script will execute: afterInteractive (defer-like behavior) | beforeInteractive | lazyOnload (async-like behavior)
|
||||
style: The style of the component.
|
||||
key: A unique key for the component.
|
||||
id: The id for the component.
|
||||
|
Loading…
Reference in New Issue
Block a user