Code Monkey home page Code Monkey logo

simple-modal's Introduction

Simple Modal

Build status Bower dependencies Version Size Published

Simple modal is a lightweight, performant, style-agnostic modal element.

<button id="button">open modal</button>

<simple-modal id="modal" title="My modal">
  My modal's content
</simple-modal>

<script>
  var button = document.querySelector('#button'),
      modal = document.querySelector('#modal');

  button.addEventListener('click', function() {
    modal.active = true;
  });
</script>

Installation & usage

Install simple-modal with Bower

$ bower install simple-modal-element --save

Import it into the <head> of your page

<link rel="import" href="/bower_components/simple-modal/simple-modal.html">

Then use it in your project, and toggle the active property to open/close it.

<simple-modal id="modal"></simple-modal>

<script>
  // Open modal
  document.querySelector('#modal').active = true;
</script>

Polyfills for cross-browser support

Simple modal relies on emerging standards, for full cross-browser support include the Web Components Lite polyfill.

bower i webcomponentsjs --save
<script src="/bower_components/webcomponentsjs/web-components-lite.js"></script>

Options

Property Type Default Description
active Boolean false State of the modal, change to open/close
title String '' Optional title to show on the modal
noExit Boolean false Disable user closing modal (change active manually instead)

Properties can either be set as attributes on the element, or imperitively with Javascript

<simple-modal no-exit></simple-modal>

<script>
    document.querySelector('simple-modal').title = 'My modal';
</script>

Methods

Method Arguments Description
getModal() none Returns the internal modal HTML element

Styling

Simple modal is easily styleable with custom properties and CSS mixins

Property Default Description
--simple-modal-overlay rgba(0,0,0, 0.4) Color of the screen overlay when modal active
--simple-modal-padding 40px Padding inside the modal dialog
--simple-modal-close-size 14px Size of the close button
--simple-modal-close-color rgba(0,0,0,0.45) Color of the close button

Apply properties on simple-modal

simple-modal {
  --simple-modal-overlay: rgba(255,255,255,0.4);
}
Mixin Description
--simple-modal Style the modal dialog
--simple-modal-title Style the modal title
--simple-modal-close Style the modal close button

Apply mixins to simple-modal

simple-modal {
  @apply(--simple-modal) {
    background: black;
    color: white;
  };
}

Events

Event Description
active-changed Fired when the active property changes - active value is stored in detail.value

--

MIT © Simpla

simple-modal's People

Watchers

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