Skip to content

Commit

Permalink
Added event and routing support
Browse files Browse the repository at this point in the history
  • Loading branch information
idimaster committed Aug 23, 2016
1 parent be80047 commit 43aac42
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 14 deletions.
16 changes: 13 additions & 3 deletions src/navigation/items/NavDropDownItem.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
import * as React from 'react'

export class NavDropDownItem extends React.Component<{label: string}, any> {
import {OnSelectCallback, Payload} from "./OnSelectCallback";

export class NavDropDownItem extends React.Component<{label: string, onSelect?: OnSelectCallback, payload?: Payload}, any> {
static propTypes() {
return {
label: React.PropTypes.string.isRequired
label: React.PropTypes.string.isRequired,
onSelect: React.PropTypes.func,
payload: React.PropTypes.object
}
}

private handleSelect = () => {
if (this.props.onSelect) {
this.props.onSelect(this.props.payload);
}
};

render(): React.ReactElement<any> {
return <li><a href="#">{this.props.label}</a></li>
return <li><a onClick={this.handleSelect}>{this.props.label}</a></li>
}
}
18 changes: 14 additions & 4 deletions src/navigation/items/NavInfoList.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
import * as React from 'react'

import { NavItem } from "./NavItem";
import {NavItem} from "./NavItem";
import {OnClearCallback} from "./OnClearCallback";

export class NavInfoList extends NavItem<{ label: string }> {
export class NavInfoList extends NavItem<{ id: string, label: string, onClear?: OnClearCallback }> {
static propTypes() {
return {
label: React.PropTypes.string.isRequired
id: React.PropTypes.string.isRequired,
label: React.PropTypes.string.isRequired,
onClear: React.PropTypes.func
}
}

private handleClear = () => {
if (this.props.onClear) {
this.props.onClear(this.props.id);
}
};


render(): React.ReactElement<any> {
const length = React.Children.count(this.props.children);
return <li className="dropdown">
Expand All @@ -22,7 +32,7 @@ export class NavInfoList extends NavItem<{ label: string }> {
{this.props.children}
</ul>
<div className="footer">
<a>Clear Messages</a>
<a onClick={this.handleClear}>Clear Messages</a>
</div>
</div>
</li>
Expand Down
3 changes: 3 additions & 0 deletions src/navigation/items/OnClearCallback.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface OnClearCallback {
(id: string)
}
11 changes: 11 additions & 0 deletions src/navigation/items/OnSelectCallback.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export interface Payload {
payload: any;
}

export interface CommandPayload extends Payload{
command: string;
}

export interface OnSelectCallback {
(event: Payload)
}
7 changes: 4 additions & 3 deletions src/navigation/items/SidebarItem.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import * as React from 'react'

export class SidebarItem extends React.Component<{ label: string, icon: string}, any> {
export class SidebarItem extends React.Component<{ label: string, icon: string, route: string}, any> {
static propTypes() {
return {
label: React.PropTypes.string.isRequired,
icon: React.PropTypes.string.isRequired
icon: React.PropTypes.string.isRequired,
route: React.PropTypes.string.isRequired
}
}

render(): React.ReactElement<any> {
return <li className="list-group-item">
<a>
<a href={this.props.route}>
<span className={'fa ' + this.props.icon} data-toggle="tooltip" title={this.props.label}></span>
<span className="list-group-item-value">{this.props.label}</span>
</a>
Expand Down
7 changes: 4 additions & 3 deletions src/navigation/items/SidebarListItem.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import * as React from 'react'

export class SidebarListItem extends React.Component<{label: string}, any> {
export class SidebarListItem extends React.Component<{label: string, route: string}, any> {
static propTypes() {
return {
label: React.PropTypes.string.isRequired
label: React.PropTypes.string.isRequired,
route: React.PropTypes.string.isRequired
}
}

render(): React.ReactElement<any> {
return <li className="list-group-item">
<a>
<a href={this.props.route}>
<span className="list-group-item-value">{this.props.label}</span>
</a>
</li>
Expand Down
4 changes: 3 additions & 1 deletion src/navigation/items/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ export * from './NavInfoList'
export * from './NavInfoItem'
export * from './SidebarItem'
export * from './SidebarItemList'
export * from './SidebarListItem'
export * from './SidebarListItem'
export * from './OnSelectCallback'
export * from './OnClearCallback'

0 comments on commit 43aac42

Please sign in to comment.