Modal
Modal copied to clipboard
Generic ModalParameters
This PR adds a new class, ModalParameters<TComponent>, which inherits from the standard ModalParameters, and uses the generic parameter to allow for lambda expression initialization of parameters. It maintains all existing functionality for backward compatibility.
Existing way of showing a modal:
var parameters = new ModalParameters();
parameters.Add(nameof(DisplayMessage.Message), _message);
var messageForm = Modal.Show<DisplayMessage>("Passing Data", parameters);
New way of showing a modal:
var parameters = new ModalParameters<DisplayMessage>();
parameters.Add(component => component.Message, _message);
var messageForm = Modal.Show("Passing Data", parameters);
Additionally, the new type implements IEnumerable, allowing for inline declaration of parameters if you prefer:
var parameters = new ModalParameters<DisplayMessage>
{
{ component => component.Message, _message} // or { nameof(DisplayMessage.Message), _message}
};
var messageForm = Modal.Show("Passing Data", parameters);
Finally, the sample code on PassDataToModal was displaying the incorrect code, so it has been fixed as part of this PR.
Hi @GravlLift,
Thanks for the PR.
I think the general idea of this is good, but maybe it would be better to first open an issue about this so we can discuss about the design. I'll leave that up to @chrissainty though.
If we do go ahead with this PR, I have some small comments about the actual code. I'll add those later.
Apologies for taking some time to get to this. I think this would be a nice addition to the library. It gives developers another option without breaking existing functionality, which is always nice.
I'd echo what @larsk2009 has said about opening an issue first though. In this case, the feature is something we'd like to add. But it might not have been and a quick issue discussions just saves everyones time.
@larsk2009 do you want to add your review. Then we can move forward with this.
With regards to the issue opening, that seems like something to include in the upcoming contributor guide.
Sorry for taking so long. My main comment is this: Could you maybe remove the changes from the PR that have nothing to do with the feature you want to add (like changes to the readme or changes with spaces or other formatting in unrelated files)? That way we keep it focused and can easily see who changed what.
We will make sure to add this to the upcoming contributor guide, but I still think it is a good idea to already do this in this PR.
I'm closing this PR due to lack of activity