-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(daffio): render subpackages on package page (#3094)
--------- Co-authored-by: xelaint <xelaint@gmail.com>
- Loading branch information
Showing
13 changed files
with
306 additions
and
18 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
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
23 changes: 23 additions & 0 deletions
23
apps/daffio/src/app/docs/api/components/api-package/api-package-theme.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,23 @@ | ||
@use 'theme' as daff-theme; | ||
|
||
@mixin daffio-api-package-theme($theme) { | ||
$neutral: daff-theme.daff-map-deep-get($theme, 'core.neutral'); | ||
$base: daff-theme.daff-map-deep-get($theme, "core.base"); | ||
$base-contrast: daff-theme.daff-map-deep-get($theme, "core.base-contrast"); | ||
|
||
.daffio-api-package { | ||
&__subpackage-name { | ||
> * { | ||
&:focus { | ||
border-radius: 4px; | ||
box-shadow: 0 0 0 4px rgba($base-contrast, 0.1); | ||
outline: none; | ||
} | ||
} | ||
|
||
&:hover { | ||
color: daff-theme.daff-illuminate($base-contrast, $neutral, 3); | ||
} | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
apps/daffio/src/app/docs/api/components/api-package/api-package.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,16 @@ | ||
<div class="daffio-api-package__wrapper"> | ||
<div class="daffio-api-package__header"> | ||
<h1 class="daffio-api-package__package-name">{{doc.title}}</h1> | ||
<p *ngIf="doc.description" class="daffio-api-package__package-description">{{doc.description}}</p> | ||
</div> | ||
<daffio-api-list-section [children]="doc.children | apiPackageFilter:true" class="daffio-doc-viewer__api-section"></daffio-api-list-section> | ||
</div> | ||
|
||
@for (package of doc.children | apiPackageFilter; track package.id) { | ||
<div class="daffio-api-package__wrapper"> | ||
<h2 class="daffio-api-package__subpackage-name"> | ||
<a [routerLink]="package.path">{{package.title}}</a> | ||
</h2> | ||
<daffio-api-list-section [children]="package.children | apiPackageFilter:true" class="daffio-doc-viewer__api-section" [attr.data-section-for-subpackage]="package.id"></daffio-api-list-section> | ||
</div> | ||
} |
64 changes: 64 additions & 0 deletions
64
apps/daffio/src/app/docs/api/components/api-package/api-package.component.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,64 @@ | ||
@use '../../../../../scss/type-descriptors/mixins' as type-mixin; | ||
@use 'utilities' as daff; | ||
|
||
:host { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 48px; | ||
|
||
a { | ||
text-decoration: none; | ||
} | ||
} | ||
|
||
.daffio-api-package { | ||
&__wrapper { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 24px; | ||
} | ||
|
||
&__header { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 16px; | ||
} | ||
|
||
&__package-name { | ||
@include daff.headline-lg; | ||
|
||
> * { | ||
@include daff.text-truncate(); | ||
|
||
@include daff.breakpoint(mobile) { | ||
display: inline; | ||
} | ||
} | ||
} | ||
|
||
&__package-description { | ||
@include daff.body-md; | ||
font-weight: 400; | ||
margin: 0; | ||
padding: 0; | ||
} | ||
|
||
&__subpackage-name { | ||
font-size: 1.125rem; | ||
font-weight: 600; | ||
line-height: 1.375rem; | ||
|
||
@include daff.breakpoint(mobile) { | ||
font-size: 1.25rem; | ||
line-height: 1.75rem; | ||
} | ||
|
||
> * { | ||
@include daff.text-truncate(); | ||
|
||
@include daff.breakpoint(mobile) { | ||
display: inline-block; | ||
} | ||
} | ||
} | ||
} |
128 changes: 128 additions & 0 deletions
128
apps/daffio/src/app/docs/api/components/api-package/api-package.component.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,128 @@ | ||
import { | ||
Component, | ||
DebugElement, | ||
} from '@angular/core'; | ||
import { | ||
ComponentFixture, | ||
TestBed, | ||
waitForAsync, | ||
} from '@angular/core/testing'; | ||
import { By } from '@angular/platform-browser'; | ||
import { RouterTestingModule } from '@angular/router/testing'; | ||
|
||
import { DaffioApiPackageComponent } from './api-package.component'; | ||
import { DaffioApiReference } from '../../models/api-reference'; | ||
import { DaffioApiListSectionComponent } from '../api-list-section/api-list-section.component'; | ||
|
||
@Component({ | ||
template: ` | ||
<daffio-api-package [doc]="apiListValue"></daffio-api-package> | ||
`, | ||
standalone: true, | ||
imports: [ | ||
DaffioApiPackageComponent, | ||
], | ||
}) | ||
class WrapperComponent { | ||
apiListValue: DaffioApiReference; | ||
} | ||
|
||
describe('DaffioApiPackageComponent', () => { | ||
let wrapper: WrapperComponent; | ||
let fixture: ComponentFixture<WrapperComponent>; | ||
let component: DaffioApiPackageComponent; | ||
let packageLinks: Array<DebugElement>; | ||
|
||
beforeEach(waitForAsync(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [ | ||
WrapperComponent, | ||
RouterTestingModule, | ||
], | ||
}) | ||
.compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(WrapperComponent); | ||
wrapper = fixture.componentInstance; | ||
wrapper.apiListValue = { | ||
id: 'Root', | ||
path: 'path', | ||
docType: 'package', | ||
docTypeShorthand: 'pk', | ||
title: 'title', | ||
description: 'description', | ||
children: [ | ||
{ | ||
id: 'name1Component', | ||
title: 'title1Component', | ||
path: 'path1', | ||
docType: 'docType1', | ||
docTypeShorthand: 'dt', | ||
children: [], | ||
}, | ||
{ | ||
id: 'name2Module', | ||
title: 'title2Module', | ||
path: 'path2', | ||
docType: 'package', | ||
docTypeShorthand: 'pk', | ||
children: [ | ||
{ | ||
id: 'name1Component', | ||
title: 'title1Component', | ||
path: 'path1', | ||
docType: 'docType1', | ||
docTypeShorthand: 'dt', | ||
children: [], | ||
}, | ||
{ | ||
id: 'name2Module', | ||
title: 'title2Module', | ||
path: 'path2', | ||
docType: 'package', | ||
docTypeShorthand: 'pk', | ||
children: [], | ||
}, | ||
], | ||
}, | ||
], | ||
}; | ||
fixture.detectChanges(); | ||
|
||
component = fixture.debugElement.query(By.css('daffio-api-package')).componentInstance; | ||
packageLinks = fixture.debugElement.queryAll(By.css('a.daffio-api-package__package-name')); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
|
||
it('should be able to take doc as input', () => { | ||
expect(component.doc).toEqual(wrapper.apiListValue); | ||
}); | ||
|
||
describe('for every subpackage in children', () => { | ||
let subpackages: Array<DaffioApiReference>; | ||
|
||
beforeEach(() => { | ||
subpackages = wrapper.apiListValue.children.filter((d) => d.docType === 'package'); | ||
}); | ||
|
||
it('should render a link with the title', () => { | ||
packageLinks.forEach((de, i) => { | ||
expect(de.nativeElement.innerText).toEqual(subpackages[i].title); | ||
expect(de.attributes['ng-reflect-router-link']).toEqual(subpackages[i].path); | ||
}); | ||
}); | ||
|
||
it('should render an API section with the subpackage children excluding packages', () => { | ||
packageLinks.forEach((de, i) => { | ||
const apiSection: DaffioApiListSectionComponent = fixture.debugElement.query(By.css(`daffio-api-list-section[data-section-for-subpackage="${subpackages[i].id}"]`)).componentInstance; | ||
expect(apiSection.children).toEqual(subpackages[i].children.filter((c) => c.docType !== 'package')); | ||
}); | ||
}); | ||
}); | ||
|
||
}); |
39 changes: 39 additions & 0 deletions
39
apps/daffio/src/app/docs/api/components/api-package/api-package.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,39 @@ | ||
import { | ||
Component, | ||
Input, | ||
ChangeDetectionStrategy, | ||
HostBinding, | ||
} from '@angular/core'; | ||
import { RouterLink } from '@angular/router'; | ||
|
||
import { DaffArticleEncapsulatedDirective } from '@daffodil/design'; | ||
import { DaffArticleModule } from '@daffodil/design/article'; | ||
|
||
import { DaffioApiPackageFilterPipe } from './not-packages.pipe'; | ||
import { DaffioApiReference } from '../../models/api-reference'; | ||
import { DaffioApiListSectionComponent } from '../api-list-section/api-list-section.component'; | ||
|
||
@Component({ | ||
selector: 'daffio-api-package', | ||
templateUrl: './api-package.component.html', | ||
styleUrls: ['./api-package.component.scss'], | ||
hostDirectives: [{ | ||
directive: DaffArticleEncapsulatedDirective, | ||
}], | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
standalone: true, | ||
imports: [ | ||
RouterLink, | ||
DaffioApiListSectionComponent, | ||
DaffArticleModule, | ||
DaffioApiPackageFilterPipe, | ||
], | ||
}) | ||
export class DaffioApiPackageComponent { | ||
@HostBinding('class.daffio-api-package') class = true; | ||
|
||
/** | ||
* A list of references for API documents. | ||
*/ | ||
@Input() doc: DaffioApiReference; | ||
} |
23 changes: 23 additions & 0 deletions
23
apps/daffio/src/app/docs/api/components/api-package/not-packages.pipe.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,23 @@ | ||
import { | ||
Pipe, | ||
PipeTransform, | ||
} from '@angular/core'; | ||
|
||
import { DaffioApiReference } from '../../models/api-reference'; | ||
|
||
/** | ||
* Filters packages from a list of API docs. | ||
* If exclude is false or omitted, will only output packages. | ||
* Otherwise it will omit packages from the output. | ||
*/ | ||
@Pipe({ | ||
name: 'apiPackageFilter', | ||
standalone: true, | ||
}) | ||
export class DaffioApiPackageFilterPipe implements PipeTransform { | ||
transform(docs: Array<DaffioApiReference>, exclude = false) { | ||
return exclude | ||
? docs.filter((doc) => doc.docType !== 'package') | ||
: docs.filter((doc) => doc.docType === 'package'); | ||
} | ||
} |
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
Oops, something went wrong.