support inner links in truncated string component

This commit is contained in:
Mononaut 2023-01-16 16:47:05 -06:00
parent dfd1de67b2
commit 73f2d54a26
No known key found for this signature in database
GPG Key ID: A3F058E41374C04E
12 changed files with 56 additions and 58 deletions

View File

@ -1,11 +1,9 @@
<div class="container-xl"> <div class="container-xl">
<h1 i18n="shared.address">Address</h1> <h1 i18n="shared.address">Address</h1>
<span class="address-link"> <span class="address-link">
<a [routerLink]="['/address/' | relativeUrl, addressString]"> <app-truncate [text]="addressString" [lastChars]="8" [link]="['/address/' | relativeUrl, addressString]">
<app-truncate [text]="addressString" [lastChars]="8">
<app-clipboard [text]="addressString"></app-clipboard> <app-clipboard [text]="addressString"></app-clipboard>
</app-truncate> </app-truncate>
</a>
</span> </span>
<br> <br>

View File

@ -7,11 +7,11 @@
</div> </div>
<span class="tx-link"> <span class="tx-link">
<a [routerLink]="['/tx/' | relativeUrl, bisqTx.id]" class="txid"> <span class="txid">
<app-truncate [text]="bisqTx.id" [lastChars]="12"> <app-truncate [text]="bisqTx.id" [lastChars]="12" [link]="['/tx/' | relativeUrl, bisqTx.id]">
<app-clipboard [text]="bisqTx.id"></app-clipboard> <app-clipboard [text]="bisqTx.id"></app-clipboard>
</app-truncate> </app-truncate>
</a> </span>
</span> </span>
<span class="grow"></span> <span class="grow"></span>
<div class="container-buttons"> <div class="container-buttons">

View File

@ -14,9 +14,7 @@
<tr *ngIf="addressInfo && addressInfo.unconfidential"> <tr *ngIf="addressInfo && addressInfo.unconfidential">
<td i18n="address.unconfidential">Unconfidential</td> <td i18n="address.unconfidential">Unconfidential</td>
<td> <td>
<a [routerLink]="['/address/' | relativeUrl, addressInfo.unconfidential]"> <app-truncate [text]="addressInfo.unconfidential" [lastChars]="7" [link]="['/address/' | relativeUrl, addressInfo.unconfidential]"></app-truncate>
<app-truncate [text]="addressInfo.unconfidential" [lastChars]="7"></app-truncate>
</a>
</td> </td>
</tr> </tr>
<ng-template [ngIf]="!address.electrum"> <ng-template [ngIf]="!address.electrum">

View File

@ -2,11 +2,9 @@
<div class="title-address"> <div class="title-address">
<h1 i18n="shared.address">Address</h1> <h1 i18n="shared.address">Address</h1>
<div class="tx-link"> <div class="tx-link">
<a [routerLink]="['/address/' | relativeUrl, addressString]" > <app-truncate [text]="addressString" [lastChars]="8" [link]="['/address/' | relativeUrl, addressString]">
<app-truncate [text]="addressString" [lastChars]="8">
<app-clipboard [text]="addressString"></app-clipboard> <app-clipboard [text]="addressString"></app-clipboard>
</app-truncate> </app-truncate>
</a>
</div> </div>
</div> </div>
@ -22,11 +20,9 @@
<tr *ngIf="addressInfo && addressInfo.unconfidential"> <tr *ngIf="addressInfo && addressInfo.unconfidential">
<td i18n="address.unconfidential">Unconfidential</td> <td i18n="address.unconfidential">Unconfidential</td>
<td> <td>
<a [routerLink]="['/address/' | relativeUrl, addressInfo.unconfidential]"> <app-truncate [text]="addressInfo.unconfidential" [lastChars]="8" [link]="['/address/' | relativeUrl, addressInfo.unconfidential]">
<app-truncate [text]="addressInfo.unconfidential" [lastChars]="8">
<app-clipboard [text]="addressInfo.unconfidential"></app-clipboard> <app-clipboard [text]="addressInfo.unconfidential"></app-clipboard>
</app-truncate> </app-truncate>
</a>
</td> </td>
</tr> </tr>
<ng-template [ngIf]="!address.electrum"> <ng-template [ngIf]="!address.electrum">

