textarea.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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.vars import Var
  6. class TextArea(ChakraComponent):
  7. """A text area component."""
  8. tag = "Textarea"
  9. # State var to bind 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. def get_controlled_triggers(self) -> Dict[str, Var]:
  30. """Get the event triggers that pass the component's value to the handler.
  31. Returns:
  32. A dict mapping the event trigger to the var that is passed to the handler.
  33. """
  34. return {
  35. "on_change": EVENT_ARG.target.value,
  36. "on_focus": EVENT_ARG.target.value,
  37. "on_blur": EVENT_ARG.target.value,
  38. "on_key_down": EVENT_ARG.key,
  39. "on_key_up": EVENT_ARG.key,
  40. }