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

@miraidesigns/modal

v1.0.0

Published

Mirai Designs Framework: Modal module

Downloads

5

Readme

Modal

Modal allows you to display any kind of content in a modal popup.
Requires the Button, Elements and Helpers module for proper appearance.


HTML

<div class="mdf-modal" aria-modal="true">
    <div class="mdf-modal__content">
        <!-- Your content here -->
    </div>

    <button class="mdf-button mdf-button--icon mdf-modal__close" aria-label="Close modal">
        <svg class="mdf-icon" viewBox="0 0 24 24" aria-hidden="true">
            <use href="./assets/images/icons.svg#clear"></use>
        </svg>
    </button>

    <div class="mdf-modal__backdrop"></div>
</div>

Sass

// Include default styles without configuration
@forward '@miraidesigns/modal/styles';
// Configure appearance
@use '@miraidesigns/modal' with (
    $variable: value
);

@include modal.styles();

TypeScript

import { MDFModal } from '@miraidesigns/modal';

const modal = new MDFModal(document.querySelector('.mdf-modal'));
modal.open();

Examples

Dynamic content

Its very easy to add content to the modal.
In the example below we will create a baby Lightbox.

import { MDFModal } from '@miraidesigns/modal';

const modal = new MDFModal(document.querySelector('.mdf-modal'));

// Here we loop through our hypothetical list of image links.
for (const link of document.querySelectorAll('a.img-link')) {
    // We listen for the click event.
    link.addEventListener('click', (evt: MouseEvent) => {
        // Prevent the default link behavior.
        evt.preventDefault();
    
        // The link's `href` attribute holds the URL to our image file.
        const src = (link as HTMLLinkElement).href;

        // Now we simply insert an `<img>` tag with our `src`.
        modal.insertHTML(`<img src="${src}">`);

        // And open the modal.
        modal.open();
    });
}

Requests

You may request content from a different URL to populate the modal.

HTML

<div class="mdf-modal" aria-modal="true">
    <div class="mdf-modal__content mdf-modal__content--padded">
        <div class="mdf-modal__loading"></div>
    </div>

    <button class="mdf-button mdf-button--icon mdf-modal__close" aria-label="Close modal">
        <svg class="mdf-icon" viewBox="0 0 24 24" aria-hidden="true">
            <use href="./assets/images/icons.svg#clear"></use>
        </svg>
    </button>

    <div class="mdf-modal__backdrop"></div>
</div>

TypeScript

import { MDFModal } from '@miraidesigns/modal';

const modal = new MDFModal(document.querySelector('.mdf-modal'));

// Open the request for the given URL.
modal.openRequest('example.org');

// Set any headers if you need to.
modal.setRequestHeader('Content-Type', 'text/html');

// Finally we request the element we need with a CSS selector.
modal.requestContent('.example');

Implementation

Classes

| Name | Type | Description | | ---------------------------- | ------------ | ------------------------------------------------ | | mdf-modal | Parent | Contains the modal content and backdrop | | mdf-modal--active | Modifier | 1. Prepares the modal to be visible | | mdf-modal--fade-in | Modifier | 2. Fades-in the modal and allows for interaction | | mdf-modal__content | Parent/Child | Content container. Child to .mdf-modal | | mdf-modal__content--padded | Modifier | Add padding to the content | | mdf-modal__close | Child | Closes the modal. Child to .mdf-modal | | mdf-modal__backdrop | Child | Modal backdrop. Child to .mdf-modal |

Events

| Name | Data | Description | | ----------------- | ------ | ----------------------------------------------- | | MDFModal:closed | null | Fires when the modal closes | | MDFModal:load | null | Fires when the requested modal content is ready | | MDFModal:open | null | Fires when the modal opens |

Properties

| Name | Type | Description | | ---------------------------------- | ----------------------------------------------------------------------------- | --------------------------------------------------------------------------- | | .container | HTMLElement | Returns the modal container element | | .request | XMLHttpRequest | Returns the current request | | .timeout | number | Get or set the request timeout value | | .readyState | number | Get the request readyState | | .open() | (): void | Open the modal | | .close() | (): void | Close the modal | | .append(elem) | (Element): void | Add the given element to the modal content | | .insertHTML(html) | (string): void | Insert the given string of HTML into the modal content | | .openRequest(url) | (string): void | Open the request for the given URL | | .setRequestHeader(header, value) | (string, string): void | Add header to the request. May be called repeatedly to add multiple headers | | .requestContent(selector) | (string): void | Request the element with the given selector from the opened URL | | .on(type, listener, options?) | (string, EventListenerOrEventListenerObject, AddEventListenerOptions): void | Listen to Modal specific events. Allowed values are load open close. |