From 0dda882b98449354378a2d3603c0458093666433 Mon Sep 17 00:00:00 2001 From: Peter Elmered Date: Wed, 17 Jan 2024 14:50:08 +0100 Subject: [PATCH] Update readme + code cleanup --- README.md | 17 +++++++++++++---- config/filament-money-field.php | 2 +- src/Forms/Components/MoneyInput.php | 6 ------ src/MoneyFormattingRules.php | 1 - src/Tables/Columns/MoneyColumn.php | 1 - 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index e3826ae..05ac5d3 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,10 @@ This package would give "1234,56 kr", while most other solutions probably would composer require pelmered/filament-money-field ``` -**Optional: Set the default options for currency and locale so that you don't have to set them for every field.** +## Configuration + +### Set the default currency and locale +**Set the default options for currency and locale so that you don't have to set them for every field.** **Option 1 (Recommended): Put the default options in your .env file.** @@ -32,6 +35,12 @@ MONEY_DEFAULT_CURRENCY=SEK php artisan vendor:publish --provider="Pelmered\FilamentMoneyField\FilamentMoneyFieldServiceProvider" --tag="config" ``` +### If you want to use the formatting mask on the `MoneyInput` component +**This will auto format the input field as you type.** +```php +MONEY_USE_INPUT_MASK=true // Defaults to false +``` + ## Usage ### InfoList @@ -58,13 +67,13 @@ MoneyEntry::make('price') ```php use Filament\Forms\Components\MoneyField; -MoneyField::make('price'); // Defaults to USD and the current Laravel locale, or what you have set in your .env/config. +MoneyInput::make('price'); // Defaults to USD and the current Laravel locale, or what you have set in your .env/config. -MoneyField::make('price') +MoneyInput::make('price') ->currency('USD') ->locale('en_US'); -MoneyField::make('price') +MoneyInput::make('price') ->currency('SEK') ->locale('sv_SE'); ``` diff --git a/config/filament-money-field.php b/config/filament-money-field.php index 72369aa..6386e1b 100644 --- a/config/filament-money-field.php +++ b/config/filament-money-field.php @@ -32,5 +32,5 @@ | The currency code to use if not set on the field. | */ - 'use_input_mask' => env('MONEY_USE_INPUT_MASK', true), + 'use_input_mask' => env('MONEY_USE_INPUT_MASK', false), ]; diff --git a/src/Forms/Components/MoneyInput.php b/src/Forms/Components/MoneyInput.php index a1a91f7..351945f 100644 --- a/src/Forms/Components/MoneyInput.php +++ b/src/Forms/Components/MoneyInput.php @@ -4,10 +4,6 @@ use Filament\Forms\Components\TextInput; use Filament\Support\RawJs; -use Money\Currencies\ISOCurrencies; -use Money\Formatter\IntlMoneyFormatter; -use Money\Money; -use NumberFormatter; use Pelmered\FilamentMoneyField\hasMoneyAttributes; use Pelmered\FilamentMoneyField\MoneyFormatter; @@ -37,7 +33,6 @@ protected function setUp(): void }); $this->dehydrateStateUsing(static function (MoneyInput $component, $state): string { - $formattingRules = MoneyFormatter::getFormattingRules($component->getLocale()); if($formattingRules->decimalSeparator === ',') { @@ -46,6 +41,5 @@ protected function setUp(): void return (int) ($state*100); }); - } } diff --git a/src/MoneyFormattingRules.php b/src/MoneyFormattingRules.php index 1754563..3539a18 100644 --- a/src/MoneyFormattingRules.php +++ b/src/MoneyFormattingRules.php @@ -3,7 +3,6 @@ class MoneyFormattingRules { - public function __construct( public string $currencySymbol, public int $fractionDigits, diff --git a/src/Tables/Columns/MoneyColumn.php b/src/Tables/Columns/MoneyColumn.php index 067da86..f88373e 100644 --- a/src/Tables/Columns/MoneyColumn.php +++ b/src/Tables/Columns/MoneyColumn.php @@ -4,7 +4,6 @@ use Filament\Tables\Columns\TextColumn; use Pelmered\FilamentMoneyField\hasMoneyAttributes; -use Pelmered\FilamentMoneyField\Infolists\Components\MoneyEntry; use Pelmered\FilamentMoneyField\MoneyFormatter; class MoneyColumn extends TextColumn