Feat: created image component
This commit is contained in:
@@ -10,6 +10,7 @@
|
|||||||
"preview": "vite preview"
|
"preview": "vite preview"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@dnd-kit/core": "^6.3.1",
|
||||||
"react": "^18.3.1",
|
"react": "^18.3.1",
|
||||||
"react-dom": "^18.3.1"
|
"react-dom": "^18.3.1"
|
||||||
},
|
},
|
||||||
|
|||||||
42
src/App.css
42
src/App.css
@@ -1,42 +0,0 @@
|
|||||||
#root {
|
|
||||||
max-width: 1280px;
|
|
||||||
margin: 0 auto;
|
|
||||||
padding: 2rem;
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.logo {
|
|
||||||
height: 6em;
|
|
||||||
padding: 1.5em;
|
|
||||||
will-change: filter;
|
|
||||||
transition: filter 300ms;
|
|
||||||
}
|
|
||||||
.logo:hover {
|
|
||||||
filter: drop-shadow(0 0 2em #646cffaa);
|
|
||||||
}
|
|
||||||
.logo.react:hover {
|
|
||||||
filter: drop-shadow(0 0 2em #61dafbaa);
|
|
||||||
}
|
|
||||||
|
|
||||||
@keyframes logo-spin {
|
|
||||||
from {
|
|
||||||
transform: rotate(0deg);
|
|
||||||
}
|
|
||||||
to {
|
|
||||||
transform: rotate(360deg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@media (prefers-reduced-motion: no-preference) {
|
|
||||||
a:nth-of-type(2) .logo {
|
|
||||||
animation: logo-spin infinite 20s linear;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.card {
|
|
||||||
padding: 2em;
|
|
||||||
}
|
|
||||||
|
|
||||||
.read-the-docs {
|
|
||||||
color: #888;
|
|
||||||
}
|
|
||||||
|
|||||||
63
src/App.tsx
63
src/App.tsx
@@ -1,35 +1,48 @@
|
|||||||
import { useState } from 'react'
|
import { useEffect, useRef, useState } from 'react';
|
||||||
import reactLogo from './assets/react.svg'
|
import './App.css';
|
||||||
import viteLogo from '/vite.svg'
|
import { TierImage } from './components/Image';
|
||||||
import './App.css'
|
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
const [count, setCount] = useState(0)
|
const [images, setImages] = useState<string[]>([]);
|
||||||
|
useEffect(() => {
|
||||||
|
console.log(images);
|
||||||
|
}, [images]);
|
||||||
|
const uploadBtn = useRef<HTMLInputElement>(null);
|
||||||
|
|
||||||
|
const clickUpload = () => {
|
||||||
|
if (uploadBtn.current) uploadBtn.current.click();
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div>
|
<div className='flex flex-row w-full'>
|
||||||
<a href="https://vite.dev" target="_blank">
|
{images.map((image, index) => (
|
||||||
<img src={viteLogo} className="logo" alt="Vite logo" />
|
<TierImage image={image} name='test' key={index} />
|
||||||
</a>
|
))}
|
||||||
<a href="https://react.dev" target="_blank">
|
|
||||||
<img src={reactLogo} className="logo react" alt="React logo" />
|
|
||||||
</a>
|
|
||||||
</div>
|
</div>
|
||||||
<h1>Vite + React</h1>
|
<div className='border border-black w-20 text-center cursor-pointer' onClick={clickUpload}>
|
||||||
<div className="card">
|
<span>Upload</span>
|
||||||
<button onClick={() => setCount((count) => count + 1)}>
|
<input
|
||||||
count is {count}
|
type='file'
|
||||||
</button>
|
name='imageUpload'
|
||||||
<p>
|
accept='.jpeg'
|
||||||
Edit <code>src/App.tsx</code> and save to test HMR
|
ref={uploadBtn}
|
||||||
</p>
|
style={{ display: 'none' }}
|
||||||
|
onChange={event => {
|
||||||
|
console.log(event.target.files);
|
||||||
|
if (event.target.files) {
|
||||||
|
const upload_images: string[] = [];
|
||||||
|
for (let i = 0; i < event.target.files.length; i++) {
|
||||||
|
const url = URL.createObjectURL(event.target.files[i]);
|
||||||
|
upload_images.push(url);
|
||||||
|
}
|
||||||
|
setImages(prev => [...prev, ...upload_images]);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<p className="read-the-docs">
|
|
||||||
Click on the Vite and React logos to learn more
|
|
||||||
</p>
|
|
||||||
</>
|
</>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default App
|
export default App;
|
||||||
|
|||||||
15
src/components/Image.tsx
Normal file
15
src/components/Image.tsx
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
interface ImageProps {
|
||||||
|
image: string;
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const TierImage = ({ image, name }: ImageProps) => {
|
||||||
|
return (
|
||||||
|
<div className='flex flex-wrap justify-center gap-4 mr-1'>
|
||||||
|
<div className={`w-[10rem] h-[calc(10rem*1.7)] relative`}>
|
||||||
|
<img src={image} alt={name} className='h-full w-full object-cover' />
|
||||||
|
<div className='w-full bg-slate-500 text-white bg-opacity-70 text-center bottom-0 left-0 absolute'>{name}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
0
src/components/Tier.tsx
Normal file
0
src/components/Tier.tsx
Normal file
@@ -1,68 +1,3 @@
|
|||||||
:root {
|
@tailwind base;
|
||||||
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
|
@tailwind components;
|
||||||
line-height: 1.5;
|
@tailwind utilities;
|
||||||
font-weight: 400;
|
|
||||||
|
|
||||||
color-scheme: light dark;
|
|
||||||
color: rgba(255, 255, 255, 0.87);
|
|
||||||
background-color: #242424;
|
|
||||||
|
|
||||||
font-synthesis: none;
|
|
||||||
text-rendering: optimizeLegibility;
|
|
||||||
-webkit-font-smoothing: antialiased;
|
|
||||||
-moz-osx-font-smoothing: grayscale;
|
|
||||||
}
|
|
||||||
|
|
||||||
a {
|
|
||||||
font-weight: 500;
|
|
||||||
color: #646cff;
|
|
||||||
text-decoration: inherit;
|
|
||||||
}
|
|
||||||
a:hover {
|
|
||||||
color: #535bf2;
|
|
||||||
}
|
|
||||||
|
|
||||||
body {
|
|
||||||
margin: 0;
|
|
||||||
display: flex;
|
|
||||||
place-items: center;
|
|
||||||
min-width: 320px;
|
|
||||||
min-height: 100vh;
|
|
||||||
}
|
|
||||||
|
|
||||||
h1 {
|
|
||||||
font-size: 3.2em;
|
|
||||||
line-height: 1.1;
|
|
||||||
}
|
|
||||||
|
|
||||||
button {
|
|
||||||
border-radius: 8px;
|
|
||||||
border: 1px solid transparent;
|
|
||||||
padding: 0.6em 1.2em;
|
|
||||||
font-size: 1em;
|
|
||||||
font-weight: 500;
|
|
||||||
font-family: inherit;
|
|
||||||
background-color: #1a1a1a;
|
|
||||||
cursor: pointer;
|
|
||||||
transition: border-color 0.25s;
|
|
||||||
}
|
|
||||||
button:hover {
|
|
||||||
border-color: #646cff;
|
|
||||||
}
|
|
||||||
button:focus,
|
|
||||||
button:focus-visible {
|
|
||||||
outline: 4px auto -webkit-focus-ring-color;
|
|
||||||
}
|
|
||||||
|
|
||||||
@media (prefers-color-scheme: light) {
|
|
||||||
:root {
|
|
||||||
color: #213547;
|
|
||||||
background-color: #ffffff;
|
|
||||||
}
|
|
||||||
a:hover {
|
|
||||||
color: #747bff;
|
|
||||||
}
|
|
||||||
button {
|
|
||||||
background-color: #f9f9f9;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user