Skip to content

Commit

Permalink
Merge b6fda4c into b96fc06
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremythuff committed Oct 2, 2020
2 parents b96fc06 + b6fda4c commit bd58c1a
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 52 deletions.
2 changes: 1 addition & 1 deletion lighthouserc.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"assertions": {
"first-contentful-paint": "off",
"categories:performance": ["error", {"minScore": 0}],
"categories:accessibility": ["error", {"minScore": 0.8}],
"categories:accessibility": ["error", {"minScore": 0.9}],
"categories:best-practices": ["error", {"minScore": 0}],
"categories:seo": ["error", {"minScore": 0}],
"categories:pwa":["error", {"minScore": 0}]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
<wvr-list-item-wrapper *ngIf="listType==='unordered' || listType==='unstyled' || listType==='ordered'">
<li>
<template #liWrapper *ngIf="listType==='unordered' || listType==='unstyled' || listType==='ordered'">
<li [id]="htmlId">
<ng-container *ngTemplateOutlet="contentProjection"></ng-container>
</li>
</wvr-list-item-wrapper>
</template>

<wvr-list-item-wrapper *ngIf="listType==='described'">
<dt>
<template #liWrapper *ngIf="listType==='described'">
<dt [id]="htmlId">
{{description}}
</dt>
<dd>
<ng-container *ngTemplateOutlet="contentProjection"></ng-container>
</dd>
</wvr-list-item-wrapper>
</template>

<wvr-list-item-wrapper *ngIf="listType==='group-ul' || listType==='group'">
<template #liWrapper *ngIf="listType==='group-ul' || listType==='group'">
<li class="list-group-item d-flex justify-content-between align-items-center"
[id]="htmlId"
[ngClass]="{
'list-group-item-primary': context === 'primary',
'list-group-item-secondary': context === 'secondary',
Expand All @@ -27,10 +28,11 @@
}">
<ng-container *ngTemplateOutlet="contentProjection"></ng-container>
</li>
</wvr-list-item-wrapper>
</template>

<wvr-list-item-wrapper *ngIf="listType==='group-div'">
<template #liWrapper *ngIf="listType==='group-div'">
<button class="list-group-item list-group-item-action"
[id]="htmlId"
[ngClass]="{
'list-group-item-primary': context === 'primary',
'list-group-item-secondary': context === 'secondary',
Expand All @@ -40,19 +42,19 @@
'list-group-item-warning': context === 'warning',
'list-group-item-light': context === 'light',
'list-group-item-dark': context === 'dark'
}">
}" role="listitem">
<ng-container *ngTemplateOutlet="contentProjection"></ng-container>
</button>
</wvr-list-item-wrapper>
</template>

<wvr-list-item-wrapper *ngIf="listType==='group-flush'">
<li class="list-group-item">
<template #liWrapper *ngIf="listType==='group-flush'">
<li [id]="htmlId" class="list-group-item">
<ng-container *ngTemplateOutlet="contentProjection"></ng-container>
</li>
</wvr-list-item-wrapper>
</template>

<wvr-list-item-wrapper *ngIf="listType==='group-custom-content'">
<a class="list-group-item list-group-item-action flex-column align-items-start">
<template #liWrapper *ngIf="listType==='group-custom-content'">
<a [id]="htmlId" class="list-group-item list-group-item-action flex-column align-items-start" role="listitem">
<div class="d-flex w-100 justify-content-between">
<h5 class="mb-1">{{customContentItemHeading}}</h5>
<small>{{cusomContentHeadingSmallText}}</small>
Expand All @@ -62,7 +64,8 @@ <h5 class="mb-1">{{customContentItemHeading}}</h5>
</p>
<small>{{customContentSmallText}}</small>
</a>
</wvr-list-item-wrapper>
</template>


<ng-template #contentProjection>
<ng-content></ng-content>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { Component, Injector, Input, OnInit } from '@angular/core';
import { AfterContentInit, Component, ElementRef, Injector, Input, OnInit, ViewChild } from '@angular/core';
import { SafeHtml } from '@angular/platform-browser';
import { Theme } from '../../shared/theme.type';
import { WvrBaseComponent } from '../../shared/wvr-base.component';
import { WvrListComponent } from '../wvr-list.component';

