Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Default Filter Input Styling #2132

Draft
wants to merge 8 commits into
base: development
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/start/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ module.exports = {
purge: [
...
'./vendor/rappasoft/laravel-livewire-tables/resources/views/**/*.blade.php',
'./vendor/rappasoft/laravel-livewire-tables/src/Traits/Styling/Defaults/**/*.php',
],
...
};
Expand All @@ -57,6 +58,7 @@ module.exports = {
content: [
...
'./vendor/rappasoft/laravel-livewire-tables/resources/views/**/*.blade.php',
'./vendor/rappasoft/laravel-livewire-tables/src/Traits/Styling/Defaults/**/*.php',
],
...
};
Expand Down
1 change: 1 addition & 0 deletions docs/start/recommended.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ If using Tailwind, you should update your tailwind.config.js file, adding the fo
```js
'./vendor/rappasoft/laravel-livewire-tables/resources/views/*.blade.php',
'./vendor/rappasoft/laravel-livewire-tables/resources/views/**/*.blade.php',
'./vendor/rappasoft/laravel-livewire-tables/src/Traits/Styling/Defaults/**/*.php',
```

It is also recommended to add the paths to any Livewire Tables components, for example:
Expand Down
2 changes: 2 additions & 0 deletions src/Traits/HasAllTraits.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Rappasoft\LaravelLivewireTables\Traits;

use Rappasoft\LaravelLivewireTables\Traits\Core\{HasCustomAttributes, HasLocalisations};
use Rappasoft\LaravelLivewireTables\Traits\Styling\Defaults\{HasDefaultFilterInputStyling};
use Rappasoft\LaravelLivewireTables\Views\Traits\Core\HasTheme;

trait HasAllTraits
Expand All @@ -13,6 +14,7 @@ trait HasAllTraits
use WithLoadingPlaceholder;
use HasTheme;
use ComponentUtilities,
HasDefaultFilterInputStyling,
WithActions,
WithData,
WithQueryString,
Expand Down
64 changes: 64 additions & 0 deletions src/Traits/Styling/Defaults/HasDefaultFilterInputStyling.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

namespace Rappasoft\LaravelLivewireTables\Traits\Styling\Defaults;

use Livewire\Attributes\Computed;

trait HasDefaultFilterInputStyling
{
public ?string $defaultFilterInputColors;

public ?string $defaultFilterInputStyling;

protected function setDefaultFilterInputColors(string $defaultFilterInputColors): self
{
$this->defaultFilterInputColors = $defaultFilterInputColors;

return $this;
}

protected function setDefaultFilterInputStyling(string $defaultFilterInputStyling): self
{
$this->defaultFilterInputStyling = $defaultFilterInputStyling;

return $this;
}

public function hasDefaultFilterInputColors(): bool
{
return isset($this->defaultFilterInputColors);
}

#[Computed]
public function getDefaultFilterInputColors(): string
{
if (isset($this->defaultFilterInputColors)) {
return $this->defaultFilterInputColors;
} else {
if ($this->isTailwind()) {
return 'border-gray-300 focus:border-indigo-300 focus:ring-indigo-200 dark:bg-gray-800 dark:text-white dark:border-gray-600';
} else {
return '';

Check warning on line 41 in src/Traits/Styling/Defaults/HasDefaultFilterInputStyling.php

View check run for this annotation

Codecov / codecov/patch

src/Traits/Styling/Defaults/HasDefaultFilterInputStyling.php#L41

Added line #L41 was not covered by tests
}
}
}

public function hasDefaultFilterInputStyling(): bool
{
return isset($this->defaultFilterInputStyling);
}

#[Computed]
public function getDefaultFilterInputStyling(): string
{
if (isset($this->defaultFilterInputStyling)) {
return $this->defaultFilterInputStyling;
} else {
if ($this->isTailwind()) {
return 'block w-full rounded-md shadow-sm transition duration-150 ease-in-out focus:ring focus:ring-opacity-50';
} else {
return 'form-control';

Check warning on line 60 in src/Traits/Styling/Defaults/HasDefaultFilterInputStyling.php

View check run for this annotation

Codecov / codecov/patch

src/Traits/Styling/Defaults/HasDefaultFilterInputStyling.php#L60

Added line #L60 was not covered by tests
}
}
}
}
110 changes: 110 additions & 0 deletions tests/Unit/Traits/Styling/FilterInputDefaultStylingTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?php

