input.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. """An input 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 Input(ChakraComponent):
  7. """The Input component is a component that is used to get user input in a text field."""
  8. tag = "Input"
  9. # State var to bind the the input.
  10. value: Var[str]
  11. # The default value of the input.
  12. default_value: Var[str]
  13. # The placeholder text.
  14. placeholder: Var[str]
  15. # The type of input.
  16. type_: Var[str] = "text" # type: ignore
  17. # The border color when the input is invalid.
  18. error_border_color: Var[str]
  19. # The border color when the input is focused.
  20. focus_border_color: Var[str]
  21. # If true, the form control will be disabled. This has 2 side effects - The FormLabel will have `data-disabled` attribute - The form element (e.g, Input) will be disabled
  22. is_disabled: Var[bool]
  23. # If true, the form control will be invalid. This has 2 side effects - The FormLabel and FormErrorIcon will have `data-invalid` set to true - The form element (e.g, Input) will have `aria-invalid` set to true
  24. is_invalid: Var[bool]
  25. # If true, the form control will be readonly.
  26. is_read_only: Var[bool]
  27. # If true, the form control will be required. This has 2 side effects - The FormLabel will show a required indicator - The form element (e.g, Input) will have `aria-required` set to true
  28. is_required: Var[bool]
  29. # "outline" | "filled" | "flushed" | "unstyled"
  30. variant: Var[str]
  31. # "lg" | "md" | "sm" | "xs"
  32. size: Var[str]
  33. @classmethod
  34. def get_controlled_triggers(cls) -> Dict[str, Var]:
  35. """Get the event triggers that pass the component's value to the handler.
  36. Returns:
  37. A dict mapping the event trigger to the var that is passed to the handler.
  38. """
  39. return {
  40. "on_change": EVENT_ARG.target.value,
  41. "on_focus": EVENT_ARG.target.value,
  42. "on_blur": EVENT_ARG.target.value,
  43. "on_key_down": EVENT_ARG.key,
  44. "on_key_up": EVENT_ARG.key,
  45. }
  46. class InputGroup(ChakraComponent):
  47. """The InputGroup component is a component that is used to group a set of inputs."""
  48. tag = "InputGroup"
  49. class InputLeftAddon(ChakraComponent):
  50. """The InputLeftAddon component is a component that is used to add an addon to the left of an input."""
  51. tag = "InputLeftAddon"
  52. class InputRightAddon(ChakraComponent):
  53. """The InputRightAddon component is a component that is used to add an addon to the right of an input."""
  54. tag = "InputRightAddon"