Skip to content

Commit b00d1e1

Browse files
feat(design)!: change daffArticleEncapsulatedMixin to a directive (#2913)
BREAKING CHANGE: daffArticleEncapsulatedMixin has been removed in favor of DaffArticleEncapsulatedDirective. Update usage by using the hostDirective instead. Co-authored-by: Damien Retzinger <[email protected]>
1 parent e953dca commit b00d1e1

File tree

18 files changed

+165
-176
lines changed

18 files changed

+165
-176
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,13 @@
1-
import {
2-
Component,
3-
ElementRef,
4-
Renderer2,
5-
} from '@angular/core';
1+
import { Component } from '@angular/core';
62

7-
import { daffArticleEncapsulatedMixin } from '@daffodil/design';
8-
9-
/**
10-
* An _elementRef and an instance of renderer2 are needed for the link set mixins
11-
*/
12-
class DesignLandArticleEncapsulatedBase {
13-
constructor(public _elementRef: ElementRef, public _renderer: Renderer2) {}
14-
}
15-
16-
const _designLandArticleEncapsulatedBase = daffArticleEncapsulatedMixin((DesignLandArticleEncapsulatedBase));
3+
import { DaffArticleEncapsulatedDirective } from '@daffodil/design';
174

185
@Component({
196
selector: 'design-land-article-encapsulated',
207
template: '<ng-content></ng-content>',
8+
hostDirectives: [{
9+
directive: DaffArticleEncapsulatedDirective,
10+
}],
2111
})
22-
export class DesignLandArticleEncapsulatedComponent extends _designLandArticleEncapsulatedBase {
23-
constructor(private elementRef: ElementRef, private renderer: Renderer2) {
24-
super(elementRef, renderer);
25-
}
12+
export class DesignLandArticleEncapsulatedComponent {
2613
}
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,9 @@
11
import {
22
ChangeDetectionStrategy,
33
Component,
4-
ElementRef,
5-
Renderer2,
64
} from '@angular/core';
75

8-
import { daffArticleEncapsulatedMixin } from '@daffodil/design';
9-
10-
/**
11-
* An _elementRef and an instance of renderer2 are needed for the link set mixins
12-
*/
13-
class DaffAccordionBase {
14-
constructor(public _elementRef: ElementRef, public _renderer: Renderer2) {}
15-
}
16-
17-
const _daffAccordionBase = daffArticleEncapsulatedMixin((DaffAccordionBase));
6+
import { DaffArticleEncapsulatedDirective } from '@daffodil/design';
187

198
@Component({
209
selector: 'daff-accordion',
@@ -24,11 +13,10 @@ const _daffAccordionBase = daffArticleEncapsulatedMixin((DaffAccordionBase));
2413
display: block;
2514
}
2615
`],
16+
hostDirectives: [{
17+
directive: DaffArticleEncapsulatedDirective,
18+
}],
2719
changeDetection: ChangeDetectionStrategy.OnPush,
2820
})
2921

30-
export class DaffAccordionComponent extends _daffAccordionBase {
31-
constructor(private elementRef: ElementRef, private renderer: Renderer2) {
32-
super(elementRef, renderer);
33-
}
34-
}
22+
export class DaffAccordionComponent {}

libs/design/article/README.md

+19-13
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,47 @@ Article provides styles to common element selectors to create an article in a co
44
## Overview
55
Article can be used on any content page that displays large blocks of text-driven information. It's meant to be used as a standalone element and should not be nested inside any other components that may change the background color from the anticipated one. In the event that you must nest an article inside another component, please ensure that you set the article's background color to the default body color.
66

7-
## Headings
7+
## Supported Elements
8+
9+
### Headings
810
<design-land-example-viewer-container example="article-headings"></design-land-example-viewer-container>
911

10-
## Article Meta
12+
### Article Meta
1113
Meta is used if there is metadata information about your article (i.e. author name, date, etc). Meta is a custom directive of article and is not a native element selector. To use it, add `daffArticleMeta` to a paragraph (`<p>`).
1214

1315
<design-land-example-viewer-container example="article-meta"></design-land-example-viewer-container>
1416

15-
## Link
17+
### Link
1618
The link style in an article uses the default browser link style.
1719

1820
<design-land-example-viewer-container example="article-link"></design-land-example-viewer-container>
1921

20-
<h2>Table</h2>
22+
### Table
2123
<design-land-example-viewer-container example="article-table"></design-land-example-viewer-container>
2224

23-
## Lists
25+
### Lists
2426

25-
### Unordered List
27+
#### Unordered List
2628
<design-land-example-viewer-container example="article-ul"></design-land-example-viewer-container>
2729

28-
### Ordered List
30+
#### Ordered List
2931
<design-land-example-viewer-container example="article-ol"></design-land-example-viewer-container>
3032

31-
## Code
33+
### Code
3234
These are styles for inline and multiline blocks of code.
3335

34-
### Inline code
36+
#### Inline code
3537
<design-land-example-viewer-container example="article-code-inline"></design-land-example-viewer-container>
3638

37-
### Code blocks
39+
#### Code blocks
3840
<design-land-example-viewer-container example="article-code-block"></design-land-example-viewer-container>
3941

40-
## Horizontal Rules
42+
### Horizontal Rules
4143
<design-land-example-viewer-container example="article-hr"></design-land-example-viewer-container>
4244

43-
## Blockquote
44-
<design-land-example-viewer-container example="article-blockquote"></design-land-example-viewer-container>
45+
### Blockquote
46+
<design-land-example-viewer-container example="article-blockquote"></design-land-example-viewer-container>
47+
48+
## Encapsulation
49+
50+
Articles also support other custom "non-native" components like [Accordions](../accordion/README.md), [Media Galleries](../media-gallery/README.md), and [Lists](../list/README.md). Unlike typical HTML (<p>, <ol>, <ul>, etc) content, these components must be style encaspulated to prevent article styles bleeding down from the article into their content. Many Daffodil components support this out of the box. If you have a custom component that you would like to place inside an article, you can use the `DaffArticleEncapsulatedDirective` on your component to prevent article styles bleeding into your component.

libs/design/button/src/button/button.component.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {
2424
daffSizeMixin,
2525
DaffStatusable,
2626
daffStatusMixin,
27-
daffArticleEncapsulatedMixin,
27+
DaffArticleEncapsulatedDirective,
2828
} from '@daffodil/design';
2929

3030
/**
@@ -46,7 +46,7 @@ class DaffButtonBase{
4646
constructor(public _elementRef: ElementRef, public _renderer: Renderer2) {}
4747
}
4848

49-
const _daffButtonBase = daffArticleEncapsulatedMixin(daffPrefixableMixin(daffSuffixableMixin(daffColorMixin(daffStatusMixin(daffSizeMixin<DaffButtonSize>(DaffButtonBase, 'md'))))));
49+
const _daffButtonBase = daffPrefixableMixin(daffSuffixableMixin(daffColorMixin(daffStatusMixin(daffSizeMixin<DaffButtonSize>(DaffButtonBase, 'md')))));
5050

5151
export type DaffButtonType = 'daff-button' | 'daff-stroked-button' | 'daff-raised-button' | 'daff-flat-button' | 'daff-icon-button' | 'daff-underline-button' | undefined;
5252

@@ -87,6 +87,9 @@ enum DaffButtonTypeEnum {
8787
//todo(damienwebdev): remove once decorators hit stage 3 - https://github.com/microsoft/TypeScript/issues/7342
8888
// eslint-disable-next-line @angular-eslint/no-inputs-metadata-property
8989
inputs: ['color', 'size', 'status'],
90+
hostDirectives: [{
91+
directive: DaffArticleEncapsulatedDirective,
92+
}],
9093
encapsulation: ViewEncapsulation.None,
9194
changeDetection: ChangeDetectionStrategy.OnPush,
9295
})

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

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import {
22
Component,
33
ViewEncapsulation,
4-
Input,
54
ElementRef,
65
ChangeDetectionStrategy,
76
HostBinding,
87
Renderer2,
98
} from '@angular/core';
109

1110
import {
12-
daffArticleEncapsulatedMixin,
11+
DaffArticleEncapsulatedDirective,
1312
DaffColorable,
1413
daffColorMixin,
1514
DaffCompactable,
@@ -26,7 +25,7 @@ class DaffCalloutBase {
2625
constructor(public _elementRef: ElementRef, public _renderer: Renderer2) {}
2726
}
2827

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

3130
/**
3231
* @inheritdoc
@@ -39,6 +38,9 @@ const _daffCalloutBase = daffArticleEncapsulatedMixin(daffManageContainerLayoutM
3938
//todo(damienwebdev): remove once decorators hit stage 3 - https://github.com/microsoft/TypeScript/issues/7342
4039
// eslint-disable-next-line @angular-eslint/no-inputs-metadata-property
4140
inputs: ['color', 'compact', 'textAlignment'],
41+
hostDirectives: [{
42+
directive: DaffArticleEncapsulatedDirective,
43+
}],
4244
changeDetection: ChangeDetectionStrategy.OnPush,
4345
})
4446
export class DaffCalloutComponent extends _daffCalloutBase implements DaffColorable, DaffTextAlignable, DaffCompactable {

libs/design/card/src/card/card.component.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
} from '@angular/core';
1111

1212
import {
13-
daffArticleEncapsulatedMixin,
13+
DaffArticleEncapsulatedDirective,
1414
DaffColorable,
1515
daffColorMixin,
1616
} from '@daffodil/design';
@@ -38,7 +38,7 @@ class DaffCardBase {
3838
constructor(public _elementRef: ElementRef, public _renderer: Renderer2) {}
3939
}
4040

41-
const _daffCardBase = daffArticleEncapsulatedMixin(daffColorMixin(DaffCardBase));
41+
const _daffCardBase = daffColorMixin(DaffCardBase);
4242

4343
/**
4444
* @inheritdoc
@@ -57,6 +57,9 @@ const _daffCardBase = daffArticleEncapsulatedMixin(daffColorMixin(DaffCardBase))
5757
//todo(damienwebdev): remove once decorators hit stage 3 - https://github.com/microsoft/TypeScript/issues/7342
5858
// eslint-disable-next-line @angular-eslint/no-inputs-metadata-property
5959
inputs: ['color'],
60+
hostDirectives: [{
61+
directive: DaffArticleEncapsulatedDirective,
62+
}],
6063
changeDetection: ChangeDetectionStrategy.OnPush,
6164
})
6265

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
} from '@angular/core';
99

1010
import {
11-
daffArticleEncapsulatedMixin,
11+
DaffArticleEncapsulatedDirective,
1212
DaffColorable,
1313
daffColorMixin,
1414
DaffCompactable,
@@ -25,7 +25,7 @@ class DaffHeroBase {
2525
constructor(public _elementRef: ElementRef, public _renderer: Renderer2) {}
2626
}
2727

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

3030
/**
3131
* @inheritdoc
@@ -38,6 +38,9 @@ const _daffHeroBase = daffArticleEncapsulatedMixin(daffManageContainerLayoutMixi
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+
}],
4144
changeDetection: ChangeDetectionStrategy.OnPush,
4245
})
4346
export class DaffHeroComponent extends _daffHeroBase implements DaffColorable, DaffTextAlignable, DaffCompactable {

libs/design/link-set/src/link-set/link-set.component.ts

+5-17
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,9 @@ import {
33
HostBinding,
44
ViewEncapsulation,
55
ChangeDetectionStrategy,
6-
ElementRef,
7-
Renderer2,
86
} from '@angular/core';
97

10-
import { daffArticleEncapsulatedMixin } from '@daffodil/design';
11-
12-
/**
13-
* An _elementRef and an instance of renderer2 are needed for the link set mixins
14-
*/
15-
class DaffLinkSetBase {
16-
constructor(public _elementRef: ElementRef, public _renderer: Renderer2) {}
17-
}
18-
19-
const _daffLinkSetBase = daffArticleEncapsulatedMixin((DaffLinkSetBase));
8+
import { DaffArticleEncapsulatedDirective } from '@daffodil/design';
209

2110
/**
2211
* DaffLinkSetComponent is a component for displaying a two or more links.
@@ -25,17 +14,16 @@ const _daffLinkSetBase = daffArticleEncapsulatedMixin((DaffLinkSetBase));
2514
selector: 'daff-link-set',
2615
template: '<ng-content></ng-content>',
2716
styleUrls: ['./link-set.component.scss'],
17+
hostDirectives: [{
18+
directive: DaffArticleEncapsulatedDirective,
19+
}],
2820
encapsulation: ViewEncapsulation.None,
2921
changeDetection: ChangeDetectionStrategy.OnPush,
3022
})
31-
export class DaffLinkSetComponent extends _daffLinkSetBase {
23+
export class DaffLinkSetComponent {
3224

3325
/**
3426
* @docs-private
3527
*/
3628
@HostBinding('class.daff-link-set') class = true;
37-
38-
constructor(private elementRef: ElementRef, private renderer: Renderer2) {
39-
super(elementRef, renderer);
40-
}
4129
}

libs/design/list/src/list/list.component.ts

+6-15
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ import {
44
ChangeDetectionStrategy,
55
HostBinding,
66
ElementRef,
7-
Renderer2,
87
} from '@angular/core';
98

10-
import { daffArticleEncapsulatedMixin } from '@daffodil/design';
9+
import { DaffArticleEncapsulatedDirective } from '@daffodil/design';
1110

1211
export type DaffListType = 'daff-list' | 'daff-nav-list';
1312

@@ -16,26 +15,20 @@ enum DaffListTypeEnum {
1615
Nav = 'daff-nav-list'
1716
}
1817

19-
/**
20-
* An _elementRef and an instance of renderer2 are needed for the list mixins
21-
*/
22-
class DaffListBase {
23-
constructor(public _elementRef: ElementRef, public _renderer: Renderer2) {}
24-
}
25-
26-
const _daffListBase = daffArticleEncapsulatedMixin((DaffListBase));
27-
2818
@Component({
2919
selector:
3020
'daff-list' + ',' +
3121
'daff-nav-list',
3222
template: '<ng-content></ng-content>',
3323
styleUrls: ['./list.component.scss'],
24+
hostDirectives: [{
25+
directive: DaffArticleEncapsulatedDirective,
26+
}],
3427
encapsulation: ViewEncapsulation.None,
3528
changeDetection: ChangeDetectionStrategy.OnPush,
3629
})
3730

38-
export class DaffListComponent extends _daffListBase {
31+
export class DaffListComponent {
3932
/**
4033
* @docs-private
4134
*/
@@ -50,9 +43,7 @@ export class DaffListComponent extends _daffListBase {
5043
return this._getHostElement().localName;
5144
}
5245

53-
constructor(private elementRef: ElementRef, private renderer: Renderer2) {
54-
super(elementRef, renderer);
55-
}
46+
constructor(private elementRef: ElementRef) {}
5647

5748
/**
5849
* @docs-private

libs/design/media-gallery/src/media-gallery/media-gallery.component.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
import {
1313
daffSkeletonableMixin,
1414
DaffSkeletonable,
15-
daffArticleEncapsulatedMixin,
15+
DaffArticleEncapsulatedDirective,
1616
} from '@daffodil/design';
1717

1818
import { DaffMediaGalleryRegistration } from '../helpers/media-gallery-registration.interface';
@@ -28,7 +28,7 @@ class DaffMediaGalleryBase {
2828
constructor(public _elementRef: ElementRef, public _renderer: Renderer2) {}
2929
}
3030

31-
const _daffMediaGalleryBase = daffSkeletonableMixin(daffArticleEncapsulatedMixin((DaffMediaGalleryBase)));
31+
const _daffMediaGalleryBase = daffSkeletonableMixin((DaffMediaGalleryBase));
3232

3333
@Component({
3434
selector: 'daff-media-gallery',
@@ -42,6 +42,9 @@ const _daffMediaGalleryBase = daffSkeletonableMixin(daffArticleEncapsulatedMixin
4242
// todo(damienwebdev): remove once decorators hit stage 3 - https://github.com/microsoft/TypeScript/issues/7342
4343
// eslint-disable-next-line @angular-eslint/no-inputs-metadata-property
4444
inputs: ['skeleton'],
45+
hostDirectives: [{
46+
directive: DaffArticleEncapsulatedDirective,
47+
}],
4548
})
4649
export class DaffMediaGalleryComponent extends _daffMediaGalleryBase implements DaffMediaGalleryRegistration, DaffSkeletonable, OnInit, OnDestroy {
4750
/**

0 commit comments

Comments
 (0)