Flag.tsx 732 B

123456789101112131415161718192021222324
  1. import { IconWorld } from "@tabler/icons-react";
  2. import { hasFlag } from "country-flag-icons";
  3. // @ts-expect-error Creating a typing for a subfolder is not easily possible
  4. import Flags from "country-flag-icons/react/3x2";
  5. interface FlagProps {
  6. className?: string;
  7. countryCode: string;
  8. }
  9. function Flag({ className, countryCode }: FlagProps) {
  10. countryCode = countryCode.toUpperCase();
  11. if (countryCode === "EN") {
  12. return <IconWorld className={className} width={20} />;
  13. }
  14. if (hasFlag(countryCode)) {
  15. const FlagElement = Flags[countryCode] as any;
  16. return <FlagElement title={countryCode} className={className} width={20} />;
  17. }
  18. console.error(`No flag for country ${countryCode} found!`);
  19. return null;
  20. }
  21. export { Flag };