diff --git a/client/package.json b/client/package.json index 9d575e32..be9555be 100644 --- a/client/package.json +++ b/client/package.json @@ -49,6 +49,7 @@ "class-variance-authority": "^0.6.0", "clsx": "^1.2.1", "cmdk": "0.2.1", + "country-iso-3-to-2": "^1.1.1", "d3-array": "3.2.4", "deck.gl": "8.9.19", "eslint": "8.42.0", diff --git a/client/src/components/flag/index.tsx b/client/src/components/flag/index.tsx new file mode 100644 index 00000000..cd321eb7 --- /dev/null +++ b/client/src/components/flag/index.tsx @@ -0,0 +1,44 @@ +import Image from 'next/image'; + +const DEFAULT_CDN_URL = 'https://cdn.jsdelivr.net/gh/lipis/flag-icons/flags/4x3/'; +const DEFAULT_CDN_SUFFIX = 'svg'; + +interface ImgProps extends React.ImgHTMLAttributes { + cdnSuffix?: string; + cdnUrl?: string; + countryCode: string; + width?: number; + height?: number; + svg?: true; +} + +export type CountryFlagProps = ImgProps; + +export const CountryFlag = ({ + cdnSuffix = DEFAULT_CDN_SUFFIX, + cdnUrl = DEFAULT_CDN_URL, + countryCode, + height = 26.66, + width = 40, + svg = true, + className, +}: CountryFlagProps) => { + if (typeof countryCode !== 'string') { + return null; + } + if (svg) { + const flagUrl = `${cdnUrl}${countryCode.toLowerCase()}.${cdnSuffix}`; + + return ( + {'Flag + ); + } +}; + +export default CountryFlag; diff --git a/client/src/containers/countries/detail/panel.tsx b/client/src/containers/countries/detail/panel.tsx index b8354c03..01284e8e 100644 --- a/client/src/containers/countries/detail/panel.tsx +++ b/client/src/containers/countries/detail/panel.tsx @@ -3,12 +3,12 @@ import { useEffect } from 'react'; import Markdown from 'react-markdown'; -import Flag from 'react-world-flags'; import Image from 'next/image'; import Link from 'next/link'; import { notFound, useParams } from 'next/navigation'; +import getCountryIso2 from 'country-iso-3-to-2'; import { useSetAtom } from 'jotai'; import { X } from 'lucide-react'; import { ArrowLeft, Download, ExternalLink, Info } from 'lucide-react'; @@ -37,6 +37,7 @@ import { usefulLinksCountry } from '@/containers/countries/detail/constants'; import { COLUMNS, CSV_COLUMNS_ORDER } from '@/containers/countries/detail/constants'; import Share from '@/containers/share'; +import CountryFlag from '@/components/flag'; import { Button } from '@/components/ui/button'; import { Dialog, DialogClose, DialogContent, DialogTrigger } from '@/components/ui/dialog'; import ContentLoader from '@/components/ui/loader'; @@ -195,11 +196,13 @@ export default function CountryDetailPanel() {
{data?.data?.attributes?.iso && ( - )}

@@ -220,11 +223,13 @@ export default function CountryDetailPanel() {
{data?.data?.attributes?.iso && ( - )}

{data?.data?.attributes?.name}

diff --git a/client/src/containers/countries/item.tsx b/client/src/containers/countries/item.tsx index 76d32293..2ad552fc 100644 --- a/client/src/containers/countries/item.tsx +++ b/client/src/containers/countries/item.tsx @@ -1,14 +1,16 @@ 'use client'; -import Flag from 'react-world-flags'; - import Link from 'next/link'; +import getCountryIso2 from 'country-iso-3-to-2'; + import { useGetCountryIndicatorFields } from '@/types/generated/country-indicator-field'; import { CountryListResponseDataItem } from '@/types/generated/strapi.schemas'; import { useSyncQueryParams } from '@/hooks/datasets'; +import CountryFlag from '@/components/flag'; + export default function CountryItem({ data }: { data: CountryListResponseDataItem }) { const queryParams = useSyncQueryParams({ bbox: true }); @@ -35,7 +37,15 @@ export default function CountryItem({ data }: { data: CountryListResponseDataIte >
{data.attributes?.iso && ( - + )}

{data.attributes?.name}

diff --git a/client/src/containers/countries/list.tsx b/client/src/containers/countries/list.tsx index a0c0b8b4..5cf43193 100644 --- a/client/src/containers/countries/list.tsx +++ b/client/src/containers/countries/list.tsx @@ -3,16 +3,16 @@ // import { useState } from 'react'; // import { Search, X } from 'lucide-react'; +import { ExternalLink } from 'lucide-react'; import { useGetCountries } from '@/types/generated/country'; -import CountryItem from '@/containers/countries/item'; import { usefulLinksCountriesList } from '@/containers/countries/detail/constants'; +import CountryItem from '@/containers/countries/item'; // import { Input } from '@/components/ui/input'; import ContentLoader from '@/components/ui/loader'; import { ScrollArea } from '@/components/ui/scroll-area'; -import { ExternalLink } from 'lucide-react'; export default function CountriesList() { // const [searchValue, setSearchValue] = useState(null); diff --git a/client/src/containers/projects/stats.tsx b/client/src/containers/projects/stats.tsx index 50a6ba7c..cc9c6178 100644 --- a/client/src/containers/projects/stats.tsx +++ b/client/src/containers/projects/stats.tsx @@ -41,7 +41,7 @@ export default function Stats() { }, } ); - console.log(data); + return ( = 18.17" + }, + "dependencies": { + "country-iso-3-to-2": "^1.1.1" } } diff --git a/yarn.lock b/yarn.lock index 9fa82467..ef183598 100644 --- a/yarn.lock +++ b/yarn.lock @@ -51,6 +51,7 @@ __metadata: class-variance-authority: ^0.6.0 clsx: ^1.2.1 cmdk: 0.2.1 + country-iso-3-to-2: ^1.1.1 cypress: 13.6.4 d3-array: 3.2.4 deck.gl: 8.9.19 @@ -7306,6 +7307,8 @@ __metadata: "afoco@workspace:.": version: 0.0.0-use.local resolution: "afoco@workspace:." + dependencies: + country-iso-3-to-2: ^1.1.1 languageName: unknown linkType: soft @@ -9388,6 +9391,13 @@ __metadata: languageName: node linkType: hard +"country-iso-3-to-2@npm:^1.1.1": + version: 1.1.1 + resolution: "country-iso-3-to-2@npm:1.1.1" + checksum: 2fca9f7beb384cbfa1eb68a8b7dabae03356456a33d15ba899475fb7f73e92e71cfa6907f57d552f47230bba25e053f4f0300d6fab9ccf2a95363f340b6bb925 + languageName: node + linkType: hard + "crc@npm:^3.8.0": version: 3.8.0 resolution: "crc@npm:3.8.0"