Skip to content

Commit 117413c

Browse files
chore(demo): add demo
1 parent a1009d6 commit 117413c

File tree

13 files changed

+185
-11
lines changed

13 files changed

+185
-11
lines changed

packages/demos/todomvc/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
2-
"name": "todomvc",
2+
"name": "todomvc",
3+
"private": true,
34
"version": "1.0.0-alpha1",
45
"description": "Overmind todomvc demo",
56
"author": "Christian Alfoni <[email protected]>",
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
import * as React from 'react'
22
import { Action } from './'
3+
import { Todo } from './state'
4+
import * as helpers from './helpers'
5+
import * as mutations from './mutations'
36

47
export default (action: Action) => ({
58
changeNewTodoTitle: action<React.ChangeEvent<HTMLInputElement>>()
6-
.map((event) => event.currentTarget.value)
7-
.mutation((value, state) => (state.newTodoTitle = value)),
9+
.map(helpers.getEventValue)
10+
.mutation(mutations.setNewTodoTitle),
11+
addTodo: action<React.FormEvent>()
12+
.do(helpers.preventEventDefault)
13+
.mutation(mutations.addTodo)
14+
.mutation(mutations.clearNewTodoTitle),
15+
toggleCompleted: action<Todo>().mutation(mutations.toggleCompleted),
816
})
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export const getEventValue = (event: React.ChangeEvent<HTMLInputElement>) =>
2+
event.currentTarget.value
3+
4+
export const preventEventDefault = (event: React.FormEvent) =>
5+
event.preventDefault()
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { State, Todo } from './state'
2+
3+
export const setNewTodoTitle = (value: string, state: State) =>
4+
(state.newTodoTitle = value)
5+
6+
export const addTodo = (_, state: State) =>
7+
state.todos.unshift({
8+
title: state.newTodoTitle,
9+
completed: false,
10+
})
11+
12+
export const clearNewTodoTitle = (_, state: State) => (state.newTodoTitle = '')
13+
14+
export const toggleCompleted = (todo: Todo) =>
15+
(todo.completed = !todo.completed)
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import styled from '../../styled-components'
2+
3+
export const Wrapper = styled.div`
4+
width: 100%;
5+
background-color: ${({ theme }) =>
6+
theme.color.lighten(theme.color.dark, 0.2)};
7+
padding: ${({ theme }) => theme.padding.small};
8+
border-radius: ${({ theme }) => theme.borderRadius.large};
9+
`
10+
11+
export const Form = styled.form`
12+
display: flex;
13+
`
14+
15+
export const Input = styled.input`
16+
flex: 1;
17+
display: block;
18+
border: 0;
19+
margin: 0;
20+
outline: none;
21+
background-color: transparent;
22+
font-size: ${({ theme }) => theme.fontSize.larger};
23+
color: ${({ theme }) => theme.color.white};
24+
height: 40px;
25+
::placeholder {
26+
color: ${({ theme }) => theme.color.fade(theme.color.white, 0.5)};
27+
}
28+
`
29+
30+
export const Button = styled.button`
31+
flex: 0 0 50px;
32+
outline: none;
33+
border-radius: ${({ theme }) => theme.borderRadius.normal};
34+
background-color: ${({ theme }) => theme.color.primary};
35+
padding: ${({ theme }) => theme.padding.smaller};
36+
text-transform: uppercase;
37+
border: 0;
38+
color: ${({ theme }) => theme.color.white};
39+
font-weight: bold;
40+
cursor: pointer;
41+
:hover:enabled {
42+
background-color: ${({ theme }) =>
43+
theme.color.lighten(theme.color.primary, 0.1)};
44+
}
45+
:disabled {
46+
cursor: default;
47+
opacity: 0.5;
48+
}
49+
`
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import * as React from 'react'
2+
import { connect, Connect } from '../../app'
3+
import { Wrapper, Input, Button, Form } from './elements'
4+
5+
const AddTodo: React.SFC<Connect> = ({ appState, actions }) => (
6+
<Wrapper>
7+
<Form onSubmit={actions.addTodo}>
8+
<Input
9+
placeholder="I need to..."
10+
value={appState.newTodoTitle}
11+
onChange={actions.changeNewTodoTitle}
12+
/>
13+
<Button disabled={!appState.newTodoTitle}>add</Button>
14+
</Form>
15+
</Wrapper>
16+
)
17+
18+
export default connect(AddTodo)

packages/demos/todomvc/src/components/App/elements.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,13 @@ export const Wrapper = styled.div`
44
display: flex;
55
justify-content: center;
66
align-items: center;
7+
height: 100%;
8+
`
9+
10+
export const InnerWrapper = styled.div`
11+
display: flex;
12+
justify-content: center;
13+
align-items: center;
14+
flex-direction: column;
15+
width: 50%;
716
`
Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import * as React from 'react'
22
import { connect, Connect } from '../../app'
3-
import actions from '../../app/actions'
3+
import { Wrapper, InnerWrapper } from './elements'
4+
import AddTodo from '../AddTodo'
5+
import Todos from '../Todos'
46

57
const App: React.SFC<Connect> = ({ appState, actions }) => (
6-
<div>
7-
<h1>hello ({appState.todos.length})</h1>
8-
<input
9-
value={appState.newTodoTitle}
10-
onChange={actions.changeNewTodoTitle}
11-
/>
12-
</div>
8+
<Wrapper>
9+
<InnerWrapper>
10+
<AddTodo />
11+
<Todos />
12+
</InnerWrapper>
13+
</Wrapper>
1314
)
1415

1516
export default connect(App)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import styled from '../../styled-components'
2+
3+
export const Item = styled.li`
4+
display: flex;
5+
cursor: pointer;
6+
align-items: center;
7+
padding: ${({ theme }) => theme.padding.normal};
8+
font-size: ${({ theme }) => theme.fontSize.larger};
9+
`
10+
11+
export const Completed = styled<
12+
{
13+
completed: boolean
14+
},
15+
'button'
16+
>('button')`
17+
outline: none;
18+
border: 0;
19+
background: transparent;
20+
margin-right: ${({ theme }) => theme.padding.normal};
21+
font-size: ${({ theme }) => theme.fontSize.larger};
22+
color: ${({ theme, completed }) =>
23+
completed
24+
? theme.color.secondary
25+
: theme.color.fade(theme.color.secondary, 0.8)};
26+
`
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import * as React from 'react'
2+
import { connect, Connect } from '../../app'
3+
import { Todo } from '../../app/state'
4+
import { Item, Completed } from './elements'
5+
6+
type Props = {
7+
todo: Todo
8+
} & Connect
9+
10+
const Todo: React.SFC<Props> = ({ todo, actions }) => (
11+
<Item onClick={() => actions.toggleCompleted(todo)}>
12+
<Completed completed={todo.completed}></Completed> {todo.title}
13+
</Item>
14+
)
15+
16+
export default connect(Todo)

0 commit comments

Comments
 (0)