responsive.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. """Responsive components."""
  2. from reflex.components.radix.themes.layout.box import Box
  3. # Add responsive styles shortcuts.
  4. def mobile_only(*children, **props):
  5. """Create a component that is only visible on mobile.
  6. Args:
  7. *children: The children to pass to the component.
  8. **props: The props to pass to the component.
  9. Returns:
  10. The component.
  11. """
  12. return Box.create(*children, **props, display=["block", "none", "none", "none"])
  13. def tablet_only(*children, **props):
  14. """Create a component that is only visible on tablet.
  15. Args:
  16. *children: The children to pass to the component.
  17. **props: The props to pass to the component.
  18. Returns:
  19. The component.
  20. """
  21. return Box.create(*children, **props, display=["none", "block", "block", "none"])
  22. def desktop_only(*children, **props):
  23. """Create a component that is only visible on desktop.
  24. Args:
  25. *children: The children to pass to the component.
  26. **props: The props to pass to the component.
  27. Returns:
  28. The component.
  29. """
  30. return Box.create(*children, **props, display=["none", "none", "none", "block"])
  31. def tablet_and_desktop(*children, **props):
  32. """Create a component that is only visible on tablet and desktop.
  33. Args:
  34. *children: The children to pass to the component.
  35. **props: The props to pass to the component.
  36. Returns:
  37. The component.
  38. """
  39. return Box.create(*children, **props, display=["none", "block", "block", "block"])
  40. def mobile_and_tablet(*children, **props):
  41. """Create a component that is only visible on mobile and tablet.
  42. Args:
  43. *children: The children to pass to the component.
  44. **props: The props to pass to the component.
  45. Returns:
  46. The component.
  47. """
  48. return Box.create(*children, **props, display=["block", "block", "block", "none"])