Skip to content

Commit

Permalink
feat(stylesytem): StyleSystem Support
Browse files Browse the repository at this point in the history
* Including appliedCssClassNames on Host Comp

* Testcase updated for better coverage

* feat(stylesytem): Supports StyleSystem

Angular SPAs can now take advantage of StyleSystem,
and authoring experience can be enriched.

* feat(stylesytem): Supports StyleSystem

Angular SPAs can now take advantage of StyleSystem, and authoring experience can be enriched.

Co-authored-by: Mahidhar Chaluvadi <mahidhar.chaluvadi@slalom.com>
  • Loading branch information
friendlymahi and Mahidhar Chaluvadi authored Sep 2, 2021
1 parent 141f1ab commit 3816ec1
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 20 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ dist/
.scannerwork/
**/*.log
*.tgz
coverage/*
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@adobe/aem-angular-editable-components",
"name": "@adobe/aem-angular-editable-components",
"version": "1.0.5",
"description": "Provides Angular components and integration layer with Adobe Experience Manager Page Editor.",
"keywords": [
Expand Down Expand Up @@ -95,12 +95,12 @@
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
},
"eslintConfig": {
"root": true,
"extends": [
"@adobe/eslint-config-editorxp/angular"
]
}
},
"eslintConfig": {
"root": true,
"extends": [
"@adobe/eslint-config-editorxp/angular"
]
}
}
36 changes: 26 additions & 10 deletions src/lib/layout/aem-component.directive.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,19 @@ class AEMDirectiveTestComponent {
@Input() data;
}


@Component({
// tslint:disable-next-line:component-selector
selector: 'directive-component',
// tslint:disable-next-line:no-host-metadata-property
host: {
'[attr.attr1]': 'attr1',
'[attr.attr2]': 'attr2',
'[class]': 'hostClasses'
'[attr.attr2]': 'attr2'
},
template: `<div></div>`
})
class DirectiveComponent extends AbstractMappedComponent {
@Input() attr1;
@Input() attr2;

get hostClasses() {
return 'component-class';
}
}
MapTo<DirectiveComponent>('directive/comp')(DirectiveComponent);
LazyMapTo<LazyComponentType>('some/lazy/comp')(() => import('../test/lazy-component-wrapper/lazy.component').then((m) => m.LazyComponent));
Expand Down Expand Up @@ -94,7 +90,8 @@ describe('AEMComponentDirective', () => {
const componentData = {
attr1: 'Some value',
attr2: 'Another value',
':type': 'directive/comp'
':type': 'directive/comp',
appliedCssClassNames: 'applied-css-class1'
};

component.data = componentData;
Expand All @@ -105,7 +102,28 @@ describe('AEMComponentDirective', () => {

expect(dynamicElement.getAttribute('attr1')).toEqual(componentData['attr1']);
expect(dynamicElement.getAttribute('attr2')).toEqual(componentData['attr2']);
expect(dynamicElement.getAttribute('class')).toEqual(componentData['appliedCssClassNames']);

});

it('should not resolve if incoming type is non existing', () => {
const componentData = {
attr1: 'Some value',
attr2: 'Another value',
':type': 'directive/unknown-comp',
appliedCssClassNames: 'applied-css-class1'
};

component.data = componentData;
fixture.detectChanges();

const element = fixture.nativeElement;
const dynamicElement = element.firstElementChild;

expect(dynamicElement).toBeNull();

});

it('should correctly pass the inputs for lazy component', async() => {
const componentData = {
some: 'Some value',
Expand All @@ -119,8 +137,6 @@ describe('AEMComponentDirective', () => {

});



it('should setup the placeholder', () => {
isInEditorSpy.and.returnValue(true);
getEditConfigSpy.and.returnValue(TEST_EDIT_CONFIG_EMPTY);
Expand Down
17 changes: 15 additions & 2 deletions src/lib/layout/aem-component.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ export class AEMComponentDirective implements AfterViewInit, OnInit, OnDestroy,

@Input() aemComponent;


constructor(
private renderer: Renderer2,
private viewContainer: ViewContainerRef,
Expand Down Expand Up @@ -188,6 +187,7 @@ export class AEMComponentDirective implements AfterViewInit, OnInit, OnDestroy,

this._component.instance.cqPath = this.cqPath;
this._component.instance.itemName = this.itemName;
this.includeAppliedCSSClasses();

const editConfig = ComponentMapping.getEditConfig(this.type);

Expand All @@ -198,6 +198,17 @@ export class AEMComponentDirective implements AfterViewInit, OnInit, OnDestroy,
this._changeDetectorRef.detectChanges();
}

/**
* Adds the applied css class names in to the element
*/
private includeAppliedCSSClasses() {
const appliedCssClassNames = this.cqItem[Constants.APPLIED_CLASS_NAMES] || '';

if (appliedCssClassNames && this._component) {
this.renderer.setAttribute(this._component.location.nativeElement, 'class', appliedCssClassNames);
}
}

/**
* Adds the specified item attributes to the element
*/
Expand Down Expand Up @@ -248,6 +259,8 @@ export class AEMComponentDirective implements AfterViewInit, OnInit, OnDestroy,
}

ngOnDestroy(): void {
this._component && this._component.destroy();
if (this._component) {
this._component.destroy();
}
}
}
5 changes: 5 additions & 0 deletions src/lib/layout/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ export const Constants = {
*/
NEW_SECTION_CLASS_NAMES: 'new section',

/**
* CSS Class names applied to a component.
*/
APPLIED_CLASS_NAMES: 'appliedCssClassNames',

TYPE_PROP: PMConstants.TYPE_PROP,

/**
Expand Down

0 comments on commit 3816ec1

Please sign in to comment.