__init__.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. """Namespace for experimental features."""
  2. from types import SimpleNamespace
  3. from reflex.components.datadisplay.shiki_code_block import code_block as code_block
  4. from reflex.components.props import PropsBase
  5. from reflex.components.radix.themes.components.progress import progress as progress
  6. from reflex.components.sonner.toast import toast as toast
  7. from ..utils.console import warn
  8. from . import hooks as hooks
  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. client_state=ClientStateVar.create,
  48. hooks=hooks,
  49. layout=layout,
  50. PropsBase=PropsBase,
  51. run_in_thread=run_in_thread,
  52. code_block=code_block,
  53. )