UNPKG

@kopexa/sight

Version:

Kopexa Sight Design System — React component library for GRC applications

43 lines (40 loc) 1.45 kB
"use client"; import { getCountryName, toAlpha2 } from "./chunk-FYWJTHFZ.mjs"; // src/components/country-picker/flag-icon.tsx import { useSafeIntl } from "@kopexa/i18n"; import { cn } from "@kopexa/shared-utils"; import { flagIcon } from "@kopexa/theme"; import { Tooltip } from "@kopexa/tooltip"; import * as FlagComponents from "country-flag-icons/react/3x2"; import { jsx } from "react/jsx-runtime"; var flags = FlagComponents; function FlagIcon({ code, size, tooltip, locale, className, "aria-label": ariaLabel, "aria-hidden": ariaHidden }) { var _a; const intl = useSafeIntl(); const resolvedLocale = locale != null ? locale : intl.locale; const a2 = toAlpha2(code); const name = getCountryName(code, resolvedLocale); const label = (_a = ariaLabel != null ? ariaLabel : name) != null ? _a : code; const Flag = a2 ? flags[a2] : void 0; const classes = cn(flagIcon({ size }), className); if (ariaHidden) { return Flag ? /* @__PURE__ */ jsx(Flag, { className: classes, "aria-hidden": true }) : /* @__PURE__ */ jsx("span", { className: classes, "aria-hidden": true }); } const flag = Flag ? /* @__PURE__ */ jsx(Flag, { className: classes, role: "img", "aria-label": label }) : /* @__PURE__ */ jsx("span", { className: classes, role: "img", "aria-label": label }); if (!tooltip || !name) return flag; return /* @__PURE__ */ jsx(Tooltip, { content: name, children: flag }); } export { FlagIcon };