Using Bootstrap

The kilua-bootstrap module provides convenient wrappers around many of the features provided by the popular Bootstrap library.

Text and colors

Bootstrap defines a lot of CSS classes for colors, backgrounds and borders. You can use these classes directly but there are also a few enum classes defined in the Bootstrap module: BsColor, BsBgColor, BsBorder and BsRounded.

div("${BsBorder.Border} ${BsBorder.BorderDanger} ${BsRounded.RoundedPill} ${BsColor.TextBgInfo}") {
    width(300.px)
    padding(10.px)
    +"Hello Bootstrap!"
}

Bootstrap buttons

You can use dedicated bsButton composable function to use Bootstrap buttons with predefined styles and sizes.

bsButton("Click me", style = ButtonStyle.BtnSuccess, size = ButtonSize.BtnLg) {
    onClick {
        console.log("Hello Bootstrap!")
    }
}

Color mode

To support color mode switching you need to initialize ThemeManger object using its init() method.

By default the last selected color mode will be used and it will be automatically saved in the browser local storage. You can customize this behaviour with optional parameters.

You can use ThemeManager.theme property to get and set the current color mode at any time.

You can also use built-in theme switcher component.

The theme switcher uses Font Awesome icons by default, so you should also add kilua-fontawesome module dependency to your project. If your applications uses a different icons set (e.g. Bootstrap Icons), you can use optional switcher parameters to customize icons.

Layout containers

TabPanel

The tabPanel() composable function allows you to create a popular tabbed layout, with tabs on the top, left or right side of the content.

For tabs displayed on the left or right side of the content, you need to declare the ratio between the size of the tabs and the content. The sideTabSize parameter takes one of six enumerated values (from Size1 to Size6) which mean 1/11, 2/10, 3/9, 4/8, 5/7, and 6/6 ratios. The default ratio is 3/9.

Tabs can be made closable. A closable tab displays a cross icon on the tab bar. When a user clicks this icon, the tab is not automatically removed from the panel, but a special closeTab event is triggered. The event need to be handled and the tab should be hidden with some custom condition, preferably backed by a compose state variable.

You can also allow to reorder tabs with drag & drop using draggableTabs = true parameter. Similar to closing, the result of the D&D operation is a moveTab event, which should be processed by your code and result in a change of the state used to define tabs order.

Offcanvas

Bootstrap offcanvas is a sidebar component that can be toggled to appear from the left, right, top, or bottom edge of the viewport.

You can use additional parameters of the composable function to customize offcanvas placement, responsiveness, closing, scrolling and backdrop usage.

Accordion

Bootstrap accordion component allows you to create vertically collapsing panels with various content.

You can use additional parameters of the composable function to customize accordion behaviour.

Bootstrap carousel component allows you to cycle through its children elements.

You can use additional parameters of the composable function to customize carousel behaviour. You can also use component reference to control carousel playback.

Last updated