Skip to content

Commit c87c491

Browse files
committed
frontend(Options.tsx): add an input for the the new fontFamily query param
1 parent d3516c2 commit c87c491

File tree

10 files changed

+45
-15
lines changed

10 files changed

+45
-15
lines changed

client/build/asset-manifest.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/build/index.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/build/static/js/main.742c82d7.js renamed to client/build/static/js/main.1f52111a.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/build/static/js/main.742c82d7.js.map renamed to client/build/static/js/main.1f52111a.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/src/components/input/Input.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,16 @@ const Input: FC<InputProps> = (props) => {
4343
/>
4444

4545
{!isError && props.helperText && (
46-
<div className="flex items-center gap-1 text-sm italic text-gh-text-secondary">
47-
<HiOutlineInformationCircle /> {props.helperText}
46+
<div className="flex items-center gap-1 text-[.8rem] italic text-gh-text-secondary">
47+
<HiOutlineInformationCircle />
48+
<span>{props.helperText}</span>
4849
</div>
4950
)}
5051

5152
{isError && (
52-
<div className="flex items-center gap-1 text-sm italic text-red-500">
53-
<BiError /> {props.validate(props.value)}
53+
<div className="flex items-center gap-1 text-[.8rem] italic text-red-500">
54+
<BiError />
55+
<span>{props.validate(props.value)}</span>
5456
</div>
5557
)}
5658
</div>

client/src/pages/Options.tsx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import NumberInput from "../components/input/NumberInput";
1212
import TrueFalseInput from "../components/input/TrueFalseInput";
1313
import Input from "../components/input/Input";
1414
import SecondaryButton from "../components/buttons/SecondaryButton";
15-
import { validateBorderRadius } from "../utils/validate";
15+
import { validateBorderRadius, validateFontFamily } from "../utils/validate";
1616

1717
interface OptionsProps {
1818
setLink: (link: string) => void;
@@ -122,6 +122,17 @@ const Options: FC<OptionsProps> = (props) => {
122122
validate={(val) => validateBorderRadius(val)}
123123
/>
124124

125+
<Input
126+
label="Font Family"
127+
placeholder="Segoe UI"
128+
value={card.fontFamily}
129+
setValue={(v) =>
130+
setCard({ ...card, fontFamily: v, lines: card.lines })
131+
}
132+
helperText="If the specified family doesn't exist, the default is used."
133+
validate={(val) => validateFontFamily(val)}
134+
/>
135+
125136
<div className="flex items-start gap-4">
126137
<TrueFalseInput
127138
label="Border"
@@ -158,7 +169,12 @@ const Options: FC<OptionsProps> = (props) => {
158169
<GreenButton
159170
icon={IoHammerOutline}
160171
onClick={() => props.setLink(generateLink(card))}
161-
disabled={validateBorderRadius(card.borderRadius) !== ""}
172+
disabled={
173+
!(
174+
validateBorderRadius(card.borderRadius) === "" &&
175+
validateFontFamily(card.fontFamily) === ""
176+
)
177+
}
162178
text="Generate"
163179
/>
164180

client/src/types/card.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export interface Card {
2323
borderRadius: string;
2424
fontWeight: string;
2525
fontSize: string;
26+
fontFamily: string;
2627
lines: Line[];
2728
}
2829

@@ -35,6 +36,7 @@ export const newCard = (): Card => {
3536
lines: [{ badges: [], lineNumber: "1" }],
3637
showBorder: true,
3738
theme: "github",
39+
fontFamily: "Segoe UI",
3840
title: "My Tech Stack",
3941
};
4042
};

client/src/utils/generate.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ export const generateLink = ({
99
borderRadius,
1010
fontWeight,
1111
fontSize,
12+
fontFamily,
1213
}: Card): string => {
1314
// replace every space with %20
1415
title = title.replace(/[ ]/g, "%20");
16+
fontFamily = fontFamily.replace(/[ ]/g, "%20");
1517

16-
let res = `https://github-readme-tech-stack.vercel.app/api/cards?title=${title}&lineCount=${lines.length}&theme=${theme}&align=${align}&showBorder=${showBorder}&borderRadius=${borderRadius}&fontSize=${fontSize}&fontWeight=${fontWeight}`;
18+
let res = `https://github-readme-tech-stack.vercel.app/api/cards?title=${title}&lineCount=${lines.length}&theme=${theme}&align=${align}&showBorder=${showBorder}&borderRadius=${borderRadius}&fontSize=${fontSize}&fontWeight=${fontWeight}&fontFamily=${fontFamily}`;
1719

1820
for (const l of lines) {
1921
// if the line doesn't contain badges

client/src/utils/validate.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ export const validateIconAndLabel = (
2323
return "";
2424
};
2525

26+
export const validateFontFamily = (val: string): string => {
27+
if (val.length < 3 || val.length > 16) {
28+
return `The font family should be between 2 and 16 characters.`;
29+
}
30+
31+
return "";
32+
};
33+
2634
export const validateBorderRadius = (val: string): string => {
2735
const num = parseInt(val);
2836

0 commit comments

Comments
 (0)