+
+@if (IsShowLabel)
+{
+
+}
+
+
+ @if (!string.IsNullOrEmpty(Text))
+ {
+
+ @Text
+
+ }
+
diff --git a/src/BootstrapBlazor/Components/Switch/NullSwitch.razor.cs b/src/BootstrapBlazor/Components/Switch/NullSwitch.razor.cs
new file mode 100644
index 000000000..3e4a67348
--- /dev/null
+++ b/src/BootstrapBlazor/Components/Switch/NullSwitch.razor.cs
@@ -0,0 +1,150 @@
+// 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/
+
+using Microsoft.AspNetCore.Components;
+using Microsoft.Extensions.Localization;
+using System.Diagnostics.CodeAnalysis;
+using System.Threading.Tasks;
+
+namespace BootstrapBlazor.Components
+{
+ ///
+ ///
+ ///
+ public partial class NullSwitch
+ {
+ ///
+ /// 获得 样式集合
+ ///
+ private string? ClassName => CssBuilder.Default("switch")
+ .AddClass("is-checked", ComponentValue)
+ .AddClass("is-disabled", IsDisabled)
+ .AddClassFromAttributes(AdditionalAttributes)
+ .Build();
+
+ private string? CoreClassName => CssBuilder.Default("switch-core")
+ .AddClass($"border-{OnColor.ToDescriptionString()}", OnColor != Color.None && ComponentValue)
+ .AddClass($"bg-{OnColor.ToDescriptionString()}", OnColor != Color.None && ComponentValue)
+ .AddClass($"border-{OffColor.ToDescriptionString()}", OffColor != Color.None && !ComponentValue)
+ .AddClass($"bg-{OffColor.ToDescriptionString()}", OffColor != Color.None && !ComponentValue)
+ .Build();
+
+ private string? GetInnerText()
+ {
+ string? ret = null;
+ if (ShowInnerText)
+ {
+ ret = ComponentValue ? OnInnerText : OffInnerText;
+ }
+ return ret;
+ }
+
+ ///
+ /// 获得 显示文字
+ ///
+ private string? Text => ComponentValue ? OnText : OffText;
+
+ ///
+ /// 获得 组件最小宽度
+ ///
+ private string? SwitchStyleName => CssBuilder.Default()
+ .AddClass($"min-width: {Width}px;", Width > 0)
+ .AddStyleFromAttributes(AdditionalAttributes)
+ .Build();
+
+ ///
+ /// 获得 Style 集合
+ ///
+ protected override string? StyleName => CssBuilder.Default()
+ .AddClass($"width: {Width}px;", Width > 0)
+ .AddClass($"height: {Height}px;", Height >= 20)
+ .Build();
+
+ ///
+ /// 获得/设置 开颜色
+ ///
+ [Parameter]
+ public Color OnColor { get; set; } = Color.Success;
+
+ ///
+ /// 获得/设置 关颜色
+ ///
+ [Parameter]
+ public Color OffColor { get; set; }
+
+ ///
+ /// 获得/设置 组件宽度 默认 40
+ ///
+ [Parameter]
+ public override int Width { get; set; } = 40;
+
+ ///
+ /// 获得/设置 控件高度默认 20px
+ ///
+ [Parameter]
+ public int Height { get; set; } = 20;
+
+ ///
+ /// 获得/设置 组件 On 时内置显示文本
+ ///
+ [Parameter]
+ [NotNull]
+ public string? OnInnerText { get; set; }
+
+ ///
+ /// 获得/设置 组件 Off 时内置显示文本
+ ///
+ [Parameter]
+ [NotNull]
+ public string? OffInnerText { get; set; }
+
+ ///
+ /// 获得/设置 是否显示内置文字 默认 false 显示
+ ///
+ [Parameter]
+ public bool ShowInnerText { get; set; }
+
+ [Inject]
+ [NotNull]
+ private IStringLocalizer? Localizer { get; set; }
+
+ ///
+ /// 获得/设置 绑定值为空时的默认值 默认为 false
+ ///
+ [Parameter]
+ public bool DefaultValueWhenNull { get; set; }
+
+ ///
+ /// 获得/设置 组件 Value 值
+ ///
+ protected bool ComponentValue => Value ?? DefaultValueWhenNull;
+
+ ///
+ /// OnInitialized 方法
+ ///
+ protected override void OnInitialized()
+ {
+ base.OnInitialized();
+
+ OnInnerText ??= Localizer[nameof(OnInnerText)];
+ OffInnerText ??= Localizer[nameof(OffInnerText)];
+ }
+
+ ///
+ /// 点击控件时触发此方法
+ ///
+ private async Task OnClick()
+ {
+ if (!IsDisabled)
+ {
+ Value = !ComponentValue;
+ if (ValueChanged.HasDelegate)
+ {
+ await ValueChanged.InvokeAsync(Value);
+ }
+ OnValueChanged?.Invoke(Value);
+ }
+ }
+ }
+}
diff --git a/src/BootstrapBlazor/Components/Switch/Switch.razor b/src/BootstrapBlazor/Components/Switch/Switch.razor
index 9de10021b..dc7975b05 100644
--- a/src/BootstrapBlazor/Components/Switch/Switch.razor
+++ b/src/BootstrapBlazor/Components/Switch/Switch.razor
@@ -1,5 +1,5 @@
@namespace BootstrapBlazor.Components
-@inherits ToggleBase
+@inherits ToggleBase
@if (IsShowLabel)
{
diff --git a/src/BootstrapBlazor/Components/Switch/Switch.razor.cs b/src/BootstrapBlazor/Components/Switch/Switch.razor.cs
index 520531325..120093495 100644
--- a/src/BootstrapBlazor/Components/Switch/Switch.razor.cs
+++ b/src/BootstrapBlazor/Components/Switch/Switch.razor.cs
@@ -5,6 +5,7 @@
using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Localization;
using System.Diagnostics.CodeAnalysis;
+using System.Threading.Tasks;
namespace BootstrapBlazor.Components
{
@@ -13,10 +14,7 @@ namespace BootstrapBlazor.Components
///