react_player.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. """React-Player component."""
  2. from __future__ import annotations
  3. from typing import Optional
  4. from pynecone.components.component import Component
  5. from pynecone.utils import imports
  6. from pynecone.vars import Var
  7. class ReactPlayerComponent(Component):
  8. """Using react-player and not implement all props and callback yet.
  9. reference: https://github.com/cookpete/react-player.
  10. """
  11. library = "react-player"
  12. tag = "ReactPlayer"
  13. # The url of a video or song to play
  14. url: Var[str]
  15. # Set to true or false to pause or play the media
  16. playing: Var[str]
  17. # Set to true or false to loop the media
  18. loop: Var[bool]
  19. # Set to true or false to display native player controls.
  20. controls: Var[bool] = True # type: ignore
  21. # Set to true to show just the video thumbnail, which loads the full player on click
  22. light: Var[bool]
  23. # Set the volume of the player, between 0 and 1
  24. volume: Var[float]
  25. # Mutes the player
  26. muted: Var[bool]
  27. # Set the width of the player: ex:640px
  28. width: Var[str]
  29. # Set the height of the player: ex:640px
  30. height: Var[str]
  31. def _get_imports(self) -> Optional[imports.ImportDict]:
  32. return {}
  33. def _get_custom_code(self) -> Optional[str]:
  34. return """
  35. import dynamic from "next/dynamic";
  36. const ReactPlayer = dynamic(() => import("react-player/lazy"), { ssr: false });
  37. """