generated from Tinkoff/angular-open-source-starter
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(demo): create documentation page
Maskito in Real World Form
- Loading branch information
1 parent
43c2874
commit 90908e1
Showing
6 changed files
with
307 additions
and
0 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
173 changes: 173 additions & 0 deletions
173
projects/demo/src/pages/documentation/real-world-form/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,173 @@ | ||
<form | ||
#formElement | ||
autocomplete="on" | ||
class="tui-form" | ||
[formGroup]="form" | ||
(ngSubmit)="log(form.value); formElement.submit()" | ||
> | ||
<h3 class="tui-form__header tui-form__header_margin-top_none">Real World Form</h3> | ||
<div class="tui-form__row tui-form__row_multi-fields"> | ||
<tui-input | ||
formControlName="name" | ||
class="tui-form__multi-field" | ||
> | ||
Name | ||
<input | ||
autocomplete="name" | ||
name="name" | ||
placeholder="Only latin letters" | ||
tuiTextfield | ||
[maskito]="nameMask" | ||
/> | ||
</tui-input> | ||
<tui-input | ||
formControlName="surname" | ||
class="tui-form__multi-field" | ||
> | ||
Surname | ||
<input | ||
autocomplete="family-name" | ||
name="surname" | ||
placeholder="Only CAPITAL latin letters" | ||
tuiTextfield | ||
[maskito]="surnameMask" | ||
/> | ||
</tui-input> | ||
</div> | ||
|
||
<div class="tui-form__row"> | ||
<tui-input | ||
formControlName="phone" | ||
[tuiTextfieldCustomContent]="countryIsoCode ? flag : 'tuiIconPhoneLarge'" | ||
> | ||
Enter phone number | ||
<input | ||
autocomplete="tel" | ||
inputmode="tel" | ||
name="phone" | ||
tuiTextfield | ||
[maskito]="phoneMask" | ||
/> | ||
</tui-input> | ||
|
||
<ng-template #flag> | ||
<img | ||
width="28" | ||
[attr.alt]="countryIsoCode" | ||
[src]="countryIsoCode | tuiFlag" | ||
/> | ||
</ng-template> | ||
</div> | ||
|
||
<div class="tui-form__row tui-form__row_multi-fields"> | ||
<tui-input | ||
formControlName="password" | ||
class="tui-form__multi-field" | ||
[tuiTextfieldCustomContent]="showHideIcon" | ||
> | ||
Enter password | ||
<input | ||
autocomplete="new-password" | ||
name="password" | ||
placeholder="Only digits and one latin letter" | ||
tuiTextfield | ||
[maskito]="passwordMask" | ||
[type]="showPassword ? 'password' : 'text'" | ||
/> | ||
</tui-input> | ||
<tui-input | ||
formControlName="repeatedPassword" | ||
class="tui-form__multi-field" | ||
[tuiTextfieldCustomContent]="showHideIcon" | ||
> | ||
Repeat password | ||
<input | ||
autocomplete="new-password" | ||
name="repeatPassword" | ||
placeholder="Only digits and one latin letter" | ||
tuiTextfield | ||
[maskito]="passwordMask" | ||
[type]="showPassword ? 'password' : 'text'" | ||
/> | ||
</tui-input> | ||
|
||
<ng-template #showHideIcon> | ||
<tui-svg | ||
class="password-icon" | ||
[src]="showPassword ? 'tuiIconEyeLarge' : 'tuiIconEyeOffLarge'" | ||
(click)="showPassword = !showPassword" | ||
/> | ||
</ng-template> | ||
</div> | ||
|
||
<div class="tui-form__row tui-form__row_multi-fields"> | ||
<tui-input | ||
formControlName="transactionDate" | ||
tuiTextfieldCustomContent="tuiIconCalendarLarge" | ||
class="tui-form__multi-field" | ||
> | ||
Transaction date | ||
<input | ||
inputmode="decimal" | ||
name="transactionDate" | ||
placeholder="dd.mm.yyyy" | ||
tuiTextfield | ||
[maskito]="transactionDateMask" | ||
/> | ||
</tui-input> | ||
|
||
<tui-input | ||
formControlName="transactionAmount" | ||
class="tui-form__multi-field" | ||
> | ||
Transaction amount | ||
<input | ||
autocomplete="transaction-amount" | ||
inputmode="decimal" | ||
name="transactionAmount" | ||
placeholder="Enter amount" | ||
tuiTextfield | ||
[maskito]="transactionAmountMask" | ||
/> | ||
</tui-input> | ||
</div> | ||
|
||
<div class="tui-form__row"> | ||
<tui-textarea | ||
formControlName="address" | ||
[expandable]="true" | ||
> | ||
Enter address | ||
|
||
<textarea | ||
autocomplete="street-address" | ||
name="address" | ||
placeholder="Only latin letters, digits and some punctuation signs are allowed" | ||
tuiTextfield | ||
[maskito]="addressMask" | ||
></textarea> | ||
</tui-textarea> | ||
</div> | ||
|
||
<div class="tui-form__buttons"> | ||
<button | ||
size="l" | ||
tuiButton | ||
type="submit" | ||
class="tui-form__button" | ||
> | ||
Submit | ||
</button> | ||
|
||
<button | ||
appearance="flat" | ||
size="l" | ||
tuiButton | ||
type="button" | ||
class="tui-form__button" | ||
(click)="form.reset()" | ||
> | ||
Clear all | ||
</button> | ||
</div> | ||
</form> |
16 changes: 16 additions & 0 deletions
16
projects/demo/src/pages/documentation/real-world-form/index.less
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,16 @@ | ||
:host { | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
padding-top: 2rem; | ||
} | ||
|
||
form { | ||
width: 80%; | ||
max-width: 40rem; | ||
} | ||
|
||
.password-icon { | ||
pointer-events: all; | ||
cursor: pointer; | ||
} |
104 changes: 104 additions & 0 deletions
104
projects/demo/src/pages/documentation/real-world-form/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,104 @@ | ||
import {ChangeDetectionStrategy, Component} from '@angular/core'; | ||
import {FormControl, FormGroup, ReactiveFormsModule} from '@angular/forms'; | ||
import {MaskitoDirective} from '@maskito/angular'; | ||
import type {MaskitoOptions} from '@maskito/core'; | ||
import { | ||
maskitoAddOnFocusPlugin, | ||
maskitoDateOptionsGenerator, | ||
maskitoNumberOptionsGenerator, | ||
maskitoRemoveOnBlurPlugin, | ||
} from '@maskito/kit'; | ||
import {maskitoGetCountryFromNumber, maskitoPhoneOptionsGenerator} from '@maskito/phone'; | ||
import { | ||
TuiButtonModule, | ||
TuiFlagPipeModule, | ||
TuiSvgModule, | ||
TuiTextfieldControllerModule, | ||
} from '@taiga-ui/core'; | ||
import {TuiInputModule, TuiTextareaModule} from '@taiga-ui/kit'; | ||
import metadata from 'libphonenumber-js/min/metadata'; | ||
|
||
const MONEY_AMOUNT_MASK = maskitoNumberOptionsGenerator({ | ||
min: 0, | ||
prefix: '$ ', | ||
precision: 2, | ||
}); | ||
|
||
const ONLY_LATIN_LETTERS_RE = /^[a-z]+$/i; | ||
|
||
@Component({ | ||
standalone: true, | ||
selector: 'real-world-form', | ||
imports: [ | ||
ReactiveFormsModule, | ||
TuiInputModule, | ||
TuiButtonModule, | ||
TuiTextfieldControllerModule, | ||
TuiTextareaModule, | ||
MaskitoDirective, | ||
TuiFlagPipeModule, | ||
TuiSvgModule, | ||
], | ||
templateUrl: './index.html', | ||
styleUrls: ['./index.less'], | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export default class RealWorldForm { | ||
protected readonly form = new FormGroup({ | ||
name: new FormControl(''), | ||
surname: new FormControl(''), | ||
phone: new FormControl(''), | ||
password: new FormControl(''), | ||
repeatedPassword: new FormControl(''), | ||
transactionDate: new FormControl(''), | ||
transactionAmount: new FormControl(''), | ||
address: new FormControl(''), | ||
}); | ||
|
||
protected nameMask: MaskitoOptions = { | ||
mask: ONLY_LATIN_LETTERS_RE, | ||
}; | ||
|
||
protected surnameMask: MaskitoOptions = { | ||
mask: ONLY_LATIN_LETTERS_RE, | ||
postprocessors: [ | ||
({value, selection}) => ({selection, value: value.toUpperCase()}), | ||
], | ||
}; | ||
|
||
protected readonly phoneMask = maskitoPhoneOptionsGenerator({ | ||
metadata, | ||
strict: false, | ||
}); | ||
|
||
protected passwordMask: MaskitoOptions = { | ||
mask: /^\d*[a-z]?\d*$/i, | ||
}; | ||
|
||
protected readonly transactionDateMask = maskitoDateOptionsGenerator({ | ||
mode: 'dd/mm/yyyy', | ||
}); | ||
|
||
protected readonly transactionAmountMask: MaskitoOptions = { | ||
...MONEY_AMOUNT_MASK, | ||
plugins: [ | ||
...MONEY_AMOUNT_MASK.plugins, | ||
maskitoAddOnFocusPlugin('$ '), | ||
maskitoRemoveOnBlurPlugin('$ '), | ||
], | ||
}; | ||
|
||
protected readonly addressMask: MaskitoOptions = { | ||
mask: /^[a-z1-9\s.,/]+$/i, | ||
}; | ||
|
||
protected showPassword = false; | ||
|
||
protected get countryIsoCode(): string { | ||
return maskitoGetCountryFromNumber(this.form.value.phone || '', metadata) || ''; | ||
} | ||
|
||
protected log(smth: any): void { | ||
console.info(smth); | ||
} | ||
} |
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