Skip to content

Commit

Permalink
fix: minor
Browse files Browse the repository at this point in the history
  • Loading branch information
lee-to committed Oct 19, 2024
1 parent c392fc2 commit 3b7a94f
Show file tree
Hide file tree
Showing 11 changed files with 128 additions and 108 deletions.
26 changes: 20 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
# ![Layouts field for MoonShine](https://github.com/moonshine-software/moonshine/raw/2.x/art/lego.png)
## Layouts field for MoonShine

### Requirements

- MoonShine v3.0+

### Support MoonShine versions

| MoonShine | Layouts |
|-------------|---------|
| 2.0+ | 1.0+ |
| 3.0+ | 2.0+ |

## Quick start

### Install
Expand Down Expand Up @@ -48,21 +59,24 @@ use MoonShine\Layouts\Casts\LayoutsCast;

class Article extends Model
{
protected $casts = [
'content' => LayoutsCast::class,
];
protected function casts(): array
{
return [
'content' => LayoutsCast::class,
];
}
}

Layouts::make('Content', 'content')
->addButton(ActionButton::make('New layout')->icon('heroicons.outline.plus')->primary())
->addButton(ActionButton::make('New layout')->icon('plus')->primary())
```
#### Customizing the button label

You can change the default "Add layout" button's text using the [ActionButton](https://moonshine-laravel.com/docs/resource/actionbutton/action_button?change-moonshine-locale=en#basics) component:
You can change the default "Add layout" button's text using the [ActionButton](https://moonshine-laravel.com/docs/3.x/components/action-button) component:

```php
Layouts::make('Content')
->addButton(ActionButton::make('New layout')->icon('heroicons.outline.plus')->primary())
->addButton(ActionButton::make('New layout')->icon('plus')->primary())
```
#### Adding search field
You can add search input in layout list as follows:
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
}
],
"require": {
"php": "^8.0|^8.1|^8.2",
"php": "^8.1|^8.2",
"ext-curl": "*",
"ext-json": "*"
},
"require-dev": {
"phpunit/phpunit": "^11.0",
"orchestra/testbench": "^9.0",
"rector/rector": "^1.0",
"moonshine/moonshine": "^2.20"
"moonshine/moonshine": "^3.0"
},
"autoload": {
"psr-4": {
Expand All @@ -38,7 +38,7 @@
}
},
"conflict": {
"moonshine/moonshine": "<2.11"
"moonshine/moonshine": "<3.0"
},
"scripts": {
"test": "vendor/bin/phpunit",
Expand Down
10 changes: 5 additions & 5 deletions resources/views/layouts.blade.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<div x-data="layouts(
`{{ $element->getAddRoute() }}`,
`{{ $element->column() }}`
`{{ $addRoute }}`,
`{{ $column }}`
)"
{{ $element->attributes() }}
{{ $attributes }}
data-top-level="true"
>
<div class="_layouts-blocks">
@foreach($element->getFilledLayouts() as $layout)
@foreach($fields as $layout)
{!! $layout !!}
@endforeach
</div>

<div>
{!! $element->getDropdown() !!}
{!! $dropdown !!}
</div>

<br />
Expand Down
6 changes: 3 additions & 3 deletions routes/moonshine.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
use Illuminate\Support\Facades\Route;
use MoonShine\Layouts\Http\Controllers\LayoutsController;

Route::group(moonshine()->configureRoutes(), static function (): void {
Route::post('/layouts/{pageUri}/{resourceUri?}', [LayoutsController::class, 'store'])
Route::moonshine(static function (): void {
Route::post('/layouts/{resourceUri?}', [LayoutsController::class, 'store'])
->name('layouts-field.store');
});
}, withPage: true, withAuthenticate: true);

2 changes: 1 addition & 1 deletion src/Contracts/LayoutContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Contracts\Support\Renderable;
use MoonShine\Fields\Fields;
use MoonShine\Laravel\Collections\Fields;
use Stringable;

interface LayoutContract extends Htmlable, Stringable, Renderable
Expand Down
28 changes: 14 additions & 14 deletions src/Fields/Layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@

use Illuminate\Contracts\View\View;
use Illuminate\Support\Traits\Conditionable;
use MoonShine\ActionButtons\ActionButton;
use MoonShine\Components\FieldsGroup;
use MoonShine\Components\FlexibleRender;
use MoonShine\Components\Icon;
use MoonShine\Decorations\Flex;
use MoonShine\Fields\Field;
use MoonShine\Fields\Fields;
use MoonShine\Fields\Position;
use MoonShine\Fields\Preview;
use MoonShine\Contracts\UI\ActionButtonContract;
use MoonShine\Laravel\Collections\Fields;
use MoonShine\Layouts\Contracts\LayoutContract;
use MoonShine\UI\Components\FieldsGroup;
use MoonShine\UI\Components\FlexibleRender;
use MoonShine\UI\Components\Icon;
use MoonShine\UI\Components\Layout\Flex;
use MoonShine\UI\Fields\Field;
use MoonShine\UI\Fields\Position;
use MoonShine\UI\Fields\Preview;
use Throwable;

final class Layout implements LayoutContract
{
use Conditionable;

private ?ActionButton $removeButton = null;
private ?ActionButtonContract $removeButton = null;

private int $key = 0;

Expand Down Expand Up @@ -117,7 +117,7 @@ public function headingFields(): Fields
return Fields::make([
Flex::make(array_filter([
$this->disableSort ? null : Preview::make(
formatted: static fn () => Icon::make('heroicons.outline.bars-4')
formatted: static fn () => Icon::make('bars-4')
)
->withoutWrapper()
->customAttributes(['class' => 'handle', 'style' => 'cursor: move']),
Expand Down Expand Up @@ -149,7 +149,7 @@ public function fields(): Fields

if ($this->isForcePreview) {
$this->fields->onlyFields()
->map(fn (Field $f): Field => $f->forcePreview());
->map(fn (Field $f): Field => $f->previewMode());
}


Expand All @@ -168,14 +168,14 @@ public function getHeadingAdditionalFields(): Fields
return $this->headingAdditionalFields;
}

public function removeButton(?ActionButton $button): self
public function removeButton(?ActionButtonContract $button): self
{
$this->removeButton = $button;

return $this;
}

public function getRemoveButton(): ?ActionButton
public function getRemoveButton(): ?ActionButtonContract
{
return $this->removeButton;
}
Expand Down
Loading

0 comments on commit 3b7a94f

Please sign in to comment.