-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add docs for dropdown-related action types
- Loading branch information
Showing
4 changed files
with
177 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<script setup> | ||
import ActionTypeOptions from "./options/action.md"; | ||
</script> | ||
|
||
# DropdownActionType | ||
|
||
The [`DropdownActionType`](https://github.com/Kreyu/data-table-bundle/blob/main/src/Action/Type/DropdownActionType.php) represents an action rendered as a dropdown, where each item corresponds to separate action. | ||
|
||
## Options | ||
|
||
### `actions` | ||
|
||
- **type**: `array` or `callable` (if using as a row action) | ||
- **default**: `[]` | ||
|
||
An array of actions that will be rendered as dropdown items. | ||
Each action can be created using `createAction`, `createRowAction` or `createBatchAction` method, depending on the context: | ||
|
||
```php | ||
use Kreyu\Bundle\DataTableBundle\Action\Type\Dropdown\DropdownActionType; | ||
use Kreyu\Bundle\DataTableBundle\Action\Type\Dropdown\LinkDropdownItemActionType; | ||
|
||
$builder | ||
->addAction('advanced', DropdownActionType::class, [ | ||
'actions' => [ | ||
$builder->createAction('update', LinkDropdownItemActionType::class, [ | ||
'href' => '#' | ||
]), | ||
], | ||
]) | ||
; | ||
``` | ||
|
||
When using the `DropdownActionType` as a [row action](../../../docs/components/actions.md), you can provide a callable | ||
that will receive the row data as an argument and should return an array of actions. | ||
|
||
```php | ||
use Kreyu\Bundle\DataTableBundle\Action\Type\Dropdown\DropdownActionType; | ||
use Kreyu\Bundle\DataTableBundle\Action\Type\Dropdown\LinkDropdownItemActionType; | ||
|
||
$builder | ||
->addRowAction('advanced', DropdownActionType::class, [ | ||
'actions' => fn (Post $post) => [ | ||
$builder->createRowAction('update', LinkDropdownItemActionType::class, [ | ||
'href' => $this->urlGenerator->generate('post_update', [ | ||
'id' => $post->getId(), | ||
]), | ||
]), | ||
], | ||
]) | ||
; | ||
``` | ||
|
||
> [!TIP] | ||
> Although any action type can be used, rendering forms and buttons inside a dropdown may look weird. | ||
> Therefore, it is recommended to use [`LinkDropdownItemActionType`](link-dropdown-item.md) for dropdown items, | ||
> so it will be rendered properly as a simple link. | ||
## Inherited options | ||
|
||
<ActionTypeOptions/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<script setup> | ||
import ActionTypeOptions from "./options/action.md"; | ||
</script> | ||
|
||
# LinkDropdownItemActionType | ||
|
||
The [`LinkDropdownItemActionType`](https://github.com/Kreyu/data-table-bundle/blob/main/src/Action/Type/Dropdown/LinkDropdownItemActionType.php) | ||
represents an action rendered as dropdown item with a simple link. It is meant to be used as a child of the [`DropdownActionType`](dropdown.md). | ||
|
||
## Options | ||
|
||
### `href` | ||
|
||
- **type**: `string` or `callable` (if using as a row action) | ||
- **default**: `'#'` | ||
|
||
A value used as an action link [href attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attr-href). | ||
|
||
```php | ||
use Kreyu\Bundle\DataTableBundle\Action\Type\Dropdown\DropdownActionType; | ||
use Kreyu\Bundle\DataTableBundle\Action\Type\Dropdown\LinkDropdownItemActionType; | ||
|
||
$builder | ||
->addAction('advanced', DropdownActionType::class, [ | ||
'actions' => [ | ||
$builder->createAction('update', LinkDropdownItemActionType::class, [ | ||
'href' => fn (Post $post) => $this->urlGenerator->generate('post_update', [ | ||
'id' => $post->getId(), | ||
]), | ||
]), | ||
], | ||
]) | ||
; | ||
``` | ||
|
||
When using the `LinkDropdownItemActionType` as a [row action](../../../docs/components/actions.md), you can provide a callable | ||
that will receive the row data as an argument and should return an array of actions. | ||
|
||
```php | ||
use Kreyu\Bundle\DataTableBundle\Action\Type\Dropdown\DropdownActionType; | ||
use Kreyu\Bundle\DataTableBundle\Action\Type\Dropdown\LinkDropdownItemActionType; | ||
|
||
$builder | ||
->addRowAction('advanced', DropdownActionType::class, [ | ||
'actions' => [ | ||
$builder->createRowAction('update', LinkDropdownItemActionType::class, [ | ||
'href' => fn (Post $post) => $this->urlGenerator->generate('post_update', [ | ||
'id' => $post->getId(), | ||
]), | ||
]), | ||
], | ||
]) | ||
; | ||
``` | ||
|
||
### `target` | ||
|
||
- **type**: `string` or `callable` | ||
- **default**: `'_self'` | ||
|
||
Sets the value that will be used as an anchor [target attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attr-target). | ||
|
||
```php | ||
use Kreyu\Bundle\DataTableBundle\Action\Type\Dropdown\DropdownActionType; | ||
use Kreyu\Bundle\DataTableBundle\Action\Type\Dropdown\LinkDropdownItemActionType; | ||
|
||
$builder | ||
->addAction('preview', DropdownActionType::class, [ | ||
'actions' => [ | ||
$builder->createAction('render', LinkDropdownItemActionType::class, [ | ||
'href' => '#', | ||
'target' => '_blank', | ||
]), | ||
], | ||
]) | ||
; | ||
``` | ||
|
||
## Inherited options | ||
|
||
<ActionTypeOptions/> |