# Migration Guidelines Overlay System If you are still using the old overlay system, we encourage you to migrate. The new way is more reliable, less error-prone and a lot easier to maintain. In addition, we now have a web component `lion-dialog` which is a declarative way of adding a modal dialog inside your template! ## Declaratively (encouraged) Using generic `lion-overlay`: ```js import { withBottomSheetConfig } from '@lion/overlays'; import '@lion/overlays/lion-overlay.js'; const template = html`
Hello, World!
`; ``` Or using a more specific component like `lion-tooltip`, which toggles on-hover: ```js import '@lion/tooltip/lion-tooltip.js'; const template = html`
Hello, World!
`; ``` Or `lion-dialog` which uses modal dialog configuration defaults ```js import '@lion/dialog/lion-dialog.js'; const template = html`
Hello, World!
`; ``` ## Instantiating an overlay controller (discouraged) ### Old ```js import { overlays, GlobalOverlayController } from '@lion/overlays'; const ctrl = overlays.add( new GlobalOverlayController({ contentTemplate: () => html`
My content
`, }), ); const template = html` Open dialog `; ``` ### New > Note: The OverlayController is render-system agnostic, you are responsible for passing a node (and rendering it prior). > For lit-html, we will use a simple helper. Let us know if you think we should export this. ```js import { render } from '@lion/core'; function renderOffline(litHtmlTemplate) { const offlineRenderContainer = document.createElement('div'); render(litHtmlTemplate, offlineRenderContainer); return offlineRenderContainer.firstElementChild; } ``` This example shows how you can use our configuration generators. ```js import { OverlayController, withModalDialogConfig } from '@lion/overlays'; const ctrl = new OverlayController({ ...withModalDialogConfig(), contentTemplate: renderOffline(html`
My content
`), }); const template = html` Open dialog `; ``` ### New (local example) ```js import { OverlayController } from '@lion/overlays'; const ctrl = new OverlayController({ ...withModalDialogConfig(), placementMode: 'local', hidesOnEsc: true, hidesOnOutsideClick: true, contentNode: renderOffline(html`
United Kingdom
`), invokerNode: renderOffline(html` `), }); const template = html`
In the ${ctrl.invoker}${ctrl.content} the weather is nice.
`; ```