wire-elements / modal

Livewire component that provides you with a modal that supports multiple child modals while maintaining state.
MIT License
1.12k stars 131 forks source link

Note on Namespacing #28

Closed roni-estein closed 3 years ago

roni-estein commented 3 years ago

Not sure if you are interested in PR's to the README, but I was thrown for a couple of minutes when setting up this package initially, so here are some notes I took and forgot to pass on. 😳

It's sometimes easier to edit material than to generate it all. So her are some is a quick issue that is you can take and edit or toss for your docs.

A Note on Namespacing

There will undoubtedly be developers who are working in organizations that allow them access to update a users profile for example. In the case where a persons rights are restricted to only updating certain fields it makes sense that only those fields show up in a modal. There are 2 easy workarounds for this.

  1. Adding some basic laravel livewire if/elses in your component. This is self evident, and really does not need an explanation but can become bulky if you have multiple authorization levels that have differing rights.

  2. A clearer and simpler approach might be to make 2 EditUser Modals. 1 for example for the user themselves that allows them to update their personal fields. And another for staff to update specific details about that user like a ban or some access that the user themselves is not allowed to touch.

Now you can always Just add EditUser and StaffEditUser but this might become bulky over time depending on the size of the project that uses it. One of the things that I do once things get larges it namespace them. So Instead generating an EditUser and a Staff/EditUser and others. In general if you have lots of modals you may want to namespace them in a Modals directory so either way here are some gotchas that might be helpful.

  1. when you are emitting an event directories in livewire are named as views so in the case of the component Modals/Staff/EditUser you need to change your call to:
 wire:click="$emit('openModal','modals.staff.edit-user', {{ json_encode([$user->id]) }})"

If you have a non-standard binding of view to component you can easily generate a list of your registered components by running this command in tinker;

app('Livewire\LivewireComponentsFinder')->getManifest();
PhiloNL commented 3 years ago

Thanks! I will add a namespace example to the docs 🙌