View File

@ -2,11 +2,9 @@
<div class="title-asset"> <div class="title-asset">
<h1 i18n="asset|Liquid Asset page title">Asset</h1> <h1 i18n="asset|Liquid Asset page title">Asset</h1>
<div class="tx-link"> <div class="tx-link">
<a [routerLink]="['/assets/asset/' | relativeUrl, assetString]"> <app-truncate [text]="assetString" [lastChars]="8" [link]="['/assets/asset/' | relativeUrl, assetString]">
<app-truncate [text]="assetString" [lastChars]="8">
<app-clipboard [text]="assetString"></app-clipboard> <app-clipboard [text]="assetString"></app-clipboard>
</app-truncate> </app-truncate>
</a>
</div> </div>
</div> </div>

View File

@ -3,20 +3,18 @@
<div class="title-block"> <div class="title-block">
<div *ngIf="rbfTransaction" class="alert alert-mempool" role="alert"> <div *ngIf="rbfTransaction" class="alert alert-mempool" role="alert">
<span i18n="transaction.rbf.replacement|RBF replacement">This transaction has been replaced by:</span> <span i18n="transaction.rbf.replacement|RBF replacement">This transaction has been replaced by:</span>
<a class="alert-link" [routerLink]="['/tx/' | relativeUrl, rbfTransaction.txid]"> <app-truncate [text]="rbfTransaction.txid" [lastChars]="12" [link]="['/tx/' | relativeUrl, rbfTransaction.txid]"></app-truncate>
<app-truncate [text]="rbfTransaction.txid" [lastChars]="12"></app-truncate>
</a>
</div> </div>
<ng-container *ngIf="!rbfTransaction || rbfTransaction?.size"> <ng-container *ngIf="!rbfTransaction || rbfTransaction?.size">
<h1 i18n="shared.transaction">Transaction</h1> <h1 i18n="shared.transaction">Transaction</h1>
<span class="tx-link"> <span class="tx-link">
<a [routerLink]="['/tx/' | relativeUrl, txId]" class="txid"> <span class="txid">
<app-truncate [text]="txId" [lastChars]="12"> <app-truncate [text]="txId" [lastChars]="12" [link]="['/tx/' | relativeUrl, txId]">
<app-clipboard [text]="txId"></app-clipboard> <app-clipboard [text]="txId"></app-clipboard>
</app-truncate> </app-truncate>
</a> </span>
</span> </span>
<div class="container-buttons"> <div class="container-buttons">
@ -158,9 +156,8 @@
<ng-template [ngIf]="cpfpInfo?.descendants?.length"> <ng-template [ngIf]="cpfpInfo?.descendants?.length">
<tr *ngFor="let cpfpTx of cpfpInfo.descendants"> <tr *ngFor="let cpfpTx of cpfpInfo.descendants">
<td><span class="badge badge-primary" i18n="transaction.descendant|Descendant">Descendant</span></td> <td><span class="badge badge-primary" i18n="transaction.descendant|Descendant">Descendant</span></td>
<td><a [routerLink]="['/tx' | relativeUrl, cpfpTx.txid]"> <td>
<app-truncate [text]="cpfpTx.txid"></app-truncate> <app-truncate [text]="cpfpTx.txid" [link]="['/tx' | relativeUrl, cpfpTx.txid]"></app-truncate>
</a>
</td> </td>
<td class="d-none d-lg-table-cell" [innerHTML]="cpfpTx.weight / 4 | vbytes: 2"></td> <td class="d-none d-lg-table-cell" [innerHTML]="cpfpTx.weight / 4 | vbytes: 2"></td>
<td>{{ cpfpTx.fee / (cpfpTx.weight / 4) | feeRounding }} <span class="symbol" i18n="shared.sat-vbyte|sat/vB">sat/vB</span></td> <td>{{ cpfpTx.fee / (cpfpTx.weight / 4) | feeRounding }} <span class="symbol" i18n="shared.sat-vbyte|sat/vB">sat/vB</span></td>
@ -171,9 +168,7 @@
<tr> <tr>
<td><span class="badge badge-success" i18n="transaction.descendant|Descendant">Descendant</span></td> <td><span class="badge badge-success" i18n="transaction.descendant|Descendant">Descendant</span></td>
<td class="txids"> <td class="txids">
<a [routerLink]="['/tx' | relativeUrl, cpfpInfo.bestDescendant.txid]"> <app-truncate [text]="cpfpInfo.bestDescendant.txid" [link]="['/tx' | relativeUrl, cpfpInfo.bestDescendant.txid]"></app-truncate>
<app-truncate [text]="cpfpInfo.bestDescendant.txid"></app-truncate>
</a>
</td> </td>
<td class="d-none d-lg-table-cell" [innerHTML]="cpfpInfo.bestDescendant.weight / 4 | vbytes: 2"></td> <td class="d-none d-lg-table-cell" [innerHTML]="cpfpInfo.bestDescendant.weight / 4 | vbytes: 2"></td>
<td>{{ cpfpInfo.bestDescendant.fee / (cpfpInfo.bestDescendant.weight / 4) | feeRounding }} <span class="symbol" i18n="shared.sat-vbyte|sat/vB">sat/vB</span></td> <td>{{ cpfpInfo.bestDescendant.fee / (cpfpInfo.bestDescendant.weight / 4) | feeRounding }} <span class="symbol" i18n="shared.sat-vbyte|sat/vB">sat/vB</span></td>
@ -184,9 +179,7 @@
<tr *ngFor="let cpfpTx of cpfpInfo.ancestors"> <tr *ngFor="let cpfpTx of cpfpInfo.ancestors">
<td><span class="badge badge-primary" i18n="transaction.ancestor|Transaction Ancestor">Ancestor</span></td> <td><span class="badge badge-primary" i18n="transaction.ancestor|Transaction Ancestor">Ancestor</span></td>
<td class="txids"> <td class="txids">
<a [routerLink]="['/tx' | relativeUrl, cpfpTx.txid]"> <app-truncate [text]="cpfpTx.txid" [link]="['/tx' | relativeUrl, cpfpTx.txid]"></app-truncate>
<app-truncate [text]="cpfpTx.txid"></app-truncate>
</a>
</td> </td>
<td class="d-none d-lg-table-cell" [innerHTML]="cpfpTx.weight / 4 | vbytes: 2"></td> <td class="d-none d-lg-table-cell" [innerHTML]="cpfpTx.weight / 4 | vbytes: 2"></td>
<td>{{ cpfpTx.fee / (cpfpTx.weight / 4) | feeRounding }} <span class="symbol" i18n="shared.sat-vbyte|sat/vB">sat/vB</span></td> <td>{{ cpfpTx.fee / (cpfpTx.weight / 4) | feeRounding }} <span class="symbol" i18n="shared.sat-vbyte|sat/vB">sat/vB</span></td>

