add a context-provider element to inject selected contexts in stories

This commit is contained in:
Jacob Overgaard
2022-08-02 13:36:24 +02:00
parent c4de9c59c8
commit 0debb6a8fb

View File

@@ -0,0 +1,36 @@
import { html, LitElement } from 'lit';
import { customElement, property } from 'lit/decorators.js';
import { UmbContextProviderMixin } from './context-provider.mixin';
@customElement('umb-context-provider')
export class UmbContextProviderElement extends UmbContextProviderMixin(LitElement) {
/**
* The value to provide to the context.
* @required
*/
@property({ type: Object })
value!: unknown;
/**
* The key to provide to the context.
* @required
*/
@property({ type: String })
key!: string;
connectedCallback() {
super.connectedCallback();
if (!this.key) {
throw new Error('The key property is required.');
}
if (!this.value) {
throw new Error('The value property is required.');
}
this.provideContext(this.key, this.value);
}
render() {
return html`<slot></slot>`;
}
}