Enterprise-level component library based on Bootstrap and Blazor

star nuget master download license repo commit

Checkbox

Multiple-select in a set of alternatives

Using alone can represent a switch between two states, and column head or header can represent a switch between three states when used. Components support generic data binding, setting the binding data type the TValue , and setting the component state by State

Demo

Check box is not available, and the IsDisabled is set by whether the component is available

Demo

Change the component background color by setting the Color property

Demo

Change the component size by setting the Size property

Demo

The check box displays text, and the component status flips when you tap display text, using the DisplayText settings component to display text

Demo

Set DisplayText property, or display text messages through bidirectional binding

Binding variables within a component, data automatically synchronized, binding data types boolean type when the value is automatically flipped

Demo

Binding variables within a component, data is automatically synchronized

Demo

When you use Checkbox in a form, the display label text is placed in front of the component

Demo

The pre-label explicit rules are consistent with the BootstrapInput component [portal]

Attributes

Loading...

Event

Loading...
@page "/checkboxs"
@inject IStringLocalizer<Checkboxs> Localizer

<h3>@Localizer["Title"]</h3>

<h4>@Localizer["H1"]</h4>

<Block Title="@Localizer["Block1Title"]" Introduction="@Localizer["Block1Intro"]">
    <div class="row g-3 form-inline">
        <div class="col-12 col-sm-6">
            <Checkbox TValue="string" State="CheckboxState.Checked" OnStateChanged="@OnStateChanged" DisplayText="@Localizer["StatusText1"]" ShowLabel="true"></Checkbox>
        </div>
        <div class="col-12 col-sm-6">
            <Checkbox TValue="string" State="CheckboxState.UnChecked" OnStateChanged="@OnStateChanged" DisplayText="@Localizer["StatusText2"]" ShowLabel="true"></Checkbox>
        </div>
    </div>
    <BlockLogger @ref="Trace" class="mt-3" />
</Block>

<Block Title="@Localizer["Block2Title"]" Introduction="@Localizer["Block2Intro"]">
    <div class="row g-3 form-inline">
        <div class="col-12 col-md-4">
            <Checkbox TValue="string" State="CheckboxState.Checked" IsDisabled="true" DisplayText="@Localizer["StatusText1"]" ShowLabel="true"></Checkbox>
        </div>
        <div class="col-12 col-md-4">
            <Checkbox TValue="string" State="CheckboxState.UnChecked" IsDisabled="true" DisplayText="@Localizer["StatusText2"]" ShowLabel="true"></Checkbox>
        </div>
    </div>
</Block>

<Block Title="@Localizer["Block3Title"]" Introduction="@Localizer["Block3Inrto"]">
    <div class="row g-3 form-inline">
        <div class="col-12 col-md-4">
            <Checkbox TValue="string" State="CheckboxState.Checked" DisplayText="@Localizer["StatusText1"]" ShowLabel="true" Color="@Color.Primary"></Checkbox>
        </div>
        <div class="col-12 col-md-4">
            <Checkbox TValue="string" State="CheckboxState.Checked" DisplayText="@Localizer["StatusText1"]" ShowLabel="true" Color="@Color.Success"></Checkbox>
        </div>
        <div class="col-12 col-md-4">
            <Checkbox TValue="string" State="CheckboxState.Checked" DisplayText="@Localizer["StatusText1"]" ShowLabel="true" Color="@Color.Danger"></Checkbox>
        </div>
        <div class="col-12 col-md-4">
            <Checkbox TValue="string" State="CheckboxState.Checked" DisplayText="@Localizer["StatusText1"]" ShowLabel="true" Color="@Color.Info"></Checkbox>
        </div>
        <div class="col-12 col-md-4">
            <Checkbox TValue="string" State="CheckboxState.Checked" DisplayText="@Localizer["StatusText1"]" ShowLabel="true" Color="@Color.Warning"></Checkbox>
        </div>
        <div class="col-12 col-md-4">
            <Checkbox TValue="string" State="CheckboxState.Checked" DisplayText="@Localizer["StatusText1"]" ShowLabel="true" Color="@Color.Dark"></Checkbox>
        </div>
    </div>
</Block>

<Block Title="@Localizer["Block4Title"]" Introduction="@Localizer["Block4Intro"]">
    <div class="row g-3 form-inline">
        <div class="col-12 col-md-3">
            <Checkbox TValue="string" State="CheckboxState.Checked" DisplayText="Default" ShowLabel="true"></Checkbox>
        </div>
        <div class="col-12 col-md-3">
            <Checkbox TValue="string" State="CheckboxState.Checked" DisplayText="Small" ShowLabel="true" Size="Size.Small"></Checkbox>
        </div>
        <div class="col-12 col-md-3">
            <Checkbox TValue="string" State="CheckboxState.Checked" DisplayText="Medium" ShowLabel="true" Size="Size.Medium"></Checkbox>
        </div>
        <div class="col-12 col-md-3">
            <Checkbox TValue="string" State="CheckboxState.Checked" DisplayText="Large" ShowLabel="true" Size="Size.Large"></Checkbox>
        </div>
    </div>
</Block>

<Block Title="@Localizer["Block5Title"]" Introduction="@Localizer["Block5Intro"]">
    <p>@((MarkupString)Localizer["P1"].Value)</p>
    <Checkbox TValue="string" DisplayText="@Localizer["Checkbox1Text"]" ShowAfterLabel="true"></Checkbox>
</Block>

