Skip to content

Commit 378e17b

Browse files
authored
feat(Tab): add ShowContextFullScreenButton parameter (#5739)
* style: 微调 divider 间隙 * feat: 增加 ShowContextMenuFullScreen 参数 * feat: 增加 ContextMenuFullScreenIcon 参数 * feat: 增加全屏右键菜单 * revert: 更新文档 * test: 更新单元测试
1 parent 97d9b30 commit 378e17b

File tree

11 files changed

+48
-8
lines changed

11 files changed

+48
-8
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -500,9 +500,8 @@ private void Navigation()
500500
<section ignore>
501501
<p>@((MarkupString)Localizer["TabsContextMenuDesc"].Value)</p>
502502
</section>
503-
<Tab IsCard="true" ShowClose="true" TabStyle="TabStyle.Chrome" ShowToolbar="true" ShowContextMenu="true"
504-
OnBeforeShowContextMenu="OnBeforeShowContextMenu">
505-
<TabItem Text="@Localizer["TabItem1Text"]" Icon="fa-solid fa-user" IsDisabled="true">
503+
<Tab IsCard="true" ShowClose="true" TabStyle="TabStyle.Chrome" ShowToolbar="true" ShowContextMenu="true">
504+
<TabItem Text="@Localizer["TabItem1Text"]" Icon="fa-solid fa-user">
506505
<div>@Localizer["TabItem1Content"]</div>
507506
<Counter></Counter>
508507
</TabItem>

src/BootstrapBlazor/Components/ContextMenu/ContextMenu.razor.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.bb-cm {
1+
.bb-cm {
22
--bb-cm-icon-min-width: #{$bb-cm-icon-min-width};
33
--bb-cm-icon-min-height: #{$bb-cm-icon-min-height};
44
z-index: 1200;
@@ -10,6 +10,6 @@
1010
}
1111

1212
.divider {
13-
margin: 0.5rem 0;
13+
margin: 0.25rem 0;
1414
}
1515
}

src/BootstrapBlazor/Components/Tab/Tab.razor

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ else if (ShowContextMenu)
2020
<ContextMenuItem Icon="@ContextMenuCloseIcon" Text="@Localizer["ContextClose"]" OnClick="OnClose"></ContextMenuItem>
2121
<ContextMenuItem Icon="@ContextMenuCloseOtherIcon" Text="@Localizer["ContextCloseOther"]" OnClick="OnCloseOther"></ContextMenuItem>
2222
<ContextMenuItem Icon="@ContextMenuCloseAllIcon" Text="@Localizer["ContextCloseAll"]" OnClick="OnCloseAll"></ContextMenuItem>
23+
@if (ShowContextMenuFullScreen)
24+
{
25+
<ContextMenuDivider></ContextMenuDivider>
26+
<ContextMenuItem Icon="@ContextMenuFullScreenIcon" Text="@Localizer["ContextFullScreen"]" OnClick="OnFullScreen"></ContextMenuItem>
27+
}
2328
@if (ContextMenuTemplate != null)
2429
{
2530
@ContextMenuTemplate(this)

src/BootstrapBlazor/Components/Tab/Tab.razor.cs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,12 @@ public partial class Tab : IHandlerException
114114
[Parameter]
115115
public bool ShowFullScreen { get; set; }
116116

117+
/// <summary>
118+
/// Gets or sets whether show the full screen button on context menu. Default is true.
119+
/// </summary>
120+
[Parameter]
121+
public bool ShowContextMenuFullScreen { get; set; } = true;
122+
117123
/// <summary>
118124
/// 关闭标签页回调方法
119125
/// </summary>
@@ -401,6 +407,12 @@ public partial class Tab : IHandlerException
401407
[Parameter]
402408
public string? ContextMenuCloseAllIcon { get; set; }
403409

410+
/// <summary>
411+
/// Gets or sets the icon of tab item context menu full screen button. Default is null.
412+
/// </summary>
413+
[Parameter]
414+
public string? ContextMenuFullScreenIcon { get; set; }
415+
404416
/// <summary>
405417
/// Gets or sets before popup context menu callback. Default is null.
406418
/// </summary>
@@ -433,6 +445,10 @@ public partial class Tab : IHandlerException
433445
[Inject, NotNull]
434446
private DialogService? DialogService { get; set; }
435447

448+
[Inject]
449+
[NotNull]
450+
private FullScreenService? FullScreenService { get; set; }
451+
436452
private ContextMenuZone? _contextMenuZone;
437453

438454
private ConcurrentDictionary<TabItem, bool> LazyTabCache { get; } = new();
@@ -490,6 +506,7 @@ protected override void OnParametersSet()
490506
ContextMenuCloseIcon ??= IconTheme.GetIconByKey(ComponentIcons.TabContextMenuCloseIcon);
491507
ContextMenuCloseOtherIcon ??= IconTheme.GetIconByKey(ComponentIcons.TabContextMenuCloseOtherIcon);
492508
ContextMenuCloseAllIcon ??= IconTheme.GetIconByKey(ComponentIcons.TabContextMenuCloseAllIcon);
509+
ContextMenuFullScreenIcon ??= IconTheme.GetIconByKey(ComponentIcons.TabContextMenuFullScreenIcon);
493510

494511
if (AdditionalAssemblies is null)
495512
{
@@ -1016,7 +1033,7 @@ public async Task DragItemCallback(int originIndex, int currentIndex)
10161033
}
10171034
}
10181035

1019-
private string? GetIdByTabItem(TabItem item) => ComponentIdGenerator.Generate(item);
1036+
private string GetIdByTabItem(TabItem item) => ComponentIdGenerator.Generate(item);
10201037

10211038
private async Task OnRefreshAsync()
10221039
{
@@ -1075,6 +1092,14 @@ private Task OnCloseAll(ContextMenuItem item, object? context)
10751092
return Task.CompletedTask;
10761093
}
10771094

1095+
private async Task OnFullScreen(ContextMenuItem item, object? context)
1096+
{
1097+
if (context is TabItem tabItem)
1098+
{
1099+
await FullScreenService.ToggleById(GetIdByTabItem(tabItem));
1100+
}
1101+
}
1102+
10781103
private async Task OnContextMenu(MouseEventArgs e, TabItem item)
10791104
{
10801105
if (_contextMenuZone != null)

src/BootstrapBlazor/Enums/ComponentIcons.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,11 @@ public enum ComponentIcons
730730
/// </summary>
731731
TabContextMenuCloseAllIcon,
732732

733+
/// <summary>
734+
/// Tab 组件 TabContextMenuFullScreenIcon 属性图标
735+
/// </summary>
736+
TabContextMenuFullScreenIcon,
737+
733738
/// <summary>
734739
/// Timer 组件 Icon 属性图标
735740
/// </summary>

src/BootstrapBlazor/Icons/BootstrapIcons.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ internal static class BootstrapIcons
9090
{ ComponentIcons.TabContextMenuCloseIcon, "bi bi-x" },
9191
{ ComponentIcons.TabContextMenuCloseOtherIcon, "bi bi-arrow" },
9292
{ ComponentIcons.TabContextMenuCloseAllIcon, "bi bi-arrow-left-right" },
93+
{ ComponentIcons.TabContextMenuFullScreenIcon, "bi bi-arrows-fullscreen" },
9394

9495
{ ComponentIcons.LogoutLinkIcon, "bi bi-box-arrow-right" },
9596

src/BootstrapBlazor/Icons/FontAwesomeIcons.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ internal static class FontAwesomeIcons
9090
{ ComponentIcons.TabContextMenuCloseIcon, "fa-fw fa-solid fa-xmark" },
9191
{ ComponentIcons.TabContextMenuCloseOtherIcon, "fa-fw fa-solid fa-left-right" },
9292
{ ComponentIcons.TabContextMenuCloseAllIcon, "fa-fw fa-solid fa-arrows-left-right-to-line" },
93+
{ ComponentIcons.TabContextMenuFullScreenIcon, "fa-fw fa-solid fa-maximize" },
9394

9495
{ ComponentIcons.LogoutLinkIcon, "fa-solid fa-key" },
9596

src/BootstrapBlazor/Icons/MaterialDesignIcons.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ internal static class MaterialDesignIcons
9090
{ ComponentIcons.TabContextMenuCloseIcon, "mdi mdi-close" },
9191
{ ComponentIcons.TabContextMenuCloseOtherIcon, "mdi mdi-menu" },
9292
{ ComponentIcons.TabContextMenuCloseAllIcon, "mdi mdi-arrow-left-right-bold" },
93+
{ ComponentIcons.TabContextMenuFullScreenIcon, "mdi mdi-arrow-expand-all" },
9394

9495
{ ComponentIcons.LogoutLinkIcon, "mdi mdi-logout" },
9596

src/BootstrapBlazor/Locales/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@
182182
"ContextRefresh": "Refresh",
183183
"ContextClose": "Close",
184184
"ContextCloseOther": "Close Other Tabs",
185-
"ContextCloseAll": "Close All Tabs"
185+
"ContextCloseAll": "Close All Tabs",
186+
"ContextFullScreen": "Full screen"
186187
},
187188
"BootstrapBlazor.Components.MultiFilter": {
188189
"MultiFilterSearchPlaceHolderText": "Please enter ...",

src/BootstrapBlazor/Locales/zh.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@
182182
"ContextRefresh": "刷新",
183183
"ContextClose": "关闭",
184184
"ContextCloseOther": "关闭其他",
185-
"ContextCloseAll": "关闭全部"
185+
"ContextCloseAll": "关闭全部",
186+
"ContextFullScreen": "全屏"
186187
},
187188
"BootstrapBlazor.Components.MultiFilter": {
188189
"MultiFilterSearchPlaceHolderText": "请输入 ...",

0 commit comments

Comments
 (0)