From 564c2f076524599f542c9d49921197a5dcdd8886 Mon Sep 17 00:00:00 2001 From: Joe <104938042+lrljoe@users.noreply.github.com> Date: Fri, 22 Nov 2024 20:04:27 +0000 Subject: [PATCH 1/6] Columns() Setup Improvements (#2089) * Initial Commit * Fix styling * Clean Up Commented Code * Fix styling --------- Co-authored-by: lrljoe --- .../Configuration/ColumnConfiguration.php | 38 +------- src/Traits/Helpers/ColumnHelpers.php | 94 +++++++------------ src/Traits/WithColumns.php | 22 +---- 3 files changed, 41 insertions(+), 113 deletions(-) diff --git a/src/Traits/Configuration/ColumnConfiguration.php b/src/Traits/Configuration/ColumnConfiguration.php index c6bbb42d8..29bfadabd 100644 --- a/src/Traits/Configuration/ColumnConfiguration.php +++ b/src/Traits/Configuration/ColumnConfiguration.php @@ -8,44 +8,14 @@ trait ColumnConfiguration { public function setPrependedColumns(array $prependedColumns): void { - $this->prependedColumns = collect($prependedColumns) - ->filter(fn ($column) => $column instanceof Column) - ->map(function (Column $column) { - $column->setTheme($this->getTheme()); - $column->setHasTableRowUrl($this->hasTableRowUrl()); - $column->setIsReorderColumn($this->getDefaultReorderColumn() == $column->getField()); - - if ($column->hasField()) { - if ($column->isBaseColumn()) { - $column->setTable($this->getBuilder()->getModel()->getTable()); - } else { - $column->setTable($this->getTableForColumn($column)); - } - } - - return $column; - }); + $this->prependedColumns = collect($prependedColumns); + $this->hasRunColumnSetup = false; } public function setAppendedColumns(array $appendedColumns): void { - $this->appendedColumns = collect($appendedColumns) - ->filter(fn ($column) => $column instanceof Column) - ->map(function (Column $column) { - $column->setTheme($this->getTheme()); - $column->setHasTableRowUrl($this->hasTableRowUrl()); - $column->setIsReorderColumn($this->getDefaultReorderColumn() == $column->getField()); - - if ($column->hasField()) { - if ($column->isBaseColumn()) { - $column->setTable($this->getBuilder()->getModel()->getTable()); - } else { - $column->setTable($this->getTableForColumn($column)); - } - } - - return $column; - }); + $this->appendedColumns = collect($appendedColumns); + $this->hasRunColumnSetup = false; } public function unsetCollapsedStatuses(): void diff --git a/src/Traits/Helpers/ColumnHelpers.php b/src/Traits/Helpers/ColumnHelpers.php index 16a84a3dc..487bcb879 100644 --- a/src/Traits/Helpers/ColumnHelpers.php +++ b/src/Traits/Helpers/ColumnHelpers.php @@ -13,14 +13,19 @@ trait ColumnHelpers */ public function setColumns(): void { - $this->prependedColumns = $this->getPrependedColumns(); + $columns = collect($this->getPrependedColumns())->concat($this->columns())->concat(collect($this->getAppendedColumns())); + $this->columns = $columns->filter(fn ($column) => $column instanceof Column); + } - $columns = collect($this->columns()) + protected function setupColumns(): void + { + $this->columns = $this->columns ->filter(fn ($column) => $column instanceof Column) ->map(function (Column $column) { - $column->setTheme($this->getTheme()); - $column->setHasTableRowUrl($this->hasTableRowUrl()); - $column->setIsReorderColumn($this->getDefaultReorderColumn() == $column->getField()); + $column->setTheme($this->getTheme()) + ->setHasTableRowUrl($this->hasTableRowUrl()) + ->setIsReorderColumn($this->getDefaultReorderColumn() == $column->getField()); + if ($column instanceof AggregateColumn) { if ($column->getAggregateMethod() == 'count' && $column->hasDataSource()) { $this->addExtraWithCount($column->getDataSource()); @@ -42,13 +47,15 @@ public function setColumns(): void return $column; }); - $this->appendedColumns = $this->getAppendedColumns(); - - $this->columns = collect([...$this->prependedColumns, ...$columns, ...$this->appendedColumns]); + $this->hasRunColumnSetup = true; } public function getColumns(): Collection { + if (! $this->hasRunColumnSetup) { + $this->setupColumns(); + } + return $this->columns; } @@ -206,63 +213,12 @@ public function getColspanCount(): int public function getPrependedColumns(): Collection { - return collect($this->prependedColumns ?? $this->prependColumns()) - ->filter(fn ($column) => $column instanceof Column) - ->map(function (Column $column) { - $column->setTheme($this->getTheme()); - $column->setHasTableRowUrl($this->hasTableRowUrl()); - $column->setIsReorderColumn($this->getDefaultReorderColumn() == $column->getField()); - if ($column instanceof AggregateColumn) { - if ($column->getAggregateMethod() == 'count' && $column->hasDataSource()) { - $this->addExtraWithCount($column->getDataSource()); - } elseif ($column->getAggregateMethod() == 'sum' && $column->hasDataSource() && $column->hasForeignColumn()) { - $this->addExtraWithSum($column->getDataSource(), $column->getForeignColumn()); - } elseif ($column->getAggregateMethod() == 'avg' && $column->hasDataSource() && $column->hasForeignColumn()) { - $this->addExtraWithAvg($column->getDataSource(), $column->getForeignColumn()); - } - } - - if ($column->hasField()) { - if ($column->isBaseColumn()) { - $column->setTable($this->getBuilder()->getModel()->getTable()); - } else { - $column->setTable($this->getTableForColumn($column)); - } - } - - return $column; - }); + return $this->prependedColumns ?? collect($this->prependColumns()); } public function getAppendedColumns(): Collection { - return collect($this->appendedColumns ?? $this->appendColumns()) - ->filter(fn ($column) => $column instanceof Column) - ->map(function (Column $column) { - $column->setTheme($this->getTheme()); - $column->setHasTableRowUrl($this->hasTableRowUrl()); - $column->setIsReorderColumn($this->getDefaultReorderColumn() == $column->getField()); - if ($column instanceof AggregateColumn) { - if ($column->getAggregateMethod() == 'count' && $column->hasDataSource()) { - $this->addExtraWithCount($column->getDataSource()); - } elseif ($column->getAggregateMethod() == 'sum' && $column->hasDataSource() && $column->hasForeignColumn()) { - $this->addExtraWithSum($column->getDataSource(), $column->getForeignColumn()); - } elseif ($column->getAggregateMethod() == 'avg' && $column->hasDataSource() && $column->hasForeignColumn()) { - $this->addExtraWithAvg($column->getDataSource(), $column->getForeignColumn()); - } - } - - if ($column->hasField()) { - if ($column->isBaseColumn()) { - $column->setTable($this->getBuilder()->getModel()->getTable()); - } else { - $column->setTable($this->getTableForColumn($column)); - } - } - - return $column; - }); - + return $this->appendedColumns ?? collect($this->appendColumns()); } public function getCollapsedAlwaysColumns(): Collection @@ -287,4 +243,20 @@ public function shouldCollapseAlways(): bool return $this->shouldAlwaysCollapse; } + + /** + * Prepend columns. + */ + public function prependColumns(): array + { + return []; + } + + /** + * Append columns. + */ + public function appendColumns(): array + { + return []; + } } diff --git a/src/Traits/WithColumns.php b/src/Traits/WithColumns.php index 729aa595a..798ec205a 100644 --- a/src/Traits/WithColumns.php +++ b/src/Traits/WithColumns.php @@ -15,9 +15,9 @@ trait WithColumns protected Collection $columns; - protected Collection $prependedColumns; + protected ?Collection $prependedColumns; - protected Collection $appendedColumns; + protected ?Collection $appendedColumns; protected ?bool $shouldAlwaysCollapse; @@ -25,6 +25,8 @@ trait WithColumns protected ?bool $shouldTabletCollapse; + protected bool $hasRunColumnSetup = false; + /** * Sets up Columns */ @@ -55,22 +57,6 @@ public function bootedWithColumns(): void */ abstract public function columns(): array; - /** - * Prepend columns. - */ - public function prependColumns(): array - { - return []; - } - - /** - * Append columns. - */ - public function appendColumns(): array - { - return []; - } - /** * Add Columns to View */ From 76e4b77191970da5f40336d6281687db1c606084 Mon Sep 17 00:00:00 2001 From: Joe <104938042+lrljoe@users.noreply.github.com> Date: Fri, 22 Nov 2024 21:48:45 +0000 Subject: [PATCH 2/6] Tweak Workflows to use an env key (#2090) * Tweak Worrkflows to use an env key * Update run-tests-pcov-pull * Adjust Discord Release Workflow --- .github/workflows/discord-releases.yml | 4 +++- .github/workflows/run-phpstan-pull.yml | 4 +++- .github/workflows/run-phpstan.yml | 4 +++- .github/workflows/run-tests-pcov-pull.yml | 6 ++++-- .github/workflows/run-tests-pull.yml | 8 ++++++-- .github/workflows/run-tests.yml | 8 ++++++-- 6 files changed, 25 insertions(+), 9 deletions(-) diff --git a/.github/workflows/discord-releases.yml b/.github/workflows/discord-releases.yml index fb008bc21..17e5ac816 100644 --- a/.github/workflows/discord-releases.yml +++ b/.github/workflows/discord-releases.yml @@ -10,8 +10,10 @@ jobs: uses: actions/checkout@v4 - name: Package Releases uses: SethCohen/github-releases-to-discord@latest + env: + WEBHOOK_DISCORD_RELEASE_URL: ${{ secrets.WEBHOOK_DISCORD_RELEASE_URL }} with: - webhook_url: ${{ secrets.WEBHOOK_DISCORD_RELEASE_URL }} + webhook_url: $WEBHOOK_DISCORD_RELEASE_URL color: "2105893" username: "GitHub Release-Bot" avatar_url: "https://cdn.discordapp.com/avatars/487431320314576937/bd64361e4ba6313d561d54e78c9e7171.png" diff --git a/.github/workflows/run-phpstan-pull.yml b/.github/workflows/run-phpstan-pull.yml index 9f8b7a5d7..9a288188b 100644 --- a/.github/workflows/run-phpstan-pull.yml +++ b/.github/workflows/run-phpstan-pull.yml @@ -66,8 +66,10 @@ jobs: restore-keys: phpstan-${{ matrix.os }}-PHP${{ matrix.php }}-L${{ matrix.laravel }}-composer- - name: Add token + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - composer config github-oauth.github.com ${{ secrets.GITHUB_TOKEN }} + composer config github-oauth.github.com $GITHUB_TOKEN - name: Install dependencies if: steps.composer-cache.outputs.cache-hit != 'true' diff --git a/.github/workflows/run-phpstan.yml b/.github/workflows/run-phpstan.yml index 742eb28a7..87180f167 100644 --- a/.github/workflows/run-phpstan.yml +++ b/.github/workflows/run-phpstan.yml @@ -69,8 +69,10 @@ jobs: restore-keys: phpstan-${{ matrix.os }}-PHP${{ matrix.php }}-L${{ matrix.laravel }}-composer- - name: Add token + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - composer config github-oauth.github.com ${{ secrets.GITHUB_TOKEN }} + composer config github-oauth.github.com $GITHUB_TOKEN - name: Install dependencies if: steps.composer-cache.outputs.cache-hit != 'true' diff --git a/.github/workflows/run-tests-pcov-pull.yml b/.github/workflows/run-tests-pcov-pull.yml index 87b9b9bd1..4457fb22a 100644 --- a/.github/workflows/run-tests-pcov-pull.yml +++ b/.github/workflows/run-tests-pcov-pull.yml @@ -71,8 +71,10 @@ jobs: restore-keys: ${{ matrix.os }}-PHP${{ matrix.php }}-L${{ matrix.laravel }}-composer- - name: Add token + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - composer config github-oauth.github.com ${{ secrets.GITHUB_TOKEN }} + composer config github-oauth.github.com $GITHUB_TOKEN - name: Install dependencies if: steps.composer-cache.outputs.cache-hit != 'true' @@ -93,7 +95,7 @@ jobs: env: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} with: - token: ${{ secrets.CODECOV_TOKEN }} + token: $CODECOV_TOKEN files: ./coverage.xml verbose: true diff --git a/.github/workflows/run-tests-pull.yml b/.github/workflows/run-tests-pull.yml index 856d27bb9..0de41ddb2 100644 --- a/.github/workflows/run-tests-pull.yml +++ b/.github/workflows/run-tests-pull.yml @@ -68,8 +68,10 @@ jobs: restore-keys: ${{ matrix.os }}-PHP${{ matrix.php }}-L${{ matrix.laravel }}-composer- - name: Add token + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - composer config github-oauth.github.com ${{ secrets.GITHUB_TOKEN }} + composer config github-oauth.github.com $GITHUB_TOKEN - name: Install dependencies if: steps.composer-cache.outputs.cache-hit != 'true' @@ -147,8 +149,10 @@ jobs: restore-keys: ${{ matrix.os }}-P${{ matrix.php }}-L${{ matrix.laravel }}-composer- - name: Add token + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - composer config github-oauth.github.com ${{ secrets.GITHUB_TOKEN }} + composer config github-oauth.github.com $GITHUB_TOKEN - name: Install dependencies if: steps.composer-cache.outputs.cache-hit != 'true' diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 55591c8f1..ff452e572 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -70,8 +70,10 @@ jobs: restore-keys: ${{ matrix.os }}-PHP${{ matrix.php }}-L${{ matrix.laravel }}-composer- - name: Add token + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - composer config github-oauth.github.com ${{ secrets.GITHUB_TOKEN }} + composer config github-oauth.github.com $GITHUB_TOKEN - name: Install dependencies if: steps.composer-cache.outputs.cache-hit != 'true' @@ -149,8 +151,10 @@ jobs: restore-keys: ${{ matrix.os }}-PHP${{ matrix.php }}-L${{ matrix.laravel }}-composer- - name: Add token + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - composer config github-oauth.github.com ${{ secrets.GITHUB_TOKEN }} + composer config github-oauth.github.com $GITHUB_TOKEN - name: Install dependencies if: steps.composer-cache.outputs.cache-hit != 'true' From 772c49ca681aa6b597541b0e089e4a3046d7c29f Mon Sep 17 00:00:00 2001 From: Joe <104938042+lrljoe@users.noreply.github.com> Date: Wed, 27 Nov 2024 23:06:35 +0000 Subject: [PATCH 3/6] Add Icon to Search Input (#2092) * Initial Commit * Add note - only tailwind for now --------- Co-authored-by: lrljoe --- docs/search/available-methods.md | 36 ++++ .../toolbar/items/search-field.blade.php | 22 ++- .../Configuration/SearchConfiguration.php | 14 -- src/Traits/Helpers/SearchHelpers.php | 19 --- src/Traits/Styling/HasSearchFieldStyling.php | 11 ++ src/Traits/Styling/Search/HasSearchIcon.php | 76 +++++++++ src/Traits/Styling/Search/HasSearchInput.php | 45 +++++ src/Traits/WithSearch.php | 6 +- .../Configuration/SearchConfigurationTest.php | 155 +++++++++++++++++- 9 files changed, 340 insertions(+), 44 deletions(-) create mode 100644 src/Traits/Styling/HasSearchFieldStyling.php create mode 100644 src/Traits/Styling/Search/HasSearchIcon.php create mode 100644 src/Traits/Styling/Search/HasSearchInput.php diff --git a/docs/search/available-methods.md b/docs/search/available-methods.md index 1d8397a5f..422757c37 100644 --- a/docs/search/available-methods.md +++ b/docs/search/available-methods.md @@ -192,3 +192,39 @@ public function configure(): void $this->setTrimSearchStringDisabled(); } ``` + +## Search Icon + +To help customise, a "Search Input Icon" has been added, allowing for the addition of an icon to the search input field. + +At present, the Search Icon is only available as a "left aligned" icon. + +This is presently only available for Tailwind implementations + +### setSearchIcon + +This adds an Icon to the Search Input Field, which expects an icon path (e.g. heroicon-m-magnifying-glass) + +```php +public function configure(): void +{ + $this->setSearchIcon('heroicon-m-magnifying-glass'); +} +``` + +### setSearchIconAttributes + +This allows you to specify attributes for the Search Icon for the Input Field. + +Note that classes will be injected prior to styles, due to the behaviour of icons. + +```php +public function configure(): void +{ + $this->setSearchIconAttributes([ + 'class' => 'h-4 w-4', + 'style' => 'color: #000000', + ]); +} + +``` \ No newline at end of file diff --git a/resources/views/components/tools/toolbar/items/search-field.blade.php b/resources/views/components/tools/toolbar/items/search-field.blade.php index 6bc8bb9c5..a52f06427 100644 --- a/resources/views/components/tools/toolbar/items/search-field.blade.php +++ b/resources/views/components/tools/toolbar/items/search-field.blade.php @@ -3,8 +3,21 @@
$this->isBootstrap, - 'flex rounded-md shadow-sm' => $this->isTailwind, + 'rounded-md shadow-sm' => $this->isTailwind, + 'flex' => !$this->hasSearchIcon, + 'relative inline-flex flex-row' => $this->hasSearchIcon, ])> + + @if($this->hasSearchIcon) +
+ + @svg($this->getSearchIcon, $this->getSearchIconClasses, $this->getSearchIconOtherAttributes()) + +
+ @endif + getSearchOptions() }}="search" placeholder="{{ $this->getSearchPlaceholder() }}" @@ -12,11 +25,12 @@ {{ $attributes->merge($this->getSearchFieldAttributes()) ->class([ - 'block w-full rounded-md shadow-sm transition duration-150 ease-in-out sm:text-sm sm:leading-5 rounded-none rounded-l-md focus:ring-0 focus:border-gray-300' => $this->isTailwind && $this->hasSearch() && (($this->getSearchFieldAttributes()['default'] ?? true) || ($this->getSearchFieldAttributes()['default-styling'] ?? true)), - 'block w-full rounded-md shadow-sm transition duration-150 ease-in-out sm:text-sm sm:leading-5 rounded-md focus:ring focus:ring-opacity-50' => $this->isTailwind && !$this->hasSearch() && (($this->getSearchFieldAttributes()['default'] ?? true) || ($this->getSearchFieldAttributes()['default-styling'] ?? true)), + 'rounded-md shadow-sm transition duration-150 ease-in-out sm:text-sm sm:leading-5 rounded-none rounded-l-md focus:ring-0 focus:border-gray-300' => $this->isTailwind && $this->hasSearch() && (($this->getSearchFieldAttributes()['default'] ?? true) || ($this->getSearchFieldAttributes()['default-styling'] ?? true)), + 'rounded-md shadow-sm transition duration-150 ease-in-out sm:text-sm sm:leading-5 rounded-md focus:ring focus:ring-opacity-50' => $this->isTailwind && !$this->hasSearch() && (($this->getSearchFieldAttributes()['default'] ?? true) || ($this->getSearchFieldAttributes()['default-styling'] ?? true)), 'border-gray-300 dark:bg-gray-700 dark:text-white dark:border-gray-600 focus:border-gray-300' => $this->isTailwind && $this->hasSearch() && (($this->getSearchFieldAttributes()['default'] ?? true) || ($this->getSearchFieldAttributes()['default-colors'] ?? true)), 'border-gray-300 dark:bg-gray-700 dark:text-white dark:border-gray-600 focus:border-indigo-300 focus:ring-indigo-200' => $this->isTailwind && !$this->hasSearch() && (($this->getSearchFieldAttributes()['default'] ?? true) || ($this->getSearchFieldAttributes()['default-colors'] ?? true)), - + 'block w-full' => !$this->hasSearchIcon, + 'pl-8 pr-4' => $this->hasSearchIcon, 'form-control' => $this->isBootstrap && $this->getSearchFieldAttributes()['default'] ?? true, ]) ->except(['default','default-styling','default-colors']) diff --git a/src/Traits/Configuration/SearchConfiguration.php b/src/Traits/Configuration/SearchConfiguration.php index 77590071f..2a1c6e926 100644 --- a/src/Traits/Configuration/SearchConfiguration.php +++ b/src/Traits/Configuration/SearchConfiguration.php @@ -147,20 +147,6 @@ public function setSearchLazy(): self return $this; } - public function setSearchPlaceholder(string $placeholder): self - { - $this->searchPlaceholder = $placeholder; - - return $this; - } - - public function setSearchFieldAttributes(array $attributes = []): self - { - $this->setCustomAttributes('searchFieldAttributes', array_merge(['default' => false, 'default-colors' => false, 'default-styling' => false], $attributes)); - - return $this; - } - public function setTrimSearchString(bool $status): self { $this->trimSearchString = $status; diff --git a/src/Traits/Helpers/SearchHelpers.php b/src/Traits/Helpers/SearchHelpers.php index b9637b13c..387155271 100644 --- a/src/Traits/Helpers/SearchHelpers.php +++ b/src/Traits/Helpers/SearchHelpers.php @@ -121,25 +121,6 @@ public function getSearchOptions(): string return '.live'; } - public function getSearchPlaceholder(): string - { - if ($this->hasSearchPlaceholder()) { - return $this->searchPlaceholder; - } - - return __($this->getLocalisationPath().'Search'); - } - - public function hasSearchPlaceholder(): bool - { - return $this->searchPlaceholder !== null; - } - - public function getSearchFieldAttributes(): array - { - return $this->getCustomAttributes('searchFieldAttributes', true); - } - public function shouldTrimSearchString(): bool { return $this->trimSearchString ?? false; diff --git a/src/Traits/Styling/HasSearchFieldStyling.php b/src/Traits/Styling/HasSearchFieldStyling.php new file mode 100644 index 000000000..01283773e --- /dev/null +++ b/src/Traits/Styling/HasSearchFieldStyling.php @@ -0,0 +1,11 @@ + 'h-4 w-4', 'style' => 'color: #000000']; + + #[Computed] + public function hasSearchIcon(): bool + { + return $this->searchIconSet; + } + + #[Computed] + public function getSearchIcon(): string + { + return $this->hasSearchIcon() ? $this->searchIcon : 'heroicon-m-magnifying-glass'; + } + + #[Computed] + public function getSearchIconClasses(): string + { + return $this->getSearchIconAttributes()['class']; + + } + + #[Computed] + public function getSearchIconAttributes(): array + { + return $this->searchIconAttributes; + } + + #[Computed] + public function getSearchIconOtherAttributes(): array + { + return collect($this->getSearchIconAttributes())->except('class')->toArray(); + } + + protected function setSearchIconStatus(bool $searchIconStatus): self + { + $this->searchIconSet = $searchIconStatus; + + return $this; + } + + protected function searchIconEnabled(): self + { + return $this->setSearchIconStatus(true); + } + + protected function searchIconDisabled(): self + { + return $this->setSearchIconStatus(false); + } + + protected function setSearchIcon(string $searchIcon): self + { + $this->searchIcon = $searchIcon; + + return $this->searchIconEnabled(); + } + + protected function setSearchIconAttributes(array $searchIconAttributes): self + { + $this->searchIconAttributes = array_merge($this->searchIconAttributes, $searchIconAttributes); + + return $this->searchIconEnabled(); + } +} diff --git a/src/Traits/Styling/Search/HasSearchInput.php b/src/Traits/Styling/Search/HasSearchInput.php new file mode 100644 index 000000000..f937f5ef5 --- /dev/null +++ b/src/Traits/Styling/Search/HasSearchInput.php @@ -0,0 +1,45 @@ +setCustomAttributes('searchFieldAttributes', array_merge(['default' => false, 'default-colors' => false, 'default-styling' => false], $attributes)); + + return $this; + } + + public function getSearchFieldAttributes(): array + { + return $this->getCustomAttributes('searchFieldAttributes', true); + } + + public function setSearchPlaceholder(string $placeholder): self + { + $this->searchPlaceholder = $placeholder; + + return $this; + } + + public function getSearchPlaceholder(): string + { + if ($this->hasSearchPlaceholder()) { + return $this->searchPlaceholder; + } + + return __($this->getLocalisationPath().'Search'); + } + + public function hasSearchPlaceholder(): bool + { + return $this->searchPlaceholder !== null; + } +} diff --git a/src/Traits/WithSearch.php b/src/Traits/WithSearch.php index ddfe98553..f4befabf9 100644 --- a/src/Traits/WithSearch.php +++ b/src/Traits/WithSearch.php @@ -8,20 +8,20 @@ use Rappasoft\LaravelLivewireTables\Traits\Configuration\SearchConfiguration; use Rappasoft\LaravelLivewireTables\Traits\Core\QueryStrings\HasQueryStringForSearch; use Rappasoft\LaravelLivewireTables\Traits\Helpers\SearchHelpers; +use Rappasoft\LaravelLivewireTables\Traits\Styling\HasSearchFieldStyling; trait WithSearch { use SearchConfiguration, SearchHelpers; use HasQueryStringForSearch; + use HasSearchFieldStyling; public string $search = ''; #[Locked] public bool $searchStatus = true; - protected ?string $searchPlaceholder = null; - protected bool $searchVisibilityStatus = true; protected ?bool $searchFilterBlur = null; @@ -36,8 +36,6 @@ trait WithSearch protected ?int $searchFilterThrottle = null; - protected array $searchFieldAttributes = []; - protected bool $trimSearchString = false; // TODO diff --git a/tests/Unit/Traits/Configuration/SearchConfigurationTest.php b/tests/Unit/Traits/Configuration/SearchConfigurationTest.php index 9daec3aeb..cc55f8362 100644 --- a/tests/Unit/Traits/Configuration/SearchConfigurationTest.php +++ b/tests/Unit/Traits/Configuration/SearchConfigurationTest.php @@ -3,6 +3,7 @@ namespace Rappasoft\LaravelLivewireTables\Tests\Unit\Traits\Configuration; use Rappasoft\LaravelLivewireTables\Exceptions\DataTableConfigurationException; +use Rappasoft\LaravelLivewireTables\Tests\Http\Livewire\PetsTable; use Rappasoft\LaravelLivewireTables\Tests\TestCase; final class SearchConfigurationTest extends TestCase @@ -180,11 +181,159 @@ public function test_can_set_search_placeholder(): void public function test_can_set_search_field_attributes(): void { - $this->assertSame(['default' => true, 'default-colors' => true, 'default-styling' => true], $this->basicTable->getSearchFieldAttributes()); + $mock = new class extends PetsTable + { + public ?array $testAttributesArray; - $this->basicTable->setSearchFieldAttributes(['class' => 'bg-blue', 'style' => 'font-size: 3em;']); + public function configure(): void + { + $this->setDataTableFingerprint('test'); + } - $this->assertSame(['class' => 'bg-blue', 'default' => false, 'default-colors' => false, 'default-styling' => false, 'style' => 'font-size: 3em;'], $this->basicTable->getSearchFieldAttributes()); + public function pubSetSearchFieldAttributes(array $attributes) + { + $this->setSearchFieldAttributes($attributes); + } + }; + + $mock->configure(); + $mock->boot(); + + $this->assertSame(['default' => true, 'default-colors' => true, 'default-styling' => true], $mock->getSearchFieldAttributes()); + + $mock->pubSetSearchFieldAttributes(['class' => 'bg-blue', 'style' => 'font-size: 3em;']); + + $this->assertSame(['class' => 'bg-blue', 'default' => false, 'default-colors' => false, 'default-styling' => false, 'style' => 'font-size: 3em;'], $mock->getSearchFieldAttributes()); + + } + + public function test_can_set_search_icon(): void + { + $mock = new class extends PetsTable + { + public ?array $testAttributesArray; + + public function configure(): void + { + $this->setDataTableFingerprint('test'); + } + + public function pubSetSearchFieldAttributes(array $attributes) + { + $this->setSearchFieldAttributes($attributes); + } + + public function pubSetSearchIcon(string $searchIcon) + { + $this->setSearchIcon($searchIcon); + } + + public function pubSetSearchIconAttributes(array $attributes) + { + $this->setSearchIconAttributes($attributes); + } + }; + + $mock->configure(); + $mock->boot(); + + $this->assertFalse($mock->hasSearchIcon()); + $mock->pubSetSearchIcon('heroicon-m-magnifying-glass-2'); + $this->assertTrue($mock->hasSearchIcon()); + + $this->assertSame($mock->getSearchIcon(), 'heroicon-m-magnifying-glass-2'); + + } + + public function test_can_set_search_icon_status(): void + { + $mock = new class extends PetsTable + { + public ?array $testAttributesArray; + + public function configure(): void + { + $this->setDataTableFingerprint('test'); + } + + public function pubSetSearchFieldAttributes(array $attributes) + { + $this->setSearchFieldAttributes($attributes); + } + + public function pubSetSearchIconEnabled() + { + $this->searchIconEnabled(); + } + + public function pubSetSearchIconDisabled() + { + $this->searchIconDisabled(); + } + }; + + $mock->configure(); + $mock->boot(); + + $this->assertFalse($mock->hasSearchIcon()); + $mock->pubSetSearchIconEnabled(); + + $this->assertTrue($mock->hasSearchIcon()); + $mock->pubSetSearchIconDisabled(); + $this->assertFalse($mock->hasSearchIcon()); + + } + + public function test_can_set_search_icon_attributes(): void + { + $mock = new class extends PetsTable + { + public ?array $testAttributesArray; + + public function configure(): void + { + $this->setDataTableFingerprint('test'); + + } + + public function pubSetSearchFieldAttributes(array $attributes) + { + $this->setSearchFieldAttributes($attributes); + } + + public function pubSetSearchIcon(string $searchIcon) + { + $this->setSearchIcon($searchIcon); + } + + public function pubSetSearchIconAttributes(array $attributes) + { + $this->setSearchIconAttributes($attributes); + } + }; + + $mock->configure(); + $mock->boot(); + + $this->assertSame('h-4 w-4', $mock->getSearchIconClasses()); + $this->assertSame([ + 'style' => 'color: #000000', + ], $mock->getSearchIconOtherAttributes()); + + $mock->pubSetSearchIconAttributes([ + 'style' => 'color: #FF0000', + 'class' => 'h-6 w-6', + ]); + + $this->assertSame('h-6 w-6', $mock->getSearchIconClasses()); + $this->assertSame([ + 'style' => 'color: #FF0000', + ], $mock->getSearchIconOtherAttributes()); + + $this->assertSame([ + 'class' => 'h-6 w-6', + 'style' => 'color: #FF0000', + ], $mock->getSearchIconAttributes()); } } From de8d3bb5220f6022e12548b1e0ac48612a76bccd Mon Sep 17 00:00:00 2001 From: Edwin van de Pol Date: Thu, 28 Nov 2024 01:01:25 +0100 Subject: [PATCH 4/6] Typehinting in blade components (#2081) --- .../components/includes/actions.blade.php | 12 +- .../components/includes/loading.blade.php | 9 +- resources/views/components/table.blade.php | 10 +- .../table/collapsed-columns.blade.php | 5 +- resources/views/components/table/td.blade.php | 3 +- .../views/components/table/td/plain.blade.php | 2 + resources/views/components/table/th.blade.php | 3 +- resources/views/components/tools.blade.php | 4 +- .../components/tools/filter-label.blade.php | 8 +- .../components/tools/filter-pills.blade.php | 2 +- .../filter-pills/buttons/reset-all.blade.php | 6 +- .../buttons/reset-filter.blade.php | 4 +- .../tools/filters/boolean.blade.php | 19 +- .../tools/filters/date-range.blade.php | 3 +- .../components/tools/filters/date.blade.php | 13 +- .../tools/filters/datetime.blade.php | 13 +- .../livewire-component-array-filter.blade.php | 2 + .../livewire-component-filter.blade.php | 2 + .../filters/multi-select-dropdown.blade.php | 8 +- .../tools/filters/multi-select.blade.php | 10 +- .../tools/filters/number-range.blade.php | 8 +- .../components/tools/filters/number.blade.php | 15 +- .../components/tools/filters/select.blade.php | 6 +- .../tools/filters/text-field.blade.php | 13 +- .../components/tools/sorting-pills.blade.php | 3 + .../views/components/tools/toolbar.blade.php | 13 +- .../toolbar/items/column-select.blade.php | 303 +++++++++--------- .../toolbar/items/filter-popover.blade.php | 4 +- .../toolbar/items/filter-slidedown.blade.php | 37 +-- resources/views/datatable.blade.php | 36 +-- .../views/includes/actions/button.blade.php | 13 +- .../views/includes/columns/boolean.blade.php | 30 +- .../views/includes/columns/link.blade.php | 2 + .../includes/columns/wire-link.blade.php | 3 +- 34 files changed, 325 insertions(+), 299 deletions(-) diff --git a/resources/views/components/includes/actions.blade.php b/resources/views/components/includes/actions.blade.php index db8925279..035c8397a 100644 --- a/resources/views/components/includes/actions.blade.php +++ b/resources/views/components/includes/actions.blade.php @@ -4,14 +4,14 @@ ->class(['' => $this->isTailwind && $this->getActionWrapperAttributes['default-colors'] ?? true]) ->class(['d-flex flex-cols py-2 space-x-2' => $this->isBootstrap && $this->getActionWrapperAttributes['default-styling'] ?? true]) ->class(['' => $this->isBootstrap && $this->getActionWrapperAttributes['default-colors'] ?? true]) - ->class(['justify-start' => $this->getActionsPosition == 'left']) - ->class(['justify-center' => $this->getActionsPosition == 'center']) - ->class(['justify-end' => $this->getActionsPosition == 'right']) - ->class(['pl-2' => $this->showActionsInToolbar && $this->getActionsPosition == 'left']) - ->class(['pr-2' => $this->showActionsInToolbar && $this->getActionsPosition == 'right']) + ->class(['justify-start' => $this->getActionsPosition === 'left']) + ->class(['justify-center' => $this->getActionsPosition === 'center']) + ->class(['justify-end' => $this->getActionsPosition === 'right']) + ->class(['pl-2' => $this->showActionsInToolbar && $this->getActionsPosition === 'left']) + ->class(['pr-2' => $this->showActionsInToolbar && $this->getActionsPosition === 'right']) ->except(['default','default-styling','default-colors']) }} > @foreach($this->getActions as $action) {{ $action->render() }} @endforeach -
\ No newline at end of file + diff --git a/resources/views/components/includes/loading.blade.php b/resources/views/components/includes/loading.blade.php index b8c988e88..ef88b43e8 100644 --- a/resources/views/components/includes/loading.blade.php +++ b/resources/views/components/includes/loading.blade.php @@ -2,9 +2,9 @@ @props(['colCount' => 1]) @php -$loaderRow = $this->getLoadingPlaceHolderRowAttributes(); -$loaderCell = $this->getLoadingPlaceHolderCellAttributes(); -$loaderIcon = $this->getLoadingPlaceHolderIconAttributes(); + $loaderRow = $this->getLoadingPlaceHolderRowAttributes(); + $loaderCell = $this->getLoadingPlaceHolderCellAttributes(); + $loaderIcon = $this->getLoadingPlaceHolderIconAttributes(); @endphp merge($loaderIcon) ->class(['lds-hourglass' => $this->isTailwind && ($loaderIcon['default'] ?? true)]) ->class(['lds-hourglass' => $this->isBootstrap && ($loaderIcon['default'] ?? true)]) - ->except(['default','default-styling','default-colors']); + ->except(['default','default-styling','default-colors']) }}>
{!! $this->getLoadingPlaceholderContent() !!}
@endif - diff --git a/resources/views/components/table.blade.php b/resources/views/components/table.blade.php index 297548694..331c0b25f 100644 --- a/resources/views/components/table.blade.php +++ b/resources/views/components/table.blade.php @@ -21,7 +21,7 @@ {{ $attributes->merge($customAttributes['table']) ->class(['min-w-full divide-y divide-gray-200 dark:divide-none' => $customAttributes['table']['default'] ?? true]) ->except(['default','default-styling','default-colors']) }} - + > merge($customAttributes['thead']) @@ -43,11 +43,11 @@ {{ $slot }} - @if (isset($tfoot)) + @isset($tfoot) {{ $tfoot }} - @endif + @endisset @elseif ($isBootstrap) @@ -84,11 +84,11 @@ {{ $slot }} - @if (isset($tfoot)) + @isset($tfoot) {{ $tfoot }} - @endif + @endisset @endif diff --git a/resources/views/components/table/collapsed-columns.blade.php b/resources/views/components/table/collapsed-columns.blade.php index 44bb45d9f..b15e9cf20 100644 --- a/resources/views/components/table/collapsed-columns.blade.php +++ b/resources/views/components/table/collapsed-columns.blade.php @@ -50,18 +50,19 @@ colspan="{{ $colspan }}" >
+ @php /** @var \Rappasoft\LaravelLivewireTables\Views\Column $column */ @endphp @foreach($columns as $colIndex => $column) @continue($column->isHidden()) @continue($this->columnSelectIsEnabled() && ! $this->columnSelectIsEnabledForColumn($column))

