forked from web-padawan/aybolit
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cxl-ui): [cxl-dialog] add more implementations
- Loading branch information
Showing
7 changed files
with
258 additions
and
21 deletions.
There are no files selected for viewing
80 changes: 80 additions & 0 deletions
80
packages/cxl-ui/src/components/cxl-dialog/cxl-dialog-custom.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { css, html, LitElement } from 'lit'; | ||
import { customElement, property } from 'lit/decorators.js'; | ||
|
||
@customElement('cxl-dialog-custom') | ||
export class CXLDialog extends LitElement { | ||
@property({ reflect: true, type: Boolean }) opened; | ||
|
||
static get styles() { | ||
return css` | ||
:host { | ||
padding: 1rem; | ||
position: absolute; | ||
inset: 0; | ||
} | ||
:host(:not([opened])) { | ||
display: none; | ||
} | ||
[part='backdrop'] { | ||
background: rgba(0, 0, 0, 0.5); | ||
background-color: var(--lumo-shade-20pct); | ||
animation: 0.2s lumo-overlay-backdrop-enter both; | ||
will-change: opacity; | ||
position: absolute; | ||
inset: 0; | ||
} | ||
[part='overlay'] { | ||
border-radius: var(--lumo-border-radius-l); | ||
box-shadow: 0 0 0 1px var(--lumo-shade-5pct), var(--lumo-box-shadow-xl); | ||
background-image: none; | ||
outline: none; | ||
-webkit-tap-highlight-color: transparent; | ||
background-color: var(--lumo-base-color); | ||
background-image: linear-gradient(var(--lumo-tint-5pct), var(--lumo-tint-5pct)); | ||
border-radius: var(--lumo-border-radius-m); | ||
box-shadow: 0 0 0 1px var(--lumo-shade-5pct), var(--lumo-box-shadow-m); | ||
color: var(--lumo-body-text-color); | ||
font-family: var(--lumo-font-family); | ||
font-size: var(--lumo-font-size-m); | ||
font-weight: 400; | ||
line-height: var(--lumo-line-height-m); | ||
letter-spacing: 0; | ||
text-transform: none; | ||
-webkit-text-size-adjust: 100%; | ||
-webkit-font-smoothing: antialiased; | ||
-moz-osx-font-smoothing: grayscale; | ||
position: relative; | ||
overflow: visible; | ||
max-height: 100%; | ||
display: flex; | ||
-webkit-overflow-scrolling: touch; | ||
overflow: auto; | ||
pointer-events: auto; | ||
max-width: 100%; | ||
box-sizing: border-box; | ||
-webkit-tap-highlight-color: initial; | ||
} | ||
`; | ||
} | ||
|
||
render() { | ||
console.log(this.opened); | ||
return html` | ||
<div part="backdrop"></div> | ||
<div part="overlay"><slot>${this.opened}</slot></div> | ||
`; | ||
} | ||
|
||
firstUpdated() { | ||
document.addEventListener('keydown', this.onKeyDown.bind(this)); | ||
} | ||
|
||
onKeyDown(e) { | ||
if (e.key === 'Escape') { | ||
this.opened = false; | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
packages/cxl-ui/src/components/cxl-dialog/cxl-dialog-iframe.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { html, LitElement } from 'lit'; | ||
import { customElement, query } from 'lit/decorators.js'; | ||
import '@vaadin/dialog'; | ||
|
||
@customElement('cxl-dialog-iframe') | ||
export class CXLDialogIFrame extends LitElement { | ||
@query('iframe') iframe; | ||
|
||
render() { | ||
return html`<iframe src="about:blank"></iframe>`; | ||
} | ||
|
||
firstUpdated() { | ||
this.iframe.srcdoc = ` | ||
<vaadin-dialog opened></vaadin-dialog> | ||
<script> | ||
const parentWindow = window.parent; | ||
document.querySelectorAll(":not(:defined)").forEach(el => | ||
customElements.define( | ||
el.localName, | ||
parentWindow.customElements.get(el.localName) | ||
) | ||
) | ||
</script> | ||
`; | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import '@conversionxl/cxl-ui/src/components/cxl-dialog/cxl-dialog-custom.js'; | ||
import { html } from 'lit'; | ||
|
||
export default { | ||
title: 'CXL UI/cxl-dialog', | ||
}; | ||
|
||
// eslint-disable-next-line no-empty-pattern | ||
const Template = ({ opened }) => html` | ||
<style> | ||
#root-inner { | ||
align-items: center; | ||
justify-content: center; | ||
display: flex; | ||
height: 100vh; | ||
} | ||
#container { | ||
border: 1px solid #000; | ||
height: 80vh; | ||
position: relative; | ||
width: 80vw; | ||
} | ||
</style> | ||
<div id="container"> | ||
<cxl-dialog-custom ?opened=${opened} ?test=${opened}>This is some content</cxl-dialog-custom> | ||
</div> | ||
`; | ||
|
||
export const Custom = Template.bind({}); | ||
|
||
Object.assign(Custom, { | ||
args: { | ||
opened: true, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import '@conversionxl/cxl-ui/src/components/cxl-dialog/cxl-dialog-vaadin.js'; | ||
import { html, render } from 'lit'; | ||
|
||
export default { | ||
title: 'CXL UI/cxl-dialog', | ||
}; | ||
|
||
// eslint-disable-next-line no-empty-pattern | ||
const Template = ({ opened }) => html` | ||
<style> | ||
#root-inner { | ||
align-items: center; | ||
justify-content: center; | ||
display: flex; | ||
height: 100vh; | ||
} | ||
#container { | ||
border: 1px solid #000; | ||
height: 80vh; | ||
position: relative; | ||
width: 80vw; | ||
} | ||
</style> | ||
<div id="container"> | ||
<cxl-dialog-vaadin | ||
contained | ||
.headerRenderer=${(root, dialog) => | ||
render( | ||
html` | ||
<vaadin-button theme="tertiary" @click="${() => (dialog.opened = false)}"> | ||
<vaadin-icon icon="lumo:cross"></vaadin-icon> | ||
</vaadin-button> | ||
`, | ||
root | ||
)} | ||
header-title="Custom Header" | ||
?opened=${opened} | ||
.renderer=${(root) => render(html`This is a dialog`, root)} | ||
></cxl-dialog-vaadin> | ||
</div> | ||
`; | ||
|
||
export const Default = Template.bind({}); | ||
|
||
Object.assign(Default, { | ||
args: { | ||
opened: true, | ||
}, | ||
}); |