Files
Umbraco-CMS/src/Umbraco.Web.UI.Client/libs/context-api/provide/context-provider.element.ts
2023-01-20 13:31:31 +01:00

36 lines
770 B
TypeScript

import { html } from 'lit';
import { customElement, property } from 'lit/decorators.js';
import { UmbLitElement } from '@umbraco-cms/element';
@customElement('umb-context-provider')
export class UmbContextProviderElement extends UmbLitElement {
/**
* 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>`;
}
}