123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- """Breadcrumb components."""
- from typing import Optional
- from reflex.components.chakra import ChakraComponent
- from reflex.components.chakra.navigation.link import Link
- from reflex.components.component import Component
- from reflex.components.core.foreach import Foreach
- from reflex.vars import Var
- class Breadcrumb(ChakraComponent):
- """The parent container for breadcrumbs."""
- tag = "Breadcrumb"
- # The visual separator between each breadcrumb item
- separator: Optional[Var[str]] = None
- # The left and right margin applied to the separator
- separator_margin: Optional[Var[str]] = None
- @classmethod
- def create(cls, *children, items=None, **props) -> Component:
- """Create a breadcrumb component.
- If the kw-args `items` is provided and is a list, they will be added as children.
- Args:
- *children: The children of the component.
- items (list): The items of the breadcrumb: (label, link)
- **props: The properties of the component.
- Returns:
- The breadcrumb component.
- """
- if len(children) == 0:
- if isinstance(items, Var):
- children = [
- Foreach.create(
- items,
- lambda item: BreadcrumbItem.create(label=item[0], href=item[1]),
- ),
- ]
- else:
- children = []
- for label, link in items or []:
- children.append(BreadcrumbItem.create(label=label, href=link))
- return super().create(*children, **props)
- class BreadcrumbItem(ChakraComponent):
- """Individual breadcrumb element containing a link and a divider."""
- tag = "BreadcrumbItem"
- # Is the current page of the breadcrumb.
- is_current_page: Optional[Var[bool]] = None
- # Is the last child of the breadcrumb.
- is_last_child: Optional[Var[bool]] = None
- # The visual separator between each breadcrumb item
- separator: Optional[Var[str]] = None
- # The left and right margin applied to the separator
- spacing: Optional[Var[str]] = None
- @classmethod
- def create(cls, *children, label=None, href=None, **props):
- """Create a Breadcrumb Item component.
- Args:
- *children: The children of the component.
- label: The label used in the link. Defaults to None.
- href: The URL of the link. Defaults to None.
- **props: The properties of the component.
- Returns:
- The BreadcrumbItem component
- """
- if len(children) == 0:
- children = [BreadcrumbLink.create(label or "", href=href or "")] # type: ignore
- return super().create(*children, **props)
- class BreadcrumbSeparator(ChakraComponent):
- """The visual separator between each breadcrumb."""
- tag = "BreadcrumbSeparator"
- class BreadcrumbLink(Link):
- """The breadcrumb link."""
- tag = "BreadcrumbLink"
- # Is the current page of the breadcrumb.
- is_current_page: Optional[Var[bool]] = None
|