Flag関数
リファレンスの説明と例は英語です。見出しと目次は日本語です。
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 { Flag } from "@johnmorrisdotca/hata/react";
定義
function Flag(props: FlagProps & Omit<React.HTMLAttributes<HTMLSpanElement>, keyof FlagProps | "role" | "dangerouslySetInnerHTML" | "children">): React.ReactElement | null
引数
| 名前 | 型 | 説明 |
|---|---|---|
props | FlagProps & Omit<React.HTMLAttributes<HTMLSpanElement>, "role" | keyof FlagProps | "dangerouslySetInnerHTML" | "children"> | The flag's props, and any span prop. |
戻り値
React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | null
A React element, or null when the package has no flag for it.
例
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この日本語は、まだ日本語を母語とする方の確認を受けていません。訂正を歓迎します。