title.py 766 B

12345678910111213141516171819202122232425
  1. """Display the title of the current page."""
  2. from pynecone.components.base.bare import Bare
  3. from pynecone.components.component import Component
  4. from pynecone.components.tags import Tag
  5. class Title(Component):
  6. """A component that displays the title of the current page."""
  7. def _render(self) -> Tag:
  8. return Tag(name="title")
  9. def render(self) -> str:
  10. """Render the title component.
  11. Returns:
  12. The rendered title component.
  13. """
  14. tag = self._render()
  15. # Make sure the title is a single string.
  16. assert len(self.children) == 1 and isinstance(
  17. self.children[0], Bare
  18. ), "Title must be a single string."
  19. return str(tag.set(contents=str(self.children[0].contents)))