tag.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. """Chakra Tag Component."""
  2. from typing import Optional
  3. from reflex.components.component import Component
  4. from reflex.components.libs.chakra import (
  5. ChakraComponent,
  6. LiteralTagColorScheme,
  7. LiteralTagSize,
  8. LiteralVariant,
  9. )
  10. from reflex.vars import Var
  11. class TagLabel(ChakraComponent):
  12. """The label of the tag."""
  13. tag = "TagLabel"
  14. class TagLeftIcon(ChakraComponent):
  15. """The left icon of the tag."""
  16. tag = "TagLeftIcon"
  17. class TagRightIcon(ChakraComponent):
  18. """The right icon of the tag."""
  19. tag = "TagRightIcon"
  20. class TagCloseButton(ChakraComponent):
  21. """The close button of the tag."""
  22. tag = "TagCloseButton"
  23. class Tag(ChakraComponent):
  24. """The parent wrapper that provides context for its children."""
  25. tag = "Tag"
  26. # The visual color appearance of the tag.
  27. # options: "gray" | "red" | "orange" | "yellow" | "green" | "teal" | "blue" |
  28. # "cyan" | "purple" | "pink"
  29. # default: "gray"
  30. color_scheme: Var[LiteralTagColorScheme]
  31. # The size of the tag
  32. # options: "sm" | "md" | "lg"
  33. # default: "md"
  34. size: Var[LiteralTagSize]
  35. # The variant of the tag
  36. # options: "solid" | "subtle" | "outline"
  37. # default: "solid"
  38. variant: Var[LiteralVariant]
  39. @classmethod
  40. def create(
  41. cls,
  42. label: Component,
  43. *,
  44. left_icon: Optional[Component] = None,
  45. right_icon: Optional[Component] = None,
  46. close_button: Optional[Component] = None,
  47. **props,
  48. ) -> Component:
  49. """Creates a Chakra Tag with a label and optionally left_icon, right_icon, and close_button, and returns it.
  50. Args:
  51. label (Component): The label of the Tag that will be created.
  52. left_icon (Optional[Component]): Should be a rx.TagLeftIcon instance.
  53. right_icon (Optional[Component]): Should be a rx.TagRightIcon instance.
  54. close_button (Optional[Component]): Should be a rx.TagCloseButton instance.
  55. props: The properties to be passed to the component.
  56. Returns:
  57. The `create()` method returns a Tag object.
  58. """
  59. children = [
  60. x for x in (left_icon, label, right_icon, close_button) if x is not None
  61. ]
  62. return super().create(*children, **props)