-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPostcardContainer.tsx
More file actions
111 lines (103 loc) · 2.32 KB
/
PostcardContainer.tsx
File metadata and controls
111 lines (103 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
'use client';
import Image from 'next/image';
import { cn } from '@/shared/lib';
import { cva, type VariantProps } from 'class-variance-authority';
interface PostcardContainerProps {
postcards: string[];
onClickCard?: (index: number) => void;
className?: string;
bordered?: boolean;
}
const postcardContainerStyle = cva(
`
layout-grid w-full
rounded-[20px] border bg-pink-50 border-pink-200
p-[1.2rem] gap-[0.6rem]
overflow-y-hidden no-scrollbar
transition-all
`,
{
variants: {
bordered: {
false: 'border-none',
},
},
defaultVariants: {
bordered: true,
},
},
);
const postcardGridStyle = `
grid grid-rows-2 grid-flow-col
auto-cols-[minmax(70px,70px)]
gap-[0.6rem]
`;
const postcardCardStyle = cva(
`
flex aspect-square rounded-[8px]
border border-pink-200 overflow-hidden
bg-gray-100 transition
`,
{
variants: {
interactive: {
true: 'cursor-pointer hover:opacity-80',
false: 'cursor-default',
},
},
defaultVariants: {
interactive: true,
},
},
);
export default function PostcardContainer({
postcards = [],
onClickCard,
className,
bordered,
}: PostcardContainerProps) {
// 엽서 기본 8개 (null placeholder유지) + 9개 부터는 가로 스크롤
const totalSlots = Math.max(postcards.length, 8);
const filledSlots = Array(totalSlots)
.fill(null)
.map((_, i) => postcards[i] ?? null);
return (
<div
className={cn(
postcardContainerStyle({ bordered }),
className,
postcards.length > 8 && 'overflow-x-auto',
)}
>
<div
className={cn(
postcardGridStyle,
postcards.length <= 8 && 'justify-center',
)}
>
{filledSlots.map((src, idx) => (
<button
key={idx}
onClick={() => src && onClickCard?.(idx)}
disabled={!src}
aria-disabled={!src}
className={cn(
postcardCardStyle({ interactive: !!src }),
!src && 'items-center justify-center bg-gray-200',
)}
>
{src && (
<Image
src={src}
alt={`엽서 ${idx + 1}`}
width={200}
height={200}
className="w-full h-full object-cover"
/>
)}
</button>
))}
</div>
</div>
);
}