Overlay
import {Overlay} from 'cx/widgets';Overlays are page elements displayed on top of the main UI. Overlays 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.
Use the
styleproperty to control the position on the page.
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.
Use the inline property to specify if the overlay should be rendered inline or appended to the body
element.
Note that inline overlays have z-index set to a very high value to get on top of the content.
<div class="widgets">
<Checkbox value-bind="$page.overlay">Show Overlay</Checkbox>
<Overlay visible-bind="$page.overlay" style={{background: 'yellow', padding: '30px'}} draggable>
This is a draggable overlay.
</Overlay>
</div>Independent overlays are explicitly opened and will remain visible until explicitly closed.
Independent overlays start their own application loop and require the store parameter.
If a new store instance is passed, the overlay will be completely disconnected from the main UI.
var addOverlay = store => {
var overlay = Overlay.create(<cx>
<Overlay style={{
left: Math.random()*100+'%',
top: Math.random()*100+'%',
padding: '30px',
border: '2px solid gray',
background: '#efefef',
textAlign: 'center'
}}>
This overlay will automatically close after 5s.
</Overlay>
</cx>);
var close = overlay.open(store);
setTimeout(close, 5000);
};
...
<Button
onClick={(e, {store}) => { addOverlay(store); }}>
Add Overlay
</Button>
HINTSwitch to another article, while both types of overlays are visible, and then return back to this page.
Configuration
| Property | Description | Type |
|---|---|---|
backdrop | Set to | boolean |
center | Set to | boolean |
closeOnEscape | Set to | boolean |
inline | Set to | boolean |
modal | Set to | boolean |
animate | Set to | boolean |
autoFocus | Set to | boolean |
autoFocusFirstChild | Set to | boolean |
baseClass | Base CSS class to be applied to the field. Defaults to | string |
centerX | Set to | boolean |
centerY | Set to | boolean |
class | Additional CSS classes to be applied to the element. If an object is provided, all keys with a "truthy" value will be added to the CSS class list. | string/object |
containerStyle | Style to be applied to the overlay's container element. | string |
destroyDelay | Number of milliseconds to wait, before removing the element from the DOM. Used in combination with the | number |
dismissOnFocusOut | Set to | boolean |
dismissOnPopState | Set to | boolean |
draggable | Set to | boolean |
focusable | Set to true to make the top level overlay element focusable. | boolean |
items | List of child elements. | array |
layout | Define an inner layout. | string/object |
mod | Appearance modifier. For example, | string/array |
onMove | A callback function which fires while the overlay is being moved around. | function |
onResize | A callback function which fires while the overlay is being resized. | function |
outerLayout | Defines the outer layout which wraps the widget. | widget |
plainText | Set to | boolean |
preserveWhitespace | Keep whitespace in text based children. Default is | boolean |
putInto | Used with outer layouts. Specifies the name of the content placeholder which should render the widget. | string |
resizable | Set to | boolean |
resizeWidth | resizeWidth | number |
style | Style object applied to the wrapper div. Used for setting the dimensions of the element. | string/object |
trimWhitespace | Remove all whitespace in text based children. Default is | boolean |
vdomKey | Key that will be used as the key when rendering the React component. | string |
visible | Visibility of the widget. Defaults to | boolean |
zIndex | zIndex | number |