Skip to content

Commit 98f19c8

Browse files
authored
feat(design)!: change daffManageContainerLayoutMixin to a directive (#2919)
BREAKING CHANGE: daffManageContainerLayoutMixin has been removed in favor of DaffManageContainerLayoutDirective. Update usage by using the hostDirective feature.
1 parent b00d1e1 commit 98f19c8

8 files changed

+110
-74
lines changed

libs/design/callout/src/callout/callout.component.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
daffColorMixin,
1414
DaffCompactable,
1515
daffCompactableMixin,
16-
daffManageContainerLayoutMixin,
16+
DaffManageContainerLayoutDirective,
1717
DaffTextAlignable,
1818
daffTextAlignmentMixin,
1919
} from '@daffodil/design';
@@ -25,7 +25,7 @@ class DaffCalloutBase {
2525
constructor(public _elementRef: ElementRef, public _renderer: Renderer2) {}
2626
}
2727

28-
const _daffCalloutBase = daffManageContainerLayoutMixin(daffColorMixin(daffCompactableMixin(daffTextAlignmentMixin(DaffCalloutBase, 'left'))));
28+
const _daffCalloutBase = daffColorMixin(daffCompactableMixin(daffTextAlignmentMixin(DaffCalloutBase, 'left')));
2929

3030
/**
3131
* @inheritdoc
@@ -38,9 +38,10 @@ const _daffCalloutBase = daffManageContainerLayoutMixin(daffColorMixin(daffCompa
3838
//todo(damienwebdev): remove once decorators hit stage 3 - https://github.com/microsoft/TypeScript/issues/7342
3939
// eslint-disable-next-line @angular-eslint/no-inputs-metadata-property
4040
inputs: ['color', 'compact', 'textAlignment'],
41-
hostDirectives: [{
42-
directive: DaffArticleEncapsulatedDirective,
43-
}],
41+
hostDirectives: [
42+
{ directive: DaffArticleEncapsulatedDirective },
43+
{ directive: DaffManageContainerLayoutDirective },
44+
],
4445
changeDetection: ChangeDetectionStrategy.OnPush,
4546
})
4647
export class DaffCalloutComponent extends _daffCalloutBase implements DaffColorable, DaffTextAlignable, DaffCompactable {

libs/design/hero/src/hero/hero.component.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
daffColorMixin,
1414
DaffCompactable,
1515
daffCompactableMixin,
16-
daffManageContainerLayoutMixin,
16+
DaffManageContainerLayoutDirective,
1717
DaffTextAlignable,
1818
daffTextAlignmentMixin,
1919
} from '@daffodil/design';
@@ -25,7 +25,7 @@ class DaffHeroBase {
2525
constructor(public _elementRef: ElementRef, public _renderer: Renderer2) {}
2626
}
2727

28-
const _daffHeroBase = daffManageContainerLayoutMixin(daffColorMixin(daffCompactableMixin(daffTextAlignmentMixin(DaffHeroBase, 'left'))));
28+
const _daffHeroBase = daffColorMixin(daffCompactableMixin(daffTextAlignmentMixin(DaffHeroBase, 'left')));
2929

3030
/**
3131
* @inheritdoc
@@ -38,9 +38,10 @@ const _daffHeroBase = daffManageContainerLayoutMixin(daffColorMixin(daffCompacta
3838
//todo(damienwebdev): remove once decorators hit stage 3 - https://github.com/microsoft/TypeScript/issues/7342
3939
// eslint-disable-next-line @angular-eslint/no-inputs-metadata-property
4040
inputs: ['color', 'compact', 'textAlignment'],
41-
hostDirectives: [{
42-
directive: DaffArticleEncapsulatedDirective,
43-
}],
41+
hostDirectives: [
42+
{ directive: DaffArticleEncapsulatedDirective },
43+
{ directive: DaffManageContainerLayoutDirective },
44+
],
4445
changeDetection: ChangeDetectionStrategy.OnPush,
4546
})
4647
export class DaffHeroComponent extends _daffHeroBase implements DaffColorable, DaffTextAlignable, DaffCompactable {

libs/design/navbar/src/navbar/navbar.component.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import {
99

1010
import {
1111
DaffColorable,
12+
DaffManageContainerLayoutDirective,
1213
daffColorMixin,
13-
daffManageContainerLayoutMixin,
1414
} from '@daffodil/design';
1515

1616
/**
@@ -20,7 +20,7 @@ class DaffNavbarBase {
2020
constructor(public _elementRef: ElementRef, public _renderer: Renderer2) {}
2121
}
2222

23-
const _daffNavbarBase = daffManageContainerLayoutMixin(daffColorMixin(DaffNavbarBase));
23+
const _daffNavbarBase = daffColorMixin(DaffNavbarBase);
2424

2525
/**
2626
* @inheritdoc
@@ -33,6 +33,9 @@ const _daffNavbarBase = daffManageContainerLayoutMixin(daffColorMixin(DaffNavbar
3333
//todo(damienwebdev): remove once decorators hit stage 3 - https://github.com/microsoft/TypeScript/issues/7342
3434
// eslint-disable-next-line @angular-eslint/no-inputs-metadata-property
3535
inputs: ['color'],
36+
hostDirectives: [{
37+
directive: DaffManageContainerLayoutDirective,
38+
}],
3639
changeDetection: ChangeDetectionStrategy.OnPush,
3740
})
3841
export class DaffNavbarComponent extends _daffNavbarBase implements DaffColorable {

libs/design/src/core/manage-container-layout/manage-container-layout-mixin.ts

-26
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import {
2+
Component,
3+
DebugElement,
4+
} from '@angular/core';
5+
import {
6+
waitForAsync,
7+
ComponentFixture,
8+
TestBed,
9+
} from '@angular/core/testing';
10+
import { By } from '@angular/platform-browser';
11+
12+
import { DaffManageContainerLayoutDirective } from './manage-container-layout.directive';
13+
14+
@Component({
15+
template: `
16+
<div daffManageContainerLayout></div>`,
17+
})
18+
19+
class WrapperComponent {}
20+
21+
describe('@daffodil/design | DaffManageContainerLayoutDirective', () => {
22+
let wrapper: WrapperComponent;
23+
let de: DebugElement;
24+
let fixture: ComponentFixture<WrapperComponent>;
25+
let directive: DaffManageContainerLayoutDirective;
26+
27+
beforeEach(waitForAsync(() => {
28+
TestBed.configureTestingModule({
29+
declarations: [
30+
WrapperComponent,
31+
],
32+
imports: [
33+
DaffManageContainerLayoutDirective,
34+
],
35+
})
36+
.compileComponents();
37+
}));
38+
39+
beforeEach(() => {
40+
fixture = TestBed.createComponent(WrapperComponent);
41+
wrapper = fixture.componentInstance;
42+
de = fixture.debugElement.query(By.css('[daffManageContainerLayout]'));
43+
directive = de.injector.get(DaffManageContainerLayoutDirective);
44+
fixture.detectChanges();
45+
});
46+
47+
it('should create', () => {
48+
expect(wrapper).toBeTruthy();
49+
expect(directive).toBeTruthy();
50+
});
51+
52+
it('should add a class of "daff-manage-container-layout" to the host element', () => {
53+
expect(de.classes).toEqual(jasmine.objectContaining({
54+
'daff-manage-container-layout': true,
55+
}));
56+
});
57+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import {
2+
Directive,
3+
HostBinding,
4+
} from '@angular/core';
5+
6+
/**
7+
* A directive that gives a component the ability to manage a DaffContainerComponent's layout.
8+
* By including this directive, predetermined layout styles are passed down to the container.
9+
*
10+
* To understand the motivation for this directive, consider:
11+
*
12+
* ```html
13+
* <daff-container>
14+
* <daff-hero></daff-hero>
15+
* </daff-container>
16+
* ```
17+
* vs.
18+
*
19+
* ```html
20+
* <daff-hero>
21+
* <daff-container></daff-container>
22+
* </daff-hero>
23+
* ```
24+
*
25+
* The former may inappropriately constrain the width of its child elements,
26+
* while the latter (without `DaffManageContainerLayoutDirective`) may unexpectedly
27+
* interfere in the layout features of its parent element (i.e. display: grid, display: flex).
28+
*/
29+
@Directive({
30+
selector: '[daffManageContainerLayout]',
31+
standalone: true,
32+
})
33+
export class DaffManageContainerLayoutDirective {
34+
@HostBinding('class.daff-manage-container-layout') class = true;
35+
}

libs/design/src/core/manage-container-layout/manage-container-layout.spec.ts

-35
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export { daffManageContainerLayoutMixin } from './manage-container-layout-mixin';
1+
export { DaffManageContainerLayoutDirective } from './manage-container-layout.directive';

0 commit comments

Comments
 (0)