Flag browser experience
The flag browser helps visitors find a flag, inspect its available forms, and reuse it in an app. The /docs/flags route explains the flag package and sends visitors to the interactive /collection/flags route, while each flag also has a crawlable detail page. For the wider catalog and package model, see Flag catalog and package.
Flag discovery routes
Documentation route
The documentation route gives the flag system a short entry point for engineers. It explains names, shapes, accessibility, locale use, installation, and licensing, then links to the collection for live search and to each flag's reuse options.
The collection route uses the flag browser instead of the normal icon grid. This keeps the general guide focused on use and gives discovery tasks a dedicated surface.
References: src/…/page.tsx• L7-12 src/…/page.tsx• L73-95 src/…/page.tsx• L122-143
Flag detail route
Each flag has an /icon/<slug> page that connects discovery to use. The page shows flag facts, three image shapes, palette data, package guidance, raw files, and links back to the guide and collection.
References: src/…/page.tsx• L77-147 src/…/page.tsx• L393-410 src/…/flag-facts.tsx• L15-55
Interactive browsing
Browse modes
The browser offers an all-flags view and a language view. The all-flags view supports direct discovery and reuse; the language view places a native language name beside a decorative flag so a flag does not stand in for a language.
The browser keeps a selected flag in the page state. A normal tile link opens the full flag page, while quick view keeps the visitor in the collection.
References: src/…/flags-browser.tsx• L150-163 src/…/flags-browser.tsx• L247-270 src/…/languages-mode.tsx• L19-43
Search and filters
Search accepts names, native names, locale values, ISO codes, numeric codes, emoji, and known aliases. Visitors can narrow results by region or palette color. They can also search for a nearby hex color and set its tolerance.
Results can use 4x3, square, or circle artwork. Visitors can choose a small, medium, or large tile size and sort by name, region, ISO code, or color. The result count and empty state show the effect of the current choices.
References: src/…/flags-browser.tsx• L164-245 src/…/model.ts• L77-110 src/…/model.ts• L144-158
Keyboard browsing
The grid supports keyboard movement without adding every tile action to the tab order. Arrow keys move through the visible results, Home and End move to the first or last result, and short keys star, copy, download, or open quick view for the focused flag.
References: src/…/flags-browser.tsx• L93-124 src/…/flags-browser.tsx• L255-267
Palette experience
Palette presentation
The browser uses each flag's extracted colors to make the palette visible during discovery. A thin color strip appears on tiles and on the flag detail header. The detail view also shows color shares and color values so a visitor can copy a hex value for reuse.
Palette colors support both visual comparison and filtering. A color family counts only when it has enough area in the flag, which avoids treating tiny artwork details as the main color.
References: src/…/palette-bar.tsx• L3-17 src/…/flag-palette.tsx• L8-39 src/…/flag-panel.tsx• L89-110 src/…/config.ts• L9-11
Language experience
Locale flag display
The language view maps supported locale tags to a conventional flag when one is available. It displays the language name in that locale and states which country or region the flag represents. The flag remains decorative, and the text remains the label.
The “Your flag” card uses the visitor's browser language list to make a local suggestion. It does not send that list away, and it offers direct import and SVG copy actions for the suggested flag.
References: src/…/languages-mode.tsx• L8-15 src/…/languages-mode.tsx• L20-39 src/…/your-flag-card.tsx• L10-17 src/…/your-flag-card.tsx• L29-58
Reuse actions
Snippet and file outputs
The detail panel turns a selected flag into common outputs. Visitors can copy a React import, the package install command, an HTML image tag, the flag slug, or the SVG itself. They can also download any of the three shapes or open the full flag page.
These actions connect the visual browser to the separate @thesvg/flags package and to CDN-backed SVG files. The generated output keeps the flag code, shape, and file path aligned so a visitor can move from browsing to use without another lookup.
References: src/…/flag-panel.tsx• L43-87 src/…/flag-tile.tsx• L30-75 src/…/snippets.ts• L1-19
Related flag navigation
Quick view includes other flags from the same region. This gives visitors a useful next step after they inspect one flag without changing the active search or leaving the browser.
References: src/…/flags-browser.tsx• L81-87 src/…/flags-browser.tsx• L126-144 src/…/flag-panel.tsx• L123-136
Browser state
Shareable view state
The browser writes filters, shape, size, sort order, selected flag, and view mode to the URL when URL syncing is enabled. A shared URL takes priority over saved browser preferences, and browser history restores earlier views.
This makes a filtered collection a reusable link rather than a private screen state. The browser also supports an embedded mode that keeps its state out of the page URL.
References: src/…/flags-browser.tsx• L24-68 src/…/model.ts• L77-110
Local preferences
The browser stores display preferences, recently viewed flags, and starred flags in local browser storage. The lists have caps, remove duplicates, and fail back to empty or default values when storage is unavailable or invalid.
Personal browsing data stays on the visitor's device. It does not become part of the flag catalog or the shareable URL.
References: src/…/flags-browser.tsx• L41-55 src/…/flags-browser.tsx• L85-91 src/…/storage.ts• L1-32 src/…/config.ts• L7-8
Search visibility
Flag page metadata
Flag detail pages use flag-specific titles, descriptions, and search terms. The metadata describes the three shapes and the main reuse paths, which helps searches for a country name, code, or flag SVG reach the matching page.
References: src/…/flag-seo.ts• L9-30 src/…/page.tsx• L77-147
Crawlable flag facts
The detail page exposes visible facts and stable links in server-rendered content. It gives search engines and visitors names, codes, regions, languages, raw files, package guidance, and nearby flags without requiring the interactive browser state.
References: src/…/flag-facts.tsx• L15-71 src/…/page.tsx• L393-410
Collection structured data
The flag collection identifies itself as a collection page and publishes a bounded list of flag items. The page can describe the full collection while limiting the structured item list so search metadata stays useful at collection scale.
References: src/…/page.tsx• L20-22 src/…/page.tsx• L91-119
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the browser state keys, URL parsing, and visible controls aligned so shared links restore the same view.
- Keep the three shape names consistent across tile paths, downloads, snippets, detail pages, and package guidance.
- Keep palette extraction, color-family thresholds, and color filters aligned so a displayed palette gives the same filter result.
- Keep locale mappings aligned with the language view and the local “Your flag” suggestion.
- Keep flag metadata, crawlable facts, canonical URLs, and collection structured data aligned with the flag catalog.
- Keep the shared-link precedence over local preferences when changing browser initialization.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| Alias data cannot load | Alias-only queries find no matches, although names and codes still work. | The browser starts with direct tile terms and permits a later search or focus event to request aliases again. |
| Browser storage is blocked or contains bad JSON | Preferences, stars, or recent flags reset for that session. | Storage reads and writes fall back without stopping the browser. |
| Clipboard access fails | A copy action does not place a snippet or SVG on the clipboard. | The panel and suggestion card show a failure status. |
| A locale has no supported flag mapping | The language view cannot show a flag for that locale. | The language name remains the primary concept, and unmapped entries are omitted. |
| Flag metadata and icon data drift | A flag page can lose flag-specific SEO or crawlable facts. | Flag pages resolve both the catalog icon and the flag metadata before rendering flag features. |
Key files
| File | Why to read it |
|---|---|
| src/…/page.tsx | Defines the flag documentation route and its links into the browser and package guide. |
| src/…/page.tsx | Selects the flag browser for the flags collection and supplies collection metadata. |
| src/…/flags-browser.tsx | Shows the main browsing flow, controls, URL state, personal lists, and quick view. |
| src/…/model.ts | Defines the browser state and the relationships between search, filters, colors, and sorting. |
| src/…/flag-panel.tsx | Shows the detail and reuse experience for one selected flag. |
| src/…/languages-mode.tsx | Defines the country-not-language display for locale browsing. |
| src/…/your-flag-card.tsx | Defines the local browser-language suggestion and its reuse actions. |
| src/…/storage.ts | Defines the local-only preference, recent, and starred flag behavior. |
| src/…/snippets.ts | Defines the package, HTML, and component outputs copied from the browser. |
| src/…/flag-seo.ts | Defines flag-specific search metadata for individual pages. |
| src/…/flag-facts.tsx | Defines the visible facts and crawlable links on an individual flag page. |