diff --git a/DotnetViewComponents/ViewComponents/HeroViewComponent.cs b/DotnetViewComponents/ViewComponents/HeroViewComponent.cs new file mode 100644 index 0000000000..cfd47adcd8 --- /dev/null +++ b/DotnetViewComponents/ViewComponents/HeroViewComponent.cs @@ -0,0 +1,21 @@ +namespace DotnetViewComponents.ViewComponents +{ + using Microsoft.AspNetCore.Mvc; + using DotnetViewComponents.ViewModels; + + /// + /// A ViewComponent that rendes a hero section. + /// + public class HeroViewComponent : ViewComponent + { + public IViewComponentResult Invoke( + string? imageSrc = null, + string? heading = null, + string? textContent = null) + { + var model = new HeroViewModel(imageSrc, heading, textContent); + + return View(model); + } + } +} diff --git a/DotnetViewComponents/ViewModels/HeroViewModel.cs b/DotnetViewComponents/ViewModels/HeroViewModel.cs new file mode 100644 index 0000000000..e1a79313c5 --- /dev/null +++ b/DotnetViewComponents/ViewModels/HeroViewModel.cs @@ -0,0 +1,36 @@ +namespace DotnetViewComponents.ViewModels +{ + public class HeroViewModel + { + /// + /// Initializes a new instance of the class. + /// + /// The source URL of the hero image. + /// The heading text for the hero section. + /// The main text content for the hero section. + public HeroViewModel( + string? imageSrc, + string? heading, + string? textContent) + { + ImageSrc = imageSrc; + Heading = heading; + TextContent = textContent; + } + + /// + /// Gets or sets the source URL of the hero image. + /// + public string? ImageSrc { get; set; } + + /// + /// Gets or sets the heading text for the hero section. + /// + public string? Heading { get; set;} + + /// + /// Gets or sets the main text content for the hero section. + /// + public string? TextContent { get; set;} + } +} diff --git a/DotnetViewComponents/Views/Shared/Components/Hero/Default.cshtml b/DotnetViewComponents/Views/Shared/Components/Hero/Default.cshtml new file mode 100644 index 0000000000..1192841720 --- /dev/null +++ b/DotnetViewComponents/Views/Shared/Components/Hero/Default.cshtml @@ -0,0 +1,33 @@ +@using DotnetViewComponents.ViewModels +@model HeroViewModel + +@{ + var hasImage = !String.IsNullOrWhiteSpace(Model.ImageSrc); + var hasHeading = !String.IsNullOrWhiteSpace(Model.Heading); + var hasTextContent = !String.IsNullOrWhiteSpace(Model.TextContent); +} + + + @if (hasHeading || hasTextContent) + { + + + + + @if (hasHeading) + { + @Model.Heading + } + @if (hasTextContent) + { + @Model.TextContent + } + + + + + + + } + +
@Model.TextContent