-
Notifications
You must be signed in to change notification settings - Fork 277
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[sitecore-jss-angular] Implement Link-List SXA component (#1898)
* [sitecore-jss] Introduce extra types from Edge schema into models (cherry picked from commit f09a6cd) * mid-way implementation * rework implementation * changelog * make SXA base component generic * cleanup console.log
- Loading branch information
1 parent
d08b137
commit 284ab8f
Showing
7 changed files
with
80 additions
and
6 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
17 changes: 17 additions & 0 deletions
17
...e-jss/src/templates/angular-xmcloud/src/app/components/link-list/link-list.component.html
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 @@ | ||
<div class="component link-list {{ styles }}" [attr.id]="id"> | ||
<div class="component-content"> | ||
<ng-container *ngIf="title; else defaultTitle"> | ||
<h3 *scText="title"></h3> | ||
</ng-container> | ||
<ul> | ||
<li *ngFor="let fieldLink of fieldLinks;index as i" [ngClass]="getFieldLinkClass(i)" > | ||
<div class="field-link"> | ||
<a *scLink="fieldLink"></a> | ||
</div> | ||
</li> | ||
</ul> | ||
</div> | ||
<ng-template #defaultTitle> | ||
<span class="is-empty-hint">Link list</span> | ||
</ng-template> | ||
</div> |
36 changes: 36 additions & 0 deletions
36
...ore-jss/src/templates/angular-xmcloud/src/app/components/link-list/link-list.component.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,36 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
import { SxaComponent } from '../sxa.component'; | ||
import { Field, LinkField, SxaLinkListFields } from '@sitecore-jss/sitecore-jss-angular'; | ||
|
||
@Component({ | ||
selector: 'app-link-list', | ||
templateUrl: './link-list.component.html', | ||
}) | ||
export class LinkListComponent extends SxaComponent<SxaLinkListFields> implements OnInit { | ||
title?: Field<string>; | ||
fieldLinks: LinkField[] = []; | ||
|
||
getFieldLinkClass(index: number): string { | ||
let className = `item${index}`; | ||
className += (index + 1) % 2 == 0 ? ' even' : ' odd'; | ||
if (index === 0) { | ||
className += ' first'; | ||
} | ||
if (index + 1 === this.fieldLinks.length) { | ||
className += ' last'; | ||
} | ||
return className; | ||
} | ||
|
||
ngOnInit() { | ||
super.ngOnInit(); | ||
const datasource = this.rendering.fields?.data?.datasource; | ||
if (datasource) { | ||
this.title = datasource.field?.title as Field<string>; | ||
datasource.children.results.forEach(item => { | ||
if (item.field?.link) | ||
this.fieldLinks.push(item.field.link as LinkField); | ||
}); | ||
} | ||
} | ||
} |
6 changes: 3 additions & 3 deletions
6
...ges/create-sitecore-jss/src/templates/angular-xmcloud/src/app/components/sxa.component.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
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