button.py 2.5 KB

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