Kotlin / kotlinx.html

Kotlin DSL for HTML
Apache License 2.0
1.6k stars 130 forks source link

TBODY should be a FlowContent #284

Open reubenfirmin opened 2 months ago

reubenfirmin commented 2 months ago

For the same reason as #283, TBODY should be a FlowContent. The strict typing makes it hard to flexibly generate fragments. HTMX style pages are where this framework really shines - but the typing makes it difficult.

Consider:

I have a data table component. My tbody is:

            tbody {
                id = tableTarget.id
                renderRows(this@Datatable.records, this@Datatable.rowStyle, this@Datatable.configs)
            }

When I call my data table component, I want it to either generate additional rows (using all of the same configs) or generate the full table.

fun <T, R> FlowContent.datatable(classes: String,
                                 records: List<TableRecord<T, R>>,
                                 configs: List<FieldConfiguration<T, R>>,
                                 headingRenderers: List<FieldHeadingConfiguration>? = null,
                                 loadNextPage: BaseRoute? = null,
                                 rowsOnly: Boolean = false,
                                 rowStyle: String = DEFAULT_ROW_STYLE) {
    if (rowsOnly) {
        renderRows(records, rowStyle, configs)
    } else {
        Datatable(classes, records, configs, headingRenderers, rowStyle, loadNextPage, consumer).visit {
            render()
        }
    }
}

What receiver works for renderRows in both cases? Nada. It's inconvenient.