update style

This commit is contained in:
2026-10-07 18:25:55 +03:00
parent 2b4967dd8c
commit 548ba43dc2
24 changed files with 314 additions and 153 deletions
+17 -5
View File
@@ -1,5 +1,5 @@
@if (sheetVisible()) {
<div class="sheet-root">
<div class="sheet-root" [style.--drag-y.px]="dragY()">
<button
class="sheet-root__backdrop"
type="button"
@@ -7,7 +7,18 @@
(click)="dismiss()"
></button>
<section class="sheet" role="dialog" aria-modal="true" aria-labelledby="auth-sheet-title">
<div class="sheet-pop">
<section
class="sheet"
[class.sheet--dragging]="dragging()"
role="dialog"
aria-modal="true"
aria-labelledby="auth-sheet-title"
(pointerdown)="onDragStart($event)"
(pointermove)="onDragMove($event)"
(pointerup)="onDragEnd($event)"
(pointercancel)="onDragEnd($event)"
>
<button
class="sheet__handle"
type="button"
@@ -42,7 +53,7 @@
}
<button
class="sheet__submit"
class="btn sheet__submit"
type="button"
[disabled]="!emailValid() || pending()"
(click)="requestCode()"
@@ -76,7 +87,7 @@
<button
class="sheet__resend"
type="button"
[disabled]="resendSeconds() > 0 || pending()"
[disabled]="secondsLeft() > 0 || pending()"
(click)="resend()"
>
{{ resendLabel() }}
@@ -87,7 +98,7 @@
}
<button
class="sheet__submit"
class="btn sheet__submit"
type="button"
[disabled]="!codeReady() || pending()"
(click)="confirm()"
@@ -97,5 +108,6 @@
<button class="sheet__ghost" type="button" (click)="changeEmail()">Изменить почту</button>
}
</section>
</div>
</div>
}
+46 -23
View File
@@ -1,3 +1,7 @@
:host {
display: contents;
}
.sheet-root {
position: fixed;
z-index: 70;
@@ -13,32 +17,57 @@
border: 0;
background: rgb(8 7 6 / 64%);
cursor: pointer;
opacity: calc(1 - min(var(--drag-y, 0px), 280px) / 280px);
}
.sheet {
.sheet-pop {
position: relative;
z-index: 1;
width: min(100%, 480px);
max-height: min(92dvh, 760px);
overflow: auto;
animation: sheet-in 0.28s ease-out;
}
.sheet {
width: 100%;
max-height: min(92dvh, 760px);
overflow: hidden auto;
padding: 8px 16px calc(16px + env(safe-area-inset-bottom));
border: 1px solid var(--color-border);
border-bottom: 0;
border-radius: 28px 28px 0 0;
background: #1a1815;
animation: sheet-in 0.28s ease-out;
transform: translateY(var(--drag-y, 0px));
transition: transform 0.22s ease-out;
touch-action: pan-y;
}
.sheet--dragging {
overflow: hidden;
transition: none;
touch-action: none;
}
.sheet__handle {
display: block;
width: 100%;
height: 28px;
margin: 0 auto 4px;
padding: 10px 0 12px;
border: 0;
background: transparent;
cursor: grab;
touch-action: none;
}
.sheet__handle::before {
content: '';
display: block;
width: 42px;
height: 4px;
margin: 6px auto 12px;
padding: 0;
border: 0;
margin: 0 auto;
border-radius: 4px;
background: #4a453c;
cursor: pointer;
}
.sheet__lock {
@@ -129,14 +158,19 @@
.sheet__resend {
display: block;
width: 100%;
min-height: 20px;
margin-top: 14px;
padding: 0;
overflow: hidden;
border: 0;
background: none;
color: var(--color-muted);
font: inherit;
font-size: 14px;
font-variant-numeric: tabular-nums;
text-align: center;
white-space: nowrap;
text-overflow: ellipsis;
cursor: pointer;
}
@@ -153,22 +187,7 @@
}
.sheet__submit {
width: 100%;
min-height: 52px;
margin-top: 16px;
border: 0;
border-radius: 16px;
background: var(--color-accent);
color: var(--color-on-accent);
font: inherit;
font-size: 16px;
font-weight: 600;
cursor: pointer;
}
.sheet__submit:disabled {
opacity: 0.45;
cursor: default;
}
.sheet__ghost {
@@ -196,7 +215,11 @@
}
@media (prefers-reduced-motion: reduce) {
.sheet {
.sheet-pop {
animation: none;
}
.sheet {
transition: none;
}
}
+161 -5
View File
@@ -1,6 +1,7 @@
import {
ChangeDetectionStrategy,
Component,
DestroyRef,
ElementRef,
HostListener,
computed,
@@ -13,6 +14,7 @@ import {
import { Store } from '@ngrx/store';
import { Icon } from '../../../shared/icon/icon';
import { RESEND_SECONDS } from '../../../state/gorodar.models';
import {
GorodarActions,
selectAuthCodeRequestId,
@@ -20,12 +22,13 @@ import {
selectAuthError,
selectAuthIntent,
selectAuthPending,
selectAuthResendSeconds,
selectAuthSheetVisible,
selectAuthStep,
} from '../../../state';
const CODE_LENGTH = 6;
const DISMISS_DISTANCE = 120;
const DISMISS_VELOCITY = 0.55;
function emptyDigits(): string[] {
return Array.from({ length: CODE_LENGTH }, () => '');
@@ -40,17 +43,31 @@ function emptyDigits(): string[] {
})
export class AuthSheet {
private readonly store = inject(Store);
private readonly destroyRef = inject(DestroyRef);
private readonly digitFields = viewChildren<ElementRef<HTMLInputElement>>('digit');
private pointerId: number | null = null;
private dragOriginY = 0;
private dragOriginX = 0;
private dragScrollTop = 0;
private dragFromHandle = false;
private dragTracking = false;
private dragMoved = false;
private dragLastY = 0;
private dragLastTime = 0;
private dragVelocity = 0;
private closeTimer = 0;
protected readonly emailDraft = signal('');
protected readonly digits = signal<string[]>(emptyDigits());
protected readonly secondsLeft = signal(0);
protected readonly dragY = signal(0);
protected readonly dragging = signal(false);
protected readonly sheetVisible = this.store.selectSignal(selectAuthSheetVisible);
protected readonly step = this.store.selectSignal(selectAuthStep);
protected readonly email = this.store.selectSignal(selectAuthEmail);
protected readonly error = this.store.selectSignal(selectAuthError);
protected readonly pending = this.store.selectSignal(selectAuthPending);
protected readonly resendSeconds = this.store.selectSignal(selectAuthResendSeconds);
protected readonly intent = this.store.selectSignal(selectAuthIntent);
private readonly codeRequestId = this.store.selectSignal(selectAuthCodeRequestId);
@@ -71,7 +88,7 @@ export class AuthSheet {
});
protected readonly resendLabel = computed(() => {
const seconds = this.resendSeconds();
const seconds = this.secondsLeft();
if (seconds <= 0) {
return 'Отправить код ещё раз';
@@ -106,8 +123,35 @@ export class AuthSheet {
return;
}
requestAnimationFrame(() => this.digitFields()[0]?.nativeElement.focus());
requestAnimationFrame(() =>
this.digitFields()[0]?.nativeElement.focus({ preventScroll: true }),
);
});
effect((onCleanup) => {
const requestId = this.codeRequestId();
if (requestId === 0) {
return;
}
let left = RESEND_SECONDS;
untracked(() => this.secondsLeft.set(left));
const timerId = window.setInterval(() => {
left -= 1;
const next = Math.max(left, 0);
this.secondsLeft.set(next);
if (next === 0) {
window.clearInterval(timerId);
}
}, 1000);
onCleanup(() => window.clearInterval(timerId));
});
this.destroyRef.onDestroy(() => window.clearTimeout(this.closeTimer));
}
protected onEmail(event: Event): void {
@@ -125,7 +169,7 @@ export class AuthSheet {
}
protected resend(): void {
if (this.resendSeconds() > 0 || this.pending()) {
if (this.secondsLeft() > 0 || this.pending()) {
return;
}
@@ -137,9 +181,121 @@ export class AuthSheet {
}
protected dismiss(): void {
window.clearTimeout(this.closeTimer);
this.closeTimer = 0;
this.dragY.set(0);
this.dragging.set(false);
this.store.dispatch(GorodarActions.authSheetDismissed());
}
protected onDragStart(event: PointerEvent): void {
if (!event.isPrimary || event.button !== 0 || !this.canDragFrom(event.target)) {
return;
}
const sheet = event.currentTarget as HTMLElement;
this.pointerId = event.pointerId;
this.dragOriginY = event.clientY;
this.dragOriginX = event.clientX;
this.dragScrollTop = sheet.scrollTop;
this.dragFromHandle = this.isHandle(event.target);
this.dragTracking = false;
this.dragMoved = false;
this.dragLastY = event.clientY;
this.dragLastTime = event.timeStamp;
this.dragVelocity = 0;
}
protected onDragMove(event: PointerEvent): void {
if (event.pointerId !== this.pointerId) {
return;
}
const dy = event.clientY - this.dragOriginY;
const dx = event.clientX - this.dragOriginX;
const sheet = event.currentTarget as HTMLElement;
if (!this.dragTracking) {
if (Math.abs(dy) < 8 && Math.abs(dx) < 8) {
return;
}
const pullingDown = dy > 0 && Math.abs(dy) > Math.abs(dx);
const atTop = this.dragScrollTop <= 0;
if (!pullingDown || (!atTop && !this.dragFromHandle)) {
this.pointerId = null;
return;
}
this.dragTracking = true;
this.dragMoved = true;
this.dragging.set(true);
sheet.setPointerCapture(event.pointerId);
}
const elapsed = event.timeStamp - this.dragLastTime;
if (elapsed > 0) {
this.dragVelocity = (event.clientY - this.dragLastY) / elapsed;
}
this.dragLastY = event.clientY;
this.dragLastTime = event.timeStamp;
this.dragY.set(Math.max(0, dy));
}
protected onDragEnd(event: PointerEvent): void {
if (event.pointerId !== this.pointerId) {
return;
}
const sheet = event.currentTarget as HTMLElement;
const offset = this.dragY();
const close =
event.type !== 'pointercancel' &&
this.dragTracking &&
(offset > DISMISS_DISTANCE || (offset > 48 && this.dragVelocity > DISMISS_VELOCITY));
this.pointerId = null;
this.dragTracking = false;
this.dragging.set(false);
if (this.dragMoved) {
const stopClick = (clickEvent: Event): void => {
clickEvent.preventDefault();
clickEvent.stopPropagation();
};
sheet.addEventListener('click', stopClick, { capture: true, once: true });
this.dragMoved = false;
}
if (!close) {
this.dragY.set(0);
return;
}
this.dragY.set(sheet.getBoundingClientRect().height);
window.clearTimeout(this.closeTimer);
this.closeTimer = window.setTimeout(() => this.dismiss(), 200);
}
private canDragFrom(target: EventTarget | null): boolean {
if (!(target instanceof Element)) {
return true;
}
if (this.isHandle(target)) {
return true;
}
return target.closest('input, textarea, button, a, label') == null;
}
private isHandle(target: EventTarget | null): boolean {
return target instanceof Element && target.closest('.sheet__handle') != null;
}
protected onDigit(index: number, event: Event): void {
const input = event.target as HTMLInputElement;
const value = input.value.replace(/\D/g, '').slice(-1);