View File

@ -1,11 +1,9 @@
<div class="mb-2 box-top"> <div class="mb-2 box-top">
<div class="box-left text-truncate"> <div class="box-left text-truncate">
<h3 class="mb-0 text-truncate">{{ channel.alias || '?' }}</h3> <h3 class="mb-0 text-truncate">{{ channel.alias || '?' }}</h3>
<a [routerLink]="['/lightning/node' | relativeUrl, channel.public_key]" > <app-truncate [text]="channel.public_key" [lastChars]="6" [link]="['/lightning/node' | relativeUrl, channel.public_key]">
<app-truncate [text]="channel.public_key" [lastChars]="6">
<app-clipboard [text]="channel.public_key"></app-clipboard> <app-clipboard [text]="channel.public_key"></app-clipboard>
</app-truncate> </app-truncate>
</a>
</div> </div>
<div class="box-right"> <div class="box-right">
<div class="second-line"><ng-container *ngTemplateOutlet="xChannels; context: {$implicit: channel.channels }"></ng-container></div> <div class="second-line"><ng-container *ngTemplateOutlet="xChannels; context: {$implicit: channel.channels }"></ng-container></div>

View File

@ -46,11 +46,9 @@
<td class="alias text-left"> <td class="alias text-left">
<div>{{ node.alias || '?' }}</div> <div>{{ node.alias || '?' }}</div>
<div class="second-line"> <div class="second-line">
<a [routerLink]="['/lightning/node' | relativeUrl, node.public_key]"> <app-truncate [text]="node.public_key" [maxWidth]="200" [lastChars]="6" [link]="['/lightning/node' | relativeUrl, node.public_key]">
<app-truncate [text]="node.public_key" [maxWidth]="200" [lastChars]="6">
<app-clipboard [text]="node.public_key" size="small"></app-clipboard> <app-clipboard [text]="node.public_key" size="small"></app-clipboard>
</app-truncate> </app-truncate>
</a>
</div> </div>
</td> </td>
<td class="alias text-left d-none d-md-table-cell"> <td class="alias text-left d-none d-md-table-cell">

