__init__.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. """Namespace for experimental features."""
  2. from types import SimpleNamespace
  3. from reflex.components.props import PropsBase
  4. from reflex.components.radix.themes.components.progress import progress as progress
  5. from reflex.components.sonner.toast import toast as toast
  6. from ..utils.console import warn
  7. from . import hooks as hooks
  8. from .assets import asset as asset
  9. from .client_state import ClientStateVar as ClientStateVar
  10. from .layout import layout as layout
  11. from .misc import run_in_thread as run_in_thread
  12. warn(
  13. "`rx._x` contains experimental features and might be removed at any time in the future .",
  14. )
  15. _EMITTED_PROMOTION_WARNINGS = set()
  16. class ExperimentalNamespace(SimpleNamespace):
  17. """Namespace for experimental features."""
  18. @property
  19. def toast(self):
  20. """Temporary property returning the toast namespace.
  21. Remove this property when toast is fully promoted.
  22. Returns:
  23. The toast namespace.
  24. """
  25. self.register_component_warning("toast")
  26. return toast
  27. @property
  28. def progress(self):
  29. """Temporary property returning the toast namespace.
  30. Remove this property when toast is fully promoted.
  31. Returns:
  32. The toast namespace.
  33. """
  34. self.register_component_warning("progress")
  35. return progress
  36. @staticmethod
  37. def register_component_warning(component_name: str):
  38. """Add component to emitted warnings and throw a warning if it
  39. doesn't exist.
  40. Args:
  41. component_name: name of the component.
  42. """
  43. if component_name not in _EMITTED_PROMOTION_WARNINGS:
  44. _EMITTED_PROMOTION_WARNINGS.add(component_name)
  45. warn(f"`rx._x.{component_name}` was promoted to `rx.{component_name}`.")
  46. _x = ExperimentalNamespace(
  47. asset=asset,
  48. client_state=ClientStateVar.create,
  49. hooks=hooks,
  50. layout=layout,
  51. PropsBase=PropsBase,
  52. run_in_thread=run_in_thread,
  53. )