Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
E
exam_7
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zarina
exam_7
Commits
95600ec5
Commit
95600ec5
authored
Mar 28, 2020
by
zarina
🌊
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#4
, реализована возможность добавления элемента в корзину
parent
4178ca4a
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
40 additions
and
11 deletions
+40
-11
Menu.js
src/components/Menu/Menu.js
+22
-5
MenuItem.css
src/components/Menu/MenuItem/MenuItem.css
+3
-2
MenuItem.js
src/components/Menu/MenuItem/MenuItem.js
+3
-3
App.js
src/containers/App.js
+12
-1
No files found.
src/components/Menu/Menu.js
View file @
95600ec5
...
...
@@ -3,11 +3,28 @@ import MenuItem from "./MenuItem/MenuItem";
import
'./Menu.css'
const
Menu
=
props
=>
{
return
(
<
div
className
=
'Menu'
>
<
MenuItem
/>
<
/div
>
);
let
createMenu
=
()
=>
{
let
menuKeys
=
Object
.
keys
(
props
.
menuList
);
return
menuKeys
.
map
(
key
=>
{
let
className
=
[
'MenuItem'
];
if
(
props
.
menuList
[
key
].
type
===
'drink'
)
{
className
.
push
(
'MenuItem_drink'
)
}
else
{
className
.
push
(
'MenuItem_eat'
)
}
return
<
MenuItem
addElem
=
{()
=>
(
props
.
addElement
(
key
))}
name
=
{
key
}
price
=
{
props
.
menuList
[
key
].
price
}
key
=
{
'MenuItem-'
+
key
}
class
=
{
className
.
join
(
' '
)}
/
>
});
};
return
(
<
div
className
=
'Menu'
>
{
createMenu
()}
<
/div
>
);
};
export
default
Menu
;
\ No newline at end of file
src/components/Menu/MenuItem/MenuItem.css
View file @
95600ec5
...
...
@@ -4,6 +4,7 @@
height
:
auto
;
width
:
35%
;
border
:
3px
solid
#eee
;
padding
:
20px
0
;
padding-left
:
70px
;
padding
:
20px
0
20px
70px
;
display
:
inline-block
;
cursor
:
pointer
;
}
\ No newline at end of file
src/components/Menu/MenuItem/MenuItem.js
View file @
95600ec5
...
...
@@ -2,9 +2,9 @@ import React from "react";
import
'./MenuItem.css'
const
MenuItem
=
props
=>
{
return
(
<
div
className
=
'MenuItem'
>
<
h3
className
=
'MenuItem_name'
>
testik
<
/h3
>
<
span
className
=
'MenuItem_price'
>
Price
:
1321312
<
/span
>
<
div
onClick
=
{
props
.
addElem
}
className
=
{
props
.
class
}
>
<
h3
className
=
'MenuItem_name'
>
{
props
.
name
}
<
/h3
>
<
span
className
=
'MenuItem_price'
>
Price
:
{
props
.
price
}
<
/span
>
<
/div
>
);
};
...
...
src/containers/App.js
View file @
95600ec5
...
...
@@ -35,13 +35,24 @@ class App extends Component {
basket
:
{}
};
addElement
=
(
name
)
=>
{
let
basket
=
{...
this
.
state
.
basket
};
if
(
!
basket
[
name
]){
basket
[
name
]
=
1
}
else
{
basket
[
name
]
++
}
let
totalPrice
=
this
.
state
.
totalPrice
+
this
.
state
.
menu
[
name
].
price
;
this
.
setState
({
totalPrice
,
basket
})
};
render
()
{
return
(
<
div
className
=
'App'
>
<
Basket
/>
<
Menu
/>
<
Menu
menuList
=
{
this
.
state
.
menu
}
addElement
=
{
this
.
addElement
}
/
>
<
/div
>
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment