Giter Club home page Giter Club logo

modal-by-shadowdom's Introduction

Shadow-DOM-Modal

this project just start for shadow learning.

live demo


Usage

new Modal(Options);

Options

Option Type Required Description
name {String} true A DOMString For CustomElementRegistry.define() first param
onClose {Function} false
onComfirm {Function} false
onCancel {Function} false
buttons {Array.<Button>} false
content `{String Element}` false
container {Element} false Parent node of the Modal component
className {String} false

Button

Option Type Required Description
text {String} true Button text
action {Function} true A function to be executed after the button click

Example

Base

const modal = new Modal({
  name: 'modal',
  buttons: [{ action: ({ close }) => close(), text: 'close' }],
  content: 'this is a modal',
});

modal.show();

With template content

<template id="template">
  <p>this is a modal</p>
</template>
const { content } = document.querySelector('#template');
const modal = new Modal({
  name: 'modal',
  content: document.importNode(content, true),
  buttons: [{ action: ({ close }) => close(), text: 'close' }],
});

With Shadow slot

<slot-modal>
  <h3 slot="content">This is a Modal create by slot mode</h3>
  <p slot="content">
    This is a Modal create by template mode.
  </p>
  <div slot="footer">
    <button onclick="closeModal()">confirm</button>
  </div>
</slot-modal>
// You still need to instantiate a Modal to register the custom element
const slotModal = new Modal({ name: 'slot-modal' });

window.closeModal = slotModal.close;

Tip: If your javascript code is executed after HTML parse, you need to code css like the following for the slot element to prevent it from appearing before the custom element is registered.

slot-modal:not(:defined) *[slot] {
  display: none;
}

modal-by-shadowdom's People

Contributors

mioco avatar

Watchers

James Cloos 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.