Skip to content

Commit

Permalink
improved crossfader + favicons + stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
antoniocosentino committed Jul 26, 2023
1 parent f2408f5 commit 0dcc593
Show file tree
Hide file tree
Showing 13 changed files with 128 additions and 12 deletions.
Binary file added public/android-chrome-192x192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/android-chrome-512x512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/apple-touch-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/favicon-16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/favicon-32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/favicon.ico
Binary file not shown.
Binary file added public/mstile-150x150.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
67 changes: 55 additions & 12 deletions src/app/components/Interface.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { GoogleFonts, StandardFonts } from "../types";
import { getDummyText } from "../utils/getDummyText";
import { Helmet } from "react-helmet";
import { useOutsideClick } from "../customHooks/useOutsideClick";
import { FONT_WEIGHTS } from "../utils/fontWeights";
import { getComputedOpacity } from "../utils/getComputedOpacity";

type InterfaceProps = {
googleFonts: GoogleFonts;
Expand All @@ -14,7 +16,7 @@ const DEFAULT_GOOGLE_FONT = "Lato";
const DEFAULT_STANDARD_FONT = "Arial";
const DEFAULT_FONT_SIZE = 22;
const DEFAULT_LINE_HEIGHT = 1.4;
const DEFAULT_FONT_WEIGHT = "normal";
const DEFAULT_FONT_WEIGHT = 400;
const DEFAULT_LETTER_SPACING = 0;
const DEFAULT_WORD_SPACING = 0;
const DEFAULT_SIZE_ADJUST = 98;
Expand Down Expand Up @@ -55,8 +57,16 @@ export const Interface = (props: InterfaceProps) => {
);

const [isInEditMode, setIsInEditMode] = useState(false);

const [overlapBalance, setOverlapBalance] = useState(50);
const [useDifferentColor, setUseDifferentColor] = useState(true);

const iterableFontWeights = FONT_WEIGHTS.entries();
const fontWeightsArray = Array.from(iterableFontWeights);

console.log(
"🍌: Interface -> getComputedOpacity(overlapBalance).fallbackFontOpacity",
getComputedOpacity(overlapBalance)
);

const handleTextareaType = (
event: React.ChangeEvent<HTMLTextAreaElement>
Expand Down Expand Up @@ -87,7 +97,7 @@ export const Interface = (props: InterfaceProps) => {
{/* eslint-disable-next-line @next/next/google-font-display, @next/next/no-page-custom-font */}
<link
rel="stylesheet"
href={`https://fonts.googleapis.com/css?family=${fontName}`}
href={`https://fonts.googleapis.com/css2?family=${fontName}:wght@${fontWeight}`}
/>
</Helmet>

Expand Down Expand Up @@ -174,11 +184,19 @@ export const Interface = (props: InterfaceProps) => {
</label>
</div>
<div className="w-2/4">
<input
<select
onChange={(e) => setFontWeight(parseInt(e.target.value))}
className={INPUT_CLASSES}
defaultValue={DEFAULT_FONT_WEIGHT}
onChange={(e) => setFontWeight(e.target.value)}
/>
>
{fontWeightsArray.map((fontWeight) => {
return (
<option key={fontWeight[1]} value={fontWeight[1]}>
{fontWeight[0]}
</option>
);
})}
</select>
</div>
</div>

Expand Down Expand Up @@ -305,18 +323,37 @@ export const Interface = (props: InterfaceProps) => {
/>
</div>
</div>

<div className="flex items-center mb-6">
<div className="w-2/4">
<label className="block font-bold text-left mb-1 pr-4">
Show with different color
</label>
<p className="text-xs text-left text-slate-600">
This is only affecting the preview
</p>
</div>
<div className="w-5">
<input
type="checkbox"
className="h-6 w-6"
defaultChecked={useDifferentColor}
onChange={(e) => setUseDifferentColor(!useDifferentColor)}
/>
</div>
</div>
</div>
</div>

<div className="text-left mt-8 flex justify-between">
<div>
<h2 className="font-medium text-2xl">Preview</h2>
<p className="text-xs text-slate-400">
<p className="text-xs text-slate-600">
Click on the preview area to edit the default text
</p>
</div>
<div>
<p className="text-sm font-bold">Preview balance</p>
<p className="text-sm font-bold">Preview crossfader™</p>
<input
className="rounded-lg overflow-hidden appearance-none bg-gray-400 h-3 w-128"
type="range"
Expand All @@ -330,19 +367,23 @@ export const Interface = (props: InterfaceProps) => {
</div>

<div className="text-left mt-3 bg-slate-50 rounded p-4 pt-1 pb-8">
<div className="mt-6 relative">
<div className="mt-6 relative overflow-hidden">
{!isInEditMode && (
<>
<div
className="relative"
className={`relative ${
useDifferentColor ? "text-sky-500" : ""
} `}
style={{
fontFamily: `fallback for ${fontName}`,
fontSize: `${fontSize}px`,
lineHeight: `${lineHeight}em`,
fontWeight: fontWeight,
letterSpacing: `${letterSpacing}px`,
wordSpacing: `${wordSpacing}px`,
opacity: `${overlapBalance}%`,
opacity: `${
getComputedOpacity(overlapBalance).fallbackFontOpacity
}%`,
}}
>
{sampleText}
Expand All @@ -357,7 +398,9 @@ export const Interface = (props: InterfaceProps) => {
fontWeight: fontWeight,
letterSpacing: `${letterSpacing}px`,
wordSpacing: `${wordSpacing}px`,
opacity: `${100 - overlapBalance}%`,
opacity: `${
getComputedOpacity(overlapBalance).finalFontOpacity
}%`,
}}
>
{sampleText}
Expand Down
Binary file modified src/app/favicon.ico
Binary file not shown.
20 changes: 20 additions & 0 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,26 @@ export default function RootLayout({
}) {
return (
<html lang="en">
<head>
<link
rel="apple-touch-icon"
sizes="180x180"
href="/apple-touch-icon.png"
/>
<link
rel="icon"
type="image/png"
sizes="32x32"
href="/favicon-32x32.png"
/>
<link
rel="icon"
type="image/png"
sizes="16x16"
href="/favicon-16x16.png"
/>
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5" />
</head>
<body className={inter.className}>{children}</body>
</html>
);
Expand Down
5 changes: 5 additions & 0 deletions src/app/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,8 @@ export type GoogleFonts = ReadonlyArray<GoogleFont>;
export type GoogleFontResponse = {
items: GoogleFonts;
};

export type ComputedOpacity = {
finalFontOpacity: number;
fallbackFontOpacity: number;
};
11 changes: 11 additions & 0 deletions src/app/utils/fontWeights.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export const FONT_WEIGHTS = new Map([
["Thin", "100"],
["Extra Light", "200"],
["Light", "300"],
["Regular", "400"],
["Medium", "500"],
["Semi Bold", "600"],
["Bold", "700"],
["Extra Bold", "800"],
["Black", "900"],
]);
37 changes: 37 additions & 0 deletions src/app/utils/getComputedOpacity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { ComputedOpacity } from "../types";

export const getComputedOpacity = (value: number): ComputedOpacity => {
// the idea of this method is to reproduce a crossfader effect
// example:
// original value 50: 100% + 100%
// original value 25: 100% + 50%
// original value 75: 50% + 100%

if (value === 50) {
return {
finalFontOpacity: 100,
fallbackFontOpacity: 100,
};
}

const convertedPercentage = (100 * value) / 50;

if (value < 50) {
return {
finalFontOpacity: 100,
fallbackFontOpacity: convertedPercentage,
};
}

if (value > 50) {
return {
finalFontOpacity: 100 - (convertedPercentage - 100),
fallbackFontOpacity: 100,
};
}

return {
finalFontOpacity: 100,
fallbackFontOpacity: 100,
};
};

0 comments on commit 0dcc593

Please sign in to comment.