Problem
Build a reusable popup/modal plugin driven by an options object.
const options = {
contentHTML: "HTMLString | Promise",
onContentClick: () => {},
showClose: true,
positiveCTA: { text: "OK", onClick: () => {} },
negativeCTA: { text: "Cancel", onClick: () => {} },
// Follow-ups
animateOnOpen: true,
backgroundOpacity: 0.5,
priority: 1,
closeOthers: false,
};
Requirements
- Render content (string or a Promise that resolves to content — show a loader until resolved).
- Optional close button and positive/negative CTAs with click handlers.
- Backdrop with configurable opacity; clicking content fires
onContentClick.
Follow-ups / Hints
- Animate on open, configurable backdrop opacity.
- Priority queue: if multiple popups are requested, show the highest
priorityfirst and queue the rest;closeOthersdismisses currently open popups. - Implementation: a singleton popup manager holding a queue;
open(options)enqueues by priority, renders the top one, and on close pops the next. Use a portal to render at the document root and trap focus for accessibility.