-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
1,099 additions
and
3,017 deletions.
There are no files selected for viewing
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,5 @@ | ||
--- | ||
'@remote-dom/core': patch | ||
--- | ||
|
||
Add `root` option to `DOMRemoteReceiver` |
Empty file.
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,62 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<body> | ||
<div id="root"></div> | ||
|
||
<iframe id="remote-iframe" src="/remote.html" hidden></iframe> | ||
|
||
<script type="module"> | ||
class UIBanner extends HTMLElement { | ||
connectedCallback() { | ||
// We will allow you to pass a `tone` attribute to the element, which | ||
// styles the banner according to our design system. We’ll see how to | ||
// use this in the remote environment in the next step. | ||
const tone = this.getAttribute('tone') ?? this.tone ?? 'neutral'; | ||
|
||
const root = this.attachShadow({mode: 'open'}); | ||
|
||
// We render a <slot> where we want the element’s children to go. | ||
root.innerHTML = ` | ||
<style> | ||
.Banner { | ||
padding: 1rem; | ||
border-radius: 0.4rem; | ||
background-color: lightgray; | ||
border: 1px solid gray; | ||
} | ||
.Banner--warning { | ||
background-color: #fff6de; | ||
border-color: #f5dab1; | ||
} | ||
</style> | ||
<div class="Banner Banner--${tone}"><slot></slot></div> | ||
`; | ||
} | ||
} | ||
|
||
customElements.define('ui-banner', UIBanner); | ||
</script> | ||
|
||
<script type="module"> | ||
import {DOMRemoteReceiver} from '@remote-dom/core/receiver'; | ||
|
||
const root = document.querySelector('#root'); | ||
const iframe = document.querySelector('#remote-iframe'); | ||
|
||
// In earlier examples, we did not pass any arguments, which allows the DOM | ||
// receiver to mirror any element it receives. By passing the `elements` option, | ||
// we are restricting the allowed elements to only the ones we list, which in this | ||
// case means only our `ui-banner` element can be rendered. | ||
const receiver = new DOMRemoteReceiver({ | ||
elements: ['ui-banner'], | ||
}); | ||
receiver.connect(root); | ||
|
||
window.addEventListener('message', ({source, data}) => { | ||
if (source !== iframe.contentWindow) return; | ||
receiver.receive(data); | ||
}); | ||
</script> | ||
</body> | ||
</html> |
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,54 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<body> | ||
<div id="root"> | ||
<ui-banner>This page was rendered 0 seconds ago.</ui-banner> | ||
</div> | ||
|
||
<script type="module"> | ||
import {RemoteElement} from '@remote-dom/core/elements'; | ||
|
||
class UIBanner extends RemoteElement { | ||
// For full details on defining remote elements, see the documentation | ||
// for `@remote-dom/core/elements`: | ||
// https://github.com/Shopify/remote-ui/tree/main/packages/core/ | ||
static get remoteProperties() { | ||
return { | ||
tone: {type: String}, | ||
}; | ||
} | ||
} | ||
|
||
customElements.define('ui-banner', UIBanner); | ||
</script> | ||
|
||
<script type="module"> | ||
import {RemoteMutationObserver} from '@remote-dom/core/elements'; | ||
|
||
const root = document.querySelector('#root'); | ||
const banner = root.querySelector('ui-banner'); | ||
const initialContent = banner.textContent; | ||
|
||
let count = 0; | ||
|
||
setInterval(() => { | ||
count += 1; | ||
|
||
banner.textContent = initialContent.replace( | ||
'0 seconds', | ||
`${count} second${count === 1 ? '' : 's'}`, | ||
); | ||
|
||
if (count === 10) { | ||
banner.setAttribute('tone', 'warning'); | ||
} | ||
}, 1000); | ||
|
||
const observer = new RemoteMutationObserver((mutations) => { | ||
window.parent.postMessage(mutations, '*'); | ||
}); | ||
|
||
observer.observe(root); | ||
</script> | ||
</body> | ||
</html> |
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,11 @@ | ||
{ | ||
"name": "example-minimal-iframes", | ||
"version": "0.0.1", | ||
"private": true, | ||
"scripts": { | ||
"start": "vite" | ||
}, | ||
"dependencies": { | ||
"@remote-dom/core": "workspace:*" | ||
} | ||
} |
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,8 @@ | ||
import {defineConfig} from 'vite'; | ||
|
||
export default defineConfig({ | ||
root: './app', | ||
resolve: { | ||
conditions: ['quilt:source'], | ||
}, | ||
}); |
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
Oops, something went wrong.