tooltip.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. """Tooltip components."""
  2. from __future__ import annotations
  3. from typing import Any, Union
  4. from reflex.components.libs.chakra import ChakraComponent, LiteralChakraDirection
  5. from reflex.vars import Var
  6. class Tooltip(ChakraComponent):
  7. """A tooltip message to appear."""
  8. tag = "Tooltip"
  9. # The padding required to prevent the arrow from reaching the very edge of the popper.
  10. arrow_padding: Var[int]
  11. # The color of the arrow shadow.
  12. arrow_shadow_color: Var[str]
  13. # Size of the arrow.
  14. arrow_size: Var[int]
  15. # Delay (in ms) before hiding the tooltip
  16. delay: Var[int]
  17. # If true, the tooltip will hide on click
  18. close_on_click: Var[bool]
  19. # If true, the tooltip will hide on pressing Esc key
  20. close_on_esc: Var[bool]
  21. # If true, the tooltip will hide while the mouse is down
  22. close_on_mouse_down: Var[bool]
  23. # If true, the tooltip will be initially shown
  24. default_is_open: Var[bool]
  25. # Theme direction ltr or rtl. Popper's placement will be set accordingly
  26. direction: Var[LiteralChakraDirection]
  27. # The distance or margin between the reference and popper. It is used internally to create an offset modifier. NB: If you define offset prop, it'll override the gutter.
  28. gutter: Var[int]
  29. # If true, the tooltip will show an arrow tip
  30. has_arrow: Var[bool]
  31. # If true, the tooltip with be disabled.
  32. is_disabled: Var[bool]
  33. # If true, the tooltip will be open.
  34. is_open: Var[bool]
  35. # The label of the tooltip
  36. label: Var[str]
  37. # Delay (in ms) before showing the tooltip
  38. open_delay: Var[int]
  39. # The placement of the popper relative to its reference.
  40. placement: Var[str]
  41. # If true, the tooltip will wrap its children in a `<span/>` with `tabIndex=0`
  42. should_wrap_children: Var[bool]
  43. def get_event_triggers(self) -> dict[str, Union[Var, Any]]:
  44. """Get the event triggers for the component.
  45. Returns:
  46. The event triggers.
  47. """
  48. return {
  49. **super().get_event_triggers(),
  50. "on_close": lambda: [],
  51. "on_open": lambda: [],
  52. }