added shared location selector
This commit is contained in:
@@ -0,0 +1,112 @@
|
||||
<div class="control-card">
|
||||
<h3>Länder/Kontinente vergleichen</h3>
|
||||
|
||||
<div class="comparison-list">
|
||||
@if (comparisonCountries().length > 0 || comparisonRegions().length > 0) {
|
||||
<!-- Countries -->
|
||||
@for (c of comparisonCountries(); track c.id) {
|
||||
<div
|
||||
class="comparison-item location-item"
|
||||
[style.border-color]="getEntityColor()(c.id)"
|
||||
[style.background]="
|
||||
'color-mix(in srgb, ' + getEntityColor()(c.id) + ' 8%, #ffffff)'
|
||||
"
|
||||
[style.color]="getEntityColor()(c.id)">
|
||||
<span class="item-name" [title]="c.name">
|
||||
<mat-icon>flag</mat-icon> {{ c.name }}
|
||||
</span>
|
||||
<div class="item-actions">
|
||||
<button
|
||||
type="button"
|
||||
class="action-btn visibility-btn"
|
||||
(click)="onToggleVisibility(c.id)"
|
||||
[style.color]="getEntityColor()(c.id)"
|
||||
[title]="
|
||||
isVisible()(c.id)
|
||||
? 'In Visualisierung ausblenden'
|
||||
: 'In Visualisierung einblenden'
|
||||
">
|
||||
<mat-icon>{{
|
||||
isVisible()(c.id) ? 'visibility' : 'visibility_off'
|
||||
}}</mat-icon>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="action-btn remove-btn"
|
||||
(click)="onRemove(c.id, 'country')"
|
||||
[style.color]="getEntityColor()(c.id)"
|
||||
aria-label="Land entfernen">
|
||||
<mat-icon>close</mat-icon>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
<!-- Regions / Continents -->
|
||||
@for (r of comparisonRegions(); track r.id) {
|
||||
<div
|
||||
class="comparison-item location-item"
|
||||
[style.border-color]="getEntityColor()(r.id)"
|
||||
[style.background]="
|
||||
'color-mix(in srgb, ' + getEntityColor()(r.id) + ' 8%, #ffffff)'
|
||||
"
|
||||
[style.color]="getEntityColor()(r.id)">
|
||||
<span class="item-name" [title]="r.name">
|
||||
<mat-icon>public</mat-icon> {{ r.name }}
|
||||
</span>
|
||||
<div class="item-actions">
|
||||
<button
|
||||
type="button"
|
||||
class="action-btn visibility-btn"
|
||||
(click)="onToggleVisibility(r.id)"
|
||||
[style.color]="getEntityColor()(r.id)"
|
||||
[title]="
|
||||
isVisible()(r.id)
|
||||
? 'In Visualisierung ausblenden'
|
||||
: 'In Visualisierung einblenden'
|
||||
">
|
||||
<mat-icon>{{
|
||||
isVisible()(r.id) ? 'visibility' : 'visibility_off'
|
||||
}}</mat-icon>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="action-btn remove-btn"
|
||||
(click)="onRemove(r.id, 'continent')"
|
||||
[style.color]="getEntityColor()(r.id)"
|
||||
aria-label="Kontinent entfernen">
|
||||
<mat-icon>close</mat-icon>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
} @else {
|
||||
<div class="empty-list-info">
|
||||
Keine Länder/Kontinente ausgewählt. Suchen zum Hinzufügen.
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<!-- Autocomplete-Suche für Länder/Kontinente -->
|
||||
<div class="autocomplete-search">
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Land oder Kontinent suchen..."
|
||||
[value]="locationQuery()"
|
||||
(input)="onSearchInput($event)" />
|
||||
@if (locationSearchResults().length > 0) {
|
||||
<ul class="autocomplete-results">
|
||||
@for (loc of locationSearchResults(); track loc.id) {
|
||||
<li>
|
||||
<button (click)="onSelectResult(loc)">
|
||||
<span class="name">{{ loc.display_name }}</span>
|
||||
<span class="hint">{{
|
||||
loc.type === 'country' ? 'Land' : 'Kontinent'
|
||||
}}</span>
|
||||
</button>
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,156 @@
|
||||
.control-card {
|
||||
background: white;
|
||||
border-radius: 10px;
|
||||
padding: 1.25rem;
|
||||
border: 1px solid #e5e7eb;
|
||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
|
||||
box-sizing: border-box;
|
||||
|
||||
h3 {
|
||||
font-size: 0.8rem;
|
||||
font-weight: 600;
|
||||
text-transform: uppercase;
|
||||
color: #6b7280;
|
||||
margin: 0 0 0.75rem 0;
|
||||
letter-spacing: 0.05em;
|
||||
}
|
||||
}
|
||||
|
||||
.comparison-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.4rem;
|
||||
max-height: 200px;
|
||||
overflow-y: auto;
|
||||
margin-bottom: 0.75rem;
|
||||
|
||||
.empty-list-info {
|
||||
font-size: 0.75rem;
|
||||
color: #9ca3af;
|
||||
text-align: center;
|
||||
padding: 8px 0;
|
||||
border: 1px dashed #e5e7eb;
|
||||
border-radius: 5px;
|
||||
}
|
||||
}
|
||||
|
||||
.comparison-item {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
border: 1px solid #e5e7eb;
|
||||
border-radius: 5px;
|
||||
padding: 0.3rem 0.5rem;
|
||||
transition: all 0.2s ease;
|
||||
|
||||
.item-name {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
font-size: 0.75rem;
|
||||
font-weight: 600;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
max-width: 170px;
|
||||
|
||||
mat-icon {
|
||||
font-size: 14px;
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
}
|
||||
}
|
||||
|
||||
.item-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.action-btn {
|
||||
background: none;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
padding: 2px;
|
||||
border-radius: 3px;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
transition: all 0.15s ease;
|
||||
|
||||
mat-icon {
|
||||
font-size: 14px;
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
background: rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
&.remove-btn:hover {
|
||||
color: #ef4444 !important;
|
||||
background: #fee2e2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.autocomplete-search {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
|
||||
input {
|
||||
width: 100%;
|
||||
padding: 0.5rem;
|
||||
border-radius: 5px;
|
||||
border: 1px solid #d1d5db;
|
||||
font-size: 0.8125rem;
|
||||
outline: none;
|
||||
box-sizing: border-box;
|
||||
&:focus {
|
||||
border-color: #3b82f6;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.autocomplete-results {
|
||||
position: absolute;
|
||||
top: 100%;
|
||||
left: 0;
|
||||
right: 0;
|
||||
z-index: 50;
|
||||
background: white;
|
||||
border: 1px solid #e5e7eb;
|
||||
border-radius: 5px;
|
||||
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
|
||||
margin-top: 3px;
|
||||
padding: 0;
|
||||
list-style: none;
|
||||
max-height: 180px;
|
||||
overflow-y: auto;
|
||||
|
||||
li button {
|
||||
width: 100%;
|
||||
text-align: left;
|
||||
background: none;
|
||||
border: none;
|
||||
padding: 0.5rem 0.75rem;
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
&:hover {
|
||||
background: #f3f4f6;
|
||||
}
|
||||
|
||||
.name {
|
||||
font-size: 0.75rem;
|
||||
font-weight: 500;
|
||||
color: #1f2937;
|
||||
}
|
||||
.hint {
|
||||
font-size: 0.65rem;
|
||||
color: #9ca3af;
|
||||
margin-top: 1px;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
import { Component, input, output } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { AutocompleteLocationItem } from '../../../api';
|
||||
|
||||
export interface CompareItem {
|
||||
id: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'app-location-selector',
|
||||
standalone: true,
|
||||
imports: [CommonModule, MatIconModule],
|
||||
templateUrl: './location-selector.component.html',
|
||||
styleUrl: './location-selector.component.scss',
|
||||
})
|
||||
export class LocationSelectorComponent {
|
||||
readonly comparisonCountries = input<CompareItem[]>([]);
|
||||
readonly comparisonRegions = input<CompareItem[]>([]);
|
||||
readonly locationQuery = input<string>('');
|
||||
readonly locationSearchResults = input<AutocompleteLocationItem[]>([]);
|
||||
readonly getEntityColor = input<(id: string) => string>(() => '#9ca3af');
|
||||
readonly isVisible = input<(id: string) => boolean>(() => true);
|
||||
|
||||
readonly addLocation = output<AutocompleteLocationItem>();
|
||||
readonly removeLocation = output<{
|
||||
id: string;
|
||||
type: 'country' | 'continent';
|
||||
}>();
|
||||
readonly searchChange = output<string>();
|
||||
readonly toggleVisibility = output<string>();
|
||||
|
||||
onSearchInput(event: Event): void {
|
||||
const val = (event.target as HTMLInputElement).value;
|
||||
this.searchChange.emit(val);
|
||||
}
|
||||
|
||||
onSelectResult(loc: AutocompleteLocationItem): void {
|
||||
this.addLocation.emit(loc);
|
||||
}
|
||||
|
||||
onRemove(id: string, type: 'country' | 'continent'): void {
|
||||
this.removeLocation.emit({ id, type });
|
||||
}
|
||||
|
||||
onToggleVisibility(id: string): void {
|
||||
this.toggleVisibility.emit(id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user