Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions src/BootstrapBlazor.Server/Components/Samples/FileIcons.razor
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,37 @@
</div>
</DemoBlock>

<DemoBlock Title="@Localizer["SizeTitle"]" Introduction="@Localizer["SizeIntro"]" Name="Size">
<div class="row row-cols-auto g-2">
<div class="col">
<FileIcon Extension=".xlsx" IconColor="Color.Success" Size="Size.ExtraSmall">
</FileIcon>
</div>
<div class="col ms-3">
<FileIcon Extension=".xlsx" IconColor="Color.Success" Size="Size.Small">
</FileIcon>
</div>
<div class="col ms-3">
<FileIcon Extension=".xlsx" IconColor="Color.Success" Size="Size.None">
</FileIcon>
</div>
<div class="col ms-3">
<FileIcon Extension=".xlsx" IconColor="Color.Success" Size="Size.Medium">
</FileIcon>
</div>
<div class="col ms-3">
<FileIcon Extension=".xlsx" IconColor="Color.Success" Size="Size.Large">
</FileIcon>
</div>
<div class="col ms-3">
<FileIcon Extension=".xlsx" IconColor="Color.Success" Size="Size.ExtraLarge">
</FileIcon>
</div>
<div class="col ms-3">
<FileIcon Extension=".xlsx" IconColor="Color.Success" Size="Size.ExtraExtraLarge">
</FileIcon>
</div>
</div>
</DemoBlock>

<AttributeTable Items="@GetAttributes()" />
4 changes: 3 additions & 1 deletion src/BootstrapBlazor.Server/Locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -5961,7 +5961,9 @@
"CustomCssIntro": "Set <code>class</code> parameter set the style for the file icon component",
"ExtensionAttr": "The extension of file",
"IconColorAttr": "The backgound color for badge of extension",
"BackgroundTemplateAttr": "The template for custom the backgroup file"
"BackgroundTemplateAttr": "The template for custom the backgroup file",
"SizeTitle": "Size",
"SizeIntro":"Set the icon size by setting <code>Size</code>"
},
"BootstrapBlazor.Server.Components.Samples.PdfReaders": {
"Title": "PDF Reader",
Expand Down
4 changes: 3 additions & 1 deletion src/BootstrapBlazor.Server/Locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -5961,7 +5961,9 @@
"CustomCssIntro": "通过设置 <code>class</code> 自定义样式调整图标大小",
"ExtensionAttr": "文件扩展名",
"IconColorAttr": "扩展名标签背景色",
"BackgroundTemplateAttr": "自定义背景图模板"
"BackgroundTemplateAttr": "自定义背景图模板",
"SizeTitle": "大小",
"SizeIntro": "通过设置 <code>Size</code> 设置图标大小"
},
"BootstrapBlazor.Server.Components.Samples.PdfReaders": {
"Title": "PDF Reader PDF阅读器",
Expand Down
9 changes: 7 additions & 2 deletions src/BootstrapBlazor/Components/FileIcon/FileIcon.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace BootstrapBlazor.Components;
public partial class FileIcon
{
private string? ClassString => CssBuilder.Default("file-icon")
.AddClass($"file-icon-{Size.ToDescriptionString()}", Size != Size.None)
.AddClassFromAttributes(AdditionalAttributes)
.Build();

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

/// <summary>
Expand All @@ -38,4 +37,10 @@ public partial class FileIcon
/// </summary>
[Parameter]
public Color IconColor { get; set; } = Color.Primary;

/// <summary>
/// 获得/设置 图标大小 默认 Color.None
/// </summary>
[Parameter]
public Size Size { get; set; }
}
30 changes: 28 additions & 2 deletions src/BootstrapBlazor/Components/FileIcon/FileIcon.razor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
--bb-file-icon-padding-left: #{$bb-file-icon-padding-left};
--bb-file-icon-badge-bottom: #{$bb-file-icon-badge-bottom};
--bb-file-icon-path-fill-color: #{$bb-file-icon-path-fill-color};
--bb-file-icon-size: 1;
padding-left: var(--bb-file-icon-padding-left);
display: inline-block;
position: relative;

.icon-svg {
width: var(--bb-file-icon-width);
height: var(--bb-file-icon-height);
width: calc(var(--bb-file-icon-width) * var(--bb-file-icon-size));
height: calc(var(--bb-file-icon-height) * var(--bb-file-icon-size));

path {
fill: var(--bb-file-icon-path-fill-color);
Expand All @@ -21,5 +22,30 @@
position: absolute;
bottom: var(--bb-file-icon-badge-bottom);
left: 0;
font-size: calc(var(--bs-badge-font-size) * var(--bb-file-icon-size));
}

&.file-icon-xs {
--bb-file-icon-size: 0.5;
}

&.file-icon-sm {
--bb-file-icon-size: 0.75;
}

&.file-icon-md {
--bb-file-icon-size: 1.25;
}

&.file-icon-lg {
--bb-file-icon-size: 1.5;
}

&.file-icon-xl {
--bb-file-icon-size: 1.75;
}

&.file-icon-xxl {
--bb-file-icon-size: 2;
}
}
29 changes: 29 additions & 0 deletions test/UnitTest/Components/FileIconTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,33 @@ public void BackgroundTemplate_Ok()
});
cut.Contains("test-content");
}

[Theory]
[InlineData(Size.ExtraSmall)]
[InlineData(Size.Small)]
[InlineData(Size.Medium)]
[InlineData(Size.Large)]
[InlineData(Size.ExtraLarge)]
[InlineData(Size.ExtraExtraLarge)]
public void Size_Ok(Size size)
{
var cut = Context.RenderComponent<FileIcon>(pb =>
{
pb.Add(a => a.Extension, ".xlsx");
pb.Add(a => a.Size, size);
});
cut.Contains($"file-icon file-icon-{size.ToDescriptionString()}");
}

[Fact]
public void Size_None()
{
var cut = Context.RenderComponent<FileIcon>(pb =>
{
pb.Add(a => a.Extension, ".xlsx");
pb.Add(a => a.Size, Size.None);
});
cut.Contains("file-icon");
cut.DoesNotContain("file-icon-none");
}
}