Lightning Web Components
Kumaresan  

Custom Hero / Image Banner LWC Component in LWC

A “hero / Image Banner” component in Lightning Web Components (LWC) is a custom element that can be used to display important information or content on a page. It typically includes a large image or visual element, a headline, and some supporting text or information. The exact design and functionality of a hero component will depend on the specific implementation and requirements of your project.

Here’s an example of a basic hero component in Lightning Web Components (LWC):

<template>
    <div class="hero">
        <img src={imageUrl} alt="Hero Image" />
        <h1>{title}</h1>
        <p>{description}</p>
    </div>
</template>
import { LightningElement, api } from 'lwc';

export default class MyHero extends LightningElement {
    @api imageUrl;
    @api title;
    @api description;
}

This component uses the @api decorator to define properties that can be passed in from the parent component. The properties are:

  • imageUrl: url of the image to be displayed
  • title: the title of the hero component
  • description: the description of the hero component

You can use this component in another component or app as follows:

<template>
    <c-my-hero image-url={imageUrl} title={title} description={description}>
    </c-my-hero>
</template>
import { LightningElement } from 'lwc';

export default class MyApp extends LightningElement {
    imageUrl = 'path/to/image.jpg';
    title = 'My Hero Component';
    description = 'Learn how to create a hero component in LWC';
}

This is a basic example and you can customize it as per your needs and requirements.

Leave A Comment