Skip to content

Commit

Permalink
Add open option (#100)
Browse files Browse the repository at this point in the history
Co-authored-by: et-hoangdv <[email protected]>
Co-authored-by: Rafael Milewski <[email protected]>
  • Loading branch information
3 people authored May 13, 2024
1 parent 53ff259 commit 817e069
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 5 deletions.
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class ExampleNovaResource extends Resource {

use MegaFilterTrait;

public function filters(RequestRequest $request): array
public function filters(NovaRequest $request): array
{
return [
MegaFilter::make([ ... ]),
Expand All @@ -78,14 +78,25 @@ class ExampleNovaResource extends Resource {
You can also set how many columns you want to display your filters:

```php
public function filters(RequestRequest $request): array
public function filters(NovaRequest $request): array
{
return [
MegaFilter::make([ ... ])->columns(3),
];
}
```

By default, the filter section is collapsed. If you want it to open or expanded initially, you can do:

```php
public function filters(NovaRequest $request): array
{
return [
MegaFilter::make([ ... ])->open(),
];
}
```

> Note: At the moment this package only works with a single Mega Filter per resource, adding multiple on the same resource may result in unexpected behavior.
## ⭐️ Show Your Support
Expand Down
2 changes: 1 addition & 1 deletion dist/css/card.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/js/card.js

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion resources/js/components/MegaFilter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
props: [
'filters',
'columns',
'open',
'resourceName',
'viaResource',
'viaResourceId',
Expand Down Expand Up @@ -141,7 +142,7 @@
await this.initializeState()
},
beforeMount() {
this.collapsed = this.filtersAreApplied
this.collapsed = this.open ? this.open : this.filtersAreApplied
},
}
Expand Down Expand Up @@ -182,6 +183,7 @@
}
.nova-mega-filter {
overflow: visible;
&.\--expanded {
background-color: rgba(var(--colors-gray-300));
Expand Down
1 change: 1 addition & 0 deletions resources/js/components/MegaFilterCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
:lens="lens"
:filters="card.filters"
:columns="card.columns"
:open="card.open"
:resource-name="resourceName"
:via-resource="viaResource"
:via-resource-id="viaResourceId"
Expand Down
5 changes: 5 additions & 0 deletions src/MegaFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ public function columns(int $columns): self
return $this->withMeta([ 'columns' => $columns ]);
}

public function open(bool $open = true): self
{
return $this->withMeta([ 'open' => $open ]);
}

private function request(): NovaRequest
{
return resolve(NovaRequest::class);
Expand Down

0 comments on commit 817e069

Please sign in to comment.