Skip to the content

Hata旗

Load a native country or region flag, choose supported framing and keep each drawing’s source, author and licence.

Hata (旗) is Japanese for a flag. About the name

Contents

Reference · /react

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

NameTypeDescription
propsFlagProps & 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

View sourceEdit on GitHubMade from the source of @johnmorrisdotca/hata 1.31.0.