Skip to content

Commit

Permalink
Update readme + code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
pelmered committed Jan 17, 2024
1 parent b9ca6fa commit 0dda882
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 13 deletions.
17 changes: 13 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.**

Expand All @@ -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
Expand All @@ -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');
```
Expand Down
2 changes: 1 addition & 1 deletion config/filament-money-field.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
];
6 changes: 0 additions & 6 deletions src/Forms/Components/MoneyInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -37,7 +33,6 @@ protected function setUp(): void
});

$this->dehydrateStateUsing(static function (MoneyInput $component, $state): string {

$formattingRules = MoneyFormatter::getFormattingRules($component->getLocale());

if($formattingRules->decimalSeparator === ',') {
Expand All @@ -46,6 +41,5 @@ protected function setUp(): void

return (int) ($state*100);
});

}
}
1 change: 0 additions & 1 deletion src/MoneyFormattingRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

class MoneyFormattingRules
{

public function __construct(
public string $currencySymbol,
public int $fractionDigits,
Expand Down
1 change: 0 additions & 1 deletion src/Tables/Columns/MoneyColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0dda882

Please sign in to comment.