Skip to content

Commit 12f5d72

Browse files
authored
feat(FileIcon): add Size parameter (#5263)
* feat: 增加 Size 参数 * doc: 增加文档 * doc: 增加本地化资源 * test: 增加单元测试
1 parent eaa9a8b commit 12f5d72

File tree

6 files changed

+103
-6
lines changed

6 files changed

+103
-6
lines changed

src/BootstrapBlazor.Server/Components/Samples/FileIcons.razor

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,37 @@
118118
</div>
119119
</DemoBlock>
120120

121+
<DemoBlock Title="@Localizer["SizeTitle"]" Introduction="@Localizer["SizeIntro"]" Name="Size">
122+
<div class="row row-cols-auto g-2">
123+
<div class="col">
124+
<FileIcon Extension=".xlsx" IconColor="Color.Success" Size="Size.ExtraSmall">
125+
</FileIcon>
126+
</div>
127+
<div class="col ms-3">
128+
<FileIcon Extension=".xlsx" IconColor="Color.Success" Size="Size.Small">
129+
</FileIcon>
130+
</div>
131+
<div class="col ms-3">
132+
<FileIcon Extension=".xlsx" IconColor="Color.Success" Size="Size.None">
133+
</FileIcon>
134+
</div>
135+
<div class="col ms-3">
136+
<FileIcon Extension=".xlsx" IconColor="Color.Success" Size="Size.Medium">
137+
</FileIcon>
138+
</div>
139+
<div class="col ms-3">
140+
<FileIcon Extension=".xlsx" IconColor="Color.Success" Size="Size.Large">
141+
</FileIcon>
142+
</div>
143+
<div class="col ms-3">
144+
<FileIcon Extension=".xlsx" IconColor="Color.Success" Size="Size.ExtraLarge">
145+
</FileIcon>
146+
</div>
147+
<div class="col ms-3">
148+
<FileIcon Extension=".xlsx" IconColor="Color.Success" Size="Size.ExtraExtraLarge">
149+
</FileIcon>
150+
</div>
151+
</div>
152+
</DemoBlock>
153+
121154
<AttributeTable Items="@GetAttributes()" />

src/BootstrapBlazor.Server/Locales/en-US.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5961,7 +5961,9 @@
59615961
"CustomCssIntro": "Set <code>class</code> parameter set the style for the file icon component",
59625962
"ExtensionAttr": "The extension of file",
59635963
"IconColorAttr": "The backgound color for badge of extension",
5964-
"BackgroundTemplateAttr": "The template for custom the backgroup file"
5964+
"BackgroundTemplateAttr": "The template for custom the backgroup file",
5965+
"SizeTitle": "Size",
5966+
"SizeIntro":"Set the icon size by setting <code>Size</code>"
59655967
},
59665968
"BootstrapBlazor.Server.Components.Samples.PdfReaders": {
59675969
"Title": "PDF Reader",

src/BootstrapBlazor.Server/Locales/zh-CN.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5961,7 +5961,9 @@
59615961
"CustomCssIntro": "通过设置 <code>class</code> 自定义样式调整图标大小",
59625962
"ExtensionAttr": "文件扩展名",
59635963
"IconColorAttr": "扩展名标签背景色",
5964-
"BackgroundTemplateAttr": "自定义背景图模板"
5964+
"BackgroundTemplateAttr": "自定义背景图模板",
5965+
"SizeTitle": "大小",
5966+
"SizeIntro": "通过设置 <code>Size</code> 设置图标大小"
59655967
},
59665968
"BootstrapBlazor.Server.Components.Samples.PdfReaders": {
59675969
"Title": "PDF Reader PDF阅读器",

src/BootstrapBlazor/Components/FileIcon/FileIcon.razor.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace BootstrapBlazor.Components;
1111
public partial class FileIcon
1212
{
1313
private string? ClassString => CssBuilder.Default("file-icon")
14+
.AddClass($"file-icon-{Size.ToDescriptionString()}", Size != Size.None)
1415
.AddClassFromAttributes(AdditionalAttributes)
1516
.Build();
1617

@@ -22,9 +23,7 @@ public partial class FileIcon
2223
/// 获得/设置 文件类型扩展名
2324
/// </summary>
2425
[Parameter]
25-
#if NET6_0_OR_GREATER
2626
[EditorRequired]
27-
#endif
2827
public string? Extension { get; set; }
2928

3029
/// <summary>
@@ -38,4 +37,10 @@ public partial class FileIcon
3837
/// </summary>
3938
[Parameter]
4039
public Color IconColor { get; set; } = Color.Primary;
40+
41+
/// <summary>
42+
/// 获得/设置 图标大小 默认 Color.None
43+
/// </summary>
44+
[Parameter]
45+
public Size Size { get; set; }
4146
}

src/BootstrapBlazor/Components/FileIcon/FileIcon.razor.scss

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
--bb-file-icon-padding-left: #{$bb-file-icon-padding-left};
55
--bb-file-icon-badge-bottom: #{$bb-file-icon-badge-bottom};
66
--bb-file-icon-path-fill-color: #{$bb-file-icon-path-fill-color};
7+
--bb-file-icon-size: 1;
78
padding-left: var(--bb-file-icon-padding-left);
89
display: inline-block;
910
position: relative;
1011

1112
.icon-svg {
12-
width: var(--bb-file-icon-width);
13-
height: var(--bb-file-icon-height);
13+
width: calc(var(--bb-file-icon-width) * var(--bb-file-icon-size));
14+
height: calc(var(--bb-file-icon-height) * var(--bb-file-icon-size));
1415

1516
path {
1617
fill: var(--bb-file-icon-path-fill-color);
@@ -21,5 +22,30 @@
2122
position: absolute;
2223
bottom: var(--bb-file-icon-badge-bottom);
2324
left: 0;
25+
font-size: calc(var(--bs-badge-font-size) * var(--bb-file-icon-size));
26+
}
27+
28+
&.file-icon-xs {
29+
--bb-file-icon-size: 0.5;
30+
}
31+
32+
&.file-icon-sm {
33+
--bb-file-icon-size: 0.75;
34+
}
35+
36+
&.file-icon-md {
37+
--bb-file-icon-size: 1.25;
38+
}
39+
40+
&.file-icon-lg {
41+
--bb-file-icon-size: 1.5;
42+
}
43+
44+
&.file-icon-xl {
45+
--bb-file-icon-size: 1.75;
46+
}
47+
48+
&.file-icon-xxl {
49+
--bb-file-icon-size: 2;
2450
}
2551
}

test/UnitTest/Components/FileIconTest.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,33 @@ public void BackgroundTemplate_Ok()
3939
});
4040
cut.Contains("test-content");
4141
}
42+
43+
[Theory]
44+
[InlineData(Size.ExtraSmall)]
45+
[InlineData(Size.Small)]
46+
[InlineData(Size.Medium)]
47+
[InlineData(Size.Large)]
48+
[InlineData(Size.ExtraLarge)]
49+
[InlineData(Size.ExtraExtraLarge)]
50+
public void Size_Ok(Size size)
51+
{
52+
var cut = Context.RenderComponent<FileIcon>(pb =>
53+
{
54+
pb.Add(a => a.Extension, ".xlsx");
55+
pb.Add(a => a.Size, size);
56+
});
57+
cut.Contains($"file-icon file-icon-{size.ToDescriptionString()}");
58+
}
59+
60+
[Fact]
61+
public void Size_None()
62+
{
63+
var cut = Context.RenderComponent<FileIcon>(pb =>
64+
{
65+
pb.Add(a => a.Extension, ".xlsx");
66+
pb.Add(a => a.Size, Size.None);
67+
});
68+
cut.Contains("file-icon");
69+
cut.DoesNotContain("file-icon-none");
70+
}
4271
}

0 commit comments

Comments
 (0)