// tslint:disable:max-classes-per-file import * as React from 'react'; import { FormControl, FormControlProps, FormGroup, InputGroup, } from 'react-bootstrap'; import { findDOMNode } from 'react-dom'; import { Icon } from 'react-fa'; import { Observable } from 'rxjs'; import { Command } from '../../../WebRx'; import { BindableInput } from '../../Common/BindableInput/BindableInput'; import { CommandButton } from '../../Common/CommandButton/CommandButton'; import { ItemListPanelView } from '../../Common/ItemListPanel/ItemListPanelView'; import { ListGroupView } from '../../Common/ListItems/ListGroupView'; import { BaseView, BaseViewProps } from '../../React'; import { TodoItemViewModel, TodoListViewModel } from './TodoListViewModel'; import './TodoList.less'; export interface TodoListProps { shadow?: boolean; } export interface TodoListViewProps extends BaseViewProps, TodoListProps {} export class TodoListView extends BaseView< TodoListViewProps, TodoListViewModel > { private inputRef = React.createRef(); constructor(props: any) { super(props); this.renderItem = this.renderItem.bind(this); this.focusInput = this.focusInput.bind(this); } componentDidMount() { this.focusInput(); } render() { const { className, props, rest } = this.restProps(x => { const { shadow } = x; return { shadow }; }); return (
); } protected renderItem(item: TodoItemViewModel) { return ; } protected renderEmptyContent() { if (this.viewModel.list.count.value > 0) { return 'No todo items to show.'; } return 'No todo items have been created yet.'; } protected renderTeaser() { return ( x.addItem, undefined, (_, e: React.KeyboardEvent) => e.keyCode === 13, () => this.focusInput(), )} /> {' Add New Todo Item'} ); } protected renderFooter() { return null; } private focusInput() { this.wxr.focusElement(this.inputRef.current); } } export interface TodoItemProps { remove: Command; } export interface TodoItemViewProps extends BaseViewProps, TodoItemProps {} export class TodoItemView extends BaseView< TodoItemViewProps, TodoItemViewModel > { constructor(props: any) { super(props); this.getRemoveCommand = this.getRemoveCommand.bind(this); } updateOn(viewModel: Readonly) { return [viewModel.completed.changed]; } render() { const { className, props, rest } = this.restProps(x => { const { remove } = x; return { remove }; }); return (
x.toggleCompleted)} stopPropagation preventDefault > {`[ ${this.viewModel.id} ] `} {this.viewModel.content}
); } protected getRemoveCommand() { return this.props.remove; } }