-
Notifications
You must be signed in to change notification settings - Fork 474
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): default options configuration for
PrimitiveTextfield
(#…
- Loading branch information
Michael M
authored
Jan 26, 2022
1 parent
8b99faa
commit af77aaf
Showing
9 changed files
with
192 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export * from './primitive-textfield.component'; | ||
export * from './primitive-textfield.module'; | ||
export * from './primitive-textfield.providers'; | ||
export * from './primitive-textfield-options'; | ||
export * from './value-decoration/value-decoration.component'; |
25 changes: 25 additions & 0 deletions
25
projects/core/components/primitive-textfield/primitive-textfield-options.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import {InjectionToken} from '@angular/core'; | ||
import {TuiHorizontalDirection} from '@taiga-ui/core/types'; | ||
import {PolymorpheusContent} from '@tinkoff/ng-polymorpheus'; | ||
|
||
export interface TuiPrimitiveTextfieldOptions { | ||
readonly iconAlign: TuiHorizontalDirection; | ||
readonly iconCleaner: PolymorpheusContent; | ||
} | ||
|
||
// TODO: remove in ivy compilation | ||
export const TUI_PRIMITIVE_TEXTFIELD_ICON_CLEANER = 'tuiIconCloseLarge'; | ||
|
||
/** Default values for primitive textfield options */ | ||
export const TUI_PRIMITIVE_TEXTFIELD_DEFAULT_OPTIONS: TuiPrimitiveTextfieldOptions = { | ||
iconAlign: 'right', | ||
iconCleaner: TUI_PRIMITIVE_TEXTFIELD_ICON_CLEANER, | ||
}; | ||
|
||
export const TUI_PRIMITIVE_TEXTFIELD_OPTIONS = | ||
new InjectionToken<TuiPrimitiveTextfieldOptions>( | ||
'Default parameters for primitive textfield component', | ||
{ | ||
factory: () => TUI_PRIMITIVE_TEXTFIELD_DEFAULT_OPTIONS, | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
projects/demo/src/modules/components/primitive-textfield/examples/2/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<div class="b-form"> | ||
<label tuiLabel i18n-label label="Modified cleaner icon"> | ||
<tui-primitive-textfield | ||
tuiTextfieldSize="m" | ||
tuiTextfieldType="email" | ||
[tuiTextfieldLabelOutside]="true" | ||
[tuiTextfieldCleaner]="true" | ||
[value]="value" | ||
(valueChange)="onValueChange($event)" | ||
(focusedChange)="onFocused($event)" | ||
> | ||
Type an email | ||
</tui-primitive-textfield> | ||
</label> | ||
|
||
<label | ||
tuiLabel | ||
i18n-label | ||
label="Override modified cleaner icon" | ||
class="tui-space_top-4" | ||
> | ||
<tui-primitive-textfield | ||
tuiTextfieldSize="m" | ||
tuiTextfieldType="email" | ||
[tuiTextfieldLabelOutside]="true" | ||
[tuiTextfieldCleaner]="true" | ||
[value]="value" | ||
[iconCleaner]="iconCleaner" | ||
(valueChange)="onValueChange($event)" | ||
(focusedChange)="onFocused($event)" | ||
> | ||
Type an email | ||
</tui-primitive-textfield> | ||
</label> | ||
</div> | ||
|
||
<ng-template #iconCleaner> | ||
<tui-svg src="tuiIconDraft"></tui-svg> | ||
</ng-template> |
69 changes: 69 additions & 0 deletions
69
projects/demo/src/modules/components/primitive-textfield/examples/2/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { | ||
ChangeDetectorRef, | ||
Component, | ||
Inject, | ||
Optional, | ||
Self, | ||
ViewChild, | ||
} from '@angular/core'; | ||
import {NgControl} from '@angular/forms'; | ||
import {changeDetection} from '@demo/emulate/change-detection'; | ||
import {encapsulation} from '@demo/emulate/encapsulation'; | ||
import {AbstractTuiControl, TuiNativeFocusableElement} from '@taiga-ui/cdk'; | ||
import { | ||
TUI_PRIMITIVE_TEXTFIELD_DEFAULT_OPTIONS, | ||
TUI_PRIMITIVE_TEXTFIELD_OPTIONS, | ||
TuiPrimitiveTextfieldComponent, | ||
} from '@taiga-ui/core'; | ||
|
||
@Component({ | ||
selector: 'tui-primitive-textfield-example-2', | ||
templateUrl: './index.html', | ||
changeDetection, | ||
encapsulation, | ||
providers: [ | ||
{ | ||
provide: TUI_PRIMITIVE_TEXTFIELD_OPTIONS, // <-- You are looking for this token | ||
useValue: { | ||
...TUI_PRIMITIVE_TEXTFIELD_DEFAULT_OPTIONS, | ||
iconCleaner: 'tuiIconChevronUp', | ||
}, | ||
}, | ||
], | ||
}) | ||
export class TuiPrimitiveTextfieldExample2 extends AbstractTuiControl<string> { | ||
@ViewChild(TuiPrimitiveTextfieldComponent) | ||
private readonly textfield?: TuiPrimitiveTextfieldComponent; | ||
|
||
constructor( | ||
@Optional() | ||
@Self() | ||
@Inject(NgControl) | ||
control: NgControl | null, | ||
@Inject(ChangeDetectorRef) changeDetectorRef: ChangeDetectorRef, | ||
) { | ||
super(control, changeDetectorRef); | ||
} | ||
|
||
get nativeFocusableElement(): TuiNativeFocusableElement | null { | ||
return this.computedDisabled || !this.textfield | ||
? null | ||
: this.textfield.nativeFocusableElement; | ||
} | ||
|
||
get focused(): boolean { | ||
return !!this.textfield && this.textfield.focused; | ||
} | ||
|
||
onValueChange(textValue: string) { | ||
this.updateValue(textValue); | ||
} | ||
|
||
onFocused(focused: boolean) { | ||
this.updateFocused(focused); | ||
} | ||
|
||
protected getFallbackValue(): string { | ||
return ''; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import {Component, forwardRef, ViewChild} from '@angular/core'; | ||
import {changeDetection} from '@demo/emulate/change-detection'; | ||
import {TuiDocExample} from '@taiga-ui/addon-doc'; | ||
import {TuiAutofillFieldName, TuiInputModeT, TuiInputTypeT} from '@taiga-ui/cdk'; | ||
import { | ||
TuiDirection, | ||
|
@@ -10,13 +11,6 @@ import { | |
} from '@taiga-ui/core'; | ||
import {PolymorpheusContent} from '@tinkoff/ng-polymorpheus'; | ||
|
||
import {default as example1Ts} from '!!raw-loader!./examples/1/component.ts'; | ||
import {default as example1Less} from '!!raw-loader!./examples/1/style.less'; | ||
import {default as example1Html} from '!!raw-loader!./examples/1/template.html'; | ||
import {default as exampleImportModule} from '!!raw-loader!./examples/import/import-module.txt'; | ||
import {default as exampleInsertTemplate} from '!!raw-loader!./examples/import/insert-template.txt'; | ||
|
||
import {FrontEndExample} from '../../interfaces/front-end-example'; | ||
import {ABSTRACT_PROPS_ACCESSOR} from '../abstract/inherited-documentation/abstract-props-accessor'; | ||
import {AbstractExampleTuiInteractive} from '../abstract/interactive'; | ||
|
||
|
@@ -45,14 +39,24 @@ export class ExampleTuiPrimitiveTextfieldComponent extends AbstractExampleTuiInt | |
@ViewChild('interactiveContent') | ||
private readonly interactiveIcon: PolymorpheusContent = ''; | ||
|
||
readonly example1: FrontEndExample = { | ||
TypeScript: example1Ts, | ||
HTML: example1Html, | ||
LESS: example1Less, | ||
readonly example1: TuiDocExample = { | ||
TypeScript: import('!!raw-loader!./examples/1/component.ts'), | ||
HTML: import('!!raw-loader!./examples/1/template.html'), | ||
LESS: import('!!raw-loader!./examples/1/style.less'), | ||
}; | ||
|
||
readonly example2: TuiDocExample = { | ||
TypeScript: import('!!raw-loader!./examples/2/index.ts'), | ||
HTML: import('!!raw-loader!./examples/2/index.html'), | ||
}; | ||
|
||
readonly exampleImportModule = exampleImportModule; | ||
readonly exampleInsertTemplate = exampleInsertTemplate; | ||
readonly exampleImportModule = import( | ||
'!!raw-loader!./examples/import/import-module.txt' | ||
); | ||
|
||
readonly exampleInsertTemplate = import( | ||
'!!raw-loader!./examples/import/insert-template.txt' | ||
); | ||
|
||
readonly themes = ['Taiga UI', 'Bootstrap', 'Material']; | ||
theme = this.themes[0]; | ||
|
@@ -118,6 +122,8 @@ export class ExampleTuiPrimitiveTextfieldComponent extends AbstractExampleTuiInt | |
|
||
password = ''; | ||
|
||
example2Value = '[email protected]'; | ||
|
||
value = ''; | ||
|
||
exampleText = ''; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters