-
Notifications
You must be signed in to change notification settings - Fork 467
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(kit): allow configuration of default options for input-count
- Loading branch information
Dima Karimov
committed
Sep 6, 2021
1 parent
4ddc513
commit 385b80d
Showing
13 changed files
with
337 additions
and
36 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
projects/demo/src/modules/components/input-count/examples/3/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,21 @@ | ||
<form class="b-form" [formGroup]="testForm"> | ||
<label tuiLabel i18n-label label="With custom options"> | ||
<tui-input-count | ||
formControlName="testValue1" | ||
[tuiTextfieldLabelOutside]="true" | ||
></tui-input-count> | ||
</label> | ||
|
||
<label | ||
tuiLabel | ||
class="tui-space_top-4" | ||
i18n-label | ||
label="With custom options and medium size" | ||
> | ||
<tui-input-count | ||
formControlName="testValue2" | ||
tuiTextfieldSize="m" | ||
[tuiTextfieldLabelOutside]="true" | ||
></tui-input-count> | ||
</label> | ||
</form> |
38 changes: 38 additions & 0 deletions
38
projects/demo/src/modules/components/input-count/examples/3/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,38 @@ | ||
import {Component} from '@angular/core'; | ||
import {FormControl, FormGroup, Validators} from '@angular/forms'; | ||
import {TUI_INPUT_COUNT_DEFAULT_OPTIONS, TUI_INPUT_COUNT_OPTIONS} from '@taiga-ui/kit'; | ||
import {changeDetection} from '../../../../../change-detection-strategy'; | ||
import {encapsulation} from '../../../../../view-encapsulation'; | ||
|
||
@Component({ | ||
selector: 'tui-input-count-example-3', | ||
templateUrl: './index.html', | ||
changeDetection, | ||
encapsulation, | ||
providers: [ | ||
{ | ||
provide: TUI_INPUT_COUNT_OPTIONS, | ||
useValue: { | ||
...TUI_INPUT_COUNT_DEFAULT_OPTIONS, | ||
icons: { | ||
up: ({$implicit}: any) => | ||
$implicit === 'm' ? 'tuiIconChevronUp' : 'tuiIconChevronUpLarge', | ||
down: ({$implicit}: any) => | ||
$implicit === 'm' | ||
? 'tuiIconChevronDown' | ||
: 'tuiIconChevronDownLarge', | ||
}, | ||
appearance: 'secondary', | ||
step: 10, | ||
min: 10, | ||
max: 100, | ||
}, | ||
}, | ||
], | ||
}) | ||
export class TuiInputCountExample3 { | ||
testForm = new FormGroup({ | ||
testValue1: new FormControl(10, Validators.required), | ||
testValue2: new FormControl(10, Validators.required), | ||
}); | ||
} |
24 changes: 24 additions & 0 deletions
24
projects/demo/src/modules/components/input-count/examples/import/define-options.txt
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,24 @@ | ||
import {TUI_INPUT_COUNT_OPTIONS, TUI_INPUT_COUNT_DEFAULT_OPTIONS} from '@taiga-ui/kit'; | ||
|
||
... | ||
|
||
@NgModule({ | ||
providers: [{ | ||
provide: TUI_INPUT_COUNT_OPTIONS, | ||
useValue: { | ||
...TUI_INPUT_COUNT_DEFAULT_OPTIONS, | ||
icons: { | ||
up: ({$implicit}: any) => | ||
$implicit === 'm' ? 'tuiIconChevronUp' : 'tuiIconChevronUpLarge', | ||
down: ({$implicit}: any) => | ||
$implicit === 'm' | ||
? 'tuiIconChevronDown' | ||
: 'tuiIconChevronDownLarge', | ||
}, | ||
appearance: 'secondary', | ||
step: 10, | ||
min: 10, | ||
max: 100, | ||
}, | ||
}], | ||
... |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './input-count.component'; | ||
export * from './input-count.module'; | ||
export * from './input-count-options'; |
42 changes: 42 additions & 0 deletions
42
projects/kit/components/input-count/input-count-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,42 @@ | ||
import {InjectionToken} from '@angular/core'; | ||
import {TuiContextWithImplicit} from '@taiga-ui/cdk'; | ||
import {TuiSizeL} from '@taiga-ui/core'; | ||
import {PolymorpheusContent} from '@tinkoff/ng-polymorpheus'; | ||
|
||
export interface InputCountOptions { | ||
readonly icons: Readonly<{ | ||
up: PolymorpheusContent<TuiContextWithImplicit<TuiSizeL>>; | ||
down: PolymorpheusContent<TuiContextWithImplicit<TuiSizeL>>; | ||
}>; | ||
appearance: string; | ||
hideButtons: boolean; | ||
min: number; | ||
max: number; | ||
step: number; | ||
postfix: string; | ||
} | ||
|
||
// TODO: remove in ivy compilation | ||
export const PASSWORD_ICON_UP = 'tuiIconPlus'; | ||
export const PASSWORD_ICON_DOWN = 'tuiIconMinus'; | ||
|
||
/** Default values for the input password options. */ | ||
export const TUI_INPUT_COUNT_DEFAULT_OPTIONS: InputCountOptions = { | ||
icons: { | ||
up: PASSWORD_ICON_UP, | ||
down: PASSWORD_ICON_DOWN, | ||
}, | ||
appearance: 'textfield', | ||
hideButtons: false, | ||
min: 0, | ||
max: Infinity, | ||
step: 1, | ||
postfix: '', | ||
}; | ||
|
||
export const TUI_INPUT_COUNT_OPTIONS = new InjectionToken<InputCountOptions>( | ||
'Default parameters for input count component', | ||
{ | ||
factory: () => TUI_INPUT_COUNT_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
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
Oops, something went wrong.