Skip to content

Commit

Permalink
feat(docs): add version select (#1599)
Browse files Browse the repository at this point in the history
  • Loading branch information
yggg authored Jun 12, 2019
1 parent c2a11fb commit 3987d76
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 23 deletions.
18 changes: 14 additions & 4 deletions docs/app/@theme/components/header/header.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@

&.middle {
flex: 1;
align-items: center;
margin: 0 -0.5rem;
}
}

Expand All @@ -53,10 +55,6 @@
.menu-item {
border: none;

&:first-child a {
padding-left: 0;
}

a {
color: $menu-item-fg;
display: block;
Expand Down Expand Up @@ -100,6 +98,10 @@
margin-left: auto;
}

.version-select {
display: none;
}

@include media-breakpoint-up(is) {
.section {
padding: 0.875rem 1.125rem;
Expand All @@ -118,6 +120,10 @@
display: inline;
}
}

.version-select {
display: block;
}
}

@include media-breakpoint-up(md) {
Expand Down Expand Up @@ -184,6 +190,9 @@
ngd-search {
display: none;
}
.version-select {
margin-left: 1rem;
}

@include media-breakpoint-up(is) {
::ng-deep nb-menu .menu-items li:first-child {
Expand All @@ -195,6 +204,7 @@
ngd-search {
display: flex;
align-items: center;
margin-left: auto;
}
}

Expand Down
20 changes: 17 additions & 3 deletions docs/app/@theme/components/header/header.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ChangeDetectionStrategy, Component, HostBinding, Input, OnInit } from '@angular/core';
import { NbMenuItem, NbSidebarService } from '@nebular/theme';
import { ChangeDetectionStrategy, Component, HostBinding, Inject, Input, OnInit } from '@angular/core';
import { NB_WINDOW, NbMenuItem, NbSidebarService } from '@nebular/theme';
import { NgdVersionService } from '../../services';

@Component({
Expand All @@ -18,6 +18,11 @@ import { NgdVersionService } from '../../services';
<div class="section middle">
<nb-menu [items]="mainMenu"></nb-menu>
<ngd-search *ngIf="showSearch"></ngd-search>
<nb-select class="version-select" [selected]="currentVersion" (selectedChange)="redirectToVersion($event)">
<nb-option *ngFor="let version of versions" [value]="version">
{{ version }}
</nb-option>
</nb-select>
</div>
<div class="section right">
<iframe class="stars"
Expand All @@ -34,6 +39,8 @@ export class NgdHeaderComponent implements OnInit {
@Input() showSearch = true;
@HostBinding('class.docs-page') @Input() isDocs = false;

private window: Window;
versions: string[];
currentVersion: string;

mainMenu: NbMenuItem[] = [
Expand Down Expand Up @@ -62,10 +69,13 @@ export class NgdHeaderComponent implements OnInit {
@Input() sidebarTag: string;

constructor(
versionService: NgdVersionService,
@Inject(NB_WINDOW) window,
private versionService: NgdVersionService,
private sidebarService: NbSidebarService,
) {
this.window = window;
this.currentVersion = versionService.getNebularVersion();
this.versions = versionService.getNebularVersions();
}

ngOnInit() {
Expand All @@ -80,4 +90,8 @@ export class NgdHeaderComponent implements OnInit {
toggleSidebar() {
this.sidebarService.toggle(false, this.sidebarTag);
}

redirectToVersion(version: string): void {
this.window.location.href = this.versionService.getVersionPath(version);
}
}
17 changes: 3 additions & 14 deletions docs/app/@theme/components/search/search.component.scss
Original file line number Diff line number Diff line change
@@ -1,28 +1,17 @@
@import '../../../@theme/styles/themes';

@include nb-install-component() {

$bg: #f6f6f7;
$fg: #8994a3;

position: relative;

input {
border-radius: 4px;
background-color: $bg;
padding: 0.685rem 3rem;
border: none;

&::placeholder {
color: $fg;
}
padding-left: 3rem;
}

nb-icon {
color: $fg;
color: nb-theme(input-placeholder-text-color);
position: absolute;
top: 50%;
transform: translate(0, -50%);
transform: translateY(-50%);
left: 1rem;
z-index: 1;
font-size: 1.25rem;
Expand Down
2 changes: 1 addition & 1 deletion docs/app/@theme/components/search/search.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { NB_WINDOW } from '@nebular/theme';
styleUrls: ['./search.component.scss'],
template: `
<nb-icon icon="search-outline"></nb-icon>
<input type="text" id="doc-search" placeholder="Start typing...">
<input type="text" nbInput id="doc-search" placeholder="Start typing...">
`,
changeDetection: ChangeDetectionStrategy.OnPush,
})
Expand Down
14 changes: 14 additions & 0 deletions docs/app/@theme/services/version.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,21 @@ import { Injectable } from '@angular/core';
@Injectable()
export class NgdVersionService {

versionsExceptCurrent = [ '3.6.0' ];

getNebularVersion() {
return require('../../../../package.json').version;
}

getNebularVersions(): string[] {
return this.versionsExceptCurrent.concat(this.getNebularVersion());
}

getVersionPath(version: string): string {
if (version === this.getNebularVersion()) {
return '/nebular';
}

return `/nebular/${version}`;
}
}
3 changes: 3 additions & 0 deletions docs/app/@theme/styles/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
@include nb-input-theme();
@include nb-typography();
@include nb-buttons-theme();
@include nb-select-theme();
@include nb-input-theme();
@include nb-overlay-theme();

@include nbd-common();

Expand Down
2 changes: 2 additions & 0 deletions docs/app/@theme/styles/themes.scss
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ $nb-themes: nb-register-theme((
radius: 0.375rem,
color-fg-highlight: #40dc7e,

select-min-width: 5rem,

color-fg: white,
color-fg-heading: #0d1c2e,
color-fg-text: #919fb1,
Expand Down
4 changes: 4 additions & 0 deletions docs/app/@theme/theme.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import {
NbCheckboxModule,
NbIconModule,
NbButtonModule,
NbSelectModule,
NbInputModule,
} from '@nebular/theme';

import { NbEvaIconsModule } from '@nebular/eva-icons';
Expand Down Expand Up @@ -63,6 +65,8 @@ import {
NbTabsetModule,
NbIconModule,
NbButtonModule,
NbSelectModule,
NbInputModule,
NbEvaIconsModule,
RouterModule,
],
Expand Down
2 changes: 1 addition & 1 deletion docs/assets/ghspa.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

;(function(l, projectPages) {

const versions = [ '3.5.0', '3.6.0' ];
const versions = ['3.6.0'];

var paths = l.pathname.split('/');
var repo = projectPages ? '/' + paths[1] : '';
Expand Down

0 comments on commit 3987d76

Please sign in to comment.