button.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. """A button component."""
  2. from typing import List, Optional
  3. from reflex.components.chakra import (
  4. ChakraComponent,
  5. LiteralButtonSize,
  6. LiteralButtonVariant,
  7. LiteralColorScheme,
  8. LiteralSpinnerPlacement,
  9. )
  10. from reflex.vars import Var
  11. class Button(ChakraComponent):
  12. """The Button component is used to trigger an event or event, such as submitting a form, opening a dialog, canceling an event, or performing a delete operation."""
  13. tag = "Button"
  14. # The space between the button icon and label.
  15. icon_spacing: Optional[Var[int]] = None
  16. # If true, the button will be styled in its active state.
  17. is_active: Optional[Var[bool]] = None
  18. # If true, the button will be styled in its disabled state.
  19. is_disabled: Optional[Var[bool]] = None
  20. # If true, the button will take up the full width of its container.
  21. is_full_width: Optional[Var[bool]] = None
  22. # If true, the button will show a spinner.
  23. is_loading: Optional[Var[bool]] = None
  24. # The label to show in the button when isLoading is true If no text is passed, it only shows the spinner.
  25. loading_text: Optional[Var[str]] = None
  26. # "lg" | "md" | "sm" | "xs"
  27. size: Optional[Var[LiteralButtonSize]] = None
  28. # "ghost" | "outline" | "solid" | "link" | "unstyled"
  29. variant: Optional[Var[LiteralButtonVariant]] = None
  30. # Built in color scheme for ease of use.
  31. # Options:
  32. # "whiteAlpha" | "blackAlpha" | "gray" | "red" | "orange" | "yellow" | "green" | "teal" | "blue" | "cyan"
  33. # | "purple" | "pink" | "linkedin" | "facebook" | "messenger" | "whatsapp" | "twitter" | "telegram"
  34. color_scheme: Optional[Var[LiteralColorScheme]] = None
  35. # Position of the loading spinner.
  36. # Options:
  37. # "start" | "end"
  38. spinner_placement: Optional[Var[LiteralSpinnerPlacement]] = None
  39. # The type of button.
  40. type_: Optional[Var[str]] = None
  41. # Components that are not allowed as children.
  42. _invalid_children: List[str] = ["Button", "MenuButton"]
  43. # The name of the form field
  44. name: Optional[Var[str]] = None
  45. class ButtonGroup(ChakraComponent):
  46. """A group of buttons."""
  47. tag = "ButtonGroup"
  48. # If true, the borderRadius of button that are direct children will be altered to look flushed together.
  49. is_attached: Optional[Var[bool]] = None
  50. # If true, all wrapped button will be disabled.
  51. is_disabled: Optional[Var[bool]] = None
  52. # The spacing between the buttons.
  53. spacing: Optional[Var[int]] = None
  54. # "lg" | "md" | "sm" | "xs"
  55. size: Optional[Var[LiteralButtonSize]] = None
  56. # "ghost" | "outline" | "solid" | "link" | "unstyled"
  57. variant: Optional[Var[LiteralButtonVariant]] = None