From 5e20a2612839a5c7be2b49df26be6175bb22b431 Mon Sep 17 00:00:00 2001 From: Alex Inkin Date: Mon, 23 Dec 2024 18:24:53 +0400 Subject: [PATCH] feat(addon-commerce): `InputCardGroup` add `inputs` option (#10033) Co-authored-by: taiga-family-bot --- .../input-card-group.component.ts | 17 ++- .../input-card-group.options.ts | 7 + .../input-card-group.style.less | 4 + .../input-card-group.template.html | 7 +- .../components/api/api-item.template.html | 2 +- .../components/input-card-group/index.html | 132 +++++++++++------- .../components/input-card-group/index.ts | 57 ++++---- 7 files changed, 135 insertions(+), 91 deletions(-) diff --git a/projects/addon-commerce/components/input-card-group/input-card-group.component.ts b/projects/addon-commerce/components/input-card-group/input-card-group.component.ts index 41dc1ecad9d4..61bf046a2acf 100644 --- a/projects/addon-commerce/components/input-card-group/input-card-group.component.ts +++ b/projects/addon-commerce/components/input-card-group/input-card-group.component.ts @@ -177,9 +177,18 @@ export class TuiInputCardGroup () => !!this.value()?.card && this.interactive(), ); + /** + * @deprecated use 'placeholder' instead + */ @Input() public exampleText = this.options.exampleText; + @Input() + public placeholder = this.options.exampleText; + + @Input() + public inputs = this.options.inputs; + @Input() public cardValidator: TuiBooleanHandler = this.options.cardValidator; @@ -219,7 +228,11 @@ export class TuiInputCardGroup } public focusExpire(): void { - this.inputExpire?.nativeElement.focus({preventScroll: true}); + if (this.inputs.expire) { + this.inputExpire?.nativeElement.focus({preventScroll: true}); + } else { + this.inputCVC?.nativeElement.focus({preventScroll: true}); + } } public focusCVC(): void { @@ -292,7 +305,7 @@ export class TuiInputCardGroup } protected get cvcPrefilled(): boolean { - return !!this.cvc.match(TUI_NON_DIGIT_REGEXP); + return !this.inputs.cvc || !!this.cvc.match(TUI_NON_DIGIT_REGEXP); } protected get cardFocusable(): boolean { diff --git a/projects/addon-commerce/components/input-card-group/input-card-group.options.ts b/projects/addon-commerce/components/input-card-group/input-card-group.options.ts index 68624c8d986b..31377f452b8b 100644 --- a/projects/addon-commerce/components/input-card-group/input-card-group.options.ts +++ b/projects/addon-commerce/components/input-card-group/input-card-group.options.ts @@ -5,11 +5,17 @@ import {tuiDefaultCardValidator} from '@taiga-ui/addon-commerce/constants'; import type {TuiBooleanHandler} from '@taiga-ui/cdk/types'; import {tuiCreateToken, tuiProvideOptions} from '@taiga-ui/cdk/utils/miscellaneous'; +export interface TuiCardInputs { + cvc: boolean; + expire: boolean; +} + export interface TuiInputCardGroupOptions extends TuiInputCardOptions { readonly cardValidator: TuiBooleanHandler; readonly exampleText: string; readonly exampleTextCVC: string; readonly cvcHidden: boolean; + readonly inputs: TuiCardInputs; } export const TUI_INPUT_CARD_GROUP_DEFAULT_OPTIONS: TuiInputCardGroupOptions = { @@ -18,6 +24,7 @@ export const TUI_INPUT_CARD_GROUP_DEFAULT_OPTIONS: TuiInputCardGroupOptions = { exampleText: '0000 0000 0000 0000', exampleTextCVC: '000', cvcHidden: true, + inputs: {cvc: true, expire: true}, }; export const TUI_INPUT_CARD_GROUP_OPTIONS = tuiCreateToken( diff --git a/projects/addon-commerce/components/input-card-group/input-card-group.style.less b/projects/addon-commerce/components/input-card-group/input-card-group.style.less index 877e080df787..12a52904aa59 100644 --- a/projects/addon-commerce/components/input-card-group/input-card-group.style.less +++ b/projects/addon-commerce/components/input-card-group/input-card-group.style.less @@ -119,6 +119,10 @@ color: var(--tui-text-tertiary); } + &_prefilled::placeholder { + color: var(--tui-text-primary); + } + &:-webkit-autofill { -webkit-text-fill-color: var(--tui-text-primary) !important; caret-color: var(--tui-text-primary) !important; diff --git a/projects/addon-commerce/components/input-card-group/input-card-group.template.html b/projects/addon-commerce/components/input-card-group/input-card-group.template.html index c5d08114fa1b..0b0f41ad8548 100644 --- a/projects/addon-commerce/components/input-card-group/input-card-group.template.html +++ b/projects/addon-commerce/components/input-card-group/input-card-group.template.html @@ -19,7 +19,7 @@ [maskito]="maskCard" [ngModel]="formattedCard" [ngModelOptions]="{standalone: true}" - [placeholder]="cardPrefilled ? '' : exampleText" + [placeholder]="cardPrefilled ? '' : placeholder || exampleText" [readOnly]="readOnly()" [tabIndex]="cardFocusable ? 0 : -1" (focus)="(0)" @@ -66,18 +66,19 @@ automation-id="tui-input-card-group__expire" inputmode="numeric" maxlength="5" - placeholder="00/00" translate="no" class="t-input" [attr.id]="id + '_expire'" [attr.name]="autocomplete ? 'ccexpiryyear' : null" [autocomplete]="autocomplete ? 'cc-exp' : 'off'" [class.t-input_inert]="!expireFocusable" + [class.t-input_prefilled]="!inputs.expire" [disabled]="disabled()" [maskito]="maskExpire" [ngModel]="expire" [ngModelOptions]="{standalone: true}" - [readOnly]="readOnly()" + [placeholder]="inputs.expire ? '00/00' : '••/••'" + [readOnly]="readOnly() || !inputs.expire" [tabIndex]="expireFocusable ? 0 : -1" (focus)="(0)" (ngModelChange)="onExpireChange($event)" diff --git a/projects/addon-doc/components/api/api-item.template.html b/projects/addon-doc/components/api/api-item.template.html index 06993cd8f01b..2999a5bd4b3a 100644 --- a/projects/addon-doc/components/api/api-item.template.html +++ b/projects/addon-doc/components/api/api-item.template.html @@ -38,7 +38,7 @@ tuiTextfieldSize="m" class="t-input" [content]="content" - [tuiTextfieldCleaner]="type.includes('null')" + [tuiTextfieldCleaner]="type.includes('null') || type.includes('PolymorpheusContent')" >