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/panel | |
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/panel')
10 files changed, 154 insertions, 0 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/DockPanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/DockPanel.kt index 82d1c117..15e66766 100644 --- a/src/main/kotlin/pl/treksoft/kvision/panel/DockPanel.kt +++ b/src/main/kotlin/pl/treksoft/kvision/panel/DockPanel.kt @@ -22,6 +22,7 @@ package pl.treksoft.kvision.panel import pl.treksoft.kvision.core.Component +import pl.treksoft.kvision.core.Container /** * Dock layout directions. @@ -185,4 +186,15 @@ open class DockPanel(classes: Set<String> = setOf(), init: (DockPanel.() -> Unit removeAt(SIDE.DOWN) return this } + + companion object { + /** + * DSL builder extension function + * + * It takes the same parameters as the constructor of the built component. + */ + fun Container.dockPanel(classes: Set<String> = setOf(), init: (DockPanel.() -> Unit)? = null) { + this.add(DockPanel(classes, init)) + } + } } diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/FlexPanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/FlexPanel.kt index 5aebe1c6..9cff2a7e 100644 --- a/src/main/kotlin/pl/treksoft/kvision/panel/FlexPanel.kt +++ b/src/main/kotlin/pl/treksoft/kvision/panel/FlexPanel.kt @@ -22,6 +22,7 @@ package pl.treksoft.kvision.panel import pl.treksoft.kvision.core.Component +import pl.treksoft.kvision.core.Container import pl.treksoft.kvision.core.StringPair import pl.treksoft.kvision.core.StyledComponent import pl.treksoft.kvision.core.WidgetWrapper @@ -275,4 +276,18 @@ internal class FlexWrapper( return snstyle } + companion object { + /** + * DSL builder extension function + * + * It takes the same parameters as the constructor of the built component. + */ + fun Container.flexPanel( + direction: FLEXDIR? = null, wrap: FLEXWRAP? = null, justify: FLEXJUSTIFY? = null, + alignItems: FLEXALIGNITEMS? = null, alignContent: FLEXALIGNCONTENT? = null, + spacing: Int? = null, classes: Set<String> = setOf(), init: (FlexPanel.() -> Unit)? = null + ) { + this.add(FlexPanel(direction, wrap, justify, alignItems, alignContent, spacing, classes, init)) + } + } } diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/GridPanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/GridPanel.kt index ba72535a..48e4a784 100644 --- a/src/main/kotlin/pl/treksoft/kvision/panel/GridPanel.kt +++ b/src/main/kotlin/pl/treksoft/kvision/panel/GridPanel.kt @@ -22,6 +22,7 @@ package pl.treksoft.kvision.panel import pl.treksoft.kvision.core.Component +import pl.treksoft.kvision.core.Container import pl.treksoft.kvision.core.StringPair import pl.treksoft.kvision.core.WidgetWrapper @@ -302,6 +303,28 @@ open class GridPanel( } return snstyle } + + companion object { + /** + * DSL builder extension function + * + * It takes the same parameters as the constructor of the built component. + */ + fun Container.gridPanel( + autoColumns: String? = null, autoRows: String? = null, autoFlow: GRIDFLOW? = null, + templateColumns: String? = null, templateRows: String? = null, templateAreas: List<String>? = null, + columnGap: Int? = null, rowGap: Int? = null, justifyItems: GRIDJUSTIFY? = null, + alignItems: GRIDALIGN? = null, justifyContent: GRIDJUSTIFYCONTENT? = null, + alignContent: GRIDALIGNCONTENT? = null, classes: Set<String> = setOf(), init: (GridPanel.() -> Unit)? = null + ) { + this.add( + GridPanel( + autoColumns, autoRows, autoFlow, templateColumns, templateRows, templateAreas, + columnGap, rowGap, justifyItems, alignItems, justifyContent, alignContent, classes, init + ) + ) + } + } } class GridWrapper( diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/HPanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/HPanel.kt index 755c675b..20cc72f8 100644 --- a/src/main/kotlin/pl/treksoft/kvision/panel/HPanel.kt +++ b/src/main/kotlin/pl/treksoft/kvision/panel/HPanel.kt @@ -21,6 +21,8 @@ */ package pl.treksoft.kvision.panel +import pl.treksoft.kvision.core.Container + /** * The container with horizontal layout. * @@ -45,4 +47,22 @@ open class HPanel( @Suppress("LeakingThis") init?.invoke(this) } + + companion object { + /** + * DSL builder extension function + * + * It takes the same parameters as the constructor of the built component. + */ + fun Container.hPanel( + wrap: FLEXWRAP? = null, + justify: FLEXJUSTIFY? = null, + alignItems: FLEXALIGNITEMS? = null, + spacing: Int? = null, + classes: Set<String> = setOf(), + init: (HPanel.() -> Unit)? = null + ) { + this.add(HPanel(wrap, justify, alignItems, spacing, classes, init)) + } + } } diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/ResponsiveGridPanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/ResponsiveGridPanel.kt index 8831e905..9ac66d20 100644 --- a/src/main/kotlin/pl/treksoft/kvision/panel/ResponsiveGridPanel.kt +++ b/src/main/kotlin/pl/treksoft/kvision/panel/ResponsiveGridPanel.kt @@ -22,6 +22,7 @@ package pl.treksoft.kvision.panel import pl.treksoft.kvision.core.Component +import pl.treksoft.kvision.core.Container import pl.treksoft.kvision.core.WidgetWrapper import pl.treksoft.kvision.html.ALIGN import pl.treksoft.kvision.html.TAG @@ -176,4 +177,19 @@ open class ResponsiveGridPanel( children.forEach { it.dispose() } removeAll() } + + companion object { + /** + * DSL builder extension function + * + * It takes the same parameters as the constructor of the built component. + */ + fun Container.responsiveGridPanel( + gridsize: GRIDSIZE = GRIDSIZE.MD, + rows: Int = 0, cols: Int = 0, align: ALIGN? = null, + classes: Set<String> = setOf(), init: (ResponsiveGridPanel.() -> Unit)? = null + ) { + this.add(ResponsiveGridPanel(gridsize, rows, cols, align, classes, init)) + } + } } diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/SimplePanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/SimplePanel.kt index aad57023..f642b353 100644 --- a/src/main/kotlin/pl/treksoft/kvision/panel/SimplePanel.kt +++ b/src/main/kotlin/pl/treksoft/kvision/panel/SimplePanel.kt @@ -100,4 +100,15 @@ open class SimplePanel(classes: Set<String> = setOf(), init: (SimplePanel.() -> children.forEach { it.dispose() } removeAll() } + + companion object { + /** + * DSL builder extension function + * + * It takes the same parameters as the constructor of the built component. + */ + fun Container.simplePanel(classes: Set<String> = setOf(), init: (SimplePanel.() -> Unit)? = null) { + this.add(SimplePanel(classes, init)) + } + } } diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/SplitPanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/SplitPanel.kt index 677d0704..c9ee7197 100644 --- a/src/main/kotlin/pl/treksoft/kvision/panel/SplitPanel.kt +++ b/src/main/kotlin/pl/treksoft/kvision/panel/SplitPanel.kt @@ -24,6 +24,7 @@ package pl.treksoft.kvision.panel import com.github.snabbdom.VNode import pl.treksoft.jquery.JQuery import pl.treksoft.jquery.JQueryEventObject +import pl.treksoft.kvision.core.Container import pl.treksoft.kvision.core.StyledComponent import pl.treksoft.kvision.core.UNIT import pl.treksoft.kvision.html.TAG @@ -97,6 +98,20 @@ open class SplitPanel( arrayOf() } } + + companion object { + /** + * DSL builder extension function + * + * It takes the same parameters as the constructor of the built component. + */ + fun Container.splitPanel( + direction: DIRECTION = DIRECTION.VERTICAL, + classes: Set<String> = setOf(), init: (SplitPanel.() -> Unit)? = null + ) { + this.add(SplitPanel(direction, classes, init)) + } + } } internal class Splitter(private val splitPanel: SplitPanel, direction: DIRECTION) : Tag( diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/StackPanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/StackPanel.kt index cf765928..c5234f88 100644 --- a/src/main/kotlin/pl/treksoft/kvision/panel/StackPanel.kt +++ b/src/main/kotlin/pl/treksoft/kvision/panel/StackPanel.kt @@ -23,6 +23,7 @@ package pl.treksoft.kvision.panel import com.github.snabbdom.VNode import pl.treksoft.kvision.core.Component +import pl.treksoft.kvision.core.Container import pl.treksoft.kvision.routing.routing /** @@ -100,4 +101,17 @@ open class StackPanel( if (activeIndex > children.size - 1) activeIndex = children.size - 1 return this } + + companion object { + /** + * DSL builder extension function + * + * It takes the same parameters as the constructor of the built component. + */ + fun Container.stackPanel( + activateLast: Boolean = true, classes: Set<String> = setOf(), init: (StackPanel.() -> Unit)? = null + ) { + this.add(StackPanel(activateLast, classes, init)) + } + } } diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/TabPanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/TabPanel.kt index 067a8146..3e882710 100644 --- a/src/main/kotlin/pl/treksoft/kvision/panel/TabPanel.kt +++ b/src/main/kotlin/pl/treksoft/kvision/panel/TabPanel.kt @@ -22,6 +22,7 @@ package pl.treksoft.kvision.panel import pl.treksoft.kvision.core.Component +import pl.treksoft.kvision.core.Container import pl.treksoft.kvision.core.ResString import pl.treksoft.kvision.html.Link import pl.treksoft.kvision.html.TAG @@ -135,4 +136,15 @@ open class TabPanel(classes: Set<String> = setOf(), init: (TabPanel.() -> Unit)? refresh() return this } + + companion object { + /** + * DSL builder extension function + * + * It takes the same parameters as the constructor of the built component. + */ + fun Container.tabPanel(classes: Set<String> = setOf(), init: (TabPanel.() -> Unit)? = null) { + this.add(TabPanel(classes, init)) + } + } } diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/VPanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/VPanel.kt index 823ab66f..a0eccb50 100644 --- a/src/main/kotlin/pl/treksoft/kvision/panel/VPanel.kt +++ b/src/main/kotlin/pl/treksoft/kvision/panel/VPanel.kt @@ -21,6 +21,8 @@ */ package pl.treksoft.kvision.panel +import pl.treksoft.kvision.core.Container + /** * The container with vertical layout. * @@ -44,5 +46,19 @@ open class VPanel( @Suppress("LeakingThis") init?.invoke(this) } + + companion object { + /** + * DSL builder extension function + * + * It takes the same parameters as the constructor of the built component. + */ + fun Container.vPanel( + justify: FLEXJUSTIFY? = null, alignItems: FLEXALIGNITEMS? = null, spacing: Int? = null, + classes: Set<String> = setOf(), init: (VPanel.() -> Unit)? = null + ) { + this.add(VPanel(justify, alignItems, spacing, classes, init)) + } + } } |