tag.py 2.1 KB

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