diff options
author | Robert Jaros <rjaros@finn.pl> | 2018-02-12 10:50:42 +0100 |
---|---|---|
committer | Robert Jaros <rjaros@finn.pl> | 2018-02-12 10:50:42 +0100 |
commit | bafcdb6fc3f1d4ec4f1a0f4fcce776ba10d8136c (patch) | |
tree | 39288bdcb59ec48cb70f1c5820fc1854949744da /src/main/kotlin/pl/treksoft/kvision/html/Link.kt | |
parent | 2feea5e7cf8d492663e826ebcfb0a58e61820352 (diff) | |
download | kvision-bafcdb6fc3f1d4ec4f1a0f4fcce776ba10d8136c.tar.gz kvision-bafcdb6fc3f1d4ec4f1a0f4fcce776ba10d8136c.tar.bz2 kvision-bafcdb6fc3f1d4ec4f1a0f4fcce776ba10d8136c.zip |
Type safe DSL builders
Diffstat (limited to 'src/main/kotlin/pl/treksoft/kvision/html/Link.kt')
-rw-r--r-- | src/main/kotlin/pl/treksoft/kvision/html/Link.kt | 15 |
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) }) + } + } } |