Skip to content

Commit

Permalink
Merge pull request #70 from squidit/feature/SQ-64533-label-template
Browse files Browse the repository at this point in the history
feat: Add support for generic label templates in sq-input component
  • Loading branch information
wreckedduck authored Jun 28, 2024
2 parents 112f8fc + a1b22ae commit e3c5514
Show file tree
Hide file tree
Showing 17 changed files with 94 additions and 16 deletions.
7 changes: 5 additions & 2 deletions src/components/sq-input-date/sq-input-date.component.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
<div class="wrapper-all-inside-input {{ customClass }}">
<label
class="display-flex"
*ngIf="label?.length || tooltipMessage"
*ngIf="label?.length || tooltipMessage || labelTemplate"
[ngClass]="{
readonly: readonly
}"
[for]="id"
>
<div *ngIf="label" [ngStyle]="{ 'color': labelColor }" [innerHtml]="label | universalSafe"></div>
<div *ngIf="label && !labelTemplate" [ngStyle]="{ 'color': labelColor }" [innerHtml]="label | universalSafe"></div>
<div *ngIf="labelTemplate">
<ng-container *ngTemplateOutlet="labelTemplate"></ng-container>
</div>
<sq-tooltip
*ngIf="tooltipMessage"
class="ml-1"
Expand Down
8 changes: 7 additions & 1 deletion src/components/sq-input-date/sq-input-date.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, ElementRef, Input, Optional } from '@angular/core'
import { Component, ContentChild, ElementRef, Input, Optional, TemplateRef } from '@angular/core'
import { TranslateService } from '@ngx-translate/core'
import { ValidatorHelper } from '../../helpers/validator.helper'
import { SqInputComponent } from '../sq-input/sq-input.component'
Expand Down Expand Up @@ -55,6 +55,12 @@ export class SqInputDateComponent extends SqInputComponent {
return this._value.toISOString().split('T')[0]
}

/**
* Reference to a label template.
*/
@ContentChild('labelTemplate')
override labelTemplate: TemplateRef<HTMLElement> | null = null

/**
* Constructs a new instance of SqInputDateComponent.
* @param validatorHelper - The ValidatorHelper service for input validation.
Expand Down
7 changes: 5 additions & 2 deletions src/components/sq-input-mask/sq-input-mask.component.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
<div class="wrapper-all-inside-input {{ customClass }}">
<label
class="display-flex"
*ngIf="label?.length || tooltipMessage"
*ngIf="label?.length || tooltipMessage || labelTemplate"
[ngClass]="{
readonly: readonly
}"
[for]="id"
>
<div *ngIf="label" [ngStyle]="{ 'color': labelColor }" [innerHtml]="label | universalSafe"></div>
<div *ngIf="label && !labelTemplate" [ngStyle]="{ 'color': labelColor }" [innerHtml]="label | universalSafe"></div>
<div *ngIf="labelTemplate">
<ng-container *ngTemplateOutlet="labelTemplate"></ng-container>
</div>
<sq-tooltip
*ngIf="tooltipMessage"
class="ml-1"
Expand Down
8 changes: 7 additions & 1 deletion src/components/sq-input-mask/sq-input-mask.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, ElementRef, Input, Optional } from "@angular/core"
import { Component, ContentChild, ElementRef, Input, Optional, TemplateRef } from "@angular/core"
import { ValidatorHelper } from '../../helpers/validator.helper'
import { TranslateService } from "@ngx-translate/core"
import { SqInputComponent } from "../sq-input/sq-input.component"
Expand Down Expand Up @@ -75,6 +75,12 @@ export class SqInputMaskComponent extends SqInputComponent {
*/
@Input() maxValue?: number

/**
* Reference to a label template.
*/
@ContentChild('labelTemplate')
override labelTemplate: TemplateRef<HTMLElement> | null = null

