mirror of
https://github.com/rio-labs/rio.git
synced 2026-01-03 11:49:47 -06:00
35 lines
1.0 KiB
TypeScript
35 lines
1.0 KiB
TypeScript
import { applySwitcheroo } from '../designApplication';
|
|
import { ColorSet, ComponentId } from '../dataModels';
|
|
import { ComponentBase, ComponentState } from './componentBase';
|
|
|
|
export type ThemeContextSwitcherState = ComponentState & {
|
|
_type_: 'ThemeContextSwitcher-builtin';
|
|
content?: ComponentId;
|
|
color?: ColorSet;
|
|
};
|
|
|
|
export class ThemeContextSwitcherComponent extends ComponentBase {
|
|
state: Required<ThemeContextSwitcherState>;
|
|
|
|
createElement(): HTMLElement {
|
|
let element = document.createElement('div');
|
|
element.classList.add('rio-single-container');
|
|
return element;
|
|
}
|
|
|
|
updateElement(
|
|
deltaState: ThemeContextSwitcherState,
|
|
latentComponents: Set<ComponentBase>
|
|
): void {
|
|
super.updateElement(deltaState, latentComponents);
|
|
|
|
// Update the child
|
|
this.replaceOnlyChild(latentComponents, deltaState.content);
|
|
|
|
// Colorize
|
|
if (deltaState.color !== undefined) {
|
|
applySwitcheroo(this.element, deltaState.color);
|
|
}
|
|
}
|
|
}
|