-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sortable): added new sortable component (#1295)
* Added sortable-list module * added sortable-list module into the main module * renamed sortable-list to sortable * removed sortable module from root index.ts export everything from sortable module * inlined html template * created docs page for sortable component * removed console.log fixed lint warning added basic tests * added tests for reordering * added tests for onZoneDragover method * added test for insert item from another container * fixed quotes * fixed insertion test * finished component covering implemented tests for service * changed dirs structure fixed compatibility with ie11 * use dumb object instead of Event * updated docs * update docs (added doc comments) * fixed compatibility with firefox
- Loading branch information
1 parent
58ca445
commit fab3df5
Showing
21 changed files
with
982 additions
and
2 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
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,10 @@ | ||
import { SortableDemoComponent } from './sortable-demo.component'; | ||
|
||
export const DEMO_COMPONENTS = [SortableDemoComponent]; | ||
|
||
export const DEMOS = { | ||
basic: { | ||
component: require('!!raw?lang=typescript!./sortable-demo.component.ts'), | ||
html: require('!!raw?lang=markup!./sortable-demo.component.html') | ||
} | ||
}; |
63 changes: 63 additions & 0 deletions
63
demo/src/app/components/sortable/demos/sortable-demo.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,63 @@ | ||
<div [ngStyle]="{ display: 'flex' }"> | ||
<div> | ||
<!-- Example with strings --> | ||
<h3>String items:</h3> | ||
<div [ngStyle]="{ display: 'flex' }"> | ||
<div [ngStyle]="{ width: '200px', 'margin-right': '10px' }"> | ||
<ng2-sortable | ||
[(ngModel)]="itemStringsLeft" | ||
[itemStyle]="itemStyle" | ||
[itemActiveStyle]="itemActiveStyle" | ||
[placeholderItem]="'Drag here'" | ||
[placeholderStyle]="placeholderStyle" | ||
[wrapperStyle]="wrapperStyle" | ||
></ng2-sortable> | ||
<pre>model: {{ itemStringsLeft | json }}</pre> | ||
</div> | ||
<div [ngStyle]="{ width: '200px' }"> | ||
<ng2-sortable | ||
[(ngModel)]="itemStringsRight" | ||
[itemStyle]="itemStyle" | ||
[itemActiveStyle]="itemActiveStyle" | ||
[placeholderItem]="'Drag here'" | ||
[placeholderStyle]="placeholderStyle" | ||
[wrapperStyle]="wrapperStyle" | ||
></ng2-sortable> | ||
<pre>model: {{ itemStringsRight | json }}</pre> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div [ngStyle]="{ 'margin-left': '50px' }"> | ||
<!-- Example with objects --> | ||
<h3>Complex data model:</h3> | ||
<div [ngStyle]="{ display: 'flex' }"> | ||
<div [ngStyle]="{ width: '200px', 'margin-right': '10px' }"> | ||
<ng2-sortable | ||
[(ngModel)]="itemObjectsLeft" | ||
[fieldName]="'name'" | ||
[itemStyle]="itemStyle" | ||
[itemActiveStyle]="itemActiveStyle" | ||
[placeholderItem]="'Drag here'" | ||
[placeholderStyle]="itemStyle" | ||
[wrapperStyle]="wrapperStyle" | ||
></ng2-sortable> | ||
<pre>model: {{ itemObjectsLeft | json }}</pre> | ||
</div> | ||
<div [ngStyle]="{ width: '200px' }"> | ||
<ng2-sortable | ||
[(ngModel)]="itemObjectsRight" | ||
[fieldName]="'name'" | ||
[itemStyle]="itemStyle" | ||
[itemActiveStyle]="itemActiveStyle" | ||
[placeholderItem]="'Drag here'" | ||
[placeholderStyle]="itemStyle" | ||
[wrapperStyle]="wrapperStyle" | ||
></ng2-sortable> | ||
<pre>model: {{ itemObjectsRight | json }}</pre> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<div> | ||
</div> |
56 changes: 56 additions & 0 deletions
56
demo/src/app/components/sortable/demos/sortable-demo.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,56 @@ | ||
import { Component } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'sortable-demo', | ||
templateUrl: './sortable-demo.component.html' | ||
}) | ||
export class SortableDemoComponent { | ||
public itemStringsLeft: any[] = [ | ||
'Windstorm', | ||
'Bombasto', | ||
'Magneta', | ||
'Tornado' | ||
]; | ||
|
||
public itemStringsRight: any[] = [ | ||
'Mr. O', | ||
'Tomato' | ||
]; | ||
|
||
public itemObjectsLeft: any[] = [ | ||
{ id: 1, name: 'Windstorm' }, | ||
{ id: 2, name: 'Bombasto' }, | ||
{ id: 3, name: 'Magneta' } | ||
]; | ||
|
||
public itemObjectsRight: any[] = [ | ||
{ id: 4, name: 'Tornado' }, | ||
{ id: 5, name: 'Mr. O' }, | ||
{ id: 6, name: 'Tomato' } | ||
]; | ||
|
||
public itemStyle: {} = { | ||
display: 'block', | ||
padding: '6px 12px', | ||
'margin-bottom': '4px', | ||
'font-size': '14px', | ||
'font-weight': 400, | ||
'line-height': '1.4em', | ||
'text-align': 'center', | ||
cursor: 'grab', | ||
border: '1px solid transparent', | ||
'border-radius': '4px', | ||
'border-color': '#adadad' | ||
}; | ||
|
||
public itemActiveStyle: {} = { | ||
'background-color': '#e6e6e6', | ||
'box-shadow': 'inset 0 3px 5px rgba(0,0,0,.125)' | ||
}; | ||
|
||
public wrapperStyle: {} = { | ||
'min-height': '150px' | ||
}; | ||
|
||
public placeholderStyle: {} = Object.assign({}, this.itemStyle, { height: '150px' }); | ||
} |
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 @@ | ||
The **sortable component** represents a list of items, with ability to sort them or move to another container via drag&drop. Input collection isn't mutated by the component, so events <code>ngModelChange</code>, <code>onChange</code> are using new collections. |
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,11 @@ | ||
```typescript | ||
// RECOMMENDED | ||
import { SortableModule } from 'ng2-bootstrap/sortable'; | ||
// or | ||
import { SortableModule } from 'ng2-bootstrap'; | ||
|
||
@NgModule({ | ||
imports: [SortableModule,...] | ||
}) | ||
export class AppModule(){} | ||
``` |
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,24 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { FormsModule } from '@angular/forms'; | ||
import { CommonModule } from '@angular/common'; | ||
import { SharedModule } from '../../shared'; | ||
|
||
import { SortableSectionComponent } from './sortable-section.component'; | ||
import { DEMO_COMPONENTS } from './demos'; | ||
import { SortableModule } from 'ng2-bootstrap/sortable'; | ||
|
||
@NgModule({ | ||
declarations: [ | ||
SortableSectionComponent, | ||
...DEMO_COMPONENTS | ||
], | ||
imports: [ | ||
CommonModule, | ||
FormsModule, | ||
SharedModule, | ||
SortableModule | ||
], | ||
exports: [SortableSectionComponent] | ||
}) | ||
export class DemoSortableModule { | ||
} |
25 changes: 25 additions & 0 deletions
25
demo/src/app/components/sortable/sortable-section.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,25 @@ | ||
<demo-section [name]="name" [src]="src" [titleDoc]="titleDoc"> | ||
<h2>Contents</h2> | ||
<ul> | ||
<li><a pageScroll href="#usage">Usage</a></li> | ||
<li><a pageScroll href="#examples">Examples</a></li> | ||
<li><a pageScroll href="#api-reference">API Reference</a> | ||
<ul> | ||
<li><a pageScroll href="#sortable-component">SortableComponent</a></li> | ||
</ul> | ||
</li> | ||
</ul> | ||
|
||
<h2 id="usage">Usage</h2> | ||
|
||
<p [innerHtml]="usageDoc"></p> | ||
|
||
<h2 id="examples">Examples</h2> | ||
|
||
<ng-sample-box [ts]="demos.basic.component" [html]="demos.basic.html"> | ||
<sortable-demo></sortable-demo> | ||
</ng-sample-box> | ||
|
||
<h2 id="api-reference">API Reference</h2> | ||
<ng-api-doc id="sortable-component" directive="SortableComponent"></ng-api-doc> | ||
</demo-section> |
19 changes: 19 additions & 0 deletions
19
demo/src/app/components/sortable/sortable-section.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,19 @@ | ||
import { Component } from '@angular/core'; | ||
|
||
import { DEMOS } from './demos'; | ||
|
||
// webpack html imports | ||
let titleDoc = require('html!markdown!./docs/title.md'); | ||
let usageDoc = require('html!markdown!./docs/usage.md'); | ||
|
||
@Component({ | ||
selector: 'sortable-section', | ||
templateUrl: './sortable-section.component.html' | ||
}) | ||
export class SortableSectionComponent { | ||
public name:string = 'Sortable'; | ||
public src:string = 'https://github.com/valor-software/ng2-bootstrap/blob/master/components/sortable'; | ||
public titleDoc:string = titleDoc; | ||
public usageDoc:string = usageDoc; | ||
public demos: any = DEMOS; | ||
} |
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.