
Switch Button state switch button
Toggle state after button click
Initialize component state by setting ToggleState
Demo
The current component state can be obtained by setting the <code>ToggleStateChanged</code> callback method
OnInitialize component state by setting ToggleState
Demo
<code>OnClick</code> callback is <code>EventCallback</code> will automatically refresh the current component or page, if you don't need to refresh the component or page, you can use <code>ToggleStateChanged</code>
OffAttributes
@page "/switchbuttons"
@inject IStringLocalizer<SwitchButtons> Localizer
<h3>Switch Button state switch button</h3>
<h4>Toggle state after button click</h4>
<DemoBlock Title="Basic usage" Introduction="Click the component to automatically switch the state" Name="Normal">
<SwitchButton />
</DemoBlock>
<DemoBlock Title="initialized state" Introduction="Initialize component state by setting <code>ToggleState</code>" Name="ToggleState">
<p>The current component state can be obtained by setting the <code>ToggleStateChanged</code> callback method</p>
<SwitchButton ToggleState="ToggleState" />
</DemoBlock>
<DemoBlock Title="click callback method" Introduction="Initialize component state by setting <code>ToggleState</code>" Name="OnClick">
<p><code>OnClick</code> callback is <code>EventCallback</code> will automatically refresh the current component or page, if you don't need to refresh the component or page, you can use <code>ToggleStateChanged</code></p>
<SwitchButton OnClick="OnClick" />
<BlockLogger @ref="Trace" class="mt-3" />
</DemoBlock>
<AttributeTable Items="@GetAttributes()" />
// Copyright (c) Argo Zhang (argo@163.com). All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Website: https://www.blazor.zone or https://argozhang.github.io/
namespace BootstrapBlazor.Shared.Samples;
/// <summary>
///
/// </summary>
public partial class SwitchButtons
{
private bool ToggleState { get; set; } = true;
[NotNull]
private BlockLogger? Trace { get; set; }
private void OnClick()
{
Trace.Log("Clicked");
}
/// <summary>
/// 获得属性方法
/// </summary>
/// <returns></returns>
private static IEnumerable<AttributeItem> GetAttributes() => new AttributeItem[]
{
// TODO: 移动到数据库中
new AttributeItem() {
Name = "OnText",
Description = "On 状态显示文字",
Type = "string",
ValueList = " — ",
DefaultValue = " — "
},
new AttributeItem() {
Name = "OffText",
Description = "Off 状态显示文字",
Type = "string",
ValueList = " — ",
DefaultValue = " — "
},
new AttributeItem() {
Name = "ToggleState",
Description = "当前状态",
Type = "boolean",
ValueList = "true/false",
DefaultValue = "false"
},
new AttributeItem() {
Name = "ToggleStateChanged",
Description = "状态切换回调方法",
Type = "Func<bool, Task>",
ValueList = " — ",
DefaultValue = " — "
},
new AttributeItem() {
Name = "OnClick",
Description = "点击回调方法",
Type = "EventCallback<MouseEventArgs>",
ValueList = " — ",
DefaultValue = " — "
}
};
}