This repository has been archived by the owner on Mar 29, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split drop-down and select into different modules with multiple changes
- Loading branch information
Showing
10 changed files
with
333 additions
and
135 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,26 @@ | ||
<!-- This button triggers the overlay and is it's origin --> | ||
<button (click)="toggle()" [class.active]="isOpen" type="button" cdkOverlayOrigin #trigger="cdkOverlayOrigin" | ||
class="border border-gray-400"> | ||
<span *ngIf="currentItem === null"> | ||
Select | ||
</span> | ||
<span *ngIf="currentItem !== null"> | ||
<ng-container *ngTemplateOutlet="currentItem.templateRef"></ng-container> | ||
</span> | ||
<div class="arrow"> | ||
<svg viewBox="0 0 24 24" class="arrow-icon"> | ||
<g fill="none" class="inner"> | ||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2.2" d="M10 16l4-4-4-4" /> | ||
</g> | ||
<div *ngIf="!externalTrigger" class="w-full" cdkOverlayOrigin #trigger="cdkOverlayOrigin" (click)="toggle(trigger)"> | ||
<ng-template [ngTemplateOutlet]="triggerTemplate || defaultTriggerTemplate"></ng-template> | ||
</div> | ||
|
||
<ng-template #defaultTriggerTemplate> | ||
<!-- TODO(ppacher): use a button rather than a div but first fix the button styling --> | ||
<div [class.rounded-b]="!isOpen" | ||
class="flex flex-row items-center justify-between w-full px-4 py-2 mt-6 bg-gray-100 rounded-t cursor-pointer hover:bg-gray-100 hover:bg-opacity-75 text-secondary"> | ||
{{ label }} | ||
|
||
<svg xmlns="http://www.w3.org/2000/svg" class="w-6 h-6" fill="none" viewBox="0 0 24 24" stroke="currentColor" | ||
stroke-width="2"> | ||
<path stroke-linecap="round" stroke-linejoin="round" d="M19 9l-7 7-7-7" /> | ||
</svg> | ||
</div> | ||
</button> | ||
</ng-template> | ||
|
||
<!-- This template displays the overlay content and is connected to the button --> | ||
<ng-template cdkConnectedOverlay [cdkConnectedOverlayMinWidth]="element.nativeElement.offsetWidth" | ||
[cdkConnectedOverlayOrigin]="trigger" [cdkConnectedOverlayOpen]="isOpen" (detach)="onOverlayClosed()" | ||
[cdkConnectedOverlayScrollStrategy]="scrollStrategy" (overlayOutsideClick)="onOutsideClick($event)"> | ||
<ul class="item-list"> | ||
<li *ngFor="let item of items" (click)="selectItem(item)" [sfng-tooltip]="item.description || null" snfgTooltipPosition="left" [class.cursor-not-allowed]="item.disabled"> | ||
<ng-container *ngTemplateOutlet="item.templateRef"></ng-container> | ||
</li> | ||
</ul> | ||
<ng-template cdkConnectedOverlay [cdkConnectedOverlayOffsetY]="offsetY" [cdkConnectedOverlayMinWidth]="minWidth" | ||
[cdkConnectedOverlayMinHeight]="minHeight" [cdkConnectedOverlayOrigin]="trigger!" [cdkConnectedOverlayOpen]="isOpen" | ||
(detach)="onOverlayClosed()" [cdkConnectedOverlayScrollStrategy]="scrollStrategy" | ||
(overlayOutsideClick)="onOutsideClick($event)" [cdkConnectedOverlayPositions]="positions"> | ||
<div class="w-full overflow-hidden bg-gray-200 rounded-b shadow" [style.maxHeight]="maxHeight" | ||
[style.maxWidth]="maxWidth" [@fadeIn] [@fadeOut]> | ||
<ng-content></ng-content> | ||
</div> | ||
</ng-template> |
18 changes: 18 additions & 0 deletions
18
modules/portmaster/src/app/shared/dropdown/dropdown.module.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,18 @@ | ||
import { OverlayModule } from "@angular/cdk/overlay"; | ||
import { CommonModule } from "@angular/common"; | ||
import { NgModule } from "@angular/core"; | ||
import { SfngDropdown } from "./dropdown"; | ||
|
||
@NgModule({ | ||
imports: [ | ||
CommonModule, | ||
OverlayModule, | ||
], | ||
declarations: [ | ||
SfngDropdown, | ||
], | ||
exports: [ | ||
SfngDropdown, | ||
] | ||
}) | ||
export class SfngDropDownModule { } |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './select'; | ||
export * from './item'; | ||
export * from './select.module' |
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<ng-template #customTriggerTemplate> | ||
<button [class.active]="dropdown.isOpen" type="button"> | ||
<span *ngIf="currentItem === null"> | ||
Select | ||
</span> | ||
<span *ngIf="currentItem !== null"> | ||
<ng-container *ngTemplateOutlet="currentItem.templateRef"></ng-container> | ||
</span> | ||
<div class="arrow"> | ||
<svg viewBox="0 0 24 24" class="arrow-icon"> | ||
<g fill="none" class="inner"> | ||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2.2" d="M10 16l4-4-4-4" /> | ||
</g> | ||
</svg> | ||
</div> | ||
</button> | ||
</ng-template> | ||
|
||
<!-- This template displays the overlay content and is connected to the button --> | ||
<sfng-dropdown #dropdown="sfngDropdown" [triggerTemplate]="customTriggerTemplate" class="w-full h-full"> | ||
<ul class="item-list"> | ||
<li *ngFor="let item of items" (click)="selectItem(item)" [sfng-tooltip]="item.description || null" | ||
snfgTooltipPosition="left" [class.cursor-not-allowed]="item.disabled"> | ||
<ng-container *ngTemplateOutlet="item.templateRef"></ng-container> | ||
</li> | ||
</ul> | ||
</sfng-dropdown> |
Oops, something went wrong.