32 lines
1.3 KiB
Plaintext
32 lines
1.3 KiB
Plaintext
@inherits DComponentBase
|
|||
|
|
@implements IDisposable
|
||
|
|
|
||
|
|
@* One item of a DAccordion: a DCollapse (so collapse + neo-raised, keyboard and aria-expanded come from there) whose
|
||
|
|
open state is the accordion's Active index. Opening it closes the others; clicking it while open closes it. *@
|
||
|
|
<DCollapse @attributes="AdditionalAttributes" IsOpen="@IsOpen" IsOpenChanged="OnIsOpenChanged" Icon="@Parent.Icon"
|
||
|
|
Disabled="@Disabled" HeaderClass="@HeaderClass" ContentClass="@ContentClass" Header="@Header"
|
||
|
|
Class="@Cx(Parent.Joined ? "join-item shadow-none!" : null, Class)">
|
||
|
|
@ChildContent
|
||
|
|
</DCollapse>
|
||
|
|
|
||
|
|
@code {
|
||
|
|
[CascadingParameter] DAccordion Parent { get; set; }
|
||
|
|
[Parameter] public RenderFragment Header { get; set; }
|
||
|
|
[Parameter] public RenderFragment ChildContent { get; set; }
|
||
|
|
[Parameter] public bool Disabled { get; set; }
|
||
|
|
[Parameter] public string HeaderClass { get; set; }
|
||
|
|
[Parameter] public string ContentClass { get; set; }
|
||
|
|
|
||
|
|
bool IsOpen => Parent.Active >= 0 && Parent.Active == Parent.IndexOf(this);
|
||
|
|
|
||
|
|
protected override void OnInitialized()
|
||
|
|
{
|
||
|
|
if (Parent is null)
|
||
|
|
throw new InvalidOperationException($"{nameof(DAccordionItem)} must be inside a {nameof(DAccordion)}.");
|
||
|
|
Parent.Add(this);
|
||
|
|
}
|
||
|
|
|
||
|
|
Task OnIsOpenChanged(bool isOpen) => Parent.Select(isOpen ? Parent.IndexOf(this) : -1);
|
||
|
|
|
||
|
|
public void Dispose() => Parent?.Remove(this);
|
||
|
|
}
|