__init__.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 ..utils.misc import run_in_thread
  9. from . import hooks as hooks
  10. from .client_state import ClientStateVar as ClientStateVar
  11. from .layout import layout as layout
  12. class ExperimentalNamespace(SimpleNamespace):
  13. """Namespace for experimental features."""
  14. def __getattribute__(self, item: str):
  15. """Get attribute from the namespace.
  16. Args:
  17. item: attribute name.
  18. Returns:
  19. The attribute.
  20. """
  21. warn(
  22. "`rx._x` contains experimental features and might be removed at any time in the future.",
  23. dedupe=True,
  24. )
  25. return super().__getattribute__(item)
  26. @property
  27. def toast(self):
  28. """Temporary property returning the toast namespace.
  29. Remove this property when toast is fully promoted.
  30. Returns:
  31. The toast namespace.
  32. """
  33. self.register_component_warning("toast")
  34. return toast
  35. @property
  36. def progress(self):
  37. """Temporary property returning the progress component.
  38. Remove this property when progress is fully promoted.
  39. Returns:
  40. The progress component.
  41. """
  42. self.register_component_warning("progress")
  43. return progress
  44. @property
  45. def run_in_thread(self):
  46. """Temporary property returning the run_in_thread helper function.
  47. Remove this property when run_in_thread is fully promoted.
  48. Returns:
  49. The run_in_thread helper function.
  50. """
  51. self.register_component_warning("run_in_thread")
  52. return run_in_thread
  53. @staticmethod
  54. def register_component_warning(component_name: str):
  55. """Add component to emitted warnings and throw a warning if it
  56. doesn't exist.
  57. Args:
  58. component_name: name of the component.
  59. """
  60. warn(
  61. f"`rx._x.{component_name}` was promoted to `rx.{component_name}`.",
  62. dedupe=True,
  63. )
  64. _x = ExperimentalNamespace(
  65. client_state=ClientStateVar.create,
  66. hooks=hooks,
  67. layout=layout,
  68. PropsBase=PropsBase,
  69. code_block=code_block,
  70. )