@if (Variant == CardVariant.Product) { if (ShowBadges && (Badges is not null || BadgesContent is not null)) {
@Badges @BadgesContent
} if (ShowActions && Actions is not null) {
@Actions
}
@if (Image is not null) { @Image } else if (!string.IsNullOrWhiteSpace(ImagePlaceholderText)) { @ImagePlaceholderText }
@if (ShowMeta && Meta is not null) {
@Meta
} @if (ShowHeading && Heading is not null) {
@Heading
} @if (ShowRating && Rating is not null) {
@Rating
} @if (ShowDescription && Description is not null) {
@Description
} @if (ShowPrices && Prices is not null) {
@Prices
} @if (ShowFooter && Footer is not null) {
@Footer
}
} else if (Variant == CardVariant.Category) { if (!string.IsNullOrWhiteSpace(LinkHref)) { @CategoryContent } else { @CategoryContent } }
@code { private const string ProductRootClass = "product-card"; private const string ProductLayoutGridClass = "product-card--layout--grid"; private const string ProductLayoutListClass = "product-card--layout--list"; private const string CategoryRootClass = "card"; private const string CategoryCardClass = "category-card"; [Parameter] public CardVariant Variant { get; set; } = CardVariant.Product; [Parameter] public string Layout { get; set; } = "grid"; [Parameter] public string CssClass { get; set; } = string.Empty; [Parameter] public string ImagePlaceholderText { get; set; } = "Image coming soon"; [Parameter] public string? LinkHref { get; set; } [Parameter] public string? LinkTarget { get; set; } [Parameter] public string? LinkRel { get; set; } [Parameter] public EventCallback OnLinkClick { get; set; } [Parameter] public RenderFragment? Badges { get; set; } [Parameter] public RenderFragment? BadgesContent { get; set; } [Parameter] public RenderFragment? Actions { get; set; } [Parameter] public RenderFragment? Image { get; set; } [Parameter] public RenderFragment? Meta { get; set; } [Parameter] public RenderFragment? Heading { get; set; } [Parameter] public RenderFragment? Rating { get; set; } [Parameter] public RenderFragment? Description { get; set; } [Parameter] public RenderFragment? Prices { get; set; } [Parameter] public RenderFragment? Footer { get; set; } [Parameter(CaptureUnmatchedValues = true)] public IReadOnlyDictionary? AdditionalAttributes { get; set; } [Parameter] public bool ShowBadges { get; set; } = true; [Parameter] public bool ShowActions { get; set; } = true; [Parameter] public bool ShowMeta { get; set; } = true; [Parameter] public bool ShowHeading { get; set; } = true; [Parameter] public bool ShowRating { get; set; } = true; [Parameter] public bool ShowDescription { get; set; } = true; [Parameter] public bool ShowPrices { get; set; } = true; [Parameter] public bool ShowFooter { get; set; } = true; private string RootClass => Variant switch { CardVariant.Category => BuildClass(CategoryRootClass, CategoryCardClass, CssClass), _ => BuildClass(ProductRootClass, ResolveLayoutClass(), CssClass) }; private string ResolveLayoutClass() => string.Equals(Layout, "list", StringComparison.OrdinalIgnoreCase) ? ProductLayoutListClass : ProductLayoutGridClass; private static string BuildClass(params string?[] values) { var parts = new List(values.Length); foreach (var value in values) { if (!string.IsNullOrWhiteSpace(value)) { parts.Add(value); } } return string.Join(" ", parts); } private RenderFragment CategoryContent => @ @if (Image is not null) {
@Image
} else if (!string.IsNullOrWhiteSpace(ImagePlaceholderText)) {
@ImagePlaceholderText
} @if (Heading is not null) {
@Heading
} @if (Description is not null) {
@Description
} @if (Footer is not null) { @Footer }
; private Task HandleLinkClickAsync(MouseEventArgs args) => OnLinkClick.HasDelegate ? OnLinkClick.InvokeAsync(args) : Task.CompletedTask; }