/**
* Reference to the native element.
*/
Expand Down
6 changes: 5 additions & 1 deletion src/components/sq-input-money/sq-input-money.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,16 @@
(keyPressUp)="keyPressUp.emit($event)"
(keyPressDown)="keyPressDown.emit($event)"
>
<ng-container *ngIf="labelTemplateOverwrite">
<ng-template #labelTemplate>
<ng-container *ngTemplateOutlet="labelTemplateOverwrite"></ng-container>
</ng-template>
</ng-container>
<ng-container *ngIf="prefix">
<ng-template #leftLabel>
{{ prefix }}
</ng-template>
</ng-container>

<ng-container *ngIf="rightLabelOverwrite">
<ng-template #rightLabel>
<ng-container *ngTemplateOutlet="rightLabelOverwrite"></ng-container>
Expand Down
6 changes: 6 additions & 0 deletions src/components/sq-input-money/sq-input-money.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ export class SqInputMoneyComponent extends SqInputComponent implements OnChanges
@ContentChild('rightLabelOverwrite')
rightLabelOverwrite: TemplateRef<HTMLElement> | null = null

/**
* Reference to a label template.
*/
@ContentChild('labelTemplate')
labelTemplateOverwrite: TemplateRef<HTMLElement> | null = null

/**
* Constructs a new instance of SqInputMaskComponent.
* @param validatorHelper - The ValidatorHelper service for input validation.
Expand Down
5 changes: 5 additions & 0 deletions src/components/sq-input-number/sq-input-number.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@
(keyPressUp)="keyPressUp.emit($event)"
(keyPressDown)="keyPressDown.emit($event)"
>
<ng-container *ngIf="labelTemplateOverwrite">
<ng-template #labelTemplate>
<ng-container *ngTemplateOutlet="labelTemplateOverwrite"></ng-container>
</ng-template>
</ng-container>
<ng-container *ngIf="leftLabelOverwrite">
<ng-template #leftLabel>
<ng-container *ngTemplateOutlet="leftLabelOverwrite"></ng-container>
Expand Down
6 changes: 6 additions & 0 deletions src/components/sq-input-number/sq-input-number.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ export class SqInputNumberComponent extends SqInputComponent {
@ContentChild('rightLabelOverwrite')
rightLabelOverwrite: TemplateRef<HTMLElement> | null = null

/**
* Reference to a label template.
*/
@ContentChild('labelTemplate')
labelTemplateOverwrite: TemplateRef<HTMLElement> | null = null

