Skip to content

Commit 08c1e0a

Browse files
authored
Merge pull request #1708 from AletheiaFact/Change-all-popover-and-tooltip
Change all popover and tooltip
2 parents 1e91041 + fd01b85 commit 08c1e0a

24 files changed

+385
-265
lines changed

src/components/AffixButton/AffixCTAButton.tsx

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,24 @@ import Banner from "../SentenceReport/Banner";
66
import { useTranslation } from "next-i18next";
77
import Cookies from "js-cookie";
88
import CtaAnimation from "../CtaAnimation";
9-
import { Tooltip } from "antd";
9+
import InfoTooltip from "../Claim/InfoTooltip";
1010
import colors from "../../styles/colors";
1111
import { trackUmamiEvent } from "../../lib/umami";
1212
import { useAppSelector } from "../../store/store";
1313

1414
const CloseIcon = () => {
1515
const { t } = useTranslation();
1616
return (
17-
<Tooltip
18-
title={t("affix:AffixCloseTooltip")}
19-
placement="topRight"
20-
defaultOpen
21-
color={colors.white}
22-
overlayInnerStyle={{ color: colors.black }}
23-
>
24-
<CloseOutlined style={{margin:"10px", color:colors.white}} />
25-
</Tooltip>
17+
<InfoTooltip
18+
children={
19+
<CloseOutlined style={{ margin: "10px", color: colors.white }} />
20+
}
21+
content={
22+
<span style={{ color: colors.black, fontSize: 15 }}>
23+
{t("affix:AffixCloseTooltip")}
24+
</span>
25+
}
26+
/>
2627
);
2728
};
2829

src/components/AffixButton/Fab.tsx

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { Button, ButtonProps, Tooltip } from "antd";
1+
import { ButtonProps, IconButton } from "@mui/material";
2+
import InfoTooltip from "../Claim/InfoTooltip";
23
import React, { useLayoutEffect, useState } from "react";
34
import colors from "../../styles/colors";
45
import { NameSpaceEnum } from "../../types/Namespace";
@@ -18,28 +19,35 @@ const Fab = ({ tooltipText, style, icon, size, ...rest }: FabProps) => {
1819
useLayoutEffect(() => {
1920
setNameSpaceProp(nameSpace);
2021
}, [nameSpace]);
22+
23+
const TooltipBanner = (
24+
<IconButton
25+
style={{
26+
background: colors.white,
27+
color:
28+
nameSpaceProp === NameSpaceEnum.Main
29+
? colors.primary
30+
: colors.secondary,
31+
boxShadow: `0px 8px 24px ${colors.shadow}`,
32+
display: "grid",
33+
placeContent: "center",
34+
width: size,
35+
height: size,
36+
...style,
37+
}}
38+
{...rest}
39+
>
40+
{icon}
41+
</IconButton>
42+
);
43+
2144
return (
22-
<Tooltip placement="left" title={tooltipText}>
23-
<Button
24-
style={{
25-
background: colors.white,
26-
color:
27-
nameSpaceProp === NameSpaceEnum.Main
28-
? colors.primary
29-
: colors.secondary,
30-
boxShadow: `0px 8px 24px ${colors.shadow}`,
31-
display: "grid",
32-
placeContent: "center",
33-
width: size,
34-
height: size,
35-
...style,
36-
}}
37-
shape="circle"
38-
type="link"
39-
icon={icon}
40-
{...rest}
41-
/>
42-
</Tooltip>
45+
<InfoTooltip
46+
useCustomStyle={false}
47+
placement="left"
48+
children={TooltipBanner}
49+
content={tooltipText}
50+
/>
4351
);
4452
};
4553

src/components/AletheiaAvatar.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Avatar } from "antd";
1+
import { Avatar } from "@mui/material";
22
import React from "react";
33
import colors from "../styles/colors";
44

@@ -25,7 +25,7 @@ const AletheiaAvatar = ({ size, src, alt }: AletheiaAvatarProps) => {
2525
aspectRatio: "1",
2626
}}
2727
>
28-
<Avatar size={size} src={src} alt={alt} />
28+
<Avatar sx={{width: size, height: size}} src={src} alt={alt} />
2929
</div>
3030
);
3131
};