namespace Rappasoft\LaravelLivewireTables\Tests\Unit\Traits\Styling;

use PHPUnit\Framework\Attributes\Group;
use Rappasoft\LaravelLivewireTables\Tests\Http\Livewire\PetsTable;
use Rappasoft\LaravelLivewireTables\Tests\TestCase;

#[Group('Filters')]
#[Group('Styling')]
final class FilterInputDefaultStylingTest extends TestCase
{
public function test_has_filter_default_input_styling(): void
{
$this->assertFalse($this->basicTable->hasDefaultFilterInputStyling());
}

public function test_can_get_filter_default_input_styling(): void
{
$this->assertFalse($this->basicTable->hasDefaultFilterInputStyling());

$this->assertSame('block w-full rounded-md shadow-sm transition duration-150 ease-in-out focus:ring focus:ring-opacity-50', $this->basicTable->getDefaultFilterInputStyling());
}

public function test_can_set_filter_default_input_styling(): void
{
$testTableDefault = new class extends PetsTable
{
public function configure(): void
{
parent::configure();

}

public function setDefaultFilterInputStyling(string $defaultFilterInputStyling): self
{
parent::setDefaultFilterInputStyling($defaultFilterInputStyling);

return $this;
}
};

$testTableDefault->configure();
$testTableDefault->boot();
$testTableDefault->bootedComponentUtilities();
$testTableDefault->bootedWithData();
$testTableDefault->bootedWithColumns();
$testTableDefault->bootedWithColumnSelect();
$testTableDefault->bootedWithSecondaryHeader();
$testTableDefault->booted();

$this->assertFalse($testTableDefault->hasDefaultFilterInputStyling());

$testTableDefault->setDefaultFilterInputStyling('p-4');

$this->assertTrue($testTableDefault->hasDefaultFilterInputStyling());

$this->assertSame('p-4', $testTableDefault->getDefaultFilterInputStyling());

}

public function test_has_filter_default_input_colors(): void
{
$this->assertFalse($this->basicTable->hasDefaultFilterInputColors());
}

public function test_can_set_filter_default_input_colors(): void
{

$testTableDefault = new class extends PetsTable
{
public function configure(): void
{
parent::configure();

}

public function setDefaultFilterInputColors(string $defaultFilterInputColors): self
{
parent::setDefaultFilterInputColors($defaultFilterInputColors);

return $this;
}
};

$testTableDefault->configure();
$testTableDefault->boot();
$testTableDefault->bootedComponentUtilities();
$testTableDefault->bootedWithData();
$testTableDefault->bootedWithColumns();
$testTableDefault->bootedWithColumnSelect();
$testTableDefault->bootedWithSecondaryHeader();
$testTableDefault->booted();
$this->assertFalse($testTableDefault->hasDefaultFilterInputColors());

$testTableDefault->setDefaultFilterInputColors('bg-blue-500');

$this->assertTrue($testTableDefault->hasDefaultFilterInputColors());

$this->assertSame('bg-blue-500', $testTableDefault->getDefaultFilterInputColors());

}

public function test_can_get_filter_default_input_colors(): void
{
$this->assertFalse($this->basicTable->hasDefaultFilterInputColors());

$this->assertSame('border-gray-300 focus:border-indigo-300 focus:ring-indigo-200 dark:bg-gray-800 dark:text-white dark:border-gray-600', $this->basicTable->getDefaultFilterInputColors());
}
}
Loading