Skip to content

Commit 7f77525

Browse files
author
Joe Seifi
committed
sold behavior
1 parent 2e712ca commit 7f77525

File tree

15 files changed

+140
-55
lines changed

15 files changed

+140
-55
lines changed

01-react-css3/solution/App.js

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
import React, { Component } from 'react'
2-
import { AddToCartButton, BuyNowButton, Button } from './Buttons'
3-
import { FoodItem, BuyStrip } from './Order'
4-
import numeral from 'numeral'
2+
import { AddToCartButton, BuyNowButton , FoodItem, BuyStrip } from './components/index'
3+
import ReactCSSTransitionGroup from 'react-addons-css-transition-group'
54

65
import { foodList } from './api'
76
import './app.css'
87

98
export default class App extends Component {
109

1110
state = {
12-
totalPrice: 0
11+
totalPrice: 0,
12+
confirmed: false
13+
}
14+
15+
onBuy () {
16+
this.setState({
17+
confirmed: true
18+
})
1319
}
1420

1521
updateTotal (price, inCart) {
@@ -19,7 +25,7 @@ export default class App extends Component {
1925
}
2026

2127
render () {
22-
const { totalPrice } = this.state
28+
const { totalPrice, confirmed } = this.state
2329

2430
return (
2531
<div>
@@ -31,6 +37,11 @@ export default class App extends Component {
3137
<figure className="food_photo">
3238
<img className="food_photo_image" src="../../workshop/img/taco.jpg" />
3339
</figure>
40+
<ReactCSSTransitionGroup
41+
transitionName="closefoods"
42+
transitionEnterTimeout={ 500 }
43+
transitionLeaveTimeout={ 600 }>
44+
{ !confirmed &&
3445
<div className="food_menu">
3546
<ul className="food_items">
3647
{
@@ -41,13 +52,19 @@ export default class App extends Component {
4152
price={ price }
4253
photoPath={ photoPath }
4354
updateTotal= { this.updateTotal.bind(this) }
55+
disabled={ confirmed }
4456
/>
4557
})
4658
}
4759
</ul>
4860
</div>
61+
}
62+
</ReactCSSTransitionGroup>
4963
</main>
50-
<BuyStrip totalPrice={ numeral(totalPrice).format('$0.00') } />
64+
<BuyStrip
65+
totalPrice={ totalPrice }
66+
onBuy={ this.onBuy.bind(this) }
67+
/>
5168
</section>
5269
<footer className="footer">
5370
123 Narrow Road, San Francisco, CA

01-react-css3/solution/Buttons/index.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

01-react-css3/solution/Order/BuyStrip.js

Lines changed: 0 additions & 31 deletions
This file was deleted.

01-react-css3/solution/Order/index.js

Lines changed: 0 additions & 2 deletions
This file was deleted.

01-react-css3/solution/Buttons/AddToCartButton.js renamed to 01-react-css3/solution/components/AddToCartButton.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export class AddToCartButton extends Component {
1010
buttonText: 'Add'
1111
}
1212

13-
onButtonClicked = (e) => {
13+
onButtonClicked = () => {
1414
this.props.onClick(!this.state.depressed)
1515
this.setState({
1616
buttonText: this.state.depressed ? 'Add' : 'Remove',
@@ -20,13 +20,14 @@ export class AddToCartButton extends Component {
2020

2121
render () {
2222
const { buttonText, depressed } = this.state
23-
const { classNames, onClick, ...otherProps } = this.props
23+
const { classNames, onClick, disabled, ...otherProps } = this.props
2424
const buttonClassNames = classnames('icon icon-add', classNames)
2525

2626
return (
2727
<Button
2828
classNames={ buttonClassNames }
2929
depressed={ depressed }
30+
disabled={ disabled }
3031
onClick={ this.onButtonClicked }
3132
{ ...otherProps }
3233
>

01-react-css3/solution/Buttons/BuyNowButton.js renamed to 01-react-css3/solution/components/BuyNowButton.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export class BuyNowButton extends Component {
88
buttonText: 'Buy Now'
99
}
1010

11-
onButtonClicked = (e) => {
11+
onButtonClicked = () => {
1212
this.props.onClick()
1313
this.setState({
1414
buttonText: 'Confirmed',
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import React, { Component } from 'react'
2+
import { BuyNowButton } from './index'
3+
import numeral from 'numeral'
4+
5+
export class BuyStrip extends Component {
6+
7+
state = {
8+
confirmed: false
9+
}
10+
11+
buyNowClicked () {
12+
this.props.onBuy()
13+
this.setState({ confirmed: true })
14+
}
15+
16+
render () {
17+
const { totalPrice } = this.props
18+
const formattedPrice = numeral(totalPrice).format('$0.00')
19+
const { confirmed } = this.state
20+
21+
return confirmed ?
22+
(
23+
<aside className="buy sold">
24+
<div className="buy_title"><p>Get Ready to eat!</p> Your order is confirmed. Your card was charged <span className="buy_total">{ formattedPrice }</span></div>
25+
</aside>
26+
) : (
27+
<aside className="buy">
28+
<div className="buy_title">Total:<span className="buy_total">{ formattedPrice }</span></div>
29+
<BuyNowButton
30+
onClick={ this.buyNowClicked.bind(this) }
31+
classNames="buy_button"
32+
disabled={ totalPrice === 0 }>
33+
Buy Now
34+
</BuyNowButton>
35+
</aside>
36+
)
37+
}
38+
39+
}

01-react-css3/solution/Order/FoodItem.js renamed to 01-react-css3/solution/components/FoodItem.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { Component } from 'react'
2-
import { AddToCartButton } from '../Buttons'
2+
import { AddToCartButton } from './index'
33
import numeral from 'numeral'
44

55
export class FoodItem extends Component {
@@ -13,14 +13,18 @@ export class FoodItem extends Component {
1313
}
1414

1515
render () {
16-
const { id, name, price, photoPath } = this.props
16+
const { id, name, price, photoPath, disabled } = this.props
1717
const { inCart } = this.state
1818

1919
return (
2020
<li className="food_item">
2121
<figure className="food_item_image"><img className="food_item_photo" src={ photoPath } /></figure>
2222
<div className="food_item_name">{ name }<span className="food_item_price">{ numeral(price).format('$0.00') }</span></div>
23-
<AddToCartButton onClick={ this.addToCart.bind(this) } classNames="food_add_button" />
23+
<AddToCartButton
24+
onClick={ this.addToCart.bind(this) }
25+
classNames="food_add_button"
26+
disabled={ disabled }
27+
/>
2428
</li>
2529
)
2630
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export { Button } from './Button'
2+
export { AddToCartButton } from './AddToCartButton'
3+
export { BuyNowButton } from './BuyNowButton'
4+
5+
export { FoodItem } from './FoodItem'
6+
export { BuyStrip } from './BuyStrip'

jsconfig.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,5 @@
44
"module": "system",
55
"experimentalDecorators": true
66
},
7-
"exclude": [
8-
"node_modules",
9-
"**/node_modules"
10-
]
7+
"exclude": [ "node_modules" ]
118
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"postcss-loader": "^1.3.0",
3939
"radium": "^0.18.1",
4040
"react": "^15.4.2",
41+
"react-addons-css-transition-group": "^15.4.2",
4142
"react-css-modules": "^4.1.0",
4243
"react-dom": "^15.4.2",
4344
"react-hot-loader": "^3.0.0-beta.6",

public/workshop/css/main.css

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ body, a {
146146

147147
@media screen and (min-width: 608px) {
148148
.food_item_photo {
149-
width: 100%;
149+
height: 100%;
150150
}
151151
}
152152

@@ -194,6 +194,7 @@ body, a {
194194
box-sizing: border-box;
195195
background-color: #EA491C;
196196
color: #fff;
197+
transition: height 300ms ease 60ms;
197198
}
198199

199200
@media screen and (min-width: 608px) {
@@ -202,10 +203,16 @@ body, a {
202203
position: inherit;
203204
bottom: inherit;
204205
justify-content: center;
206+
transition: height 300ms ease 260ms;
205207
}
206208
}
207209

210+
.sold.buy {
211+
height: 200px;
212+
}
213+
208214
.buy_title {
215+
display: flex;
209216
flex-grow: 1;
210217
font-weight: bold;
211218
}
@@ -215,12 +222,31 @@ body, a {
215222
}
216223
}
217224

225+
.sold .buy_title {
226+
font-weight: normal;
227+
display: block;
228+
line-height: 1.2;
229+
text-align: center;
230+
}
231+
232+
@media screen and (min-width: 608px) {
233+
.sold .buy_title {
234+
line-height: 2;
235+
}
236+
}
237+
218238
.buy_total {
219239
padding-left: 10px;
220-
padding-right: 30px;
240+
padding-right: 10px;
241+
min-width: 80px;
221242
font-weight: normal;
222243
}
223244

245+
.sold .buy_total {
246+
padding-left: 0;
247+
min-width: auto;
248+
}
249+
224250
.buy_button {
225251
background-color: #fff;
226252
color: #000;
@@ -242,4 +268,27 @@ body, a {
242268
text-align: center;
243269
padding: 20px;
244270
font-size: 12px;
271+
}
272+
273+
/* animate close food list */
274+
.closefoods-enter {
275+
opacity: 0.01;
276+
max-height: 0;
277+
}
278+
279+
.closefoods-enter-active {
280+
opacity: 1;
281+
max-height: 1000;
282+
transition: all 500ms ease-in;
283+
}
284+
285+
.closefoods-leave {
286+
max-height: 1000px;
287+
opacity: 1;
288+
}
289+
290+
.closefoods-leave-active {
291+
opacity: 0.01;
292+
max-height: 0;
293+
transition: all 600ms ease;
245294
}

templates/app.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
<meta name="viewport" content="width=device-width, initial-scale=1">
66
</head>
77
<body>
8-
<div id="app"></div>
8+
<div id="app" class="app"></div>
99
</body>
1010
</html>

yarn.lock

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4932,6 +4932,13 @@ rc@^1.1.2, rc@~1.1.6:
49324932
minimist "^1.2.0"
49334933
strip-json-comments "~2.0.1"
49344934

4935+
react-addons-css-transition-group@^15.4.2:
4936+
version "15.4.2"
4937+
resolved "https://registry.yarnpkg.com/react-addons-css-transition-group/-/react-addons-css-transition-group-15.4.2.tgz#b7828834dfa14229fe07750e331e8a8cb6fb7745"
4938+
dependencies:
4939+
fbjs "^0.8.4"
4940+
object-assign "^4.1.0"
4941+
49354942
react-css-modules@^4.1.0:
49364943
version "4.1.0"
49374944
resolved "https://registry.yarnpkg.com/react-css-modules/-/react-css-modules-4.1.0.tgz#848e3d5089ec6596feabf6c0daaacc06866c58e7"

0 commit comments

Comments
 (0)