Skip to content

Commit

Permalink
Kreyu#88 Create the DropdownActionType
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandre-castelain committed Jul 11, 2024
1 parent 29c330c commit 080bf6c
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 0 deletions.
15 changes: 15 additions & 0 deletions assets/controllers/dropdown.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import {Controller} from '@hotwired/stimulus'

export default class extends Controller {
static values = {
toggledClass: { type: String, default: 'show' },
}

static targets = [
'content',
];

toggle() {
this.contentTarget.classList.toggle(this.toggledClassValue)
}
}
5 changes: 5 additions & 0 deletions assets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
"main": "controllers/batch.js",
"fetch": "eager",
"enabled": true
},
"dropdown": {
"main": "controllers/dropdown.js",
"fetch": "eager",
"enabled": true
}
},
"importmap": {
Expand Down
24 changes: 24 additions & 0 deletions src/Action/Type/DropdownActionType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
declare(strict_types=1);

namespace Kreyu\Bundle\DataTableBundle\Action\Type;

use Kreyu\Bundle\DataTableBundle\Action\ActionInterface;
use Kreyu\Bundle\DataTableBundle\Action\ActionView;
use Symfony\Component\OptionsResolver\OptionsResolver;

class DropdownActionType extends AbstractActionType
{
public function buildView(ActionView $view, ActionInterface $action, array $options): void
{
$view->vars['actions'] = $options['actions'];
}

public function configureOptions(OptionsResolver $resolver): void
{
$resolver->define('actions')
->allowedTypes('array')
->required()
;
}
}
6 changes: 6 additions & 0 deletions src/Resources/config/actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Kreyu\Bundle\DataTableBundle\Action\ActionRegistryInterface;
use Kreyu\Bundle\DataTableBundle\Action\Type\ActionType;
use Kreyu\Bundle\DataTableBundle\Action\Type\ButtonActionType;
use Kreyu\Bundle\DataTableBundle\Action\Type\DropdownActionType;
use Kreyu\Bundle\DataTableBundle\Action\Type\FormActionType;
use Kreyu\Bundle\DataTableBundle\Action\Type\LinkActionType;
use Kreyu\Bundle\DataTableBundle\Action\Type\ResolvedActionTypeFactory;
Expand Down Expand Up @@ -60,4 +61,9 @@
->set('kreyu_data_table.action.type.form', FormActionType::class)
->tag('kreyu_data_table.action.type')
;

$services
->set('kreyu_data_table.action.type.dropdown', DropdownActionType::class)
->tag('kreyu_data_table.action.type')
;
};
20 changes: 20 additions & 0 deletions src/Resources/views/themes/base.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,26 @@
</form>
{% endblock %}
{% block action_dropdown_value %}
<style>
#linkList {
display: none;
}
#linkList.show {
display: block;
}
</style>
<div class="dropdown-container" data-controller="kreyu--data-table-bundle--dropdown">
<button id="toggleButton" data-action="kreyu--data-table-bundle--dropdown#toggle">{{- block('action_value', theme, _context) -}}</button>
<ul id="linkList" data-kreyu--data-table-bundle--dropdown-target="content">
<li><a href="https://example.com">Lien 1</a></li>
<li><a href="https://example.com">Lien 2</a></li>
<li><a href="https://example.com">Lien 3</a></li>
</ul>
</div>
{% endblock %}
{% block sort_arrow_none %}{% endblock %}
{% block sort_arrow_asc %}↑{% endblock %}
Expand Down

0 comments on commit 080bf6c

Please sign in to comment.