Falko Schindler преди 2 години
родител
ревизия
7c71e13db5
променени са 2 файла, в които са добавени 18 реда и са изтрити 1 реда
  1. 17 0
      nicegui/elements/link.py
  2. 1 1
      nicegui/ui.py

+ 17 - 0
nicegui/elements/link.py

@@ -3,6 +3,7 @@ from typing import Callable, Union
 import justpy as jp
 
 from .. import globals
+from .element import Element
 from .group import Group
 
 
@@ -13,6 +14,9 @@ class Link(Group):
 
         Create a hyperlink.
 
+        To jump to a specific location within a page you can place linkable anchors with `ui.link_target("name")`
+        and link to it with `ui.link(target="#name")`.
+
         :param text: display text
         :param target: page function or string that is a an absolute URL or relative path from base URL
         """
@@ -20,3 +24,16 @@ class Link(Group):
         view = jp.A(text=text, href=href, classes='underline text-blue', temp=False)
 
         super().__init__(view)
+
+
+class LinkTarget(Element):
+
+    def __init__(self, name: str) -> None:
+        """Link target
+
+        Create an anchor tag that can be used as inner-page target for links.
+
+        :param name: target name
+        """
+        view = jp.A(name=name, temp=False)
+        super().__init__(view)

+ 1 - 1
nicegui/ui.py

@@ -32,7 +32,7 @@ class Ui:
     from .elements.joystick import Joystick as joystick
     from .elements.keyboard import Keyboard as keyboard
     from .elements.label import Label as label
-    from .elements.link import Link as link
+    from .elements.link import Link as link, LinkTarget as link_target
     from .elements.log import Log as log
     from .elements.markdown import Markdown as markdown
     from .elements.menu import Menu as menu