diff --git a/src/Traits/Core/Search/HandlesSearchFieldStyling.php b/src/Traits/Core/Search/HandlesSearchFieldStyling.php new file mode 100644 index 000000000..19956ee01 --- /dev/null +++ b/src/Traits/Core/Search/HandlesSearchFieldStyling.php @@ -0,0 +1,11 @@ +shouldTrimSearchString()) { - $this->search = trim($query); - } else { - $this->search = $query; - } + protected ?bool $searchFilterBlur = null; - return $this; - } + protected ?int $searchFilterDebounce = null; - public function setSearchStatus(bool $status): self - { - $this->searchStatus = $status; + protected ?bool $searchFilterDefer = null; - return $this; - } + protected ?bool $searchFilterLazy = null; - public function setSearchEnabled(): self + protected ?bool $searchFilterLive = null; + + protected ?int $searchFilterThrottle = null; + + public function hasSearchDebounce(): bool { - $this->setSearchStatus(true); + return $this->searchFilterDebounce !== null; + } - return $this; + public function getSearchDebounce(): ?int + { + return $this->searchFilterDebounce; } - /** - * @return $this - */ - public function setSearchDisabled(): self + public function hasSearchDefer(): bool { - $this->setSearchStatus(false); - $this->search = ''; + return $this->searchFilterDefer !== null; + } - return $this; + public function hasSearchLazy(): bool + { + return $this->searchFilterLazy !== null; } - public function setSearchVisibilityStatus(bool $status): self + public function hasSearchLive(): bool { - $this->searchVisibilityStatus = $status; + return $this->searchFilterLive !== null; + } - return $this; + public function hasSearchThrottle(): bool + { + return $this->searchFilterThrottle !== null; } - public function setSearchVisibilityEnabled(): self + public function getSearchThrottle(): ?int { - $this->setSearchVisibilityStatus(true); + return $this->searchFilterThrottle; + } - return $this; + public function hasSearchBlur(): bool + { + return $this->searchFilterBlur !== null; } - public function setSearchVisibilityDisabled(): self + public function getSearchOptions(): string { - $this->setSearchVisibilityStatus(false); + if ($this->hasSearchDebounce()) { + return '.live.debounce.'.$this->getSearchDebounce().'ms'; + } - return $this; + if ($this->hasSearchDefer()) { + return ''; + } + + if ($this->hasSearchLive()) { + return '.live'; + } + + if ($this->hasSearchBlur()) { + return '.blur'; + } + + if ($this->hasSearchLazy()) { + return '.live.lazy'; + } + + if ($this->hasSearchThrottle()) { + return '.live.throttle.'.$this->getSearchThrottle().'ms'; + } + + return '.live'; } /** @@ -146,25 +170,4 @@ public function setSearchLazy(): self return $this; } - - public function setTrimSearchString(bool $status): self - { - $this->trimSearchString = $status; - - return $this; - } - - public function setTrimSearchStringEnabled(): self - { - $this->setTrimSearchString(true); - - return $this; - } - - public function setTrimSearchStringDisabled(): self - { - $this->setTrimSearchString(false); - - return $this; - } } diff --git a/src/Traits/Core/Search/HandlesSearchStatus.php b/src/Traits/Core/Search/HandlesSearchStatus.php new file mode 100644 index 000000000..1f32395f7 --- /dev/null +++ b/src/Traits/Core/Search/HandlesSearchStatus.php @@ -0,0 +1,53 @@ +searchStatus; + } + + #[Computed] + public function searchIsEnabled(): bool + { + return $this->getSearchStatus() === true; + } + + public function searchIsDisabled(): bool + { + return $this->getSearchStatus() === false; + } + + public function setSearchStatus(bool $status): self + { + $this->searchStatus = $status; + + return $this; + } + + public function setSearchEnabled(): self + { + $this->setSearchStatus(true); + + return $this; + } + + /** + * @return $this + */ + public function setSearchDisabled(): self + { + $this->search = ''; + + $this->setSearchStatus(false); + + return $this; + } +} diff --git a/src/Traits/Core/Search/HandlesSearchTrim.php b/src/Traits/Core/Search/HandlesSearchTrim.php new file mode 100644 index 000000000..e4ec6b625 --- /dev/null +++ b/src/Traits/Core/Search/HandlesSearchTrim.php @@ -0,0 +1,34 @@ +trimSearchString ?? false; + } + + public function setTrimSearchString(bool $status): self + { + $this->trimSearchString = $status; + + return $this; + } + + public function setTrimSearchStringEnabled(): self + { + $this->setTrimSearchString(true); + + return $this; + } + + public function setTrimSearchStringDisabled(): self + { + $this->setTrimSearchString(false); + + return $this; + } +} diff --git a/src/Traits/Core/Search/HandlesSearchVisibility.php b/src/Traits/Core/Search/HandlesSearchVisibility.php new file mode 100644 index 000000000..a73ccc9b9 --- /dev/null +++ b/src/Traits/Core/Search/HandlesSearchVisibility.php @@ -0,0 +1,43 @@ +searchVisibilityStatus; + } + + #[Computed] + public function searchVisibilityIsEnabled(): bool + { + return $this->getSearchVisibilityStatus() === true; + } + + public function searchVisibilityIsDisabled(): bool + { + return $this->getSearchVisibilityStatus() === false; + } + + public function setSearchVisibilityStatus(bool $status): self + { + $this->searchVisibilityStatus = $status; + + return $this; + } + + public function setSearchVisibilityEnabled(): self + { + return $this->setSearchVisibilityStatus(true); + } + + public function setSearchVisibilityDisabled(): self + { + return $this->setSearchVisibilityStatus(false); + } +} diff --git a/src/Traits/Styling/Search/HasSearchIcon.php b/src/Traits/Core/Search/Styling/HasSearchIcon.php similarity index 96% rename from src/Traits/Styling/Search/HasSearchIcon.php rename to src/Traits/Core/Search/Styling/HasSearchIcon.php index 3a7cbd656..8133197d2 100644 --- a/src/Traits/Styling/Search/HasSearchIcon.php +++ b/src/Traits/Core/Search/Styling/HasSearchIcon.php @@ -1,6 +1,6 @@ search != ''; - } - - #[Computed] - public function getSearch(): string - { - return $this->search ?? ''; - } - - /** - * Search the search query from the table array - */ - public function clearSearch(): void - { - $this->search = ''; - } - - public function getSearchStatus(): bool - { - return $this->searchStatus; - } - - #[Computed] - public function searchIsEnabled(): bool - { - return $this->getSearchStatus() === true; - } - - public function searchIsDisabled(): bool - { - return $this->getSearchStatus() === false; - } - - public function getSearchVisibilityStatus(): bool - { - return $this->searchVisibilityStatus; - } - - #[Computed] - public function searchVisibilityIsEnabled(): bool - { - return $this->getSearchVisibilityStatus() === true; - } - - public function searchVisibilityIsDisabled(): bool - { - return $this->getSearchVisibilityStatus() === false; - } - - public function hasSearchDebounce(): bool - { - return $this->searchFilterDebounce !== null; - } - - public function getSearchDebounce(): ?int - { - return $this->searchFilterDebounce; - } - - public function hasSearchDefer(): bool - { - return $this->searchFilterDefer !== null; - } - - public function hasSearchLazy(): bool - { - return $this->searchFilterLazy !== null; - } - - public function hasSearchLive(): bool - { - return $this->searchFilterLive !== null; - } - - public function hasSearchThrottle(): bool - { - return $this->searchFilterThrottle !== null; - } - - public function getSearchThrottle(): ?int - { - return $this->searchFilterThrottle; - } - - public function hasSearchBlur(): bool - { - return $this->searchFilterBlur !== null; - } - - public function getSearchOptions(): string - { - if ($this->hasSearchDebounce()) { - return '.live.debounce.'.$this->getSearchDebounce().'ms'; - } - - if ($this->hasSearchDefer()) { - return ''; - } - - if ($this->hasSearchLive()) { - return '.live'; - } - - if ($this->hasSearchBlur()) { - return '.blur'; - } - - if ($this->hasSearchLazy()) { - return '.live.lazy'; - } - - if ($this->hasSearchThrottle()) { - return '.live.throttle.'.$this->getSearchThrottle().'ms'; - } - - return '.live'; - } - - public function shouldTrimSearchString(): bool - { - return $this->trimSearchString ?? false; - } -} diff --git a/src/Traits/Styling/HasSearchFieldStyling.php b/src/Traits/Styling/HasSearchFieldStyling.php deleted file mode 100644 index 01283773e..000000000 --- a/src/Traits/Styling/HasSearchFieldStyling.php +++ /dev/null @@ -1,11 +0,0 @@ -getSearchableColumns(); $search = $this->getSearch(); - if ($this->shouldTrimSearchString()) { - $search = trim($search); - } - $this->callHook('searchUpdated', ['value' => $search]); $this->callTraitHook('searchUpdated', ['value' => $search]); if ($this->getEventStatusSearchApplied() && $search != null) { @@ -90,4 +67,39 @@ public function updatedSearch(string|array|null $value): void $this->clearSearch(); } } + + #[Computed] + public function hasSearch(): bool + { + return $this->search != ''; + } + + #[Computed] + public function getSearch(): string + { + if ($this->shouldTrimSearchString() && $this->search != trim($this->search)) { + $this->search = trim($this->search); + } + + return $this->search ?? ''; + } + + /** + * Search the search query from the table array + */ + public function clearSearch(): void + { + $this->search = ''; + } + + public function setSearch(string $query): self + { + if ($this->shouldTrimSearchString()) { + $this->search = trim($query); + } else { + $this->search = $query; + } + + return $this; + } }