npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

bootstrap-tabs

v1.0.7

Published

Extends an input text field to store multiple values

Downloads

24

Readme

Bootstrap Tabs

Extends an input text field to store multiple values. This library works by duplicating the input element you provide it in order to keep your existing form elements intact. Values are then written back to your original input as a comma separated (customisable) string.

Installation

It is assumed Bootstrap (tested with ^5.3.3) is already installed in your project.

npm i bootstrap-tabs

API

Create an instance:

import { BootstrapTabs } from "bootstrap-tabs";

let tabs = new BootstrapTabs(document.getElementById("input-field"));

Settings

You can also provide a settings object as the second parameter to provide customisation. All settings are optional.

| Setting | Type | Default | Notes | | ------- | ---- | ------- | ----- | | allowDuplicates | boolean | false | Pass in true to allow duplicate entries, default is false | | valueSeparator | string | ',' | Provide a custom value separator when written back to the original input's value attribute | sortItems | boolean | false | Enables or disables the default sort (Calls the built in array sort() function) | | sort | (a: string, b: string) => number; | null | Provide a custom sort callback to order the tabs how you wish. Providing this value overrides the sortItems value. | | beforeAdd | (text: string) => boolean; | null | Provide a callback function which returns a boolean to validate the newly created tab. This can be used to discard tabs before they're created | | disableDelete | boolean | false | Set this to true to hide the delete button within each tab | | tabContentRenderer | (text: string, index: number) => string; | <span>${text}</span> | Provide a function that returns an HTML string containing the contents of the tab to render. | | deleteContentRenderer | (text: string, index: number) => string; | <i class="bi bi-x-circle"></i> | Provide a function that returns an HTML string containing the contents of the delete button within each tab to render. By default this uses the bootstrap-icons library bi-x-circle icon, so this function can be used to override this behaviour | | tabClassList | Array<string> | ["badge", "bg-light", "text-dark"] | The list of additional classes to be added to the tab. You can provide these as a way to fully customise how the tabs look. (Note: If you specify this array, the default classes will not be added) | | deleteBtnClassList | Array<string> | ["btn", "btn-sm", "text-dark"] | The list of additional classes to be added to the delete button. You can provide these as a way to fully customise how the delete button looks. (Note: If you specify this array, the default classes will not be added) |

Exposed methods

You can interact with your bootstrap-tabs instance in the following ways:

// Add a new tab (Note this will still execute the beforeAdd / sort settings parameters if provided):
const successfullyAdded = instance.addTab("<Tab value>");

// Remove a tab:
instance.removeTab("<Tab value>");

// Cleanup the instance by calling:
instance.dispose();

CSS/SCSS

Both compiled CSS and the source SCSS is included in this package. You can from whichever works best for your project.

To import the SCSS into your worflow, you can add the following to your sass file:

@import "bootstrap-tabs/dist/scss/bootstrap-tabs";

If you're using vite you may need to add an alias to your vite.config.js:

export default defineConfig({
    resolve: {
        alias: {
            '~bootstrap': path.resolve(__dirname, 'node_modules/bootstrap'),
            '~bootstrap-tabs': path.resolve(__dirname, 'node_modules/bootstrap-tabs'),
        }
    },
    ...

and then import using the alias:

@import "~bootstrap-tabs/dist/scss/bootstrap-tabs";