Toggle navigation
Toggle navigation
This project
Loading...
Sign in
2021-1-capstone-design1
/
MAC_Project1
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
이정민
2021-04-13 22:17:33 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
d1e2ee9ec40b944af8e6db6d49980016ca157f6d
d1e2ee9e
1 parent
5afdccfa
사진 셀렉트
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
64 additions
and
1 deletions
src/components/Image.js
src/components/Image.js
View file @
d1e2ee9
import
{
useState
}
from
"react"
;
import
styled
from
"styled-components"
;
const
Image
=
()
=>
{
const
[
file
,
setFile
]
=
useState
(
undefined
);
const
[
previewURL
,
setPreviewURL
]
=
useState
(
""
);
// const uploadImage = (file) => {
// if (!file) {
// return;
// }
// };
const
selectImg
=
(
e
)
=>
{
const
reader
=
new
FileReader
();
const
targetFile
=
e
.
target
.
files
[
0
];
setFile
(
targetFile
);
// uploadImage(targetFile);
reader
.
onloadend
=
()
=>
{
setPreviewURL
(
reader
.
result
);
};
reader
.
readAsDataURL
(
targetFile
);
};
return
(
<
Container
>
<
ImgBox
/>
<
ImgBox
>
{
file
===
undefined
?
(
<>
<
BlankBox
/>
<
div
>
Click
to
add
a
photo
<
/div
>
<
input
type
=
"file"
style
=
{{
marginTop
:
"5px"
,
position
:
"absolute"
,
zIndex
:
0
,
width
:
"90%"
,
height
:
"100%"
,
border
:
"none"
,
cursor
:
"pointer"
,
outline
:
"none"
,
}}
onChange
=
{
selectImg
}
/
>
<
/
>
)
:
(
<
img
alt
=
{
""
}
style
=
{{
objectFit
:
"cover"
,
display
:
"flex"
,
margin
:
"0 auto"
}}
src
=
{
previewURL
}
/
>
)}
<
/ImgBox
>
<
Menu
/>
<
/Container
>
);
...
...
@@ -26,12 +76,17 @@ const Container = styled.div`
justify-content: center;
`
;
const
ImgBox
=
styled
.
div
`
position: relative;
width: 40rem;
height: 30rem;
background-color: white;
box-shadow:
${({
theme
})
=>
theme
.
boxShadow
.
normal
}
;
border-radius: 2rem;
margin-top: 2rem;
display: flex;
align-items: center;
justify-content: center;
font-size: 1rem;
`
;
const
Box
=
styled
.
div
`
...
...
@@ -42,5 +97,13 @@ const Box = styled.div`
background-color: white;
box-shadow:
${({
theme
})
=>
theme
.
boxShadow
.
normal
}
;
`
;
const
BlankBox
=
styled
.
div
`
z-index: 1;
position: absolute;
top: 0;
width: 90%;
height: 50px;
background-color: white;
`
;
export
default
Image
;
...
...
Please
register
or
login
to post a comment