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

feat(): Search and virtual scroll readme refactor #1093

Merged
merged 4 commits into from
Jan 17, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
75 changes: 4 additions & 71 deletions src/app/components/components/search/search.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,74 +42,7 @@ <h3>Search Box in Toolbar</h3>
<button mat-button color="primary" (click)="toggleAlwaysVisible()" class="text-upper">Always Visible</button>
</mat-card-actions>
</mat-card>
<mat-card>
<mat-card-title>TdSearchInputComponent</mat-card-title>
<mat-card-subtitle>How to use this component</mat-card-subtitle>
<mat-divider></mat-divider>
<mat-card-content>
<h2><code><![CDATA[<td-search-input>]]></code></h2>
<p>Use <code><![CDATA[<td-search-input>]]></code> element to generate a search input with its animated cancel button.</p>
<h3>Properties:</h3>
<p>The <code><![CDATA[<td-search-input>]]></code> component has {{searchInputAttrs.length}} properties:</p>
<mat-list>
<ng-template let-attr let-last="attr" ngFor [ngForOf]="searchInputAttrs">
<a mat-list-item layout-align="row">
<h3 matLine> {{attr.name}}: <span>{{attr.type}}</span></h3>
<p matLine> {{attr.description}} </p>
</a>
<mat-divider *ngIf="!last"></mat-divider>
</ng-template>
</mat-list>
<h3>Example:</h3>
<p>HTML:</p>
<td-highlight lang="html">
<![CDATA[
<td-search-input placeholder="Search here" [(ngModel)]="searchInputTerm" [showUnderline]="false|true" [debounce]="500" (searchDebounce)="searchInputTerm = $event" (search)="searchInputTerm = $event" (clear)="searchInputTerm = ''">
</td-search-input>
]]>
</td-highlight>
<h3>Setup:</h3>
<p>Import the [CovalentSearchModule] in your NgModule:</p>
<td-highlight lang="typescript">
<![CDATA[
import { CovalentSearchModule } from '@covalent/core/search';
@NgModule({
imports: [
CovalentSearchModule,
...
],
...
})
export class MyModule {}
]]>
</td-highlight>
</mat-card-content>
</mat-card>
<mat-card>
<mat-card-title>TdSearchBoxComponent</mat-card-title>
<mat-card-subtitle>How to use this component</mat-card-subtitle>
<mat-divider></mat-divider>
<mat-card-content>
<h2><code><![CDATA[<td-search-box>]]></code></h2>
<p>Use <code><![CDATA[<td-search-box>]]></code> element to generate a search box with animations.</p>
<h3>Properties:</h3>
<p>The <code><![CDATA[<td-search-box>]]></code> component has {{searchBoxAttrs.length}} properties:</p>
<mat-list>
<ng-template let-attr let-last="last" ngFor [ngForOf]="searchBoxAttrs">
<a mat-list-item layout-align="row">
<h3 matLine> {{attr.name}}: <span>{{attr.type}}</span></h3>
<p matLine> {{attr.description}} </p>
</a>
<mat-divider *ngIf="!last"></mat-divider>
</ng-template>
</mat-list>
<h3>Example:</h3>
<p>HTML:</p>
<td-highlight lang="html">
<![CDATA[
<td-search-box backIcon="arrow_back" placeholder="Search here" [(ngModel)]="searchInputTerm" [showUnderline]="false|true" [debounce]="500" [alwaysVisible]="false|true" (searchDebounce)="searchInputTerm = $event" (search)="searchInputTerm = $event" (clear)="searchInputTerm = ''">
</td-search-box>
]]>
</td-highlight>
</mat-card-content>
</mat-card>

<td-readme-loader resourceUrl="platform/core/search/search-input/README.md"></td-readme-loader>

<td-readme-loader resourceUrl="platform/core/search/search-box/README.md"></td-readme-loader>
69 changes: 0 additions & 69 deletions src/platform/core/search/README.md

This file was deleted.

59 changes: 59 additions & 0 deletions src/platform/core/search/search-box/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# TdSearchBoxComponent: td-search-box

`td-search-box` element to generate a search box with animations.

## API Summary

#### Inputs

+ backIcon?: string
+ The icon used to close the search toggle, only shown when [alwaysVisible] is false. Defaults to 'search' icon.
+ searchIcon?: string
+ The icon used to open/focus the search toggle. Defaults to 'search' icon.
+ clearIcon?: string
+ The icon used to clear the search input. Defaults to 'cancel' icon.
+ showUnderline?: boolean
+ Sets if the input underline should be visible. Defaults to 'false'.
+ debounce?: number
+ Debounce timeout between keypresses. Defaults to 400.
+ alwaysVisible?: boolean
+ Sets if the input should always be visible. Defaults to 'false'.
+ placeholder?: string
+ Placeholder for the underlying input component.

#### Events

+ searchDebounce?: string
+ Event emitted after the [debounce] timeout.
+ Emits a [string].
+ search?: string
+ Event emitted after the key enter has been pressed.
+ Emits a [string].
+ clear?: string
+ Event emitted after the clear icon has been clicked.
+ Emits [void].

## Setup

