Skip to content

Commit

Permalink
moved logic to a trait
Browse files Browse the repository at this point in the history
  • Loading branch information
Wiebe Nieuwenhuis committed Apr 11, 2023
1 parent f178f4e commit 0b122c1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 32 deletions.
22 changes: 22 additions & 0 deletions src/Concerns/HasCharacterLimit.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Wiebenieuwenhuis\FilamentCharCounter\Concerns;

trait HasCharacterLimit
{
protected $characterLimit = 0;

public function characterLimit(int $value): self
{
$this->characterLimit = $value;
return $this;
}

public function getCharacterLimit(): int
{
if($this->maxLength){
return $this->maxLength;
}
return $this->characterLimit;
}
}
19 changes: 3 additions & 16 deletions src/TextInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
19 changes: 3 additions & 16 deletions src/Textarea.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}

0 comments on commit 0b122c1

Please sign in to comment.