__init__.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. """Import all the components."""
  2. from pynecone import utils
  3. from pynecone.event import EventSpec
  4. from pynecone.var import Var
  5. from .component import Component
  6. from .datadisplay import *
  7. from .disclosure import *
  8. from .feedback import *
  9. from .forms import *
  10. from .graphing import *
  11. from .layout import *
  12. from .media import *
  13. from .navigation import *
  14. from .overlay import *
  15. from .typography import *
  16. # Add the convenience methods for all the components.
  17. locals().update(
  18. {
  19. utils.to_snake_case(name): value.create
  20. for name, value in locals().items()
  21. if isinstance(value, type) and issubclass(value, Component)
  22. }
  23. )
  24. # Add responsive styles shortcuts.
  25. def mobile_only(*children, **props):
  26. """Create a component that is only visible on mobile.
  27. Args:
  28. *children: The children to pass to the component.
  29. **props: The props to pass to the component.
  30. Returns:
  31. The component.
  32. """
  33. return Box.create(*children, **props, display=["block", "none", "none", "none"])
  34. def tablet_only(*children, **props):
  35. """Create a component that is only visible on tablet.
  36. Args:
  37. *children: The children to pass to the component.
  38. **props: The props to pass to the component.
  39. Returns:
  40. The component.
  41. """
  42. return Box.create(*children, **props, display=["none", "block", "block", "none"])
  43. def desktop_only(*children, **props):
  44. """Create a component that is only visible on desktop.
  45. Args:
  46. *children: The children to pass to the component.
  47. **props: The props to pass to the component.
  48. Returns:
  49. The component.
  50. """
  51. return Box.create(*children, **props, display=["none", "none", "none", "block"])
  52. def tablet_and_desktop(*children, **props):
  53. """Create a component that is only visible on tablet and desktop.
  54. Args:
  55. *children: The children to pass to the component.
  56. **props: The props to pass to the component.
  57. Returns:
  58. The component.
  59. """
  60. return Box.create(*children, **props, display=["none", "block", "block", "block"])
  61. def mobile_and_tablet(*children, **props):
  62. """Create a component that is only visible on mobile and tablet.
  63. Args:
  64. *children: The children to pass to the component.
  65. **props: The props to pass to the component.
  66. Returns:
  67. The component.
  68. """
  69. return Box.create(*children, **props, display=["block", "block", "block", "none"])