<Block Title="@Localizer["Block6Title"]" Introduction="@Localizer["Block6Intro"]">
    <div class="row g-3 form-inline">
        <div class="col-12">
            <Checkbox DisplayText="@Localizer["Checkbox2Text"]" ShowLabel="true" @bind-Value="@BindValue" OnStateChanged="@OnItemChanged"></Checkbox>
        </div>
        <div class="col-12">
            <BootstrapInput @bind-Value="@BindValue" IsDisabled="true"></BootstrapInput>
        </div>
    </div>
    <BlockLogger @ref="BinderLog" class="mt-3" />
</Block>

<Block Title="@Localizer["Block7Title"]" Introduction="@Localizer["Block7Intro"]">
    <div class="row g-3 form-inline">
        <div class="col-12">
            <Checkbox DisplayText="@Localizer["Checkbox2Text"]" ShowLabel="true" @bind-Value="@BindString" OnStateChanged="@OnItemChangedString"></Checkbox>
        </div>
        <div class="col-12">
            <BootstrapInput @bind-Value="@BindString"></BootstrapInput>
        </div>
    </div>
    <BlockLogger @ref="BinderLog" class="mt-3" />
</Block>

<Block Title="@Localizer["Block8Title"]" Introduction="@Localizer["Block8Intro"]">
    <p>@((MarkupString)Localizer["P2"].Value)</p>
    <ValidateForm Model="@Model">
        <div class="row g-3 form-inline">
            <div class="col-12 col-sm-6">
                <Checkbox @bind-Value="@Model.BindValue" ShowLabel="true"></Checkbox>
            </div>
            <div class="col-12 col-sm-6">
                <Checkbox @bind-Value="@Model.BindValue1" ShowLabel="true" DisplayText="@Localizer["Checkbox3Text"]"></Checkbox>
            </div>
        </div>
    </ValidateForm>
</Block>

<AttributeTable Items="@GetAttributes()" />

<EventTable Items="@GetEvents()" />
// 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 BootstrapBlazor.Components;
using BootstrapBlazor.Shared.Common;
using BootstrapBlazor.Shared.Pages.Components;
using System.Collections.Generic;
using System.ComponentModel;
using System.Threading.Tasks;

namespace BootstrapBlazor.Shared.Pages
{
    /// <summary>
    /// 
    /// </summary>
    public sealed partial class Checkboxs
    {
        private class Foo
        {
            [DisplayName("标签文字1")]
            public bool BindValue { get; set; }

            [DisplayName("标签文字2")]
            public bool BindValue1 { get; set; }
        }

        private Foo Model { get; set; } = new Foo();

        /// <summary>
        /// 
        /// </summary>
        private BlockLogger? Trace { get; set; }

        /// <summary>
        /// 
        /// </summary>
        private BlockLogger? BinderLog { get; set; }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="state"></param>
        /// <param name="value"></param>
        private Task OnStateChanged(CheckboxState state, string value)
        {
            Trace?.Log($"Checkbox state changed State: {state}");
            return Task.CompletedTask;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="state"></param>
        /// <param name="value"></param>
        private Task OnItemChanged(CheckboxState state, bool value)
        {
            BinderLog?.Log($"CheckboxState: {state} - Bind Value: {value}");
            return Task.CompletedTask;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="state"></param>
        /// <param name="value"></param>
        private Task OnItemChangedString(CheckboxState state, string value)
        {
            BinderLog?.Log($"CheckboxState: {state} - Bind Value: {value}");
            return Task.CompletedTask;
        }

        /// <summary>
        /// 
        /// </summary>
        private string BindString { get; set; } = "我爱 Blazor";

        /// <summary>
        /// 
        /// </summary>
        private bool BindValue { get; set; }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        private IEnumerable<AttributeItem> GetAttributes()
        {
            return new AttributeItem[]
            {
                new AttributeItem() {
                    Name = "ShowLabel",
                    Description = Localizer["Att1"]!,
                    Type = "bool",
                    ValueList = "true|false",
                    DefaultValue = "false"
                },
                new AttributeItem() {
                    Name = "ShowAfterLabel",
                    Description = Localizer["Att2"]!,
                    Type = "bool",
                    ValueList = "true|false",
                    DefaultValue = "false"
                },
                new AttributeItem() {
                    Name = "DisplayText",
                    Description = Localizer["Att3"]!,
                    Type = "string",
                    ValueList = " — ",
                    DefaultValue = " — "
                },
                new AttributeItem(){
                    Name = "IsDisabled",
                    Description = Localizer["Att4"]!,
                    Type = "boolean",
                    ValueList = "true / false",
                    DefaultValue = "false"
                },
                new AttributeItem()
                {
                    Name = "State",
                    Description = Localizer["Att5"]!,
                    Type = "CheckboxState",
                    ValueList = "Mixed / Checked / UnChecked",
                    DefaultValue = "UnChecked"
                },
            };
        }

        /// <summary>
        /// 获得事件方法
        /// </summary>
        /// <returns></returns>
        private IEnumerable<EventItem> GetEvents() => new EventItem[]
        {
            new EventItem()
            {
                Name = "OnStateChanged",
                Description = Localizer["Event1"]!, 
                Type ="Action<CheckboxState, TItem>"
            },
            new EventItem()
            {
                Name = "StateChanged",
                Description = Localizer["Event2"]!,
                Type ="EventCallback<CheckboxState>"
            }
        };
    }
}

B 站相关视频链接

暂无

交流群

QQ Group:BootstrapAdmin & Blazor 795206915( Full) 675147445 Welcome to join the group discussion
Themes
Bootstrap
Ant Design (完善中)
Bluma (完善中)
LayUI (完善中)
Motronic (已集成)
An error has occurred. This application may no longer respond until reloaded. Reload