-
Notifications
You must be signed in to change notification settings - Fork 467
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(kit): allow configuration of default options for input-count #675
Merged
waterplea
merged 10 commits into
taiga-family:main
from
KarimovDev:feat-input-count-options
Sep 13, 2021
Merged
Changes from 4 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
385b80d
feat(kit): allow configuration of default options for input-count
729143c
fix(kit): implement review notes
b9bc31c
fix(kit): implement review notes
028d273
Merge branch 'main' into feat-input-count-options
waterplea 47cfec7
chore(build): fix
waterplea be66cf1
fix(kit): implement review notes
17074da
chore(core): deprecate `TableModeDirective`
waterplea 8e0eb48
chore(kit): fix class
waterplea cfc4153
chore(kit): fix condition
waterplea 4b13a60
chore(kit): fix condition
waterplea File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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> |
34 changes: 34 additions & 0 deletions
34
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,34 @@ | ||
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: 'tuiIconChevronUp', | ||
down: 'tuiIconChevronDown', | ||
}, | ||
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), | ||
}); | ||
} |
20 changes: 20 additions & 0 deletions
20
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,20 @@ | ||
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: 'tuiIconChevronUp', | ||
down: 'tuiIconChevronDown', | ||
}, | ||
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'; |
40 changes: 40 additions & 0 deletions
40
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,40 @@ | ||
import {InjectionToken} from '@angular/core'; | ||
import {PolymorpheusContent} from '@tinkoff/ng-polymorpheus'; | ||
|
||
export interface InputCountOptions { | ||
readonly icons: Readonly<{ | ||
up: PolymorpheusContent<{}>; | ||
down: PolymorpheusContent<{}>; | ||
}>; | ||
readonly appearance: string; | ||
readonly hideButtons: boolean; | ||
readonly min: number; | ||
readonly max: number; | ||
readonly step: number; | ||
readonly postfix: string; | ||
} | ||
|
||
// TODO: remove in ivy compilation | ||
export const PASSWORD_ICON_UP = 'tuiIconPlus'; | ||
export const PASSWORD_ICON_DOWN = 'tuiIconMinus'; | ||
|
||
/** Default values for the input count 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right now we force hide buttons in tables by comparing appearance to table. That's rather hardcode. @vladimirpotekhin @nsbarsukov what do you think, it probably makes sense to alter this token in
Table
directive now? With a factory, skipSelf and spread withhideButtons
set totrue
? Sounds like that would be more idiomatic.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case someone can override token by mistake if they use nested components inside the table. Or am I wrong?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case, if somebody uses component inside table and for some reason want to change it, they can create a directive that would override it, yes. I don't think that's bad.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. I've already done this as an example. @vladimirpotekhin @nsbarsukov you can check it right here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@waterplea there is also tuiTableMode directive with TUI_TEXTFIELD_APPEARANCE token. Should we add TUI_INPUT_COUNT_OPTIONS here as well? In this case, should we move TUI_INPUT_COUNT_OPTIONS into core package?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, that directive was there before we introduced table component. I believe we might end up just dropping it in the next major release.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, @KarimovDev I see this directive is still actually in use on the demo and that fails the screenshots. Let's copy-paste this factory for the time being then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done