Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FR-252] Pass clicked element to userOnClick callback #53

Merged
merged 2 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Message/MessageAuthor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ function MessageAuthor({
<Styles.MessageAuthor
clickable={userOnClick !== undefined}
{...props}
onClick={() => userOnClick?.(author)}
onClick={(e) => userOnClick?.(author, e.currentTarget)}
>
<Styles.Username style={{ color: dominantRoleColor }}>
{displayName}
Expand All @@ -114,7 +114,7 @@ function MessageAuthor({
<Styles.MessageAuthor
clickable={userOnClick !== undefined}
{...props}
onClick={() => userOnClick?.(author)}
onClick={(e) => userOnClick?.(author, e.currentTarget)}
>
<Styles.AnimatedAvatarTrigger
data-is-animated={animatedAvatarUrl !== undefined}
Expand Down
2 changes: 1 addition & 1 deletion src/core/ConfigContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export type Config<SvgConfig extends PartialSvgConfig> = {
// Click handlers
currentUser(): APIUser | null;
seeThreadOnClick?(messageId: Snowflake, thread: APIChannel): void;
userOnClick?(user: APIUser): void;
userOnClick?(user: APIUser, element: EventTarget & HTMLSpanElement): void;
roleMentionOnClick?(role: APIRole): void;
channelMentionOnClick?(channel: APIChannel): void;
openPinnedMessagesOnClick?(channel: APIChannel): void;
Expand Down
4 changes: 2 additions & 2 deletions src/markdown/render/elements/mentions/userMention.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ function UserMention({ userId }: UserMentionProps) {

return (
<Styles.Mention
onClick={() => {
if (user !== null) userOnClick?.(user);
onClick={(e) => {
if (user !== null) userOnClick?.(user, e.currentTarget);
}}
canBeClicked={userOnClick !== undefined}
>
Expand Down
12 changes: 11 additions & 1 deletion src/stories/Wrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,17 @@ const Wrapper: Decorator = (Story) => {
seeThreadOnClick={(messageId, thread) =>
alert(`See Thread "${thread.name}" clicked on message ${messageId}`)
}
userOnClick={(user) => alert(`User "${getDisplayName(user)}" clicked!`)}
userOnClick={(user, el) => {
const elPos = el.getBoundingClientRect();

return alert(
`User "${getDisplayName(
user
)}" clicked! \nClicked Position: X - ${Math.floor(
elPos.left
)} Y - ${Math.floor(elPos.top)}`
);
}}
roleMentionOnClick={(role) =>
alert(`Role "${role.name}" mention clicked!`)
}
Expand Down