@Component({
selector: 'wvr-list-item-element',
templateUrl: './wvr-list-item.component.html',
styleUrls: ['./wvr-list-item.component.scss']
})
export class WvrListItemComponent extends WvrBaseComponent implements OnInit {
export class WvrListItemComponent extends WvrBaseComponent implements OnInit, AfterContentInit {

private _parent: HTMLElement;
private parent: WvrListComponent;

listType: string;

Expand All @@ -23,21 +25,47 @@ export class WvrListItemComponent extends WvrBaseComponent implements OnInit {

@Input() customContentSmallText: string;

htmlId = `wvr-li-${this.id}`;

@ViewChild('liWrapper') contentProjection: ElementRef<HTMLTemplateElement>;

get htmlContent(): string {
const elems = this.contentProjection.nativeElement.children;

let htmlString = '';
for (let i = 0; i < elems.length; i++) {
const elem = elems.item(i);
htmlString += elem.outerHTML;
}

return htmlString;
}

constructor(injector: Injector) {
super(injector);
}

ngOnInit(): void {
this._parent = (this._eRef.nativeElement as HTMLElement).closest('wvr-list');

const listTypeAttribute = this._parent ? this._parent.getAttribute('list-type') : undefined;
this.listType = listTypeAttribute ? listTypeAttribute : 'unordered';
const contextAttribute = this._parent ? (this._parent.getAttribute('context') as Theme) : undefined;
this.context = this.context ?
this.context :
contextAttribute ?
contextAttribute :
undefined;

const listElem: HTMLElement = (this._eRef.nativeElement as HTMLElement).closest('wvr-list');

if (listElem) {
this.parent = this.componentRegistry
.getComponentByElement(listElem) as WvrListComponent;
this.parent.addListItem(this);

const listTypeAttribute = this.parent ? this.parent.listType : undefined;
this.listType = listTypeAttribute ? listTypeAttribute : 'unordered';
const parentTheme = this.parent ? this.parent.context : undefined;
this.context = this.context ?
this.context :
parentTheme ?
parentTheme :
undefined;
} else {
console.warn('The wvr-list-item component must be contained within a wvr-list component.');
}

}

}
29 changes: 14 additions & 15 deletions projects/wvr-elements/src/lib/wvr-list/wvr-list.component.html
Original file line number Diff line number Diff line change
@@ -1,35 +1,34 @@
<wvr-list-wrapper #animationRoot>
<ul *ngIf="listType==='unordered' || listType==='unstyled'" [ngClass]="{'list-unstyled': listType==='unstyled'}">
<ng-container *ngTemplateOutlet="listContent"></ng-container>

<ul innerHtml="{{listItemsHtml}}" *ngIf="listType==='unordered' || listType==='unstyled'" [ngClass]="{'list-unstyled': listType==='unstyled'}">
</ul>

<ol *ngIf="listType==='ordered'">
<ng-container *ngTemplateOutlet="listContent"></ng-container>
<ol innerHtml="{{listItemsHtml}}" *ngIf="listType==='ordered'">
</ol>

<dl *ngIf="listType==='described'">
<ng-container *ngTemplateOutlet="listContent"></ng-container>
<dl innerHtml="{{listItemsHtml}}" *ngIf="listType==='described'">
</dl>

<ul *ngIf="listType==='group-ul' || listType==='group'" class="list-group">
<ng-container *ngTemplateOutlet="listContent"></ng-container>
<ul innerHtml="{{listItemsHtml}}" *ngIf="listType==='group-ul' || listType==='group'" class="list-group">
</ul>

<div *ngIf="listType==='group-div'" class="list-group">
<ng-container *ngTemplateOutlet="listContent"></ng-container>
<div innerHtml="{{listItemsHtml}}" *ngIf="listType==='group-div'" class="list-group">
</div>

<ul *ngIf="listType==='group-flush'" class="list-group list-group-flush">
<ng-container *ngTemplateOutlet="listContent"></ng-container>
<ul innerHtml="{{listItemsHtml}}" *ngIf="listType==='group-flush'" class="list-group list-group-flush">
</ul>

<div *ngIf="listType==='group-custom-content'" class="list-group">
<ng-container *ngTemplateOutlet="listContent"></ng-container>
<div innerHtml="{{listItemsHtml}}" *ngIf="listType==='group-custom-content'" class="list-group">
</div>

</wvr-list-wrapper>

<ng-template #listContent>

<template>
<ng-container *ngTemplateOutlet="contentProjection"></ng-container>
</template>

<ng-template #contentProjection>
<ng-content select="wvr-list-item, wvr-list-item-element, .badge"></ng-content>
</ng-template>

30 changes: 28 additions & 2 deletions projects/wvr-elements/src/lib/wvr-list/wvr-list.component.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,43 @@
import { Component, Injector, Input } from '@angular/core';
import { AfterContentInit, AfterViewInit, Component, Injector, Input } from '@angular/core';
import { SafeHtml } from '@angular/platform-browser';
import { Theme } from '../shared/theme.type';
import { WvrBaseComponent } from '../shared/wvr-base.component';
import { WvrListItemComponent } from './wvr-list-item/wvr-list-item.component';

@Component({
selector: 'wvr-list-element',
templateUrl: './wvr-list.component.html',
styleUrls: ['./wvr-list.component.scss']
})
export class WvrListComponent extends WvrBaseComponent {
export class WvrListComponent extends WvrBaseComponent implements AfterContentInit {

private readonly listItems: Array<WvrListItemComponent>;

@Input() listType = 'unordered';

@Input() context: Theme;

private _htmlString: string;

get listItemsHtml(): SafeHtml {
return this._htmlString;
}

constructor(injector: Injector) {
super(injector);
this.listItems = new Array<WvrListItemComponent>();
}

addListItem(listItem: WvrListItemComponent): void {
this.listItems.push(listItem);
}

ngAfterContentInit(): void {
setTimeout(() => {
this._htmlString = this.listItems
.map(li => li.htmlContent)
.join('\n');
}, 0);
}

}
12 changes: 8 additions & 4 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -721,12 +721,16 @@ <h4 class="alert-heading">

<wvr-tabs>
<wvr-tab tab-text="Tab One">
<h3><wvr-text value="First Tab Header"></wvr-text></h3>
<wvr-text value="My First Tab Content"></wvr-text>
<div class="jumbotron">
<h3><wvr-text value="First Tab Header"></wvr-text></h3>
<wvr-text value="My First Tab Content"></wvr-text>
</div>
</wvr-tab>
<wvr-tab tab-text="Tab Two">
<h3><wvr-text value="Second Tab Header"></wvr-text></h3>
<wvr-text value="My Second Tab Content"></wvr-text>
<div class="jumbotron">
<h3><wvr-text value="Second Tab Header"></wvr-text></h3>
<wvr-text value="My Second Tab Content"></wvr-text>
</div>
</wvr-tab>
</wvr-tabs>

Expand Down

0 comments on commit bd58c1a

Please sign in to comment.