mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2026-07-25 17:34:52 +10:00
Merge branch 'main' into feat/increase-test-coverage
# Conflicts: # packages/ui/src/components/input-group.test.tsx
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
import type { Style } from "@react-pdf/types";
|
||||
import type { CustomField } from "@reactive-resume/schema/resume/data";
|
||||
import type { IconName } from "phosphor-icons-react-pdf/dynamic";
|
||||
import { View } from "@react-pdf/renderer";
|
||||
import { getCustomFieldLinkUrl, getWebsiteDisplayText } from "./contact";
|
||||
import { Icon, Link, Text } from "./primitives";
|
||||
|
||||
type WebsiteDisplay = {
|
||||
url: string;
|
||||
label?: string | undefined;
|
||||
};
|
||||
|
||||
type ContactStyle = Style | Style[];
|
||||
|
||||
export const WebsiteContactItem = ({
|
||||
website,
|
||||
style,
|
||||
textStyle,
|
||||
iconColor,
|
||||
}: {
|
||||
website: WebsiteDisplay;
|
||||
style?: ContactStyle;
|
||||
textStyle?: ContactStyle;
|
||||
iconColor?: string;
|
||||
}) => {
|
||||
if (!website.url) return null;
|
||||
|
||||
return (
|
||||
<Link src={website.url} {...(style ? { style } : {})}>
|
||||
<Icon name="globe" {...(iconColor ? { color: iconColor } : {})} />
|
||||
<Text {...(textStyle ? { style: textStyle } : {})}>{getWebsiteDisplayText(website)}</Text>
|
||||
</Link>
|
||||
);
|
||||
};
|
||||
|
||||
export const CustomFieldContactItem = ({
|
||||
field,
|
||||
style,
|
||||
textStyle,
|
||||
iconColor,
|
||||
}: {
|
||||
field: CustomField;
|
||||
style?: ContactStyle;
|
||||
textStyle?: ContactStyle;
|
||||
iconColor?: string;
|
||||
}) => {
|
||||
const linkUrl = getCustomFieldLinkUrl(field);
|
||||
const children = (
|
||||
<>
|
||||
<Icon name={field.icon as IconName} {...(iconColor ? { color: iconColor } : {})} />
|
||||
<Text {...(textStyle ? { style: textStyle } : {})}>{field.text}</Text>
|
||||
</>
|
||||
);
|
||||
|
||||
if (linkUrl) {
|
||||
return (
|
||||
<Link src={linkUrl} {...(style ? { style } : {})}>
|
||||
{children}
|
||||
</Link>
|
||||
);
|
||||
}
|
||||
|
||||
return <View {...(style ? { style } : {})}>{children}</View>;
|
||||
};
|
||||
@@ -0,0 +1,30 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { getCustomFieldLinkUrl, getWebsiteDisplayText } from "./contact";
|
||||
|
||||
describe("getWebsiteDisplayText", () => {
|
||||
it("falls back to the full URL when the website label is blank", () => {
|
||||
expect(getWebsiteDisplayText({ url: "https://davidkowalski.games", label: "" })).toBe(
|
||||
"https://davidkowalski.games",
|
||||
);
|
||||
expect(getWebsiteDisplayText({ url: "https://davidkowalski.games", label: " " })).toBe(
|
||||
"https://davidkowalski.games",
|
||||
);
|
||||
expect(getWebsiteDisplayText({ url: "http://example.com", label: undefined })).toBe("http://example.com");
|
||||
});
|
||||
|
||||
it("uses the website label when one is provided", () => {
|
||||
expect(getWebsiteDisplayText({ url: "https://davidkowalski.games", label: "Portfolio" })).toBe("Portfolio");
|
||||
});
|
||||
});
|
||||
|
||||
describe("getCustomFieldLinkUrl", () => {
|
||||
it("returns no link URL for blank custom field links", () => {
|
||||
expect(getCustomFieldLinkUrl({ link: "" })).toBeUndefined();
|
||||
expect(getCustomFieldLinkUrl({ link: " " })).toBeUndefined();
|
||||
expect(getCustomFieldLinkUrl({ link: undefined })).toBeUndefined();
|
||||
});
|
||||
|
||||
it("returns the custom field link URL when one is provided", () => {
|
||||
expect(getCustomFieldLinkUrl({ link: "https://example.com" })).toBe("https://example.com");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,20 @@
|
||||
type WebsiteDisplay = {
|
||||
url: string;
|
||||
label?: string | undefined;
|
||||
};
|
||||
|
||||
type CustomFieldLink = {
|
||||
link?: string | undefined;
|
||||
};
|
||||
|
||||
export const getWebsiteDisplayText = (website: WebsiteDisplay): string => {
|
||||
const label = website.label?.trim();
|
||||
|
||||
return label || website.url;
|
||||
};
|
||||
|
||||
export const getCustomFieldLinkUrl = (field: CustomFieldLink): string | undefined => {
|
||||
const link = field.link?.trim();
|
||||
|
||||
return link || undefined;
|
||||
};
|
||||
@@ -25,6 +25,7 @@ import { match } from "ts-pattern";
|
||||
import { useRender } from "../../context";
|
||||
import { getResumeSectionTitle } from "../../section-title";
|
||||
import { getSectionItemRows, getSectionItemsLayout, shouldUseSectionTimeline } from "./columns";
|
||||
import { getWebsiteDisplayText } from "./contact";
|
||||
import {
|
||||
TemplatePlacementProvider,
|
||||
useTemplateFeature,
|
||||
@@ -225,7 +226,7 @@ const ItemTitle = ({ children, website }: { children: ReactNode; website: ItemWe
|
||||
const ItemWebsiteLink = ({ website }: { website: ItemWebsite }) => {
|
||||
if (!shouldRenderSeparateItemWebsite(website)) return null;
|
||||
|
||||
return <Link src={website.url}>{website.label || website.url}</Link>;
|
||||
return <Link src={website.url}>{getWebsiteDisplayText(website)}</Link>;
|
||||
};
|
||||
|
||||
const SummarySection = ({ showHeading = true }: { showHeading?: boolean } = {}) => {
|
||||
|
||||
Reference in New Issue
Block a user