Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@cloudcmd/modal

cloudcmd276MIT3.0.2

lightbox library for displaying modals with api similar to FancyBox v2

modal, fancybox, lightbox, viewer, view

readme

Modal License NPM version Build Status Coverage

Lightbox library for displaying modals with api similar to FancyBox v2.

Modal

Install

npm i @cloudcmd/modal

How Come?

I used fancybox for a long time but there is a couple things I don't like about it:

  • has not tests
  • uses jquery
  • big (30kb of jquery + 13kb = 43kb against 23kb of modal)
  • slow
  • does not support common.js, esm etc
  • license not compatible with MIT

Modal in the other hand:

  • written on vanilla js
  • has no extra dependencies
  • has full test coverage
  • does most stuff using css
  • can be installed using npm
  • supports common.js, esm
  • contains css and images inside of a js bundle (for using with webpack see webpack.config.js)
  • Api compatible with fancybox

API

First things first, import modal with:

import modal from '@cloudcmd/modal';

Using build file:

open(el[, options])

const el = document.createElement('div');
el.textContent = 'hello';

// simplest possible modal open using existing html element
modal.open(el);
modal.close();

// usage with title and hooks
modal.open(el, {
    title: 'hello world',
    beforeOpen: () => console.log('before open'),
    afterOpen: () => console.log('after open'),
    beforeClose: () => console.log('before close'),
    afterClose: () => console.log('after close'),
    helpers: {
        title: true,
    },
});

open(images[, options])

const image = {
    title: 'hello',
    href: 'cloudcmd.png',
};

modal.open([image], {
    autoSize: true,
    helpers: {
        title: true,
    },
});

close

Close opened modal window:

modal.close();

License

MIT

changelog

2023.01.15, v3.0.2

feature:

  • @cloudcmd/modal: rm duplicate box shadow

2023.01.15, v3.0.1

fix:

  • modal: get rid of optional chaining

2023.01.15, v3.0.0

feature:

  • package: auto-globals v3.0.0
  • package: eslint-plugin-n v15.6.1
  • package: stylelint-config-standard v29.0.0
  • package: @cloudcmd/stub v4.0.1
  • package: rimraf v4.0.5
  • package: supertape v8.2.0
  • package: c8 v7.12.0
  • package: madrun v9.0.7
  • package: stylelint v14.16.1
  • package: eslint-plugin-putout v16.3.0
  • package: putout v28.5.0
  • package: eslint v8.32.0
  • modal: close: add stopPropagation of event

2020.03.25, v2.0.3

feature:

  • (package) nodemon v2.0.2
  • (package) url-loader v4.0.0
  • (package) eslint-plugin-node v11.0.0
  • (package) eslint-plugin-putout v3.5.0
  • (package) nyc v15.0.0
  • (package) stylelint-config-standard v20.0.0
  • (package) stylelint v13.2.1
  • (package) putout v7.20.2
  • (package) madrun v5.4.5
  • (package) fullstore v3.0.0

2019.09.20, v2.0.2

feature:

  • (package) currify v4.0.0

2019.09.18, v2.0.1

feature:

  • (package) @cloudcmd/create-element v2.0.0

2019.09.18, v2.0.0

feature:

  • (modal) drop support of dist, legacy
  • (package) stylelint v11.0.0
  • (package) wraptile v3.0.0
  • (package) style-loader v1.0.0
  • (package) rimraf v3.0.0
  • (package) putout v6.0.0
  • (package) madrun v3.0.5
  • (package) eslint-plugin-putout v2.0.0
  • (package) eslint-plugin-node v10.0.0
  • (package) fullstore v2.0.2
  • (package) css-loader v3.1.0
  • (package) clean-css-loader v2.0.0
  • (package) url-loader v2.1.0
  • (package) nyc v14.1.1
  • (package) eslint-plugin-node v9.1.0
  • (package) eslint v6.1.0
  • (package) stylelint v10.1.0

2019.03.21, v1.1.2

feature:

  • (package) css-loader v2.1.1
  • (modal) redrun -> madrun
  • (package) add auto-globals
  • (modal) sinon, sinon-called-with-diff -> @cloudcmd/stub
  • (modal) sinon, sinon-called-with-diff -> @cloudcmd/stub
  • (package) sinon-called-with-diff v3.0.0
  • (package) sinon v7.1.1
  • (test) rm unused

2018.10.10, v1.1.1

feature:

  • (package) redrun v7.0.2
  • (package) currify v3.0.0

2018.09.18, v1.1.0

feature:

  • (modal) move out create-lement to @cloudcmd/create-element

2018.09.14, v1.0.1

fix:

  • (package) repo url
  • (npmignore) add lib