|
| 1 | +type BookCoverBadgeType = 'adult' | 'reading' | 'stopped' | 'readCount'; |
| 2 | + |
| 3 | +type BookCoverBadge = { |
| 4 | + type: BookCoverBadgeType; |
| 5 | + readCount?: number; |
| 6 | +}; |
| 7 | + |
1 | 8 | type BookCoverProps = { |
2 | 9 | url: string; |
3 | 10 | label?: string; |
4 | 11 | ratio?: number; |
5 | 12 | rounded?: 'sm' | 'lg'; |
6 | 13 | shadowLeftBar?: boolean; |
| 14 | + shadowRightTriangle?: boolean; |
| 15 | + topRightBadge?: BookCoverBadge; |
| 16 | + bottomRightBadge?: BookCoverBadge; |
7 | 17 | className?: string; |
8 | 18 | }; |
9 | 19 |
|
10 | | -export const BookCover = (props: BookCoverProps) => { |
11 | | - const { url, label = '', shadowLeftBar, ratio = 3 / 4, className = '', rounded = 'lg' } = props; |
12 | | - const roundedClass = rounded === 'sm' ? 'rounded' : 'rounded-md'; |
| 20 | +const MSG_BOOK_COVER_BADGE_ADULT = '성인'; |
| 21 | +const MSG_BOOK_COVER_BADGE_READING = '읽는중'; |
| 22 | +const MSG_BOOK_COVER_BADGE_STOPPED = '중단'; |
| 23 | +const MSG_BOOK_COVER_BADGE_READ_COUNT = '회독'; |
| 24 | + |
| 25 | +const getBadgeLabel = (badge: BookCoverBadge) => { |
| 26 | + if (badge.type === 'adult') return MSG_BOOK_COVER_BADGE_ADULT; |
| 27 | + if (badge.type === 'reading') return MSG_BOOK_COVER_BADGE_READING; |
| 28 | + if (badge.type === 'stopped') return MSG_BOOK_COVER_BADGE_STOPPED; |
| 29 | + |
| 30 | + return `${badge.readCount ?? 0}${MSG_BOOK_COVER_BADGE_READ_COUNT}`; |
| 31 | +}; |
| 32 | + |
| 33 | +const getBadgeClassName = (type: BookCoverBadgeType) => { |
| 34 | + if (type === 'adult') { |
| 35 | + return 'bg-[#FF4D4F]/90 text-white'; |
| 36 | + } |
| 37 | + |
| 38 | + return 'bg-[#888888]/80 text-white'; |
| 39 | +}; |
| 40 | + |
| 41 | +const Badge = (props: { badge: BookCoverBadge }) => { |
| 42 | + const { badge } = props; |
| 43 | + const label = getBadgeLabel(badge); |
| 44 | + const badgeClassName = getBadgeClassName(badge.type); |
13 | 45 |
|
14 | 46 | return ( |
15 | | - <div |
16 | | - className={`relative inline-block overflow-hidden border border-neutral-20 ${roundedClass} ${className}`} |
17 | | - style={{ aspectRatio: ratio }} |
| 47 | + <span className={`text-caption3 inline-flex items-center rounded-full px-2 py-0.5 ${badgeClassName}`}>{label}</span> |
| 48 | + ); |
| 49 | +}; |
| 50 | + |
| 51 | +const ShadowLeftBar = () => ( |
| 52 | + <span |
| 53 | + className="pointer-events-none absolute left-0 top-0 z-bookShadow h-full w-[9px] mix-blend-multiply" |
| 54 | + style={{ background: 'linear-gradient(90deg, #FFFFFF 65%, #E0E0E0 100%)' }} |
| 55 | + /> |
| 56 | +); |
| 57 | + |
| 58 | +const ShadowRightTriangleSvg = () => { |
| 59 | + return ( |
| 60 | + <svg |
| 61 | + width="16" |
| 62 | + height="21" |
| 63 | + viewBox="0 0 16 21" |
| 64 | + fill="none" |
| 65 | + xmlns="http://www.w3.org/2000/svg" |
| 66 | + className="pointer-events-none absolute -right-[11px] bottom-0 z-bookShadow w-4" |
| 67 | + aria-hidden="true" |
| 68 | + preserveAspectRatio="none" |
18 | 69 | > |
19 | | - <img className="relative z-20 size-full object-cover" src={url} alt={label} /> |
20 | | - {shadowLeftBar && ( |
21 | | - <span |
22 | | - className="pointer-events-none absolute left-0 top-0 z-30 h-full w-[9px] mix-blend-multiply" |
23 | | - style={{ background: 'linear-gradient(90deg, #FFFFFF 65%, #E0E0E0 100%)' }} |
| 70 | + <g opacity="0.6" style={{ mixBlendMode: 'multiply' }}> |
| 71 | + <path |
| 72 | + d="M4.65332 17.2529C3.65271 18.8944 1.90719 19.9246 0 20.0225C1.99315 19.888 3.56836 18.2304 3.56836 16.2031V0H15.1689L4.65332 17.2529Z" |
| 73 | + fill="url(#book-cover-shadow-right)" |
24 | 74 | /> |
25 | | - )} |
| 75 | + </g> |
| 76 | + <defs> |
| 77 | + <linearGradient |
| 78 | + id="book-cover-shadow-right" |
| 79 | + x1="9.08767" |
| 80 | + y1="0" |
| 81 | + x2="9.08767" |
| 82 | + y2="20.0313" |
| 83 | + gradientUnits="userSpaceOnUse" |
| 84 | + > |
| 85 | + <stop stopColor="#EEEEEE" /> |
| 86 | + <stop offset="1" stopColor="#888888" /> |
| 87 | + </linearGradient> |
| 88 | + </defs> |
| 89 | + </svg> |
| 90 | + ); |
| 91 | +}; |
| 92 | + |
| 93 | +export const BookCover = (props: BookCoverProps) => { |
| 94 | + const { |
| 95 | + url, |
| 96 | + label = '', |
| 97 | + shadowLeftBar = false, |
| 98 | + shadowRightTriangle = true, |
| 99 | + topRightBadge, |
| 100 | + bottomRightBadge, |
| 101 | + ratio = 3 / 4, |
| 102 | + className = '', |
| 103 | + rounded = 'lg', |
| 104 | + } = props; |
| 105 | + const roundedClass = rounded === 'sm' ? 'rounded' : 'rounded-md'; |
| 106 | + |
| 107 | + return ( |
| 108 | + <div className={`relative w-full ${className}`}> |
| 109 | + <div |
| 110 | + className={`relative w-full overflow-hidden border border-neutral-20 ${roundedClass}`} |
| 111 | + style={{ aspectRatio: ratio }} |
| 112 | + > |
| 113 | + <img className="absolute inset-0 z-bookShadow h-full w-full object-cover" src={url} alt={label} /> |
| 114 | + {shadowLeftBar && <ShadowLeftBar />} |
| 115 | + {topRightBadge && ( |
| 116 | + <div className="z-bookText absolute right-1 top-1"> |
| 117 | + <Badge badge={topRightBadge} /> |
| 118 | + </div> |
| 119 | + )} |
| 120 | + {bottomRightBadge && ( |
| 121 | + <div className="z-bookText absolute bottom-1 right-1"> |
| 122 | + <Badge badge={bottomRightBadge} /> |
| 123 | + </div> |
| 124 | + )} |
| 125 | + </div> |
| 126 | + {shadowRightTriangle && <ShadowRightTriangleSvg />} |
26 | 127 | </div> |
27 | 128 | ); |
28 | 129 | }; |
|
0 commit comments