8000 Card component by albx · Pull Request #16 · albx/bitblazor · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions BitBlazor.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
# Visual Studio Version 18
VisualStudioVersion = 18.0.10828.68 main
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{827E0CD3-B72D-47B6-A68D-7590B98EB39B}"
EndProject
Expand Down
2 changes: 1 addition & 1 deletion src/BitBlazor/BitBlazor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="9.0.6" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="9.0.8" />
</ItemGroup>

</Project>
8 changes: 8 additions & 0 deletions src/BitBlazor/Components/Button/ButtonBadge.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

namespace BitBlazor.Components;

/// <summary>
/// Represents a badge component that displays text and integrates with a parent button.
/// </summary>
/// <remarks>
/// The <see cref="ButtonBadge"/> is designed to be used in conjunction with a <see cref="BitButton"/> component.
/// It displays a badge with customizable text and optional additional context for assistive technologies.
/// The badge's appearance is influenced by the parent button's properties, such as its variant and color.
/// </remarks>
public partial class ButtonBadge
{
[CascadingParameter]
Expand Down
7 changes: 7 additions & 0 deletions src/BitBlazor/Components/Card/BitCard.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@namespace BitBlazor.Components

<CascadingValue Value="this">
<article class="@ComputedCssClasses">
@ChildContent
</article>
</CascadingValue>
172 changes: 172 additions & 0 deletions src/BitBlazor/Components/Card/BitCard.razor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
using Microsoft.AspNetCore.Components;

namespace BitBlazor.Components;

/// <summary>
/// Represents a card component using Bootstrap Italia styles.
/// </summary>
public partial class BitCard
{
/// <summary>
/// Gets or sets the content of the card
/// </summary>
[Parameter]
public RenderFragment ChildContent { get; set; } = default!;

/// <summary>
/// Gets or sets the type of the card
/// </summary>
/// <remarks>
/// Set this property in order to display the different types of card (inline cards, profile cards or banner cards)
/// </remarks>
[Parameter]
public CardType Type { get; set; } = CardType.Default;

/// <summary>
/// Gets or sets whether the component should display a border. (default true)
/// </summary>
[Parameter]
public bool Bordered { get; set; } = true;

/// <summary>
/// Gets or sets the shadow style applied to the card.
/// </summary>
[Parameter]
public CardShadow Shadow { get; set; } = CardShadow.Small;

/// <summary>
/// Gets or sets whether the component should occupy the full height of its container.
/// </summary>
[Parameter]
public bool FullHeight { get; set; }

/// <summary>
/// Gets or sets a value indicating whether the content should be rendered inline.
/// </summary>
[Parameter]
public bool Inline { get; set; }

/// <summary>
/// Gets or sets whether display the inline card in reverse mode.
/// </summary>
/// <remarks>This parameter works only when the card is Inline</remarks>
[Parameter]
public bool Reverse { get; set; }

/// <summary>
/// Gets or sets whether display the inline card as mini variant.
/// </summary>
/// <remarks>This parameter works only when the card is Inline</remarks>
[Parameter]
public bool Mini { get; set; }

/// <summary>
/// Gets or sets additional css classes
/// </summary>
[Parameter]
public string? CssClass { get; set; }

/// <summary>
/// Gets or sets the color of the top border of the card.
/// </summary>
[Parameter]
public Color? BorderTopColor { get; set; }

private string ComputedCssClasses => $"it-card rounded {ComputeCssClasses()}".Trim();

#region Image management
private bool hasImage = false;

internal void NotifyHasImageChanged(bool hasImage)
{
this.hasImage = hasImage;
StateHasChanged();
}
#endregion

private string ComputeCssClasses()
{
var cssClasses = new List<string>();

switch (Type)
{
case CardType.Profile:
cssClasses.Add("it-card-profile");
break;
case CardType.Banner:
cssClasses.Add("it-card-banner");
break;
default:
break;
}

if (Inline)
{
AddInlineClasses(cssClasses);
}

if (Bordered)
{
cssClasses.Add("border");
}

var shadowClass = Shadow switch
{
CardShadow.Small => "shadow-sm",
CardShadow.Medium => "shadow",
CardShadow.Large => "shadow-lg",
_ => string.Empty
};
cssClasses.Add(shadowClass);

if (FullHeight)
{
cssClasses.Add("it-card-height-full");
}

if (hasImage)
{
cssClasses.Add("it-card-image");
}

if (!string.IsNullOrWhiteSpace(CssClass))
{
cssClasses.Add(CssClass);
}

if (BorderTopColor.HasValue)
{
cssClasses.Add("it-card-border-top");
var borderTopColorClass = BorderTopColor.Value switch
{
Color.Primary => "it-card-border-top-primary",
Color.Secondary => "it-card-border-top-secondary",
Color.Success => "it-card-border-top-success",
Color.Warning => "it-card-border-top-warning",
Color.Danger => "it-card-border-top-danger",
_ => string.Empty
};

if (!string.IsNullOrEmpty(borderTopColorClass))
{
cssClasses.Add(borderTopColorClass);
}
}

return string.Join(" ", cssClasses);
}

private void AddInlineClasses(List<string> cssClasses)
{
cssClasses.Add("it-card-inline");

if (Mini)
{
cssClasses.Add("it-card-inline-mini");
}
if (Reverse)
{
cssClasses.Add("it-card-inline-reverse");
}
}
}
8 changes: 8 additions & 0 deletions src/BitBlazor/Components/Card/CardBannerIcon.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@namespace BitBlazor.Components

<div class="it-card-banner-icon-wrapper">
<BitIcon IconName="@Icon"
Color="IconColor"
Size="IconSize.ExtraLarge"
AriaHidden="AriaHidden"/>
</div>
32 changes: 32 additions & 0 deletions src/BitBlazor/Components/Card/CardBannerIcon.razor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using BitBlazor.Utilities;
using Microsoft.AspNetCore.Components;

namespace BitBlazor.Components;

/// <summary>
/// Represents the container for the icon displayed in the card banner.
/// </summary>
public partial class CardBannerIcon
{
[CascadingParameter]
BitCard Parent { get; set; } = default!;

/// <summary>
/// Gets or sets the icon to be displayed in the profile section.
/// </summary>
[Parameter]
[EditorRequired]
public string Icon { get; set; } = string.Empty;

/// <summary>
/// Gets or sets the color of the icon.
/// </summary>
[Parameter]
public IconColor IconColor { get; set; } = IconColor.Primary;

/// <summary>
/// Gets or sets a value indicating whether the element is hidden from assistive technologies.
/// </summary>
[Parameter]
public bool AriaHidden { get; set; }
}
5 changes: 5 additions & 0 deletions src/BitBlazor/Components/Card/CardBody.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@namespace BitBlazor.Components

<div class="it-card-body">
@ChildContent
</div>
18 changes: 18 additions & 0 deletions src/BitBlazor/Components/Card/CardBody.razor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Microsoft.AspNetCore.Components;

namespace BitBlazor.Components;

/// <summary>
/// Represents the body of the card
/// </summary>
public partial class CardBody
{
[CascadingParameter]
BitCard Parent { get; set; } = default!;

/// <summary>
/// Gets or sets the content of the card body
/// </summary>
[Parameter]
public RenderFragment ChildContent { get; set; } = default!;
}
5 changes: 5 additions & 0 deletions src/BitBlazor/Components/Card/CardDate.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@namespace BitBlazor.Components

<time class="@ComputeCssClasses()" datetime="@FormattedDatetimeValue">
@FormattedDisplayDate
</time>
68 changes: 68 additions & 0 deletions src/BitBlazor/Components/Card/CardDate.razor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using Microsoft.AspNetCore.Components;

namespace BitBlazor.Components;

/// <summary>
/// Represents the element which display the date on a card component
/// </summary>
public partial class CardDate
{
[CascadingParameter]
BitCard Parent { get; set; } = default!;

/// <summary>
/// Gets or sets the date to be displayed in the card.
/// </summary>
[Parameter]
[EditorRequired]
public DateTime Date { get; set; }

/// <summary>
/// Gets or sets the format string used to display the value in the datetime attribute
/// </summary>
/// <remarks>
/// For the list of valid datetime values, please refer to the official documentation: https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/time#valid_datetime_values
/// </remarks>
[Parameter]
[EditorRequired]
public string DatetimeFormat { get; set; } = "yyyy-MM-dd";

/// <summary>
/// Gets or sets the format for displaying the date.
/// </summary>
[Parameter]
[EditorRequired]
public string DisplayFormat { get; set; } = string.Empty;

/// <summary>
/// Gets or sets the color of the text
/// </summary>
[Parameter]
public Color? TextColor { get; set; }

private string FormattedDatetimeValue => string.IsNullOrEmpty(DatetimeFormat) ? Date.ToString("yyyy-MM-dd") : Date.ToString(DatetimeFormat);

private string FormattedDisplayDate => string.IsNullOrEmpty(DisplayFormat) ? Date.ToString() : Date.ToString(DisplayFormat);

private string ComputeCssClasses()
{
List<string> cssClasses = ["it-card-date"];

if (TextColor.HasValue)
{
var textColorClass = TextColor.Value switch
{
Color.Primary => "text-primary",
Color.Secondary => "text-secondary",
Color.Warning => "text-warning",
Color.Success => "text-success",
Color.Danger => "text-danger",
_ => string.Empty
};

cssClasses.Add(textColorClass);
}

return string.Join(" ", cssClasses);
}
}
5 changes: 5 additions & 0 deletions src/BitBlazor/Components/Card/CardFooter.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@namespace BitBlazor.Components

<footer class="@ComputeCssClasses()" @attributes="attributes">
@ChildContent
</footer>
Loading
0