Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/lekoala/bs-companion

The perfect Bootstrap companion
https://github.com/lekoala/bs-companion

bootstrap bootstrap5 form modal responsive table tabs toast validator

Last synced: 13 days ago
JSON representation

The perfect Bootstrap companion

Awesome Lists containing this project

README

        

# bs-companion

[![NPM](https://nodei.co/npm/bs-companion.png?mini=true)](https://nodei.co/npm/bs-companion/)
[![Downloads](https://img.shields.io/npm/dt/bs-companion.svg)](https://www.npmjs.com/package/bs-companion)

> Components with super powers for your Bootstrap apps!

This packages includes:

- Responsive Table: Nice responsive tables without ugly scrollbars
- BS Tabs: Improved tabs, that collapse down to a dropdown and with linkable tabs
- Toaster: Generate beautiful toast message without markup
- Toasts: Easily generate basic ui toasts (success, warning, error) and enforce default styling
- Modalizer: Generate beautiful modals without markup
- Form Validator: Consistent validator that works across tabs and accordions
- BS Progress: indeterminate and top page progress bars

## Tabs

Simply wrap your regular tabs in a `bs-tabs` component

```html

```

Supported features (add attributes)

- Linkable: clicking on the tab will update the hash
- Responsive: when there is not enough space to fit everything on one line, it will collapse to a dropdown

It can also lazy load content in the tabs. It will trigger a `lazyload` on any `lazy-loadable` element

## Modals

Basic usage using the `modalizer` function

```js
modalizer({
body: "Hello!",
title: "This is a modal",
icon: btn.dataset.icon,
});
```

For confirm modals, you can use

```js
modalizerConfirm(
{
body: btn.dataset.confirm,
icon: "question",
},
(res) => {
// form elements are exposed as FormData inside detail
let name = res.detail.get("your_name");

console.log("accepted", res);
},
(res) => {
console.log("denied", res);
}
);
```

## Toasts

Basic usage using the `toaster` function

```js
// You can simply pass a string
toaster("Hello world");
// Or an array
toaster({
body: "Hello world some link here",
header: `

My header
`,
autohide: false,
});
```

However, it can be bothersome to always specify all options. Enters the `Toasts` class

```js
Toasts.success("Hello world");
```

## Form validation

You can easily validate all your forms using `FormValidator`

```html

FormValidator.init();

...
```

Simply set a `needs-validation` class. You can also set a message that will be shown in case some fields are invalid.
It will also checks in tabs and accordion and show invalid icons.

### Validation on trigger

You can validate on `blur` or `keydown`.

```html

```

### Custom validation

You can use custom validation rules. Multiple rules are supported using a , as separator.

```html

```

Built-in rules:
- same {fieldSelector}: check if the value is the same
- digits: contains only digits
- number: is a valid number
- alnum: contains only alnum

You can register custom rules using `FormValidation.registerRule`.

## Also check out

- [Bootstrap 5 Tags](https://github.com/lekoala/bootstrap5-tags): tags input for bootstrap
- [Bootstrap5 autocomplete](https://github.com/lekoala/bootstrap5-autocomplete): the autocomplete input for bootstrap 5 (and more!)
- [Admini](https://github.com/lekoala/admini): the minimalistic bootstrap 5 admin panel
- [Formidable Elements](https://github.com/lekoala/formidable-elements): more custom elements for your bootstrap app!