editable.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. """An editable component."""
  2. from typing import Set
  3. from pynecone.components.libs.chakra import ChakraComponent
  4. from pynecone.var import Var
  5. class Editable(ChakraComponent):
  6. """The wrapper component that provides context value."""
  7. tag = "Editable"
  8. # If true, the Editable will be disabled.
  9. is_disabled: Var[bool]
  10. # If true, the read only view, has a tabIndex set to 0 so it can receive focus via the keyboard or click.
  11. is_preview_focusable: Var[bool]
  12. # The placeholder text when the value is empty.
  13. placeholder: Var[str]
  14. # If true, the input's text will be highlighted on focus.
  15. select_all_on_focus: Var[bool]
  16. # If true, the Editable will start with edit mode by default.
  17. start_with_edit_view: Var[bool]
  18. # If true, it'll update the value onBlur and turn off the edit mode.
  19. submit_on_blur: Var[bool]
  20. # The value of the Editable in both edit & preview mode
  21. value: Var[str]
  22. # The initial value of the Editable in both edit and preview mode.
  23. default_value: Var[str]
  24. @classmethod
  25. def get_controlled_triggers(cls) -> Set[str]:
  26. """Get the event triggers that pass the component's value to the handler.
  27. Returns:
  28. The controlled event triggers.
  29. """
  30. return {
  31. "on_change",
  32. "on_edit",
  33. "on_submit",
  34. "on_cancel",
  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"