Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sitecore-jss-angular] Implement Link-List SXA component #1898

Merged
merged 6 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Our versioning strategy is as follows:
* Richtext component ([#1864](https://github.com/Sitecore/jss/pull/1864))
* Container component ([#1872](https://github.com/Sitecore/jss/pull/1872))
* Angular SXA layout ([#1873](https://github.com/Sitecore/jss/pull/1873))([#1880](https://github.com/Sitecore/jss/pull/1880))([#1890](https://github.com/Sitecore/jss/pull/1890))
* Link-List ([#1898](https://github.com/Sitecore/jss/pull/1898))
* Column-Splitter ([#1889](https://github.com/Sitecore/jss/pull/1889))

### 🛠 Breaking Change
Expand Down
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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
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 {
art-alexeyenko marked this conversation as resolved.
Show resolved Hide resolved
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);
});
}
console.log(datasource);
art-alexeyenko marked this conversation as resolved.
Show resolved Hide resolved
}
}
19 changes: 19 additions & 0 deletions packages/sitecore-jss-angular/src/components/rendering-field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,25 @@ export interface LinkField extends LinkFieldValue, RenderingField {
editableLastPart?: string;
}

interface LayoutServiceLinkField {
field: {
link: LinkField;
};
}

export interface SxaLinkListFields {
data: {
datasource: {
children: {
results: LayoutServiceLinkField[];
};
field: {
title: TextField;
};
};
};
}

export interface RichTextField extends RenderingField<string> {}

export interface TextField extends RenderingField<string> {}
1 change: 1 addition & 0 deletions packages/sitecore-jss-angular/src/public_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export {
RenderingField,
RichTextField,
TextField,
SxaLinkListFields,
} from './components/rendering-field';
export { RichTextDirective } from './components/rich-text.directive';
export { TextDirective } from './components/text.directive';
Expand Down
6 changes: 3 additions & 3 deletions packages/sitecore-jss/src/layout/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ export interface ComponentParams {
/**
* Definition of a component instance within a placeholder on a route
*/
export interface ComponentRendering {
export interface ComponentRendering<T = ComponentFields> {
componentName: string;
dataSource?: string;
uid?: string;
placeholders?: PlaceholdersData;
fields?: ComponentFields;
fields?: T;
params?: ComponentParams;
}

Expand Down Expand Up @@ -137,7 +137,7 @@ export interface FieldMetadata {
}

/**
* Content data returned from Content Service
* Content data returned from Layout Service
*/
export interface Item {
name: string;
Expand Down