checkbox.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. """A checkbox component."""
  2. from __future__ import annotations
  3. from reflex.components.chakra import (
  4. ChakraComponent,
  5. LiteralColorScheme,
  6. LiteralTagSize,
  7. )
  8. from reflex.event import EventHandler
  9. from reflex.vars import Var
  10. class Checkbox(ChakraComponent):
  11. """The Checkbox component is used in forms when a user needs to select multiple values from several options."""
  12. tag = "Checkbox"
  13. # Color scheme for checkbox.
  14. # Options:
  15. # "whiteAlpha" | "blackAlpha" | "gray" | "red" | "orange" | "yellow" | "green" | "teal" | "blue" | "cyan"
  16. # | "purple" | "pink" | "linkedin" | "facebook" | "messenger" | "whatsapp" | "twitter" | "telegram"
  17. color_scheme: Var[LiteralColorScheme]
  18. # "sm" | "md" | "lg"
  19. size: Var[LiteralTagSize]
  20. # If true, the checkbox will be checked.
  21. is_checked: Var[bool]
  22. # If true, the checkbox will be disabled
  23. is_disabled: Var[bool]
  24. # If true and is_disabled is passed, the checkbox will remain tabbable but not interactive
  25. is_focusable: Var[bool]
  26. # If true, the checkbox will be indeterminate. This only affects the icon shown inside checkbox and does not modify the is_checked var.
  27. is_indeterminate: Var[bool]
  28. # If true, the checkbox is marked as invalid. Changes style of unchecked state.
  29. is_invalid: Var[bool]
  30. # If true, the checkbox will be readonly
  31. is_read_only: Var[bool]
  32. # If true, the checkbox input is marked as required, and required attribute will be added
  33. is_required: Var[bool]
  34. # The name of the input field in a checkbox (Useful for form submission).
  35. name: Var[str]
  36. # The value of the input field when checked (use is_checked prop for a bool)
  37. value: Var[str] = Var.create("true", _var_is_string=True) # type: ignore
  38. # The spacing between the checkbox and its label text (0.5rem)
  39. spacing: Var[str]
  40. # Fired when the checkbox is checked or unchecked
  41. on_change: EventHandler[lambda e0: [e0.target.checked]]
  42. class CheckboxGroup(ChakraComponent):
  43. """A group of checkboxes."""
  44. tag = "CheckboxGroup"
  45. # The value of the checkbox group
  46. value: Var[str]
  47. # The initial value of the checkbox group
  48. default_value: Var[str]
  49. # If true, all wrapped checkbox inputs will be disabled
  50. is_disabled: Var[bool]
  51. # If true, input elements will receive checked attribute instead of isChecked. This assumes, you're using native radio inputs
  52. is_native: Var[bool]