|
| 1 | +import CardImage from 'components/CardImage' |
| 2 | +import CardFooter from 'components/CardFooter' |
| 3 | +import CardHeader from 'components/CardHeader' |
| 4 | + |
| 5 | +const {useState} = React |
| 6 | + |
| 7 | +export default function Card({ |
| 8 | + content, |
| 9 | + url, |
| 10 | + urlToImage, |
| 11 | + publishedAt, |
| 12 | + description, |
| 13 | + source, |
| 14 | + title |
| 15 | +}) { |
| 16 | + const [showMore, setShowMore] = useState(false) |
| 17 | + const [hover, setHover] = useState(false) |
| 18 | + |
| 19 | + const handleReadMore = e => { |
| 20 | + e.preventDefault() |
| 21 | + e.stopPropagation() |
| 22 | + setShowMore(!showMore) |
| 23 | + } |
| 24 | + |
| 25 | + return ( |
| 26 | + <> |
| 27 | + <a |
| 28 | + href={url} |
| 29 | + onMouseOver={() => setHover(true)} |
| 30 | + onMouseLeave={() => setHover(false)} |
| 31 | + > |
| 32 | + <article itemScope itemType="http://schema.org/Article"> |
| 33 | + <CardImage urlToImage={urlToImage} /> |
| 34 | + <div> |
| 35 | + <CardHeader |
| 36 | + title={title} |
| 37 | + description={description} |
| 38 | + handleReadMore={handleReadMore} |
| 39 | + show={hover && !showMore} |
| 40 | + /> |
| 41 | + </div> |
| 42 | + |
| 43 | + <p className={showMore ? 'show' : ''}>{content}</p> |
| 44 | + |
| 45 | + <div> |
| 46 | + <CardFooter |
| 47 | + show={hover} |
| 48 | + source={source.name} |
| 49 | + publishedAt={publishedAt} |
| 50 | + url={url} |
| 51 | + title={title} |
| 52 | + /> |
| 53 | + </div> |
| 54 | + </article> |
| 55 | + </a> |
| 56 | + <style jsx>{` |
| 57 | + @keyframes scale { |
| 58 | + from { |
| 59 | + transform: scale(0.9); |
| 60 | + } |
| 61 | + to { |
| 62 | + transform: scale(1); |
| 63 | + } |
| 64 | + } |
| 65 | +
|
| 66 | + a { |
| 67 | + display: block; |
| 68 | + text-decoration: none; |
| 69 | + transition: all 0.3s ease; |
| 70 | + } |
| 71 | +
|
| 72 | + a:hover { |
| 73 | + transform: scale(1.05); |
| 74 | + } |
| 75 | +
|
| 76 | + a:hover .onHover { |
| 77 | + opacity: 1; |
| 78 | + } |
| 79 | +
|
| 80 | + .onHover { |
| 81 | + opacity: 0; |
| 82 | + transition: all 0.3s ease; |
| 83 | + } |
| 84 | +
|
| 85 | + div { |
| 86 | + padding-left: 96px; |
| 87 | + } |
| 88 | +
|
| 89 | + p { |
| 90 | + color: #000; |
| 91 | + font-size: 14px; |
| 92 | + line-height: 1.5; |
| 93 | + margin: 0; |
| 94 | + max-height: 0; |
| 95 | + overflow: hidden; |
| 96 | + transition: height 0.3s ease; |
| 97 | + } |
| 98 | +
|
| 99 | + p.show { |
| 100 | + max-height: 5000px; |
| 101 | + padding-top: 16px; |
| 102 | + } |
| 103 | +
|
| 104 | + a:hover article { |
| 105 | + box-shadow: rgba(0, 0, 0, 0.1) 0px 8px 24px; |
| 106 | + transition: all 0.2s ease-in 0s; |
| 107 | + } |
| 108 | +
|
| 109 | + article { |
| 110 | + animation: scale 1s ease-in-out; |
| 111 | + background: rgb(255, 255, 255); |
| 112 | + box-shadow: rgba(0, 0, 0, 0.08) 0px 4px 8px; |
| 113 | + border-radius: 8px; |
| 114 | + display: flex; |
| 115 | + flex-direction: column; |
| 116 | + padding: 16px; |
| 117 | + position: relative; |
| 118 | + transition: all 0.2s ease-out 0s; |
| 119 | + } |
| 120 | + `}</style> |
| 121 | + </> |
| 122 | + ) |
| 123 | +} |
0 commit comments