From e1a12fd78bb9725fdd366aa6bcc31ac8e7b683a8 Mon Sep 17 00:00:00 2001 From: hmacr Date: Wed, 2 Apr 2025 15:58:32 +0530 Subject: [PATCH] tweak mention display --- .../HoverPreview/HoverPreviewIssue.tsx | 2 +- .../HoverPreview/HoverPreviewPullRequest.tsx | 2 +- .../components}/IssueStatusIcon.tsx | 0 .../components}/PullRequestIcon.tsx | 0 shared/components/Text.tsx | 73 +++++++++++++++++++ shared/editor/components/Mentions.tsx | 44 ++++++++--- 6 files changed, 109 insertions(+), 12 deletions(-) rename {app/components/Icons => shared/components}/IssueStatusIcon.tsx (100%) rename {app/components/Icons => shared/components}/PullRequestIcon.tsx (100%) create mode 100644 shared/components/Text.tsx diff --git a/app/components/HoverPreview/HoverPreviewIssue.tsx b/app/components/HoverPreview/HoverPreviewIssue.tsx index 032328ffa0..bf71e62ac4 100644 --- a/app/components/HoverPreview/HoverPreviewIssue.tsx +++ b/app/components/HoverPreview/HoverPreviewIssue.tsx @@ -1,9 +1,9 @@ import * as React from "react"; import { Trans } from "react-i18next"; +import { IssueStatusIcon } from "@shared/components/IssueStatusIcon"; import { UnfurlResourceType, UnfurlResponse } from "@shared/types"; import { Avatar } from "~/components/Avatar"; import Flex from "~/components/Flex"; -import { IssueStatusIcon } from "../Icons/IssueStatusIcon"; import Text from "../Text"; import Time from "../Time"; import { diff --git a/app/components/HoverPreview/HoverPreviewPullRequest.tsx b/app/components/HoverPreview/HoverPreviewPullRequest.tsx index 6393695134..c4165e4bf9 100644 --- a/app/components/HoverPreview/HoverPreviewPullRequest.tsx +++ b/app/components/HoverPreview/HoverPreviewPullRequest.tsx @@ -1,9 +1,9 @@ import * as React from "react"; import { Trans } from "react-i18next"; +import { PullRequestIcon } from "@shared/components/PullRequestIcon"; import { UnfurlResourceType, UnfurlResponse } from "@shared/types"; import { Avatar } from "~/components/Avatar"; import Flex from "~/components/Flex"; -import { PullRequestIcon } from "../Icons/PullRequestIcon"; import Text from "../Text"; import Time from "../Time"; import { diff --git a/app/components/Icons/IssueStatusIcon.tsx b/shared/components/IssueStatusIcon.tsx similarity index 100% rename from app/components/Icons/IssueStatusIcon.tsx rename to shared/components/IssueStatusIcon.tsx diff --git a/app/components/Icons/PullRequestIcon.tsx b/shared/components/PullRequestIcon.tsx similarity index 100% rename from app/components/Icons/PullRequestIcon.tsx rename to shared/components/PullRequestIcon.tsx diff --git a/shared/components/Text.tsx b/shared/components/Text.tsx new file mode 100644 index 0000000000..812eeb6a48 --- /dev/null +++ b/shared/components/Text.tsx @@ -0,0 +1,73 @@ +import styled, { css } from "styled-components"; +import { ellipsis } from "../styles"; + +type Props = { + /** The type of text to render */ + type?: "secondary" | "tertiary" | "danger"; + /** The size of the text */ + size?: "xlarge" | "large" | "medium" | "small" | "xsmall"; + /** The direction of the text (defaults to ltr) */ + dir?: "ltr" | "rtl" | "auto"; + /** Whether the text should be selectable (defaults to false) */ + selectable?: boolean; + /** The font weight of the text */ + weight?: "xbold" | "bold" | "normal"; + /** Whether the text should be italic */ + italic?: boolean; + /** Whether the text should be truncated with an ellipsis */ + ellipsis?: boolean; + /** Whether the text should be monospaced */ + monospace?: boolean; +}; + +/** + * Use this component for all interface text that should not be selectable + * by the user, this is the majority of UI text explainers, notes, headings. + */ +const Text = styled.span` + margin-top: 0; + text-align: ${(props) => (props.dir ? props.dir : "inherit")}; + color: ${(props) => + props.type === "secondary" + ? props.theme.textSecondary + : props.type === "tertiary" + ? props.theme.textTertiary + : props.type === "danger" + ? props.theme.brand.red + : props.theme.text}; + font-size: ${(props) => + props.size === "xlarge" + ? "26px" + : props.size === "large" + ? "18px" + : props.size === "medium" + ? "16px" + : props.size === "small" + ? "14px" + : props.size === "xsmall" + ? "13px" + : "inherit"}; + + ${(props) => + props.weight && + css` + font-weight: ${props.weight === "xbold" + ? 600 + : props.weight === "bold" + ? 500 + : props.weight === "normal" + ? 400 + : "inherit"}; + `} + + font-style: ${(props) => (props.italic ? "italic" : "normal")}; + font-family: ${(props) => + props.monospace ? props.theme.fontFamilyMono : "inherit"}; + + white-space: normal; + user-select: ${(props) => (props.selectable ? "text" : "none")}; + + ${(props) => props.ellipsis && ellipsis()} +`; + +export default Text; diff --git a/shared/editor/components/Mentions.tsx b/shared/editor/components/Mentions.tsx index 6a6cd66d7e..71f31ecadb 100644 --- a/shared/editor/components/Mentions.tsx +++ b/shared/editor/components/Mentions.tsx @@ -9,8 +9,12 @@ import { Node } from "prosemirror-model"; import * as React from "react"; import { useTranslation } from "react-i18next"; import { Link } from "react-router-dom"; +import Flex from "../../components/Flex"; import Icon from "../../components/Icon"; +import { IssueStatusIcon } from "../../components/IssueStatusIcon"; +import { PullRequestIcon } from "../../components/PullRequestIcon"; import Spinner from "../../components/Spinner"; +import Text from "../../components/Text"; import useStores from "../../hooks/useStores"; import theme from "../../styles/theme"; import type { UnfurlResourceType, UnfurlResponse } from "../../types"; @@ -116,7 +120,7 @@ export const MentionCollection = observer(function MentionCollection_( export const MentionIssue = (props: ComponentProps) => { const { unfurls } = useStores(); - const [data, setData] = + const [issue, setIssue] = React.useState(); const [loaded, setLoaded] = React.useState(false); @@ -125,7 +129,7 @@ export const MentionIssue = (props: ComponentProps) => { React.useEffect(() => { const fetchIssue = async () => { - setData(await unfurls.fetch(attrs.href)); + setIssue(await unfurls.fetch(attrs.href)); setLoaded(true); }; @@ -136,7 +140,7 @@ export const MentionIssue = (props: ComponentProps) => { return ; } - if (!data) { + if (!issue) { return ; } @@ -150,14 +154,24 @@ export const MentionIssue = (props: ComponentProps) => { target="_blank" rel="noopener noreferrer" > - {data.title} + + + + {issue.title} + {issue.id} + + ); }; export const MentionPullRequest = (props: ComponentProps) => { const { unfurls } = useStores(); - const [data, setData] = + const [pullRequest, setPullRequest] = React.useState(); const [loaded, setLoaded] = React.useState(false); @@ -166,7 +180,7 @@ export const MentionPullRequest = (props: ComponentProps) => { React.useEffect(() => { const fetchPR = async () => { - setData(await unfurls.fetch(attrs.href)); + setPullRequest(await unfurls.fetch(attrs.href)); setLoaded(true); }; @@ -177,7 +191,7 @@ export const MentionPullRequest = (props: ComponentProps) => { return ; } - if (!data) { + if (!pullRequest) { return ; } @@ -191,7 +205,17 @@ export const MentionPullRequest = (props: ComponentProps) => { target="_blank" rel="noopener noreferrer" > - {data.title} + + + + {pullRequest.title} + {pullRequest.id} + + ); }; @@ -202,7 +226,7 @@ const MentionLoading = ({ className }: { className: string }) => { return ( - {`${t("Loading")}…`} + {`${t("Loading")}…`} ); }; @@ -213,7 +237,7 @@ const MentionError = ({ className }: { className: string }) => { return ( - {`${t("Error loading data")}`} + {`${t("Error loading data")}`} ); };