textarea.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. """A textarea component."""
  2. from typing import Set
  3. from pynecone.components.component import EVENT_ARG
  4. from pynecone.components.libs.chakra import ChakraComponent
  5. from pynecone.var import Var
  6. class TextArea(ChakraComponent):
  7. """A text area component."""
  8. tag = "Textarea"
  9. # State var to bind the the input.
  10. value: Var[str]
  11. # The default value of the textarea.
  12. default_value: Var[str]
  13. # The placeholder text.
  14. placeholder: Var[str]
  15. # The border color when the input is invalid.
  16. error_border_color: Var[str]
  17. # The border color when the input is focused.
  18. focus_border_color: Var[str]
  19. # If true, the form control will be disabled.
  20. is_disabled: Var[bool]
  21. # If true, the form control will be invalid.
  22. is_invalid: Var[bool]
  23. # If true, the form control will be readonly.
  24. is_read_only: Var[bool]
  25. # If true, the form control will be required.
  26. is_required: Var[bool]
  27. # "outline" | "filled" | "flushed" | "unstyled"
  28. variant: Var[str]
  29. @classmethod
  30. def get_controlled_triggers(cls) -> Set[str]:
  31. """Get the event triggers that pass the component's value to the handler.
  32. Returns:
  33. The controlled event triggers.
  34. """
  35. return {"on_change", "on_focus", "on_blur"}
  36. @classmethod
  37. def get_controlled_value(cls) -> Var:
  38. """Get the var that is passed to the event handler for controlled triggers.
  39. Returns:
  40. The controlled value.
  41. """
  42. return EVENT_ARG.target.value