Skip to content

pennants/react ​

React components. import { Pennant, PennantSvg } from 'pennants/react'.

Interfaces ​

PennantBox ​

CSS box of a pennant, as returned by pennantBox.

Properties ​

PropertyTypeDescription
heightstringCSS height: "<n>px" for numbers, the given length for strings, "1em" by default.
widthstringCSS width, derived from the height with the shape's ratio ("29.333px", "calc(2rem * 66 / 72)").

PennantCommonProps ​

Props shared by Pennant and PennantSvg.

Extended by ​

Properties ​

PropertyTypeDescription
locale?stringLocale used for the default title (via Intl.DisplayNames). Default en.
shape?"pennant" | "rect" | "square" | "circle"Flag shape: pennant (default), rect (4:3), square or circle.
size?PennantSizeHeight (px number or CSS length). Width follows the 66:72 ratio. Default 1em.
title?stringAccessible name. Defaults to the localised flag name. Pass "" to mark the pennant as decorative (aria-hidden, empty alt).

PennantProps ​

Props of Pennant. Other HTML attributes and ref are forwarded.

Extends ​

Properties ​

PropertyTypeDescriptionInherited from
base?stringfetch/img modes: where the package's svg/ folder is served. Default: versioned jsDelivr CDN.-
codePennantCode | Uppercase<PennantCode>Flag code, lowercase or uppercase ("ar", "AR", "gb-eng", "GB-ENG"); normalised with toPennantCode. Unknown codes throw a RangeError.-
decoding?"auto" | "async" | "sync"img mode: image decoding hint. Default async.-
loading?"lazy" | "eager"img mode: native lazy loading. Default lazy.-
locale?stringLocale used for the default title (via Intl.DisplayNames). Default en.PennantCommonProps.locale
mode?"img" | "inline" | "fetch"- inline (default): lazy-loads the flag's bundled artwork chunk and inlines the SVG; - fetch: fetches <base>/svg/<shape>/<code>.svg at runtime and inlines it (no bundled flag data at all); - img: renders an <img> pointing at <base>/svg/<shape>/<code>.svg.-
shape?"pennant" | "rect" | "square" | "circle"Flag shape: pennant (default), rect (4:3), square or circle.PennantCommonProps.shape
size?PennantSizeHeight (px number or CSS length). Width follows the 66:72 ratio. Default 1em.PennantCommonProps.size
title?stringAccessible name. Defaults to the localised flag name. Pass "" to mark the pennant as decorative (aria-hidden, empty alt).PennantCommonProps.title

PennantSvgProps ​

Props of PennantSvg: shared props plus statically imported artwork.

Extends ​

Properties ​

PropertyTypeDescriptionInherited from
artFlagArtFlag artwork, e.g. import ar from 'pennants/art/1x1/ar'. Use the 4x3 set for shape="rect" and 1x1 for the other shapes. Must be trusted.-
locale?stringLocale used for the default title (via Intl.DisplayNames). Default en.PennantCommonProps.locale
shape?"pennant" | "rect" | "square" | "circle"Flag shape: pennant (default), rect (4:3), square or circle.PennantCommonProps.shape
size?PennantSizeHeight (px number or CSS length). Width follows the 66:72 ratio. Default 1em.PennantCommonProps.size
title?stringAccessible name. Defaults to the localised flag name. Pass "" to mark the pennant as decorative (aria-hidden, empty alt).PennantCommonProps.title

Type Aliases ​

PennantHtmlAttributes ​

ts
type PennantHtmlAttributes = Omit<HTMLAttributes<HTMLElement>, "title" | "children" | "dangerouslySetInnerHTML">;

HTML attributes forwarded to the rendered element (title/children/inner HTML are managed).


PennantSize ​

ts
type PennantSize = number | string;

Pennant height: a number of CSS pixels or any CSS length ("2rem").

Variables ​

Pennant ​

ts
const Pennant: ForwardRefExoticComponent<PennantProps & RefAttributes<HTMLElement>>;

Renders a flag (any shape) on the client. Unknown codes or shapes throw a RangeError. Inline/fetch modes keep the box reserved while loading; img mode points at the static SVG asset.


PennantSvg ​

ts
const PennantSvg: ForwardRefExoticComponent<PennantSvgProps & RefAttributes<HTMLSpanElement>>;

Synchronous flag from statically imported artwork: import ar from 'pennants/art/1x1/ar' then <PennantSvg art={ar} shape="circle" />. Uses only useId/useMemo, so it also renders in React Server Components. Throws a RangeError for unknown shapes.

Functions ​

pennantBox() ​

ts
function pennantBox(size?, shape?): PennantBox;

Box size for a given size prop: explicit height, width derived from the shape's aspect ratio (66:72 pennant, 4:3 rect, 1:1 square/circle). Handy to reserve space for a flag outside the components.

Parameters ​

ParameterTypeDefault value
size?PennantSizeundefined
shape?"pennant" | "rect" | "square" | "circle"'pennant'

Returns ​

PennantBox

MIT licensed. Flag artwork from flag-icons (MIT).