Files
bim_engine/src/managers/button-group-manager.ts

49 lines
1.3 KiB
TypeScript
Raw Normal View History

import { BimButtonGroup } from '../components/button-group';
import type { ButtonGroupOptions } from '../components/button-group/index.type';
import type { ThemeConfig } from '../themes/types';
/**
*
*
*/
export class ButtonGroupManager {
private activeGroups: BimButtonGroup[] = [];
private container: HTMLElement;
constructor(container: HTMLElement) {
this.container = container;
}
/**
*
*/
public create(options: Omit<ButtonGroupOptions, 'container'>): BimButtonGroup {
// 自动创建一个 div 作为容器
const groupContainer = document.createElement('div');
this.container.appendChild(groupContainer);
const group = new BimButtonGroup({
container: groupContainer,
...options
});
// 立即初始化
group.init();
this.activeGroups.push(group);
return group;
}
public updateTheme(theme: ThemeConfig) {
this.activeGroups.forEach(g => g.setTheme(theme));
}
public refresh() {
this.activeGroups.forEach(g => g.render());
}
public destroy() {
this.activeGroups.forEach(g => g.destroy());
this.activeGroups = [];
}
}