Skip to content

Commit 25569d0

Browse files
author
Joe Seifi
committed
split up component css files
1 parent 7f77525 commit 25569d0

File tree

18 files changed

+385
-343
lines changed

18 files changed

+385
-343
lines changed

01-react-css3/solution/App.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React, { Component } from 'react'
2-
import { AddToCartButton, BuyNowButton , FoodItem, BuyStrip } from './components/index'
2+
import { FoodItem, BuyStrip } from './components/index'
33
import ReactCSSTransitionGroup from 'react-addons-css-transition-group'
44

5-
import { foodList } from './api'
5+
import { foodListData } from './api'
66
import './app.css'
77

88
export default class App extends Component {
@@ -34,8 +34,8 @@ export default class App extends Component {
3434
</header>
3535
<section className="order">
3636
<main className="food">
37-
<figure className="food_photo">
38-
<img className="food_photo_image" src="../../workshop/img/taco.jpg" />
37+
<figure className="food_header">
38+
<img className="food_header_image" src="../../workshop/img/taco.jpg" />
3939
</figure>
4040
<ReactCSSTransitionGroup
4141
transitionName="closefoods"
@@ -45,7 +45,7 @@ export default class App extends Component {
4545
<div className="food_menu">
4646
<ul className="food_items">
4747
{
48-
foodList.map( ({ id, name, price, photoPath }) => {
48+
foodListData.map( ({ id, name, price, photoPath }) => {
4949
return <FoodItem
5050
key={ id }
5151
name={ name }

01-react-css3/solution/api.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const foodList = [
1+
const foodListData = [
22
{
33
id: 1231,
44
name: 'Carne Asada',
@@ -25,4 +25,4 @@ const foodList = [
2525
}
2626
]
2727

28-
export { foodList }
28+
export { foodListData }

01-react-css3/solution/app.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
@import url("../../public/workshop/css/reset.css");
2-
@import url("../../public/workshop/css/main.css")
2+
@import url("../../public/workshop/css/app.css")

01-react-css3/solution/components/AddToCartButton.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import React, { Component } from 'react'
2-
import classnames from 'classnames'
1+
import React, { Component, PropTypes } from 'react'
32
import { Button } from './index'
43
import '../../../public/workshop/css/button-icons.css'
4+
import '../../../public/workshop/css/add-to-cart-button.css'
55

66
export class AddToCartButton extends Component {
77

@@ -10,6 +10,11 @@ export class AddToCartButton extends Component {
1010
buttonText: 'Add'
1111
}
1212

13+
static propTypes = {
14+
disabled: PropTypes.bool,
15+
onClick: PropTypes.func.isRequired
16+
}
17+
1318
onButtonClicked = () => {
1419
this.props.onClick(!this.state.depressed)
1520
this.setState({
@@ -20,12 +25,11 @@ export class AddToCartButton extends Component {
2025

2126
render () {
2227
const { buttonText, depressed } = this.state
23-
const { classNames, onClick, disabled, ...otherProps } = this.props
24-
const buttonClassNames = classnames('icon icon-add', classNames)
28+
const { onClick, disabled, ...otherProps } = this.props
2529

2630
return (
2731
<Button
28-
classNames={ buttonClassNames }
32+
classNames="icon icon-add add_to_cart_button"
2933
depressed={ depressed }
3034
disabled={ disabled }
3135
onClick={ this.onButtonClicked }

01-react-css3/solution/components/BuyNowButton.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import React, { Component } from 'react'
1+
import React, { Component, PropTypes } from 'react'
22
import { Button } from './index'
3+
import '../../../public/workshop/css/buy-now-button.css'
34

45
export class BuyNowButton extends Component {
56

@@ -8,6 +9,10 @@ export class BuyNowButton extends Component {
89
buttonText: 'Buy Now'
910
}
1011

12+
static propTypes = {
13+
onClick: PropTypes.func.isRequired
14+
}
15+
1116
onButtonClicked = () => {
1217
this.props.onClick()
1318
this.setState({
@@ -19,11 +24,11 @@ export class BuyNowButton extends Component {
1924

2025
render () {
2126
const { buttonText, depressed, disabled } = this.state
22-
const { classNames, onClick, ...otherProps } = this.props
27+
const { onClick, ...otherProps } = this.props
2328

2429
return (
2530
<Button
26-
classNames={ classNames }
31+
classNames="buy_now_button"
2732
depressed={ depressed }
2833
disabled={ disabled }
2934
onClick={ this.onButtonClicked }

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1-
import React, { Component } from 'react'
1+
import React, { Component, PropTypes } from 'react'
22
import { BuyNowButton } from './index'
33
import numeral from 'numeral'
4+
import '../../../public/workshop/css/buy-strip.css'
45

56
export class BuyStrip extends Component {
67

78
state = {
89
confirmed: false
910
}
1011

12+
static propTypes = {
13+
totalPrice: PropTypes.number,
14+
onBuy: PropTypes.func.isRequired
15+
}
16+
1117
buyNowClicked () {
1218
this.props.onBuy()
1319
this.setState({ confirmed: true })
@@ -28,7 +34,6 @@ export class BuyStrip extends Component {
2834
<div className="buy_title">Total:<span className="buy_total">{ formattedPrice }</span></div>
2935
<BuyNowButton
3036
onClick={ this.buyNowClicked.bind(this) }
31-
classNames="buy_button"
3237
disabled={ totalPrice === 0 }>
3338
Buy Now
3439
</BuyNowButton>

01-react-css3/solution/components/FoodItem.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
1-
import React, { Component } from 'react'
1+
import React, { Component, PropTypes } from 'react'
22
import { AddToCartButton } from './index'
33
import numeral from 'numeral'
4+
import '../../../public/workshop/css/food-item.css'
45

56
export class FoodItem extends Component {
67

78
state = {
89
inCart: false
910
}
1011

12+
static propTypes = {
13+
id: PropTypes.number,
14+
name: PropTypes.string,
15+
price: PropTypes.number,
16+
photoPath: PropTypes.string,
17+
disabled: PropTypes.bool,
18+
updateTotal: PropTypes.func.isRequired
19+
}
20+
1121
addToCart (inCart) {
1222
this.props.updateTotal(this.props.price, inCart)
1323
}
@@ -18,11 +28,10 @@ export class FoodItem extends Component {
1828

1929
return (
2030
<li className="food_item">
21-
<figure className="food_item_image"><img className="food_item_photo" src={ photoPath } /></figure>
31+
<figure className="food_item_figure"><img className="food_item_image" src={ photoPath } /></figure>
2232
<div className="food_item_name">{ name }<span className="food_item_price">{ numeral(price).format('$0.00') }</span></div>
2333
<AddToCartButton
2434
onClick={ this.addToCart.bind(this) }
25-
classNames="food_add_button"
2635
disabled={ disabled }
2736
/>
2837
</li>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export { Button } from './Button'
2+
23
export { AddToCartButton } from './AddToCartButton'
34
export { BuyNowButton } from './BuyNowButton'
45

05-react-css-modules/lessons/Button/Button.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import CSSModules from 'react-css-modules'
33
import styles from './button.css'
44
import classnames from 'classnames'
55

6-
@CSSModules(styles, {allowMultiple: true})
6+
@CSSModules(styles, { allowMultiple: true })
77
export class Button extends Component {
88

99
state = { depressed: false }
@@ -13,13 +13,11 @@ export class Button extends Component {
1313
})
1414

1515
render () {
16-
const buttonClassNames = classnames('btn', {
17-
'depressed': this.state.depressed
18-
})
1916
return (
2017
<button
21-
styleName={buttonClassNames}
22-
onClick={this.onButtonClicked}>
18+
styleName="btn"
19+
className={ this.state.depressed && styles.depressed }
20+
onClick={ this.onButtonClicked }>
2321
{this.props.children}
2422
</button>
2523
)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/* Custom styling for Add to Cart Button */
2+
3+
.add_to_cart_button {
4+
min-width: 110px;
5+
}

public/workshop/css/all.css

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
11
@import url("./reset.css");
2+
23
@import url("./button.css");
34
@import url("./button-icons.css");
4-
@import url("./main.css")
5+
@import url("./add-to-cart-button.css");
6+
@import url("./buy-now-button.css");
7+
8+
@import url("./food.css");
9+
@import url("./food-item.css");
10+
11+
@import url("./buy-strip.css");
12+
13+
@import url("./app.css");
14+
15+

public/workshop/css/app.css

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
/* app specific */
2+
3+
body {
4+
background-color: #E1E1E1;
5+
font-size: 16px;
6+
}
7+
8+
@media screen and (min-width: 608px) {
9+
body {
10+
font-size: 15px;
11+
}
12+
}
13+
14+
body, input, button {
15+
font-family: helvetica;
16+
}
17+
18+
body, a {
19+
color: #222324;
20+
}
21+
22+
.app {
23+
min-width: 320px;
24+
}
25+
26+
/* header section */
27+
28+
.header {
29+
display: flex;
30+
margin: 0 auto;
31+
position: relative;
32+
justify-content: center;
33+
height: 70px;
34+
align-items: center;
35+
background-color: #02573A;
36+
color: #fff;
37+
}
38+
39+
.logo {
40+
background-image: url(../img/logo.png);
41+
width: 800px;
42+
height: 54px;
43+
background-repeat: no-repeat;
44+
background-position: 50% 50%;
45+
background-size: 80%;
46+
}
47+
48+
@media screen and (min-width: 608px) {
49+
.logo {
50+
background-size: 50%;
51+
}
52+
}
53+
54+
.logo span {
55+
display: none;
56+
}
57+
58+
/* order section */
59+
60+
@media screen and (min-width: 608px) {
61+
.order {
62+
max-width: 900px;
63+
margin: 30px auto 0;
64+
}
65+
}
66+
67+
/* order food header */
68+
.order .food .food_header {
69+
max-width: 100%;
70+
max-height: 224px;
71+
width: 100%;
72+
overflow: hidden;
73+
display: flex;
74+
align-items: center;
75+
}
76+
77+
@media screen and (min-width: 608px) {
78+
.order .food .food_header {
79+
max-height: 226px;
80+
}
81+
}
82+
83+
.order .food .food_header .food_header_image {
84+
display: block;
85+
width: 100%;
86+
height: 100%;
87+
}
88+
89+
/* order food menu */
90+
91+
.food_menu {
92+
background-color: #fff;
93+
}
94+
95+
.food_items {
96+
transition: 300ms all ease-in;
97+
}
98+
99+
@media screen and (min-width: 608px) {
100+
.food_items {
101+
display: flex;
102+
flex-wrap: wrap;
103+
justify-content: space-around;
104+
padding: 32px;
105+
}
106+
}
107+
108+
/* animate close food list */
109+
.closefoods-enter {
110+
opacity: 0.01;
111+
max-height: 0;
112+
}
113+
114+
.closefoods-enter-active {
115+
opacity: 1;
116+
max-height: 1000;
117+
transition: all 500ms ease-in;
118+
}
119+
120+
.closefoods-leave {
121+
max-height: 1000px;
122+
opacity: 1;
123+
}
124+
125+
.closefoods-leave-active {
126+
opacity: 0.01;
127+
max-height: 0;
128+
transition: all 600ms ease;
129+
}
130+
131+
/* footer section */
132+
133+
.footer {
134+
text-align: center;
135+
padding: 20px;
136+
font-size: 12px;
137+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/* Custom styling for Buy Now Button */
2+
3+
.buy_now_button {
4+
background-color: #fff;
5+
color: #000;
6+
box-shadow: 1px -1px 2px rgba(0, 0, 0, .2);
7+
width: 110px;
8+
}
9+
10+
.buy_now_button:hover {
11+
background-color: #000;
12+
color: #fff;
13+
}
14+
15+
.btn.buy_now_button.depressed {
16+
box-shadow: 1px -1px 2px rgba(0, 0, 0, 0);
17+
}

0 commit comments

Comments
 (0)