feat(overlays): add before-show event to OverlayMixin

This commit is contained in:
Joren Broekema 2019-11-27 08:46:51 +01:00 committed by Thomas Allmer
parent 45f557183d
commit 57a3c04873
2 changed files with 32 additions and 0 deletions

View file

@ -36,6 +36,9 @@ export const OverlayMixin = dedupeMixin(
} }
set opened(show) { set opened(show) {
if (show) {
this.dispatchEvent(new Event('before-show'));
}
this._opened = show; // mainly captured for sync on connectedCallback this._opened = show; // mainly captured for sync on connectedCallback
if (this._overlayCtrl) { if (this._overlayCtrl) {
this.__syncOpened(); this.__syncOpened();

View file

@ -323,6 +323,35 @@ storiesOf('Overlay System | Overlay as a WC', module)
</div> </div>
`; `;
}) })
.add(
'Responsive switching',
() => html`
<style>
${overlayDemoStyle}
</style>
<lion-demo-overlay
.config=${{ ...withBottomSheetConfig() }}
@before-show=${e => {
if (window.innerWidth >= 600) {
e.target.config = { ...withModalDialogConfig() };
} else {
e.target.config = { ...withBottomSheetConfig() };
}
}}
>
<lion-button slot="invoker">Overlay</lion-button>
<div slot="content" class="overlay">
Hello! You can close this notification here:
<lion-button
class="close-button"
@click=${e =>
e.target.dispatchEvent(new Event('demo-overlay-close', { bubbles: true }))}
></lion-button
>
</div>
</lion-demo-overlay>
`,
)
.add('On hover', () => { .add('On hover', () => {
const popup = renderOffline(html` const popup = renderOffline(html`
<lion-demo-overlay <lion-demo-overlay