├── .babelrc ├── .gitignore ├── LICENSE ├── README.md ├── client ├── actions │ └── todos.js ├── components │ ├── Footer │ │ ├── index.js │ │ └── style.js │ ├── Header │ │ ├── index.js │ │ └── style.js │ ├── MainSection │ │ ├── index.js │ │ └── style.js │ ├── TodoItem │ │ ├── index.js │ │ └── style.js │ └── TodoTextInput │ │ ├── index.js │ │ └── style.js ├── constants │ └── filters.js ├── containers │ └── App │ │ ├── index.js │ │ └── style.js ├── index.html ├── index.js ├── middleware │ ├── index.js │ └── logger.js ├── prod-index.js ├── reducers │ ├── index.js │ └── todos.js ├── shared │ └── style.js └── store │ └── index.js ├── docs ├── bundle.js ├── index.html └── vendor.bundle.js ├── package.json └── webpack.config.js /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["es2015", "stage-0", "react"], 3 | "plugins": ["transform-decorators-legacy", "transform-runtime"], 4 | "env": { 5 | "STATIC": { 6 | "plugins": [ 7 | [ 8 | "babel-plugin-webpack-loaders", 9 | { 10 | "config": "./webpack.config.js", 11 | "verbose": false 12 | } 13 | ] 14 | ] 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | 11 | # Directory for instrumented libs generated by jscoverage/JSCover 12 | lib-cov 13 | 14 | # Coverage directory used by tools like istanbul 15 | coverage 16 | 17 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 18 | .grunt 19 | 20 | # node-waf configuration 21 | .lock-wscript 22 | 23 | # Compiled binary addons (http://nodejs.org/api/addons.html) 24 | build/Release 25 | 26 | # Dependency directory 27 | node_modules 28 | 29 | # Optional npm cache directory 30 | .npm 31 | 32 | # Optional REPL history 33 | .node_repl_history 34 | 35 | # OS-specific temporary files 36 | Thumbs.db 37 | .DS_Store 38 | 39 | # Ignore build files 40 | static/bundle.js 41 | static/vendor.bundle.js 42 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Matthew DeLambo 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # JSS Todomvc Example 2 | 3 | Most of this code was lifted from [Matt Delambo's Aphrodite Todomvc Example](https://github.com/delambo/react-todomvc-aphrodite) (which in turn is lifted from [TJ's Frontend Boilerplate](https://github.com/tj/frontend-boilerplate)). 4 | 5 | I replaced [Aphrodite](https://github.com/Khan/aphrodite) inline styles with [JSS](https://github.com/jsstyles/jss). 6 | 7 | ## Development 8 | 9 | ``` 10 | npm start 11 | ``` 12 | 13 | ## Production Build and Run 14 | 15 | The following commands will build the app to `docs/` with the styles dehydrated and included inline in the html, and run it: 16 | 17 | ``` 18 | npm run build 19 | static docs 20 | ``` 21 | -------------------------------------------------------------------------------- /client/actions/todos.js: -------------------------------------------------------------------------------- 1 | 2 | import { createAction } from 'redux-actions' 3 | 4 | export const addTodo = createAction('add todo') 5 | export const deleteTodo = createAction('delete todo') 6 | export const editTodo = createAction('edit todo') 7 | export const completeTodo = createAction('complete todo') 8 | export const completeAll = createAction('complete all') 9 | export const clearCompleted = createAction('clear complete') 10 | -------------------------------------------------------------------------------- /client/components/Footer/index.js: -------------------------------------------------------------------------------- 1 | 2 | import React, { Component } from 'react' 3 | import { SHOW_ALL, SHOW_COMPLETED, SHOW_ACTIVE } from '../../constants/filters' 4 | import classnames from 'classnames' 5 | import useSheet from 'react-jss' 6 | import styles from './style' 7 | 8 | const FILTER_TITLES = { 9 | [SHOW_ALL]: 'All', 10 | [SHOW_ACTIVE]: 'Active', 11 | [SHOW_COMPLETED]: 'Completed', 12 | } 13 | 14 | @useSheet(styles) 15 | class Footer extends Component { 16 | renderTodoCount() { 17 | const { activeCount, sheet: {classes} } = this.props 18 | const itemWord = activeCount === 1 ? 'item' : 'items' 19 | 20 | return ( 21 | 22 | {activeCount || 'No'} {itemWord} left 23 | 24 | ) 25 | } 26 | 27 | renderFilterLink(filter) { 28 | const title = FILTER_TITLES[filter] 29 | const { filter: selectedFilter, onShow, sheet: {classes} } = this.props 30 | 31 | return ( 32 | onShow(filter)}> 35 | {title} 36 | 37 | ) 38 | } 39 | 40 | renderClearButton() { 41 | const { completedCount, onClearCompleted, sheet: {classes} } = this.props 42 | if (completedCount > 0) { 43 | return ( 44 | 47 | ) 48 | } 49 | } 50 | 51 | render() { 52 | const {classes} = this.props.sheet; 53 | return ( 54 | 65 | ) 66 | } 67 | } 68 | 69 | export default Footer 70 | -------------------------------------------------------------------------------- /client/components/Footer/style.js: -------------------------------------------------------------------------------- 1 | import shared from './../../shared/style' 2 | 3 | const filterLinkHighlight = { 4 | borderColor: 'rgba(175, 47, 47, 0.1)', 5 | } 6 | 7 | export default { 8 | normal: { 9 | color: '#777', 10 | padding: '10px 15px', 11 | height: '20px', 12 | textAlign: 'center', 13 | borderTop: '1px solid #e6e6e6', 14 | 15 | '&:before': { 16 | content: '""', 17 | position: 'absolute', 18 | right: 0, 19 | bottom: 0, 20 | left: 0, 21 | height: '50px', 22 | overflow: 'hidden', 23 | boxShadow: '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)', 24 | }, 25 | }, 26 | 27 | '@media (max-width: 430px)': { 28 | smallNormal: { 29 | height: '50px', 30 | }, 31 | }, 32 | 33 | filters: { 34 | margin: 0, 35 | padding: 0, 36 | listStyle: 'none', 37 | position: 'absolute', 38 | right: 0, 39 | left: 0, 40 | }, 41 | 42 | '@media (max-width: 430px)': { 43 | smallFilters: { 44 | bottom: '10px', 45 | }, 46 | }, 47 | 48 | filtersItem: { 49 | display: 'inline', 50 | }, 51 | 52 | filterLink: { 53 | color: 'inherit', 54 | margin: '3px', 55 | padding: '3px 7px', 56 | textDecoration: 'none', 57 | border: '1px solid transparent', 58 | borderRadius: '3px', 59 | 60 | '&:hover': filterLinkHighlight 61 | }, 62 | 63 | filterLinkHighlight: filterLinkHighlight, 64 | 65 | count: { 66 | float: 'left', 67 | textAlign: 'left', 68 | }, 69 | 70 | strong: { 71 | fontWeight: 300, 72 | }, 73 | 74 | clearCompleted: { 75 | ...shared.button, 76 | ...shared.formEl, 77 | 78 | float: 'right', 79 | position: 'relative', 80 | lineHeight: '20px', 81 | textDecoration: 'none', 82 | cursor: 'pointer', 83 | visibility: 'hidden', 84 | position: 'relative', 85 | 86 | '&:active': { 87 | float: 'right', 88 | position: 'relative', 89 | lineHeight: '20px', 90 | textDecoration: 'none', 91 | cursor: 'pointer', 92 | visibility: 'hidden', 93 | position: 'relative', 94 | }, 95 | 96 | '&:after': { 97 | visibility: 'visible', 98 | content: '"Clear completed"', 99 | position: 'absolute', 100 | right: 0, 101 | whiteSpace: 'nowrap', 102 | }, 103 | 104 | '&:hover': { 105 | '&:after': { 106 | textDecoration: 'underline', 107 | }, 108 | }, 109 | }, 110 | 111 | } 112 | -------------------------------------------------------------------------------- /client/components/Header/index.js: -------------------------------------------------------------------------------- 1 | 2 | import React, { Component } from 'react' 3 | import TodoTextInput from '../TodoTextInput' 4 | import useSheet from 'react-jss' 5 | import styles from './style' 6 | 7 | @useSheet(styles) 8 | class Header extends Component { 9 | handleSave(text) { 10 | if (text.length) { 11 | this.props.addTodo(text) 12 | } 13 | } 14 | 15 | render() { 16 | const {classes} = this.props.sheet 17 | return ( 18 |
19 |

Todos

20 | 24 |
25 | ) 26 | } 27 | } 28 | 29 | export default Header 30 | -------------------------------------------------------------------------------- /client/components/Header/style.js: -------------------------------------------------------------------------------- 1 | export default { 2 | 3 | h1: { 4 | position: 'absolute', 5 | top: '-155px', 6 | width: '100%', 7 | fontSize: '100px', 8 | fontWeight: '100', 9 | textAlign: 'center', 10 | textRendering: 'optimizeLegibility', 11 | color: 'rgba(175, 47, 47, 0.15)', 12 | }, 13 | 14 | } 15 | -------------------------------------------------------------------------------- /client/components/MainSection/index.js: -------------------------------------------------------------------------------- 1 | 2 | import React, { Component } from 'react' 3 | import TodoItem from '../TodoItem' 4 | import Footer from '../Footer' 5 | import { SHOW_ALL, SHOW_COMPLETED, SHOW_ACTIVE } from '../../constants/filters' 6 | import styles from './style' 7 | import useSheet from 'react-jss' 8 | import classnames from 'classnames' 9 | 10 | const TODO_FILTERS = { 11 | [SHOW_ALL]: () => true, 12 | [SHOW_ACTIVE]: todo => !todo.completed, 13 | [SHOW_COMPLETED]: todo => todo.completed 14 | } 15 | 16 | @useSheet(styles) 17 | class MainSection extends Component { 18 | constructor(props, context) { 19 | super(props, context) 20 | this.state = { filter: SHOW_ALL } 21 | } 22 | 23 | handleClearCompleted() { 24 | const atLeastOneCompleted = this.props.todos.some(todo => todo.completed) 25 | if (atLeastOneCompleted) { 26 | this.props.actions.clearCompleted() 27 | } 28 | } 29 | 30 | handleShow(filter) { 31 | this.setState({ filter }) 32 | } 33 | 34 | renderToggleAll(completedCount) { 35 | const { todos, actions, sheet: {classes} } = this.props 36 | if (todos.length > 0) { 37 | return 42 | } 43 | } 44 | 45 | renderFooter(completedCount) { 46 | const { todos } = this.props 47 | const { filter } = this.state 48 | const activeCount = todos.length - completedCount 49 | 50 | if (todos.length) { 51 | return ( 52 |