2024-10-19 21:14:38 +02:00
|
|
|
using Microsoft.AspNetCore.Components;
|
2025-03-03 00:56:32 +01:00
|
|
|
using WatchIt.DTO.Models.Generics.Image;
|
2024-10-19 21:14:38 +02:00
|
|
|
|
2025-03-03 00:56:32 +01:00
|
|
|
namespace WatchIt.Website.Components.Subcomponents.Common;
|
2024-10-19 21:14:38 +02:00
|
|
|
|
2025-03-03 00:56:32 +01:00
|
|
|
public partial class Image : Component
|
2024-10-19 21:14:38 +02:00
|
|
|
{
|
|
|
|
|
#region PARAMETERS
|
|
|
|
|
|
2025-03-03 00:56:32 +01:00
|
|
|
[Parameter] public ImageBase? Content { get; set; }
|
2024-10-19 21:14:38 +02:00
|
|
|
[Parameter] public required string Placeholder { get; set; }
|
2025-03-03 00:56:32 +01:00
|
|
|
[Parameter] public ImageComponentAspectRatio AspectRatio { get; set; } = ImageComponentAspectRatio.Default;
|
2024-10-19 21:14:38 +02:00
|
|
|
[Parameter] public string AlternativeText { get; set; } = "picture";
|
|
|
|
|
[Parameter] public string Class { get; set; } = string.Empty;
|
2024-10-19 22:05:53 +02:00
|
|
|
[Parameter] public int? Height { get; set; }
|
|
|
|
|
[Parameter] public int? Width { get; set; }
|
2024-11-03 23:01:34 +01:00
|
|
|
[Parameter] public bool Circle { get; set; }
|
|
|
|
|
[Parameter] public bool Shadow { get; set; } = true;
|
2024-10-19 22:05:53 +02:00
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region FIELDS
|
|
|
|
|
|
|
|
|
|
private Dictionary<string, object> _attributes = [];
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region PRIVATE METHODS
|
|
|
|
|
|
|
|
|
|
protected override void OnParametersSet()
|
|
|
|
|
{
|
|
|
|
|
_attributes.Clear();
|
|
|
|
|
if (Height.HasValue)
|
|
|
|
|
{
|
|
|
|
|
_attributes.Add("height", Height.Value);
|
|
|
|
|
}
|
|
|
|
|
else if (Width.HasValue)
|
|
|
|
|
{
|
|
|
|
|
_attributes.Add("width", Width.Value);
|
|
|
|
|
}
|
2024-11-03 23:01:34 +01:00
|
|
|
|
|
|
|
|
if (Circle)
|
|
|
|
|
{
|
2025-03-03 00:56:32 +01:00
|
|
|
AspectRatio = ImageComponentAspectRatio.Square;
|
2024-11-03 23:01:34 +01:00
|
|
|
}
|
2024-10-19 22:05:53 +02:00
|
|
|
}
|
2024-10-19 21:14:38 +02:00
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region STRUCTS
|
|
|
|
|
|
2025-03-03 00:56:32 +01:00
|
|
|
public struct ImageComponentAspectRatio
|
2024-10-19 21:14:38 +02:00
|
|
|
{
|
|
|
|
|
#region Properties
|
|
|
|
|
|
|
|
|
|
public int Vertical { get; set; }
|
|
|
|
|
public int Horizontal { get; set; }
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region Constructors
|
|
|
|
|
|
2025-03-03 00:56:32 +01:00
|
|
|
public ImageComponentAspectRatio() : this(3, 5) {}
|
2024-10-19 21:14:38 +02:00
|
|
|
|
2025-03-03 00:56:32 +01:00
|
|
|
public ImageComponentAspectRatio(int horizontal, int vertical)
|
2024-10-19 21:14:38 +02:00
|
|
|
{
|
|
|
|
|
Horizontal = horizontal;
|
|
|
|
|
Vertical = vertical;
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-03 00:56:32 +01:00
|
|
|
public static readonly ImageComponentAspectRatio Default = new ImageComponentAspectRatio();
|
|
|
|
|
public static readonly ImageComponentAspectRatio Photo = new ImageComponentAspectRatio(16, 9);
|
|
|
|
|
public static readonly ImageComponentAspectRatio Square = new ImageComponentAspectRatio(1, 1);
|
2024-10-19 21:14:38 +02:00
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region Public methods
|
|
|
|
|
|
|
|
|
|
public override string ToString() => $"{Horizontal}/{Vertical}";
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|