2022-06-25 20:56:51 +08:00
|
|
|
|
// Licensed to the .NET Foundation under one or more agreements.
|
|
|
|
|
// The .NET Foundation licenses this file to you under the MIT license.
|
|
|
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
|
|
|
|
|
|
namespace AntDesign
|
|
|
|
|
{
|
|
|
|
|
public partial class SegmentedItem<TValue> : AntDomComponentBase
|
|
|
|
|
{
|
|
|
|
|
[Parameter]
|
|
|
|
|
public TValue Value { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public string Label { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public bool Disabled { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public RenderFragment ChildContent { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public string Icon { get; set; }
|
|
|
|
|
|
|
|
|
|
[CascadingParameter]
|
|
|
|
|
private Segmented<TValue> Parent { get; set; }
|
|
|
|
|
|
|
|
|
|
protected string PrefixCls => "ant-segmented-item";
|
|
|
|
|
|
|
|
|
|
private bool _selected;
|
|
|
|
|
|
|
|
|
|
protected override void OnInitialized()
|
|
|
|
|
{
|
|
|
|
|
base.OnInitialized();
|
|
|
|
|
|
|
|
|
|
ClassMapper.Add(PrefixCls)
|
|
|
|
|
.If($"{PrefixCls}-selected", () => _selected)
|
2022-11-09 17:40:16 +08:00
|
|
|
|
.If($"{PrefixCls}-disabled", () => Disabled || Parent?.Disabled == true)
|
2022-06-25 20:56:51 +08:00
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
Parent?.AddItem(this);
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-11 09:21:46 +08:00
|
|
|
|
protected internal void SetSelected(bool selected)
|
2022-06-25 20:56:51 +08:00
|
|
|
|
{
|
|
|
|
|
_selected = selected;
|
|
|
|
|
|
|
|
|
|
StateHasChanged();
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-11 09:21:46 +08:00
|
|
|
|
protected internal void MarkStateHasChanged() => StateHasChanged();
|
|
|
|
|
|
2022-06-25 20:56:51 +08:00
|
|
|
|
private void OnClick()
|
|
|
|
|
{
|
2022-10-11 09:21:46 +08:00
|
|
|
|
if (Disabled || Parent.Disabled)
|
2022-06-25 20:56:51 +08:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Parent.Select(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Dispose(bool disposing)
|
|
|
|
|
{
|
|
|
|
|
Parent?.RemoveItem(this);
|
|
|
|
|
base.Dispose(disposing);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|