__init__.py 2.9 KB

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