Skip to content

Commit b58d252

Browse files
authored
doc(Pre): add Height parameter (#7713)
1 parent ac30d0b commit b58d252

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

src/BootstrapBlazor.Server/Components/Components/Pre.razor

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
@inherits WebSiteModuleComponentBase
1+
@inherits WebSiteModuleComponentBase
22
@attribute [JSModuleAutoLoader("Components/Pre.razor.js")]
33
@inject IOptions<WebsiteOptions> WebsiteOption
44

55
<div @attributes="@AdditionalAttributes" class="@ClassString" id="@Id" data-bb-title="@CopiedText">
66
<p class="loading">@LoadingText</p>
77
@if (Loaded)
88
{
9-
<pre class="scroll"><code>@ChildContent</code></pre>
9+
<pre class="scroll" style="@StyleString"><code>@ChildContent</code></pre>
1010
@if (CanCopy)
1111
{
1212
@if (ShowToolbar)

src/BootstrapBlazor.Server/Components/Components/Pre.razor.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the Apache 2.0 License
33
// See the LICENSE file in the project root for more information.
44
// Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone
@@ -53,6 +53,12 @@ public partial class Pre
5353
[Parameter]
5454
public bool ShowToolbar { get; set; }
5555

56+
/// <summary>
57+
/// 获得/设置 组件高度 默认 null 不设置高度
58+
/// </summary>
59+
[Parameter]
60+
public string? Height { get; set; }
61+
5662
[Inject]
5763
[NotNull]
5864
private IStringLocalizer<Pre>? Localizer { get; set; }
@@ -67,6 +73,12 @@ public partial class Pre
6773

6874
private string? CopiedText { get; set; }
6975

76+
private string? StyleString => CssBuilder.Default()
77+
.AddClass($"height: {Height};", !string.IsNullOrEmpty(Height))
78+
.AddClass("max-height: 260px;", string.IsNullOrEmpty(Height))
79+
.AddClassFromAttributes(AdditionalAttributes)
80+
.Build();
81+
7082
/// <summary>
7183
/// <inheritdoc/>
7284
/// </summary>

src/BootstrapBlazor.Server/Components/Components/Pre.razor.css

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.pre-code {
1+
.pre-code {
22
position: relative;
33
border: 1px solid var(--bs-border-color);
44
border-radius: var(--bs-border-radius);
@@ -22,7 +22,6 @@
2222
.pre-code > pre {
2323
color: #e83e8c;
2424
margin-bottom: 0;
25-
max-height: 260px;
2625
}
2726

2827
::deep .btn-group {

0 commit comments

Comments
 (0)