/**
* Reference to the native element.
*/
Expand Down
7 changes: 5 additions & 2 deletions src/components/sq-input-range/sq-input-range.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
}">
<label
class="display-flex"
*ngIf="label?.length"
*ngIf="label?.length || labelTemplate"
[ngClass]="{
readonly: readonly
}"
[for]="id"
>
<div *ngIf="label?.length" [ngStyle]="{ 'color': labelColor }" [innerHtml]="label | universalSafe"></div>
<div *ngIf="label?.length && !labelTemplate" [ngStyle]="{ 'color': labelColor }" [innerHtml]="label | universalSafe"></div>
</label>
<div *ngIf="labelTemplate">
<ng-container *ngTemplateOutlet="labelTemplate"></ng-container>
</div>
<div
class="p-0 wrapper-input wrapper-input-squid"
[ngClass]="{
Expand Down
9 changes: 8 additions & 1 deletion src/components/sq-input-range/sq-input-range.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AfterContentInit, Component, ElementRef, EventEmitter, Input, OnChanges, Optional, Output, SimpleChanges, ViewChild } from '@angular/core'
import { AfterContentInit, Component, ContentChild, ElementRef, EventEmitter, Input, OnChanges, Optional, Output, SimpleChanges, TemplateRef, ViewChild } from '@angular/core'
import { TranslateService } from '@ngx-translate/core'
import { ValidatorHelper } from '../../helpers/validator.helper'
import { sleep } from '../../helpers/sleep.helper'
Expand Down Expand Up @@ -133,6 +133,13 @@ export class SqInputRangeComponent implements AfterContentInit, OnChanges {
*/
@ViewChild('input') input!: ElementRef

/**
* Reference to a label template.
*/
@ContentChild('labelTemplate')
labelTemplate: TemplateRef<HTMLElement> | null = null


/**
* The error message associated with the input.
*/
Expand Down
7 changes: 5 additions & 2 deletions src/components/sq-select/sq-select.component.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
<div class="wrapper-all-inside-input {{ customClass }}">
<label
class="display-flex"
*ngIf="label?.length || tooltipMessage"
*ngIf="label?.length || tooltipMessage || labelTemplate"
[ngClass]="{
readonly: readonly
}"
[for]="id"
>
<div *ngIf="label" [ngStyle]="{ 'color': labelColor }" [innerHtml]="label | universalSafe"></div>
<div *ngIf="label && !labelTemplate" [ngStyle]="{ 'color': labelColor }" [innerHtml]="label | universalSafe"></div>
<div *ngIf="labelTemplate">
<ng-container *ngTemplateOutlet="labelTemplate"></ng-container>
</div>
<sq-tooltip
*ngIf="tooltipMessage"
class="ml-1"
Expand Down
6 changes: 6 additions & 0 deletions src/components/sq-select/sq-select.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,12 @@ export class SqSelectComponent {
@ContentChild('rightLabel')
rightLabel: TemplateRef<HTMLElement> | null = null

/**
* Reference to a right-aligned label template.
*/
@ContentChild('labelTemplate')
labelTemplate: TemplateRef<HTMLElement> | null = null

/**
* The error state of the select input.
*/
Expand Down
7 changes: 6 additions & 1 deletion src/components/sq-selector/sq-selector.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@
block: block,
}"
>
<label [for]="id" *ngIf="leftLabel" [ngClass]="{'label-max-width': hideInput}">
<label [for]="id" *ngIf="leftLabel && !labelTemplate" [ngClass]="{'label-max-width': hideInput}">
<ng-container
*ngTemplateOutlet="leftLabel; context: context"
></ng-container>
</label>
<label for="id" *ngIf="labelTemplate" [ngClass]="{'label-max-width': hideInput}">
<div *ngIf="labelTemplate">
<ng-container *ngTemplateOutlet="labelTemplate"></ng-container>
</div>
</label>
<input
[id]="id"
[name]="name"
Expand Down
6 changes: 6 additions & 0 deletions src/components/sq-selector/sq-selector.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,12 @@ export class SqSelectorComponent implements OnChanges {
@ContentChild('leftLabel')
leftLabel: TemplateRef<HTMLElement> | null = null

/**
* Reference to a right-aligned label template.
*/
@ContentChild('labelTemplate')
labelTemplate: TemplateRef<HTMLElement> | null = null

/**
* Indicates whether the selector input is currently checked.
*/
Expand Down
7 changes: 5 additions & 2 deletions src/components/sq-textarea/sq-textarea.component.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
<div class="wrapper-all-inside-input {{ customClass }}">
<label
class="display-flex"
*ngIf="label?.length || tooltipMessage"
*ngIf="label?.length || tooltipMessage || labelTemplate"
[ngClass]="{
readonly: readonly
}"
[for]="id"
>
<div *ngIf="label" [ngStyle]="{ 'color': labelColor }" [innerHtml]="label | universalSafe"></div>
<div *ngIf="label && !labelTemplate" [ngStyle]="{ 'color': labelColor }" [innerHtml]="label | universalSafe"></div>
<div *ngIf="labelTemplate">
<ng-container *ngTemplateOutlet="labelTemplate"></ng-container>
</div>
<sq-tooltip
*ngIf="tooltipMessage"
class="ml-1"
Expand Down
6 changes: 6 additions & 0 deletions src/components/sq-textarea/sq-textarea.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@ export class SqTextAreaComponent {
@ContentChild('rightLabel')
rightLabel: TemplateRef<HTMLElement> | null = null

/**
* Reference to a label template.
*/
@ContentChild('labelTemplate')
labelTemplate: TemplateRef<HTMLElement> | null = null

/**
* Represents the error state of the textarea.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@squidit/ngx-css",
"version": "1.3.39",
"version": "1.3.40",
"peerDependencies": {
"@angular/common": ">=15.0.0",
"@angular/core": ">=15.0.0",
Expand Down

0 comments on commit e3c5514

Please sign in to comment.