mirror of
https://gitee.com/LongbowEnterprise/BootstrapBlazor.git
synced 2024-11-30 02:58:37 +08:00
!10 增加功能:增加 Toggle 开关组件
* doc: 增加禁止样式文档 * feat: 增加 Toggle 禁用效果 * feat: 增加 StyleName * style: 微调 toggle-off 标签背景颜色 * feat: 增加 Toggle 组件
This commit is contained in:
parent
cc18f4ace7
commit
eb6f917e39
64
src/BootstrapBlazor.WebConsole/Pages/Toggles.razor
Normal file
64
src/BootstrapBlazor.WebConsole/Pages/Toggles.razor
Normal file
@ -0,0 +1,64 @@
|
||||
@page "/toggles"
|
||||
|
||||
<Block Title="Toggle 开关" Introduction="提供最普通的开关应用">
|
||||
<CardBodyTemplate>
|
||||
<div class="form-inline">
|
||||
<div class="row">
|
||||
<div class="form-group col-6 col-sm-4 col-md-3 col-lg-auto"><Toggle Value="true" OnText="开启" OffText="关闭" Color="Color.Primary" OnValueChanged="@OnValueChanged"></Toggle></div>
|
||||
<div class="form-group col-6 col-sm-4 col-md-3 col-lg-auto"><Toggle Value="true" OnText="开启" OffText="关闭" Color="Color.Secondary" OnValueChanged="@OnValueChanged"></Toggle></div>
|
||||
<div class="form-group col-6 col-sm-4 col-md-3 col-lg-auto"><Toggle Value="true" OnText="开启" OffText="关闭" Color="Color.Success" OnValueChanged="@OnValueChanged"></Toggle></div>
|
||||
<div class="form-group col-6 col-sm-4 col-md-3 col-lg-auto"><Toggle Value="true" OnText="开启" OffText="关闭" Color="Color.Danger" OnValueChanged="@OnValueChanged"></Toggle></div>
|
||||
<div class="form-group col-6 col-sm-4 col-md-3 col-lg-auto"><Toggle Value="true" OnText="开启" OffText="关闭" Color="Color.Warning" OnValueChanged="@OnValueChanged"></Toggle></div>
|
||||
<div class="form-group col-6 col-sm-4 col-md-3 col-lg-auto"><Toggle Value="true" OnText="开启" OffText="关闭" Color="Color.Info" OnValueChanged="@OnValueChanged"></Toggle></div>
|
||||
<div class="form-group col-6 col-sm-4 col-md-3 col-lg-auto"><Toggle Value="true" OnText="开启" OffText="关闭" Color="Color.Dark" OnValueChanged="@OnValueChanged"></Toggle></div>
|
||||
<div class="form-group col-6 col-sm-4 col-md-3 col-lg-auto"><Toggle Value="false" OnText="开启" OffText="关闭" Color="Color.Success" OnValueChanged="@OnValueChanged"></Toggle></div>
|
||||
</div>
|
||||
</div>
|
||||
<Logger @ref="Trace" class="mt-3" />
|
||||
</CardBodyTemplate>
|
||||
<CodeTemplate>
|
||||
<pre>
|
||||
<Toggle OnText="开启" OffText="关闭" OnValueChanged="@@OnValueChanged" Color="Color.Primary"></Toggle>
|
||||
<Toggle OnText="开启" OffText="关闭" OnValueChanged="@@OnValueChanged" Color="Color.Secondary"></Toggle>
|
||||
<Toggle OnText="开启" OffText="关闭" OnValueChanged="@@OnValueChanged" Color="Color.Success"></Toggle>
|
||||
<Toggle OnText="开启" OffText="关闭" OnValueChanged="@@OnValueChanged" Color="Color.Danger"></Toggle>
|
||||
<Toggle OnText="开启" OffText="关闭" OnValueChanged="@@OnValueChanged" Color="Color.Warning"></Toggle>
|
||||
<Toggle OnText="开启" OffText="关闭" OnValueChanged="@@OnValueChanged" Color="Color.Info"></Toggle>
|
||||
<Toggle OnText="开启" OffText="关闭" OnValueChanged="@@OnValueChanged" Color="Color.Dark"></Toggle>
|
||||
<Toggle OnText="开启" OffText="关闭" OnValueChanged="@@OnValueChanged" Color="Color.Dark" Value="false"></Toggle>
|
||||
</pre>
|
||||
</CodeTemplate>
|
||||
</Block>
|
||||
|
||||
<Block Title="禁用状态" Introduction="开关不可用状态。">
|
||||
<CardBodyTemplate>
|
||||
<div class="form-inline">
|
||||
<div class="row">
|
||||
<div class="form-group col-6 col-sm-4 col-md-3 col-lg-auto"><Toggle IsDisabled="true" Value="true" OnText="开启" OffText="关闭" Color="Color.Primary" OnValueChanged="@OnValueChanged"></Toggle></div>
|
||||
<div class="form-group col-6 col-sm-4 col-md-3 col-lg-auto"><Toggle IsDisabled="true" Value="true" OnText="开启" OffText="关闭" Color="Color.Secondary" OnValueChanged="@OnValueChanged"></Toggle></div>
|
||||
<div class="form-group col-6 col-sm-4 col-md-3 col-lg-auto"><Toggle IsDisabled="true" Value="true" OnText="开启" OffText="关闭" Color="Color.Success" OnValueChanged="@OnValueChanged"></Toggle></div>
|
||||
<div class="form-group col-6 col-sm-4 col-md-3 col-lg-auto"><Toggle IsDisabled="true" Value="true" OnText="开启" OffText="关闭" Color="Color.Danger" OnValueChanged="@OnValueChanged"></Toggle></div>
|
||||
<div class="form-group col-6 col-sm-4 col-md-3 col-lg-auto"><Toggle IsDisabled="true" Value="true" OnText="开启" OffText="关闭" Color="Color.Warning" OnValueChanged="@OnValueChanged"></Toggle></div>
|
||||
<div class="form-group col-6 col-sm-4 col-md-3 col-lg-auto"><Toggle IsDisabled="true" Value="true" OnText="开启" OffText="关闭" Color="Color.Info" OnValueChanged="@OnValueChanged"></Toggle></div>
|
||||
<div class="form-group col-6 col-sm-4 col-md-3 col-lg-auto"><Toggle IsDisabled="true" Value="true" OnText="开启" OffText="关闭" Color="Color.Dark" OnValueChanged="@OnValueChanged"></Toggle></div>
|
||||
<div class="form-group col-6 col-sm-4 col-md-3 col-lg-auto"><Toggle IsDisabled="true" Value="false" OnText="开启" OffText="关闭" Color="Color.Success" OnValueChanged="@OnValueChanged"></Toggle></div>
|
||||
</div>
|
||||
</div>
|
||||
</CardBodyTemplate>
|
||||
<CodeTemplate>
|
||||
<pre>
|
||||
<Toggle IsDisabled="true" OnText="开启" OffText="关闭" OnValueChanged="@@OnValueChanged" Color="Color.Primary"></Toggle>
|
||||
<Toggle IsDisabled="true" OnText="开启" OffText="关闭" OnValueChanged="@@OnValueChanged" Color="Color.Secondary"></Toggle>
|
||||
<Toggle IsDisabled="true" OnText="开启" OffText="关闭" OnValueChanged="@@OnValueChanged" Color="Color.Success"></Toggle>
|
||||
<Toggle IsDisabled="true" OnText="开启" OffText="关闭" OnValueChanged="@@OnValueChanged" Color="Color.Danger"></Toggle>
|
||||
<Toggle IsDisabled="true" OnText="开启" OffText="关闭" OnValueChanged="@@OnValueChanged" Color="Color.Warning"></Toggle>
|
||||
<Toggle IsDisabled="true" OnText="开启" OffText="关闭" OnValueChanged="@@OnValueChanged" Color="Color.Info"></Toggle>
|
||||
<Toggle IsDisabled="true" OnText="开启" OffText="关闭" OnValueChanged="@@OnValueChanged" Color="Color.Dark"></Toggle>
|
||||
<Toggle IsDisabled="true" OnText="开启" OffText="关闭" OnValueChanged="@@OnValueChanged" Color="Color.Dark" Value="false"></Toggle>
|
||||
</pre>
|
||||
</CodeTemplate>
|
||||
</Block>
|
||||
|
||||
<AttributeTable Items="@GetAttributes()" />
|
||||
|
||||
<EventTable Items="@GetEvents()" />
|
67
src/BootstrapBlazor.WebConsole/Pages/Toggles.razor.cs
Normal file
67
src/BootstrapBlazor.WebConsole/Pages/Toggles.razor.cs
Normal file
@ -0,0 +1,67 @@
|
||||
using BootstrapBlazor.WebConsole.Common;
|
||||
using BootstrapBlazor.WebConsole.Pages.Components;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace BootstrapBlazor.WebConsole.Pages
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public partial class Toggles
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
protected Logger? Trace { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="val"></param>
|
||||
protected void OnValueChanged(bool val) => Trace?.Log($"Toggle CurrentValue: {val}");
|
||||
|
||||
/// <summary>
|
||||
/// 获得事件方法
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected IEnumerable<EventItem> GetEvents() => new EventItem[]
|
||||
{
|
||||
new EventItem()
|
||||
{
|
||||
Name = "OnValueChanged",
|
||||
Description="组件值变化时触发此事件",
|
||||
Type ="EventCallback<bool>"
|
||||
}
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// 获得属性方法
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected IEnumerable<AttributeItem> GetAttributes() => new AttributeItem[]
|
||||
{
|
||||
// TODO: 移动到数据库中
|
||||
new AttributeItem() {
|
||||
Name = "Color",
|
||||
Description = "颜色",
|
||||
Type = "Color",
|
||||
ValueList = "Primary / Secondary / Success / Danger / Warning / Info / Dark",
|
||||
DefaultValue = "Success"
|
||||
},
|
||||
new AttributeItem() {
|
||||
Name = "Width",
|
||||
Description = "组件宽度",
|
||||
Type = "int",
|
||||
ValueList = " — ",
|
||||
DefaultValue = "120"
|
||||
},
|
||||
new AttributeItem() {
|
||||
Name = "IsDisabled",
|
||||
Description = "是否禁用",
|
||||
Type = "boolean",
|
||||
ValueList = " — ",
|
||||
DefaultValue = "false"
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
@ -16,13 +16,11 @@
|
||||
<link href="~/lib/twitter-bootstrap/css/bootstrap.css" rel="stylesheet" />
|
||||
<link href="~/lib/font-awesome/css/font-awesome.css" rel="stylesheet" />
|
||||
<link href="~/lib/overlayscrollbars/OverlayScrollbars.css" rel="stylesheet" />
|
||||
<link href="~/lib/bootstrap-toggle/css/bootstrap-toggle.css" rel="stylesheet" />
|
||||
</environment>
|
||||
<environment exclude="Development">
|
||||
<link href="~/lib/twitter-bootstrap/css/bootstrap.min.css" rel="stylesheet" />
|
||||
<link href="~/lib/font-awesome/css/font-awesome.min.css" rel="stylesheet" />
|
||||
<link href="~/lib/overlayscrollbars/OverlayScrollbars.min.css" rel="stylesheet" />
|
||||
<link href="~/lib/bootstrap-toggle/css/bootstrap-toggle.min.css" rel="stylesheet" />
|
||||
</environment>
|
||||
<link href="~/lib/longbow-checkbox/longbow-checkbox.css" rel="stylesheet" />
|
||||
<link href="~/_content/BootstrapBlazor/css/bootstrap.blazor.css" rel="stylesheet" />
|
||||
|
@ -78,6 +78,9 @@
|
||||
<li class="nav-item">
|
||||
<NavLink class="nav-link" href="toasts" Match="NavLinkMatch.All"><span>轻量弹窗</span><span>Toasts</span></NavLink>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<NavLink class="nav-link" href="toggles" Match="NavLinkMatch.All"><span>开关</span><span>Toggle</span></NavLink>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<NavLink class="nav-link" href="tooltips" Match="NavLinkMatch.All"><span>工具条</span><span>Tooltips</span></NavLink>
|
||||
</li>
|
||||
|
@ -1,84 +0,0 @@
|
||||
/*! ========================================================================
|
||||
* Bootstrap Toggle: bootstrap-toggle.css v2.2.0
|
||||
* http://www.bootstraptoggle.com
|
||||
* ========================================================================
|
||||
* Copyright 2014 Min Hur, The New York Times Company
|
||||
* Licensed under MIT
|
||||
* ======================================================================== */
|
||||
|
||||
|
||||
.checkbox label .toggle,
|
||||
.checkbox-inline .toggle {
|
||||
margin-left: -20px;
|
||||
margin-right: 5px;
|
||||
}
|
||||
|
||||
.toggle {
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
}
|
||||
.toggle input[type="checkbox"] {
|
||||
display: none;
|
||||
}
|
||||
.toggle-group {
|
||||
position: absolute;
|
||||
width: 200%;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
transition: left 0.35s;
|
||||
-webkit-transition: left 0.35s;
|
||||
-moz-user-select: none;
|
||||
-webkit-user-select: none;
|
||||
}
|
||||
.toggle.off .toggle-group {
|
||||
left: -100%;
|
||||
}
|
||||
.toggle-on {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 50%;
|
||||
margin: 0;
|
||||
border: 0;
|
||||
border-radius: 0;
|
||||
}
|
||||
.toggle-off {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
left: 50%;
|
||||
right: 0;
|
||||
margin: 0;
|
||||
border: 0;
|
||||
border-radius: 0;
|
||||
}
|
||||
.toggle-handle {
|
||||
position: relative;
|
||||
margin: 0 auto;
|
||||
padding-top: 0px;
|
||||
padding-bottom: 0px;
|
||||
height: 100%;
|
||||
width: 0px;
|
||||
border-width: 0 1px;
|
||||
}
|
||||
|
||||
.toggle.btn { min-width: 59px; min-height: 34px; }
|
||||
.toggle-on.btn { padding-right: 24px; }
|
||||
.toggle-off.btn { padding-left: 24px; }
|
||||
|
||||
.toggle.btn-lg { min-width: 79px; min-height: 45px; }
|
||||
.toggle-on.btn-lg { padding-right: 31px; }
|
||||
.toggle-off.btn-lg { padding-left: 31px; }
|
||||
.toggle-handle.btn-lg { width: 40px; }
|
||||
|
||||
.toggle.btn-sm { min-width: 50px; min-height: 30px;}
|
||||
.toggle-on.btn-sm { padding-right: 20px; }
|
||||
.toggle-off.btn-sm { padding-left: 20px; }
|
||||
|
||||
.toggle.btn-xs { min-width: 35px; min-height: 22px;}
|
||||
.toggle-on.btn-xs { padding-right: 12px; }
|
||||
.toggle-off.btn-xs { padding-left: 12px; }
|
||||
|
||||
.toggle-group label, .toggle-group span {cursor: pointer;}
|
@ -1,28 +0,0 @@
|
||||
/*! ========================================================================
|
||||
* Bootstrap Toggle: bootstrap-toggle.css v2.2.0
|
||||
* http://www.bootstraptoggle.com
|
||||
* ========================================================================
|
||||
* Copyright 2014 Min Hur, The New York Times Company
|
||||
* Licensed under MIT
|
||||
* ======================================================================== */
|
||||
.checkbox label .toggle,.checkbox-inline .toggle{margin-left:-20px;margin-right:5px}
|
||||
.toggle{position:relative;overflow:hidden}
|
||||
.toggle input[type=checkbox]{display:none}
|
||||
.toggle-group{position:absolute;width:200%;top:0;bottom:0;left:0;transition:left .35s;-webkit-transition:left .35s;-moz-user-select:none;-webkit-user-select:none}
|
||||
.toggle.off .toggle-group{left:-100%}
|
||||
.toggle-on{position:absolute;top:0;bottom:0;left:0;right:50%;margin:0;border:0;border-radius:0}
|
||||
.toggle-off{position:absolute;top:0;bottom:0;left:50%;right:0;margin:0;border:0;border-radius:0}
|
||||
.toggle-handle{position:relative;margin:0 auto;padding-top:0;padding-bottom:0;height:100%;width:0;border-width:0 1px}
|
||||
.toggle.btn{min-width:59px;min-height:34px}
|
||||
.toggle-on.btn{padding-right:24px}
|
||||
.toggle-off.btn{padding-left:24px}
|
||||
.toggle.btn-lg{min-width:79px;min-height:45px}
|
||||
.toggle-on.btn-lg{padding-right:31px}
|
||||
.toggle-off.btn-lg{padding-left:31px}
|
||||
.toggle-handle.btn-lg{width:40px}
|
||||
.toggle.btn-sm{min-width:50px;min-height:30px}
|
||||
.toggle-on.btn-sm{padding-right:20px}
|
||||
.toggle-off.btn-sm{padding-left:20px}
|
||||
.toggle.btn-xs{min-width:35px;min-height:22px}
|
||||
.toggle-on.btn-xs{padding-right:12px}
|
||||
.toggle-off.btn-xs{padding-left:12px}
|
@ -1,180 +0,0 @@
|
||||
/*! ========================================================================
|
||||
* Bootstrap Toggle: bootstrap-toggle.js v2.2.0
|
||||
* http://www.bootstraptoggle.com
|
||||
* ========================================================================
|
||||
* Copyright 2014 Min Hur, The New York Times Company
|
||||
* Licensed under MIT
|
||||
* ======================================================================== */
|
||||
|
||||
|
||||
+function ($) {
|
||||
'use strict';
|
||||
|
||||
// TOGGLE PUBLIC CLASS DEFINITION
|
||||
// ==============================
|
||||
|
||||
var Toggle = function (element, options) {
|
||||
this.$element = $(element)
|
||||
this.options = $.extend({}, this.defaults(), options)
|
||||
this.render()
|
||||
}
|
||||
|
||||
Toggle.VERSION = '2.2.0'
|
||||
|
||||
Toggle.DEFAULTS = {
|
||||
on: 'On',
|
||||
off: 'Off',
|
||||
onstyle: 'primary',
|
||||
offstyle: 'default',
|
||||
size: 'normal',
|
||||
style: '',
|
||||
width: null,
|
||||
height: null
|
||||
}
|
||||
|
||||
Toggle.prototype.defaults = function() {
|
||||
return {
|
||||
on: this.$element.attr('data-on') || Toggle.DEFAULTS.on,
|
||||
off: this.$element.attr('data-off') || Toggle.DEFAULTS.off,
|
||||
onstyle: this.$element.attr('data-onstyle') || Toggle.DEFAULTS.onstyle,
|
||||
offstyle: this.$element.attr('data-offstyle') || Toggle.DEFAULTS.offstyle,
|
||||
size: this.$element.attr('data-size') || Toggle.DEFAULTS.size,
|
||||
style: this.$element.attr('data-style') || Toggle.DEFAULTS.style,
|
||||
width: this.$element.attr('data-width') || Toggle.DEFAULTS.width,
|
||||
height: this.$element.attr('data-height') || Toggle.DEFAULTS.height
|
||||
}
|
||||
}
|
||||
|
||||
Toggle.prototype.render = function () {
|
||||
this._onstyle = 'btn-' + this.options.onstyle
|
||||
this._offstyle = 'btn-' + this.options.offstyle
|
||||
var size = this.options.size === 'large' ? 'btn-lg'
|
||||
: this.options.size === 'small' ? 'btn-sm'
|
||||
: this.options.size === 'mini' ? 'btn-xs'
|
||||
: ''
|
||||
var $toggleOn = $('<label class="btn">').html(this.options.on)
|
||||
.addClass(this._onstyle + ' ' + size)
|
||||
var $toggleOff = $('<label class="btn">').html(this.options.off)
|
||||
.addClass(this._offstyle + ' ' + size + ' active')
|
||||
var $toggleHandle = $('<span class="toggle-handle btn btn-default">')
|
||||
.addClass(size)
|
||||
var $toggleGroup = $('<div class="toggle-group">')
|
||||
.append($toggleOn, $toggleOff, $toggleHandle)
|
||||
var $toggle = $('<div class="toggle btn" data-toggle="toggle">')
|
||||
.addClass( this.$element.prop('checked') ? this._onstyle : this._offstyle+' off' )
|
||||
.addClass(size).addClass(this.options.style)
|
||||
|
||||
this.$element.wrap($toggle)
|
||||
$.extend(this, {
|
||||
$toggle: this.$element.parent(),
|
||||
$toggleOn: $toggleOn,
|
||||
$toggleOff: $toggleOff,
|
||||
$toggleGroup: $toggleGroup
|
||||
})
|
||||
this.$toggle.append($toggleGroup)
|
||||
|
||||
var width = this.options.width || Math.max($toggleOn.outerWidth(), $toggleOff.outerWidth())+($toggleHandle.outerWidth()/2)
|
||||
var height = this.options.height || Math.max($toggleOn.outerHeight(), $toggleOff.outerHeight())
|
||||
$toggleOn.addClass('toggle-on')
|
||||
$toggleOff.addClass('toggle-off')
|
||||
this.$toggle.css({ width: width, height: height })
|
||||
if (this.options.height) {
|
||||
$toggleOn.css('line-height', $toggleOn.height() + 'px')
|
||||
$toggleOff.css('line-height', $toggleOff.height() + 'px')
|
||||
}
|
||||
this.update(true)
|
||||
this.trigger(true)
|
||||
}
|
||||
|
||||
Toggle.prototype.toggle = function () {
|
||||
if (this.$element.prop('checked')) this.off()
|
||||
else this.on()
|
||||
}
|
||||
|
||||
Toggle.prototype.on = function (silent) {
|
||||
if (this.$element.prop('disabled')) return false
|
||||
this.$toggle.removeClass(this._offstyle + ' off').addClass(this._onstyle)
|
||||
this.$element.prop('checked', true)
|
||||
if (!silent) this.trigger()
|
||||
}
|
||||
|
||||
Toggle.prototype.off = function (silent) {
|
||||
if (this.$element.prop('disabled')) return false
|
||||
this.$toggle.removeClass(this._onstyle).addClass(this._offstyle + ' off')
|
||||
this.$element.prop('checked', false)
|
||||
if (!silent) this.trigger()
|
||||
}
|
||||
|
||||
Toggle.prototype.enable = function () {
|
||||
this.$toggle.removeAttr('disabled')
|
||||
this.$element.prop('disabled', false)
|
||||
}
|
||||
|
||||
Toggle.prototype.disable = function () {
|
||||
this.$toggle.attr('disabled', 'disabled')
|
||||
this.$element.prop('disabled', true)
|
||||
}
|
||||
|
||||
Toggle.prototype.update = function (silent) {
|
||||
if (this.$element.prop('disabled')) this.disable()
|
||||
else this.enable()
|
||||
if (this.$element.prop('checked')) this.on(silent)
|
||||
else this.off(silent)
|
||||
}
|
||||
|
||||
Toggle.prototype.trigger = function (silent) {
|
||||
this.$element.off('change.bs.toggle')
|
||||
if (!silent) this.$element.change()
|
||||
this.$element.on('change.bs.toggle', $.proxy(function() {
|
||||
this.update()
|
||||
}, this))
|
||||
}
|
||||
|
||||
Toggle.prototype.destroy = function() {
|
||||
this.$element.off('change.bs.toggle')
|
||||
this.$toggleGroup.remove()
|
||||
this.$element.removeData('bs.toggle')
|
||||
this.$element.unwrap()
|
||||
}
|
||||
|
||||
// TOGGLE PLUGIN DEFINITION
|
||||
// ========================
|
||||
|
||||
function Plugin(option) {
|
||||
return this.each(function () {
|
||||
var $this = $(this)
|
||||
var data = $this.data('bs.toggle')
|
||||
var options = typeof option == 'object' && option
|
||||
|
||||
if (!data) $this.data('bs.toggle', (data = new Toggle(this, options)))
|
||||
if (typeof option == 'string' && data[option]) data[option]()
|
||||
})
|
||||
}
|
||||
|
||||
var old = $.fn.bootstrapToggle
|
||||
|
||||
$.fn.bootstrapToggle = Plugin
|
||||
$.fn.bootstrapToggle.Constructor = Toggle
|
||||
|
||||
// TOGGLE NO CONFLICT
|
||||
// ==================
|
||||
|
||||
$.fn.toggle.noConflict = function () {
|
||||
$.fn.bootstrapToggle = old
|
||||
return this
|
||||
}
|
||||
|
||||
// TOGGLE DATA-API
|
||||
// ===============
|
||||
|
||||
$(function() {
|
||||
$('input[type=checkbox][data-toggle^=toggle]').bootstrapToggle()
|
||||
})
|
||||
|
||||
$(document).on('click.bs.toggle', 'div[data-toggle^=toggle]', function(e) {
|
||||
var $checkbox = $(this).find('input[type=checkbox]')
|
||||
$checkbox.bootstrapToggle('toggle')
|
||||
e.preventDefault()
|
||||
})
|
||||
|
||||
}(jQuery);
|
@ -1,9 +0,0 @@
|
||||
/*! ========================================================================
|
||||
* Bootstrap Toggle: bootstrap-toggle.js v2.2.0
|
||||
* http://www.bootstraptoggle.com
|
||||
* ========================================================================
|
||||
* Copyright 2014 Min Hur, The New York Times Company
|
||||
* Licensed under MIT
|
||||
* ======================================================================== */
|
||||
+function(a){"use strict";function b(b){return this.each(function(){var d=a(this),e=d.data("bs.toggle"),f="object"==typeof b&&b;e||d.data("bs.toggle",e=new c(this,f)),"string"==typeof b&&e[b]&&e[b]()})}var c=function(b,c){this.$element=a(b),this.options=a.extend({},this.defaults(),c),this.render()};c.VERSION="2.2.0",c.DEFAULTS={on:"On",off:"Off",onstyle:"primary",offstyle:"default",size:"normal",style:"",width:null,height:null},c.prototype.defaults=function(){return{on:this.$element.attr("data-on")||c.DEFAULTS.on,off:this.$element.attr("data-off")||c.DEFAULTS.off,onstyle:this.$element.attr("data-onstyle")||c.DEFAULTS.onstyle,offstyle:this.$element.attr("data-offstyle")||c.DEFAULTS.offstyle,size:this.$element.attr("data-size")||c.DEFAULTS.size,style:this.$element.attr("data-style")||c.DEFAULTS.style,width:this.$element.attr("data-width")||c.DEFAULTS.width,height:this.$element.attr("data-height")||c.DEFAULTS.height}},c.prototype.render=function(){this._onstyle="btn-"+this.options.onstyle,this._offstyle="btn-"+this.options.offstyle;var b="large"===this.options.size?"btn-lg":"small"===this.options.size?"btn-sm":"mini"===this.options.size?"btn-xs":"",c=a('<label class="btn">').html(this.options.on).addClass(this._onstyle+" "+b),d=a('<label class="btn">').html(this.options.off).addClass(this._offstyle+" "+b+" active"),e=a('<span class="toggle-handle btn btn-default">').addClass(b),f=a('<div class="toggle-group">').append(c,d,e),g=a('<div class="toggle btn" data-toggle="toggle">').addClass(this.$element.prop("checked")?this._onstyle:this._offstyle+" off").addClass(b).addClass(this.options.style);this.$element.wrap(g),a.extend(this,{$toggle:this.$element.parent(),$toggleOn:c,$toggleOff:d,$toggleGroup:f}),this.$toggle.append(f);var h=this.options.width||Math.max(c.outerWidth(),d.outerWidth())+e.outerWidth()/2,i=this.options.height||Math.max(c.outerHeight(),d.outerHeight());c.addClass("toggle-on"),d.addClass("toggle-off"),this.$toggle.css({width:h,height:i}),this.options.height&&(c.css("line-height",c.height()+"px"),d.css("line-height",d.height()+"px")),this.update(!0),this.trigger(!0)},c.prototype.toggle=function(){this.$element.prop("checked")?this.off():this.on()},c.prototype.on=function(a){return this.$element.prop("disabled")?!1:(this.$toggle.removeClass(this._offstyle+" off").addClass(this._onstyle),this.$element.prop("checked",!0),void(a||this.trigger()))},c.prototype.off=function(a){return this.$element.prop("disabled")?!1:(this.$toggle.removeClass(this._onstyle).addClass(this._offstyle+" off"),this.$element.prop("checked",!1),void(a||this.trigger()))},c.prototype.enable=function(){this.$toggle.removeAttr("disabled"),this.$element.prop("disabled",!1)},c.prototype.disable=function(){this.$toggle.attr("disabled","disabled"),this.$element.prop("disabled",!0)},c.prototype.update=function(a){this.$element.prop("disabled")?this.disable():this.enable(),this.$element.prop("checked")?this.on(a):this.off(a)},c.prototype.trigger=function(b){this.$element.off("change.bs.toggle"),b||this.$element.change(),this.$element.on("change.bs.toggle",a.proxy(function(){this.update()},this))},c.prototype.destroy=function(){this.$element.off("change.bs.toggle"),this.$toggleGroup.remove(),this.$element.removeData("bs.toggle"),this.$element.unwrap()};var d=a.fn.bootstrapToggle;a.fn.bootstrapToggle=b,a.fn.bootstrapToggle.Constructor=c,a.fn.toggle.noConflict=function(){return a.fn.bootstrapToggle=d,this},a(function(){a("input[type=checkbox][data-toggle^=toggle]").bootstrapToggle()}),a(document).on("click.bs.toggle","div[data-toggle^=toggle]",function(b){var c=a(this).find("input[type=checkbox]");c.bootstrapToggle("toggle"),b.preventDefault()})}(jQuery);
|
||||
//# sourceMappingURL=bootstrap-toggle.min.js.map
|
@ -1 +0,0 @@
|
||||
{"version":3,"file":"bootstrap-toggle.min.js","sources":["bootstrap-toggle.js"],"names":["$","Plugin","option","this","each","$this","data","options","Toggle","element","$element","extend","defaults","render","VERSION","DEFAULTS","on","off","onstyle","offstyle","size","style","width","height","prototype","attr","_onstyle","_offstyle","$toggleOn","html","addClass","$toggleOff","$toggleHandle","$toggleGroup","append","$toggle","prop","wrap","parent","Math","max","outerWidth","outerHeight","css","update","trigger","toggle","silent","removeClass","enable","removeAttr","disable","change","proxy","destroy","remove","removeData","unwrap","old","fn","bootstrapToggle","Constructor","noConflict","document","e","$checkbox","find","preventDefault","jQuery"],"mappings":";;;;;;;CASE,SAAUA,GACV,YAoID,SAASC,GAAOC,GACf,MAAOC,MAAKC,KAAK,WAChB,GAAIC,GAAUL,EAAEG,MACZG,EAAUD,EAAMC,KAAK,aACrBC,EAA2B,gBAAVL,IAAsBA,CAEtCI,IAAMD,EAAMC,KAAK,YAAcA,EAAO,GAAIE,GAAOL,KAAMI,IACvC,gBAAVL,IAAsBI,EAAKJ,IAASI,EAAKJ,OAtItD,GAAIM,GAAS,SAAUC,EAASF,GAC/BJ,KAAKO,SAAYV,EAAES,GACnBN,KAAKI,QAAYP,EAAEW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OgB,UAAUyB,OAAS,WACzB9C,KAAKgC,QAAQe,WAAW,YACxB/C,KAAKO,SAAS0B,KAAK,YAAY,IAGhC5B,EAAOgB,UAAU2B,QAAU,WAC1BhD,KAAKgC,QAAQV,KAAK,WAAY,YAC9BtB,KAAKO,SAAS0B,KAAK,YAAY,IAGhC5B,EAAOgB,UAAUoB,OAAS,SAAUG,GAC/B5C,KAAKO,SAAS0B,KAAK,YAAajC,KAAKgD,UACpChD,KAAK8C,SACN9C,KAAKO,SAAS0B,KAAK,WAAYjC,KAAKa,GAAG+B,GACtC5C,KAAKc,IAAI8B,IAGfvC,EAAOgB,UAAUqB,QAAU,SAAUE,GACpC5C,KAAKO,SAASO,IAAI,oBACb8B,GAAQ5C,KAAKO,SAAS0C,SAC3BjD,KAAKO,SAASM,GAAG,mBAAoBhB,EAAEqD,MAAM,WAC5ClD,KAAKyC,UACHzC,QAGJK,EAAOgB,UAAU8B,QAAU,WAC1BnD,KAAKO,SAASO,IAAI,oBAClBd,KAAK8B,aAAasB,SAClBpD,KAAKO,SAAS8C,WAAW,aACzBrD,KAAKO,SAAS+C,SAiBf,IAAIC,GAAM1D,EAAE2D,GAAGC,eAEf5D,GAAE2D,GAAGC,gBAA8B3D,EACnCD,EAAE2D,GAAGC,gBAAgBC,YAAcrD,EAKnCR,EAAE2D,GAAGb,OAAOgB,WAAa,WAExB,MADA9D,GAAE2D,GAAGC,gBAAkBF,EAChBvD,MAMRH,EAAE,WACDA,EAAE,6CAA6C4D,oBAGhD5D,EAAE+D,UAAU/C,GAAG,kBAAmB,2BAA4B,SAASgD,GACtE,GAAIC,GAAYjE,EAAEG,MAAM+D,KAAK,uBAC7BD,GAAUL,gBAAgB,UAC1BI,EAAEG,oBAGFC"}
|
@ -1 +0,0 @@
|
||||
{"version":3,"file":"bootstrap2-toggle.min.js","sources":["bootstrap2-toggle.js"],"names":["$","Plugin","option","this","each","$this","data","options","Toggle","element","$element","extend","defaults","render","VERSION","DEFAULTS","on","off","onstyle","offstyle","size","style","width","height","prototype","attr","_onstyle","_offstyle","$toggleOn","html","addClass","$toggleOff","$toggleHandle","$toggleGroup","append","$toggle","prop","wrap","parent","Math","max","outerWidth","css","update","trigger","toggle","silent","removeClass","enable","removeAttr","disable","change","proxy","destroy","remove","removeData","unwrap","old","fn","bootstrapToggle","Constructor","noConflict","document","e","$checkbox","find","preventDefault","jQuery"],"mappings":";;;;;;;CASE,SAAUA,GACV,YAoID,SAASC,GAAOC,GACf,MAAOC,MAAKC,KAAK,WAChB,GAAIC,GAAUL,EAAEG,MACZG,EAAUD,EAAMC,KAAK,aACrBC,EAA2B,gBAAVL,IAAsBA,CAEtCI,IAAMD,EAAMC,KAAK,YAAcA,EAAO,GAAIE,GAAOL,KAAMI,IACvC,gBAAVL,IAAsBI,EAAKJ,IAASI,EAAKJ,OAtItD,GAAIM,GAAS,SAAUC,EAASF,GAC/BJ,KAAKO,SAAYV,EAAES,GACnBN,KAAKI,QAAYP,EAAEW,UAAWR,KAAKS,WAAYL,GAC/CJ,KAAKU,SAGNL,GAAOM,QAAW,QAElBN,EAAOO,UACNC,GAAI,KACJC,IAAK,MACLC,QAAS,UACTC,SAAU,UACVC,KAAM,SACNC,MAAO,GACPC,MAAO,KACPC,OAAQ,MAGTf,EAAOgB,UAAUZ,SAAW,WAC3B,OACCI,GAAIb,KAAKO,SAASe,KAAK,YAAcjB,EAAOO,SAASC,GACrDC,IAAKd,KAAKO,SAASe,KAAK,aAAejB,EAAOO,SAASE,IACvDC,QAASf,KAAKO,SAASe,KAAK,iBAAmBjB,EAAOO,SAASG,QAC/DC,SAAUhB,KAAKO,SAASe,KAAK,kBAAoBjB,EAAOO,SAASI,SACjEC,KAAMjB,KAAKO,SAASe,KAAK,cAAgBjB,EAAOO,SAASK,KACzDC,MAAOlB,KAAKO,SAASe,KAAK,eAAiBjB,EAAOO,SAASM,MAC3DC,MAAOnB,KAAKO,SAASe,KAAK,eAAiBjB,EAAOO,SAASO,MAC3DC,OAAQpB,KAAKO,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,SAClBnD,KAAKO,SAAS6C,WAAW,aACzBpD,KAAKO,SAAS8C,SAiBf,IAAIC,GAAMzD,EAAE0D,GAAGC,eAEf3D,GAAE0D,GAAGC,gBAA8B1D,EACnCD,EAAE0D,GAAGC,gBAAgBC,YAAcpD,EAKnCR,EAAE0D,GAAGb,OAAOgB,WAAa,WAExB,MADA7D,GAAE0D,GAAGC,gBAAkBF,EAChBtD,MAMRH,EAAE,WACDA,EAAE,6CAA6C2D,oBAGhD3D,EAAE8D,UAAU9C,GAAG,kBAAmB,2BAA4B,SAAS+C,GACtE,GAAIC,GAAYhE,EAAEG,MAAM8D,KAAK,uBAC7BD,GAAUL,gBAAgB,UAC1BI,EAAEG,oBAGFC"}
|
10
src/BootstrapBlazor/Components/Toggle/Toggle.razor
Normal file
10
src/BootstrapBlazor/Components/Toggle/Toggle.razor
Normal file
@ -0,0 +1,10 @@
|
||||
@namespace BootstrapBlazor.Components
|
||||
@inherits ToggleBase
|
||||
|
||||
<div class="@ClassName" data-toggle="toggle" style="@StyleName" @attributes="AdditionalAttributes" @onclick="@OnClick">
|
||||
<div class="toggle-group">
|
||||
<label class="toggle-on">@OnText</label>
|
||||
<label class="toggle-off">@OffText</label>
|
||||
<span class="btn btn-handle"></span>
|
||||
</div>
|
||||
</div>
|
82
src/BootstrapBlazor/Components/Toggle/ToggleBase.cs
Normal file
82
src/BootstrapBlazor/Components/Toggle/ToggleBase.cs
Normal file
@ -0,0 +1,82 @@
|
||||
using BootstrapBlazor.Utils;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.Components.Web;
|
||||
using System;
|
||||
|
||||
namespace BootstrapBlazor.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// Toggle 开关组件
|
||||
/// </summary>
|
||||
public class ToggleBase : BootstrapComponentBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 获得 样式集合
|
||||
/// </summary>
|
||||
protected override string? ClassName => CssBuilder.Default("toggle btn")
|
||||
.AddClass($"btn-{Color.ToDescriptionString()}", Color != Color.None)
|
||||
.AddClass("btn-default off", !Value)
|
||||
.AddClass("disabled", IsDisabled)
|
||||
.Build();
|
||||
|
||||
/// <summary>
|
||||
/// 获得 Style 集合
|
||||
/// </summary>
|
||||
protected string? StyleName => CssBuilder.Default()
|
||||
.AddClass($"width: {Width}px;", Width > 0)
|
||||
.Build();
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 组件高度
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public int Width { get; set; } = 120;
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 组件 On 时显示文本
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public string OnText { get; set; } = "展开";
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 是否禁用
|
||||
/// </summary>
|
||||
[Parameter] public bool IsDisabled { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 组件 Off 时显示文本
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public string OffText { get; set; } = "收缩";
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 组件是否处于 On 状态 默认为 Off 状态
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public bool Value { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 组件颜色 默认为 Success 颜色
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public Color Color { get; set; } = Color.Success;
|
||||
|
||||
/// <summary>
|
||||
/// 点击控件时触发此方法
|
||||
/// </summary>
|
||||
protected void OnClick()
|
||||
{
|
||||
if (!IsDisabled)
|
||||
{
|
||||
Value = !Value;
|
||||
OnValueChanged?.Invoke(Value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 控件值变化时触发此事件
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public Action<bool>? OnValueChanged { get; set; }
|
||||
}
|
||||
}
|
140
src/BootstrapBlazor/wwwroot/css/bootstrap.blazor.css
vendored
140
src/BootstrapBlazor/wwwroot/css/bootstrap.blazor.css
vendored
@ -186,3 +186,143 @@ a {
|
||||
border-color: #28a745;
|
||||
box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(40, 167, 69,.6);
|
||||
}
|
||||
|
||||
/*toggle*/
|
||||
.toggle {
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.toggle.btn {
|
||||
min-width: 70px;
|
||||
min-height: 35px;
|
||||
}
|
||||
|
||||
.toggle.off .toggle-group {
|
||||
left: -100%;
|
||||
}
|
||||
|
||||
.toggle .btn-default, .toggle.btn-default {
|
||||
background-color: #e0e0e0;
|
||||
border-color: #ccc;
|
||||
box-shadow: inset 0 1px 0 rgba(255, 255, 255, .15), 0 1px 1px rgba(0, 0, 0, .075);
|
||||
}
|
||||
|
||||
.toggle .btn-default:hover {
|
||||
color: #333;
|
||||
background-color: #d4d4d4;
|
||||
}
|
||||
|
||||
.toggle .toggle-group {
|
||||
position: absolute;
|
||||
width: 200%;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
-webkit-transition: left 0.35s;
|
||||
-moz-user-select: none;
|
||||
-webkit-user-select: none;
|
||||
transition: left 0.35s;
|
||||
}
|
||||
|
||||
.toggle .toggle-group label {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.toggle .toggle-group label, .toggle .toggle-group span {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.toggle .btn-handle {
|
||||
position: relative;
|
||||
margin: 0 auto;
|
||||
padding-top: 0px;
|
||||
padding-bottom: 0px;
|
||||
height: 100%;
|
||||
width: 0px;
|
||||
border-width: 0 1px;
|
||||
background-image: linear-gradient(to bottom, #fff 0%, #e0e0e0 100%);
|
||||
border-color: #ccc;
|
||||
box-shadow: inset 0 1px 0 rgba(255, 255, 255, .15), 0 1px 1px rgba(0, 0, 0, .075);
|
||||
}
|
||||
|
||||
.toggle .toggle-on {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 50%;
|
||||
margin: 0;
|
||||
border: 0;
|
||||
border-radius: 0;
|
||||
}
|
||||
|
||||
.toggle .toggle-on.btn {
|
||||
padding-right: 24px;
|
||||
}
|
||||
|
||||
.toggle .toggle-on.btn-lg {
|
||||
padding-right: 31px;
|
||||
}
|
||||
|
||||
.toggle.off .toggle-off {
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.toggle .toggle-off {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
left: 50%;
|
||||
right: 0;
|
||||
margin: 0;
|
||||
border: 0;
|
||||
border-radius: 0;
|
||||
background-color: #e0e0e0;
|
||||
}
|
||||
|
||||
.toggle .toggle-off.btn {
|
||||
padding-left: 24px;
|
||||
}
|
||||
|
||||
.toggle .toggle-off.btn-lg {
|
||||
padding-left: 31px;
|
||||
}
|
||||
|
||||
.toggle.btn-lg {
|
||||
min-width: 79px;
|
||||
min-height: 45px;
|
||||
}
|
||||
|
||||
.toggle-handle.btn-lg {
|
||||
width: 40px;
|
||||
}
|
||||
|
||||
.toggle.btn-sm {
|
||||
min-width: 50px;
|
||||
min-height: 30px;
|
||||
}
|
||||
|
||||
.toggle-on.btn-sm {
|
||||
padding-right: 20px;
|
||||
}
|
||||
|
||||
.toggle-off.btn-sm {
|
||||
padding-left: 20px;
|
||||
}
|
||||
|
||||
.toggle.btn-xs {
|
||||
min-width: 35px;
|
||||
min-height: 22px;
|
||||
}
|
||||
|
||||
.toggle-on.btn-xs {
|
||||
padding-right: 12px;
|
||||
}
|
||||
|
||||
.toggle-off.btn-xs {
|
||||
padding-left: 12px;
|
||||
}
|
||||
/*end toggle*/
|
||||
|
Loading…
Reference in New Issue
Block a user