Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ fallbackLocale = np;
<Country
code="JP"
renderOption={(code, label) => (
<div className="custom-style">
<div className="custom-render">
<span
className={`flag-icon flag-icon-${code.toLowerCase()} flag-icon-rounded`}
/>
Expand All @@ -250,7 +250,7 @@ fallbackLocale = np;
<Country
code="JP"
renderOption={(code, label) => (
<div className="custom-style">
<div className="custom-render">
<span className={\`flag-icon flag-icon-\${code.toLowerCase()} flag-icon-rounded\`}></span>
<span>{label}</span>
</div>
Expand Down
19 changes: 6 additions & 13 deletions apps/demo/src/assets/css/country.css
Original file line number Diff line number Diff line change
@@ -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;
}
33 changes: 20 additions & 13 deletions packages/ui/src/CountryDisplay/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -45,12 +47,11 @@ export const Country: React.FC<CountryDisplayProperties> = ({
);
}, [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;
}
Expand All @@ -69,16 +70,22 @@ export const Country: React.FC<CountryDisplayProperties> = ({
return <span className={flagClass} title={countryLabel} />;
};

return renderOption && countryCode && countryLabel ? (
renderOption(countryCode, countryLabel)
) : (
<span
className={`country ${className}`.trim()}
return (
<div
className={`country-display ${className}`.trim()}
data-country-code={countryCode}
>
{getFlagElement()}
<span className="country-label">{countryLabel ?? "-"}</span>
</span>
<div className="country-content">
{renderOption && countryCode && countryLabel ? (
renderOption(countryCode, countryLabel)
) : (
<>
{renderFlag()}
<span className="country-label">{countryLabel ?? "-"}</span>
</>
)}
</div>
</div>
);
};

Expand Down
53 changes: 27 additions & 26 deletions packages/ui/src/assets/css/country-display.css
Original file line number Diff line number Diff line change
@@ -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;
}