本文へ移動

Hata旗

国や地域の旗を読み込み、対応する表示の形を選び、絵ごとの資料・作者・ライセンスを保てます。

「旗(はた)」は、旗を表す日本語です。 名前について(英語)

目次

リファレンス · /react

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

引数

名前型説明
propsFlagProps & 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

ソースを見るGitHub で編集@johnmorrisdotca/hata 1.31.0 のソースから作成しました。

この日本語は、まだ日本語を母語とする方の確認を受けていません。訂正を歓迎します。