|
1 | | -import React, { useState, useEffect } from 'react'; |
2 | | -import {Link} from 'react-router-dom'; |
3 | | -export default function Card({user}) { |
| 1 | +import { useState, useEffect } from "react"; |
| 2 | +import { Link } from "react-router-dom"; |
| 3 | +import PropTypes from "prop-types"; |
4 | 4 |
|
5 | | - const [truncatedText, setTruncatedText] = useState(''); |
6 | | - const maxLength = 25; // Maximum number of words |
7 | | - |
8 | | - useEffect(() => { |
9 | | - const text = user.description |
10 | | - const words = text.split(' '); |
11 | | - |
12 | | - if (words.length > maxLength) { |
13 | | - setTruncatedText(words.slice(0, maxLength).join(' ') + '...'); |
14 | | - } else { |
15 | | - setTruncatedText(text); |
16 | | - } |
17 | | - }, []); |
| 5 | +function Card({ user }) { |
| 6 | + const [truncatedText, setTruncatedText] = useState(""); |
| 7 | + const maxLength = 25; // Maximum number of words |
| 8 | + |
| 9 | + useEffect(() => { |
| 10 | + const text = user.description; |
| 11 | + const words = text.split(" "); |
| 12 | + |
| 13 | + if (words.length > maxLength) { |
| 14 | + setTruncatedText(words.slice(0, maxLength).join(" ")); |
| 15 | + } else { |
| 16 | + setTruncatedText(text); |
| 17 | + } |
| 18 | + }, []); |
18 | 19 | return ( |
19 | | - <> |
20 | | - <div className=" shadow-lg bg-zinc-600 rounded-2xl max-w-96 h-[30rem] relative"> |
21 | | - <img className="w-mag rounded-se-2xl rounded-ss-2xl" src={`${user.image}`} alt={user.alt} /> |
22 | | - <div className='content-box px-4 pt-2'> |
| 20 | + <div className=" shadow-lg bg-zinc-600 rounded-2xl max-w-96 h-[30rem] relative"> |
| 21 | + <img |
| 22 | + className="w-mag rounded-se-2xl rounded-ss-2xl" |
| 23 | + src={`${user.image}`} |
| 24 | + alt={user.alt} |
| 25 | + /> |
| 26 | + <div className="content-box px-4 pt-2"> |
23 | 27 | <p className="py-1 font-medium text-white break-words">{user.name}</p> |
24 | 28 | <p className="date font-thin py-2 pr-3 text-zinc-400">{user.date}</p> |
25 | 29 | <p className="description text-white font-light ">{truncatedText}</p> |
26 | | - </div> |
27 | | - <Link to={user.link} className="absolute bottom-0 left-0 right-0 text-center tracking-widest font-thin drop-shadow-lg text-white py-7 hover:text-red-600">READ MORE</Link> |
28 | | - </div> |
29 | | - </> |
| 30 | + </div> |
| 31 | + <Link |
| 32 | + to={user.link} |
| 33 | + className="absolute bottom-0 left-0 right-0 text-center tracking-widest font-thin drop-shadow-lg text-white py-7 hover:text-red-600" |
| 34 | + > |
| 35 | + READ MORE |
| 36 | + </Link> |
| 37 | + </div> |
30 | 38 | ); |
31 | 39 | } |
| 40 | +Card.propTypes = { |
| 41 | + user: PropTypes.isRequired, |
| 42 | +}; |
| 43 | + |
| 44 | +export default Card; |
0 commit comments