This repository was archived by the owner on Jan 29, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcoupon.tsx
More file actions
273 lines (251 loc) · 6.75 KB
/
coupon.tsx
File metadata and controls
273 lines (251 loc) · 6.75 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
import { styled } from 'styled-components'
import { format, isAfter, subMinutes } from 'date-fns'
import { formatNumber } from '@titicaca/view-utilities'
import { Button, FlexBox, Text } from '@titicaca/tds-ui'
import { CouponBubbleProp } from '../type'
import { ButtonBubble } from '../button'
import { nolBackgroundColor } from './styles'
const CouponContainer = styled.div<{ valid: boolean }>`
display: inline-flex;
border-radius: 14px;
border: 1px solid ${({ valid }) => (valid ? '#B2BAFF' : '#E1E2E7')};
overflow: hidden;
`
const Coupon = styled.div<{ valid: boolean }>`
padding: 15px;
width: 213px;
text-align: left;
display: inline-block;
color: ${({ valid }) => (valid ? '#1B1C1F' : '#B6B7BB')};
background-color: ${({ valid }) => (valid ? 'white' : '#FEFEFF')};
`
const StyledDownloadIcon = styled.svg<{ disabled?: boolean }>`
stroke: ${({ disabled }) => (disabled ? '#DADBDF' : '#1B1C1F')};
`
function DownloadIcon({ disabled }: { disabled?: boolean }) {
return (
<StyledDownloadIcon
disabled={disabled}
width="20"
height="20"
viewBox="0 0 20 20"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path d="M10 2.5V11.25" strokeWidth="1.625" strokeLinecap="round" />
<path
d="M5.625 8.75L9.73483 12.8598C9.88128 13.0063 10.1187 13.0063 10.2652 12.8598L14.375 8.75"
strokeWidth="1.625"
strokeLinecap="round"
/>
<path d="M4.375 16.75H15.625" strokeWidth="1.625" strokeLinecap="round" />
</StyledDownloadIcon>
)
}
const DownloadButton = styled(Button)`
padding: 0;
border-radius: 0;
border-left: 1px solid #ecedf7;
background-color: #f7f7ff;
width: 39px;
display: flex;
align-items: center;
justify-content: center;
&:disabled {
background-color: #f7f8fb;
}
`
const Badge = styled.div<{ valid: boolean }>`
margin-bottom: 2px;
padding: 0 6px;
width: fit-content;
border-radius: 6px;
font-size: 11px;
font-weight: 700;
line-height: 22px;
color: ${({ valid, theme }) => (valid ? theme.nol.colorPrimaryNol : 'white')};
background-color: ${({ valid }) =>
valid ? '#F5F6FF' : 'rgba(0, 0, 0, 0.2)'};
`
const PartnerBadge = styled(Badge)<{ valid: boolean }>`
margin-bottom: 0;
font-size: 10px;
line-height: 20px;
color: #6e6f73;
background-color: #f2f3f7;
opacity: ${({ valid }) => (valid ? 1 : 0.5)};
`
const CouponTitle = styled(Text).attrs({
size: 13,
bold: true,
lineHeight: '16px',
})`
color: #1b1c1f;
`
const CouponPrice = styled(Text).attrs({
size: 32,
bold: true,
lineHeight: '38px',
margin: { bottom: 12 },
})`
color: #1b1c1f;
`
const CouponPropertyText = styled(Text).attrs({
size: 12,
lineHeight: '14px',
})`
color: #6e6f73;
font-weight: 400;
`
const CouponContainerWithNotch = styled.button<{ valid: boolean }>`
--border-color: ${({ valid }) => (valid ? '#dfe2ff' : '#e9eaef')};
width: 254px;
height: 142px;
background: white;
border-radius: 20px;
border: 2px solid var(--border-color);
text-align: left;
position: relative;
&::before {
content: '';
width: 20px;
height: 20px;
position: absolute;
top: 50%;
right: -22px;
transform: translate(-50%, -50%) rotate(225deg);
border-radius: 50%;
border: 2px solid transparent;
border-top-color: var(--border-color);
border-right-color: var(--border-color);
background-color: ${nolBackgroundColor};
}
> div {
padding: 18px;
}
${CouponTitle}, ${CouponPrice}, ${CouponPropertyText} {
color: ${({ valid }) => !valid && 'rgba(0, 0, 0, 0.30)'};
}
`
export function NolCouponContentBubble({ coupon, onClick }: CouponBubbleProp) {
const valid = isAfter(new Date(coupon.period.endAt), new Date())
return (
<CouponContainer valid={valid}>
<Coupon valid={valid}>
<Badge valid={valid}>쉿! 🤫 고객님께만 드려요!</Badge>
<Text
css={{
color: 'inherit',
fontSize: '30px',
fontWeight: 700,
lineHeight: '38px',
marginBottom: '6px',
}}
>
{formatNumber(coupon.discount.value)}원
</Text>
<Text
css={{
color: 'inherit',
fontSize: '12px',
fontWeight: 700,
lineHeight: '14px',
marginBottom: '2px',
}}
>
중복사용가능
</Text>
<Text
css={{
color: 'inherit',
fontSize: '12px',
fontWeight: 400,
lineHeight: '14px',
marginBottom: '2px',
}}
>
{valid
? `${format(
subMinutes(new Date(coupon.period.endAt), 1),
'yyyy.MM.dd(HH:mm)',
)}까지 사용`
: '쿠폰 사용 기간 만료'}
</Text>
<Text
css={{
color: 'inherit',
fontSize: '12px',
fontWeight: 400,
lineHeight: '14px',
}}
maxLines={1}
>
{coupon.propertyName}
</Text>
</Coupon>
<DownloadButton
disabled={!valid}
onClick={() => valid && onClick?.(coupon, 'download')}
>
<DownloadIcon disabled={!valid} />
</DownloadButton>
</CouponContainer>
)
}
export function NolCouponButtonBubble({
id,
my,
coupon,
onClick,
...props
}: CouponBubbleProp) {
const valid = isAfter(new Date(coupon.period.endAt), new Date())
return (
<ButtonBubble
id={id}
my={my}
label="쿠폰 바로 사용하기"
action={{ type: 'button' }}
onButtonClick={() => valid && onClick?.(coupon, 'product')}
disabled={!valid}
hasArrow={false}
{...props}
/>
)
}
export function NolCouponContentPartnerBubble({
coupon,
onClick,
}: CouponBubbleProp) {
const valid = isAfter(new Date(coupon.period.endAt), new Date())
return (
<CouponContainerWithNotch
valid={valid}
onClick={() => valid && onClick?.(coupon, 'download')}
>
<div>
<FlexBox
flex
flexDirection="row"
alignItems="center"
justifyContent="space-between"
>
<CouponTitle>{coupon.name}</CouponTitle>
<PartnerBadge valid={valid}>중복사용가능</PartnerBadge>
</FlexBox>
<CouponPrice>{formatNumber(coupon.discount.value)}원</CouponPrice>
<CouponPropertyText css={{ marginBottom: '4px' }}>
{valid
? `${format(
subMinutes(new Date(coupon.period.endAt), 1),
'yyyy.MM.dd(HH:mm)',
)}까지 사용`
: '사용 기간 만료'}
</CouponPropertyText>
<CouponPropertyText maxLines={1}>
{coupon.propertyName}
</CouponPropertyText>
</div>
</CouponContainerWithNotch>
)
}