-
Notifications
You must be signed in to change notification settings - Fork 477
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(experimental):
TuiAmount
add new pipe (#5735)
- Loading branch information
1 parent
a45f0d4
commit 33588c3
Showing
29 changed files
with
401 additions
and
9 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
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './number-format.directive'; | ||
export * from './number-format.module'; |
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,5 @@ | ||
{ | ||
"lib": { | ||
"entryFile": "index.ts" | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
projects/core/directives/number-format/number-format.directive.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,26 @@ | ||
import {Directive, forwardRef, Inject, Input} from '@angular/core'; | ||
import {TuiNumberFormatSettings} from '@taiga-ui/core/interfaces'; | ||
import {TUI_NUMBER_FORMAT, TUI_NUMBER_FORMAT_OBSERVABLE} from '@taiga-ui/core/tokens'; | ||
import {BehaviorSubject} from 'rxjs'; | ||
|
||
@Directive({ | ||
selector: '[tuiNumberFormat]', | ||
providers: [ | ||
{ | ||
provide: TUI_NUMBER_FORMAT_OBSERVABLE, | ||
useExisting: forwardRef(() => TuiNumberFormatDirective), | ||
}, | ||
], | ||
}) | ||
export class TuiNumberFormatDirective extends BehaviorSubject<TuiNumberFormatSettings> { | ||
@Input() | ||
set tuiNumberFormat(format: Partial<TuiNumberFormatSettings>) { | ||
this.next({...this.settings, decimalLimit: NaN, ...format}); | ||
} | ||
|
||
constructor( | ||
@Inject(TUI_NUMBER_FORMAT) private readonly settings: TuiNumberFormatSettings, | ||
) { | ||
super({...settings, decimalLimit: NaN}); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
projects/core/directives/number-format/number-format.module.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,9 @@ | ||
import {NgModule} from '@angular/core'; | ||
|
||
import {TuiNumberFormatDirective} from './number-format.directive'; | ||
|
||
@NgModule({ | ||
declarations: [TuiNumberFormatDirective], | ||
exports: [TuiNumberFormatDirective], | ||
}) | ||
export class TuiNumberFormatModule {} |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import {tuiCreateToken} from '@taiga-ui/cdk'; | ||
import {TUI_DEFAULT_NUMBER_FORMAT} from '@taiga-ui/core/constants'; | ||
import {of} from 'rxjs'; | ||
|
||
/** | ||
* Formatting configuration for displayed numbers | ||
*/ | ||
export const TUI_NUMBER_FORMAT_OBSERVABLE = tuiCreateToken( | ||
of({...TUI_DEFAULT_NUMBER_FORMAT, decimalLimit: NaN}), | ||
); |
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
33 changes: 33 additions & 0 deletions
33
projects/demo/src/modules/experimental/amount/amount.component.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,33 @@ | ||
import {Component} from '@angular/core'; | ||
import {changeDetection} from '@demo/emulate/change-detection'; | ||
import {TuiDocExample, TuiRawLoaderContent} from '@taiga-ui/addon-doc'; | ||
|
||
@Component({ | ||
selector: 'example-amount', | ||
templateUrl: './amount.template.html', | ||
changeDetection, | ||
}) | ||
export class ExampleTuiAmountComponent { | ||
readonly exampleModule: TuiRawLoaderContent = import( | ||
'./examples/import/import-module.md?raw' | ||
); | ||
|
||
readonly exampleHtml: TuiRawLoaderContent = import( | ||
'./examples/import/insert-template.md?raw' | ||
); | ||
|
||
readonly example1: TuiDocExample = { | ||
HTML: import('./examples/1/index.html?raw'), | ||
TypeScript: import('./examples/1/index.ts?raw'), | ||
}; | ||
|
||
readonly example2: TuiDocExample = { | ||
HTML: import('./examples/2/index.html?raw'), | ||
TypeScript: import('./examples/2/index.ts?raw'), | ||
}; | ||
|
||
readonly example3: TuiDocExample = { | ||
HTML: import('./examples/3/index.html?raw'), | ||
TypeScript: import('./examples/3/index.ts?raw'), | ||
}; | ||
} |
33 changes: 33 additions & 0 deletions
33
projects/demo/src/modules/experimental/amount/amount.module.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,33 @@ | ||
import {CommonModule} from '@angular/common'; | ||
import {NgModule} from '@angular/core'; | ||
import {tuiGetDocModules} from '@taiga-ui/addon-doc'; | ||
import { | ||
TuiLinkModule, | ||
TuiNotificationModule, | ||
TuiNumberFormatModule, | ||
} from '@taiga-ui/core'; | ||
import {TuiAmountPipeModule} from '@taiga-ui/experimental'; | ||
|
||
import {ExampleTuiAmountComponent} from './amount.component'; | ||
import {TuiAmountExample1} from './examples/1'; | ||
import {TuiAmountExample2} from './examples/2'; | ||
import {TuiAmountExample3} from './examples/3'; | ||
|
||
@NgModule({ | ||
imports: [ | ||
CommonModule, | ||
TuiAmountPipeModule, | ||
TuiNotificationModule, | ||
TuiNumberFormatModule, | ||
tuiGetDocModules(ExampleTuiAmountComponent), | ||
TuiLinkModule, | ||
], | ||
declarations: [ | ||
ExampleTuiAmountComponent, | ||
TuiAmountExample1, | ||
TuiAmountExample2, | ||
TuiAmountExample3, | ||
], | ||
exports: [ExampleTuiAmountComponent], | ||
}) | ||
export class ExampleTuiAmountModule {} |
72 changes: 72 additions & 0 deletions
72
projects/demo/src/modules/experimental/amount/amount.template.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,72 @@ | ||
<tui-doc-page | ||
header="AmountPipe" | ||
package="EXPERIMENTAL" | ||
type="pipes" | ||
> | ||
<ng-template pageTab> | ||
<tui-notification status="warning"> | ||
This code is | ||
<strong>experimental</strong> | ||
and is a subject to change. Expect final solution to be shipped in the next major version | ||
</tui-notification> | ||
|
||
<p>Pipe to format number values to show money sums</p> | ||
|
||
<p> | ||
Number formatting can be customized by using | ||
<a | ||
fragment="number-format" | ||
routerLink="/utils/tokens" | ||
tuiLink | ||
> | ||
TUI_NUMBER_FORMAT | ||
</a> | ||
</p> | ||
|
||
<tui-doc-example | ||
id="base" | ||
heading="Basic" | ||
[content]="example1" | ||
> | ||
<tui-amount-example-1></tui-amount-example-1> | ||
</tui-doc-example> | ||
|
||
<tui-doc-example | ||
id="format" | ||
heading="Format" | ||
[content]="example2" | ||
> | ||
<tui-amount-example-2></tui-amount-example-2> | ||
</tui-doc-example> | ||
|
||
<tui-doc-example | ||
id="options" | ||
heading="Options" | ||
[content]="example3" | ||
> | ||
<tui-amount-example-3></tui-amount-example-3> | ||
</tui-doc-example> | ||
</ng-template> | ||
|
||
<ng-template pageTab="Setup"> | ||
<ol class="b-demo-steps"> | ||
<li> | ||
<p>Import into a module</p> | ||
|
||
<tui-doc-code | ||
filename="myComponent.module.ts" | ||
[code]="exampleModule" | ||
></tui-doc-code> | ||
</li> | ||
|
||
<li> | ||
<p>Add to the template:</p> | ||
|
||
<tui-doc-code | ||
filename="myComponent.template.html" | ||
[code]="exampleHtml" | ||
></tui-doc-code> | ||
</li> | ||
</ol> | ||
</ng-template> | ||
</tui-doc-page> |
14 changes: 14 additions & 0 deletions
14
projects/demo/src/modules/experimental/amount/examples/1/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,14 @@ | ||
<ol> | ||
<li>{{ 10728.9 | tuiAmount | async }}</li> | ||
<li>{{ 10728.9 | tuiAmount: 'RUB' | async }}</li> | ||
<li>{{ 10728.9 | tuiAmount: 'EUR' | async }}</li> | ||
<li>{{ 10728.9 | tuiAmount: 'USD' | async }}</li> | ||
<li>{{ 10728.9 | tuiAmount: 'GBP' | async }}</li> | ||
<li>{{ -12345.1 | tuiAmount: 'USD' : 'left' | async }}</li> | ||
<li>{{ 100 | tuiAmount: '£' : 'left' | async }}</li> | ||
<li>{{ 200 | tuiAmount: 'AED' : 'left' | async }}</li> | ||
</ol> | ||
|
||
<hr class="tui-space_top-1 tui-space_bottom-1" /> | ||
|
||
<span>Remaining {{ 10728.9 | tuiAmount | async }} of {{ 11000 | tuiAmount | async }}</span> |
11 changes: 11 additions & 0 deletions
11
projects/demo/src/modules/experimental/amount/examples/1/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,11 @@ | ||
import {Component} from '@angular/core'; | ||
import {changeDetection} from '@demo/emulate/change-detection'; | ||
import {encapsulation} from '@demo/emulate/encapsulation'; | ||
|
||
@Component({ | ||
selector: 'tui-amount-example-1', | ||
templateUrl: './index.html', | ||
changeDetection, | ||
encapsulation, | ||
}) | ||
export class TuiAmountExample1 {} |
9 changes: 9 additions & 0 deletions
9
projects/demo/src/modules/experimental/amount/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,9 @@ | ||
<div [tuiNumberFormat]="{rounding: 'round', thousandSeparator: ',', decimalSeparator: '.'}"> | ||
{{ -10000000.536 | tuiAmount: 'USD' : 'left' | async }} | ||
</div> | ||
|
||
<div>{{ 200.536 | tuiAmount: 'EUR' | async }}</div> | ||
|
||
<div [tuiNumberFormat]="{rounding: 'ceil', decimalLimit: 1}"> | ||
{{ 54000.643 | tuiAmount: 'USD' : 'left' | async }} | ||
</div> |
11 changes: 11 additions & 0 deletions
11
projects/demo/src/modules/experimental/amount/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,11 @@ | ||
import {Component} from '@angular/core'; | ||
import {changeDetection} from '@demo/emulate/change-detection'; | ||
import {encapsulation} from '@demo/emulate/encapsulation'; | ||
|
||
@Component({ | ||
selector: 'tui-amount-example-2', | ||
templateUrl: './index.html', | ||
changeDetection, | ||
encapsulation, | ||
}) | ||
export class TuiAmountExample2 {} |
2 changes: 2 additions & 0 deletions
2
projects/demo/src/modules/experimental/amount/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,2 @@ | ||
<div>{{ -12.3 | tuiAmount | async }}</div> | ||
<div>{{ 3000 | tuiAmount | async }}</div> |
19 changes: 19 additions & 0 deletions
19
projects/demo/src/modules/experimental/amount/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,19 @@ | ||
import {Component} from '@angular/core'; | ||
import {changeDetection} from '@demo/emulate/change-detection'; | ||
import {encapsulation} from '@demo/emulate/encapsulation'; | ||
import {tuiAmountOptionsProvider} from '@taiga-ui/experimental'; | ||
|
||
@Component({ | ||
selector: 'tui-amount-example-3', | ||
templateUrl: './index.html', | ||
changeDetection, | ||
encapsulation, | ||
providers: [ | ||
tuiAmountOptionsProvider({ | ||
sign: 'always', | ||
currency: 'USD', | ||
currencyAlign: 'left', | ||
}), | ||
], | ||
}) | ||
export class TuiAmountExample3 {} |
13 changes: 13 additions & 0 deletions
13
projects/demo/src/modules/experimental/amount/examples/import/import-module.md
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,13 @@ | ||
```ts | ||
import {TuiAmountPipeModule} from '@taiga-ui/experimental'; | ||
|
||
// ... | ||
|
||
@NgModule({ | ||
imports: [ | ||
// ... | ||
TuiAmountPipeModule, | ||
], | ||
}) | ||
export class MyModule {} | ||
``` |
3 changes: 3 additions & 0 deletions
3
projects/demo/src/modules/experimental/amount/examples/import/insert-template.md
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,3 @@ | ||
```html | ||
{{ 100000 | tuiAmount : currency : align}} | ||
``` |
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,9 @@ | ||
import {NgModule} from '@angular/core'; | ||
|
||
import {TuiAmountPipePipe} from './amount.pipe'; | ||
|
||
@NgModule({ | ||
declarations: [TuiAmountPipePipe], | ||
exports: [TuiAmountPipePipe], | ||
}) | ||
export class TuiAmountPipeModule {} |
Oops, something went wrong.