-
Notifications
You must be signed in to change notification settings - Fork 303
Expand file tree
/
Copy pathFeedCardGlassActions.tsx
More file actions
243 lines (233 loc) · 8.68 KB
/
Copy pathFeedCardGlassActions.tsx
File metadata and controls
243 lines (233 loc) · 8.68 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
import type { ReactElement } from 'react';
import React, { useMemo } from 'react';
import classNames from 'classnames';
import type { ActionButtonsProps } from './ActionButtons';
import { UpvoteButtonIcon } from './UpvoteButtonIcon';
import InteractionCounter from '../../InteractionCounter';
import { QuaternaryButton } from '../../buttons/QuaternaryButton';
import { BookmarkButton } from '../../buttons/BookmarkButton';
import PostAwardAction from '../../post/PostAwardAction';
import {
DiscussIcon as CommentIcon,
DownvoteIcon,
LinkIcon,
} from '../../icons';
import { ButtonColor, ButtonSize, ButtonVariant } from '../../buttons/Button';
import { IconSize } from '../../Icon';
import { Tooltip } from '../../tooltip/Tooltip';
import { useFeedPreviewMode } from '../../../hooks/useFeedPreviewMode';
import { useCardActions } from '../../../hooks/cards/useCardActions';
import { useBrandSponsorship } from '../../../hooks/useBrandSponsorship';
// Full-bleed cover: drop side padding/bottom margin and round only the bottom
// corners so the image meets the card edges. Height/crop are untouched.
export const glassCoverImageClassName =
'!px-0 !mb-0 !rounded-t-none !rounded-b-16';
const outerClasses = 'pointer-events-none absolute inset-x-2 bottom-2 z-1';
// Only the rest color is pinned to text-primary for contrast on the glass;
// hover/pressed colors are left to each `btn-tertiary-*` class so icons keep
// their brand tint on hover, matching the standard ActionButtons.
const pillClasses = classNames(
'pointer-events-auto flex h-10 w-full items-center justify-between gap-0.5 overflow-hidden px-1',
'rounded-12 border border-border-subtlest-tertiary',
'bg-blur-bg text-text-primary backdrop-blur-xl backdrop-saturate-150',
'[&_.btn-quaternary]:[--button-default-color:var(--theme-text-primary)]',
'[&_.btn]:[--button-default-color:var(--theme-text-primary)]',
);
// Each action sizes to its content (so the count inside the upvote/comment
// button isn't clipped) and the row spreads them with `justify-between`. An
// equal-width `flex-1` layout forced every slot to 1/N of the pill, which is
// narrower than a count-bearing button on tight (e.g. 5-column) cards — so the
// buttons overflowed their slots and overlapped.
const slotClasses = 'flex min-w-0 shrink items-center justify-center';
// Dark glow behind the pill so it stays readable over busy cover images. Fixed
// pepper tint in both themes; inline gradient since it's a one-off scrim.
const scrimGradient =
'radial-gradient(75% 90% at 0% 100%, rgba(14, 18, 23, 0.55) 0%, rgba(14, 18, 23, 0) 70%)';
const scrimClasses =
'pointer-events-none absolute bottom-0 left-0 z-0 h-24 w-3/5 rounded-bl-16';
export function FeedCardGlassActions({
post,
onUpvoteClick,
onCommentClick,
onBookmarkClick,
onCopyLinkClick,
onDownvoteClick,
showDownvoteAction = true,
showAwardAction = true,
coverScrim = false,
}: ActionButtonsProps & { coverScrim?: boolean }): ReactElement | null {
const isFeedPreview = useFeedPreviewMode();
const { getUpvoteAnimation } = useBrandSponsorship();
const {
isUpvoteActive,
isDownvoteActive,
onToggleUpvote,
onToggleDownvote,
onToggleBookmark,
} = useCardActions({
post,
onUpvoteClick,
onDownvoteClick,
onBookmarkClick,
onCopyLinkClick,
});
// Branded upvote animation (icon swaps to the advertiser logo) when the post
// has a sponsored tag (engagement ad).
const brandAnimation = useMemo(() => {
const animationResult = getUpvoteAnimation(post.tags || []);
if (
!animationResult.shouldAnimate ||
!animationResult.colors ||
!animationResult.config
) {
return null;
}
return {
colors: animationResult.colors,
config: animationResult.config,
brandLogo: animationResult.brandLogo,
};
}, [getUpvoteAnimation, post.tags]);
if (isFeedPreview) {
return null;
}
const upvoteCount = post.numUpvotes ?? 0;
const commentCount = post.numComments ?? 0;
return (
<>
{coverScrim && (
<div
aria-hidden
className={scrimClasses}
style={{ background: scrimGradient }}
/>
)}
<div className={outerClasses}>
<div className={pillClasses}>
<div className={slotClasses}>
<Tooltip
content={isUpvoteActive ? 'Remove upvote' : 'More like this'}
side="bottom"
>
<QuaternaryButton
labelClassName="!pl-[1px] pr-1.5"
className="btn-tertiary-avocado pointer-events-auto"
id={`post-${post.id}-upvote-btn`}
color={ButtonColor.Avocado}
pressed={isUpvoteActive}
onClick={onToggleUpvote}
variant={ButtonVariant.Tertiary}
size={ButtonSize.Small}
icon={
<UpvoteButtonIcon
secondary={isUpvoteActive}
size={IconSize.XSmall}
brandAnimation={brandAnimation}
/>
}
>
{upvoteCount > 0 && (
<InteractionCounter
className="tabular-nums typo-footnote"
value={upvoteCount}
/>
)}
</QuaternaryButton>
</Tooltip>
</div>
<div className={slotClasses}>
<Tooltip content="Comments" side="bottom">
<QuaternaryButton
labelClassName="!pl-[1px] pr-1.5"
id={`post-${post.id}-comment-btn`}
icon={
<CommentIcon
secondary={post.commented}
size={IconSize.XSmall}
/>
}
pressed={post.commented}
onClick={() => onCommentClick?.(post)}
size={ButtonSize.Small}
className="btn-tertiary-blueCheese pointer-events-auto"
>
{commentCount > 0 && (
<InteractionCounter
className="tabular-nums typo-footnote"
value={commentCount}
/>
)}
</QuaternaryButton>
</Tooltip>
</div>
{showDownvoteAction && (
<div className={slotClasses}>
<Tooltip
content={
isDownvoteActive ? 'Remove downvote' : 'Less like this'
}
side="bottom"
>
<QuaternaryButton
className="pointer-events-auto"
id={`post-${post.id}-downvote-btn`}
color={ButtonColor.Ketchup}
icon={
<DownvoteIcon
secondary={isDownvoteActive}
size={IconSize.XSmall}
/>
}
pressed={isDownvoteActive}
onClick={onToggleDownvote}
variant={ButtonVariant.Tertiary}
size={ButtonSize.Small}
/>
</Tooltip>
</div>
)}
{showAwardAction && (
<div className={slotClasses}>
<PostAwardAction post={post} iconSize={IconSize.XSmall} />
</div>
)}
<div className={slotClasses}>
<BookmarkButton
tooltipSide="bottom"
post={post}
buttonProps={{
id: `post-${post.id}-bookmark-btn`,
onClick: onToggleBookmark,
size: ButtonSize.Small,
className: 'btn-tertiary-bun pointer-events-auto',
}}
iconSize={IconSize.XSmall}
/>
</div>
<div className={slotClasses}>
<Tooltip content="Copy link" side="bottom">
{/* DEMO: static copy button. Does a plain synchronous clipboard
write with no interaction tracking or async state, so it can
never render a loading spinner in the action pill. */}
<QuaternaryButton
id="copy-post-btn"
size={ButtonSize.Small}
icon={<LinkIcon size={IconSize.XSmall} />}
onClick={() => {
if (typeof navigator !== 'undefined') {
navigator.clipboard?.writeText(
post.commentsPermalink || post.permalink || '',
);
}
}}
variant={ButtonVariant.Tertiary}
color={ButtonColor.Cabbage}
className="pointer-events-auto"
/>
</Tooltip>
</div>
</div>
</div>
</>
);
}