mirror of
https://gitee.com/ant-design-blazor/ant-design-blazor.git
synced 2024-12-15 09:21:24 +08:00
555fdb9a43
* fix(module:checkbox): allow binding to Checked parameter * fix(module:switch): allow binding to Checked parameter * fix(modules): checkbox & switch get AntInputBoolComponentBase class * test(module:switch): add tests * test(module:checkbox): add tests * test(module:divider): simplify by using id:ignore * docs(module:checkbox): bind example * docs(module:switch): bind example * fix(module:switch): add Control + docs + tests * feat(module:checkboxgroup): add layout and mixed mode * fix: review comments + tests * fix(module:checkboxgroup): parameter name should be MixedMode added more tests * fix demo * fix(module:checkboxgroup): allow toggling between modes Co-authored-by: James Yeung <shunjiey@hotmail.com>
70 lines
2.0 KiB
C#
70 lines
2.0 KiB
C#
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.AspNetCore.Components.Web;
|
|
|
|
namespace AntDesign
|
|
{
|
|
public partial class Switch : AntInputBoolComponentBase
|
|
{
|
|
[Parameter]
|
|
public bool Loading { get; set; }
|
|
|
|
[Parameter]
|
|
public string CheckedChildren { get; set; } = string.Empty;
|
|
|
|
[Parameter]
|
|
public RenderFragment CheckedChildrenTemplate { get; set; }
|
|
|
|
/// <summary>
|
|
/// The status of Switch is completely up to the user and no longer
|
|
/// automatically changes the data based on the click event.
|
|
/// </summary>
|
|
[Parameter]
|
|
public bool Control { get; set; }
|
|
|
|
[Parameter]
|
|
public EventCallback OnClick { get; set; }
|
|
|
|
[Parameter]
|
|
public string UnCheckedChildren { get; set; } = string.Empty;
|
|
|
|
[Parameter]
|
|
public RenderFragment UnCheckedChildrenTemplate { get; set; }
|
|
|
|
private bool _clickAnimating = false;
|
|
|
|
private string _prefixCls = "ant-switch";
|
|
|
|
protected override void OnInitialized()
|
|
{
|
|
base.OnInitialized();
|
|
SetClass();
|
|
}
|
|
|
|
protected void SetClass()
|
|
{
|
|
ClassMapper.Clear()
|
|
.Add(_prefixCls)
|
|
.If($"{_prefixCls}-checked", () => CurrentValue)
|
|
.If($"{_prefixCls}-disabled", () => Disabled || Loading)
|
|
.If($"{_prefixCls}-loading", () => Loading)
|
|
.If($"{_prefixCls}-small", () => Size == "small")
|
|
.If($"{_prefixCls}-rtl", () => RTL);
|
|
;
|
|
}
|
|
|
|
private async Task HandleClick(MouseEventArgs e)
|
|
{
|
|
if (!Control)
|
|
await base.ChangeValue(!CurrentValue);
|
|
if (OnClick.HasDelegate)
|
|
await OnClick.InvokeAsync(null);
|
|
}
|
|
|
|
private void HandleMouseOver(MouseEventArgs e) => _clickAnimating = true;
|
|
|
|
private void HandleMouseOut(MouseEventArgs e) => _clickAnimating = false;
|
|
|
|
}
|
|
}
|