generated from IvettaGoIT/react_vite
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from MargoMarm/addProductForm
added component AddProductForm
- Loading branch information
Showing
4 changed files
with
190 additions
and
5 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { useState } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import { | ||
AddButton, | ||
ButtonContainer, | ||
Calories, | ||
CloseButton, | ||
InputContainer, | ||
InputQuantity, | ||
InputTitle, | ||
TitleCalories, | ||
} from './AddProductForm.styled'; | ||
|
||
function AddProductForm({ data, closeModal }) { | ||
const [quantity, setQuantity] = useState(0); | ||
|
||
const amount = Math.round((quantity * data.calories) / 100); | ||
|
||
return ( | ||
<form> | ||
<InputContainer> | ||
<label> | ||
<InputTitle type="text" value={data.title} disabled /> | ||
</label> | ||
|
||
<label> | ||
<InputQuantity | ||
placeholder="grams" | ||
type="number" | ||
value={quantity} | ||
onChange={e => setQuantity(e.target.value)} | ||
/> | ||
</label> | ||
</InputContainer> | ||
|
||
<Calories> | ||
<TitleCalories>Calories:</TitleCalories> {amount} | ||
</Calories> | ||
|
||
<ButtonContainer> | ||
<AddButton type="button">Add to diary</AddButton> | ||
<CloseButton type="button" onClick={closeModal}> | ||
Cancel | ||
</CloseButton> | ||
</ButtonContainer> | ||
</form> | ||
); | ||
} | ||
|
||
AddProductForm.propTypes = { | ||
data: PropTypes.object, | ||
closeModal: PropTypes.func, | ||
}; | ||
|
||
export default AddProductForm; |
127 changes: 127 additions & 0 deletions
127
src/components/AddProductForm/AddProductForm.styled.jsx
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
import styled from '@emotion/styled'; | ||
import { colors, mq } from '../../utils'; | ||
|
||
export const Container = styled.div` | ||
background-color: ${colors.modalBlack}; | ||
border-radius: 12px; | ||
padding: 48px 24px; | ||
${mq.tablet} { | ||
padding: 48px 32px; | ||
} | ||
`; | ||
|
||
export const InputContainer = styled.div` | ||
margin-bottom: 16px; | ||
display: flex; | ||
flex-direction: column; | ||
gap: 16px; | ||
${mq.tablet} { | ||
flex-direction: row; | ||
} | ||
`; | ||
|
||
export const InputTitle = styled.input` | ||
width: 287px; | ||
height: 34px; | ||
padding: 8px 14px; | ||
border-radius: 12px; | ||
border: 1px solid ${colors.orange}; | ||
gap: 10px; | ||
background-color: inherit; | ||
color: ${colors.textWhite03}; | ||
${mq.tablet} { | ||
width: 244px; | ||
height: 40px; | ||
} | ||
`; | ||
|
||
export const InputQuantity = styled.input` | ||
width: 287px; | ||
height: 34px; | ||
padding: 8px 14px; | ||
border-radius: 12px; | ||
border: 1px solid ${colors.orange}; | ||
gap: 10px; | ||
background-color: inherit; | ||
color: ${colors.white}; | ||
&::placeholder { | ||
color: ${colors.textWhite03}; | ||
text-align: right; | ||
} | ||
${mq.tablet} { | ||
width: 155px; | ||
height: 40px; | ||
margin-top: 0; | ||
} | ||
`; | ||
|
||
export const Calories = styled.p` | ||
font-size: 12px; | ||
align-items: end; | ||
color: ${colors.white}; | ||
`; | ||
|
||
export const TitleCalories = styled.span` | ||
font-family: Roboto; | ||
font-size: 12px; | ||
font-weight: 400; | ||
line-height: 18px; | ||
letter-spacing: 0px; | ||
text-align: left; | ||
color: ${colors.textWhite04}; | ||
`; | ||
|
||
export const ButtonContainer = styled.div` | ||
display: flex; | ||
margin-top: 24px; | ||
${mq.tablet} { | ||
margin-top: 64px; | ||
} | ||
`; | ||
|
||
export const AddButton = styled.button` | ||
display: flex; | ||
padding: 12px 32px; | ||
justify-content: center; | ||
align-items: center; | ||
font-family: inherit; | ||
background-color: ${colors.orange}; | ||
color: ${colors.white}; | ||
border-radius: 12px; | ||
font-size: 16px; | ||
font-weight: 500; | ||
line-height: calc(18 / 16); | ||
border: 1px solid ${colors.textWhite03}; | ||
transition: background 0.3s ease-out; | ||
margin-right: 14px; | ||
&:hover { | ||
background: #ef8964; | ||
} | ||
${mq.tablet} { | ||
margin-right: 16px; | ||
} | ||
`; | ||
|
||
export const CloseButton = styled.button` | ||
display: flex; | ||
padding: 12px 36px; | ||
justify-content: center; | ||
align-items: center; | ||
font-family: inherit; | ||
background-color: inherit; | ||
color: ${colors.white}; | ||
border-radius: 12px; | ||
border: 1px solid ${colors.textWhite03}; | ||
font-size: 16px; | ||
font-weight: 500; | ||
line-height: calc(18 / 16); | ||
${mq.tablet} { | ||
padding: 12px 40px; | ||
} | ||
`; |
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
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