textarea.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. """A textarea component."""
  2. from typing import Dict
  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) -> Dict[str, Var]:
  31. """Get the event triggers that pass the component's value to the handler.
  32. Returns:
  33. A dict mapping the event trigger to the var that is passed to the handler.
  34. """
  35. return {
  36. "on_change": EVENT_ARG.target.value,
  37. "on_focus": EVENT_ARG.target.value,
  38. "on_blur": EVENT_ARG.target.value,
  39. "on_key_down": EVENT_ARG.key,
  40. "on_key_up": EVENT_ARG.key,
  41. }