-
-
Save Killavus/4ff03774c2226c4b3a5f to your computer and use it in GitHub Desktop.
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
{DOM} = React | |
books = [ new Book(1, "Book #1", "Author #1"), | |
new Book(2, "Book #2", "Author #2") ] | |
BookListHeader = React.createClass | |
getInitialState: -> | |
expanded: true | |
toggleExpandedState: -> | |
@setState expanded: !@state.expanded | |
renderExpandAction: -> | |
DOM.div | |
key: 'bookListExpandBox' | |
className: 'pull-right' | |
DOM.a | |
key: 'bookListExpandAction' | |
onClick: @toggleExpandedState | |
@expandActionText() | |
expandActionText: -> | |
if @state.expanded | |
"Click to hide" | |
else | |
"Click to expand" | |
render: -> | |
DOM.div | |
className: 'book-list-box' | |
DOM.h2 | |
key: 'bookListHeader' | |
@renderExpandAction() | |
"Listing #{@props.companyName} Books (#{@props.children.length} titles in stock)" | |
DOM.ul | |
className: 'list-group' | |
@props.children if @state.expanded | |
bookListComponent = | |
BookListHeader | |
companyName: "Arkency" | |
books.map (book) => | |
BookItem | |
book: book | |
BookItem = React.createClass | |
renderAuthor: -> | |
DOM.div | |
key: "bookItem_#{@props.book.id}_Author" | |
className: 'pull-right' | |
@props.book.author | |
renderBookTitle: -> | |
DOM.strong | |
key: "bookItem_#{@props.book.id}_Title" | |
@props.book.title | |
render: -> | |
DOM.li | |
key: "bookItem_#{@props.book.id}" | |
className: 'list-group-item' | |
@renderAuthor() | |
@renderBookTitle() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment