__init__.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. 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 toast namespace.
  38. Remove this property when toast is fully promoted.
  39. Returns:
  40. The toast namespace.
  41. """
  42. self.register_component_warning("progress")
  43. return progress
  44. @staticmethod
  45. def register_component_warning(component_name: str):
  46. """Add component to emitted warnings and throw a warning if it
  47. doesn't exist.
  48. Args:
  49. component_name: name of the component.
  50. """
  51. warn(
  52. f"`rx._x.{component_name}` was promoted to `rx.{component_name}`.",
  53. dedupe=True,
  54. )
  55. _x = ExperimentalNamespace(
  56. client_state=ClientStateVar.create,
  57. hooks=hooks,
  58. layout=layout,
  59. PropsBase=PropsBase,
  60. run_in_thread=run_in_thread,
  61. code_block=code_block,
  62. )