-
Notifications
You must be signed in to change notification settings - Fork 395
feat(toc): add table of contents to overview and guides #230
Changes from 4 commits
d301182
d4fe59d
0d5d263
4e68acc
a33fd9d
db25f6f
32b431b
3368cdf
fef4b11
5c01747
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
<doc-viewer | ||
documentUrl="/assets/documents/overview/{{componentViewer.componentDocItem.id}}.html" | ||
class="docs-component-view-text-content"></doc-viewer> | ||
class="docs-component-view-text-content docs-component-overview"> | ||
</doc-viewer> | ||
<table-of-contents | ||
container=".mat-sidenav-content"> | ||
</table-of-contents> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import {Component, Input, OnInit} from '@angular/core'; | ||
import {Router} from '@angular/router'; | ||
|
||
/** | ||
* Header link is a component that handles normalizing | ||
* the anchor jump tags with the current route url. | ||
* | ||
* For example: | ||
* | ||
* <a href="#foo">Foo</a> | ||
* | ||
* would result in the wrong url, this component | ||
* combines the current route with that jump link: | ||
* | ||
* <a href="/guide#foo">Foo</a> | ||
*/ | ||
@Component({ | ||
selector: 'header-link', | ||
template: ` | ||
<a | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this anchor would also benefit from an |
||
title="Link to this heading" | ||
class="docs-markdown-a docs-header-link" | ||
aria-label="Link to this heading" | ||
[href]="url"> | ||
<i class="material-icons">link</i> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This |
||
</a> | ||
` | ||
}) | ||
export class HeaderLink implements OnInit { | ||
|
||
@Input() example: string; | ||
|
||
url: string; | ||
private _rootUrl: string; | ||
|
||
constructor(router: Router) { | ||
this._rootUrl = router.url.split('#')[0]; | ||
} | ||
|
||
ngOnInit(): void { | ||
this.url = `${this._rootUrl}#${this.example}`; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
@mixin table-of-contents-theme($theme) { | ||
$primary: map-get($theme, primary); | ||
$accent: map-get($theme, accent); | ||
$warn: map-get($theme, warn); | ||
$background: map-get($theme, background); | ||
$foreground: map-get($theme, foreground); | ||
|
||
.docs-toc-container { | ||
border-left: solid 4px mat-color($primary); | ||
|
||
a { | ||
color: mat-color($foreground, secondary-text); | ||
|
||
&:hover, | ||
&.active { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need to prefix these classes with |
||
color: mat-color($primary); | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import {CommonModule} from '@angular/common'; | ||
import {NgModule} from '@angular/core'; | ||
import {TableOfContents} from './table-of-contents'; | ||
import {RouterModule} from '@angular/router'; | ||
|
||
@NgModule({ | ||
imports: [CommonModule, RouterModule], | ||
declarations: [TableOfContents], | ||
exports: [TableOfContents], | ||
entryComponents: [TableOfContents], | ||
}) | ||
export class TableOfContentsModule { } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
:host { | ||
font-size: 13px; | ||
width: 15%; | ||
position: sticky; | ||
top: 0; | ||
} | ||
|
||
.docs-toc-container { | ||
padding: 5px 0 10px 12px; | ||
} | ||
|
||
.docs-toc-heading { | ||
margin: 0; | ||
padding: 0; | ||
font-size: 13px; | ||
font-weight: bold; | ||
} | ||
|
||
a { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change you make this style a css class instead of styling |
||
line-height: 16px; | ||
margin: 8px 0 0; | ||
position: relative; | ||
text-decoration: none; | ||
display: block; | ||
} | ||
|
||
.docs-level-h4 { | ||
margin-left: 12px; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to be nested? Nesting for organization should be avoided
https://github.com/angular/material2/blob/master/CODING_STANDARDS.md#use-lowest-specificity-possible
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it needs to override the host
top
position.