The user wants a plan for a "UI overlay orchestration" system.
The main goal is to prevent the "stacking" of UI elements like modals, toasts, and drawers.
The system needs specific "arbitration rules" to decide what happens when multiple requests occur.
This is a software architecture/design question, not a request for code generation alone, but rather a conceptual plan with likely some structural examples.
Decision: Dismiss Low priority modal, show Critical.
Scenario C: Toast showing -> Drawer opens.
Decision: Drawer takes focus. Toast might stay or be dismissed depending on UI style.
6. Drafting the Plan Structure:
Phase 1: The Mental Model (Architecture): Explain the centralized registry.
Phase 2: The Priority System (Z-Index & Logic): Define the hierarchy.
Phase 3: The Arbitration Logic (The "Brain"): The specific rules (Pre-emption, Queuing, Denying).
Phase 4: Implementation Strategy (Technical): React Context or Zustand/Redux example.
Phase 5: Edge Case Handling: Accessibility (focus trapping), Animations.
7. Refining the Rules (Self-Correction):
Initial thought: Just use z-index.
Correction: No, z-index just stacks visual layers. It doesn't solve interaction blocking. If a modal is open, you shouldn't open a drawer that steals focus unless it's critical. The Orchestrator must prevent the render or state conflict, not just visual overlap.
Refined Rule: "One High-Focus element at a time." Toasts can exist alongside High-Focus elements but need high z-index.
8. Structuring the Output:
Use clear headings.
Use a table for the rules.
Provide a conceptual code snippet for the logic engine.
Address UX (User Experience) implications.
9. Detailed Logic for "Arbitration":
Let's define "Lanes".
Lane 1: High Focus (Modals, Drawers). Limit: 1.
Lane 2: Notification (Toasts). Limit: 3 (stacked vertically).
Lane 3: System (OS-level, crash reports). Limit: 1.
10. Final Polish:
Make sure to mention Focus Management (a11y).
Mention Animation locking (don't animate out while animating in unless forced).
(Self-Correction during drafting): Should I include code? Yes, a pseudo-code logic block helps clarify the abstract concepts.
Summary of the Plan:
Architecture: Global Singleton/Context.
Prioritization: Integer-based ranking.
Conflict Rules: Matrix of interactions (Modal vs Modal, Toast vs Modal).
Implementation: State machine approach.
Let's write this out clearly.
To prevent the chaotic user experience of "Z-index fighting" (where modals cover toasts, drawers block modals, and everything becomes unreadable), you need a Centralized Overlay Orchestrator.
This system moves overlay management from individual components (imperative calls) to a global state manager (declarative queue).
Here is the architectural plan for the Orchestration Layer, including priority definitions, arbitration rules, and implementation strategies.
1. The Mental Model: The "TV Station"
Imagine your UI is a TV broadcast.
The Stack (State): A queue of "shows" waiting to air.
The Director (Orchestrator): Decides what goes on screen based on importance.
The Screen (Outlet): A single high-level container where overlays are rendered.
2. The Priority Hierarchy (Precedence)
We must assign numerical weights to different overlay types. Higher numbers beat lower numbers.
Level
Type
Category
Behavior
100
System Critical
Force Update, Session Expired
Blocking. Cannot be dismissed by other UI interactions. Halts all lower logic.
80
High-Focus Modal
Delete Confirmation, Privilege Escalation
Blocking. Must be resolved before returning to normal flow.
60
Standard Overlay
Standard Modal, Full-screen Drawer
Interruptible. Can be minimized or forced closed by a Level 100 event.
40
Transient Notification
Toasts, Snackbars
Non-blocking. Stacks visually, but respects z-index clearance.
20
Popover / Tooltip
Dropdowns, Hover cards
Ephemeral. Auto-dismiss on any outside click or scroll.
3. The Arbitration Rules
When a new overlay request is dispatched, the Orchestrator runs it through these rules before rendering.
Rule 1: Exclusive High-Focus (The "One Modal" Rule)
Logic: Only one High-Focus or Standard Overlay can occupy the "Primary Slot" at a time.
Conflict: If a Modal (60) is open, and a new Modal (60) is requested.
Resolution:
Option A (Strict): Reject the new request and log a warning.
Option B (Replacement): Automatically dismiss the current Modal (firing its onClose callback) and immediately mount the new one.
Recommended:Option B (Replacement) for better UX flow.
Rule 2: Supremacy Override (The "Emergency" Rule)
Logic: System Critical events (100) always win.
Conflict: User is editing a Modal (60), and the session times out (100).
Resolution: Immediately unmount the Edit Modal and mount the Session Expired Modal. The Edit Modal state should ideally be preserved (minimized) or discarded based on business logic.
Rule 3: Transient Stacking (The "Toast" Rule)
Logic: Toasts (40) do not interact directly with Modals (60+) regarding space, but they do regarding Z-Index.
Conflict: A Toast appears while a Modal is open.
Resolution: Render the Toast inside the Overlay Container but visually distinct. Do not stack Modals, but do stack Toasts (limit 3 visible).
Rule 4: Drawer Collision
Logic: Drawers usually take up screen real estate (left/right).
Conflict: Drawer A is open (left). Request comes for Drawer B (left).
Resolution: Close Drawer A -> Open Drawer B. If Drawer B is on the opposite side, allow both open simultaneously only if UX permits.
4. Technical Implementation Strategy
We will use a Reactive Store (Redux, Zustand, or React Context) to hold the queue.
A. The Data Structure (The Queue)
We don't just store components; we store "Requests".
typescript
type OverlayType = 'MODAL' | 'DRAWER' | 'TOAST' | 'SYSTEM';
type OverlayPriority = 20 | 40 | 60 | 80 | 100;
interface OverlayRequest {
id: string; // Unique ID for React keys
type: OverlayType;
priority: OverlayPriority;
component: React.ComponentType<any>;
props: Record<string, any>;
// Callback to notify the caller if they were preempted
onDismissBySystem?: () => void;
}
// State Shape
interface OverlayState {
activeQueue: OverlayRequest[]; // Sorted by Priority
}
B. The Orchestrator Logic (Reducer/Action)
When dispatch(showModal, ...) is called:
Assess Priority: Determine the weight of the incoming request.
Clean Up: Check the activeQueue.
If the incoming request is a Singleton Type (Modal/Drawer)...
...Find any existing item in the queue with type === 'MODAL' or type === 'DRAWER'.
If the existing item has a lower or equal priority, trigger its onDismissBySystem and remove it from the queue.
Insert: Add the new request to the queue.
Render: The UI component observes the activeQueue and renders the last item (or specific stacking logic for toasts).
C. The UI Outlet (The Container)
You need a top-level component, usually at the root of your app (above the Router).
Trap: When a Modal (60+) is active, focus is trapped inside that component (using aria-modal="true" and a focus-trap library).
Return Focus: When the Orchestrator dismisses a component (via arbitration or user close), focus must return to the element that triggered it.
The "Soft Dismiss" vs. "Hard Kill"
Sometimes an overlay shouldn't just be unmounted instantly by arbitration; it might need to save data.
Hard Kill (System Critical): The component is unmounted immediately.
Soft Dismiss (Standard): The Orchestrator calls props.onClose() first, allowing the Modal to clean up (e.g., "Are you sure you want to discard changes?") before actually removing it from the queue.
6. Summary Checklist
Define Priorities: Assign integer values to every overlay type.
Create Global Store: A single source of truth for all overlay requests.
Implement Arbiter: Logic that compares incoming requests vs. active items.
Singleton Enforcement: Ensure only one "Modal" slot is active at a time (unless specific layout needs permit otherwise).
Auto-Dismissal: Logic to clean up lower-priority items when high-priority items arrive.