CRUD
CRUD copied to clipboard
add hide functionality to menu components
WHY
BEFORE - What was wrong? What was happening before this PR?
We've implemented menu components in https://github.com/Laravel-Backpack/CRUD/pull/5135/ . One nice feature Pedro mentioned was the ability to hide a component, upon a condition. For example, when a user is not an admin, hide a menu item.
AFTER - What is happening after this PR?
You can do exactly that, by using the :hidden attribute on all components we have:
<!-- Users, Roles Permissions -->
@php
$is_admin = true;
@endphp
<x-backpack::menu-dropdown title="Authentication" icon="la la-group" :hidden="$is_admin">
<x-backpack::menu-dropdown-item title="Users" icon="la la-user" :link="backpack_url('user')" />
<x-backpack::menu-dropdown-item title="Roles" icon="la la-group" :link="backpack_url('role')" />
<x-backpack::menu-dropdown-item title="Permissions" icon="la la-key" :link="backpack_url('permission')" />
</x-backpack::menu-dropdown>
HOW
How did you achieve that, in technical terms?
The hidden attribute can be:
- a
boolean - a
Closure
That gets evaluated, and if it's false the PHP Component itself won't even load the blade file. No HTML gets written on page.
Is it a breaking change?
No - it's non-breaking. No PRs to themes is necessary.
The PR is 100% working but... I don't really like it:
- I'm not 100% sure we should use
:hiddenand not:visibleas the component attribute name; - I'm not 100% sure we are accepting all variable types that devs might want;
- I'm not 100% sure we should do this in the first place, since a dev can easily wrap the
<x-something />into a conditional; so from this point of view we aren't adding any features, we're just polluting the components for something that can already be done, very easily;
For the reasons above, I'm not going to spend any more time on this right now. We have a launch to finish, so let's do that. This is a COULD/SHOULD and non-breaking, so let's postpone thinking or talking about this until after the launch.
I've proven with this PR that it can be done in a non-breaking way. And convinced myself that https://github.com/Laravel-Backpack/CRUD/pull/5135/ is worth merging right away. So this was useful, but merging it... meeeh.
Let's keep it simple.
Dev can wrap it in a conditional. 👍