| 57 | }, |
| 58 | }) |
| 59 | export class ToolbarWidget implements OnInit, OnDestroy { |
| 60 | /** A reference to the host element. */ |
| 61 | private readonly _elementRef = inject(ElementRef); |
| 62 | |
| 63 | /** A reference to the host element. */ |
| 64 | readonly element = this._elementRef.nativeElement as HTMLElement; |
| 65 | |
| 66 | /** The parent Toolbar. */ |
| 67 | private readonly _toolbar = inject<Toolbar>(Toolbar); |
| 68 | |
| 69 | /** A unique identifier for the widget. */ |
| 70 | readonly id = input(inject(_IdGenerator).getId('ng-toolbar-widget-', true)); |
| 71 | |
| 72 | /** The parent Toolbar UIPattern. */ |
| 73 | readonly _toolbarPattern = computed<ToolbarPattern>(() => this._toolbar._pattern); |
| 74 | |
| 75 | /** Whether the widget is disabled. */ |
| 76 | readonly disabled = input(false, {transform: booleanAttribute}); |
| 77 | |
| 78 | /** Whether the widget is 'hard' disabled, which is different from `aria-disabled`. A hard disabled widget cannot receive focus. */ |
| 79 | readonly hardDisabled = computed(() => this._pattern.disabled() && !this._toolbar.softDisabled()); |
| 80 | |
| 81 | /** The optional ToolbarWidgetGroup this widget belongs to. */ |
| 82 | readonly _group = inject<ToolbarWidgetGroup>(TOOLBAR_WIDGET_GROUP, {optional: true}); |
| 83 | |
| 84 | /** Whether the widget is currently active (focused). */ |
| 85 | readonly active = computed(() => this._pattern.active()); |
| 86 | |
| 87 | private readonly _groupPattern: SignalLike<ToolbarWidgetGroupPattern | undefined> = () => |
| 88 | this._group?._pattern; |
| 89 | |
| 90 | /** The ToolbarWidget UIPattern. */ |
| 91 | readonly _pattern = new ToolbarWidgetPattern({ |
| 92 | ...this, |
| 93 | group: this._groupPattern, |
| 94 | toolbar: this._toolbarPattern, |
| 95 | id: this.id, |
| 96 | element: () => this.element, |
| 97 | }); |
| 98 | |
| 99 | ngOnInit() { |
| 100 | this._toolbar._collection.register(this); |
| 101 | } |
| 102 | |
| 103 | ngOnDestroy() { |
| 104 | this._toolbar._collection.unregister(this); |
| 105 | } |
| 106 | } |