mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-02-20 13:34:37 +01:00
UI: Fix for truncate center component (#6213)
This commit is contained in:
parent
e389d6a96b
commit
b7ba53eb60
3 changed files with 25 additions and 21 deletions
|
@ -1,7 +1,6 @@
|
|||
@model BTCPayServer.Components.TruncateCenter.TruncateCenterViewModel
|
||||
@{
|
||||
var classes = string.IsNullOrEmpty(Model.Classes) ? string.Empty : Model.Classes.Trim();
|
||||
var isTruncated = !string.IsNullOrEmpty(Model.Start) && !string.IsNullOrEmpty(Model.End);
|
||||
@if (Model.Copy) classes += " truncate-center--copy";
|
||||
@if (Model.Elastic) classes += " truncate-center--elastic";
|
||||
var prefix = Model.IsVue ? ":" : "";
|
||||
|
@ -24,8 +23,8 @@
|
|||
}
|
||||
else
|
||||
{
|
||||
<span class="truncate-center-truncated" @(isTruncated ? $"data-bs-toggle=tooltip title={Model.Text}" : "")>
|
||||
<span class="truncate-center-start">@(Model.Elastic || !isTruncated ? Model.Text[..^Model.Padding] : $"{Model.Start}…")</span>
|
||||
<span class="truncate-center-truncated" @(Model.IsTruncated ? $"data-bs-toggle=tooltip title={Model.Text}" : "")>
|
||||
<span class="truncate-center-start">@Model.Start</span>
|
||||
<span class="truncate-center-end">@Model.End</span>
|
||||
</span>
|
||||
<span class="truncate-center-text">@Model.Text</span>
|
||||
|
|
|
@ -19,6 +19,7 @@ public class TruncateCenter : ViewComponent
|
|||
{
|
||||
if (string.IsNullOrEmpty(text))
|
||||
return new HtmlContentViewComponentResult(new StringHtmlContent(string.Empty));
|
||||
|
||||
var vm = new TruncateCenterViewModel
|
||||
{
|
||||
Classes = classes,
|
||||
|
@ -28,12 +29,15 @@ public class TruncateCenter : ViewComponent
|
|||
Copy = copy,
|
||||
Text = text,
|
||||
Link = link,
|
||||
Id = id
|
||||
Id = id,
|
||||
IsTruncated = text.Length > 2 * padding
|
||||
};
|
||||
if (!isVue && text.Length > 2 * padding)
|
||||
if (!vm.IsVue)
|
||||
{
|
||||
vm.Start = text[..padding];
|
||||
vm.End = text[^padding..];
|
||||
vm.Start = vm.IsTruncated ? text[..padding] : text;
|
||||
vm.End = vm.IsTruncated ? text[^padding..] : string.Empty;
|
||||
if (!vm.Elastic && vm.IsTruncated)
|
||||
vm.Start = $"{vm.Start}…";
|
||||
}
|
||||
return View(vm);
|
||||
}
|
||||
|
|
|
@ -1,16 +1,17 @@
|
|||
namespace BTCPayServer.Components.TruncateCenter
|
||||
#nullable enable
|
||||
namespace BTCPayServer.Components.TruncateCenter;
|
||||
|
||||
public class TruncateCenterViewModel
|
||||
{
|
||||
public class TruncateCenterViewModel
|
||||
{
|
||||
public string Text { get; set; }
|
||||
public string Start { get; set; }
|
||||
public string End { get; set; }
|
||||
public string Id { get; set; }
|
||||
public string Classes { get; set; }
|
||||
public string Link { get; set; }
|
||||
public int Padding { get; set; }
|
||||
public bool Copy { get; set; }
|
||||
public bool Elastic { get; set; }
|
||||
public bool IsVue { get; set; }
|
||||
}
|
||||
public string Text { get; init; } = null!;
|
||||
public string? Start { get; set; }
|
||||
public string? End { get; set; }
|
||||
public string? Id { get; init; }
|
||||
public string? Classes { get; init; }
|
||||
public string? Link { get; init; }
|
||||
public int Padding { get; init; }
|
||||
public bool Copy { get; init; }
|
||||
public bool Elastic { get; init; }
|
||||
public bool IsVue { get; init; }
|
||||
public bool IsTruncated { get; init; }
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue