From e1853dd2842352cbe67f7c82447250b206c49db3 Mon Sep 17 00:00:00 2001 From: Alex Inkin Date: Mon, 16 Sep 2024 19:02:36 +0400 Subject: [PATCH] feat(core): `Appearance` allow multiple modes (#9042) --- .../input-card-group.component.ts | 3 ++- .../input-card-group.style.less | 2 +- .../constants/attr-with-values-to-replace.ts | 2 +- .../templates/migrate-button-appearance.ts | 7 +++++-- .../tests/schematic-migrate-blocked.spec.ts | 2 +- ...chematic-migrate-button-appearance.spec.ts | 8 +++---- .../components/textfield/select.directive.ts | 5 ++--- .../textfield/textfield.component.ts | 4 ++-- .../textfield/textfield.directive.ts | 21 ++++++++++++------- .../appearance/appearance.bindings.ts | 8 +++++++ .../appearance/appearance.directive.ts | 13 +++++++++++- .../directives/appearance/with-appearance.ts | 1 + .../core/styles/components/appearance.less | 2 +- projects/core/styles/components/group.less | 11 +++++----- .../core/styles/components/textfield.less | 10 ++++----- .../core/styles/theme/appearance/outline.less | 11 +++++----- .../core/styles/theme/appearance/primary.less | 3 ++- .../styles/theme/appearance/secondary.less | 17 +++++++++------ .../core/styles/theme/appearance/status.less | 18 ++++++++++------ .../styles/theme/appearance/textfield.less | 4 ++-- .../demo/src/components/appearance/index.html | 4 ++-- .../demo/src/components/appearance/index.ts | 4 ++-- .../src/modules/components/block/index.html | 2 +- .../components/button/examples/2/index.html | 10 +++++---- .../components/filter/examples/4/index.html | 2 +- .../dropdown-open/examples/4/index.html | 2 +- .../input-phone-international.template.html | 7 ++++--- 27 files changed, 115 insertions(+), 68 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 701abc142c24..ca286f17e2f1 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 @@ -45,6 +45,7 @@ import { TuiAppearance, tuiAppearance, tuiAppearanceFocus, + tuiAppearanceMode, tuiAppearanceState, } from '@taiga-ui/core/directives/appearance'; import { @@ -104,7 +105,6 @@ export interface TuiCard { ], host: { 'data-size': 'l', - '[attr.data-mode]': 'mode()', '(mousedown)': 'onMouseDown($event)', }, }) @@ -144,6 +144,7 @@ export class TuiInputCardGroup protected readonly texts = toSignal(inject(TUI_INPUT_CARD_GROUP_TEXTS)); protected readonly open = tuiDropdownOpen(); + protected readonly m = tuiAppearanceMode(this.mode); protected readonly appearance = tuiAppearance( inject(TUI_TEXTFIELD_OPTIONS).appearance, ); 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 6a8ba3e31f9d..9a6576db798a 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 @@ -196,7 +196,7 @@ transform: translateY(-0.7em); } - :host([data-mode='invalid']) & { + :host([data-mode~='invalid']) & { color: var(--tui-text-negative); } diff --git a/projects/cdk/schematics/ng-update/v4/steps/constants/attr-with-values-to-replace.ts b/projects/cdk/schematics/ng-update/v4/steps/constants/attr-with-values-to-replace.ts index 4c28567b3016..8c8ffb1463bf 100644 --- a/projects/cdk/schematics/ng-update/v4/steps/constants/attr-with-values-to-replace.ts +++ b/projects/cdk/schematics/ng-update/v4/steps/constants/attr-with-values-to-replace.ts @@ -44,7 +44,7 @@ export const ATTR_WITH_VALUES_TO_REPLACE: ReplacementAttributeValue[] = [ }, { attrNames: ['[pseudoInvalid]'], - newAttrName: '[attr.data-mode]', + newAttrName: '[tuiAppearanceMode]', withTagNames: hasPseudoInvalid, valueReplacer: (condition) => `${condition} ? 'invalid' : null`, }, diff --git a/projects/cdk/schematics/ng-update/v4/steps/templates/migrate-button-appearance.ts b/projects/cdk/schematics/ng-update/v4/steps/templates/migrate-button-appearance.ts index b0c067e370f0..7e6c226e8fdc 100644 --- a/projects/cdk/schematics/ng-update/v4/steps/templates/migrate-button-appearance.ts +++ b/projects/cdk/schematics/ng-update/v4/steps/templates/migrate-button-appearance.ts @@ -68,7 +68,10 @@ export function migrateButtonAppearance({ startOffset + templateOffset, ` ${appearanceInputName}="whiteblock"`, ); - recorder.insertLeft(startOffset + templateOffset, ' data-mode="checked"'); + recorder.insertLeft( + startOffset + templateOffset, + ' tuiAppearanceMode="checked"', + ); } }); @@ -87,6 +90,6 @@ export function migrateButtonAppearance({ function addTodo(recorder: UpdateRecorder, templateOffset: number): void { recorder.insertRight( templateOffset, - '\n', + '\n', ); } diff --git a/projects/cdk/schematics/ng-update/v4/tests/schematic-migrate-blocked.spec.ts b/projects/cdk/schematics/ng-update/v4/tests/schematic-migrate-blocked.spec.ts index bfaea4247bbb..826523b375ac 100644 --- a/projects/cdk/schematics/ng-update/v4/tests/schematic-migrate-blocked.spec.ts +++ b/projects/cdk/schematics/ng-update/v4/tests/schematic-migrate-blocked.spec.ts @@ -88,7 +88,7 @@ const TEMPLATE_BEFORE = ` `.trim(); const TEMPLATE_AFTER = ` - +