Skip to content

Commit

Permalink
chore(demo): create documentation page Maskito in Real World Form
Browse files Browse the repository at this point in the history
  • Loading branch information
nsbarsukov committed Jun 21, 2024
1 parent 43c2874 commit 90908e1
Show file tree
Hide file tree
Showing 6 changed files with 307 additions and 0 deletions.
7 changes: 7 additions & 0 deletions projects/demo/src/app/app.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,13 @@ export const appRoutes: Routes = [
title: 'Supported <input /> types',
},
},
{
path: DemoPath.RealWorldForm,
loadComponent: () => import('../pages/documentation/real-world-form'),
data: {
title: 'Maskito in Real World Form',
},
},
{
path: DemoPath.Changelog,
loadComponent: () =>
Expand Down
1 change: 1 addition & 0 deletions projects/demo/src/app/constants/demo-path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const DemoPath = {
Placeholder: 'recipes/placeholder',
BrowserSupport: 'browser-support',
SupportedInputTypes: 'supported-input-types',
RealWorldForm: 'real-world-form',
Changelog: 'changelog',
Stackblitz: 'stackblitz',
} as const;
173 changes: 173 additions & 0 deletions projects/demo/src/pages/documentation/real-world-form/index.html
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 projects/demo/src/pages/documentation/real-world-form/index.less
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 projects/demo/src/pages/documentation/real-world-form/index.ts
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);
}
}
6 changes: 6 additions & 0 deletions projects/demo/src/pages/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@ export const DEMO_PAGES: TuiDocPages = [
keywords:
'input, type, text, password, search, tel, url, email, number, date, month',
},
{
section: 'Other',
title: 'Maskito in Real World Form',
route: DemoPath.RealWorldForm,
keywords: 'browser, autofill, showcase, in, action, demo',
},
{
section: 'Other',
title: 'Changelog',
Expand Down

0 comments on commit 90908e1

Please sign in to comment.