GithubHelp home page GithubHelp logo

wrapped_boostrap5_modal's Introduction

Wrapped Boostrap 5 Modal

A simple and complete way to use Bootstrap 5.x.x Modals from JS!

For the moment this is a basic class, in the future I will implement more features like asynchronous functions in button_click() listeners and the possibility to add icons in buttons.

Specifications

WrappedModal object

Parameter Description Optional Type Default
id Your Modal ID in DOM. False string undefined
title Your Title of Modal. True string "title"
body Your Body of Modal in string format HTML output. False string undefined
options Your Modal behavior options. True object undefined
buttons Your Buttons in modal-footer. True array undefined
  • If options is not set default Modal behavior will be used.
  • If buttons is not set default button in modal-footer will be used.

options parameter

Parameter Description Optional Type Default
fade If true Modal effect transition is enabled when toggle() is called. True boolean undefined
shadow If true Modal shadow effect is enabled. True boolean undefined
static If true Static Backdrop is enabled so Modal will not close when clicking outside of it. True boolean undefined
scrollable If true modal-body is scrollable. True boolean undefined
centered If true Modal is centered in screen. True boolean undefined
size Defines the size of Modal.
You can choose between sm, lg and xl

If no value is set default size will be used
True string undefined
reload If true web page will be reloaded after closing the Modal. True boolean undefined

buttons parameter

Parameter Description Optional Type Default
text Label of your Button. True string undefined
class class attribute of the button. True string undefined
dismiss If true your Modal will close after button_click() event is triggered. True boolean undefined
function The function that will be called in your button_click() listener. True function undefined

Usage

const modalId = 'example-modal';
const modalTitle = 'Modal Example Title';
const modalBody = '<h5>This is the body</h5><p>This is the description</p>';
const modalOptions = {
  fade: true,
  shadow: true,
  static: true,
  scrollable: true,
  centered: true
}
const modalButtons = [
  { text: 'Button 1', dismiss: false, class: 'btn btn-primary', function: () => {
      alert('Button 1 triggered');
    } 
  },
  { text: 'Button 2', dismiss: false, class: 'btn btn-secondary', function: () => {
      alert('Button 2 triggered');
    }
  },
  { text: 'Button 3', dismiss: true, class: 'btn btn-success'}
];

new WrappedModal(
  modalId,
  modalTitle,
  modalBody,
  modalOptions,
  modalButtons
).show();

Demo

Click here to open codepen.io

wrapped_boostrap5_modal's People

Contributors

xxconcasxx avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.