PicoModal

3.0.0 · abandoned · verified Sun Apr 19

PicoModal is a lightweight, self-contained JavaScript library designed for creating modal dialogs. It boasts a minimal footprint, weighing approximately 2KB when minified and gzipped, and operates without any external JavaScript dependencies, making it highly embeddable in various environments. The library handles focus management, keyboard events (like Esc key closing), and ARIA attributes for accessibility out-of-the-box. Key differentiators include its plain vanilla JS approach, eliminating the need for jQuery or other frameworks, and its self-contained nature, requiring no separate CSS or image files. Despite these features, the package appears to be abandoned, with its latest stable version (3.0.0) published over nine years ago in September 2016. There is no active development or defined release cadence, and users should be aware of its long-term maintenance status.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates creating a PicoModal with custom content, styling, a custom close button, and event handling. It shows how to obtain a modal instance and interact with its API.

import picoModal from 'picomodal';

const myModalContent = `
  <p>This is a custom PicoModal example.</p>
  <p>It's styled with an interesting overlay color and custom button text.</p>
  <button id="closeCustomModal">Got it!</button>
`;

const modal = picoModal({
  content: myModalContent,
  overlayStyles: {
    backgroundColor: '#333',
    opacity: 0.85
  },
  modalStyles: {
    border: '2px solid #007bff',
    padding: '20px',
    borderRadius: '8px'
  },
  closeButton: false, // We'll use our custom button
  overlayClose: true // Allow closing by clicking outside
}).afterCreate(function(modalInstance) {
  // Attach event listener to our custom close button after the modal DOM is created
  const closeButton = modalInstance.modalElem().querySelector('#closeCustomModal');
  if (closeButton) {
    closeButton.addEventListener('click', () => modalInstance.close());
  }
}).afterClose(() => {
  console.log('Custom modal has been closed!');
});

// To demonstrate, let's show the modal after a short delay
setTimeout(() => {
  modal.show();
}, 1000);

// You would typically trigger this from a user action, e.g.:
// document.getElementById('openModalButton').addEventListener('click', () => modal.show());

view raw JSON →