Flagfunction
A flag, drawn inline: a <span role="img"> holding the flag's SVG, with the element's box (its height, proportions, round corners, border and shadow).
It takes the props of <hata-flag> (code, shape, fit, size, width, label, lang, border, shadow, theme, date, variant, which,
allowRestricted) and any other prop of a span. The SVG is part of the HTML, so it is in a server render and a static build: preload the flags
(preloadFlags) for renderToString, which cannot wait; a streaming render waits for them by itself in React 19.
Import it
import { Flag } from "@johnmorrisdotca/hata/react";
Definition
function Flag(props: FlagProps & Omit<React.HTMLAttributes<HTMLSpanElement>, keyof FlagProps | "role" | "dangerouslySetInnerHTML" | "children">): React.ReactElement | null
Parameters
| Name | Type | Description |
|---|---|---|
props | FlagProps & Omit<React.HTMLAttributes<HTMLSpanElement>, "role" | keyof FlagProps | "dangerouslySetInnerHTML" | "children"> | The flag's props, and any span prop. |
Returns
React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | null
A React element, or null when the package has no flag for it.
Examples
import { createElement } from "react";
import { renderToString } from "react-dom/server";
import { Flag, preloadFlags } from "@johnmorrisdotca/hata/react";
await preloadFlags([{ code: "JP-13", shape: "round" }]);
const html = renderToString(createElement(Flag, { code: "JP-13", shape: "round", label: "Tokyo" }));
console.log(html.includes('aria-label="Tokyo"'), html.includes("<svg")); // true true