View File

@ -3,11 +3,11 @@
<div class="title-container mb-2" *ngIf="!error"> <div class="title-container mb-2" *ngIf="!error">
<h1 class="mb-0 text-truncate">{{ node.alias }}</h1> <h1 class="mb-0 text-truncate">{{ node.alias }}</h1>
<span class="tx-link"> <span class="tx-link">
<a class="node-id" [routerLink]="['/lightning/node' | relativeUrl, node.public_key]"> <span class="node-id">
<app-truncate [text]="node.public_key" [lastChars]="8"> <app-truncate [text]="node.public_key" [lastChars]="8" [link]="['/lightning/node' | relativeUrl, node.public_key]">
<app-clipboard [text]="node.public_key"></app-clipboard> <app-clipboard [text]="node.public_key"></app-clipboard>
</app-truncate> </app-truncate>
</a> </span>
</span> </span>
</div> </div>

View File

@ -1,9 +1,19 @@
<span class="truncate" [style.max-width]="maxWidth ? maxWidth + 'px' : null"> <span class="truncate" [style.max-width]="maxWidth ? maxWidth + 'px' : null">
<ng-container *ngIf="!rtl"> <ng-container *ngIf="link">
<span class="first">{{text.slice(0,-lastChars)}}</span><span class="last-four">{{text.slice(-lastChars)}}</span> <a [routerLink]="link" class="truncate-link">
<ng-container *ngIf="rtl; then rtlTruncated; else ltrTruncated;"></ng-container>
</a>
</ng-container> </ng-container>
<ng-container *ngIf="rtl"> <ng-container *ngIf="!link">
<span class="first">{{text.slice(lastChars)}}</span><span class="last-four">{{text.slice(0,lastChars)}}</span> <ng-container *ngIf="rtl; then rtlTruncated; else ltrTruncated;"></ng-container>
</ng-container> </ng-container>
<ng-content></ng-content> <ng-content></ng-content>
</span> </span>
<ng-template #ltrTruncated>
<span class="first">{{text.slice(0,-lastChars)}}</span><span class="last-four">{{text.slice(-lastChars)}}</span>
</ng-template>
<ng-template #rtlTruncated>
<span class="first">{{text.slice(lastChars)}}</span><span class="last-four">{{text.slice(0,lastChars)}}</span>
</ng-template>

View File

@ -4,6 +4,14 @@
flex-direction: row; flex-direction: row;
align-items: baseline; align-items: baseline;
.truncate-link {
display: flex;
flex-direction: row;
align-items: baseline;
flex-shrink: 1;
overflow: hidden;
}
.first { .first {
flex-grow: 0; flex-grow: 0;
flex-shrink: 1; flex-shrink: 1;

View File

@ -7,6 +7,7 @@ import { Component, Input, Inject, LOCALE_ID } from '@angular/core';
}) })
export class TruncateComponent { export class TruncateComponent {
@Input() text: string; @Input() text: string;
@Input() link: any = null;
@Input() lastChars: number = 4; @Input() lastChars: number = 4;
@Input() maxWidth: number = null; @Input() maxWidth: number = null;
rtl: boolean; rtl: boolean;