editable.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. """An editable component."""
  2. from typing import Set
  3. from pynecone.components.libs.chakra import ChakraComponent
  4. from pynecone.components.tags import Tag
  5. from pynecone.var 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. @classmethod
  26. def get_controlled_triggers(cls) -> Set[str]:
  27. """Get the event triggers that pass the component's value to the handler.
  28. Returns:
  29. The controlled event triggers.
  30. """
  31. return {
  32. "on_change",
  33. "on_edit",
  34. "on_submit",
  35. "on_cancel",
  36. }
  37. class EditableInput(ChakraComponent):
  38. """The edit view of the component. It shows when you click or focus on the text."""
  39. tag = "EditableInput"
  40. class EditableTextarea(ChakraComponent):
  41. """Use the textarea element to handle multi line text input in an editable context."""
  42. tag = "EditableTextarea"
  43. class EditablePreview(ChakraComponent):
  44. """The read-only view of the component."""
  45. tag = "EditablePreview"