diff --git a/apps/demo/src/Views/Ui/components/CountryDisplay/CountryDisplayDemo.tsx b/apps/demo/src/Views/Ui/components/CountryDisplay/CountryDisplayDemo.tsx index 4e1200e2e..a3d612880 100644 --- a/apps/demo/src/Views/Ui/components/CountryDisplay/CountryDisplayDemo.tsx +++ b/apps/demo/src/Views/Ui/components/CountryDisplay/CountryDisplayDemo.tsx @@ -235,7 +235,7 @@ fallbackLocale = np; ( -
+
@@ -250,7 +250,7 @@ fallbackLocale = np; ( -
+
{label}
diff --git a/apps/demo/src/assets/css/country.css b/apps/demo/src/assets/css/country.css index 3f877a2d8..f405bdfad 100644 --- a/apps/demo/src/assets/css/country.css +++ b/apps/demo/src/assets/css/country.css @@ -1,17 +1,10 @@ -.country-wrapper { - display: flex; - flex-direction: column; - gap: 0.25rem; -} - -.custom-style { +.country-display .custom-render { + background-color: #eef2ff; + border: 1px solid var(--border-color, #e2e8f0); + border-radius: 1rem; display: inline-flex; align-items: center; - gap: 8px; - background: #eef2ff; - padding: 4px 12px; - border-radius: 20px; - border: 1px solid #c7d2fe; - color: #3730a3; + gap: 0.5rem; + padding: 0.25rem 1rem; width: 8rem; } diff --git a/packages/ui/src/CountryDisplay/index.tsx b/packages/ui/src/CountryDisplay/index.tsx index bebcb5e9b..8d3c6f546 100644 --- a/packages/ui/src/CountryDisplay/index.tsx +++ b/packages/ui/src/CountryDisplay/index.tsx @@ -4,6 +4,8 @@ import { getFallbackTranslation, getFlagClass } from "../utils/country-picker"; import type { Locales } from "../types"; +import "../assets/css/country-display.css"; + interface CountryDisplayProperties { className?: string; code: string; @@ -45,12 +47,11 @@ export const Country: React.FC = ({ ); }, [countryCode, locale, fallbackLocale, locales]); - const flagClass = useMemo( - () => getFlagClass(countryCode, flagsPosition, flagsStyle), - [countryCode, flagsPosition, flagsStyle], - ); + const flagClass = useMemo(() => { + return getFlagClass(countryCode, flagsPosition, flagsStyle); + }, [countryCode, flagsPosition, flagsStyle]); - const getFlagElement = () => { + const renderFlag = () => { if (!showFlag || !countryCode || countryLabel === countryCode) { return null; } @@ -69,16 +70,22 @@ export const Country: React.FC = ({ return ; }; - return renderOption && countryCode && countryLabel ? ( - renderOption(countryCode, countryLabel) - ) : ( - - {getFlagElement()} - {countryLabel ?? "-"} - +
+ {renderOption && countryCode && countryLabel ? ( + renderOption(countryCode, countryLabel) + ) : ( + <> + {renderFlag()} + {countryLabel ?? "-"} + + )} +
+
); }; diff --git a/packages/ui/src/assets/css/country-display.css b/packages/ui/src/assets/css/country-display.css index 48e16689c..029ef8d9a 100644 --- a/packages/ui/src/assets/css/country-display.css +++ b/packages/ui/src/assets/css/country-display.css @@ -1,41 +1,42 @@ -.country { - align-items: center; - display: inline-flex; - width: 100%; - vertical-align: middle; +.country-display { + max-width: 100%; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; } -.country.is-code-only .flag-icon { - display: none; +.country-display > .country-content { + align-items: center; + display: flex; + gap: 0.5rem; + width: 100%; } -.country-label { - display: block; - flex: 0 1 auto; +.country-display .country-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; - order: 1; } -.country .flag-icon { - margin-right: 0.5rem; - order: 0; - flex-shrink: 0; - background-size: cover; - background-position: center; - min-width: 1.5rem; +.country-display > .country-content:has(.flag-icon-right) { + flex-direction: row-reverse; + justify-content: flex-end; +} + +.country-display > .country-content:has(.flag-icon-right-edge) { + flex-direction: row-reverse; + justify-content: space-between; +} + +.country-display .flag-icon { line-height: inherit; + min-width: 1.5rem; } -.country .flag-icon-right { - margin-right: 0; - margin-left: 0.5rem; - order: 2; +.country-display .flag-icon-rounded { + object-fit: cover; } -.country .flag-icon-right-edge { - margin-right: 0; - margin-left: auto; - order: 2; +.country-display .flag-icon-squared { + border-radius: 0; }