-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #420 from patryk0605/go-tree
[Feature] Go-Tree
- Loading branch information
Showing
13 changed files
with
260 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { | ||
animate, | ||
AnimationTriggerMetadata, | ||
state, | ||
style, | ||
transition, | ||
trigger, | ||
} from '@angular/animations'; | ||
|
||
import { easing, timing } from './_configs'; | ||
|
||
export const treeAnimation: AnimationTriggerMetadata = trigger('treeAnimation', [ | ||
state('open', style({ | ||
height: '*', | ||
overflow: 'visible', | ||
visibility: 'visible' | ||
})), | ||
state('close', style({ | ||
height: 0, | ||
overflow: 'hidden', | ||
visibility: 'hidden' | ||
})), | ||
transition('open <=> close', [ | ||
animate(timing + easing) | ||
]) | ||
]); |
5 changes: 5 additions & 0 deletions
5
projects/go-lib/src/lib/components/go-tree/go-tree-node-config.model.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,5 @@ | ||
export interface GoTreeNodeConfig { | ||
name: string; | ||
children?: GoTreeNodeConfig[]; | ||
expanded?: boolean; | ||
} |
23 changes: 23 additions & 0 deletions
23
projects/go-lib/src/lib/components/go-tree/go-tree.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,23 @@ | ||
<ng-template | ||
#nodeTemplate | ||
let-node="node" | ||
let-isChildNode="isChildNode"> | ||
<div [ngClass]="{ 'go-tree-node-item__child-offset': isChildNode }"> | ||
<go-icon | ||
class="go-tree-node-item__expander" | ||
[icon]="node.expanded ? 'expand_more' : 'expand_less'" | ||
(click)="node.expanded = !node.expanded" | ||
*ngIf="node?.children"> | ||
</go-icon> | ||
{{ node.name }} | ||
<div [@treeAnimation]="node.expanded ? 'open' : 'close'"> | ||
<ng-container *ngFor="let node of node?.children"> | ||
<ng-container *ngTemplateOutlet="nodeTemplate; context:{ node: node, isChildNode: true }"></ng-container> | ||
</ng-container> | ||
</div> | ||
</div> | ||
</ng-template> | ||
|
||
<ng-container *ngFor="let node of nodeConfig"> | ||
<ng-container *ngTemplateOutlet="nodeTemplate; context:{ node: node }"></ng-container> | ||
</ng-container> |
7 changes: 7 additions & 0 deletions
7
projects/go-lib/src/lib/components/go-tree/go-tree.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,7 @@ | ||
.go-tree-node-item__child-offset { | ||
margin-left: 2.5rem; | ||
} | ||
|
||
.go-tree-node-item__expander { | ||
cursor: pointer; | ||
} |
29 changes: 29 additions & 0 deletions
29
projects/go-lib/src/lib/components/go-tree/go-tree.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,29 @@ | ||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { GoIconModule } from '../go-icon/go-icon.module'; | ||
import { GoTreeComponent } from './go-tree.component'; | ||
|
||
describe('GoTreeComponent', () => { | ||
let component: GoTreeComponent; | ||
let fixture: ComponentFixture<GoTreeComponent>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ GoTreeComponent ], | ||
imports: [ | ||
GoIconModule | ||
] | ||
}) | ||
.compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(GoTreeComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
14 changes: 14 additions & 0 deletions
14
projects/go-lib/src/lib/components/go-tree/go-tree.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,14 @@ | ||
import { Component, Input } from '@angular/core'; | ||
|
||
import { GoTreeNodeConfig } from './go-tree-node-config.model'; | ||
import { treeAnimation } from '../../animations/tree.animation'; | ||
|
||
@Component({ | ||
animations: [ treeAnimation ], | ||
selector: 'go-tree', | ||
templateUrl: './go-tree.component.html', | ||
styleUrls: ['./go-tree.component.scss'] | ||
}) | ||
export class GoTreeComponent { | ||
@Input() nodeConfig: GoTreeNodeConfig[]; | ||
} |
19 changes: 19 additions & 0 deletions
19
projects/go-lib/src/lib/components/go-tree/go-tree.module.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 { CommonModule } from '@angular/common'; | ||
import { NgModule } from '@angular/core'; | ||
|
||
import { GoIconModule } from '../go-icon/go-icon.module'; | ||
import { GoTreeComponent } from './go-tree.component'; | ||
|
||
@NgModule({ | ||
declarations: [ | ||
GoTreeComponent | ||
], | ||
imports: [ | ||
CommonModule, | ||
GoIconModule | ||
], | ||
exports: [ | ||
GoTreeComponent | ||
] | ||
}) | ||
export class GoTreeModule { } |
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
54 changes: 54 additions & 0 deletions
54
...ects/go-style-guide/src/app/features/ui-kit/components/tree-docs/tree-docs.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,54 @@ | ||
<header class="go-page-title"> | ||
<h1 class="go-heading-1">Tree</h1> | ||
</header> | ||
|
||
<section class="go-container"> | ||
<go-card [showHeader]="false" class="go-column go-column--100"> | ||
<div class="go-container" go-card-content> | ||
|
||
<div class="go-column go-column--100"> | ||
<h2 class="go-heading-2">Usage</h2> | ||
<p class="go-body-copy"> | ||
The <code class="code-block--inline"><go-tree></code> component should be used for any instance | ||
of "tree" like data, such as folder structures or groupings. | ||
</p> | ||
</div> | ||
|
||
<div class="go-column go-column--100"> | ||
<h3 class="go-heading-3">Bindings</h3> | ||
<code [highlight]="componentBindings"></code> | ||
</div> | ||
|
||
<div class="go-column go-column--100"> | ||
<h4 class="go-heading-4">nodeConfig</h4> | ||
<p class="go-body-copy"> | ||
The layout of the tree. This binding is required. The interface <code class="code-block--inline">GoTreeNodeConfig</code> | ||
supports the following options: | ||
</p> | ||
<p class="go-body-copy go-body-copy--no-margin"> | ||
<code [highlight]="goTreeNodeConfig"></code> | ||
</p> | ||
</div> | ||
</div> | ||
</go-card> | ||
|
||
|
||
<go-card class="go-column go-column--100"> | ||
<header go-card-header> | ||
<h2 class="go-heading-2">Default</h2> | ||
</header> | ||
<div go-card-content> | ||
<div class="go-container"> | ||
<div class="go-column go-column--50"> | ||
<h4 class="go-heading-4 go-heading--underlined">View</h4> | ||
<go-tree [nodeConfig]="exampleDefaultTreeData"></go-tree> | ||
</div> | ||
<div class="go-column go-column--50"> | ||
<h4 class="go-heading-4 go-heading--underlined">Code</h4> | ||
<code [highlight]="exampleDefaultTreeDataHtml"></code> | ||
</div> | ||
</div> | ||
</div> | ||
</go-card> | ||
|
||
</section> |
67 changes: 67 additions & 0 deletions
67
projects/go-style-guide/src/app/features/ui-kit/components/tree-docs/tree-docs.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,67 @@ | ||
import { Component } from '@angular/core'; | ||
|
||
import { GoTreeNodeConfig } from 'projects/go-lib/src/public_api'; | ||
|
||
@Component({ | ||
templateUrl: './tree-docs.component.html' | ||
}) | ||
export class TreeDocsComponent { | ||
|
||
readonly componentBindings: string = ` | ||
@Input() nodeConfig: GoTreeNodeConfig[]; | ||
`; | ||
|
||
readonly goTreeNodeConfig: string = ` | ||
interface GoTreeNodeConfig { | ||
name: string; | ||
children?: GoTreeNodeConfig[]; | ||
expanded?: boolean; | ||
} | ||
`; | ||
|
||
exampleDefaultTreeDataHtml: string = ` | ||
exampleTreeData: GoTreeNodeConfig[] = [ | ||
{ | ||
name: 'Fruit', | ||
children: [{ name: 'Apple' }, { name: 'Banana' }], | ||
expanded: true | ||
}, | ||
{ | ||
name: 'Vegetables', | ||
children: [ | ||
{ | ||
name: 'Green', | ||
children: [{ name: 'Broccoli' }, { name: 'Brussel sprouts' }] | ||
}, | ||
{ | ||
name: 'Orange', | ||
children: [{ name: 'Pumpkins' }, { name: 'Carrots' }] | ||
} | ||
] | ||
} | ||
]; | ||
<go-tree [nodeConfig]="exampleDefaultTreeData"></go-tree> | ||
`; | ||
|
||
exampleDefaultTreeData: GoTreeNodeConfig[] = [ | ||
{ | ||
name: 'Fruit', | ||
children: [{ name: 'Apple' }, { name: 'Banana' }], | ||
expanded: true | ||
}, | ||
{ | ||
name: 'Vegetables', | ||
children: [ | ||
{ | ||
name: 'Green', | ||
children: [{ name: 'Broccoli' }, { name: 'Brussel sprouts' }] | ||
}, | ||
{ | ||
name: 'Orange', | ||
children: [{ name: 'Pumpkins' }, { name: 'Carrots' }] | ||
} | ||
] | ||
} | ||
]; | ||
} |
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