outhebox/blade-flags
Composer 安装命令:
composer require outhebox/blade-flags
包简介
A package to easily make use of country & language flags in your Laravel Blade views.
README 文档
README
Laravel | Vue | React | Vanilla JS | Variants | Contributing
Introduction
1,759 SVG country and language flags for Laravel Blade, Vue, React, and vanilla JavaScript. Three flag styles, 128 language mappings, and full support for regional variants like ar-sa, en-us, and fr-ca. Works great with Inertia.js.
Use them anywhere — locale switchers, address forms, dashboards, or admin panels.
| Variant | Blade | JS import | Countries | Languages | Source |
|---|---|---|---|---|---|
| Default (rounded) | <x-flag-country-us /> |
defaultFlags |
264 | 281 | TwEmoji |
| Circle | <x-flag-circle-country-us /> |
circleFlags |
405 | 275 | circle-flags |
| Flat (4:3) | <x-flag-flat-country-us /> |
flatFlags |
270 | 264 | flag-icons |
For a full list of available icons see the SVG directories: default, circle, flat.
Installation
# Laravel / PHP composer require outhebox/blade-flags # Vue npm install @blade-flags/core @blade-flags/vue # React npm install @blade-flags/core @blade-flags/react # Vanilla JS / Node npm install @blade-flags/core
Laravel / Blade
Requires PHP 8.0+ and Laravel 9+. Uses Blade Icons under the hood — see their readme for caching and additional features.
Watch a 3-minute video by Povilas Korop showcasing the package.
Icons can be used as self-closing Blade components which will be compiled to SVG icons.
Default (Rounded Rectangle)
<x-flag-country-us /> <x-flag-country-gb /> <x-flag-country-br /> <x-flag-country-cn /> <x-flag-country-ru />
<x-flag-language-en /> <x-flag-language-ar /> <x-flag-language-es />
Circle
<x-flag-circle-country-us /> <x-flag-circle-country-gb /> <x-flag-circle-country-br /> <x-flag-circle-country-cn /> <x-flag-circle-country-ru />
<x-flag-circle-language-en /> <x-flag-circle-language-ar /> <x-flag-circle-language-ar-sa /> <x-flag-circle-language-ar-eg />
Flat (4:3 Rectangle)
<x-flag-flat-country-us /> <x-flag-flat-country-gb /> <x-flag-flat-country-br /> <x-flag-flat-country-cn /> <x-flag-flat-country-ru />
<x-flag-flat-language-en /> <x-flag-flat-language-ar /> <x-flag-flat-language-fr />
Classes & Attributes
You can pass classes to any variant:
<x-flag-country-us class="w-6 h-6"/> <x-flag-circle-country-us class="w-6 h-6"/> <x-flag-flat-country-us class="w-6 h-6"/>
Dynamic Icons
For dynamic icon names (e.g. from a database or variable), use the @svg Blade directive:
@svg('flag-country-'.$country->iso2_code) @svg('flag-circle-country-'.$country->iso2_code, 'w-6 h-6') @svg('flag-flat-country-'.$country->iso2_code) @svg('flag-language-'.$language->code) @svg('flag-circle-language-'.$language->code, 'w-6 h-6') @svg('flag-flat-language-'.$language->code)
Or the svg() helper in PHP:
svg('flag-country-us')->toHtml() svg('flag-circle-country-us', 'w-6 h-6')->toHtml()
Raw SVG Icons
Publish the raw SVG files as public assets:
php artisan vendor:publish --tag=blade-flags --force php artisan vendor:publish --tag=blade-flags-circle --force php artisan vendor:publish --tag=blade-flags-flat --force
Then use them in your views:
<img src="{{ asset('vendor/blade-flags/country-us.svg') }}" width="32" height="32"/> <img src="{{ asset('vendor/blade-flags-circle/circle-country-us.svg') }}" width="32" height="32"/> <img src="{{ asset('vendor/blade-flags-flat/flat-country-us.svg') }}" width="32" height="32"/>
Configuration
Blade Flags also offers the ability to use features from Blade Icons like default classes, default attributes, etc. If you'd like to configure these, publish the blade-flags.php config file:
php artisan vendor:publish --tag=blade-flags-config
Language Flag Overrides
By default, language flags use the country mappings defined in config/language-countries.json (e.g. ar → UAE, en → UK). You can override these defaults per-language:
-
Publish the config file:
php artisan vendor:publish --tag=blade-flags-config
-
Edit
config/blade-flags.phpto set your preferred mappings:'language_overrides' => [ 'ar' => ['default' => 'sa'], // Arabic → Saudi Arabia 'en' => ['default' => 'us'], // English → United States ],
-
Publish the SVG assets and apply your overrides:
php artisan vendor:publish --tag=blade-flags --force php artisan vendor:publish --tag=blade-flags-circle --force php artisan vendor:publish --tag=blade-flags-flat --force php artisan blade-flags:generate
The blade-flags:generate command reads the package defaults, merges your overrides, and regenerates the language flag SVGs in the published vendor directories.
Vue
Works with Vue 3.3+. Ideal for Inertia.js apps.
<script setup> import { Flag } from '@blade-flags/vue' import { circleFlags } from '@blade-flags/core/flags/circle' </script> <template> <!-- Dynamic: pass the full map, resolve by code at runtime --> <Flag :code="user.country" :flags="circleFlags" /> <Flag code="ar-sa" type="language" :flags="circleFlags" /> </template>
React
Works with React 18+.
import { Flag } from '@blade-flags/react' import { circleFlags } from '@blade-flags/core/flags/circle' // Dynamic: pass the full map, resolve by code at runtime <Flag code={user.country} flags={circleFlags} /> <Flag code="ar-sa" type="language" flags={circleFlags} />
Vanilla JS
Use @blade-flags/core directly in any JavaScript or TypeScript project:
import { resolveFlag } from '@blade-flags/core' import { circleFlags } from '@blade-flags/core/flags/circle' // Dynamic: resolve by code at runtime (loads all flags in the variant) const svg = resolveFlag(circleFlags, user.country) document.getElementById('flag').innerHTML = svg
Tree-Shaking & Bundle Size
Every flag is a named export. If you know which flags you need at build time, import them directly — your bundler will tree-shake the rest:
// Only the flags you import end up in your bundle import { countryUs, countryGb, languageAr, languageArSa } from '@blade-flags/core/flags/circle'
Flag names follow the pattern country{Code} and language{Code} in camelCase:
| SVG key | Named export | Type |
|---|---|---|
country-us |
countryUs |
Country |
country-gb-eng |
countryGbEng |
Country (region) |
language-ar |
languageAr |
Language |
language-ar-sa |
languageArSa |
Language (regional) |
For dynamic use (code comes from a database or API), import the full variant map. The Flag component uses this approach:
// Loads all flags in the variant — use when the code isn't known at build time import { circleFlags } from '@blade-flags/core/flags/circle' import { resolveFlag } from '@blade-flags/core' const countrySvg = resolveFlag(circleFlags, 'us') // country flag const languageSvg = resolveFlag(circleFlags, 'ar-sa', 'language') // language flag
| Import style | When to use | Bundle impact |
|---|---|---|
import { countryUs } from '.../circle' |
You know the flags at build time | Only the flags you import |
import { circleFlags } from '.../circle' |
Code is dynamic (from data/API) | All flags in the variant |
Flag Variants
Import only the variant you need:
import { defaultFlags } from '@blade-flags/core/flags/default' // 264 country + 281 language import { circleFlags } from '@blade-flags/core/flags/circle' // 405 country + 275 language import { flatFlags } from '@blade-flags/core/flags/flat' // 270 country + 264 language
| Package | Description |
|---|---|
@blade-flags/core |
SVG strings as JS modules + resolveFlag() helper |
@blade-flags/vue |
<Flag> component for Vue 3 (peer dep: vue ^3.3) |
@blade-flags/react |
<Flag> component for React 18+ (peer dep: react ^18 | ^19) |
The AutoFlag convenience component accepts a variant string prop but bundles all variants:
<script setup> import { AutoFlag } from '@blade-flags/vue' </script> <template> <AutoFlag code="us" variant="circle" /> </template>
Disclaimer
This package aims for broad compatibility by mirroring upstream flag collections. Inclusion of any flag does not imply endorsement. The author of this package stands with Palestine (the Palestine flag is featured in the project cover). If you want to exclude specific flags, you can do so in your application/UI, or exclude them during the build via bin/build.sh.
Contributing
Please see CONTRIBUTING for details.
License
Blade Flags is open-sourced software licensed under the MIT license.
outhebox/blade-flags 适用场景与选型建议
outhebox/blade-flags 是一款 基于 TypeScript 开发的 Composer 扩展包,目前已累计 872.28k 次下载、GitHub Stars 达 306, 最近一次更新时间为 2022 年 09 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「flags」 「laravel」 「blade」 「country flags」 「language flags」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 outhebox/blade-flags 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 outhebox/blade-flags 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 outhebox/blade-flags 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
ZF2 module for the Opensoft Rollout library
A PHP trait to enable bitwise comparison of flags
Adds flags support to your model/entity
County and languages flags css
Alfabank REST API integration
Render blade templates into a PSR-7 Response object.
统计信息
- 总下载量: 872.28k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 306
- 点击次数: 16
- 依赖项目数: 5
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-09-21
