From 0a2da365dab7a31e4e54caf91d21c9cc5627fda0 Mon Sep 17 00:00:00 2001 From: Matheus Wichman Date: Fri, 7 Jan 2022 23:35:46 -0300 Subject: [PATCH] Make flags work on Windows --- .../src/renderer/renderCountry.tsx | 36 ++++++++----------- .../src/renderer/renderEditCountry.tsx | 24 ++++++------- .../src/renderer/renderEditCurrency.tsx | 26 ++++++-------- 3 files changed, 36 insertions(+), 50 deletions(-) diff --git a/packages/grid/x-data-grid-generator/src/renderer/renderCountry.tsx b/packages/grid/x-data-grid-generator/src/renderer/renderCountry.tsx index da37aa50c2d0..35907ddbc518 100644 --- a/packages/grid/x-data-grid-generator/src/renderer/renderCountry.tsx +++ b/packages/grid/x-data-grid-generator/src/renderer/renderCountry.tsx @@ -2,16 +2,6 @@ import * as React from 'react'; import Box from '@mui/material/Box'; import { GridRenderCellParams } from '@mui/x-data-grid-pro'; -// ISO 3166-1 alpha-2 -// ⚠️ No support for IE 11 -function countryToFlag(isoCode: string) { - return typeof String.fromCodePoint !== 'undefined' && isoCode - ? isoCode - .toUpperCase() - .replace(/./g, (char) => String.fromCodePoint(char.charCodeAt(0) + 127397)) - : isoCode; -} - interface CountryProps { value: { code: string; @@ -23,18 +13,22 @@ const Country = React.memo(function Country(props: CountryProps) { const { value } = props; return ( - - img': { mr: '4px', - height: '32px', - width: '32px', - fontSize: '28px', - }} - > - {value.code && countryToFlag(value.code)} - + width: '20px', + }, + }} + > + {value.label} diff --git a/packages/grid/x-data-grid-generator/src/renderer/renderEditCountry.tsx b/packages/grid/x-data-grid-generator/src/renderer/renderEditCountry.tsx index cf5105c4e615..e58a9fb3a154 100644 --- a/packages/grid/x-data-grid-generator/src/renderer/renderEditCountry.tsx +++ b/packages/grid/x-data-grid-generator/src/renderer/renderEditCountry.tsx @@ -6,16 +6,6 @@ import Box from '@mui/material/Box'; import { styled } from '@mui/material/styles'; import { COUNTRY_ISO_OPTIONS } from '../services/static-data'; -// ISO 3166-1 alpha-2 -// ⚠️ No support for IE 11 -function countryToFlag(isoCode: string) { - return typeof String.fromCodePoint !== 'undefined' - ? isoCode - .toUpperCase() - .replace(/./g, (char) => String.fromCodePoint(char.charCodeAt(0) + 127397)) - : isoCode; -} - const StyledAutocomplete = styled(Autocomplete)(({ theme }) => ({ [`& .${autocompleteClasses.inputRoot}`]: { ...theme.typography.body2, @@ -56,14 +46,20 @@ function EditCountry(props: GridRenderEditCellParams) { span': { - mr: '10px', - fontSize: '18px', + '& > img': { + mr: 2, + flexShrink: 0, }, }} {...optionProps} > - {countryToFlag(option.code)} + {option.label} )} diff --git a/packages/grid/x-data-grid-generator/src/renderer/renderEditCurrency.tsx b/packages/grid/x-data-grid-generator/src/renderer/renderEditCurrency.tsx index 134323b25806..644139948a78 100644 --- a/packages/grid/x-data-grid-generator/src/renderer/renderEditCurrency.tsx +++ b/packages/grid/x-data-grid-generator/src/renderer/renderEditCurrency.tsx @@ -6,16 +6,6 @@ import Box from '@mui/material/Box'; import { styled } from '@mui/material/styles'; import { CURRENCY_OPTIONS } from '../services/static-data'; -// ISO 3166-1 alpha-2 -// ⚠️ No support for IE 11 -function countryToFlag(isoCode: string) { - return typeof String.fromCodePoint !== 'undefined' - ? isoCode - .toUpperCase() - .replace(/./g, (char) => String.fromCodePoint(char.charCodeAt(0) + 127397)) - : isoCode; -} - const StyledAutocomplete = styled(Autocomplete)(({ theme }) => ({ [`& .${autocompleteClasses.inputRoot}`]: { ...theme.typography.body2, @@ -51,18 +41,24 @@ function EditCurrency(props: GridRenderEditCellParams) { fullWidth open disableClearable - renderOption={(optionProps, option) => ( + renderOption={(optionProps, option: any) => ( span': { - mr: '10px', - fontSize: '18px', + '& > img': { + mr: 2, + flexShrink: 0, }, }} {...optionProps} > - {countryToFlag(String(option).slice(0, -1))} + {option} )}