$isTailwind && $column->shouldCollapseAlways(), 'block mb-2 sm:hidden' => $isTailwind && !$column->shouldCollapseAlways() && !$column->shouldCollapseOnTablet() && !$column->shouldCollapseOnMobile(), 'block mb-2 md:hidden' => $isTailwind && !$column->shouldCollapseAlways() && !$column->shouldCollapseOnTablet() && $column->shouldCollapseOnMobile(), 'block mb-2 lg:hidden' => $isTailwind && !$column->shouldCollapseAlways() && ($column->shouldCollapseOnTablet() || $column->shouldCollapseOnMobile()), - + 'd-block mb-2' => $isBootstrap && $column->shouldCollapseAlways(), 'd-block mb-2 d-sm-none' => $isBootstrap && !$column->shouldCollapseAlways() && !$column->shouldCollapseOnTablet() && !$column->shouldCollapseOnMobile(), 'd-block mb-2 d-md-none' => $isBootstrap && !$column->shouldCollapseAlways() && !$column->shouldCollapseOnTablet() && $column->shouldCollapseOnMobile(), diff --git a/resources/views/components/table/td.blade.php b/resources/views/components/table/td.blade.php index 0ba2f050d..8320d2d9f 100644 --- a/resources/views/components/table/td.blade.php +++ b/resources/views/components/table/td.blade.php @@ -2,12 +2,13 @@ @props(['column', 'colIndex']) @php + /** @var \Rappasoft\LaravelLivewireTables\Views\Column $column */ $customAttributes = $this->getTdAttributes($column, $row, $colIndex, $rowIndex) @endphp isClickable()) - @if($this->getTableRowUrlTarget($row) === "navigate") wire:navigate href="{{ $this->getTableRowUrl($row) }}" + @if($this->getTableRowUrlTarget($row) === 'navigate') wire:navigate href="{{ $this->getTableRowUrl($row) }}" @else onclick="window.open('{{ $this->getTableRowUrl($row) }}', '{{ $this->getTableRowUrlTarget($row) ?? '_self' }}')" @endif @endif diff --git a/resources/views/components/table/td/plain.blade.php b/resources/views/components/table/td/plain.blade.php index d2e9ffb6f..824bcf2af 100644 --- a/resources/views/components/table/td/plain.blade.php +++ b/resources/views/components/table/td/plain.blade.php @@ -1,6 +1,8 @@ @aware(['component', 'rowIndex', 'rowID','isTailwind','isBootstrap']) @props(['column' => null, 'customAttributes' => [], 'displayMinimisedOnReorder' => false, 'hideUntilReorder' => false]) +@php /** @var \Rappasoft\LaravelLivewireTables\Views\Column|null $column */ @endphp + @if ($isTailwind) merge($customAttributes) diff --git a/resources/views/components/table/th.blade.php b/resources/views/components/table/th.blade.php index 3afee536c..ee837bf28 100644 --- a/resources/views/components/table/th.blade.php +++ b/resources/views/components/table/th.blade.php @@ -2,6 +2,7 @@ @props(['column', 'index']) @php + /** @var \Rappasoft\LaravelLivewireTables\Views\Column $column */ $attributes = $attributes->merge(['wire:key' => $tableName . '-header-col-'.$column->getSlug()]); $allThAttributes = $this->getAllThAttributes($column); @@ -41,7 +42,7 @@ }} > except(['default', 'default-colors', 'default-styling']) }}>{{ $column->getTitle() }} - merge($customSortIconAttributes) ->except(['default', 'default-colors', 'default-styling', 'wire:key']) diff --git a/resources/views/components/tools.blade.php b/resources/views/components/tools.blade.php index bdb31a745..d40efaed3 100644 --- a/resources/views/components/tools.blade.php +++ b/resources/views/components/tools.blade.php @@ -1,11 +1,11 @@ @aware(['component','isTailwind','isBootstrap']) @php($toolsAttributes = $this->getToolsAttributesBag()) -

