Skip to main content

LWC Model PopUp

Requirement :



Create a LWC to open Model Popup.
Or in other words
On button click open Model PopUp.

cmpShowModelPopUp.html

<template>
    <lightning-card 
        title="LWC Model" 
        icon-name="custom:custom2">
        <div class="slds-theme_default">
            <div class="slds-p-around_medium">
                <lightning-button 
                    label="Show LWC Modal" variant="brand" 
                    onclick={handleOpenModal}>
                </lightning-button>
            </div>
            <template if:true={isOpenModal}>
                <div style="height: 500px;">
                    <section role="dialog" 
                        tabindex="-1" 
                        aria-labelledby="modal-heading-01" 
                        aria-modal="true" 
                        aria-describedby="modal-content-id-1" 
                        class="slds-modal slds-fade-in-open">

                        <div class="slds-modal__container">
                            <header class="slds-modal__header">
                                <button 
                                class="slds-button 
slds-button_icon slds-modal__close 
slds-button_icon-inverse" 
                                title="Close" 
                                onclick={handleCloseModal}>
                                    <lightning-icon 
                                        icon-name="utility:close"
                                        variant="inverse" 
                                        alternative-text="Close" 
                                        size="medium">
                                    </lightning-icon>
                                    <span 
                                        class="slds-assistive-text">
                                        Close
                                    </span>
                                </button>
                                <h2 id="modal-heading-01" 
                                class="slds-text-heading_medium slds-hyphenate">
                                    LWC Modal Example
                                </h2>
                            </header>
                            <div 
                            class="slds-modal__content slds-p-around_medium" 
                            id="modal-content-id-1">
                                <div 
                                class="slds-text-heading_small 
slds-text-align_center">
                                    Welcome to Gyanender Model
                                </div>
                            </div>
                            <footer class="slds-modal__footer">
                                <lightning-button 
                                    label="Cancel" 
                                    variant="neutral" 
                                    onclick={handleCloseModal}>
                                </lightning-button>
                            </footer>
                        </div>
                    </section>
                    <div class="slds-backdrop slds-backdrop_open"></div>
                </div>
            </template>
        </div>
    </lightning-card>
</template>

cmpShowModelPopUp.js
import {LightningElementtrackfrom 'lwc';
export default class cmpShowModelPopUp extends LightningElement {
    @track isOpenModal = false;
    handleOpenModal() {
        this.isOpenModal = true;
    }
    handleCloseModal() {
        this.isOpenModal = false;
    }
}

cmpShowModelPopUp.js-meta.xml
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>48.0</apiVersion>
    <isExposed>true</isExposed>
    <targets>
        <target>lightning__AppPage</target>
        <target>lightning__RecordPage</target>
        <target>lightning__HomePage</target>
        <target>lightning__Tab</target>
      </targets>
</LightningComponentBundle>

Output:

Other Useful Blog

Lightning Component

Happy Learning !!


Comments

Popular posts from this blog

LWC Show Records In Table

Requirement : ‹ › Create a LWC component which will show the most recently created 10 Opportunity from the org and show them in table having Name , Close Date , Stage Name , Type and Create . or in other words Show Opportunity data in table format. cmpOpportunityRecords.html < template >      < lightning-card   title = "Opportunity Records"   icon-name = "standard:opportunity" >                  < lightning-datatable                            data = {data}                columns = {columns}                key-field = "Id" >          </ lightning-...

LWC Development Environment

Requirement : ‹ › Setup LWC Development Environment  1. VS (Visual Stdio) Code 2. Salesforce CLI Download and install the latest version of  Visual Studio Code . Open the Visual Studio Code and add extensions by clicking on the extensions icon present on the left side of the VS code editor. Search for  Salesforce Extension Pack  and install the extension. After that install  Lightning Web Components extension. Once you done with installing the above two extensions Re-launch the VS code editor. Now it’s time to check that our environment is ready for creating Lightning Web Components by pressing  Command + Shift + P  on  macOS or Ctrl + Shift + P  on Windows and type  sfdx . Hola..!! you are now ready to create your Lightning Web Components. Creating SFDX Project First create a folder somewhere on your machine and name it  trailblazer  or anything of your choice. Navigate to that folder from VS code ...

LWC Component Only

Requirement : ‹ › Create a LWC having two input fields which will take two number as input and show result, addition happen on button click. cmpAddition.html < template >      < lightning-card   title = "Addition"   icon-name = "custom:custom62" >                   < p   class = "slds-p-horizontal_small" >              < lightning-input                    value = {firstNumber}                    name = "fnumber"                    label = "First Number"             ...