Laravel Livewire + AlpineJS currency switcher
MIT License
Under the hood, Switcheroo is a single Livewire component with some AlpineJS magic sprinkled on top. The component uses and requires TailwindCss for it's styling, but you're free to change to any other CSS framework or even native CSS if you wish.
This package does not offer any currency conversion features yet.
You can install the package via composer:
composer require heureka-agency/switcheroo
You will also need to install the flag-icons
npm package to display currency flags:
npm install flag-icons
First, publish the Switcheroo config with the following command:
php artisan vendor:publish --tag=switcheroo-config
return [
/**
* Add any currencies you would like to handle with Switcheroo.
* You can select all currencies using \HeurekaAgency\Switcheroo\Enums\Currency::all()
*/
'enabled_currencies' => [
\HeurekaAgency\Switcheroo\Enums\Currency::EUR,
\HeurekaAgency\Switcheroo\Enums\Currency::USD,
\HeurekaAgency\Switcheroo\Enums\Currency::GBP,
],
/**
* Set the default currency of the currency switcher.
*/
'default_currency' => \HeurekaAgency\Switcheroo\Enums\Currency::EUR
];
Make sure to import the Switcheroo CSS in your app.css:
@import "../../vendor/heureka-agency/switcheroo/resources/css/switcheroo.css";
Then simply include the Switcheroo component wherever you'd like:
<livewire:switcheroo::currency-switcher />
Switcheroo sends a single Livewire event every time a currency is selected. You can freely access this event from any other Livewire component or even from Javascript.
#[On('currency-selected')]
public function yourCurrencySwitchHandler(string $currency): void
{
$currency = Currency::from($currency);
// any other business logic
}
The selected currency is also stored in local storage using Alpine.$persist
.
You're free to publish the Switcheroo views to customize the look and feel of the currency switcher:
php artisan vendor:publish --tag=switcheroo-views
Switcheroo is multilingual ready! Not that it has any readable strings to translate, but nonetheless, you can publish the language files using:
php artisan vendor:publish --tag=switcheroo-translations
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.