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
Binary file modified web/e2e/style-guide.e2e.ts-snapshots/desktop-chrome-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified web/e2e/style-guide.e2e.ts-snapshots/phone-chrome-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion web/src/features/players/PlayerHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export async function PlayerHeader({ steamid }: { steamid: string }) {
<h1 className="text-3xl font-bold">{player.name}</h1>
<Flag
code={player.country_code}
className="text-xl"
size="lg"
hint={
isOwn && !player.country_code
? "Your Steam profile has no country. Pick one in your details below, or set one on Steam and it shows here after your next sign-in."
Expand Down
21 changes: 18 additions & 3 deletions web/src/ui/Flag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,28 @@ import { classNames } from "./classNames";

const countryNames = new Intl.DisplayNames(["en"], { type: "region" });

// The 4:3 drawings lose a pixel top and bottom, so stripes stay on whole pixels.
const sizes = {
md: "h-4 w-6 rounded-[2px]",
lg: "h-5.5 w-8 rounded-[3px]",
};

const outline =
"shadow-[0_0_0_1px_color-mix(in_srgb,var(--color-text)_10%,transparent)]";

/**
* flag-icons' stylesheet points at one SVG per country, so a browser downloads only the flags it shows.
* `hint` replaces the tooltip, e.g. to tell a player how to set their country.
*/
export function Flag({
code,
hint,
size = "md",
className,
}: {
code: string | null | undefined;
hint?: string;
size?: keyof typeof sizes;
className?: string;
}) {
const valid = code && /^[A-Z]{2}$/.test(code) ? code : null;
Expand All @@ -29,7 +40,9 @@ export function Flag({
title={hint ? undefined : label}
tabIndex={hint ? 0 : undefined}
className={classNames(
`fi fi-${valid.toLowerCase()} shrink-0 rounded-sm shadow-[0_0_0_1px_var(--color-border-strong)]`,
`fi-${valid.toLowerCase()} inline-block shrink-0 bg-cover bg-center align-middle`,
sizes[size],
outline,
className,
)}
/>
Expand All @@ -41,11 +54,13 @@ export function Flag({
title={hint ? undefined : label}
tabIndex={hint ? 0 : undefined}
className={classNames(
"bg-surface-raised text-text-subtle inline-flex h-[1em] w-[1.333em] shrink-0 items-center justify-center rounded-sm align-middle shadow-[0_0_0_1px_var(--color-border-strong)]",
"bg-surface-raised text-text-subtle inline-flex shrink-0 items-center justify-center align-middle",
sizes[size],
outline,
className,
)}
>
<span aria-hidden className="text-[0.75em] leading-none font-bold">
<span aria-hidden className="text-[10px] leading-none font-bold">
?
</span>
</span>
Expand Down