Import the [CovalentSearchModule] in your NgModule:

```typescript
import { CovalentSearchModule } from '@covalent/core/search';
@NgModule({
imports: [
CovalentSearchModule,
...
],
...
})
export class MyModule {}
```

## Usage

Example for HTML usage:

```html
<td-search-box backIcon="arrow_back" placeholder="Search here" [(ngModel)]="searchInputTerm" [showUnderline]="false|true" [debounce]="500" [alwaysVisible]="false|true" (searchDebounce)="searchInputTerm = $event" (search)="searchInputTerm = $event" (clear)="searchInputTerm = ''">
</td-search-box>
```
62 changes: 62 additions & 0 deletions src/platform/core/search/search-input/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# TdSearchInputComponent: td-search-input

`td-search-input` element to generate a search input with its animated cancel button.

## API Summary

#### Inputs

+ debounce?: number
+ Debounce timeout between keypresses. Defaults to 400.
+ placeholder?: string
+ Placeholder for the underlying input component.
+ showUnderline?: boolean
+ Sets if the input underline should be visible. Defaults to 'false'.
+ clearIcon?: string
+ The icon used to clear the search input. Defaults to 'cancel' icon.

#### Events

+ searchDebounce: function
+ Event emitted after the [debounce] timeout.
+ Emits a [string].
+ search: function
+ Event emitted after the key enter has been pressed.
+ Emits a [string].
+ clear: function
+ Event emitted after the clear icon has been clicked.
+ Emits [void].
+ blur: function
+ Event emitted after the blur event has been called in underlying input.
+ Emits [void].

#### Methods
+ focus: function
+ Method to focus to underlying input.
+ clearSearch: function
+ Method to clear the underlying input.

## Setup

Import the [CovalentSearchModule] in your NgModule:

```typescript
import { CovalentSearchModule } from '@covalent/core/search';
@NgModule({
imports: [
CovalentSearchModule,
...
],
...
})
export class MyModule {}
```

## Usage

Example for HTML usage:

```html
<td-search-input placeholder="Search here" [(ngModel)]="searchInputTerm" [showUnderline]="false|true" [debounce]="500" (searchDebounce)="searchInputTerm = $event" (search)="searchInputTerm = $event" (clear)="searchInputTerm = ''">
</td-search-input>
```
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ export class TdSearchInputComponent extends _TdSearchInputMixinBase implements I
this.onSearch.emit(this.value);
}

/**
* Method to clear the underlying input.
*/
clearSearch(): void {
this.value = '';
this._changeDetectorRef.markForCheck();
Expand Down
27 changes: 17 additions & 10 deletions src/platform/core/virtual-scroll/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,23 @@

## API Summary

Properties:

| Name | Type | Description |
| --- | --- | 650--- |
| `data` | `any[]` | List of items to virtually iterate on.
| `trackBy?` | `TrackByFunction` | This accepts the same trackBy function [ngFor] does. https://angular.io/api/core/TrackByFunction
| `refresh` | `function()` | Method to refresh and recalculate the virtual rows
| `scrollTo` | `function(row)` | Method to scroll to a specific row of the list.
| `scrollToStart` | `function()` | Method to scroll to the start of the list.
| `scrollToEnd` | `function()` | Method to scroll to the end of the list.
#### Inputs

+ data?: any[]
+ List of items to virtually iterate on.
+ trackBy?: TrackByFunction
+ This accepts the same trackBy function [ngFor] does.

#### Methods

+ refresh?: function()
+ Method to refresh and recalculate the virtual rows
+ scrollTo?: function(row: number)
+ Method to scroll to a specific row of the list.
+ scrollToStart?: function()
+ Method to scroll to the start of the list.
+ scrollToEnd?: function()
+ Method to scroll to the end of the list.

## Setup

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, Directive, Input, Output, EventEmitter, ContentChild, AfterViewInit, ViewChild,
import { Component, Directive, Input, EventEmitter, ContentChild, AfterViewInit, ViewChild,
ChangeDetectionStrategy, ChangeDetectorRef, QueryList, ViewChildren, ElementRef, HostListener,
Renderer2, AfterViewChecked, OnDestroy, TrackByFunction } from '@angular/core';
import { DomSanitizer, SafeStyle } from '@angular/platform-browser';
Expand Down Expand Up @@ -27,7 +27,7 @@ export class TdVirtualScrollContainerComponent implements AfterViewInit, AfterVi

private _fromRow: number = 0;
private _toRow: number = 0;

private _data: any[];
private _virtualData: any[];

Expand Down Expand Up @@ -129,7 +129,7 @@ export class TdVirtualScrollContainerComponent implements AfterViewInit, AfterVi
}
}
}

/**
* Method to refresh and recalculate the virtual rows
* e.g. after changing the [data] content
Expand Down Expand Up @@ -180,7 +180,7 @@ export class TdVirtualScrollContainerComponent implements AfterViewInit, AfterVi
this._fromRow = 0;
this._toRow = 0;
}

let offset: number = 0;
if (this._scrollVerticalOffset > (TD_VIRTUAL_OFFSET * this.rowHeight)) {
offset = this.fromRow * this.rowHeight;
Expand Down