From 300b2488d508cbedd464e665eb36c275a999e75c Mon Sep 17 00:00:00 2001 From: Renee Vandervelde Date: Sat, 21 Sep 2024 11:13:28 -0500 Subject: [PATCH] Add Breadcrumbs in static renderer --- render-static-html/api/render-static-html.api | 4 ++++ .../ink/ui/render/statichtml/HtmlRenderer.kt | 1 + .../statichtml/renderer/BreadcrumbRenderer.kt | 16 +++++++++++++ sample-web/src/staticMain/header.inkui.kts | 6 +++++ structures/api/structures.api | 24 +++++++++++++++++++ .../structures/elements/BreadcrumbElement.kt | 10 ++++++++ 6 files changed, 61 insertions(+) create mode 100644 render-static-html/src/main/java/ink/ui/render/statichtml/renderer/BreadcrumbRenderer.kt create mode 100644 structures/src/commonMain/kotlin/ink/ui/structures/elements/BreadcrumbElement.kt diff --git a/render-static-html/api/render-static-html.api b/render-static-html/api/render-static-html.api index a0169e3..da6141f 100644 --- a/render-static-html/api/render-static-html.api +++ b/render-static-html/api/render-static-html.api @@ -62,6 +62,10 @@ public abstract class ink/ui/render/statichtml/PartialScript : ink/ui/render/sta public fun include (Ljava/lang/String;)V } +public final class ink/ui/render/statichtml/renderer/BreadcrumbRendererKt { + public static final fun getBreadcrumbRenderer ()Link/ui/render/statichtml/renderer/ElementRenderer; +} + public final class ink/ui/render/statichtml/renderer/DividerRendererKt { public static final fun getDividerRenderer ()Link/ui/render/statichtml/renderer/ElementRenderer; } diff --git a/render-static-html/src/main/java/ink/ui/render/statichtml/HtmlRenderer.kt b/render-static-html/src/main/java/ink/ui/render/statichtml/HtmlRenderer.kt index d2c3ab3..9889a38 100644 --- a/render-static-html/src/main/java/ink/ui/render/statichtml/HtmlRenderer.kt +++ b/render-static-html/src/main/java/ink/ui/render/statichtml/HtmlRenderer.kt @@ -23,6 +23,7 @@ class HtmlRenderer( TextRenderer, DividerRenderer, FormattedTextRenderer, + BreadcrumbRenderer, StatusRenderer(iconUrl), IconRenderer(iconUrl), LinkButtonRenderer(iconUrl) diff --git a/render-static-html/src/main/java/ink/ui/render/statichtml/renderer/BreadcrumbRenderer.kt b/render-static-html/src/main/java/ink/ui/render/statichtml/renderer/BreadcrumbRenderer.kt new file mode 100644 index 0000000..bcad36b --- /dev/null +++ b/render-static-html/src/main/java/ink/ui/render/statichtml/renderer/BreadcrumbRenderer.kt @@ -0,0 +1,16 @@ +package ink.ui.render.statichtml.renderer + +import ink.ui.structures.elements.BreadcrumbElement +import kotlinx.html.* + +val BreadcrumbRenderer = renderer { element -> + nav { + ul { + element.items.forEach { breadcrumb -> + li { + a(href = breadcrumb.url) { +breadcrumb.text } + } + } + } + } +} diff --git a/sample-web/src/staticMain/header.inkui.kts b/sample-web/src/staticMain/header.inkui.kts index a0a4bea..b82818c 100644 --- a/sample-web/src/staticMain/header.inkui.kts +++ b/sample-web/src/staticMain/header.inkui.kts @@ -1,3 +1,9 @@ addPageHeader(TextElement("Page Header", TextStyle.H1)) addPageHeader(TextElement("Subtitle")) +addPageHeader( + BreadcrumbElement(listOf( + BreadcrumbElement.Breadcrumb("Home", "#"), + BreadcrumbElement.Breadcrumb("Guide", "#guide"), + )) +) diff --git a/structures/api/structures.api b/structures/api/structures.api index 717d940..6614174 100644 --- a/structures/api/structures.api +++ b/structures/api/structures.api @@ -89,6 +89,30 @@ public final class ink/ui/structures/TextStyle : java/lang/Enum { public static fun values ()[Link/ui/structures/TextStyle; } +public final class ink/ui/structures/elements/BreadcrumbElement : ink/ui/structures/elements/UiElement$Static { + public fun (Ljava/util/List;)V + public final fun component1 ()Ljava/util/List; + public final fun copy (Ljava/util/List;)Link/ui/structures/elements/BreadcrumbElement; + public static synthetic fun copy$default (Link/ui/structures/elements/BreadcrumbElement;Ljava/util/List;ILjava/lang/Object;)Link/ui/structures/elements/BreadcrumbElement; + public fun equals (Ljava/lang/Object;)Z + public final fun getItems ()Ljava/util/List; + public fun hashCode ()I + public fun toString ()Ljava/lang/String; +} + +public final class ink/ui/structures/elements/BreadcrumbElement$Breadcrumb { + public fun (Ljava/lang/String;Ljava/lang/String;)V + public final fun component1 ()Ljava/lang/String; + public final fun component2 ()Ljava/lang/String; + public final fun copy (Ljava/lang/String;Ljava/lang/String;)Link/ui/structures/elements/BreadcrumbElement$Breadcrumb; + public static synthetic fun copy$default (Link/ui/structures/elements/BreadcrumbElement$Breadcrumb;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Link/ui/structures/elements/BreadcrumbElement$Breadcrumb; + public fun equals (Ljava/lang/Object;)Z + public final fun getText ()Ljava/lang/String; + public final fun getUrl ()Ljava/lang/String; + public fun hashCode ()I + public fun toString ()Ljava/lang/String; +} + public final class ink/ui/structures/elements/ButtonElement : ink/ui/structures/elements/UiElement$Interactive { public synthetic fun (Ljava/lang/String;Lkotlin/jvm/functions/Function0;Link/ui/structures/Sentiment;ZZLjava/lang/String;Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V public synthetic fun (Ljava/lang/String;Lkotlin/jvm/functions/Function0;Link/ui/structures/Sentiment;ZZLjava/lang/String;Ljava/lang/String;Lkotlin/jvm/internal/DefaultConstructorMarker;)V diff --git a/structures/src/commonMain/kotlin/ink/ui/structures/elements/BreadcrumbElement.kt b/structures/src/commonMain/kotlin/ink/ui/structures/elements/BreadcrumbElement.kt new file mode 100644 index 0000000..4653c43 --- /dev/null +++ b/structures/src/commonMain/kotlin/ink/ui/structures/elements/BreadcrumbElement.kt @@ -0,0 +1,10 @@ +package ink.ui.structures.elements + +data class BreadcrumbElement( + val items: List, +): UiElement.Static { + data class Breadcrumb( + val text: String, + val url: String, + ) +}