UI: Fix for truncate center component (#6213)

This commit is contained in:
d11n 2024-09-13 10:55:31 +02:00 committed by GitHub
parent e389d6a96b
commit b7ba53eb60
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 25 additions and 21 deletions

View file

@ -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>

View file

@ -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);
}

View file

@ -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; }
}