In this blog I will show you how you can implement Curtain Effect in your Lightning Web Component.
I will be creating a custom LWC and in that I will add the Curtain css using a custom modal component.
Please follow the code below :
CurtainModal.html
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | <template> <div data-id="curtainModal" id="curtainModal" class="overlay"> <lightning-button-icon icon-name="utility:close" variant="bare-inverse" class="closebtn" onclick={closeModal} size="large" ></lightning-button-icon> <div class="overlay-content"> <section role="dialog" tabindex="-1" aria-labelledby="modal-heading-01" aria-modal="true" aria-describedby="modal-content-id-1" > <div class="slds-modal__container"> <!-- Header Start --> <header class="slds-modal__header"> <h2 class="slds-text-heading_medium slds-hyphenate header-string"> Curtain Modal Popup </h2> </header> <!-- Header End --> <div class="slds-modal__content slds-p-around_medium" id="modal-content-id-1" > <slot> <p>This is a curtain modal popup component.</p> </slot> </div> </div> </section> </div> </div> <lightning-card title="Curtain Modal" icon-name="utility:user"> <div class="slds-var-m-around_medium"> <lightning-button variant="brand" label=" Show Curtain Modal" title=" Show Curtain Modal" onclick={handleShowModal} class="slds-m-left_x-small" ></lightning-button> </div> </lightning-card> </template> |
CurtainModal.js
1 2 3 4 5 6 7 8 9 10 11 | import { LightningElement } from "lwc"; export default class CurtainModal extends LightningElement { closeModal() { this.template.querySelector('[data-id="curtainModal"]').style.width = "0%"; } handleShowModal() { this.template.querySelector('[data-id="curtainModal"]').style.width = "100%"; } } |
CurtainModal.css
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | .overlay { height: 100%; width: 0; position: fixed; z-index: 1; top: 0; left: 0; background-color: rgb(0, 0, 0); background-color: rgba(0, 0, 0, 0.9); overflow-x: hidden; transition: 0.5s; } .overlay-content { position: relative; top: 25%; width: 100%; margin-top: 30px; } .overlay .closebtn { position: absolute; top: 60px; right: 45px; font-size: 60px; } |
Output
Checkout the complete video below
If you have any question please leave a comment below.
If you would like to add something to this post please leave a comment below.
Share this blog with your friends if you find it helpful somehow !
Thanks
Happy Coding :)
0 Comments