diff --git a/README.md b/README.md
index 26632e7..5b98604 100644
--- a/README.md
+++ b/README.md
@@ -151,8 +151,19 @@ You use the import-map-overrides UI via web components. This means you just need
You have three options for the UI, depending on how much you want to customize the UI:
```html
-
-
+
+
diff --git a/src/ui/custom-elements.js b/src/ui/custom-elements.js
index c0ca0a2..ef705e3 100644
--- a/src/ui/custom-elements.js
+++ b/src/ui/custom-elements.js
@@ -7,7 +7,7 @@ import List from "./list/list.component";
if (window.customElements) {
window.customElements.define(
"import-map-overrides-full",
- preactCustomElement(FullUI)
+ preactCustomElement(FullUI, ["show-when-local-storage"])
);
window.customElements.define(
"import-map-overrides-popup",
@@ -19,13 +19,27 @@ if (window.customElements) {
);
}
-function preactCustomElement(Comp) {
+function preactCustomElement(Comp, observedAttributes = []) {
return class PreactCustomElement extends HTMLElement {
connectedCallback() {
- render(h(Comp, this), this);
+ this.renderWithPreact();
}
disconnectedCallback() {
render(null, this);
+ this.renderedEl = null;
+ }
+ static get observedAttributes() {
+ return observedAttributes;
+ }
+ attributeChangedCallback() {
+ this.renderWithPreact();
+ }
+ renderWithPreact() {
+ this.renderedEl = render(
+ h(Comp, { customElement: this }),
+ this,
+ this.renderedEl
+ );
}
};
}
diff --git a/src/ui/full-ui.component.js b/src/ui/full-ui.component.js
index dbf23d8..5b5d049 100644
--- a/src/ui/full-ui.component.js
+++ b/src/ui/full-ui.component.js
@@ -6,6 +6,16 @@ export default class FullUI extends Component {
showingPopup: false
};
render(props, state) {
+ const shouldShow =
+ !props.customElement.hasAttribute("show-when-local-storage") ||
+ localStorage.getItem(
+ props.customElement.getAttribute("show-when-local-storage")
+ ) === "true";
+
+ if (!shouldShow) {
+ return null;
+ }
+
const atLeastOneOverride =
Object.keys(window.importMapOverrides.getOverrideMap().imports).length >
0;