UNPKG

client-cert-login-component

Version:

Web component for client certificate authentication and registration form.

147 lines (125 loc) 4.42 kB
/* MIT License Copyright (c) 2019 Priyesh Patel Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ export class Modal extends HTMLElement { constructor() { super(); this._modal; this.attachShadow({ mode: 'open' }); this.shadowRoot.innerHTML = ` <style> /* The Modal (background) */ .modal { display: none; position: fixed; z-index: 1; padding-top: 100px; left: 0; top: 0; width: 100%; height: 100%; overflow: auto; background-color: rgba(0,0,0,0.4); } /* Modal Content */ .modal-content { position: relative; background-color: #fefefe; margin: auto; padding: 0; border: 1px solid #888; width: 80%; box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2),0 6px 20px 0 rgba(0,0,0,0.19); -webkit-animation-name: animatetop; -webkit-animation-duration: 0.4s; animation-name: animatetop; animation-duration: 0.4s } /* Add Animation */ @-webkit-keyframes animatetop { from {top:-300px; opacity:0} to {top:0; opacity:1} } @keyframes animatetop { from {top:-300px; opacity:0} to {top:0; opacity:1} } /* The Close Button */ .close { color: white; float: right; font-size: 28px; font-weight: bold; } .close:hover, .close:focus { color: #000; text-decoration: none; cursor: pointer; } .modal-header { padding: 2px 16px; background-color: #000066; color: white; } .modal-body {padding: 2px 16px; margin: 20px 2px} </style> <div class="modal"> <div class="modal-content"> <div class="modal-header"> <span class="close">&times;</span> <slot name="header"><h1>Default text</h1></slot> </div> <div class="modal-body"> <slot><slot> </div> </div> </div> ` } connectedCallback() { this._modal = this.shadowRoot.querySelector(".modal"); this.shadowRoot.querySelector(".close").addEventListener('click', this._hideModal.bind(this)); } disconnectedCallback() { this.shadowRoot.querySelector(".close").removeEventListener('click', this._hideModal); } get visible () { return this.hasAttribute('visible') } set visible (value) { if (value) { this._modalVisible = true; this._modal.style.display = 'block'; this.setAttribute('visible', value) } else { this._modalVisible = false; this._modal.style.display = 'none'; this.removeAttribute('visible'); } } _showModal () { this.visible = true } _hideModal () { this.visible = false } } customElements.define('pp-modal',Modal); export default Modal