merge() ->class(['flex-col' => $isTailwind && ($toolsAttributes['default-styling'] ?? true)]) ->class(['d-flex flex-column' => $isBootstrap && ($toolsAttributes['default-styling'] ?? true)]) - ->except(['default','default-styling','default-colors']) + ->except(['default','default-styling','default-colors']) }} > {{ $slot }} diff --git a/resources/views/components/tools/filter-label.blade.php b/resources/views/components/tools/filter-label.blade.php index 6fc9022dc..eb81b92d3 100644 --- a/resources/views/components/tools/filter-label.blade.php +++ b/resources/views/components/tools/filter-label.blade.php @@ -2,10 +2,11 @@ @props(['filter', 'filterLayout' => 'popover', 'tableName' => 'table', 'isTailwind' => false, 'isBootstrap' => false, 'isBootstrap4' => false, 'isBootstrap5' => false, 'for' => null]) @php + /** @var \Rappasoft\LaravelLivewireTables\Views\Filter $filter */ $filterLabelAttributes = $filter->getFilterLabelAttributes(); $customLabelAttributes = $filter->getLabelAttributes(); - @endphp + @if($filter->hasCustomFilterLabel() && !$filter->hasCustomPosition()) @include($filter->getCustomFilterLabel(),['filter' => $filter, 'filterLayout' => $filterLayout, 'tableName' => $tableName, 'isTailwind' => $isTailwind, 'isBootstrap' => $isBootstrap, 'isBootstrap4' => $isBootstrap4, 'isBootstrap5' => $isBootstrap5, 'customLabelAttributes' => $customLabelAttributes]) @elseif(!$filter->hasCustomPosition()) @@ -14,13 +15,12 @@ {{ $attributes->merge($customLabelAttributes)->merge($filterLabelAttributes) ->class(['block text-sm font-medium leading-5 text-gray-700 dark:text-white' => $isTailwind && ($filterLabelAttributes['default'] ?? true)]) - ->class(['d-block' => $isBootstrap && $filterLayout == 'slide-down' && ($filterLabelAttributes['default'] ?? true)]) - ->class(['mb-2' => $isBootstrap && $filterLayout == 'popover' && ($filterLabelAttributes['default'] ?? true)]) + ->class(['d-block' => $isBootstrap && $filterLayout === 'slide-down' && ($filterLabelAttributes['default'] ?? true)]) + ->class(['mb-2' => $isBootstrap && $filterLayout === 'popover' && ($filterLabelAttributes['default'] ?? true)]) ->except(['default', 'default-colors', 'default-styling']) }} > {{ $filter->getName() }} - @endif diff --git a/resources/views/components/tools/filter-pills.blade.php b/resources/views/components/tools/filter-pills.blade.php index ba84a9b74..400de52b9 100644 --- a/resources/views/components/tools/filter-pills.blade.php +++ b/resources/views/components/tools/filter-pills.blade.php @@ -14,6 +14,7 @@ @foreach($this->getAppliedFiltersWithValues() as $filterSelectName => $value) + @php /** @var \Rappasoft\LaravelLivewireTables\Views\Filter $filter */ @endphp @php($filter = $this->getFilterByKey($filterSelectName)) @continue(is_null($filter) || $filter->isHiddenFromPills()) @php( $filterPillTitle = $filter->getFilterPillTitle()) @@ -31,4 +32,3 @@
@endif - diff --git a/resources/views/components/tools/filter-pills/buttons/reset-all.blade.php b/resources/views/components/tools/filter-pills/buttons/reset-all.blade.php index 78a42dc21..508c3e201 100644 --- a/resources/views/components/tools/filter-pills/buttons/reset-all.blade.php +++ b/resources/views/components/tools/filter-pills/buttons/reset-all.blade.php @@ -3,11 +3,11 @@ - - - +