CxJS

Overlay

import { Overlay } from 'cx/widgets'; Copied

Overlays are page elements displayed on top of the main UI. They include windows, message boxes, dropdowns, tooltips, etc. Overlays may be defined in the widget tree context or opened independently. In either case, overlays are appended inside the body element.

Contextual Overlays

Contextual overlays are defined inside the widget tree and controlled using the visible property. A contextual overlay will not be shown unless its parent is visible.

<div>
  <Checkbox value={m.showOverlay}>Show Overlay</Checkbox>
  <Overlay
    visible={m.showOverlay}
    style={{ background: "yellow", padding: "30px" }}
    draggable
  >
    This is a draggable overlay.
  </Overlay>
</div>

Use the style property to control the position on the page. Use inline to render the overlay inline instead of appending to the body element.

Independent Overlays

Independent overlays are explicitly opened and remain visible until explicitly closed. They start their own application loop and require a store parameter.

<Button
  onClick={(e, { store }) => {
    let overlay = Widget.create(
      <Overlay
        style={{
          left: Math.random() * 50 + 25 + "%",
          top: Math.random() * 50 + 25 + "%",
          padding: "30px",
          border: "2px solid gray",
          background: "#efefef",
          textAlign: "center",
        }}
      >
        This overlay will automatically close after 3s.
      </Overlay>,
    )

    let close = overlay.open(store)
    setTimeout(close, 3000)
  }}
>
  Add Overlay
</Button>

The open method returns a close function that can be called to dismiss the overlay.

Configuration

PropertyTypeDescription
visiblebooleanControls overlay visibility for contextual overlays.
modalbooleanAdds a modal backdrop that masks mouse events for the rest of the page.
backdropbooleanAdds a backdrop that dismisses the overlay when clicked.
centerbooleanInitially places the overlay in the center of the page.
draggablebooleanEnables dragging the overlay.
resizablebooleanEnables resizing the overlay.
inlinebooleanForces the overlay to render inline instead of appending to body.
closeOnEscapebooleanCloses the overlay when Escape key is pressed.
dismissOnFocusOutbooleanDismisses the overlay when it loses focus.
dismissOnPopStatebooleanDismisses the overlay if the user presses the browser back button.
animatebooleanAppends the animate state after initial render for CSS animations.
destroyDelaynumberMilliseconds to wait before removing from DOM (use with animate).
autoFocusbooleanAutomatically focuses the overlay when shown.
autoFocusFirstChildbooleanAutomatically focuses the first child element when shown.
zIndexnumberCustom z-index value for the overlay.