diff --git a/ide-helper.stubs.php b/ide-helper.stubs.php index 532ff1a..706f479 100644 --- a/ide-helper.stubs.php +++ b/ide-helper.stubs.php @@ -11,6 +11,13 @@ public function currency(string | Closure | null $currency = null, bool $shouldC return $this; } } + class TextInputColumn + { + public function currencyMask($thousandSeparator = ',', $decimalSeparator = '.', $precision = 2): self + { + return $this; + } + } } namespace Filament\Forms\Components { diff --git a/resources/views/currency-mask.blade.php b/resources/views/currency-mask.blade.php index 65b39dd..1f3dc7f 100644 --- a/resources/views/currency-mask.blade.php +++ b/resources/views/currency-mask.blade.php @@ -1,13 +1,11 @@ @php $datalistOptions = $getDatalistOptions(); $extraAlpineAttributes = $getExtraAlpineAttributes(); + $hasInlineLabel = $hasInlineLabel(); $id = $getId(); $isConcealed = $isConcealed(); $isDisabled = $isDisabled(); - $isLive = $isLive(); - $isLiveOnBlur = $isLiveOnBlur(); - $isLiveDebounced = $isLiveDebounced(); - $liveDebounce = $getLiveDebounce(); + $isPasswordRevealable = $isPasswordRevealable(); $isPrefixInline = $isPrefixInline(); $isSuffixInline = $isSuffixInline(); $mask = $getMask(); @@ -31,21 +29,31 @@ }, updateMasked(){ if(this.input !== undefined && typeof Number(this.input) === 'number') { - if(this.masked?.replaceAll('$thousandSeparator','').replaceAll('$decimalSeparator','.') !== this.input){ + if(this.masked?.toString().replaceAll('$thousandSeparator','').replaceAll('$decimalSeparator','.') !== this.input){ this.masked = this.input?.toString().replaceAll('.','$decimalSeparator'); } } }, updateInput(value, oldValue){ - if(value?.replaceAll('$thousandSeparator','').replaceAll('$decimalSeparator','.') !== oldValue?.replaceAll('$thousandSeparator','').replaceAll('$decimalSeparator','.')){ - this.input = this.masked?.replaceAll('$thousandSeparator','').replaceAll('$decimalSeparator','.'); + if(value?.toString().replaceAll('$thousandSeparator','').replaceAll('$decimalSeparator','.') !== oldValue?.toString().replaceAll('$thousandSeparator','').replaceAll('$decimalSeparator','.')){ + this.input = this.masked?.toString().replaceAll('$thousandSeparator','').replaceAll('$decimalSeparator','.'); } } } JS; @endphp - + + $hasInlineLabel, + ]) + > + {{ $getLabel() }} + merge($getExtraAttributes(), escape: false) + ->class([ + 'fi-ta-text-input', + 'px-3 py-4' => ! $isInline(), + ]) + }} +> + replace(',','') }}" + x-ref="newState" + /> + + + {{-- format-ignore-start --}} + + {{-- format-ignore-end --}} + + diff --git a/src/FilamentCurrencyServiceProvider.php b/src/FilamentCurrencyServiceProvider.php index 4ab9731..d343f98 100644 --- a/src/FilamentCurrencyServiceProvider.php +++ b/src/FilamentCurrencyServiceProvider.php @@ -9,6 +9,7 @@ use Filament\Tables\Columns\Column; use Filament\Tables\Columns\Summarizers; use Filament\Tables\Columns\TextColumn; +use Filament\Tables\Columns\TextInputColumn; use Spatie\LaravelPackageTools\Package; use Spatie\LaravelPackageTools\PackageServiceProvider; @@ -64,7 +65,15 @@ public function bootingPackage(): void return $this; }); + TextInputColumn::macro('currencyMask',function ($thousandSeparator = ',', $decimalSeparator = '.', $precision = 2): TextInputColumn { + /** + * @var TextInput $this + */ + $this->view = 'filament-currency::text-input-column'; + $this->viewData(compact('thousandSeparator', 'decimalSeparator', 'precision')); + return $this; + }); Summarizers\Sum::macro('currency', function (string | Closure | null $currency = null, bool $shouldConvert = false) use ($formatter): Summarizers\Sum { /** * @var Summarizers\Sum $this