-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(design): create daffArticleEncapsulatedMixin to prevent article …
…styles from cascading down to nested @daffodil/design components (#1917)
- Loading branch information
Showing
7 changed files
with
116 additions
and
58 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
libs/design/src/core/article-encapsulated/article-encapsulated-mixin.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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { | ||
ElementRef, | ||
Renderer2, | ||
} from '@angular/core'; | ||
|
||
import { Constructor } from '../constructor/constructor'; | ||
|
||
export interface HasElementRef { | ||
_elementRef: ElementRef; | ||
_renderer: Renderer2; | ||
} | ||
|
||
/** | ||
* A mixin for giving a component the ability to prevent article styles from cascading down. | ||
*/ | ||
export function | ||
daffArticleEncapsulatedMixin<T extends Constructor<HasElementRef>>(Base: T) { | ||
return class extends Base { | ||
constructor(...args: any[]) { | ||
super(...args); | ||
this._renderer.addClass(this._elementRef.nativeElement, `daff-ae`); | ||
} | ||
}; | ||
} |
35 changes: 35 additions & 0 deletions
35
libs/design/src/core/article-encapsulated/article-encapsulated.spec.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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { ElementRef } from '@angular/core'; | ||
|
||
import { | ||
daffArticleEncapsulatedMixin, | ||
HasElementRef, | ||
} from './article-encapsulated-mixin'; | ||
|
||
class TestingClass implements HasElementRef { | ||
element: HTMLElement = document.createElement('div'); | ||
|
||
_elementRef = new ElementRef<HTMLElement>(this.element); | ||
_renderer: any = { | ||
addClass: (el: HTMLElement, className: string) => { | ||
el.classList.add(className); | ||
}, | ||
removeClass: (el: HTMLElement, className: string) => { | ||
el.classList.remove(className); | ||
}, | ||
}; | ||
} | ||
|
||
describe('daffArticleEncapsulatedMixin', () => { | ||
let instance; | ||
let manageContainerLayoutClass; | ||
|
||
beforeEach(() => { | ||
manageContainerLayoutClass = daffArticleEncapsulatedMixin(TestingClass); | ||
instance = new manageContainerLayoutClass(); | ||
}); | ||
|
||
|
||
it('should set a namespaced manage container layout class', () => { | ||
expect(instance.element.classList).toContain('daff-ae'); | ||
}); | ||
}); |
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 @@ | ||
export { daffArticleEncapsulatedMixin } from './article-encapsulated-mixin'; |
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
7 changes: 7 additions & 0 deletions
7
libs/design/src/molecules/article/article/stops-article-cascade.scss
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,7 @@ | ||
@mixin stopsArticleCascade($selector...) { | ||
#{$selector} { | ||
&:not(.daff-ae *, .daff-ae) { | ||
@content; | ||
} | ||
} | ||
} |