PluginProbe
Yatra – Travel Booking & Tour Operator Software / 3.0.9
Yatra – Travel Booking & Tour Operator Software v3.0.9
3.0.16 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 All 84 releases
yatra / resources / js / components / ui / icon-selector.tsx

icon-selector.tsx in Yatra – Travel Booking & Tour Operator Software 3.0.9, at resources/js/components/ui/icon-selector.tsx

96 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * Renders a stored icon in admin lists: Yatra SVG library (icons.json) or Font Awesome Free (webfont).
3 */
4
5 import React from "react";
6 import { Package } from "lucide-react";
7 import { getYatraIconSvg } from "../../lib/icons";
8 import {
9 FA_REGULAR_NAME_SET,
10 FA_SOLID_NAME_SET,
11 } from "../../lib/fa-free-picker-icons";
12 import type { IconPickerValue } from "../../lib/icon-picker-types";
13
14 export type IconSelectorProvider = "yatra" | "fa-solid" | "fa-regular";
15
16 interface IconSelectorProps {
17 /** Legacy: slug only (Yatra library) */
18 iconName: string;
19 provider?: IconSelectorProvider;
20 className?: string;
21 size?: number;
22 }
23
24 export const IconSelector: React.FC<IconSelectorProps> = ({
25 iconName,
26 provider = "yatra",
27 className = "w-5 h-5",
28 size,
29 }: IconSelectorProps) => {
30 const sizeStyle =
31 size !== undefined
32 ? {
33 fontSize: size,
34 width: size,
35 height: size,
36 lineHeight: 1,
37 display: "inline-flex" as const,
38 alignItems: "center" as const,
39 justifyContent: "center" as const,
40 }
41 : undefined;
42
43 if (provider === "fa-solid" || provider === "fa-regular") {
44 const ok =
45 provider === "fa-regular"
46 ? FA_REGULAR_NAME_SET.has(iconName)
47 : FA_SOLID_NAME_SET.has(iconName);
48 if (ok) {
49 const prefix = provider === "fa-regular" ? "fa-regular" : "fa-solid";
50 return (
51 <i
52 className={`${prefix} fa-${iconName} ${className}`}
53 style={sizeStyle}
54 aria-hidden="true"
55 />
56 );
57 }
58 return <Package className={className} style={sizeStyle} />;
59 }
60
61 const svg = getYatraIconSvg(iconName);
62 if (svg) {
63 return (
64 <span
65 className={`inline-flex items-center justify-center ${className}`}
66 dangerouslySetInnerHTML={{ __html: svg }}
67 style={sizeStyle}
68 />
69 );
70 }
71
72 return <Package className={className} style={sizeStyle} />;
73 };
74
75 /** @deprecated Use getIconOptions() from lib/icons for the full Yatra set */
76 export const availableIcons: Array<{
77 name: string;
78 label: string;
79 }> = [];
80
81 export function iconPickerValueToSelectorProps(
82 val: IconPickerValue | null | undefined,
83 ): { iconName: string; provider: IconSelectorProvider } {
84 if (!val || val.type !== "icon" || !val.value) {
85 return { iconName: "package", provider: "yatra" };
86 }
87 const p = val.provider ?? "yatra";
88 if (p === "fa-solid" || p === "fa-regular") {
89 return { iconName: val.value, provider: p };
90 }
91
92 return { iconName: val.value, provider: "yatra" };
93 }
94
95 export default IconSelector;
96