mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-24 09:46:36 +00:00
Add custom elements to picture-elements. (#1482)
This commit is contained in:
parent
abf85ae19b
commit
06532def08
@ -5,8 +5,10 @@ import '../elements/hui-state-badge-element.js';
|
||||
import '../elements/hui-state-icon-element.js';
|
||||
import '../elements/hui-state-label-element.js';
|
||||
|
||||
import fireEvent from '../../../common/dom/fire_event.js';
|
||||
import createErrorCardConfig from './create-error-card-config.js';
|
||||
|
||||
const CUSTOM_TYPE_PREFIX = 'custom:';
|
||||
const ELEMENT_TYPES = new Set([
|
||||
'icon',
|
||||
'image',
|
||||
@ -38,6 +40,21 @@ export default function createHuiElement(config) {
|
||||
return _createErrorElement('No element type configured.', config);
|
||||
}
|
||||
|
||||
if (config.type.startsWith(CUSTOM_TYPE_PREFIX)) {
|
||||
const tag = config.type.substr(CUSTOM_TYPE_PREFIX.length);
|
||||
|
||||
if (customElements.get(tag)) {
|
||||
return _createElement(tag, config);
|
||||
}
|
||||
|
||||
const element = _createErrorElement(`Custom element doesn't exist: ${tag}.`, config);
|
||||
|
||||
customElements.whenDefined(tag)
|
||||
.then(() => fireEvent(element, 'rebuild-view'));
|
||||
|
||||
return element;
|
||||
}
|
||||
|
||||
if (!ELEMENT_TYPES.has(config.type)) {
|
||||
return _createErrorElement(`Unknown element type encountered: ${config.type}.`, config);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user