src/components/sq-input-money-form-control/sq-input-money-form-control.component.ts
Componente de input monetário que estende SqInputMaskFormControlComponent. Configura automaticamente a máscara para valores monetários e calcula o prefixo da moeda baseado no código ISO 4217 (BRL, USD, EUR, etc).
Example :```html
<sq-input-money-form-control
[formControl]="priceControl"
[label]="'Preço'"
[currency]="'BRL'"
></sq-input-money-form-control>
SqInputMaskFormControlComponent
OnInit
OnChanges
| changeDetection | ChangeDetectionStrategy.OnPush |
| providers |
{
provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => SqInputMoneyFormControlComponent), multi: true,
}
{
provide: NG_VALIDATORS, useExisting: forwardRef(() => SqInputMoneyFormControlComponent), multi: true,
}
|
| selector | sq-input-money-form-control |
| standalone | true |
| imports |
NgClass
NgStyle
NgTemplateOutlet
ReactiveFormsModule
NgxMaskDirective
SqTooltipComponent
UniversalSafePipe
|
| styleUrls | ./sq-input-money-form-control.component.scss |
| templateUrl | ./sq-input-money-form-control.component.html |
Properties |
|
Methods |
Inputs |
|
Outputs |
| currency | |
Type : string
|
|
Default value : 'BRL'
|
|
|
Código da moeda no padrão ISO 4217 (BRL, USD, EUR, GBP, etc). O prefixo será calculado automaticamente. |
|
| allowNegativeNumbers | |
Type : boolean
|
|
Default value : false
|
|
|
Inherited from
SqInputMaskFormControlComponent
|
|
|
Defined in
SqInputMaskFormControlComponent:113
|
|
|
Indicates whether negative numbers are allowed. |
|
| decimalMarker | |
Type : "." | "," |
|
|
Default value : ['.', ',']
|
|
|
Inherited from
SqInputMaskFormControlComponent
|
|
|
Defined in
SqInputMaskFormControlComponent:119
|
|
|
The decimal marker character or an array of characters to represent decimal values. |
|
| leadZero | |
Type : boolean
|
|
Default value : false
|
|
|
Inherited from
SqInputMaskFormControlComponent
|
|
|
Defined in
SqInputMaskFormControlComponent:132
|
|
|
Indicates whether leading zeros should be preserved. |
|
| mask | |
Type : string
|
|
Default value : ''
|
|
|
Inherited from
SqInputMaskFormControlComponent
|
|
|
Defined in
SqInputMaskFormControlComponent:77
|
|
|
The mask pattern for input validation and formatting. Example : |
|
| maxValue | |
Type : number
|
|
|
Inherited from
SqInputMaskFormControlComponent
|
|
|
Defined in
SqInputMaskFormControlComponent:144
|
|
|
Defines the maximum value that can be accepted as input (for numeric masks). |
|
| minValue | |
Type : number
|
|
|
Inherited from
SqInputMaskFormControlComponent
|
|
|
Defined in
SqInputMaskFormControlComponent:138
|
|
|
Defines the minimum value that can be accepted as input (for numeric masks). |
|
| placeHolderCharacter | |
Type : string
|
|
Default value : ''
|
|
|
Inherited from
SqInputMaskFormControlComponent
|
|
|
Defined in
SqInputMaskFormControlComponent:126
|
|
|
The character to use as a placeholder in empty mask slots. Example : |
|
| prefix | |
Type : string
|
|
Default value : ''
|
|
|
Inherited from
SqInputMaskFormControlComponent
|
|
|
Defined in
SqInputMaskFormControlComponent:101
|
|
|
The prefix to be prepended to the input value. Example : |
|
| showMaskTyped | |
Type : boolean
|
|
Default value : false
|
|
|
Inherited from
SqInputMaskFormControlComponent
|
|
|
Defined in
SqInputMaskFormControlComponent:107
|
|
|
Indicates whether the mask should be visible while typing. |
|
| suffix | |
Type : string
|
|
Default value : ''
|
|
|
Inherited from
SqInputMaskFormControlComponent
|
|
|
Defined in
SqInputMaskFormControlComponent:93
|
|
|
The suffix to be appended to the input value. Example : |
|
| thousandSeparator | |
Type : string
|
|
Default value : ''
|
|
|
Inherited from
SqInputMaskFormControlComponent
|
|
|
Defined in
SqInputMaskFormControlComponent:85
|
|
|
The character used as a thousand separator in numeric input. Example : |
|
| backgroundColor | |
Type : string
|
|
Default value : ''
|
|
|
Inherited from
SqInputFormControlComponent
|
|
|
Defined in
SqInputFormControlComponent:132
|
|
|
Background color of the input element. |
|
| borderColor | |
Type : string
|
|
Default value : ''
|
|
|
Inherited from
SqInputFormControlComponent
|
|
|
Defined in
SqInputFormControlComponent:137
|
|
|
Border color of the input element. |
|
| customClass | |
Type : string
|
|
Default value : ''
|
|
|
Inherited from
SqInputFormControlComponent
|
|
|
Defined in
SqInputFormControlComponent:92
|
|
|
Custom CSS class for the input element. |
|
| id | |
Type : string
|
|
|
Inherited from
SqInputFormControlComponent
|
|
|
Defined in
SqInputFormControlComponent:82
|
|
|
The id attribute for the input element. |
|
| inputMode | |
Type : string
|
|
Default value : ''
|
|
|
Inherited from
SqInputFormControlComponent
|
|
|
Defined in
SqInputFormControlComponent:162
|
|
|
Input mode for mobile devices. |
|
| label | |
Type : string
|
|
|
Inherited from
SqInputFormControlComponent
|
|
|
Defined in
SqInputFormControlComponent:87
|
|
|
An optional label for the input. |
|
| labelColor | |
Type : string
|
|
Default value : ''
|
|
|
Inherited from
SqInputFormControlComponent
|
|
|
Defined in
SqInputFormControlComponent:142
|
|
|
Color of the input label. |
|
| maxLength | |
Type : number | null
|
|
Default value : null
|
|
|
Inherited from
SqInputFormControlComponent
|
|
|
Defined in
SqInputFormControlComponent:152
|
|
|
Maximum length for the input element. |
|
| name | |
Type : string
|
|
Default value : `random-name-${(1 + Date.now() + Math.random()).toString().replace('.', '')}`
|
|
|
Inherited from
SqInputFormControlComponent
|
|
|
Defined in
SqInputFormControlComponent:77
|
|
|
The name attribute for the input element. |
|
| pattern | |
Type : string
|
|
Default value : ''
|
|
|
Inherited from
SqInputFormControlComponent
|
|
|
Defined in
SqInputFormControlComponent:157
|
|
|
Regular expression pattern for input validation. |
|
| placeholder | |
Type : string
|
|
Default value : ''
|
|
|
Inherited from
SqInputFormControlComponent
|
|
|
Defined in
SqInputFormControlComponent:97
|
|
|
Placeholder text for the input element. |
|
| readonly | |
Type : boolean
|
|
Default value : false
|
|
|
Inherited from
SqInputFormControlComponent
|
|
|
Defined in
SqInputFormControlComponent:107
|
|
|
Flag to make the input element readonly. |
|
| timeToChange | |
Type : number
|
|
Default value : 0
|
|
|
Inherited from
SqInputFormControlComponent
|
|
|
Defined in
SqInputFormControlComponent:102
|
|
|
Time in milliseconds before triggering input timeout (debounce). |
|
| tooltipColor | |
Type : string
|
|
Default value : 'inherit'
|
|
|
Inherited from
SqInputFormControlComponent
|
|
|
Defined in
SqInputFormControlComponent:122
|
|
|
Color of the tooltip. |
|
| tooltipIcon | |
Type : string
|
|
Default value : ''
|
|
|
Inherited from
SqInputFormControlComponent
|
|
|
Defined in
SqInputFormControlComponent:127
|
|
|
Icon for the tooltip. |
|
| tooltipMessage | |
Type : string
|
|
Default value : ''
|
|
|
Inherited from
SqInputFormControlComponent
|
|
|
Defined in
SqInputFormControlComponent:112
|
|
|
Tooltip message to display. |
|
| tooltipPlacement | |
Type : "center top" | "center bottom" | "left center" | "right center"
|
|
Default value : 'right center'
|
|
|
Inherited from
SqInputFormControlComponent
|
|
|
Defined in
SqInputFormControlComponent:117
|
|
|
Placement of the tooltip. |
|
| type | |
Type : "text" | "email" | "email-multiple" | "hidden" | "password" | "tel" | "url" | "file"
|
|
Default value : 'text'
|
|
|
Inherited from
SqInputFormControlComponent
|
|
|
Defined in
SqInputFormControlComponent:147
|
|
|
Type of the input element (e.g., text, email, password). |
|
| blurred | |
Type : EventEmitter<FocusEvent>
|
|
|
Inherited from
SqInputFormControlComponent
|
|
|
Defined in
SqInputFormControlComponent:187
|
|
|
Event emitter for blur events. |
|
| focused | |
Type : EventEmitter<FocusEvent>
|
|
|
Inherited from
SqInputFormControlComponent
|
|
|
Defined in
SqInputFormControlComponent:182
|
|
|
Event emitter for focus events. |
|
| keyPressDown | |
Type : EventEmitter<KeyboardEvent>
|
|
|
Inherited from
SqInputFormControlComponent
|
|
|
Defined in
SqInputFormControlComponent:167
|
|
|
Event emitter for keydown events. |
|
| keyPressUp | |
Type : EventEmitter<KeyboardEvent>
|
|
|
Inherited from
SqInputFormControlComponent
|
|
|
Defined in
SqInputFormControlComponent:172
|
|
|
Event emitter for keyup events. |
|
| valueChange | |
Type : EventEmitter<any>
|
|
|
Inherited from
SqInputFormControlComponent
|
|
|
Defined in
SqInputFormControlComponent:177
|
|
|
Event emitter for input value changes. |
|
| Private getCurrencySymbol |
getCurrencySymbol()
|
|
Obtém o símbolo da moeda via Intl.NumberFormat.
Returns :
string
|
| ngOnChanges | ||||||
ngOnChanges(changes: SimpleChanges)
|
||||||
|
Inherited from
SqInputFormControlComponent
|
||||||
|
Defined in
SqInputFormControlComponent:96
|
||||||
|
Atualiza o prefixo quando a moeda muda.
Parameters :
Returns :
void
|
| ngOnInit |
ngOnInit()
|
|
Inherited from
SqInputMaskFormControlComponent
|
|
Defined in
SqInputMaskFormControlComponent:66
|
|
Configura os valores padrão para input monetário.
Returns :
void
|
| ngOnDestroy |
ngOnDestroy()
|
|
Inherited from
SqInputFormControlComponent
|
|
Defined in
SqInputFormControlComponent:307
|
|
Cleanup on component destruction.
Returns :
void
|
| onBlur | ||||||
onBlur(event: FocusEvent)
|
||||||
|
Inherited from
SqInputFormControlComponent
|
||||||
|
Defined in
SqInputFormControlComponent:421
|
||||||
|
Handle blur events.
Parameters :
Returns :
void
|
| onChangeEvent | ||||||
onChangeEvent(event: Event)
|
||||||
|
Inherited from
SqInputFormControlComponent
|
||||||
|
Defined in
SqInputFormControlComponent:387
|
||||||
|
Handle input value changes with optional debounce.
Parameters :
Returns :
void
|
| onFocus | ||||||
onFocus(event: FocusEvent)
|
||||||
|
Inherited from
SqInputFormControlComponent
|
||||||
|
Defined in
SqInputFormControlComponent:429
|
||||||
|
Handle focus events.
Parameters :
Returns :
void
|
| onKeyDown | ||||||||
onKeyDown(event: KeyboardEvent)
|
||||||||
|
Inherited from
SqInputFormControlComponent
|
||||||||
|
Defined in
SqInputFormControlComponent:406
|
||||||||
|
Handle keydown events.
Parameters :
Returns :
void
|
| onKeyUp | ||||||||
onKeyUp(event: KeyboardEvent)
|
||||||||
|
Inherited from
SqInputFormControlComponent
|
||||||||
|
Defined in
SqInputFormControlComponent:414
|
||||||||
|
Handle keyup events.
Parameters :
Returns :
void
|
| registerOnChange | ||||||||
registerOnChange(fn: any)
|
||||||||
|
Inherited from
SqInputFormControlComponent
|
||||||||
|
Defined in
SqInputFormControlComponent:327
|
||||||||
|
ControlValueAccessor: Registers a callback function that is called when the control's value changes.
Parameters :
Returns :
void
|
| registerOnTouched | ||||||||
registerOnTouched(fn: any)
|
||||||||
|
Inherited from
SqInputFormControlComponent
|
||||||||
|
Defined in
SqInputFormControlComponent:335
|
||||||||
|
ControlValueAccessor: Registers a callback function that is called when the control is touched.
Parameters :
Returns :
void
|
| registerOnValidatorChange | ||||||||
registerOnValidatorChange(fn: () => void)
|
||||||||
|
Inherited from
SqInputFormControlComponent
|
||||||||
|
Defined in
SqInputFormControlComponent:365
|
||||||||
|
Validator: Registers a callback for validation changes.
Parameters :
Returns :
void
|
| setDisabledState | ||||||||
setDisabledState(isDisabled: boolean)
|
||||||||
|
Inherited from
SqInputFormControlComponent
|
||||||||
|
Defined in
SqInputFormControlComponent:343
|
||||||||
|
ControlValueAccessor: Sets the disabled state of the control.
Parameters :
Returns :
void
|
| Private updateValidators |
updateValidators()
|
|
Inherited from
SqInputFormControlComponent
|
|
Defined in
SqInputFormControlComponent:277
|
|
Updates validators based on the input type. Automatically applies appropriate validators for email, phone, URL, etc. Uses ValidatorHelper through InputValidators for consistency.
Returns :
void
|
| validate |
validate()
|
|
Inherited from
SqInputFormControlComponent
|
|
Defined in
SqInputFormControlComponent:355
|
|
Validator: Validates the control.
Returns :
ValidationErrors | null
Validation errors or null. |
| writeValue | ||||||||
writeValue(value: any)
|
||||||||
|
Inherited from
SqInputFormControlComponent
|
||||||||
|
Defined in
SqInputFormControlComponent:319
|
||||||||
|
ControlValueAccessor: Writes a new value to the element.
Parameters :
Returns :
void
|
| currencyPrefix |
Type : string
|
Default value : ''
|
|
Prefixo da moeda exibido no span separado (igual ao componente legado). |
| control |
Default value : new FormControl('')
|
|
Inherited from
SqInputFormControlComponent
|
|
Defined in
SqInputFormControlComponent:210
|
|
Internal FormControl for managing the input value and state. |
| Private destroy$ |
Default value : new Subject<void>()
|
|
Inherited from
SqInputFormControlComponent
|
|
Defined in
SqInputFormControlComponent:225
|
|
Subject for managing subscriptions. |
| labelTemplate |
Type : TemplateRef<HTMLElement> | null
|
Default value : null
|
Decorators :
@ContentChild('labelTemplate')
|
|
Inherited from
SqInputFormControlComponent
|
|
Defined in
SqInputFormControlComponent:205
|
|
Reference to a label template. |
| leftLabel |
Type : TemplateRef<HTMLElement> | null
|
Default value : null
|
Decorators :
@ContentChild('leftLabel')
|
|
Inherited from
SqInputFormControlComponent
|
|
Defined in
SqInputFormControlComponent:193
|
|
Reference to a left-aligned label template. |
| nativeElement |
Type : ElementRef
|
Default value : inject(ElementRef)
|
|
Inherited from
SqInputFormControlComponent
|
|
Defined in
SqInputFormControlComponent:215
|
|
Reference to the native element. |
| Private onChange |
Type : function
|
Default value : () => {...}
|
|
Inherited from
SqInputFormControlComponent
|
|
Defined in
SqInputFormControlComponent:232
|
|
ControlValueAccessor callback function called when the value changes. Registered via registerOnChange(). |
| Private onTouched |
Type : function
|
Default value : () => {...}
|
|
Inherited from
SqInputFormControlComponent
|
|
Defined in
SqInputFormControlComponent:239
|
|
ControlValueAccessor callback function called when the control is touched. Registered via registerOnTouched(). |
| Private onValidationChange |
Type : function
|
Default value : () => {...}
|
|
Inherited from
SqInputFormControlComponent
|
|
Defined in
SqInputFormControlComponent:245
|
|
External validator function (propagated from parent control). |
| rightLabel |
Type : TemplateRef<HTMLElement> | null
|
Default value : null
|
Decorators :
@ContentChild('rightLabel')
|
|
Inherited from
SqInputFormControlComponent
|
|
Defined in
SqInputFormControlComponent:199
|
|
Reference to a right-aligned label template. |
| Private Optional timeoutInput |
Type : ReturnType<>
|
|
Inherited from
SqInputFormControlComponent
|
|
Defined in
SqInputFormControlComponent:220
|
|
Timeout for input changes (debounce). |
import { Component, Input, forwardRef, OnInit, OnChanges, SimpleChanges, ChangeDetectionStrategy } from '@angular/core';
import { NG_VALUE_ACCESSOR, NG_VALIDATORS, ReactiveFormsModule } from '@angular/forms';
import { NgClass, NgStyle, NgTemplateOutlet } from '@angular/common';
import { NgxMaskDirective } from 'ngx-mask';
import { SqInputMaskFormControlComponent } from '../sq-input-mask-form-control/sq-input-mask-form-control.component';
import { SqTooltipComponent } from '../sq-tooltip/sq-tooltip.component';
import { UniversalSafePipe } from '../../pipes/universal-safe/universal-safe.pipe';
/**
* Componente de input monetário que estende SqInputMaskFormControlComponent.
* Configura automaticamente a máscara para valores monetários e calcula
* o prefixo da moeda baseado no código ISO 4217 (BRL, USD, EUR, etc).
*
* @example
* ```html
* <sq-input-money-form-control
* [formControl]="priceControl"
* [label]="'Preço'"
* [currency]="'BRL'"
* ></sq-input-money-form-control>
* ```
*/
@Component({
selector: 'sq-input-money-form-control',
templateUrl: './sq-input-money-form-control.component.html',
styleUrls: ['./sq-input-money-form-control.component.scss'],
standalone: true,
imports: [
NgClass,
NgStyle,
NgTemplateOutlet,
ReactiveFormsModule,
NgxMaskDirective,
SqTooltipComponent,
UniversalSafePipe,
],
changeDetection: ChangeDetectionStrategy.OnPush,
providers: [
{
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => SqInputMoneyFormControlComponent),
multi: true,
},
{
provide: NG_VALIDATORS,
useExisting: forwardRef(() => SqInputMoneyFormControlComponent),
multi: true,
},
],
})
export class SqInputMoneyFormControlComponent extends SqInputMaskFormControlComponent implements OnInit, OnChanges {
/**
* Código da moeda no padrão ISO 4217 (BRL, USD, EUR, GBP, etc).
* O prefixo será calculado automaticamente.
*/
@Input() currency = 'BRL';
/**
* Prefixo da moeda exibido no span separado (igual ao componente legado).
*/
currencyPrefix = '';
/**
* Configura os valores padrão para input monetário.
*/
override ngOnInit(): void {
// Máscara para valores decimais com 2 casas
this.mask = 'separator.2';
// Formato brasileiro como padrão (se não definido)
if (this.thousandSeparator === '') {
this.thousandSeparator = '.';
}
if (Array.isArray(this.decimalMarker)) {
this.decimalMarker = ',';
}
// Configurações automáticas
this.inputMode = 'decimal';
this.leadZero = true;
// Prefixo exibido em span separado (não na máscara)
this.currencyPrefix = this.getCurrencySymbol();
// Valor inicial 0 se não definido (pode ser sobrescrito pelo form pai)
if (this.control.value === null || this.control.value === undefined || this.control.value === '') {
this.control.setValue('0', { emitEvent: false });
}
super.ngOnInit();
}
/**
* Atualiza o prefixo quando a moeda muda.
*/
override ngOnChanges(changes: SimpleChanges): void {
super.ngOnChanges(changes);
if (changes['currency'] && !changes['currency'].firstChange) {
this.currencyPrefix = this.getCurrencySymbol();
}
}
/**
* Obtém o símbolo da moeda via Intl.NumberFormat.
*/
private getCurrencySymbol(): string {
try {
return new Intl.NumberFormat(undefined, { style: 'currency', currency: this.currency })
.format(0)
.replace(/[\d.,\s]/g, '')
.trim();
} catch {
return this.currency;
}
}
}
<div class="wrapper-all-inside-input {{ customClass }}">
@if (label?.length || tooltipMessage || labelTemplate) {
<label
class="display-flex"
[ngClass]="{
readonly: readonly,
}"
[for]="id"
>
@if (label && !labelTemplate) {
<div [ngStyle]="{ color: labelColor }" [innerHtml]="label | universalSafe"></div>
}
@if (labelTemplate) {
<div>
<ng-container *ngTemplateOutlet="labelTemplate"></ng-container>
</div>
}
@if (tooltipMessage) {
<sq-tooltip
class="ml-1"
[message]="tooltipMessage"
[placement]="tooltipPlacement"
[color]="tooltipColor"
[icon]="tooltipIcon"
></sq-tooltip>
}
</label>
}
<div
class="p-0 wrapper-input wrapper-input-squid text-ellipsisarea"
[ngClass]="{
readonly: readonly,
}"
>
@if (leftLabel) {
<span class="input-group-text m-0">
<ng-container *ngTemplateOutlet="leftLabel"></ng-container>
</span>
} @else if (currencyPrefix) {
<span class="input-group-text m-0">{{ currencyPrefix }}</span>
}
<input
class="col input"
[ngClass]="{
disabled: disabled,
readonly: readonly,
}"
[ngStyle]="{
'background-color': backgroundColor,
'border-color': borderColor,
}"
[id]="id"
type="text"
[name]="name"
[placeholder]="placeholder || '0,00'"
[readonly]="readonly"
[formControl]="control"
(keydown)="onKeyDown($event)"
(keyup)="onKeyUp($event)"
(blur)="onBlur($event)"
(focus)="onFocus($event)"
[attr.inputmode]="inputMode"
[mask]="mask"
[thousandSeparator]="thousandSeparator"
[suffix]="suffix"
[allowNegativeNumbers]="allowNegativeNumbers"
[decimalMarker]="decimalMarker"
[leadZero]="leadZero"
/>
@if (rightLabel) {
<span class="input-group-text m-0">
<ng-container *ngTemplateOutlet="rightLabel"></ng-container>
</span>
}
</div>
</div>
./sq-input-money-form-control.component.scss
// Importa os estilos do componente pai (mask-form-control)
@use '../sq-input-mask-form-control/sq-input-mask-form-control.component';
// Estilo específico para placeholder do input monetário
input::placeholder {
color: var(--color_text-icon_neutral_tertiary, #999);
opacity: 0.7;
}