-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #492 from MerlinMoos/feat/menu-signal-based
refactor(context-menu): migrate to signals (#418)
- Loading branch information
Showing
7 changed files
with
66 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { ConnectedPosition } from '@angular/cdk/overlay'; | ||
|
||
export type BrnMenuAlign = 'start' | 'center' | 'end' | undefined; | ||
export const getBrnMenuAlign = (align: Exclude<BrnMenuAlign, undefined>): ConnectedPosition[] => [ | ||
{ | ||
originX: align, | ||
originY: 'bottom', | ||
overlayX: align, | ||
overlayY: 'top', | ||
}, | ||
{ | ||
originX: align, | ||
originY: 'top', | ||
overlayX: align, | ||
overlayY: 'bottom', | ||
}, | ||
]; |
37 changes: 11 additions & 26 deletions
37
libs/ui/menu/brain/src/lib/brn-menu-item-checkbox.directive.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,24 @@ | ||
import { CdkMenuItemCheckbox } from '@angular/cdk/menu'; | ||
import { Directive, Input, Output, booleanAttribute, inject, signal } from '@angular/core'; | ||
import { booleanAttribute, Directive, effect, inject, input } from '@angular/core'; | ||
import { outputFromObservable } from '@angular/core/rxjs-interop'; | ||
|
||
@Directive({ | ||
selector: '[brnMenuItemCheckbox]', | ||
standalone: true, | ||
hostDirectives: [CdkMenuItemCheckbox], | ||
host: { | ||
'[class.checked]': '_checked()', | ||
'[disabled]': '_disabled()', | ||
'[class.checked]': 'checked()', | ||
'[disabled]': 'disabled()', | ||
}, | ||
}) | ||
export class BrnMenuItemCheckboxDirective { | ||
private readonly _cdkMenuItem = inject(CdkMenuItemCheckbox, { host: true }); | ||
private readonly _cdkMenuItem = inject(CdkMenuItemCheckbox); | ||
public readonly checked = input(this._cdkMenuItem.checked, { transform: booleanAttribute }); | ||
public readonly disabled = input(this._cdkMenuItem.disabled, { transform: booleanAttribute }); | ||
public readonly triggered = outputFromObservable(this._cdkMenuItem.triggered); | ||
|
||
protected readonly _checked = signal(this._cdkMenuItem.checked); | ||
@Input({ transform: booleanAttribute }) | ||
public set checked(value: boolean) { | ||
this._cdkMenuItem.checked = value; | ||
this._checked.set(value); | ||
constructor() { | ||
effect(() => (this._cdkMenuItem.disabled = this.disabled())); | ||
effect(() => (this._cdkMenuItem.checked = this.checked())); | ||
} | ||
|
||
public get checked() { | ||
return this._checked(); | ||
} | ||
|
||
protected readonly _disabled = signal(this._cdkMenuItem.disabled); | ||
@Input({ transform: booleanAttribute }) | ||
public set disabled(value: boolean) { | ||
this._cdkMenuItem.disabled = value; | ||
this._disabled.set(value); | ||
} | ||
public get disabled() { | ||
return this._disabled(); | ||
} | ||
|
||
@Output() | ||
public readonly triggered = this._cdkMenuItem.triggered; | ||
} |
36 changes: 11 additions & 25 deletions
36
libs/ui/menu/brain/src/lib/brn-menu-item-radio.directive.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,24 @@ | ||
import { CdkMenuItemRadio } from '@angular/cdk/menu'; | ||
import { Directive, Input, Output, booleanAttribute, inject, signal } from '@angular/core'; | ||
import { booleanAttribute, Directive, effect, inject, input } from '@angular/core'; | ||
import { outputFromObservable } from '@angular/core/rxjs-interop'; | ||
|
||
@Directive({ | ||
selector: '[brnMenuItemRadio]', | ||
standalone: true, | ||
hostDirectives: [CdkMenuItemRadio], | ||
host: { | ||
'[class.checked]': '_checked()', | ||
'[disabled]': '_disabled()', | ||
'[class.checked]': 'checked()', | ||
'[disabled]': 'disabled()', | ||
}, | ||
}) | ||
export class BrnMenuItemRadioDirective { | ||
private readonly _cdkMenuItem = inject(CdkMenuItemRadio, { host: true }); | ||
private readonly _cdkMenuItem = inject(CdkMenuItemRadio); | ||
public readonly checked = input(this._cdkMenuItem.checked, { transform: booleanAttribute }); | ||
public readonly disabled = input(this._cdkMenuItem.disabled, { transform: booleanAttribute }); | ||
public readonly triggered = outputFromObservable(this._cdkMenuItem.triggered); | ||
|
||
protected readonly _checked = signal(this._cdkMenuItem.checked); | ||
@Input({ transform: booleanAttribute }) | ||
public set checked(value: boolean) { | ||
this._cdkMenuItem.checked = value; | ||
this._checked.set(value); | ||
constructor() { | ||
effect(() => (this._cdkMenuItem.disabled = this.disabled())); | ||
effect(() => (this._cdkMenuItem.checked = this.checked())); | ||
} | ||
public get checked() { | ||
return this._checked(); | ||
} | ||
|
||
protected readonly _disabled = signal(this._cdkMenuItem.disabled); | ||
@Input({ transform: booleanAttribute }) | ||
public set disabled(value: boolean) { | ||
this._cdkMenuItem.disabled = value; | ||
this._disabled.set(value); | ||
} | ||
public get disabled() { | ||
return this._disabled(); | ||
} | ||
|
||
@Output() | ||
public readonly triggered = this._cdkMenuItem.triggered; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,21 @@ | ||
import { CdkMenuItem } from '@angular/cdk/menu'; | ||
import { Directive, Input, Output, booleanAttribute, inject, signal } from '@angular/core'; | ||
import { booleanAttribute, Directive, effect, inject, input } from '@angular/core'; | ||
import { outputFromObservable } from '@angular/core/rxjs-interop'; | ||
|
||
@Directive({ | ||
selector: '[brnMenuItem]', | ||
standalone: true, | ||
hostDirectives: [CdkMenuItem], | ||
host: { | ||
'[disabled]': '_disabled()', | ||
'[disabled]': 'disabled()', | ||
}, | ||
}) | ||
export class BrnMenuItemDirective { | ||
private readonly _cdkMenuItem = inject(CdkMenuItem, { host: true }); | ||
private readonly _cdkMenuItem = inject(CdkMenuItem); | ||
public readonly disabled = input(this._cdkMenuItem.disabled, { transform: booleanAttribute }); | ||
public readonly triggered = outputFromObservable(this._cdkMenuItem.triggered); | ||
|
||
protected readonly _disabled = signal(this._cdkMenuItem.disabled); | ||
@Input({ transform: booleanAttribute }) | ||
public set disabled(value: boolean) { | ||
this._cdkMenuItem.disabled = value; | ||
this._disabled.set(value); | ||
constructor() { | ||
effect(() => (this._cdkMenuItem.disabled = this.disabled())); | ||
} | ||
|
||
public get disabled() { | ||
return this._disabled(); | ||
} | ||
|
||
@Output() | ||
public readonly triggered = this._cdkMenuItem.triggered; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters