Coder Social home page Coder Social logo

vanilla-modals's Introduction

Vanilla Modals

Modals without built in HTML tags

ts logo html5 logo css3 logo

Introduction

This project focuses on Modal features, but without using built-in HTML tags or JavaScript APIs, like <dialog> HTML tag, or JavaScript Popover API. Clicking over a button, for example, "Edit content", this will be able to simply open a modal with the context of the clicked button, in this case, a random content.

Creating and loading new modals

By default, the project comes with two templates, inside the templates folder. If you notice, both will follow a standard HTML structure like this:

<html>
    <body>
        <template>
            <!-- A modal wrapper, starting with a "display: none" -->
            <div data-modal="hello-world" data-modal-visibility="hidden" style="display: none;">
                <div data-modal-content="hello-world">
                    <!-- A close button -->
                    <span data-close-modal="hello-world" class="material-symbols-outlined close-btn" role="button">close</span>
                    <div>...</div>
                </div>
            </div>
            <!-- A button to open the modal wrapper -->
            <button data-open-modal="hello-world" class="modal-btn">
                ...
            </button>
        </template>
    </body>
</html>

After creating a new template, you need to loading it by adding it to the modals > modals-loader.ts file, in the src folder, at the modalsTemplatesNames array, inside the getModalTemplates() function. Once the template is loaded, the script will handle toggling the modal visibility.

Try it out

If you want, take a look at the online version of this project - clicking on the follow link, you will be able to try it out: modals.vinicius-goncalves.com.

vanilla-modals's People

Contributors

vinicius-goncalves avatar

Stargazers

 avatar  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.