From 0b122c1c50a099902938b9ff9e9efcae1e697e7a Mon Sep 17 00:00:00 2001 From: Wiebe Nieuwenhuis Date: Tue, 11 Apr 2023 11:59:40 +0200 Subject: [PATCH] moved logic to a trait --- src/Concerns/HasCharacterLimit.php | 22 ++++++++++++++++++++++ src/TextInput.php | 19 +++---------------- src/Textarea.php | 19 +++---------------- 3 files changed, 28 insertions(+), 32 deletions(-) create mode 100644 src/Concerns/HasCharacterLimit.php diff --git a/src/Concerns/HasCharacterLimit.php b/src/Concerns/HasCharacterLimit.php new file mode 100644 index 0000000..6239f18 --- /dev/null +++ b/src/Concerns/HasCharacterLimit.php @@ -0,0 +1,22 @@ +characterLimit = $value; + return $this; + } + + public function getCharacterLimit(): int + { + if($this->maxLength){ + return $this->maxLength; + } + return $this->characterLimit; + } +} diff --git a/src/TextInput.php b/src/TextInput.php index c583834..06b9b0e 100644 --- a/src/TextInput.php +++ b/src/TextInput.php @@ -3,24 +3,11 @@ namespace Wiebenieuwenhuis\FilamentCharCounter; use Filament\Forms\Components\TextInput as FilamentTextInput; +use Wiebenieuwenhuis\FilamentCharCounter\Concerns\HasCharacterLimit; class TextInput extends FilamentTextInput { - protected string $view = 'filament-char-counter::text-input'; - - protected $characterLimit = 0; + use HasCharacterLimit; - public function characterLimit(int $value): self - { - $this->characterLimit = $value; - return $this; - } - - public function getCharacterLimit(): int - { - if($this->maxLength){ - return $this->maxLength; - } - return $this->characterLimit; - } + protected string $view = 'filament-char-counter::text-input'; } diff --git a/src/Textarea.php b/src/Textarea.php index e9d9a27..ca03bc9 100644 --- a/src/Textarea.php +++ b/src/Textarea.php @@ -3,24 +3,11 @@ namespace Wiebenieuwenhuis\FilamentCharCounter; use Filament\Forms\Components\Textarea as FilamentTextarea; +use Wiebenieuwenhuis\FilamentCharCounter\Concerns\HasCharacterLimit; class Textarea extends FilamentTextarea { - protected string $view = 'filament-char-counter::textarea'; - - protected $characterLimit = 0; + use HasCharacterLimit; - public function characterLimit(int $value): self - { - $this->characterLimit = $value; - return $this; - } - - public function getCharacterLimit(): int - { - if($this->maxLength){ - return $this->maxLength; - } - return $this->characterLimit; - } + protected string $view = 'filament-char-counter::textarea'; }