Skip to content

useOverlay: bind emits on overlay instances #5233

@edimitchel

Description

@edimitchel

Package

v4.x

Description

Modals which have presentation responsibility will emits events to make the host change its state or behave with http requests, and so and so update props.

useOverlay could help to listen emit events by defining them on create method.

Instead of:

const myModal = overlay.create(MyModalComponent);
myModal.open({
  myProps,
  onClose: myModal.close,
  onDelete: handleDelete,
});

Doing this:

const myModal = overlay.create(
  MyModalComponent,
);
myModal.on('close', myModal.close);
myModal.on('delete', handleDelete);
// OR
myModal.on({
  close: myModal.close,
  delete: handleDelete
});


// ...

myModal.open({
  myProps,
});

Simple alternative would permits partial props on second create method argument (which currently waits for all required props).
One another idea about this alternative is that all required props assigned on create would be set as optional on the open method as it's been already defined. This could be helpful for static props.

Additional context

I use useOverlay with a modal which don't have inner state except props.

Metadata

Metadata

Labels

enhancementNew feature or requesttriageAwaiting initial review and prioritizationv4#4488

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions