aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/pl/treksoft/kvision/html/Link.kt
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin/pl/treksoft/kvision/html/Link.kt')
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/html/Link.kt15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/html/Link.kt b/src/main/kotlin/pl/treksoft/kvision/html/Link.kt
index ad8897d5..7572d444 100644
--- a/src/main/kotlin/pl/treksoft/kvision/html/Link.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/html/Link.kt
@@ -22,6 +22,7 @@
package pl.treksoft.kvision.html
import com.github.snabbdom.VNode
+import pl.treksoft.kvision.core.Container
import pl.treksoft.kvision.core.ResString
import pl.treksoft.kvision.core.StringPair
import pl.treksoft.kvision.panel.SimplePanel
@@ -81,4 +82,18 @@ open class Link(
override fun getSnAttrs(): List<StringPair> {
return super.getSnAttrs() + ("href" to url)
}
+
+ companion object {
+ /**
+ * DSL builder extension function
+ *
+ * It takes the same parameters as the constructor of the built component.
+ */
+ fun Container.link(
+ label: String, url: String, icon: String? = null, image: ResString? = null,
+ classes: Set<String> = setOf(), init: (Link.() -> Unit)? = null
+ ) {
+ this.add(Link(label, url, icon, image, classes).apply { init?.invoke(this) })
+ }
+ }
}