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/Components/Carousel/CarouselItem.razor.cs

92 lines
4.0 KiB

using Connected.Annotations;
using Connected.Extensions;
using Connected.Utilities;
using Microsoft.AspNetCore.Components;
namespace Connected.Components;
public partial class CarouselItem : UIComponent, IDisposable
{
protected string Classname =>
new CssBuilder("mud-carousel-item")
.AddClass($"mud-carousel-item-{Color.ToDescriptionString()}")
.AddClass("mud-carousel-item-exit", !_disposed && Parent.LastContainer == this)
.AddClass("mud-carousel-transition-fade-in", !_disposed && Transition == Transition.Fade && Parent.SelectedContainer == this)
.AddClass("mud-carousel-transition-fade-out", !_disposed && Transition == Transition.Fade && Parent.LastContainer == this)
.AddClass("mud-carousel-transition-slide-next-enter", !_disposed && Transition == Transition.Slide && RightToLeft == false && Parent.SelectedContainer == this && Parent._moveNext)
.AddClass("mud-carousel-transition-slide-next-exit", !_disposed && Transition == Transition.Slide && RightToLeft == false && Parent.LastContainer == this && Parent._moveNext)
.AddClass("mud-carousel-transition-slide-prev-enter", !_disposed && Transition == Transition.Slide && RightToLeft == false && Parent.SelectedContainer == this && !Parent._moveNext)
.AddClass("mud-carousel-transition-slide-prev-exit", !_disposed && Transition == Transition.Slide && RightToLeft == false && Parent.LastContainer == this && !Parent._moveNext)
.AddClass("mud-carousel-transition-slide-next-rtl-enter", !_disposed && Transition == Transition.Slide && RightToLeft == true && Parent.SelectedContainer == this && Parent._moveNext)
.AddClass("mud-carousel-transition-slide-next-rtl-exit", !_disposed && Transition == Transition.Slide && RightToLeft == true && Parent.LastContainer == this && Parent._moveNext)
.AddClass("mud-carousel-transition-slide-prev-rtl-enter", !_disposed && Transition == Transition.Slide && RightToLeft == true && Parent.SelectedContainer == this && !Parent._moveNext)
.AddClass("mud-carousel-transition-slide-prev-rtl-exit", !_disposed && Transition == Transition.Slide && RightToLeft == true && Parent.LastContainer == this && !Parent._moveNext)
.AddClass("mud-carousel-transition-none", !_disposed && Transition == Transition.None && Parent.SelectedContainer != this)
.AddClass(CustomTransitionEnter, !_disposed && Transition == Transition.Custom && Parent.SelectedContainer == this && Parent.SelectedContainer == this)
.AddClass(CustomTransitionExit, !_disposed && Transition == Transition.Custom && Parent.LastContainer == this && Parent.LastContainer == this)
.AddClass(Class)
.Build();
[Parameter]
[Category(CategoryTypes.Carousel.Behavior)]
public RenderFragment ChildContent { get; set; }
[CascadingParameter] protected internal ItemsControlBase<CarouselItem> Parent { get; set; }
[CascadingParameter(Name = "RightToLeft")] public bool RightToLeft { get; set; }
/// <summary>
/// The color of the component. It supports the theme colors.
/// </summary>
[Parameter]
[Category(CategoryTypes.Carousel.Appearance)]
public ThemeColor Color { get; set; } = ThemeColor.Default;
/// <summary>
/// The transition effect of the component.
/// </summary>
[Parameter]
[Category(CategoryTypes.Carousel.Appearance)]
public Transition Transition { get; set; } = Transition.Slide;
/// <summary>
/// The name of custom transition on entrance time
/// </summary>
[Parameter]
[Category(CategoryTypes.Carousel.Appearance)]
public string CustomTransitionEnter { get; set; }
/// <summary>
/// The name of custom transition on exiting time
/// </summary>
[Parameter]
[Category(CategoryTypes.Carousel.Appearance)]
public string CustomTransitionExit { get; set; }
public bool IsVisible => Parent != null && (Parent.LastContainer == this || Parent.SelectedIndex == Parent.Items.IndexOf(this));
protected override Task OnInitializedAsync()
{
Parent?.AddItem(this);
return Task.CompletedTask;
}
private bool _disposed = false;
public void Dispose()
{
_disposed = true;
Parent?.Items.Remove(this);
}
}