From af92c80a0887f50af667996609f5046c00195a69 Mon Sep 17 00:00:00 2001 From: patrickjahr Date: Fri, 19 Apr 2024 08:15:40 +0200 Subject: [PATCH] feat(lib): add style file for users --- .../select-with-style.component.html | 1 + apps/demo-app/src/styles.css | 15 ++++++++------- .../select/directives/overlay.directive.ts | 13 ++++++++++--- .../lib/components/select/select.component.html | 2 ++ .../src/lib/components/select/select.component.ts | 2 ++ 5 files changed, 23 insertions(+), 10 deletions(-) diff --git a/apps/demo-app/src/app/pages/select-sample/select-with-style/select-with-style.component.html b/apps/demo-app/src/app/pages/select-sample/select-with-style/select-with-style.component.html index a7def21..64ab84b 100644 --- a/apps/demo-app/src/app/pages/select-sample/select-with-style/select-with-style.component.html +++ b/apps/demo-app/src/app/pages/select-sample/select-with-style/select-with-style.component.html @@ -6,6 +6,7 @@ [multiple]="multiple()" [animationDelay]="250" [closeOnSelect]="!multiple()" + [panelOffsetY]="10" (open)="showAnimation.set($event)" >
diff --git a/apps/demo-app/src/styles.css b/apps/demo-app/src/styles.css index 8d63845..8f42865 100644 --- a/apps/demo-app/src/styles.css +++ b/apps/demo-app/src/styles.css @@ -1,14 +1,15 @@ -/* TODO: move to lib component*/ -@import '@angular/cdk/overlay-prebuilt.css'; +@import url('@angular/cdk/overlay-prebuilt.css'); /* You can add global styles to this file, and also import other style files */ :root { --sk-top-bar-height: 84px; - --sk-font-family: Montserrat, 'Helevetika Neue', sans-serif; + --sk-font-family: 'Montserrat', 'Helevetika Neue', sans-serif; --sk-primary-color-rgb: 252, 0, 84; --sk-primary-color: rgb(var(--sk-primary-color-rgb)); --sk-secondary-color-rgb: 59, 61, 64; --sk-secondary-color: rgb(var(--sk-secondary-color-rgb)); + --sk-light-color-rgb: 255, 255, 255; + --sk-gray-color-rgb: 59, 61, 64; } * { @@ -20,12 +21,12 @@ html, body { font-family: var(--sk-font-family); - color: rgb(255, 255, 255); - background: rgb(59, 61, 64); + color: rgb(var(--sk-light-color-rgb)); + background: rgb(var(--sk-secondary-color-rgb)); background: linear-gradient( 149deg, - rgba(var(--sk-secondary-color-rgb), 1) 0%, - rgba(var(--sk-primary-color-rgb), 1) 100% + rgb(var(--sk-secondary-color-rgb)) 0%, + rgb(var(--sk-primary-color-rgb)) 100% ); background-repeat: no-repeat; height: 100svh; diff --git a/libs/sketch/src/lib/components/select/directives/overlay.directive.ts b/libs/sketch/src/lib/components/select/directives/overlay.directive.ts index db9ab66..8db97e3 100644 --- a/libs/sketch/src/lib/components/select/directives/overlay.directive.ts +++ b/libs/sketch/src/lib/components/select/directives/overlay.directive.ts @@ -9,7 +9,7 @@ import { import { CdkPortal } from '@angular/cdk/portal'; import { ConnectedPosition, Overlay, OverlayRef } from '@angular/cdk/overlay'; import { DOCUMENT } from '@angular/common'; -import { fromEvent, merge } from 'rxjs'; +import { debounceTime, fromEvent, merge } from 'rxjs'; import { toSignal } from '@angular/core/rxjs-interop'; export const DEFAULT_POSITIONS: ConnectedPosition[] = [ @@ -26,7 +26,7 @@ export class CdkOverlayDirective { private readonly window = inject(DOCUMENT)?.defaultView; private readonly windowResize = this.window - ? toSignal(fromEvent(this.window, 'resize')) + ? toSignal(fromEvent(this.window, 'resize').pipe(debounceTime(500))) : undefined; portal = input(undefined, { alias: 'skCdkOverlay' }); @@ -44,6 +44,12 @@ export class CdkOverlayDirective { panelClass = input('cdk-overlay-panel', { alias: 'skCdkOverlayPanelClass', }); + offsetX = input(0, { + alias: 'skCdkOverlayOffsetX', + }); + offsetY = input(0, { + alias: 'skCdkOverlayOffsetY', + }); visible = output({ alias: 'skCdkOverlayVisible' }); private _overlayRef?: OverlayRef; @@ -76,7 +82,8 @@ export class CdkOverlayDirective { .flexibleConnectedTo(this._relatedElement) .withPositions(this.connectedPositions()) .withPush(true) - .withDefaultOffsetY(10) + .withDefaultOffsetX(this.offsetX()) + .withDefaultOffsetY(this.offsetY()) .withFlexibleDimensions(false); this._overlayRef = this.overlay.create({ diff --git a/libs/sketch/src/lib/components/select/select.component.html b/libs/sketch/src/lib/components/select/select.component.html index a19b3d4..01b67ce 100644 --- a/libs/sketch/src/lib/components/select/select.component.html +++ b/libs/sketch/src/lib/components/select/select.component.html @@ -3,6 +3,8 @@ [skCdkOverlay]="overlay" [skCdkOverlayShow]="panelIsVisible()" [skCdkOverlayDisposeDelay]="animationDelay()" + [skCdkOverlayOffsetX]="panelOffsetX()" + [skCdkOverlayOffsetY]="panelOffsetY()" [tabIndex]="0" (click)="togglePanel(true)" (keydown.enter)="togglePanel(!this.panelIsVisible())" diff --git a/libs/sketch/src/lib/components/select/select.component.ts b/libs/sketch/src/lib/components/select/select.component.ts index c1ce7a1..9d2308f 100644 --- a/libs/sketch/src/lib/components/select/select.component.ts +++ b/libs/sketch/src/lib/components/select/select.component.ts @@ -39,6 +39,8 @@ export class SelectComponent implements ControlValueAccessor { animationDelay = input(0); closeOnSelect = input(false); + panelOffsetX = input(0); + panelOffsetY = input(0); multiple = input(false, { transform: booleanAttribute }); readonly autoFocus = signal(true);