You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Connected.Components/src/Connected.Components/Components/Image/Image.razor.cs

85 lines
1.9 KiB

// Copyright (c) MudBlazor 2021
// MudBlazor licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using Connected.Extensions;
using Connected.Utilities;
using Microsoft.AspNetCore.Components;
namespace Connected.Components;
public partial class Image : UIComponent
{
#region Content
/// <summary>
/// Specifies the path to the image.
/// </summary>
[Parameter]
public string Src { get; set; }
/// <summary>
/// Specifies an alternate text for the image.
/// </summary>
[Parameter]
public string Alt { get; set; }
#endregion
#region Styling
/// <summary>
/// Specifies the height of the image in px.
/// </summary>
[Parameter]
public int? Height { get; set; }
/// <summary>
/// Specifies the width of the image in px.
/// </summary>
[Parameter]
public int? Width { get; set; }
/// <summary>
/// The higher the number, the heavier the drop-shadow.
/// </summary>
[Parameter]
public int Elevation { set; get; }
private CssBuilder CompiledClassList
{
get
{
return new CssBuilder("image")
.AddClass("fluid", Fluid)
.AddClass($"object-{ObjectFit.ToDescription()}")
.AddClass($"object-{ObjectPosition.ToDescription()}")
.AddClass($"elevation-{Elevation}", Elevation > 0)
.AddClass(ClassList);
}
}
/// <summary>
/// Applies the fluid class so the image scales with the parent width.
/// </summary>
[Parameter]
public bool Fluid { get; set; }
/// <summary>
/// Controls how the image should be resized.
/// </summary>
[Parameter]
public ObjectFit ObjectFit { set; get; } = ObjectFit.Fill;
/// <summary>
/// Controls how the image should positioned within its container.
/// </summary>
[Parameter]
public Position ObjectPosition { set; get; } = Position.Center;
/// <summary>
/// A space separated list of class names, added on top of the default class list.
/// </summary>
[Parameter]
public string? ClassList { get; set; }
#endregion
}