Skip to content

Commit

Permalink
feat(addon-mobile): MobileCalendar switch to dropdown (#7254)
Browse files Browse the repository at this point in the history
Signed-off-by: waterplea <alexander@inkin.ru>
  • Loading branch information
waterplea committed May 8, 2024
1 parent 9ad7c8c commit 33f0e54
Show file tree
Hide file tree
Showing 21 changed files with 246 additions and 126 deletions.
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './mobile-calendar-dialog.component';
export * from './mobile-calendar-dialog.module';
export * from './mobile-calendar-dropdown.component';
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import {NgModule} from '@angular/core';
import {TuiMobileCalendarModule} from '@taiga-ui/addon-mobile/components/mobile-calendar';
import {TuiActiveZoneModule} from '@taiga-ui/cdk';
import {TUI_MOBILE_CALENDAR} from '@taiga-ui/kit';

import {TuiMobileCalendarDialogComponent} from './mobile-calendar-dialog.component';
import {TuiMobileCalendarDropdownComponent} from './mobile-calendar-dropdown.component';

@NgModule({
imports: [TuiMobileCalendarModule],
declarations: [TuiMobileCalendarDialogComponent],
imports: [TuiMobileCalendarModule, TuiActiveZoneModule],
declarations: [TuiMobileCalendarDialogComponent, TuiMobileCalendarDropdownComponent],
providers: [
{
provide: TUI_MOBILE_CALENDAR,
useValue: TuiMobileCalendarDialogComponent,
useValue: TuiMobileCalendarDropdownComponent,
},
],
exports: [TuiMobileCalendarDialogComponent],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import {
ChangeDetectionStrategy,
Component,
HostBinding,
Inject,
Optional,
} from '@angular/core';
import {TuiKeyboardService} from '@taiga-ui/addon-mobile/services';
import {
ALWAYS_FALSE_HANDLER,
TUI_FIRST_DAY,
TUI_LAST_DAY,
TuiActiveZoneDirective,
} from '@taiga-ui/cdk';
import {
TUI_ANIMATIONS_DURATION,
tuiFadeIn,
TuiHostedDropdownComponent,
tuiSlideInTop,
} from '@taiga-ui/core';
import {
TuiInputDateComponent,
TuiInputDateMultiComponent,
TuiInputDateRangeComponent,
} from '@taiga-ui/kit';

@Component({
selector: 'tui-mobile-calendar-dropdown',
templateUrl: './mobile-calendar-dropdown.template.html',
styleUrls: ['./mobile-calendar-dropdown.style.less'],
changeDetection: ChangeDetectionStrategy.OnPush,
animations: [tuiSlideInTop, tuiFadeIn],
})
export class TuiMobileCalendarDropdownComponent {
@HostBinding('@tuiSlideInTop')
@HostBinding('@tuiFadeIn')
readonly animation = {
value: '',
params: {
start: '100vh',
duration: this.duration,
},
} as const;

readonly min =
this.single?.min ||
this.multi?.min ||
this.range?.maxLengthMapper(
this.range.computedMin,
this.range.value,
this.range.maxLength,
true,
) ||
TUI_FIRST_DAY;

readonly max =
this.single?.max ||
this.multi?.max ||
this.range?.maxLengthMapper(
this.range.computedMax,
this.range.value,
this.range.maxLength,
false,
) ||
TUI_LAST_DAY;

readonly disabledItemHandler =
this.single?.disabledItemHandler ||
this.multi?.disabledItemHandler ||
this.range?.disabledItemHandler ||
ALWAYS_FALSE_HANDLER;

constructor(
@Inject(TuiActiveZoneDirective) readonly zone: TuiActiveZoneDirective,
@Inject(TUI_ANIMATIONS_DURATION) private readonly duration: number,
@Optional()
@Inject(TuiInputDateComponent)
readonly single: TuiInputDateComponent | null,
@Optional()
@Inject(TuiInputDateMultiComponent)
readonly multi: TuiInputDateMultiComponent | null,
@Optional()
@Inject(TuiInputDateRangeComponent)
private readonly range: TuiInputDateRangeComponent | null,
@Inject(TuiHostedDropdownComponent)
private readonly dropdown: TuiHostedDropdownComponent,
@Inject(TuiKeyboardService)
private readonly keyboard: TuiKeyboardService,
) {
this.keyboard.hide();
}

close(): void {
this.dropdown.computedHost.focus();
this.dropdown.updateOpen(false);
this.keyboard.show();
}

confirm(value: any): void {
const control = this.single || this.multi || this.range;

if (control) {
control.value = value;
}

this.close();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@import '@taiga-ui/core/styles/taiga-ui-local';

/* stylelint-disable */
:host {
.fullsize(fixed);
background: var(--tui-elevation-01);
box-shadow:
0 10rem var(--tui-elevation-01),
0 -90vh 1rem 2rem rgba(0, 0, 0, 0.75);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<tui-mobile-calendar
tuiActiveZone
[disabledItemHandler]="disabledItemHandler"
[max]="max"
[min]="min"
[multi]="!!multi"
[single]="!!single"
(cancel)="close()"
(confirm)="confirm($event)"
></tui-mobile-calendar>
2 changes: 1 addition & 1 deletion projects/core/animations/animations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ export const tuiSlideInTop = trigger('tuiSlideInTop', [
transition(
':leave',
[
style({transform: 'translate3d(0,{{end}},0)'}),
style({transform: 'translate3d(0,{{end}},0)', pointerEvents: 'none'}),
animate(TRANSITION, style({transform: 'translate3d(0,{{start}},0)'})),
],
{params: {end: 0, start: '100%', duration: 300}},
Expand Down
8 changes: 8 additions & 0 deletions projects/core/styles/mixins/mixins.less
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@import 'browsers';

.interactive(@ruleset) {
// TODO switch to :is after Safari 14 and FF 78 support
&:-webkit-any(a, button, select, textarea, input, label) {
Expand Down Expand Up @@ -132,6 +134,12 @@
appearance: none;
word-break: keep-all;
-webkit-text-fill-color: currentColor; // for Safari

.ios-only({
&:active {
font-size: 1rem;
}
});
}

.visually-hidden() {
Expand Down
8 changes: 8 additions & 0 deletions projects/core/styles/mixins/mixins.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@import 'browsers';

@mixin interactive {
// TODO switch to :is after Safari 14 and FF 78 support
&:-webkit-any(a, button, select, textarea, input) {
Expand Down Expand Up @@ -132,6 +134,12 @@
appearance: none;
word-break: keep-all;
-webkit-text-fill-color: currentColor; // for Safari

@include ios-only {
&:active {
font-size: 1rem;
}
}
}

@mixin visually-hidden() {
Expand Down
4 changes: 4 additions & 0 deletions projects/core/styles/mixins/textfield.less
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@
text-transform: inherit;
resize: none;

&[inputMode='none'] {
caret-color: transparent;
}

/* stylelint-disable */
/* Safari autofill icons */
//noinspection CssInvalidPseudoSelector
Expand Down
4 changes: 4 additions & 0 deletions projects/core/styles/mixins/textfield.scss
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ $line-height-l: 1.25rem;
text-transform: inherit;
resize: none;

&[inputMode='none'] {
caret-color: transparent;
}

/* stylelint-disable */
/* Safari autofill icons */
//noinspection CssInvalidPseudoSelector
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ test.describe('InputDate and mobile user agent', () => {
.locator('tui-input-date-range .t-icons')
.click();

await page.waitForSelector('tui-dialog', {state: 'visible'});
await page.waitForSelector('tui-mobile-calendar-dropdown', {state: 'visible'});
await expect(page).toHaveScreenshot('01-input-date-range-mobile-1.png');

await page.locator(november).nth(0).click();
Expand All @@ -42,7 +42,7 @@ test.describe('InputDate and mobile user agent', () => {
.locator('tui-input-date[multiple] .t-icons')
.click();

await page.waitForSelector('tui-dialog', {state: 'visible'});
await page.waitForSelector('tui-mobile-calendar-dropdown', {state: 'visible'});
await expect(page).toHaveScreenshot('02-input-date-range-mobile-1.png');

await page.locator(november).nth(0).click();
Expand Down Expand Up @@ -72,7 +72,7 @@ test.describe('InputDate and mobile user agent', () => {
.locator('tui-input-date .t-icons')
.click();

await page.waitForSelector('tui-dialog', {state: 'visible'});
await page.waitForSelector('tui-mobile-calendar-dropdown', {state: 'visible'});
await expect(page).toHaveScreenshot('03-input-date-range-mobile-1.png');

await page.locator(november).nth(0).click();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,21 @@
>
Choose a date
</tui-input-date>
<p>
<tui-hosted-dropdown [content]="dropdown">
<button tuiButton>In dropdown</button>
<ng-template
#dropdown
let-activeZone
>
<tui-input-date
formControlName="testValue"
tuiTextfieldSize="l"
[tuiActiveZoneParent]="activeZone"
>
Choose a date
</tui-input-date>
</ng-template>
</tui-hosted-dropdown>
</p>
</form>
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import {FormsModule, ReactiveFormsModule} from '@angular/forms';
import {RouterModule} from '@angular/router';
import {TuiAddonDocModule, tuiGenerateRoutes} from '@taiga-ui/addon-doc';
import {TuiMobileCalendarDialogModule} from '@taiga-ui/addon-mobile';
import {TuiActiveZoneModule} from '@taiga-ui/cdk';
import {
TuiButtonModule,
TuiDropdownModule,
TuiErrorModule,
TuiHintModule,
TuiHostedDropdownModule,
TuiLinkModule,
TuiNotificationModule,
TuiTextfieldControllerModule,
Expand Down Expand Up @@ -50,6 +52,8 @@ import {ExampleTuiInputDateComponent} from './input-date.component';
TuiNotificationModule,
RouterModule.forChild(tuiGenerateRoutes(ExampleTuiInputDateComponent)),
TuiDropdownModule,
TuiHostedDropdownModule,
TuiActiveZoneModule,
],
declarations: [
ExampleTuiInputDateComponent,
Expand Down
1 change: 1 addition & 0 deletions projects/kit/components/accordion/accordion.style.less
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@

.t-group {
display: flex;
align-items: stretch;
}

0 comments on commit 33f0e54

Please sign in to comment.