Skip to content

Commit

Permalink
Add option to custom per page
Browse files Browse the repository at this point in the history
  • Loading branch information
mansoorkhan96 committed Mar 21, 2024
1 parent 2ba9089 commit 39cfe34
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,28 @@ Forms\Components\FileUpload::make('featured_image')
- `->small()`
- `->thumbnail()`

# Specifying Per Page

You can specify how many image results should show on a single page.

Update per_page option in `.env`

```php
'per_page' => env('UNSPLASH_PICKER_PER_PAGE', 20),
```

You can also set different per page option for each `UnsplashPickerAction` by appending `->perPage()` method

```php
Forms\Components\FileUpload::make('featured_image')
->image()
->hintAction(
UnsplashPickerAction::make()
->thumbnail()
->perPage(20)
)
```

## Customization

The `UnsplashPickerAction` is simple Filament Form Action and you append all the available methods. The Image picker component is a livewire component, you can extend and override the methods.
Expand All @@ -84,6 +106,7 @@ This is the contents of the published config file:
```php
return [
'unsplash_client_id' => env('UNSPLASH_CLIENT_ID'),
'per_page' => env('UNSPLASH_PICKER_PER_PAGE', 20),
];
```

Expand Down
1 change: 1 addition & 0 deletions config/unsplash-picker.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

return [
'unsplash_client_id' => env('UNSPLASH_CLIENT_ID'),
'per_page' => env('UNSPLASH_PICKER_PER_PAGE', 20),
];
11 changes: 10 additions & 1 deletion src/Actions/UnsplashPickerAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class UnsplashPickerAction extends Action
{
protected ?ImageSize $imageSize = null;

protected ?int $perPage = null;

public static function getDefaultName(): ?string
{
return 'unsplash_picker';
Expand All @@ -38,11 +40,18 @@ protected function setUp(): void

$this->modalWidth(fn (MountableAction $action): ?MaxWidth => MaxWidth::ScreenLarge);

$this->modalContent(fn () => new HtmlString(Blade::render("@livewire('unsplash-picker-component')")));
$this->modalContent(fn () => new HtmlString(Blade::render("@livewire('unsplash-picker-component', ['perPage' => {$this->perPage}])")));

$this->action($this->uploadImage(...));
}

public function perPage(int $perPage): static
{
$this->perPage = $perPage;

return $this;
}

public function raw(): static
{
$this->imageSize = ImageSize::Raw;
Expand Down
4 changes: 3 additions & 1 deletion src/Components/UnsplashPickerComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class UnsplashPickerComponent extends Component implements HasActions, HasForms

public string $search = '';

public ?int $perPage = null;

public int $page = 1;

public ?int $totalPages = null;
Expand Down Expand Up @@ -97,7 +99,7 @@ public function getTotalPages(): int

public function getPerPage(): int
{
return 9;
return $this->perPage ?? config('unsplash-picker.per_page');
}

public function render()
Expand Down

0 comments on commit 39cfe34

Please sign in to comment.