2023-01-04 10:41:40 +01:00
|
|
|
import { html } from 'lit';
|
2022-08-02 13:36:24 +02:00
|
|
|
import { customElement, property } from 'lit/decorators.js';
|
2023-01-24 08:30:18 +01:00
|
|
|
import { UmbLitElement } from '@umbraco-cms/element';
|
2022-08-02 13:36:24 +02:00
|
|
|
|
|
|
|
|
@customElement('umb-context-provider')
|
2023-01-04 10:41:40 +01:00
|
|
|
export class UmbContextProviderElement extends UmbLitElement {
|
2022-08-02 13:36:24 +02:00
|
|
|
/**
|
|
|
|
|
* The value to provide to the context.
|
|
|
|
|
* @required
|
|
|
|
|
*/
|
|
|
|
|
@property({ type: Object })
|
2022-08-09 15:57:44 +02:00
|
|
|
value: unknown;
|
2022-08-02 13:36:24 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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>`;
|
|
|
|
|
}
|
|
|
|
|
}
|