src/components/Claim/ClaimSentence.tsx

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import styled from "styled-components";
44
import colors from "../../styles/colors";
55
import actions from "../../store/actions";
66
import { useDispatch } from "react-redux";
7-
import SentencePopover from "./SentencePopover";
7+
import InfoTooltip from "./InfoTooltip";
8+
import { InfoOutlined, SecurityOutlined } from "@mui/icons-material";
9+
import { useTranslation } from "react-i18next";
810

911
const Sentence = styled.a`
1012
color: ${colors.primary};
@@ -25,6 +27,7 @@ const ClaimSentence = ({
2527
handleSentenceClick,
2628
}) => {
2729
let style = {};
30+
const { t } = useTranslation();
2831
if (properties.classification && showHighlights) {
2932
style = {
3033
...style,
@@ -37,6 +40,24 @@ const ClaimSentence = ({
3740
handleSentenceClick();
3841
dispatch(actions.openReviewDrawer());
3942
};
43+
44+
const tooltipContent = (
45+
<span
46+
style={{
47+
color: colors.primary,
48+
lineHeight: "20px",
49+
fontSize: 14,
50+
display: "flex",
51+
alignItems: "center",
52+
gap: 4,
53+
padding: 5
54+
}}
55+
>
56+
<SecurityOutlined fontSize="small" />
57+
{t("reviewTask:sentenceInfo")}
58+
</span>
59+
);
60+
4061
return (
4162
<>
4263
<Sentence
@@ -59,7 +80,10 @@ const ClaimSentence = ({
5980
padding: "0 4px 0 1px",
6081
}}
6182
>
62-
<SentencePopover />
83+
<InfoTooltip
84+
children={<InfoOutlined style={{ fontSize: "18px", color: colors.neutralSecondary }} />}
85+
content={tooltipContent}
86+
/>
6387
</sup>
6488
)}
6589
</>

src/components/Claim/ClaimView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ const ClaimView = ({ personality, claim, href, hideDescriptions }) => {
7979
personality={personality}
8080
header={true}
8181
mobile={true}
82-
titleLevel={2}
82+
titleLevel="h2"
8383
/>
8484
)}
8585
<section>
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { styled, Tooltip, tooltipClasses, TooltipProps } from "@mui/material";
2+
import React from "react";
3+
import colors from "../../styles/colors";
4+
5+
type InfoTooltipProps = {
6+
placement?: TooltipProps["placement"];
7+
content: React.ReactNode;
8+
children: React.ReactElement;
9+
useCustomStyle?: boolean;
10+
};
11+
12+
const DefaultTooltip = ({ className, ...props }: TooltipProps) => {
13+
return (
14+
<Tooltip {...props} arrow
15+
title={
16+
<span style={{ fontSize: 15 }}>
17+
{props.title}
18+
</span>
19+
}
20+
>
21+
{props.children}
22+
</Tooltip>
23+
);
24+
};
25+
26+
const InfoTooltip: React.FC<InfoTooltipProps> = ({
27+
placement = "top",
28+
content,
29+
children,
30+
useCustomStyle = true,
31+
}) => {
32+
33+
const CustomTooltip = styled(({ className, ...props }: TooltipProps) => (
34+
<Tooltip {...props} arrow classes={{ popper: className }} />
35+
))(() => ({
36+
[`& .${tooltipClasses.arrow}`]: {
37+
color: colors.white,
38+
},
39+
[`& .${tooltipClasses.tooltip}`]: {
40+
backgroundColor: colors.white,
41+
maxWidth: "100%",
42+
boxShadow: `0px 0px 15px ${colors.shadow}`,
43+
},
44+
}));
45+
46+
47+
const TooltipComponent = useCustomStyle ? CustomTooltip : DefaultTooltip;
48+
49+
return (
50+
<TooltipComponent placement={placement} title={content}>
51+
{children}
52+
</TooltipComponent>
53+
);
54+
};
55+
56+
export default InfoTooltip;

src/components/Claim/Popover.tsx

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import React from "react";
2+
import { IconButton, Popover, PopoverOrigin } from "@mui/material";
3+
4+
interface PopoverClickProps {
5+
children: React.ReactNode;
6+
content: React.ReactNode;
7+
anchorOrigin?: PopoverOrigin;
8+
transformOrigin?: PopoverOrigin;
9+
}
10+
11+
const PopoverClick: React.FC<PopoverClickProps> = ({
12+
children,
13+
content,
14+
anchorOrigin = { vertical: "bottom", horizontal: "center" },
15+
transformOrigin = { vertical: "top", horizontal: "center" },
16+
}) => {
17+
const [anchorEl, setAnchorEl] = React.useState<HTMLElement | null>(null);
18+
const open = Boolean(anchorEl);
19+
const id = open ? "simple-popover" : undefined;
20+
21+
const handleClick = (event: React.MouseEvent<HTMLElement>) => {
22+
setAnchorEl(event.currentTarget);
23+
};
24+
25+
const handleClose = () => {
26+
setAnchorEl(null);
27+
};
28+
29+
return (
30+
<>
31+
<IconButton
32+
aria-describedby={id}
33+
onClick={handleClick}
34+
>
35+
{children}
36+
</IconButton>
37+
<Popover
38+
id={id}
39+
open={open}
40+
anchorEl={anchorEl}
41+
onClose={handleClose}
42+
anchorOrigin={anchorOrigin}
43+
transformOrigin={transformOrigin}
44+
>
45+
{content}
46+
</Popover>
47+
</>
48+
);
49+
};
50+
51+
export default PopoverClick;

src/components/Claim/SentencePopover.tsx

Lines changed: 0 additions & 33 deletions
This file was deleted.

src/components/Collaborative/Comment/CommentCardActions.tsx

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { useContext } from "react";
22
import MoreVertIcon from "@mui/icons-material/MoreVert";
33
import CheckIcon from "@mui/icons-material/Check";
44
import CommentPopoverContent from "./CommentPopoverContent";
5-
import { Popover } from "antd";
5+
import PopoverClick from "../../Claim/Popover";
66
import Button, { ButtonType } from "../../Button";
77
import ReviewTaskApi from "../../../api/reviewTaskApi";
88
import CommentApi from "../../../api/comment";
@@ -45,11 +45,11 @@ const CommentCardActions = ({ content, setIsResolved }) => {
4545
comments.map((comment) =>
4646
comment._id === content.targetId
4747
? {
48-
...comment,
49-
replies: comment.replies.filter(
50-
(reply) => reply._id !== content._id
51-
),
52-
}
48+
...comment,
49+
replies: comment.replies.filter(
50+
(reply) => reply._id !== content._id
51+
),
52+
}
5353
: comment
5454
)
5555
);
@@ -82,18 +82,16 @@ const CommentCardActions = ({ content, setIsResolved }) => {
8282
{role !== Roles.Regular &&
8383
role !== Roles.FactChecker &&
8484
isReviewing && (
85-
<Popover
86-
trigger="click"
87-
placement="bottom"
88-
overlayInnerStyle={{ padding: 0 }}
85+
<PopoverClick
86+
children={
87+
<MoreVertIcon style={{ cursor: "pointer" }} />
88+
}
8989
content={
9090
<CommentPopoverContent
9191
handleDeleteClick={handleDeleteClick}
9292
/>
9393
}
94-
>
95-
<MoreVertIcon style={{ cursor: "pointer" }} />
96-
</Popover>
94+
/>
9795
)}
9896
</div>
9997
);

src/components/Collaborative/Comment/CommentPopoverContent.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const CommentPopoverContent = ({ handleDeleteClick }) => {
1515
border: "none",
1616
display: "flex",
1717
justifyContent: "start",
18-
padding: 0,
18+
margin: "5px 0px",
1919
}}
2020
onClick={handleDeleteClick}
2121
>

0 commit comments

Comments
 (0)