PluginProbe
Yatra – Travel Booking & Tour Operator Software / 3.0.15
Yatra – Travel Booking & Tour Operator Software v3.0.15
3.0.15 3.0.14 3.0.14.1 3.0.14.2 3.0.12 3.0.13 3.0.11 3.0.10 3.0.9 3.0.8 3.0.7 3.0.6 3.0.5 3.0.5.1 3.0.4 3.0.3 3.0.2.9 3.0.2.7 3.0.2.8 3.0.2.6 trunk 1.0.0 2.0.0 2.0.1 2.0.10 All 83 releases
yatra / resources / js / lib / icons.ts

icons.ts in Yatra – Travel Booking & Tour Operator Software 3.0.15, at resources/js/lib/icons.ts

97 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * Yatra icon library (includes/icons.json, expanded via scripts/sync-lucide-icons-json.mjs)
3 * + helpers for admin UI. Public PHP rendering uses yatra_svg_icon() / yatra_stored_picker_icon_markup().
4 */
5
6 import { createElement } from "react";
7 import type { SVGProps } from "react";
8 import yatraIconsManifest from "@yatra/icons";
9
10 export interface YatraManifestEntry {
11 label: string;
12 category: string;
13 svg: string;
14 }
15
16 export type IconOption = {
17 name: string;
18 label: string;
19 category: string;
20 svg: string;
21 };
22
23 /** @deprecated All string slugs from manifest are valid */
24 export type IconName = string;
25
26 export function getYatraIconManifest(): Record<string, YatraManifestEntry> {
27 return yatraIconsManifest as Record<string, YatraManifestEntry>;
28 }
29
30 export function getIconOptions(): IconOption[] {
31 const m = yatraIconsManifest as Record<string, YatraManifestEntry>;
32 // Some manifest entries only carry `svg` (sync script left them without
33 // label/category). Without defensive defaults, IconPicker's search filter
34 // calls `.toLowerCase()` on undefined and crashes the whole panel.
35 // Derive a readable label from the slug ("hot-air-balloon" → "Hot Air
36 // Balloon") and fall back to a "general" bucket for the category so the
37 // search and category-filter UI still works.
38 const slugToLabel = (slug: string): string =>
39 slug
40 .split(/[-_\s]+/)
41 .filter(Boolean)
42 .map((w) => w.charAt(0).toUpperCase() + w.slice(1))
43 .join(" ");
44 return Object.entries(m).map(([name, meta]) => {
45 const safeMeta = (meta || {}) as Partial<YatraManifestEntry>;
46 return {
47 name,
48 label:
49 typeof safeMeta.label === "string" && safeMeta.label.length > 0
50 ? safeMeta.label
51 : slugToLabel(name),
52 category:
53 typeof safeMeta.category === "string" && safeMeta.category.length > 0
54 ? safeMeta.category
55 : "general",
56 svg: safeMeta.svg || "",
57 };
58 });
59 }
60
61 export function getYatraIconSvg(slug: string): string | null {
62 const m = yatraIconsManifest as Record<string, YatraManifestEntry>;
63 return m[slug]?.svg ?? null;
64 }
65
66 /** @deprecated Prefer getYatraIconSvg + inline SVG; kept for narrow compatibility */
67 export function getIconComponent(): null {
68 return null;
69 }
70
71 export function renderIcon(
72 iconName: string,
73 props: SVGProps<HTMLSpanElement> = {},
74 ): ReturnType<typeof createElement> | null {
75 const svg = getYatraIconSvg(iconName);
76 if (!svg) {
77 return null;
78 }
79 return createElement("span", {
80 ...props,
81 dangerouslySetInnerHTML: { __html: svg },
82 });
83 }
84
85 export async function loadIcons(): Promise<Record<string, YatraManifestEntry>> {
86 return getYatraIconManifest();
87 }
88
89 export default {
90 loadIcons,
91 getIconOptions,
92 getIconComponent,
93 renderIcon,
94 getYatraIconSvg,
95 getYatraIconManifest,
96 };
97