-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(demos): add todomvc demo (#190)
- Loading branch information
Showing
27 changed files
with
2,312 additions
and
151 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
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 |
---|---|---|
@@ -1,12 +1,14 @@ | ||
import {FeatureAppDefinition} from '@feature-hub/core'; | ||
import {DomFeatureApp} from '@feature-hub/dom'; | ||
|
||
export default { | ||
const featureAppDefinition: FeatureAppDefinition<DomFeatureApp> = { | ||
id: 'test:hello-world', | ||
|
||
create: () => ({ | ||
attachTo(element: HTMLElement): void { | ||
element.innerHTML = 'Hello, World!'; | ||
} | ||
}) | ||
} as FeatureAppDefinition<DomFeatureApp>; | ||
}; | ||
|
||
export default featureAppDefinition; |
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,34 @@ | ||
import {FeatureAppDefinition} from '@feature-hub/core'; | ||
import {ReactFeatureApp} from '@feature-hub/react'; | ||
import * as React from 'react'; | ||
import {TodoManagerV1} from '../todo-manager'; | ||
import {TodoMvcFooter} from './todomvc-footer'; | ||
|
||
export interface FooterFeatureServices { | ||
readonly 'test:todomvc-todo-manager': TodoManagerV1; | ||
} | ||
|
||
const featureAppDefinition: FeatureAppDefinition< | ||
ReactFeatureApp, | ||
undefined, | ||
undefined, | ||
FooterFeatureServices | ||
> = { | ||
id: 'test:todomvc-footer', | ||
|
||
dependencies: { | ||
featureServices: { | ||
'test:todomvc-todo-manager': '^1.0.0' | ||
} | ||
}, | ||
|
||
create: ({featureServices}) => { | ||
const todoManager = featureServices['test:todomvc-todo-manager']; | ||
|
||
return { | ||
render: () => <TodoMvcFooter todoManager={todoManager} /> | ||
}; | ||
} | ||
}; | ||
|
||
export default featureAppDefinition; |
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,42 @@ | ||
.footer { | ||
color: #777; | ||
padding: 10px 15px; | ||
height: 20px; | ||
text-align: center; | ||
border-top: 1px solid #e6e6e6; | ||
|
||
&:before { | ||
content: ''; | ||
position: absolute; | ||
right: 0; | ||
bottom: 0; | ||
left: 0; | ||
height: 50px; | ||
overflow: hidden; | ||
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.2), 0 8px 0 -3px #f6f6f6, | ||
0 9px 1px -3px rgba(0, 0, 0, 0.2), 0 16px 0 -6px #f6f6f6, | ||
0 17px 2px -6px rgba(0, 0, 0, 0.2); | ||
} | ||
} | ||
|
||
.todoCount { | ||
float: left; | ||
text-align: left; | ||
|
||
& strong { | ||
font-weight: 300; | ||
} | ||
} | ||
|
||
.clearCompleted, | ||
html .clearCompleted:active { | ||
float: right; | ||
position: relative; | ||
line-height: 20px; | ||
text-decoration: none; | ||
cursor: pointer; | ||
} | ||
|
||
.clearCompleted:hover { | ||
text-decoration: underline; | ||
} |
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,59 @@ | ||
import * as React from 'react'; | ||
import {Todo, TodoManagerV1} from '../todo-manager'; | ||
import styles from './styles.css'; | ||
|
||
export interface TodoMvcFooterProps { | ||
readonly todoManager: TodoManagerV1; | ||
} | ||
|
||
export interface TodoMvcFooterState { | ||
readonly todos: Todo[]; | ||
} | ||
|
||
export class TodoMvcFooter extends React.Component< | ||
TodoMvcFooterProps, | ||
TodoMvcFooterState | ||
> { | ||
public readonly state = {todos: this.props.todoManager.getTodos()}; | ||
|
||
public componentDidMount(): void { | ||
this.props.todoManager.subscribe(() => { | ||
this.setState({todos: this.props.todoManager.getTodos()}); | ||
}); | ||
} | ||
|
||
public render(): JSX.Element | null { | ||
const {todos} = this.state; | ||
|
||
if (todos.length === 0) { | ||
return null; | ||
} | ||
|
||
const itemsLeft = todos.filter(todo => !todo.completed).length; | ||
const hasCompletedTodos = todos.length - itemsLeft > 0; | ||
|
||
return ( | ||
<footer className={styles.footer}> | ||
<span className={styles.todoCount}> | ||
<strong>{itemsLeft}</strong> {itemsLeft === 1 ? 'item' : 'items'} left | ||
</span> | ||
{hasCompletedTodos && ( | ||
<button | ||
className={styles.clearCompleted} | ||
onClick={this.handleClearCompletedClick} | ||
> | ||
Clear completed | ||
</button> | ||
)} | ||
</footer> | ||
); | ||
} | ||
|
||
private readonly handleClearCompletedClick = () => { | ||
for (const todo of this.state.todos) { | ||
if (todo && todo.completed) { | ||
this.props.todoManager.remove(todo.id); | ||
} | ||
} | ||
}; | ||
} |
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,17 @@ | ||
.new-todo { | ||
position: relative; | ||
margin: 0; | ||
width: 100%; | ||
font-size: 24px; | ||
font-family: inherit; | ||
font-weight: inherit; | ||
line-height: 1.4em; | ||
border: none; | ||
color: inherit; | ||
padding: 16px 16px 16px 60px; | ||
box-shadow: inset 0 -2px 1px rgba(0, 0, 0, 0.03); | ||
box-sizing: border-box; | ||
background: rgba(0, 0, 0, 0.003); | ||
-webkit-font-smoothing: antialiased; | ||
-moz-osx-font-smoothing: grayscale; | ||
} |
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,31 @@ | ||
import {FeatureAppDefinition} from '@feature-hub/core'; | ||
import {DomFeatureApp} from '@feature-hub/react'; | ||
import {TodoManagerV1} from '../todo-manager'; | ||
import {TodoMvcHeader} from './todomvc-header'; | ||
|
||
export interface HeaderFeatureServices { | ||
readonly 'test:todomvc-todo-manager': TodoManagerV1; | ||
} | ||
|
||
const featureAppDefinition: FeatureAppDefinition< | ||
DomFeatureApp, | ||
undefined, | ||
undefined, | ||
HeaderFeatureServices | ||
> = { | ||
id: 'test:todomvc-header', | ||
|
||
dependencies: { | ||
featureServices: { | ||
'test:todomvc-todo-manager': '^1.0.0' | ||
} | ||
}, | ||
|
||
create: ({featureServices}) => { | ||
const todoManager = featureServices['test:todomvc-todo-manager']; | ||
|
||
return new TodoMvcHeader(todoManager); | ||
} | ||
}; | ||
|
||
export default featureAppDefinition; |
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,36 @@ | ||
import {DomFeatureApp} from '@feature-hub/react'; | ||
import {html, render} from 'lit-html'; | ||
import {TodoManagerV1} from '../todo-manager'; | ||
|
||
export class TodoMvcHeader implements DomFeatureApp { | ||
public readonly kind = 'react-container'; | ||
|
||
public constructor(private readonly todoManager: TodoManagerV1) {} | ||
|
||
public attachTo(container: Element): void { | ||
const header = html` | ||
<header class="header"> | ||
<h1>todos</h1> | ||
<input | ||
class="new-todo" | ||
placeholder="What needs to be done?" | ||
@keypress="${this.handleKeypress}" | ||
autofocus | ||
/> | ||
</header> | ||
`; | ||
|
||
render(header, container); | ||
} | ||
|
||
private readonly handleKeypress = (event: KeyboardEvent): void => { | ||
if (event.key === 'Enter') { | ||
const input = event.target as HTMLInputElement; | ||
const title = input.value.trim(); | ||
|
||
this.todoManager.add(title); | ||
|
||
input.value = ''; | ||
} | ||
}; | ||
} |
Oops, something went wrong.