editable.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. """An editable component."""
  2. from __future__ import annotations
  3. from reflex.components.chakra import ChakraComponent
  4. from reflex.event import EventHandler
  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. # Fired when the Editable is changed.
  26. on_change: EventHandler[lambda e0: [e0]]
  27. # Fired when the Editable is in edit mode.
  28. on_edit: EventHandler[lambda e0: [e0]]
  29. # Fired when the Editable is submitted.
  30. on_submit: EventHandler[lambda e0: [e0]]
  31. # Fired when the Editable is canceled.
  32. on_cancel: EventHandler[lambda e0: [e0]]
  33. class EditableInput(ChakraComponent):
  34. """The edit view of the component. It shows when you click or focus on the text."""
  35. tag = "EditableInput"
  36. class EditableTextarea(ChakraComponent):
  37. """Use the textarea element to handle multi line text input in an editable context."""
  38. tag = "EditableTextarea"
  39. class EditablePreview(ChakraComponent):
  40. """The read-only view of the component."""
  41. tag = "EditablePreview"