Skip to content

Commit c7be111

Browse files
authored
feat(ColorPicker): add Swatches parameter (#4560)
* feat: 增加 Swatches 参数 * test: 更新单元测试 * chore: bump version 8.11.0
1 parent 39ba47c commit c7be111

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

src/BootstrapBlazor/BootstrapBlazor.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Razor">
22

33
<PropertyGroup>
4-
<Version>8.10.5-beta01</Version>
4+
<Version>8.11.0</Version>
55
</PropertyGroup>
66

77
<ItemGroup>

src/BootstrapBlazor/Components/ColorPicker/ColorPicker.razor.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ public partial class ColorPicker
3737
[Parameter]
3838
public bool IsSupportOpacity { get; set; }
3939

40+
/// <summary>
41+
/// 获得/设置 预设候选颜色 <see cref="IsSupportOpacity"/> 开启时生效 默认 null
42+
/// </summary>
43+
/// <remarks>字符串集合格式为 ["rgba(244, 67, 54, 1)", "rgba(233, 30, 99, 0.95)"]</remarks>
44+
[Parameter]
45+
public List<string>? Swatches { get; set; }
46+
4047
private string? _formattedValueString;
4148

4249
private bool _originalSupportOpacityValue;
@@ -72,15 +79,15 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
7279
{
7380
_originalSupportOpacityValue = IsSupportOpacity;
7481
_originalIsDisabledValue = IsDisabled;
75-
await InvokeVoidAsync("update", Id, new { IsSupportOpacity, Value, Disabled = IsDisabled, Lang = CultureInfo.CurrentUICulture.Name });
82+
await InvokeVoidAsync("update", Id, new { IsSupportOpacity, Value, Disabled = IsDisabled, Lang = CultureInfo.CurrentUICulture.Name, Swatches });
7683
}
7784
}
7885

7986
/// <summary>
8087
/// <inheritdoc/>
8188
/// </summary>
8289
/// <returns></returns>
83-
protected override Task InvokeInitAsync() => InvokeVoidAsync("init", Id, Interop, new { IsSupportOpacity, Default = Value, Disabled = IsDisabled, Lang = CultureInfo.CurrentUICulture.Name });
90+
protected override Task InvokeInitAsync() => InvokeVoidAsync("init", Id, Interop, new { IsSupportOpacity, Default = Value, Disabled = IsDisabled, Lang = CultureInfo.CurrentUICulture.Name, Swatches });
8491

8592
private async Task Setter(string v)
8693
{

src/BootstrapBlazor/Components/ColorPicker/ColorPicker.razor.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,14 @@ const getOptions = (el, options) => {
9797
'rgba(103, 58, 183, 0.85)',
9898
'rgba(63, 81, 181, 0.8)',
9999
'rgba(33, 150, 243, 0.75)',
100-
'rgba(3, 169, 244, 0.7)'
100+
'rgba(3, 169, 244, 0.7)',
101+
'rgba(0, 188, 212, 0.7)',
102+
'rgba(0, 150, 136, 0.75)',
103+
'rgba(76, 175, 80, 0.8)',
104+
'rgba(139, 195, 74, 0.85)',
105+
'rgba(205, 220, 57, 0.9)',
106+
'rgba(255, 235, 59, 0.95)',
107+
'rgba(255, 193, 7, 1)'
101108
],
102109
defaultRepresentation: 'HEXA',
103110
components: {

test/UnitTest/Components/ColorPickerTest.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public async Task IsSupportOpacity_Ok()
5858
{
5959
builder.Add(a => a.IsSupportOpacity, true);
6060
builder.Add(a => a.Value, "#AABBCCDD");
61+
builder.Add(a => a.Swatches, ["rgba(123, 1, 2, 1)", "rgba(1, 255,10, 1)"]);
6162
});
6263
cut.Contains("<div class=\"bb-color-picker-body\" style=\"--bb-color-pick-val: #AABBCCDD\"></div>");
6364

0 commit comments

Comments
 (0)