Enhance icon picker UI and usability
This commit is contained in:
committed by
Aditya Chandel
parent
0f6141ad6c
commit
225824b6f5
+12
@@ -0,0 +1,12 @@
|
||||
<input type="text" placeholder="Search icons..." [(ngModel)]="searchText" class="icon-search"/>
|
||||
|
||||
<div class="icon-grid">
|
||||
@for (icon of filteredIcons(); track icon) {
|
||||
<div
|
||||
class="icon-item"
|
||||
(click)="selectIcon(icon)"
|
||||
[class.selected]="icon === selectedIcon">
|
||||
<i [class]="icon"></i>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
import {Component, EventEmitter, inject, Output} from '@angular/core';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
|
||||
@Component({
|
||||
selector: 'app-icon-picker-component',
|
||||
imports: [
|
||||
FormsModule
|
||||
],
|
||||
templateUrl: './icon-picker-component.html',
|
||||
styleUrl: './icon-picker-component.scss'
|
||||
})
|
||||
export class IconPickerComponent {
|
||||
|
||||
iconCategories: string[] = [
|
||||
"address-book", "align-center", "align-justify", "align-left", "align-right", "amazon", "android",
|
||||
"angle-double-down", "angle-double-left", "angle-double-right", "angle-double-up", "angle-down", "angle-left",
|
||||
"angle-right", "angle-up", "apple", "arrow-circle-down", "arrow-circle-left", "arrow-circle-right", "arrow-circle-up",
|
||||
"arrow-down", "arrow-down-left", "arrow-down-left-and-arrow-up-right-to-center", "arrow-down-right", "arrow-left",
|
||||
"arrow-right", "arrow-right-arrow-left", "arrow-up", "arrow-up-left", "arrow-up-right", "arrow-up-right-and-arrow-down-left-from-center",
|
||||
"arrows-alt", "arrows-h", "arrows-v", "asterisk", "at", "backward", "ban", "barcode", "bars", "bell", "bell-slash",
|
||||
"bitcoin", "bolt", "book", "bookmark", "bookmark-fill", "box", "briefcase", "building", "building-columns", "bullseye",
|
||||
"calculator", "calendar", "calendar-clock", "calendar-minus", "calendar-plus", "calendar-times", "camera", "car",
|
||||
"caret-down", "caret-left", "caret-right", "caret-up", "cart-arrow-down", "cart-minus", "cart-plus", "chart-bar",
|
||||
"chart-line", "chart-pie", "chart-scatter", "check", "check-circle", "check-square", "chevron-circle-down",
|
||||
"chevron-circle-left", "chevron-circle-right", "chevron-circle-up", "chevron-down", "chevron-left", "chevron-right",
|
||||
"chevron-up", "circle", "circle-fill", "circle-off", "circle-on", "clipboard", "clock", "clone", "cloud", "cloud-download",
|
||||
"cloud-upload", "code", "cog", "comment", "comments", "compass", "copy", "credit-card", "crown", "database", "delete-left",
|
||||
"desktop", "directions", "directions-alt", "discord", "dollar", "download", "eject", "ellipsis-h", "ellipsis-v",
|
||||
"envelope", "equals", "eraser", "ethereum", "euro", "exclamation-circle", "exclamation-triangle", "expand",
|
||||
"external-link", "eye", "eye-slash", "face-smile", "facebook", "fast-backward", "fast-forward", "file", "file-arrow-up",
|
||||
"file-check", "file-edit", "file-excel", "file-export", "file-import", "file-o", "file-pdf", "file-plus", "file-word",
|
||||
"filter", "filter-fill", "filter-slash", "flag", "flag-fill", "folder", "folder-open", "folder-plus", "forward", "gauge",
|
||||
"gift", "github", "globe", "google", "graduation-cap", "hammer", "hashtag", "headphones", "heart", "heart-fill", "history",
|
||||
"home", "hourglass", "id-card", "image", "images", "inbox", "indian-rupee", "info", "info-circle", "instagram", "key",
|
||||
"language", "lightbulb", "link", "linkedin", "list", "list-check", "lock", "lock-open", "map", "map-marker", "mars", "megaphone",
|
||||
"microchip", "microchip-ai", "microphone", "microsoft", "minus", "minus-circle", "mobile", "money-bill", "moon", "objects-column",
|
||||
"palette", "paperclip", "pause", "pause-circle", "paypal", "pen-to-square", "pencil", "percentage", "phone", "pinterest", "play",
|
||||
"play-circle", "plus", "plus-circle", "pound", "power-off", "prime", "print", "qrcode", "question", "question-circle", "receipt",
|
||||
"reddit", "refresh", "replay", "reply", "save", "search", "search-minus", "search-plus", "send", "server", "share-alt", "shield",
|
||||
"shop", "shopping-bag", "shopping-cart", "sign-in", "sign-out", "sitemap", "slack", "sliders-h", "sliders-v", "sort",
|
||||
"sort-alpha-down", "sort-alpha-down-alt", "sort-alpha-up", "sort-alpha-up-alt", "sort-alt", "sort-alt-slash",
|
||||
"sort-amount-down", "sort-amount-down-alt", "sort-amount-up", "sort-amount-up-alt", "sort-down", "sort-down-fill",
|
||||
"sort-numeric-down", "sort-numeric-down-alt", "sort-numeric-up", "sort-numeric-up-alt", "sort-up", "sort-up-fill", "sparkles",
|
||||
"spinner", "spinner-dotted", "star", "star-fill", "star-half", "star-half-fill", "step-backward", "step-backward-alt",
|
||||
"step-forward", "step-forward-alt", "stop", "stop-circle", "stopwatch", "sun", "sync", "table", "tablet", "tag", "tags",
|
||||
"telegram", "th-large", "thumbs-down", "thumbs-down-fill", "thumbs-up", "thumbs-up-fill", "thumbtack", "ticket", "tiktok",
|
||||
"times", "times-circle", "trash", "trophy", "truck", "turkish-lira", "twitch", "twitter", "undo", "unlock", "upload", "user",
|
||||
"user-edit", "user-minus", "user-plus", "users", "venus", "verified", "video", "vimeo", "volume-down", "volume-off",
|
||||
"volume-up", "wallet", "warehouse", "wave-pulse", "whatsapp", "wifi", "window-maximize", "window-minimize", "wrench",
|
||||
"youtube"
|
||||
];
|
||||
|
||||
searchText: string = '';
|
||||
selectedIcon: string | null = null;
|
||||
icons: string[] = this.createIconList(this.iconCategories);
|
||||
|
||||
ref = inject(DynamicDialogRef);
|
||||
|
||||
createIconList(categories: string[]): string[] {
|
||||
return categories.map(iconName => `pi pi-${iconName}`);
|
||||
}
|
||||
|
||||
filteredIcons(): string[] {
|
||||
if (!this.searchText) return this.icons;
|
||||
return this.icons.filter(icon => icon.toLowerCase().includes(this.searchText.toLowerCase()));
|
||||
}
|
||||
|
||||
selectIcon(icon: string) {
|
||||
this.selectedIcon = icon;
|
||||
this.ref.close(icon);
|
||||
}
|
||||
|
||||
cancel() {
|
||||
this.ref.close();
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
<p-dialog
|
||||
[(visible)]="iconDialogVisible"
|
||||
header="Select an Icon"
|
||||
[modal]="true"
|
||||
[draggable]="false"
|
||||
[style]="{ width: '500px', height: '500px' }">
|
||||
<input type="text" placeholder="Search icons..." [(ngModel)]="searchText" class="icon-search"/>
|
||||
<div class="icon-grid">
|
||||
@for (icon of filteredIcons(); track icon) {
|
||||
<div
|
||||
class="icon-item"
|
||||
(click)="selectIcon(icon)"
|
||||
[class.selected]="icon === selectedIcon">
|
||||
<i [class]="icon"></i>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</p-dialog>
|
||||
@@ -1,78 +0,0 @@
|
||||
import {Component, EventEmitter, Input, Output} from '@angular/core';
|
||||
import {DialogModule} from 'primeng/dialog';
|
||||
|
||||
import {FormsModule} from '@angular/forms';
|
||||
|
||||
@Component({
|
||||
selector: 'app-icon-picker',
|
||||
templateUrl: './icon-picker.component.html',
|
||||
styleUrls: ['./icon-picker.component.scss'],
|
||||
imports: [
|
||||
DialogModule,
|
||||
FormsModule
|
||||
],
|
||||
standalone: true
|
||||
})
|
||||
export class IconPickerComponent {
|
||||
iconCategories: string[] = [
|
||||
"address-book", "align-center", "align-justify", "align-left", "align-right", "android",
|
||||
"angle-double-down", "angle-double-left", "angle-double-right", "angle-double-up", "angle-down", "angle-left",
|
||||
"angle-right", "angle-up", "apple", "arrow-circle-down", "arrow-circle-left", "arrow-circle-right",
|
||||
"arrow-circle-up", "arrow-down-left-and-arrow-up-right-to-center", "arrow-down-left", "arrow-down-right", "arrow-down", "arrow-left",
|
||||
"arrow-right-arrow-left", "arrow-right", "arrow-up-left", "arrow-up-right-and-arrow-down-left-from-center", "arrow-up-right", "arrow-up",
|
||||
"arrows-alt", "arrows-h", "arrows-v", "asterisks", "at", "backward", "ban", "barcode", "bars", "bell-slash", "bell", "bitcoin",
|
||||
"bolt", "book", "bookmark-fill", "bookmark", "box", "briefcase", "building-columns", "building", "bullseye", "calculator", "calendar-clock", "calendar-minus",
|
||||
"calendar-plus", "calendar-times", "calendar", "camera", "car", "caret-down", "caret-left", "caret-right", "caret-up", "cart-arrow-down", "cart-minus", "cart-plus",
|
||||
"chart-bar", "chart-line", "chart-pie", "chart-scatter", "check-circle", "check-square", "check", "chevron-circle-down", "chevron-circle-left", "chevron-circle-right",
|
||||
"chevron-circle-up", "chevron-down", "chevron-left", "chevron-right", "chevron-up", "circle-fill", "circle-off", "circle-on", "circle", "clipboard", "clock", "clone", "cloud-download", "cloud-upload",
|
||||
"cloud", "code", "cog", "comment", "comments", "compass", "copy", "credit-card", "crown", "database", "delete-left", "desktop",
|
||||
"directions-alt", "directions", "discord", "dollar", "download", "eject", "ellipsis-h", "ellipsis-v", "envelope", "equals", "eraser", "ethereum",
|
||||
"euro", "exclamation-circle", "exclamation-triangle", "expand", "external-link", "eye-slash", "eye", "face-smile", "facebook", "fast-backward", "fast-forward", "file-arrow-up",
|
||||
"file-check", "file-edit", "file-excel", "file-export", "file-import", "file-o", "file-pdf", "file-plus", "file-word", "file", "filter-fill", "filter-slash",
|
||||
"filter", "flag-fill", "flag", "folder-open", "folder-plus", "folder", "forward", "gauge", "gift", "github", "globe", "google",
|
||||
"graduation-cap", "hammer", "hashtag", "headphones", "heart-fill", "heart", "history", "home", "hourglass", "id-card", "image", "images",
|
||||
"inbox", "indian-rupee", "info-circle", "info", "instagram", "key", "language", "lightbulb", "link", "linkedin", "list-check", "list",
|
||||
"lock-open", "lock", "map-marker", "map", "mars", "megaphone", "microchip-ai", "microchip", "microphone", "microsoft", "minus-circle", "minus",
|
||||
"mobile", "money-bill", "moon", "objects-column", "palette", "paperclip", "pause-circle", "pause", "paypal", "pen-to-square", "pencil", "percentage",
|
||||
"phone", "pinterest", "play-circle", "play", "plus-circle", "plus", "pound", "power-off", "prime", "print", "qrcode", "question-circle",
|
||||
"question", "receipt", "reddit", "refresh", "replay", "reply", "save", "search-minus", "search-plus", "search", "send", "server",
|
||||
"share-alt", "shield", "shop", "shopping-bag", "shopping-cart", "sign-in", "sign-out", "sitemap", "slack", "sliders-h", "sliders-v", "sort-alpha-alt-down",
|
||||
"sort-alpha-alt-up", "sort-alpha-down", "sort-alpha-up", "sort-alt-slash", "sort-alt", "sort-amount-down-alt", "sort-amount-down", "sort-amount-up-alt",
|
||||
"sort-amount-up", "sort-down-fill", "sort-down", "sort-numeric-alt-down",
|
||||
"sort-numeric-alt-up", "sort-numeric-down", "sort-numeric-up", "sort-up-fill", "sort-up", "sort", "sparkles", "spinner-dotted", "spinner", "star-fill", "star-half-fill", "star-half",
|
||||
"star", "step-backward-alt", "step-backward", "step-forward-alt", "step-forward", "stop-circle", "stop", "stopwatch", "sun", "sync", "table", "tablet",
|
||||
"tag", "tags", "telegram", "th-large", "thumbs-down-fill", "thumbs-down", "thumbs-up-fill", "thumbs-up", "thumbtack", "ticket", "tiktok", "times-circle",
|
||||
"times", "trash", "trophy", "truck", "turkish-lira", "twitch", "twitter", "undo", "unlock", "upload", "user-edit", "user-minus",
|
||||
"user-plus", "user", "users", "venus", "verified", "video", "vimeo", "volume-down", "volume-off", "volume-up", "wallet", "warehouse",
|
||||
"wave-pulse", "whatsapp", "wifi", "window-maximize", "window-minimize", "wrench", "youtube"
|
||||
];
|
||||
|
||||
icons: string[] = this.createIconList(this.iconCategories);
|
||||
iconDialogVisible: boolean = false;
|
||||
searchText: string = '';
|
||||
|
||||
selectedIcon: string | null = null;
|
||||
@Output() iconSelected = new EventEmitter<string>();
|
||||
|
||||
createIconList(categories: string[]): string[] {
|
||||
return categories.map(iconName => `pi pi-${iconName}`);
|
||||
}
|
||||
|
||||
filteredIcons(): string[] {
|
||||
if (!this.searchText) {
|
||||
return this.icons;
|
||||
}
|
||||
return this.icons.filter(icon => icon.toLowerCase().includes(this.searchText.toLowerCase()));
|
||||
}
|
||||
|
||||
open() {
|
||||
this.iconDialogVisible = true;
|
||||
}
|
||||
|
||||
selectIcon(icon: string) {
|
||||
this.selectedIcon = icon;
|
||||
this.iconDialogVisible = false;
|
||||
this.iconSelected.emit(icon);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import { Injectable, inject } from '@angular/core';
|
||||
import { DialogService, DynamicDialogRef } from 'primeng/dynamicdialog';
|
||||
import { IconPickerComponent } from '../component/icon-picker-component/icon-picker-component';
|
||||
import { Observable } from 'rxjs';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class IconPickerService {
|
||||
private dialog = inject(DialogService);
|
||||
|
||||
open(): Observable<string> {
|
||||
const isMobile = window.innerWidth <= 768;
|
||||
const ref: DynamicDialogRef = this.dialog.open(IconPickerComponent, {
|
||||
header: 'Choose an Icon',
|
||||
modal: true,
|
||||
closable: true,
|
||||
style: {
|
||||
position: 'absolute',
|
||||
top: '10%',
|
||||
bottom: '10%',
|
||||
width: isMobile ? '90vw' : '800px',
|
||||
maxWidth: isMobile ? '90vw' : '800px',
|
||||
minWidth: isMobile ? '90vw' : '800px',
|
||||
}
|
||||
});
|
||||
return ref.onClose as Observable<string>;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user