editable.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. """An editable component."""
  2. from typing import Dict
  3. from reflex.components.libs.chakra import ChakraComponent
  4. from reflex.event import EVENT_ARG
  5. from reflex.vars import Var
  6. class Editable(ChakraComponent):
  7. """The wrapper component that provides context value."""
  8. tag = "Editable"
  9. # If true, the Editable will be disabled.
  10. is_disabled: Var[bool]
  11. # If true, the read only view, has a tabIndex set to 0 so it can receive focus via the keyboard or click.
  12. is_preview_focusable: Var[bool]
  13. # The placeholder text when the value is empty.
  14. placeholder: Var[str]
  15. # If true, the input's text will be highlighted on focus.
  16. select_all_on_focus: Var[bool]
  17. # If true, the Editable will start with edit mode by default.
  18. start_with_edit_view: Var[bool]
  19. # If true, it'll update the value onBlur and turn off the edit mode.
  20. submit_on_blur: Var[bool]
  21. # The value of the Editable in both edit & preview mode
  22. value: Var[str]
  23. # The initial value of the Editable in both edit and preview mode.
  24. default_value: Var[str]
  25. def get_controlled_triggers(self) -> Dict[str, Var]:
  26. """Get the event triggers that pass the component's value to the handler.
  27. Returns:
  28. A dict mapping the event trigger to the var that is passed to the handler.
  29. """
  30. return {
  31. "on_change": EVENT_ARG,
  32. "on_edit": EVENT_ARG,
  33. "on_submit": EVENT_ARG,
  34. "on_cancel": EVENT_ARG,
  35. }
  36. class EditableInput(ChakraComponent):
  37. """The edit view of the component. It shows when you click or focus on the text."""
  38. tag = "EditableInput"
  39. class EditableTextarea(ChakraComponent):
  40. """Use the textarea element to handle multi line text input in an editable context."""
  41. tag = "EditableTextarea"
  42. class EditablePreview(ChakraComponent):
  43. """The read-only view of the component."""
  44. tag = "EditablePreview"