-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #6649 Add a new Twig component to create Action Menus (javier…
…eguiluz) This PR was squashed before being merged into the 4.x branch. Discussion ---------- Add a new Twig component to create Action Menus This is the first anonymous Twig Component that we added to the project. It's modeled after GitHub's `ActionMenu` component (https://primer.style/components/action-menu) and allows to create dropdowns. Sadly, using this component means that we lost the `{% block user_menu %}...{% endblock %}` TWig block in the template. This is because I can't make it work with the new Twig component. If anybody knows how to keep that block, please tell me. Thanks! ----- Again, this was possible thanks to the excellent article written by `@yceruto` in https://dev.to/yceruto/bundling-your-symfony-ux-twig-components-4997 Just a quick comment for `@yceruto`. In this section: https://dev.to/yceruto/bundling-your-symfony-ux-twig-components-4997#bundling-uionly-components you propose to use this: ```php $builder->prependExtensionConfig('twig', [ 'paths' => [ 'templates/bundles/AcmeBundle/' => null, dirname(__DIR__).'/templates/' => null, ], ]); ``` This didn't work for me because the application that installs the bundle might not have defined the `templates/bundles/AcmeBundle/` dir. Maybe I'm doing something wrong ... but in any case, I updated it as follows: ```php $bundleTemplatesOverrideDir = $builder->getParameter('kernel.project_dir').'/templates/bundles/EasyAdminBundle/'; $builder->prependExtensionConfig('twig', [ 'paths' => is_dir($bundleTemplatesOverrideDir) ? [ 'templates/bundles/EasyAdminBundle/' => null, dirname(__DIR__).'/../templates/' => 'ea', ] : [ dirname(__DIR__).'/../templates/' => 'ea', ], ]); ``` Commits ------- da8ece2 Add a new Twig component to create Action Menus
- Loading branch information
Showing
20 changed files
with
216 additions
and
112 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,7 @@ | ||
{# ActionMenu is a component to create dropdowns of related actions. | ||
It defines several sub-components (Overlay, ActionList, etc.) | ||
Inspired by https://primer.style/components/action-menu | ||
#} | ||
<div {{ attributes.defaults({class: 'dropdown'}) }}> | ||
<twig:block name="content"></twig:block> | ||
</div> |
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,3 @@ | ||
<ul {{ attributes.defaults({class: 'dropdown-menu dropdown-menu-end'}) }}> | ||
<twig:block name="content"></twig:block> | ||
</ul> |
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,3 @@ | ||
<li {{ attributes }}> | ||
<twig:block name="content"></twig:block> | ||
</li> |
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 @@ | ||
<li class="dropdown-divider"></li> |
13 changes: 13 additions & 0 deletions
13
templates/components/ActionMenu/ActionList/Header.html.twig
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,13 @@ | ||
{% props | ||
label = null, | ||
renderLabelRaw = false, | ||
icon = null, | ||
htmlAttributes = {}, | ||
%} | ||
|
||
{% if label is not empty or icon is not empty %} | ||
<li {{ attributes.defaults({class: 'dropdown-header'}|merge(htmlAttributes)) }}> | ||
{%- if icon %}<twig:ea:Icon {{ ...attributes.nested('icon').defaults({name: icon}) }} /> {% endif -%} | ||
{%- if label is not empty -%}<span {{ attributes.nested('label') }}>{{ renderLabelRaw ? label|raw : label }}</span>{%- endif -%} | ||
</li> | ||
{% endif %} |
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,14 @@ | ||
{% props | ||
label = null, | ||
renderLabelRaw = false, | ||
icon = null, | ||
url = null, | ||
htmlAttributes = {}, | ||
%} | ||
|
||
<li> | ||
<a {{ attributes.defaults({class: 'dropdown-item', href: url}|merge(htmlAttributes)) }}> | ||
{%- if icon %}<twig:ea:Icon {{ ...attributes.nested('icon').defaults({name: icon}) }} /> {% endif -%} | ||
{%- if label is not empty -%}<span {{ attributes.nested('label') }}>{{ renderLabelRaw ? label|raw : label }}</span>{%- endif -%} | ||
</a> | ||
</li> |
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,12 @@ | ||
{% props | ||
withoutDropdownToggleMarker = false, | ||
%} | ||
|
||
{% set css_class = html_classes( | ||
'dropdown-toggle', | ||
{ 'dropdown-toggle-hidden-marker': withoutDropdownToggleMarker } | ||
) %} | ||
|
||
<a {{ attributes.defaults({class: css_class, href: '#', role: 'button', 'data-bs-toggle': 'dropdown', 'aria-haspopup': 'true', 'aria-expanded': 'false'}) }}> | ||
<twig:block name="content"></twig:block> | ||
</a> |
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,3 @@ | ||
<div {{ attributes.defaults({class: 'dropdown-overlay'}) }}> | ||
<twig:block name="content"></twig:block> | ||
</div> |
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
Oops, something went wrong.