aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/pl/treksoft/kvision/table
diff options
context:
space:
mode:
authorRobert Jaros <rjaros@finn.pl>2019-10-03 19:03:21 +0200
committerRobert Jaros <rjaros@finn.pl>2019-10-03 19:03:21 +0200
commit6b53324c97bfc80ed14dfca6a5dbc879950715b9 (patch)
tree55c7bb7d06e37470795a93e1f542e51ef3f1ace6 /src/main/kotlin/pl/treksoft/kvision/table
parent22a8d5c35db97d65a90b21d97e6835380191845d (diff)
downloadkvision-6b53324c97bfc80ed14dfca6a5dbc879950715b9.tar.gz
kvision-6b53324c97bfc80ed14dfca6a5dbc879950715b9.tar.bz2
kvision-6b53324c97bfc80ed14dfca6a5dbc879950715b9.zip
Upgrade to Bootstrap 4.
Upgrade to Font Awesome 5. Restructure modules.
Diffstat (limited to 'src/main/kotlin/pl/treksoft/kvision/table')
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/table/Cell.kt16
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/table/HeaderCell.kt13
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/table/Table.kt46
3 files changed, 63 insertions, 12 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/table/Cell.kt b/src/main/kotlin/pl/treksoft/kvision/table/Cell.kt
index 0a79c9f9..44646897 100644
--- a/src/main/kotlin/pl/treksoft/kvision/table/Cell.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/table/Cell.kt
@@ -64,6 +64,22 @@ open class Cell(
this.add(cell)
return cell
}
+
+ /**
+ * DSL builder extension function.
+ *
+ * It takes the same parameters as the constructor of the built component.
+ */
+ fun Row.thcell(
+ content: String? = null,
+ rich: Boolean = false,
+ align: Align? = null,
+ classes: Set<String> = setOf(), init: (HeaderCell.() -> Unit)? = null
+ ): HeaderCell {
+ val headerCell = HeaderCell(content, rich, align, Scope.ROW, classes, init)
+ this.add(headerCell)
+ return headerCell
+ }
}
}
diff --git a/src/main/kotlin/pl/treksoft/kvision/table/HeaderCell.kt b/src/main/kotlin/pl/treksoft/kvision/table/HeaderCell.kt
index b70845d6..14527f0f 100644
--- a/src/main/kotlin/pl/treksoft/kvision/table/HeaderCell.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/table/HeaderCell.kt
@@ -25,6 +25,11 @@ import pl.treksoft.kvision.html.Align
import pl.treksoft.kvision.html.TAG
import pl.treksoft.kvision.html.Tag
+enum class Scope(internal val scope: String) {
+ ROW("row"),
+ COL("col")
+}
+
/**
* HTML table header cell component.
*
@@ -39,11 +44,16 @@ open class HeaderCell(
content: String? = null,
rich: Boolean = false,
align: Align? = null,
+ scope: Scope? = null,
classes: Set<String> = setOf(),
init: (HeaderCell.() -> Unit)? = null
) : Tag(TAG.TH, content, rich, align, classes) {
init {
+ scope?.let {
+ @Suppress("LeakingThis")
+ setAttribute("scope", it.scope)
+ }
@Suppress("LeakingThis")
init?.invoke(this)
}
@@ -58,9 +68,10 @@ open class HeaderCell(
content: String? = null,
rich: Boolean = false,
align: Align? = null,
+ scope: Scope? = null,
classes: Set<String> = setOf(), init: (HeaderCell.() -> Unit)? = null
): HeaderCell {
- val cell = HeaderCell(content, rich, align, classes, init)
+ val cell = HeaderCell(content, rich, align, scope, classes, init)
this.add(cell)
return cell
}
diff --git a/src/main/kotlin/pl/treksoft/kvision/table/Table.kt b/src/main/kotlin/pl/treksoft/kvision/table/Table.kt
index 11ed52fc..6d7c9b6e 100644
--- a/src/main/kotlin/pl/treksoft/kvision/table/Table.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/table/Table.kt
@@ -38,8 +38,29 @@ import pl.treksoft.kvision.utils.snOpt
enum class TableType(val type: String) {
STRIPED("table-striped"),
BORDERED("table-bordered"),
+ BORDERLESS("table-borderless"),
HOVER("table-hover"),
- CONDENSED("table-condensed")
+ SMALL("table-sm"),
+ DARK("table-dark")
+}
+
+/**
+ * HTML table responsive types.
+ */
+enum class ResponsiveType(val type: String) {
+ RESPONSIVE("table-responsive"),
+ RESPONSIVESM("table-responsive-sm"),
+ RESPONSIVEMD("table-responsive-md"),
+ RESPONSIVELG("table-responsive-lg"),
+ RESPONSIVEXL("table-responsive-xl")
+}
+
+/**
+ * HTML table header types.
+ */
+enum class TheadType(internal val type: String) {
+ DARK("thead-dark"),
+ LIGHT("thead-light")
}
/**
@@ -56,8 +77,8 @@ enum class TableType(val type: String) {
@Suppress("TooManyFunctions")
open class Table(
headerNames: List<String>? = null,
- types: Set<TableType> = setOf(), caption: String? = null, responsive: Boolean = false,
- classes: Set<String> = setOf(), init: (Table.() -> Unit)? = null
+ types: Set<TableType> = setOf(), caption: String? = null, responsiveType: ResponsiveType? = null,
+ theadType: TheadType? = null, classes: Set<String> = setOf(), init: (Table.() -> Unit)? = null
) : SimplePanel(classes + "table") {
/**
@@ -75,10 +96,13 @@ open class Table(
/**
* Determines if the table is responsive.
*/
- var responsive by refreshOnUpdate(responsive)
+ var responsiveType by refreshOnUpdate(responsiveType)
private val theadRow = Tag(TAG.TR)
- private val thead = Tag(TAG.THEAD).add(theadRow)
+ private val thead = Tag(TAG.THEAD).apply {
+ if (theadType != null) addCssClass(theadType.type)
+ add(theadRow)
+ }
private val tbody = Tag(TAG.TBODY)
init {
@@ -94,7 +118,7 @@ open class Table(
private fun refreshHeaders() {
theadRow.removeAll()
headerNames?.forEach {
- theadRow.add(HeaderCell(it))
+ theadRow.add(HeaderCell(it, scope = Scope.COL))
}
}
@@ -128,9 +152,9 @@ open class Table(
}
override fun render(): VNode {
- return if (responsive) {
+ return if (responsiveType != null) {
val opt = snOpt {
- `class` = snClasses(listOf("table-responsive" to true))
+ `class` = snClasses(listOf(responsiveType!!.type to true))
}
h("div", opt, arrayOf(render("table", childrenVNodes())))
} else {
@@ -185,11 +209,11 @@ open class Table(
*/
fun Container.table(
headerNames: List<String>? = null,
- types: Set<TableType> = setOf(), caption: String? = null, responsive: Boolean = false,
- classes: Set<String> = setOf(), init: (Table.() -> Unit)? = null
+ types: Set<TableType> = setOf(), caption: String? = null, responsiveType: ResponsiveType? = null,
+ theadType: TheadType? = null, classes: Set<String> = setOf(), init: (Table.() -> Unit)? = null
): Table {
val table =
- Table(headerNames, types, caption, responsive, classes, init)
+ Table(headerNames, types, caption, responsiveType, theadType, classes, init)
this.add(table)
return table
}